Index: palm/trunk/SOURCE/fft_xy_mod.f90
===================================================================
--- palm/trunk/SOURCE/fft_xy_mod.f90	(revision 4645)
+++ palm/trunk/SOURCE/fft_xy_mod.f90	(revision 4646)
@@ -1,39 +1,41 @@
 !> @file fft_xy_mod.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4370 2020-01-10 14:00:44Z raasch
 ! bugfix for Temperton-fft usage on GPU
-! 
+!
 ! 4366 2020-01-09 08:12:43Z raasch
 ! Vectorized Temperton-fft added
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Corrected "Former revisions" section
-! 
+!
 ! 4069 2019-07-01 14:05:51Z Giersch
 ! Code added to avoid compiler warnings
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! OpenACC port for SPEC
@@ -50,12 +52,12 @@
 !------------------------------------------------------------------------------!
  MODULE fft_xy
- 
-
-    USE control_parameters,                                                    &
+
+
+    USE control_parameters,                                                                        &
         ONLY:  fft_method, loop_optimization, message_string
-        
+
     USE cuda_fft_interfaces
-        
-    USE indices,                                                               &
+
+    USE indices,                                                                                   &
         ONLY:  nx, ny, nz
 
@@ -67,11 +69,11 @@
 
     USE kinds
-    
-    USE singleton,                                                             &
+
+    USE singleton,                                                                                 &
         ONLY: fftn
-    
+
     USE temperton_fft
-    
-    USE transpose_indices,                                                     &
+
+    USE transpose_indices,                                                                         &
         ONLY:  nxl_y, nxr_y, nyn_x, nys_x, nzb_x, nzb_y, nzt_x, nzt_y
 
@@ -79,5 +81,5 @@
 
     PRIVATE
-    PUBLIC fft_x, fft_x_1d, fft_y, fft_y_1d, fft_init, fft_x_m, fft_y_m, f_vec_x, temperton_fft_vec
+    PUBLIC fft_init, f_vec_x, fft_x, fft_x_1d, fft_x_m, fft_y, fft_y_1d, fft_y_m, temperton_fft_vec
 
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE, SAVE ::  ifax_x  !<
@@ -91,6 +93,6 @@
     REAL(wp), SAVE ::  sqr_dnx  !<
     REAL(wp), SAVE ::  sqr_dny  !<
-    
-    REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE ::  trigs_x  !< 
+
+    REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE ::  trigs_x  !<
     REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE ::  trigs_y  !<
 
@@ -98,22 +100,21 @@
 
 #if defined( __ibm )
-    INTEGER(iwp), PARAMETER ::  nau1 = 20000  !< 
+    INTEGER(iwp), PARAMETER ::  nau1 = 20000  !<
     INTEGER(iwp), PARAMETER ::  nau2 = 22000  !<
 !
-!-- The following working arrays contain tables and have to be "save" and
-!-- shared in OpenMP sense
-    REAL(wp), DIMENSION(nau1), SAVE ::  aux1  !< 
+!-- The following working arrays contain tables and have to be "save" and shared in OpenMP sense
+    REAL(wp), DIMENSION(nau1), SAVE ::  aux1  !<
     REAL(wp), DIMENSION(nau1), SAVE ::  auy1  !<
-    REAL(wp), DIMENSION(nau1), SAVE ::  aux3  !< 
+    REAL(wp), DIMENSION(nau1), SAVE ::  aux3  !<
     REAL(wp), DIMENSION(nau1), SAVE ::  auy3  !<
-    
+
 #elif defined( __nec_fft )
     INTEGER(iwp), SAVE ::  nz1  !<
-    
+
     REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE ::  trig_xb  !<
-    REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE ::  trig_xf  !< 
+    REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE ::  trig_xf  !<
     REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE ::  trig_yb  !<
     REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE ::  trig_yf  !<
-    
+
 #elif defined( __cuda_fft )
     INTEGER(C_INT), SAVE ::  plan_xf  !<
@@ -126,18 +127,15 @@
 #if defined( __fftw )
     INCLUDE  'fftw3.f03'
+    COMPLEX(KIND=C_DOUBLE_COMPLEX), DIMENSION(:), ALLOCATABLE, SAVE ::  x_out  !<
+    COMPLEX(KIND=C_DOUBLE_COMPLEX), DIMENSION(:), ALLOCATABLE, SAVE ::  y_out  !<
+
     INTEGER(KIND=C_INT) ::  nx_c  !<
     INTEGER(KIND=C_INT) ::  ny_c  !<
-    
-    COMPLEX(KIND=C_DOUBLE_COMPLEX), DIMENSION(:), ALLOCATABLE, SAVE ::  x_out  !<
-    COMPLEX(KIND=C_DOUBLE_COMPLEX), DIMENSION(:), ALLOCATABLE, SAVE ::         &
-       y_out  !<
-    
-    REAL(KIND=C_DOUBLE), DIMENSION(:), ALLOCATABLE, SAVE ::                    &
-       x_in   !<
-    REAL(KIND=C_DOUBLE), DIMENSION(:), ALLOCATABLE, SAVE ::                    &
-       y_in   !<
+
+    REAL(KIND=C_DOUBLE), DIMENSION(:), ALLOCATABLE, SAVE ::  x_in   !<
+    REAL(KIND=C_DOUBLE), DIMENSION(:), ALLOCATABLE, SAVE ::  y_in   !<
     !$OMP THREADPRIVATE( x_out, y_out, x_in, y_in )
-    
-    
+
+
     TYPE(C_PTR), SAVE ::  plan_xf, plan_xi, plan_yf, plan_yi
 #endif
@@ -176,9 +174,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE fft_init
 
@@ -192,10 +190,10 @@
 !--    in OpenMP sense
 #if defined( __ibm )
+       REAL(wp), DIMENSION(nau2)   ::  aux2   !<
+       REAL(wp), DIMENSION(nau2)   ::  auy2   !<
+       REAL(wp), DIMENSION(nau2)   ::  aux4   !<
+       REAL(wp), DIMENSION(nau2)   ::  auy4   !<
        REAL(wp), DIMENSION(0:nx+2) ::  workx  !<
        REAL(wp), DIMENSION(0:ny+2) ::  worky  !<
-       REAL(wp), DIMENSION(nau2)   ::  aux2   !< 
-       REAL(wp), DIMENSION(nau2)   ::  auy2   !< 
-       REAL(wp), DIMENSION(nau2)   ::  aux4   !< 
-       REAL(wp), DIMENSION(nau2)   ::  auy4   !<
 #elif defined( __nec_fft )
        REAL(wp), DIMENSION(0:nx+3,nz+1)   ::  work_x  !<
@@ -203,5 +201,5 @@
        REAL(wp), DIMENSION(6*(nx+3),nz+1) ::  workx   !<
        REAL(wp), DIMENSION(6*(ny+3),nz+1) ::  worky   !<
-#endif 
+#endif
 
 !
@@ -233,21 +231,15 @@
 !
 !--       Initialize tables for fft along x
-          CALL DRCFT( 1, workx, 1, workx, 1, nx+1, 1,  1, sqr_dnx, aux1, nau1, &
-                      aux2, nau2 )
-          CALL DCRFT( 1, workx, 1, workx, 1, nx+1, 1, -1, sqr_dnx, aux3, nau1, &
-                      aux4, nau2 )
+          CALL DRCFT( 1, workx, 1, workx, 1, nx+1, 1,  1, sqr_dnx, aux1, nau1, aux2, nau2 )
+          CALL DCRFT( 1, workx, 1, workx, 1, nx+1, 1, -1, sqr_dnx, aux3, nau1, aux4, nau2 )
 !
 !--       Initialize tables for fft along y
-          CALL DRCFT( 1, worky, 1, worky, 1, ny+1, 1,  1, sqr_dny, auy1, nau1, &
-                      auy2, nau2 )
-          CALL DCRFT( 1, worky, 1, worky, 1, ny+1, 1, -1, sqr_dny, auy3, nau1, &
-                      auy4, nau2 )
+          CALL DRCFT( 1, worky, 1, worky, 1, ny+1, 1,  1, sqr_dny, auy1, nau1, auy2, nau2 )
+          CALL DCRFT( 1, worky, 1, worky, 1, ny+1, 1, -1, sqr_dny, auy3, nau1, auy4, nau2 )
 #elif defined( __nec_fft )
-          message_string = 'fft method "' // TRIM( fft_method) // &
-                           '" currently does not work on NEC'
+          message_string = 'fft method "' // TRIM( fft_method) // '" currently does not work on NEC'
           CALL message( 'fft_init', 'PA0187', 1, 2, 0, 6, 0 )
 
-          ALLOCATE( trig_xb(2*(nx+1)), trig_xf(2*(nx+1)),                      &
-                    trig_yb(2*(ny+1)), trig_yf(2*(ny+1)) )
+          ALLOCATE( trig_xb(2*(nx+1)), trig_xf(2*(nx+1)), trig_yb(2*(ny+1)), trig_yf(2*(ny+1)) )
 
           work_x = 0.0_wp
@@ -260,16 +252,12 @@
           CALL DZFFT( 0, nx+1, sqr_dnx, work_x, work_x, trig_xf, workx, 0 )
           CALL ZDFFT( 0, nx+1, sqr_dnx, work_x, work_x, trig_xb, workx, 0 )
-          CALL DZFFTM( 0, nx+1, nz1, sqr_dnx, work_x, nx+4, work_x, nx+4,      &
-                       trig_xf, workx, 0 )
-          CALL ZDFFTM( 0, nx+1, nz1, sqr_dnx, work_x, nx+4, work_x, nx+4,      &
-                       trig_xb, workx, 0 )
+          CALL DZFFTM( 0, nx+1, nz1, sqr_dnx, work_x, nx+4, work_x, nx+4, trig_xf, workx, 0 )
+          CALL ZDFFTM( 0, nx+1, nz1, sqr_dnx, work_x, nx+4, work_x, nx+4, trig_xb, workx, 0 )
 !
 !--       Initialize tables for fft along y (non-vector and vector case (M))
           CALL DZFFT( 0, ny+1, sqr_dny, work_y, work_y, trig_yf, worky, 0 )
           CALL ZDFFT( 0, ny+1, sqr_dny, work_y, work_y, trig_yb, worky, 0 )
-          CALL DZFFTM( 0, ny+1, nz1, sqr_dny, work_y, ny+4, work_y, ny+4,      &
-                       trig_yf, worky, 0 )
-          CALL ZDFFTM( 0, ny+1, nz1, sqr_dny, work_y, ny+4, work_y, ny+4,      &
-                       trig_yb, worky, 0 )
+          CALL DZFFTM( 0, ny+1, nz1, sqr_dny, work_y, ny+4, work_y, ny+4, trig_yf, worky, 0 )
+          CALL ZDFFTM( 0, ny+1, nz1, sqr_dny, work_y, ny+4, work_y, ny+4, trig_yb, worky, 0 )
 #elif defined( __cuda_fft )
           CALL CUFFTPLAN1D( plan_xf, nx+1, CUFFT_D2Z, (nyn_x-nys_x+1) * (nzt_x-nzb_x+1) )
@@ -303,6 +291,5 @@
           ny_c = ny+1
           !$OMP PARALLEL
-          ALLOCATE( x_in(0:nx+2), y_in(0:ny+2), x_out(0:(nx+1)/2),             &
-                    y_out(0:(ny+1)/2) )
+          ALLOCATE( x_in(0:nx+2), y_in(0:ny+2), x_out(0:(nx+1)/2), y_out(0:(ny+1)/2) )
           !$OMP END PARALLEL
           plan_xf = FFTW_PLAN_DFT_R2C_1D( nx_c, x_in, x_out, FFTW_ESTIMATE )
@@ -321,6 +308,5 @@
        ELSE
 
-          message_string = 'fft method "' // TRIM( fft_method) // &
-                           '" not available'
+          message_string = 'fft method "' // TRIM( fft_method) // '" not available'
           CALL message( 'fft_init', 'PA0189', 1, 2, 0, 6, 0 )
        ENDIF
@@ -329,13 +315,13 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Fourier-transformation along x-direction.                 
+!> Fourier-transformation along x-direction.
 !> Version for 2D-decomposition.
-!> It uses internal algorithms (Singleton or Temperton) or      
-!> system-specific routines, if they are available           
-!------------------------------------------------------------------------------!
- 
+!> It uses internal algorithms (Singleton or Temperton) or system-specific routines, if they are
+!> available.
+!--------------------------------------------------------------------------------------------------!
+
     SUBROUTINE fft_x( ar, direction, ar_2d, ar_inv )
 
@@ -344,8 +330,8 @@
 
        CHARACTER (LEN=*) ::  direction  !<
-       
+
        COMPLEX(wp), DIMENSION(:), ALLOCATABLE ::  cwork  !<
 
-       INTEGER(iwp) ::  i          !< 
+       INTEGER(iwp) ::  i          !<
        INTEGER(iwp) ::  ishape(1)  !<
        INTEGER(iwp) ::  j          !<
@@ -354,16 +340,16 @@
 
        LOGICAL ::  forward_fft !<
-       
+
        REAL(wp), DIMENSION(0:nx+2) ::  work   !<
        REAL(wp), DIMENSION(nx+2)   ::  work1  !<
-       
+
        REAL(wp), DIMENSION(:,:), ALLOCATABLE           ::  work_vec  !<
        REAL(wp), DIMENSION(0:nx,nys_x:nyn_x), OPTIONAL ::  ar_2d     !<
 
+       REAL(wp), DIMENSION(0:nx,nys_x:nyn_x,nzb_x:nzt_x)           ::  ar       !<
        REAL(wp), DIMENSION(nys_x:nyn_x,nzb_x:nzt_x,0:nx), OPTIONAL ::  ar_inv   !<
-       REAL(wp), DIMENSION(0:nx,nys_x:nyn_x,nzb_x:nzt_x)           ::  ar       !<
 
 #if defined( __ibm )
-       REAL(wp), DIMENSION(nau2) ::  aux2  !< 
+       REAL(wp), DIMENSION(nau2) ::  aux2  !<
        REAL(wp), DIMENSION(nau2) ::  aux4  !<
 #elif defined( __nec_fft )
@@ -387,9 +373,9 @@
 
 !
-!--       Performing the fft with singleton's software works on every system,
-!--       since it is part of the model
+!--       Performing the fft with singleton's software works on every system, since it is part of
+!--       the model.
           ALLOCATE( cwork(0:nx) )
-      
-          IF ( forward_fft )   then
+
+          IF ( forward_fft )  THEN
 
              !$OMP PARALLEL PRIVATE ( cwork, i, ishape, j, k )
@@ -425,8 +411,6 @@
                    cwork(0) = CMPLX( ar(0,j,k), 0.0_wp, KIND=wp )
                    DO  i = 1, (nx+1)/2 - 1
-                      cwork(i)      = CMPLX( ar(i,j,k), -ar(nx+1-i,j,k),       &
-                                             KIND=wp )
-                      cwork(nx+1-i) = CMPLX( ar(i,j,k),  ar(nx+1-i,j,k),       &
-                                             KIND=wp )
+                      cwork(i)      = CMPLX( ar(i,j,k), -ar(nx+1-i,j,k), KIND=wp )
+                      cwork(nx+1-i) = CMPLX( ar(i,j,k),  ar(nx+1-i,j,k), KIND=wp )
                    ENDDO
                    cwork((nx+1)/2) = CMPLX( ar((nx+1)/2,j,k), 0.0_wp, KIND=wp )
@@ -450,6 +434,6 @@
 
 !
-!--       Performing the fft with Temperton's software works on every system,
-!--       since it is part of the model
+!--       Performing the fft with Temperton's software works on every system, since it is part of
+!--       the model.
           IF ( forward_fft )  THEN
 
@@ -633,9 +617,7 @@
                       x_out(0) = CMPLX( ar_2d(0,j), 0.0_wp, KIND=wp )
                       DO  i = 1, (nx+1)/2 - 1
-                         x_out(i) = CMPLX( ar_2d(i,j), ar_2d(nx+1-i,j),        &
-                                           KIND=wp )
-                      ENDDO
-                      x_out((nx+1)/2) = CMPLX( ar_2d((nx+1)/2,j), 0.0_wp,      &
-                                               KIND=wp )
+                         x_out(i) = CMPLX( ar_2d(i,j), ar_2d(nx+1-i,j), KIND=wp )
+                      ENDDO
+                      x_out((nx+1)/2) = CMPLX( ar_2d((nx+1)/2,j), 0.0_wp, KIND=wp )
 
                    ELSE
@@ -645,6 +627,5 @@
                          x_out(i) = CMPLX( ar(i,j,k), ar(nx+1-i,j,k), KIND=wp )
                       ENDDO
-                      x_out((nx+1)/2) = CMPLX( ar((nx+1)/2,j,k), 0.0_wp,       &
-                                               KIND=wp )
+                      x_out((nx+1)/2) = CMPLX( ar((nx+1)/2,j,k), 0.0_wp, KIND=wp )
 
                    ENDIF
@@ -670,6 +651,5 @@
                 DO  j = nys_x, nyn_x
 
-                   CALL DRCFT( 0, ar, 1, work, 1, nx+1, 1, 1, sqr_dnx, aux1,   &
-                               nau1, aux2, nau2 )
+                   CALL DRCFT( 0, ar, 1, work, 1, nx+1, 1, 1, sqr_dnx, aux1, nau1, aux2, nau2 )
 
                    DO  i = 0, (nx+1)/2
@@ -700,6 +680,5 @@
                    work(nx+2) = 0.0_wp
 
-                   CALL DCRFT( 0, work, 1, work, 1, nx+1, 1, -1, sqr_dnx,      & 
-                               aux3, nau1, aux4, nau2 )
+                   CALL DCRFT( 0, work, 1, work, 1, nx+1, 1, -1, sqr_dnx, aux3, nau1, aux4, nau2 )
 
                    DO  i = 0, nx
@@ -725,5 +704,5 @@
 
                    CALL DZFFT( 1, nx+1, sqr_dnx, work, work, trig_xf, work2, 0 )
-      
+
                    DO  i = 0, (nx+1)/2
                       ar(i,j,k) = work(2*i)
@@ -797,9 +776,7 @@
 
                    DO  i = 1, (nx+1)/2 - 1
-                      ar_tmp(i,j,k) = CMPLX( ar(i,j,k), ar(nx+1-i,j,k),        &
-                                             KIND=wp )
-                   ENDDO
-                   ar_tmp((nx+1)/2,j,k) = CMPLX( ar((nx+1)/2,j,k), 0.0_wp,     &
-                                                 KIND=wp )
+                      ar_tmp(i,j,k) = CMPLX( ar(i,j,k), ar(nx+1-i,j,k), KIND=wp )
+                   ENDDO
+                   ar_tmp((nx+1)/2,j,k) = CMPLX( ar((nx+1)/2,j,k), 0.0_wp, KIND=wp )
 
                 ENDDO
@@ -818,13 +795,13 @@
     END SUBROUTINE fft_x
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Fourier-transformation along x-direction.
 !> Version for 1D-decomposition.
-!> It uses internal algorithms (Singleton or Temperton) or
-!> system-specific routines, if they are available
-!------------------------------------------------------------------------------!
- 
+!> It uses internal algorithms (Singleton or Temperton) or system-specific routines, if they are
+!> available.
+!--------------------------------------------------------------------------------------------------!
+
     SUBROUTINE fft_x_1d( ar, direction )
 
@@ -833,5 +810,5 @@
 
        CHARACTER (LEN=*) ::  direction  !<
-       
+
        INTEGER(iwp) ::  i               !<
        INTEGER(iwp) ::  ishape(1)       !<
@@ -842,7 +819,7 @@
        REAL(wp), DIMENSION(0:nx+2) ::  work   !<
        REAL(wp), DIMENSION(nx+2)   ::  work1  !<
-       
+
        COMPLEX(wp), DIMENSION(:), ALLOCATABLE ::  cwork  !<
-       
+
 #if defined( __ibm )
        REAL(wp), DIMENSION(nau2) ::  aux2       !<
@@ -861,9 +838,9 @@
 
 !
-!--       Performing the fft with singleton's software works on every system,
-!--       since it is part of the model
+!--       Performing the fft with singleton's software works on every system, since it is part of
+!--       the model.
           ALLOCATE( cwork(0:nx) )
-      
-          IF ( forward_fft )   then
+
+          IF ( forward_fft )  THEN
 
              DO  i = 0, nx
@@ -902,6 +879,6 @@
 
 !
-!--       Performing the fft with Temperton's software works on every system,
-!--       since it is part of the model
+!--       Performing the fft with Temperton's software works on every system, since it is part of
+!--       the model.
           IF ( forward_fft )  THEN
 
@@ -966,6 +943,5 @@
           IF ( forward_fft )  THEN
 
-             CALL DRCFT( 0, ar, 1, work, 1, nx+1, 1, 1, sqr_dnx, aux1, nau1,   &
-                         aux2, nau2 )
+             CALL DRCFT( 0, ar, 1, work, 1, nx+1, 1, 1, sqr_dnx, aux1, nau1, aux2, nau2 )
 
              DO  i = 0, (nx+1)/2
@@ -987,6 +963,5 @@
              work(nx+2) = 0.0_wp
 
-             CALL DCRFT( 0, work, 1, work, 1, nx+1, 1, -1, sqr_dnx, aux3, nau1, &
-                         aux4, nau2 )
+             CALL DCRFT( 0, work, 1, work, 1, nx+1, 1, -1, sqr_dnx, aux3, nau1, aux4, nau2 )
 
              DO  i = 0, nx
@@ -1001,5 +976,5 @@
 
              CALL DZFFT( 1, nx+1, sqr_dnx, work, work, trig_xf, work2, 0 )
-      
+
              DO  i = 0, (nx+1)/2
                 ar(i) = work(2*i)
@@ -1031,30 +1006,29 @@
     END SUBROUTINE fft_x_1d
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Fourier-transformation along y-direction.
 !> Version for 2D-decomposition.
-!> It uses internal algorithms (Singleton or Temperton) or
-!> system-specific routines, if they are available.
-!> 
+!> It uses internal algorithms (Singleton or Temperton) or system-specific routines, if they are
+!> available.
+!>
 !> direction:  'forward' or 'backward'
-!> ar, ar_tr:  3D data arrays 
+!> ar, ar_tr:  3D data arrays
 !>             forward:   ar: before  ar_tr: after transformation
 !>             backward:  ar_tr: before  ar: after transfosition
-!> 
+!>
 !> In case of non-overlapping transposition/transformation:
-!> nxl_y_bound = nxl_y_l = nxl_y 
-!> nxr_y_bound = nxr_y_l = nxr_y 
-!> 
+!> nxl_y_bound = nxl_y_l = nxl_y
+!> nxr_y_bound = nxr_y_l = nxr_y
+!>
 !> In case of overlapping transposition/transformation
-!> - nxl_y_bound  and  nxr_y_bound have the original values of
-!>   nxl_y, nxr_y.  ar_tr is dimensioned using these values.
-!> - nxl_y_l = nxr_y_r.  ar is dimensioned with these values, so that
-!>   transformation is carried out for a 2D-plane only.
-!------------------------------------------------------------------------------!
- 
-    SUBROUTINE fft_y( ar, direction, ar_tr, nxl_y_bound, nxr_y_bound, nxl_y_l, &
-                      nxr_y_l, ar_inv )
+!> - nxl_y_bound  and  nxr_y_bound have the original values of nxl_y, nxr_y.  ar_tr is dimensioned
+!>   using these values.
+!> - nxl_y_l = nxr_y_r.  ar is dimensioned with these values, so that transformation is carried out
+!>   for a 2D-plane only.
+!--------------------------------------------------------------------------------------------------!
+
+    SUBROUTINE fft_y( ar, direction, ar_tr, nxl_y_bound, nxr_y_bound, nxl_y_l, nxr_y_l, ar_inv )
 
 
@@ -1062,7 +1036,7 @@
 
        CHARACTER (LEN=*) ::  direction  !<
-       
+
        INTEGER(iwp) ::  i            !<
-       INTEGER(iwp) ::  j            !< 
+       INTEGER(iwp) ::  j            !<
        INTEGER(iwp) ::  jshape(1)    !<
        INTEGER(iwp) ::  k            !<
@@ -1077,5 +1051,5 @@
        REAL(wp), DIMENSION(0:ny+2) ::  work   !<
        REAL(wp), DIMENSION(ny+2)   ::  work1  !<
-       
+
        REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  f_vec_y
        REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  work_vec
@@ -1086,5 +1060,5 @@
 
        COMPLEX(wp), DIMENSION(:), ALLOCATABLE ::  cwork  !<
-       
+
 #if defined( __ibm )
        REAL(wp), DIMENSION(nau2) ::  auy2  !<
@@ -1093,6 +1067,5 @@
        REAL(wp), DIMENSION(6*(ny+1)) ::  work2  !<
 #elif defined( __cuda_fft )
-       COMPLEX(dp), DIMENSION(0:(ny+1)/2,nxl_y:nxr_y,nzb_y:nzt_y) ::           &
-          ar_tmp  !<
+       COMPLEX(dp), DIMENSION(0:(ny+1)/2,nxl_y:nxr_y,nzb_y:nzt_y) ::  ar_tmp  !<
        !$ACC DECLARE CREATE(ar_tmp)
 #endif
@@ -1108,9 +1081,9 @@
 
 !
-!--       Performing the fft with singleton's software works on every system,
-!--       since it is part of the model
+!--       Performing the fft with singleton's software works on every system, since it is part of
+!--       the model.
           ALLOCATE( cwork(0:ny) )
 
-          IF ( forward_fft )   then
+          IF ( forward_fft )  THEN
 
              !$OMP PARALLEL PRIVATE ( cwork, i, jshape, j, k )
@@ -1146,11 +1119,8 @@
                    cwork(0) = CMPLX( ar_tr(0,i,k), 0.0_wp, KIND=wp )
                    DO  j = 1, (ny+1)/2 - 1
-                      cwork(j)      = CMPLX( ar_tr(j,i,k), -ar_tr(ny+1-j,i,k), &
-                                             KIND=wp )
-                      cwork(ny+1-j) = CMPLX( ar_tr(j,i,k),  ar_tr(ny+1-j,i,k), &
-                                             KIND=wp )
-                   ENDDO
-                   cwork((ny+1)/2) = CMPLX( ar_tr((ny+1)/2,i,k), 0.0_wp,       &
-                                            KIND=wp )
+                      cwork(j)      = CMPLX( ar_tr(j,i,k), -ar_tr(ny+1-j,i,k), KIND=wp )
+                      cwork(ny+1-j) = CMPLX( ar_tr(j,i,k),  ar_tr(ny+1-j,i,k), KIND=wp )
+                   ENDDO
+                   cwork((ny+1)/2) = CMPLX( ar_tr((ny+1)/2,i,k), 0.0_wp, KIND=wp )
 
                    jshape = SHAPE( cwork )
@@ -1172,6 +1142,6 @@
 
 !
-!--       Performing the fft with Temperton's software works on every system,
-!--       since it is part of the model
+!--       Performing the fft with Temperton's software works on every system, since it is part of
+!--       the model.
           IF ( forward_fft )  THEN
 
@@ -1361,9 +1331,7 @@
                    y_out(0) = CMPLX( ar_tr(0,i,k), 0.0_wp, KIND=wp )
                    DO  j = 1, (ny+1)/2 - 1
-                      y_out(j) = CMPLX( ar_tr(j,i,k), ar_tr(ny+1-j,i,k),       &
-                                        KIND=wp )
-                   ENDDO
-                   y_out((ny+1)/2) = CMPLX( ar_tr((ny+1)/2,i,k), 0.0_wp,       &
-                                            KIND=wp )
+                      y_out(j) = CMPLX( ar_tr(j,i,k), ar_tr(ny+1-j,i,k), KIND=wp )
+                   ENDDO
+                   y_out((ny+1)/2) = CMPLX( ar_tr((ny+1)/2,i,k), 0.0_wp, KIND=wp )
 
                    CALL FFTW_EXECUTE_DFT_C2R( plan_yi, y_out, y_in )
@@ -1387,6 +1355,5 @@
                 DO  i = nxl_y_l, nxr_y_l
 
-                   CALL DRCFT( 0, ar, 1, work, 1, ny+1, 1, 1, sqr_dny, auy1,   & 
-                               nau1, auy2, nau2 )
+                   CALL DRCFT( 0, ar, 1, work, 1, ny+1, 1, 1, sqr_dny, auy1, nau1, auy2, nau2 )
 
                    DO  j = 0, (ny+1)/2
@@ -1417,6 +1384,5 @@
                    work(ny+2) = 0.0_wp
 
-                   CALL DCRFT( 0, work, 1, work, 1, ny+1, 1, -1, sqr_dny,      &
-                               auy3, nau1, auy4, nau2 )
+                   CALL DCRFT( 0, work, 1, work, 1, ny+1, 1, -1, sqr_dny, auy3, nau1, auy4, nau2 )
 
                    DO  j = 0, ny
@@ -1491,5 +1457,5 @@
 
                    DO  j = 0, (ny+1)/2
-                      ar(j,i,k)      = REAL( ar_tmp(j,i,k), KIND=wp )  * dny
+                      ar(j,i,k)      = REAL( ar_tmp(j,i,k), KIND=wp ) * dny
                    ENDDO
 
@@ -1511,9 +1477,7 @@
 
                    DO  j = 1, (ny+1)/2 - 1
-                      ar_tmp(j,i,k) = CMPLX( ar(j,i,k), ar(ny+1-j,i,k),        &
-                                             KIND=wp )
-                   ENDDO
-                   ar_tmp((ny+1)/2,i,k) = CMPLX( ar((ny+1)/2,i,k), 0.0_wp,     &
-                                                 KIND=wp )
+                      ar_tmp(j,i,k) = CMPLX( ar(j,i,k), ar(ny+1-j,i,k), KIND=wp )
+                   ENDDO
+                   ar_tmp((ny+1)/2,i,k) = CMPLX( ar((ny+1)/2,i,k), 0.0_wp, KIND=wp )
 
                 ENDDO
@@ -1532,13 +1496,13 @@
     END SUBROUTINE fft_y
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Fourier-transformation along y-direction.
 !> Version for 1D-decomposition.
-!> It uses internal algorithms (Singleton or Temperton) or
-!> system-specific routines, if they are available.
-!------------------------------------------------------------------------------!
- 
+!> It uses internal algorithms (Singleton or Temperton) or system-specific routines, if they are
+!> available.
+!--------------------------------------------------------------------------------------------------!
+
     SUBROUTINE fft_y_1d( ar, direction )
 
@@ -1547,5 +1511,5 @@
 
        CHARACTER (LEN=*) ::  direction
-       
+
        INTEGER(iwp) ::  j          !<
        INTEGER(iwp) ::  jshape(1)  !<
@@ -1556,7 +1520,7 @@
        REAL(wp), DIMENSION(0:ny+2)  ::  work   !<
        REAL(wp), DIMENSION(ny+2)    ::  work1  !<
-       
+
        COMPLEX(wp), DIMENSION(:), ALLOCATABLE ::  cwork  !<
-       
+
 #if defined( __ibm )
        REAL(wp), DIMENSION(nau2) ::  auy2  !<
@@ -1575,6 +1539,6 @@
 
 !
-!--       Performing the fft with singleton's software works on every system,
-!--       since it is part of the model
+!--       Performing the fft with singleton's software works on every system, since it is part of
+!--       the model.
           ALLOCATE( cwork(0:ny) )
 
@@ -1618,6 +1582,6 @@
 
 !
-!--       Performing the fft with Temperton's software works on every system,
-!--       since it is part of the model
+!--       Performing the fft with Temperton's software works on every system, since it is part of
+!--       the model.
           IF ( forward_fft )  THEN
 
@@ -1682,6 +1646,5 @@
           IF ( forward_fft )  THEN
 
-             CALL DRCFT( 0, ar, 1, work, 1, ny+1, 1, 1, sqr_dny, auy1, nau1,   &
-                         auy2, nau2 )
+             CALL DRCFT( 0, ar, 1, work, 1, ny+1, 1, 1, sqr_dny, auy1, nau1, auy2, nau2 )
 
              DO  j = 0, (ny+1)/2
@@ -1703,6 +1666,5 @@
              work(ny+2) = 0.0_wp
 
-             CALL DCRFT( 0, work, 1, work, 1, ny+1, 1, -1, sqr_dny, auy3,      &
-                         nau1, auy4, nau2 )
+             CALL DCRFT( 0, work, 1, work, 1, ny+1, 1, -1, sqr_dny, auy3, nau1, auy4, nau2 )
 
              DO  j = 0, ny
@@ -1747,13 +1709,13 @@
     END SUBROUTINE fft_y_1d
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Fourier-transformation along x-direction.
-!> Version for 1d domain decomposition
+!> Version for 1d domain decomposition,
 !> using multiple 1D FFT from Math Keisan on NEC or Temperton-algorithm
-!> (no singleton-algorithm on NEC because it does not vectorize)
-!------------------------------------------------------------------------------!
- 
+!> (no singleton-algorithm on NEC because it does not vectorize).
+!--------------------------------------------------------------------------------------------------!
+
     SUBROUTINE fft_x_m( ar, direction )
 
@@ -1762,5 +1724,5 @@
 
        CHARACTER (LEN=*) ::  direction  !<
-       
+
        INTEGER(iwp) ::  i     !<
        INTEGER(iwp) ::  k     !<
@@ -1773,5 +1735,5 @@
        REAL(wp), DIMENSION(0:nx+3,nz+1)   ::  ai     !<
        REAL(wp), DIMENSION(6*(nx+4),nz+1) ::  work1  !<
-       
+
 #if defined( __nec_fft )
        COMPLEX(wp), DIMENSION(:,:), ALLOCATABLE ::  work
@@ -1827,8 +1789,7 @@
 
 !
-!--          Tables are initialized once more. This call should not be
-!--          necessary, but otherwise program aborts in asymmetric case
-             CALL DZFFTM( 0, nx+1, nz1, sqr_dnx, work, nx+4, work, nx+4,       &
-                          trig_xf, work1, 0 )
+!--          Tables are initialized once more. This call should not be necessary, but otherwise
+!--          program aborts in asymmetric case.
+             CALL DZFFTM( 0, nx+1, nz1, sqr_dnx, work, nx+4, work, nx+4, trig_xf, work1, 0 )
 
              ai(0:nx,1:nz) = ar(0:nx,1:nz)
@@ -1837,6 +1798,5 @@
              ENDIF
 
-             CALL DZFFTM( 1, nx+1, nz1, sqr_dnx, ai, siza, work, sizw,         &
-                          trig_xf, work1, 0 )
+             CALL DZFFTM( 1, nx+1, nz1, sqr_dnx, ai, siza, work, sizw, trig_xf, work1, 0 )
 
              DO  k = 1, nz
@@ -1854,6 +1814,5 @@
 !--          Tables are initialized once more. This call should not be
 !--          necessary, but otherwise program aborts in asymmetric case
-             CALL ZDFFTM( 0, nx+1, nz1, sqr_dnx, work, nx+4, work, nx+4,       &
-                          trig_xb, work1, 0 )
+             CALL ZDFFTM( 0, nx+1, nz1, sqr_dnx, work, nx+4, work, nx+4, trig_xb, work1, 0 )
 
              IF ( nz1 > nz )  THEN
@@ -1868,6 +1827,5 @@
              ENDDO
 
-             CALL ZDFFTM( -1, nx+1, nz1, sqr_dnx, work, sizw, ai, siza, &
-                          trig_xb, work1, 0 )
+             CALL ZDFFTM( -1, nx+1, nz1, sqr_dnx, work, sizw, ai, siza, trig_xb, work1, 0 )
 
              ar(0:nx,1:nz) = ai(0:nx,1:nz)
@@ -1882,13 +1840,13 @@
     END SUBROUTINE fft_x_m
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Fourier-transformation along y-direction.
-!> Version for 1d domain decomposition
+!> Version for 1d domain decomposition,
 !> using multiple 1D FFT from Math Keisan on NEC or Temperton-algorithm
-!> (no singleton-algorithm on NEC because it does not vectorize)
-!------------------------------------------------------------------------------!
- 
+!> (no singleton-algorithm on NEC because it does not vectorize).
+!--------------------------------------------------------------------------------------------------!
+
     SUBROUTINE fft_y_m( ar, ny1, direction )
 
@@ -1897,6 +1855,6 @@
 
        CHARACTER (LEN=*) ::  direction  !<
-       
-       INTEGER(iwp) ::  j     !< 
+
+       INTEGER(iwp) ::  j     !<
        INTEGER(iwp) ::  k     !<
        INTEGER(iwp) ::  ny1   !<
@@ -1964,8 +1922,7 @@
 
 !
-!--          Tables are initialized once more. This call should not be
-!--          necessary, but otherwise program aborts in asymmetric case
-             CALL DZFFTM( 0, ny+1, nz1, sqr_dny, work, ny+4, work, ny+4, &
-                          trig_yf, work1, 0 )
+!--          Tables are initialized once more. This call should not be necessary, but otherwise
+!--          program aborts in asymmetric case.
+             CALL DZFFTM( 0, ny+1, nz1, sqr_dny, work, ny+4, work, ny+4, trig_yf, work1, 0 )
 
              ai(0:ny,1:nz) = ar(0:ny,1:nz)
@@ -1974,6 +1931,5 @@
              ENDIF
 
-             CALL DZFFTM( 1, ny+1, nz1, sqr_dny, ai, siza, work, sizw, &
-                          trig_yf, work1, 0 )
+             CALL DZFFTM( 1, ny+1, nz1, sqr_dny, ai, siza, work, sizw, trig_yf, work1, 0 )
 
              DO  k = 1, nz
@@ -1989,8 +1945,7 @@
 
 !
-!--          Tables are initialized once more. This call should not be
-!--          necessary, but otherwise program aborts in asymmetric case
-             CALL ZDFFTM( 0, ny+1, nz1, sqr_dny, work, ny+4, work, ny+4, &
-                          trig_yb, work1, 0 )
+!--          Tables are initialized once more. This call should not be necessary, but otherwise
+!--          program aborts in asymmetric case.
+             CALL ZDFFTM( 0, ny+1, nz1, sqr_dny, work, ny+4, work, ny+4, trig_yb, work1, 0 )
 
              IF ( nz1 > nz )  THEN
@@ -2005,6 +1960,5 @@
              ENDDO
 
-             CALL ZDFFTM( -1, ny+1, nz1, sqr_dny, work, sizw, ai, siza, &
-                          trig_yb, work1, 0 )
+             CALL ZDFFTM( -1, ny+1, nz1, sqr_dny, work, sizw, ai, siza, trig_yb, work1, 0 )
 
              ar(0:ny,1:nz) = ai(0:ny,1:nz)
Index: palm/trunk/SOURCE/flow_statistics.f90
===================================================================
--- palm/trunk/SOURCE/flow_statistics.f90	(revision 4645)
+++ palm/trunk/SOURCE/flow_statistics.f90	(revision 4646)
@@ -1,39 +1,41 @@
 !> @file flow_statistics.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! ------------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4581 2020-06-29 08:49:58Z suehring
 ! Formatting adjustment
-! 
+!
 ! 4551 2020-06-02 10:22:25Z suehring
 ! Bugfix in summation for statistical regions
-! 
+!
 ! 4521 2020-05-06 11:39:49Z schwenkel
 ! Rename variable
-! 
+!
 ! 4502 2020-04-17 16:14:16Z schwenkel
 ! Implementation of ice microphysics
-! 
+!
 ! 4472 2020-03-24 12:21:00Z Giersch
 ! Calculations of the Kolmogorov lengt scale eta implemented
@@ -43,6 +45,5 @@
 !
 ! 4463 2020-03-17 09:27:36Z Giersch
-! Calculate horizontally averaged profiles of all velocity components at the
-! same place
+! Calculate horizontally averaged profiles of all velocity components at the same place
 !
 ! 4444 2020-03-05 15:59:50Z raasch
@@ -50,10 +51,9 @@
 !
 ! 4442 2020-03-04 19:21:13Z suehring
-! Change order of dimension in surface array %frac to allow for better
-! vectorization.
+! Change order of dimension in surface array %frac to allow for better vectorization.
 !
 ! 4441 2020-03-04 19:20:35Z suehring
-! Introduction of wall_flags_total_0, which currently sets bits based on static
-! topography information used in wall_flags_static_0
+! Introduction of wall_flags_total_0, which currently sets bits based on static topography
+! information used in wall_flags_static_0
 !
 ! 4329 2019-12-10 15:46:36Z motisi
@@ -67,6 +67,5 @@
 !
 ! 4039 2019-06-18 10:32:41Z suehring
-! Correct conversion to kinematic scalar fluxes in case of pw-scheme and
-! statistic regions
+! Correct conversion to kinematic scalar fluxes in case of pw-scheme and statistic regions
 !
 ! 3828 2019-03-27 19:36:23Z raasch
@@ -82,54 +81,50 @@
 ! Description:
 ! ------------
-!> Compute average profiles and further average flow quantities for the different
-!> user-defined (sub-)regions. The region indexed 0 is the total model domain.
+!> Compute average profiles and further average flow quantities for the different user-defined
+!> (sub-)regions. The region indexed 0 is the total model domain.
 !>
-!> @note For simplicity, nzb_s_inner and nzb_diff_s_inner are being used as a
-!>       lower vertical index for k-loops for all variables, although strictly
-!>       speaking the k-loops would have to be split up according to the staggered
-!>       grid. However, this implies no error since staggered velocity components
-!>       are zero at the walls and inside buildings.
-!------------------------------------------------------------------------------!
+!> @note For simplicity, nzb_s_inner and nzb_diff_s_inner are used as a lower vertical index for
+!>       k-loops for all variables, although strictly speaking the k-loops would have to be split
+!>       up according to the staggered grid. However, this implies no error since staggered velocity
+!>       components are zero at the walls and inside buildings.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE flow_statistics
 
 
-    USE arrays_3d,                                                             &
-        ONLY:  ddzu, ddzw, e, heatflux_output_conversion, hyp, km, kh,         &
-               momentumflux_output_conversion, nc, ni, nr, p, prho, prr, pt, q,&
-               qc, qi, ql, qr, rho_air, rho_air_zw, rho_ocean, s,              &
-               sa, u, ug, v, vg, vpt, w, w_subs, waterflux_output_conversion,  &
-               zw, d_exner
-
-    USE basic_constants_and_equations_mod,                                     &
+    USE arrays_3d,                                                                                 &
+        ONLY:  ddzu, ddzw, d_exner, e, heatflux_output_conversion, hyp, km, kh,                    &
+               momentumflux_output_conversion, nc, ni, nr, p, prho, prr, pt, q, qc, qi, ql, qr,    &
+               rho_air, rho_air_zw, rho_ocean, s, sa, u, ug, v, vg, vpt, w, w_subs,                &
+               waterflux_output_conversion, zw
+
+    USE basic_constants_and_equations_mod,                                                         &
         ONLY:  g, lv_d_cp
 
-    USE bulk_cloud_model_mod,                                                  &
-        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert,   &
-              microphysics_ice_phase
-
-    USE chem_modules,                                                          &
+    USE bulk_cloud_model_mod,                                                                      &
+        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert, microphysics_ice_phase
+
+    USE chem_modules,                                                                              &
         ONLY:  max_pr_cs
 
-    USE control_parameters,                                                    &
-        ONLY:   air_chemistry, average_count_pr, cloud_droplets, do_sum,       &
-                dt_3d, humidity, initializing_actions, kolmogorov_length_scale,&
-                land_surface, large_scale_forcing, large_scale_subsidence,     &
-                max_pr_user, message_string, neutral, ocean_mode,              &
-                passive_scalar, simulated_time, simulated_time_at_begin,       &
-                use_subsidence_tendencies, use_surface_fluxes, use_top_fluxes, &
-                ws_scheme_mom, ws_scheme_sca, salsa, max_pr_salsa
-
-    USE cpulog,                                                                &
+    USE control_parameters,                                                                        &
+        ONLY:   air_chemistry, average_count_pr, cloud_droplets, do_sum, dt_3d, humidity,          &
+                initializing_actions, kolmogorov_length_scale, land_surface, large_scale_forcing,  &
+                large_scale_subsidence, max_pr_salsa, max_pr_user, message_string, neutral,        &
+                ocean_mode, passive_scalar, salsa, simulated_time, simulated_time_at_begin,        &
+                use_subsidence_tendencies, use_surface_fluxes, use_top_fluxes, ws_scheme_mom,      &
+                ws_scheme_sca
+
+    USE cpulog,                                                                                    &
         ONLY:   cpu_log, log_point
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                                            &
         ONLY:   ddx, ddy
 
-    USE indices,                                                               &
-        ONLY:   ngp_2dh, ngp_2dh_s_inner, ngp_3d, ngp_3d_inner, nxl, nxr, nyn, &
-                nys, nzb, nzt, topo_min_level, wall_flags_total_0
+    USE indices,                                                                                   &
+        ONLY:   ngp_2dh, ngp_2dh_s_inner, ngp_3d, ngp_3d_inner, nxl, nxr, nyn, nys, nzb, nzt,      &
+                topo_min_level, wall_flags_total_0
 
 #if defined( __parallel )
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  ngp_sums, ngp_sums_ls
 #endif
@@ -137,26 +132,26 @@
     USE kinds
 
-    USE land_surface_model_mod,                                                &
+    USE land_surface_model_mod,                                                                    &
         ONLY:   m_soil_h, nzb_soil, nzt_soil, t_soil_h
 
-    USE lsf_nudging_mod,                                                       &
+    USE lsf_nudging_mod,                                                                           &
         ONLY:   td_lsa_lpt, td_lsa_q, td_sub_lpt, td_sub_q, time_vert
 
-    USE module_interface,                                                      &
+    USE module_interface,                                                                          &
         ONLY:  module_interface_statistics
 
-    USE netcdf_interface,                                                      &
+    USE netcdf_interface,                                                                          &
         ONLY:  dots_rad, dots_soil, dots_max
 
     USE pegrid
 
-    USE radiation_model_mod,                                                   &
-        ONLY:  radiation, radiation_scheme,                                    &
-               rad_lw_in, rad_lw_out, rad_lw_cs_hr, rad_lw_hr,                 &
+    USE radiation_model_mod,                                                                       &
+        ONLY:  radiation, radiation_scheme,                                                        &
+               rad_lw_in, rad_lw_out, rad_lw_cs_hr, rad_lw_hr,                                     &
                rad_sw_in, rad_sw_out, rad_sw_cs_hr, rad_sw_hr
 
     USE statistics
 
-    USE surface_mod,                                                           &
+    USE surface_mod,                                                                               &
         ONLY :  surf_def_h, surf_lsm_h, surf_usm_h
 
@@ -215,14 +210,14 @@
     REAL(wp) ::  sums_ll(nzb:nzt+1,2)  !<
 
+
     CALL cpu_log( log_point(10), 'flow_statistics', 'start' )
 
 
 !
-!-- To be on the safe side, check whether flow_statistics has already been
-!-- called once after the current time step
+!-- To be on the safe side, check whether flow_statistics has already been called once after the
+!-- current time step.
     IF ( flow_statistics_called )  THEN
 
-       message_string = 'flow_statistics is called two times within one ' // &
-                        'timestep'
+       message_string = 'flow_statistics is called two times within one ' // 'timestep'
        CALL message( 'flow_statistics', 'PA0190', 1, 2, 0, 6, 0 )
 
@@ -243,9 +238,8 @@
 
 !
-!--    Store sums that have been computed in other subroutines in summation
-!--    array
+!--    Store sums that have been computed in other subroutines in summation array
        sums_l(:,11,:) = sums_l_l(:,sr,:)      ! mixing length from diffusivities
 !--    WARNING: next line still has to be adjusted for OpenMP
-       sums_l(:,21,0) = sums_wsts_bc_l(:,sr) *                                 &
+       sums_l(:,21,0) = sums_wsts_bc_l(:,sr) *                                                     &
                         heatflux_output_conversion  ! heat flux from advec_s_bc
        sums_l(nzb+9,pr_palm,0)  = sums_divold_l(sr)  ! old divergence from pres
@@ -253,23 +247,21 @@
 
 !
-!--    When calcuating horizontally-averaged total (resolved- plus subgrid-
-!--    scale) vertical fluxes and velocity variances by using commonly-
-!--    applied Reynolds-based methods ( e.g. <w'pt'> = (w-<w>)*(pt-<pt>) )
-!--    in combination with the 5th order advection scheme, pronounced
-!--    artificial kinks could be observed in the vertical profiles near the
-!--    surface. Please note: these kinks were not related to the model truth,
-!--    i.e. these kinks are just related to an evaluation problem.
-!--    In order avoid these kinks, vertical fluxes and horizontal as well
-!--    vertical velocity variances are calculated directly within the advection
-!--    routines, according to the numerical discretization, to evaluate the
-!--    statistical quantities as they will appear within the prognostic
-!--    equations.
-!--    Copy the turbulent quantities, evaluated in the advection routines to
-!--    the local array sums_l() for further computations.
+!--    When calcuating horizontally-averaged total (resolved- plus subgrid-scale) vertical fluxes
+!--    and velocity variances by using commonly-applied Reynolds-based methods
+!--    ( e.g. <w'pt'> = (w-<w>)*(pt-<pt>) ) in combination with the 5th order advection scheme,
+!--    pronounced artificial kinks could be observed in the vertical profiles near the surface.
+!--    Please note: these kinks were not related to the model truth, i.e. these kinks are just
+!--    related to an evaluation problem.
+!--    In order avoid these kinks, vertical fluxes and horizontal as well vertical velocity
+!--    variances are calculated directly within the advection routines, according to the numerical
+!--    discretization, to evaluate the statistical quantities as they will appear within the
+!--    prognostic equations.
+!--    Copy the turbulent quantities, evaluated in the advection routines to the local array
+!--    sums_l() for further computations.
        IF ( ws_scheme_mom .AND. sr == 0 )  THEN
 
 !
-!--       According to the Neumann bc for the horizontal velocity components,
-!--       the corresponding fluxes has to satisfiy the same bc.
+!--       According to the Neumann bc for the horizontal velocity components, the corresponding
+!--       fluxes has to satisfiy the same bc.
           IF ( ocean_mode )  THEN
              sums_us2_ws_l(nzt+1,:) = sums_us2_ws_l(nzt,:)
@@ -280,14 +272,11 @@
 !
 !--          Swap the turbulent quantities evaluated in advec_ws.
-             sums_l(:,13,i) = sums_wsus_ws_l(:,i)                              &
-                              * momentumflux_output_conversion ! w*u*
-             sums_l(:,15,i) = sums_wsvs_ws_l(:,i)                              &
-                              * momentumflux_output_conversion ! w*v*
-             sums_l(:,30,i) = sums_us2_ws_l(:,i)        ! u*2
-             sums_l(:,31,i) = sums_vs2_ws_l(:,i)        ! v*2
-             sums_l(:,32,i) = sums_ws2_ws_l(:,i)        ! w*2
-             sums_l(:,34,i) = sums_l(:,34,i) + 0.5_wp *                        &
-                              ( sums_us2_ws_l(:,i) + sums_vs2_ws_l(:,i) +      &
-                                sums_ws2_ws_l(:,i) )    ! e*
+             sums_l(:,13,i) = sums_wsus_ws_l(:,i) * momentumflux_output_conversion ! w*u*
+             sums_l(:,15,i) = sums_wsvs_ws_l(:,i) * momentumflux_output_conversion ! w*v*
+             sums_l(:,30,i) = sums_us2_ws_l(:,i)                                   ! u*2
+             sums_l(:,31,i) = sums_vs2_ws_l(:,i)                                   ! v*2
+             sums_l(:,32,i) = sums_ws2_ws_l(:,i)                                   ! w*2
+             sums_l(:,34,i) = sums_l(:,34,i) + 0.5_wp *                                            &
+                              ( sums_us2_ws_l(:,i) + sums_vs2_ws_l(:,i) + sums_ws2_ws_l(:,i) )  ! e*
           ENDDO
 
@@ -297,10 +286,10 @@
 
           DO  i = 0, threads_per_task-1
-             sums_l(:,17,i)                        = sums_wspts_ws_l(:,i)      &
-                                           * heatflux_output_conversion  ! w*pt*
-             IF ( ocean_mode     ) sums_l(:,66,i)  = sums_wssas_ws_l(:,i) ! w*sa*
-             IF ( humidity       ) sums_l(:,49,i)  = sums_wsqs_ws_l(:,i)       &
-                                           * waterflux_output_conversion  ! w*q*
-             IF ( passive_scalar ) sums_l(:,114,i) = sums_wsss_ws_l(:,i)  ! w*s*
+             sums_l(:,17,i)                        = sums_wspts_ws_l(:,i)                          &
+                                                     * heatflux_output_conversion   ! w*pt*
+             IF ( ocean_mode     ) sums_l(:,66,i)  = sums_wssas_ws_l(:,i)           ! w*sa*
+             IF ( humidity       ) sums_l(:,49,i)  = sums_wsqs_ws_l(:,i)                           &
+                                                     * waterflux_output_conversion  ! w*q*
+             IF ( passive_scalar ) sums_l(:,114,i) = sums_wsss_ws_l(:,i)            ! w*s*
           ENDDO
 
@@ -308,6 +297,6 @@
 !
 !--    Horizontally averaged profiles of horizontal velocities and temperature.
-!--    They must have been computed before, because they are already required
-!--    for other horizontal averages.
+!--    They must have been computed before, because they are already required for other horizontal
+!--    averages.
        tn = 0
        !$OMP PARALLEL PRIVATE( i, j, k, tn, flag )
@@ -321,12 +310,9 @@
                 flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 22 ) )
                 !$ACC ATOMIC
-                sums_l(k,1,tn)  = sums_l(k,1,tn)  + u(k,j,i)  * rmask(j,i,sr)  &
-                                                              * flag
-                !$ACC ATOMIC
-                sums_l(k,2,tn)  = sums_l(k,2,tn)  + v(k,j,i)  * rmask(j,i,sr)  &
-                                                              * flag
-                !$ACC ATOMIC
-                sums_l(k,4,tn)  = sums_l(k,4,tn)  + pt(k,j,i) * rmask(j,i,sr)  &
-                                                              * flag
+                sums_l(k,1,tn)  = sums_l(k,1,tn)  + u(k,j,i)  * rmask(j,i,sr) * flag
+                !$ACC ATOMIC
+                sums_l(k,2,tn)  = sums_l(k,2,tn)  + v(k,j,i)  * rmask(j,i,sr) * flag
+                !$ACC ATOMIC
+                sums_l(k,4,tn)  = sums_l(k,4,tn)  + pt(k,j,i) * rmask(j,i,sr) * flag
              ENDDO
           ENDDO
@@ -341,8 +327,8 @@
              DO  j =  nys, nyn
                 DO  k = nzb, nzt+1
-                   sums_l(k,23,tn)  = sums_l(k,23,tn) + sa(k,j,i)              &
-                                    * rmask(j,i,sr)                            &
-                                    * MERGE( 1.0_wp, 0.0_wp,                   &
-                                             BTEST( wall_flags_total_0(k,j,i), 22 ) )
+                   sums_l(k,23,tn)  = sums_l(k,23,tn) + sa(k,j,i)                                  &
+                                      * rmask(j,i,sr)                                              &
+                                      * MERGE( 1.0_wp, 0.0_wp,                                     &
+                                               BTEST( wall_flags_total_0(k,j,i), 22 ) )
                 ENDDO
              ENDDO
@@ -351,7 +337,6 @@
 
 !
-!--    Horizontally averaged profiles of virtual potential temperature,
-!--    total water content, water vapor mixing ratio and liquid water potential
-!--    temperature
+!--    Horizontally averaged profiles of virtual potential temperature, total water content, water
+!--    vapor mixing ratio and liquid water potential temperature
        IF ( humidity )  THEN
           !$OMP DO
@@ -360,8 +345,6 @@
                 DO  k = nzb, nzt+1
                    flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 22 ) )
-                   sums_l(k,44,tn)  = sums_l(k,44,tn) +                        &
-                                      vpt(k,j,i) * rmask(j,i,sr) * flag
-                   sums_l(k,41,tn)  = sums_l(k,41,tn) +                        &
-                                      q(k,j,i) * rmask(j,i,sr)   * flag
+                   sums_l(k,44,tn)  = sums_l(k,44,tn) + vpt(k,j,i) * rmask(j,i,sr) * flag
+                   sums_l(k,41,tn)  = sums_l(k,41,tn) + q(k,j,i) * rmask(j,i,sr)   * flag
                 ENDDO
              ENDDO
@@ -374,10 +357,8 @@
                       flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 22 ) )
                       sums_l(k,42,tn) = sums_l(k,42,tn) +                      &
-                                      ( q(k,j,i) - ql(k,j,i) ) * rmask(j,i,sr) &
-                                                               * flag
-                      sums_l(k,43,tn) = sums_l(k,43,tn) + (                    &
-                                      pt(k,j,i) + lv_d_cp * d_exner(k) * ql(k,j,i) &
-                                                          ) * rmask(j,i,sr)    &
-                                                            * flag
+                                        ( q(k,j,i) - ql(k,j,i) ) * rmask(j,i,sr) * flag
+                      sums_l(k,43,tn) = sums_l(k,43,tn) + (                                        &
+                                           pt(k,j,i) + lv_d_cp * d_exner(k) * ql(k,j,i)            &
+                                                          ) * rmask(j,i,sr) * flag
                    ENDDO
                 ENDDO
@@ -393,8 +374,8 @@
              DO  j =  nys, nyn
                 DO  k = nzb, nzt+1
-                   sums_l(k,115,tn)  = sums_l(k,115,tn) + s(k,j,i)             &
-                                    * rmask(j,i,sr)                            &
-                                    * MERGE( 1.0_wp, 0.0_wp,                   &
-                                             BTEST( wall_flags_total_0(k,j,i), 22 ) )
+                   sums_l(k,115,tn)  = sums_l(k,115,tn) + s(k,j,i)                                 &
+                                       * rmask(j,i,sr)                                             &
+                                       * MERGE( 1.0_wp, 0.0_wp,                                    &
+                                                BTEST( wall_flags_total_0(k,j,i), 22 ) )
                 ENDDO
              ENDDO
@@ -430,31 +411,31 @@
 !--    Compute total sum from local sums
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( sums_l(nzb,1,0), sums(nzb,1), nzt+2-nzb, MPI_REAL,  &
-                           MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( sums_l(nzb,1,0), sums(nzb,1), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,     &
+                           ierr )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( sums_l(nzb,2,0), sums(nzb,2), nzt+2-nzb, MPI_REAL,  &
-                           MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( sums_l(nzb,2,0), sums(nzb,2), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,     &
+                           ierr )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( sums_l(nzb,4,0), sums(nzb,4), nzt+2-nzb, MPI_REAL,  &
-                           MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( sums_l(nzb,4,0), sums(nzb,4), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,     &
+                           ierr )
        IF ( ocean_mode )  THEN
           IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-          CALL MPI_ALLREDUCE( sums_l(nzb,23,0), sums(nzb,23), nzt+2-nzb,       &
-                              MPI_REAL, MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( sums_l(nzb,23,0), sums(nzb,23), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,&
+                              ierr )
        ENDIF
        IF ( humidity ) THEN
           IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-          CALL MPI_ALLREDUCE( sums_l(nzb,44,0), sums(nzb,44), nzt+2-nzb,       &
-                              MPI_REAL, MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( sums_l(nzb,44,0), sums(nzb,44), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,&
+                              ierr )
           IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-          CALL MPI_ALLREDUCE( sums_l(nzb,41,0), sums(nzb,41), nzt+2-nzb,       &
-                              MPI_REAL, MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( sums_l(nzb,41,0), sums(nzb,41), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,&
+                              ierr )
           IF ( bulk_cloud_model ) THEN
              IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-             CALL MPI_ALLREDUCE( sums_l(nzb,42,0), sums(nzb,42), nzt+2-nzb,    &
-                                 MPI_REAL, MPI_SUM, comm2d, ierr )
+             CALL MPI_ALLREDUCE( sums_l(nzb,42,0), sums(nzb,42), nzt+2-nzb, MPI_REAL, MPI_SUM,     &
+                                 comm2d, ierr )
              IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-             CALL MPI_ALLREDUCE( sums_l(nzb,43,0), sums(nzb,43), nzt+2-nzb,    &
-                                 MPI_REAL, MPI_SUM, comm2d, ierr )
+             CALL MPI_ALLREDUCE( sums_l(nzb,43,0), sums(nzb,43), nzt+2-nzb, MPI_REAL, MPI_SUM,     &
+                                 comm2d, ierr )
           ENDIF
        ENDIF
@@ -462,6 +443,6 @@
        IF ( passive_scalar )  THEN
           IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-          CALL MPI_ALLREDUCE( sums_l(nzb,115,0), sums(nzb,115), nzt+2-nzb,       &
-                              MPI_REAL, MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( sums_l(nzb,115,0), sums(nzb,115), nzt+2-nzb, MPI_REAL, MPI_SUM,      &
+                              comm2d, ierr )
        ENDIF
 #else
@@ -482,6 +463,6 @@
 
 !
-!--    Final values are obtained by division by the total number of grid points
-!--    used for summation. After that store profiles.
+!--    Final values are obtained by division by the total number of grid points used for summation.
+!--    After that store profiles.
        sums(:,1) = sums(:,1) / ngp_2dh(sr)
        sums(:,2) = sums(:,2) / ngp_2dh(sr)
@@ -517,16 +498,14 @@
 !
 !--    Passive scalar
-       IF ( passive_scalar )  hom(:,1,115,sr) = sums(:,115) /                  &
-            ngp_2dh_s_inner(:,sr)                    ! s
-
-!
-!--    Horizontally averaged profiles of the remaining prognostic variables,
-!--    variances, the total and the perturbation energy (single values in last
-!--    column of sums_l) and some diagnostic quantities.
-!--    NOTE: for simplicity, nzb_s_inner is used below, although strictly
-!--    ----  speaking the following k-loop would have to be split up and
-!--          rearranged according to the staggered grid.
-!--          However, this implies no error since staggered velocity components
-!--          are zero at the walls and inside buildings.
+       IF ( passive_scalar )  hom(:,1,115,sr) = sums(:,115) / ngp_2dh_s_inner(:,sr)  ! s
+
+!
+!--    Horizontally averaged profiles of the remaining prognostic variables, variances, the total
+!--    and the perturbation energy (single values in last column of sums_l) and some diagnostic
+!--    quantities.
+!--    NOTE: for simplicity, nzb_s_inner is used below, although strictly speaking the following
+!--    ----  k-loop would have to be split up and rearranged according to the staggered grid.
+!--          However, this implies no error since staggered velocity components are zero at the
+!--          walls and inside buildings.
        tn = 0
        !$OMP PARALLEL PRIVATE( i, j, k, pts, sums_ll,                          &
@@ -554,34 +533,26 @@
 !--             Prognostic and diagnostic variables
                 !$ACC ATOMIC
-                sums_l(k,3,tn)  = sums_l(k,3,tn)  + w(k,j,i)  * rmask(j,i,sr)  &
-                                                              * flag
-                !$ACC ATOMIC
-                sums_l(k,8,tn)  = sums_l(k,8,tn)  + e(k,j,i)  * rmask(j,i,sr)  &
-                                                              * flag
-                !$ACC ATOMIC
-                sums_l(k,9,tn)  = sums_l(k,9,tn)  + km(k,j,i) * rmask(j,i,sr)  &
-                                                              * flag
-                !$ACC ATOMIC
-                sums_l(k,10,tn) = sums_l(k,10,tn) + kh(k,j,i) * rmask(j,i,sr)  &
-                                                              * flag
-                !$ACC ATOMIC
-                sums_l(k,40,tn) = sums_l(k,40,tn) + ( p(k,j,i)                 &
-                                         / momentumflux_output_conversion(k) ) &
-                                                              * flag
+                sums_l(k,3,tn)  = sums_l(k,3,tn)  + w(k,j,i)  * rmask(j,i,sr) * flag
+                !$ACC ATOMIC
+                sums_l(k,8,tn)  = sums_l(k,8,tn)  + e(k,j,i)  * rmask(j,i,sr) * flag
+                !$ACC ATOMIC
+                sums_l(k,9,tn)  = sums_l(k,9,tn)  + km(k,j,i) * rmask(j,i,sr) * flag
+                !$ACC ATOMIC
+                sums_l(k,10,tn) = sums_l(k,10,tn) + kh(k,j,i) * rmask(j,i,sr) * flag
+                !$ACC ATOMIC
+                sums_l(k,40,tn) = sums_l(k,40,tn) + ( p(k,j,i)                                     &
+                                         / momentumflux_output_conversion(k) ) * flag
 
                 !$ACC ATOMIC
                 sums_l(k,33,tn) = sums_l(k,33,tn) + &
-                                  ( pt(k,j,i)-hom(k,1,4,sr) )**2 * rmask(j,i,sr)&
-                                                                 * flag
+                                  ( pt(k,j,i)-hom(k,1,4,sr) )**2 * rmask(j,i,sr) * flag
 #ifndef _OPENACC
                 IF ( humidity )  THEN
-                   sums_l(k,70,tn) = sums_l(k,70,tn) + &
-                                  ( q(k,j,i)-hom(k,1,41,sr) )**2 * rmask(j,i,sr)&
-                                                                 * flag
+                   sums_l(k,70,tn) = sums_l(k,70,tn) +                                             &
+                                     ( q(k,j,i)-hom(k,1,41,sr) )**2 * rmask(j,i,sr) * flag
                 ENDIF
                 IF ( passive_scalar )  THEN
-                   sums_l(k,116,tn) = sums_l(k,116,tn) + &
-                                  ( s(k,j,i)-hom(k,1,115,sr) )**2 * rmask(j,i,sr)&
-                                                                  * flag
+                   sums_l(k,116,tn) = sums_l(k,116,tn) +                                           &
+                                      ( s(k,j,i)-hom(k,1,115,sr) )**2 * rmask(j,i,sr) * flag
                 ENDIF
 #endif
@@ -590,15 +561,12 @@
 !--             (Computation of the skewness of w further below)
                 !$ACC ATOMIC
-                sums_l(k,38,tn) = sums_l(k,38,tn) + w(k,j,i)**3 * rmask(j,i,sr) &
-                                                                * flag
-
-                sums_l_etot  = sums_l_etot + &
-                                        0.5_wp * ( u(k,j,i)**2 + v(k,j,i)**2 +  &
-                                        w(k,j,i)**2 )            * rmask(j,i,sr)&
-                                                                 * flag
-
-!
-!--             Computation of the Kolmogorov length scale. Calculation is based
-!--             on gradients of the deviations from the horizontal mean.
+                sums_l(k,38,tn) = sums_l(k,38,tn) + w(k,j,i)**3 * rmask(j,i,sr) * flag
+
+                sums_l_etot  = sums_l_etot + 0.5_wp * ( u(k,j,i)**2 + v(k,j,i)**2 + w(k,j,i)**2 )  &
+                                             * rmask(j,i,sr) * flag
+
+!
+!--             Computation of the Kolmogorov length scale. Calculation is based on gradients of the
+!--             deviations from the horizontal mean.
 !--             Kolmogorov scale at the boundaries (k=0/z=0m and k=nzt+1) is set to zero.
                 IF ( kolmogorov_length_scale .AND. k /= nzb .AND. k /= nzt+1) THEN
@@ -607,50 +575,47 @@
 !
 !--                Calculate components of the fluctuating rate-of-strain tensor
-!--                (0.5*(del u'_i/del x_j + del u'_j/del x_i)) defined in the
-!--                center of each grid box.
-                   du_dx = ( ( u(k,j,i+1) - hom(k,1,1,sr) ) -                  &
+!--                (0.5*(del u'_i/del x_j + del u'_j/del x_i)) defined in the center of each grid
+!--                box.
+                   du_dx = ( ( u(k,j,i+1) - hom(k,1,1,sr) ) -                                      &
                              ( u(k,j,i) - hom(k,1,1,sr) ) ) * ddx
-                   du_dy = 0.25_wp * ddy *                                     &
-                           ( ( u(k,j+1,i) - hom(k,1,1,sr) ) -                  &
-                             ( u(k,j-1,i) - hom(k,1,1,sr) ) +                  &
-                             ( u(k,j+1,i+1) - hom(k,1,1,sr) ) -                &
+                   du_dy = 0.25_wp * ddy *                                                         &
+                           ( ( u(k,j+1,i) - hom(k,1,1,sr) ) -                                      &
+                             ( u(k,j-1,i) - hom(k,1,1,sr) ) +                                      &
+                             ( u(k,j+1,i+1) - hom(k,1,1,sr) ) -                                    &
                              ( u(k,j-1,i+1) - hom(k,1,1,sr) ) )
-                   du_dz = 0.25_wp * ( ( ( u(k+1,j,i) - hom(k+1,1,1,sr) ) -    &
-                                         ( u(k,j,i) - hom(k,1,1,sr) ) ) *      &
-                                        ddzu(k+1) +                            &
-                                       ( ( u(k,j,i) - hom(k,1,1,sr) ) -        &
-                                         ( u(k-1,j,i) - hom(k-1,1,1,sr) ) )*   &
-                                        ddzu(k) +                              &
-                                       ( ( u(k+1,j,i+1) - hom(k+1,1,1,sr) )-   &
-                                         ( u(k,j,i+1) - hom(k,1,1,sr) ) ) *    &
-                                        ddzu(k+1) +                            &
-                                       ( ( u(k,j,i+1) - hom(k,1,1,sr) ) -      &
-                                         ( u(k-1,j,i+1) - hom(k-1,1,1,sr) ) ) *&
-                                        ddzu(k) )
-
-                   dv_dx = 0.25_wp * ddx *                                     &
-                           ( ( v(k,j,i+1) - hom(k,1,2,sr) ) -                  &
-                             ( v(k,j,i-1) - hom(k,1,2,sr) ) +                  &
-                             ( v(k,j+1,i+1) - hom(k,1,2,sr) ) -                &
+                   du_dz = 0.25_wp * ( ( ( u(k+1,j,i) - hom(k+1,1,1,sr) ) -                        &
+                                         ( u(k,j,i) - hom(k,1,1,sr) ) ) *                          &
+                                       ddzu(k+1) +                                                 &
+                                       ( ( u(k,j,i) - hom(k,1,1,sr) ) -                            &
+                                         ( u(k-1,j,i) - hom(k-1,1,1,sr) ) ) *                      &
+                                       ddzu(k) +                                                   &
+                                       ( ( u(k+1,j,i+1) - hom(k+1,1,1,sr) ) -                      &
+                                         ( u(k,j,i+1) - hom(k,1,1,sr) ) ) *                        &
+                                       ddzu(k+1) +                                                 &
+                                       ( ( u(k,j,i+1) - hom(k,1,1,sr) ) -                          &
+                                         ( u(k-1,j,i+1) - hom(k-1,1,1,sr) ) ) *                    &
+                                       ddzu(k) )
+
+                   dv_dx = 0.25_wp * ddx *                                                         &
+                           ( ( v(k,j,i+1) - hom(k,1,2,sr) ) -                                      &
+                             ( v(k,j,i-1) - hom(k,1,2,sr) ) +                                      &
+                             ( v(k,j+1,i+1) - hom(k,1,2,sr) ) -                                    &
                              ( v(k,j+1,i-1) - hom(k,1,2,sr) ) )
-                   dv_dy = ( ( v(k,j+1,i) - hom(k,1,2,sr) ) -                  &
-                             ( v(k,j,i) - hom(k,1,2,sr) ) ) * ddy
-                   dv_dz = 0.25_wp * ( ( ( v(k+1,j,i) - hom(k+1,1,2,sr) ) -    &
-                                         ( v(k,j,i) - hom(k,1,2,sr) ) ) *      &
-                                        ddzu(k+1) +                            &
-                                       ( ( v(k,j,i) - hom(k,1,2,sr) ) -        &
-                                         ( v(k-1,j,i) - hom(k-1,1,2,sr) ) ) *  &
-                                        ddzu(k) +                              &
-                                       ( ( v(k+1,j+1,i) - hom(k+1,1,2,sr) ) -  &
-                                         ( v(k,j+1,i) - hom(k,1,2,sr) ) ) *    &
-                                        ddzu(k+1) +                            &
-                                       ( ( v(k,j+1,i) - hom(k,1,2,sr) ) -      &
-                                         ( v(k-1,j+1,i) - hom(k-1,1,2,sr) ) ) *&
-                                        ddzu(k) )
-
-                   dw_dx = 0.25_wp * ddx * ( w(k,j,i+1) - w(k,j,i-1) +         &
-                                             w(k-1,j,i+1) - w(k-1,j,i-1) )
-                   dw_dy = 0.25_wp * ddy * ( w(k,j+1,i) - w(k,j-1,i) +         &
-                                             w(k-1,j+1,i) - w(k-1,j-1,i) )
+                   dv_dy = ( ( v(k,j+1,i) - hom(k,1,2,sr) ) - ( v(k,j,i) - hom(k,1,2,sr) ) ) * ddy
+                   dv_dz = 0.25_wp * ( ( ( v(k+1,j,i) - hom(k+1,1,2,sr) ) -                        &
+                                         ( v(k,j,i) - hom(k,1,2,sr) ) ) *                          &
+                                       ddzu(k+1) +                                                 &
+                                       ( ( v(k,j,i) - hom(k,1,2,sr) ) -                            &
+                                         ( v(k-1,j,i) - hom(k-1,1,2,sr) ) ) *                      &
+                                       ddzu(k) +                                                   &
+                                       ( ( v(k+1,j+1,i) - hom(k+1,1,2,sr) ) -                      &
+                                         ( v(k,j+1,i) - hom(k,1,2,sr) ) ) *                        &
+                                       ddzu(k+1) +                                                 &
+                                       ( ( v(k,j+1,i) - hom(k,1,2,sr) ) -                          &
+                                         ( v(k-1,j+1,i) - hom(k-1,1,2,sr) ) ) *                    &
+                                       ddzu(k) )
+
+                   dw_dx = 0.25_wp * ddx * ( w(k,j,i+1) - w(k,j,i-1) + w(k-1,j,i+1) - w(k-1,j,i-1) )
+                   dw_dy = 0.25_wp * ddy * ( w(k,j+1,i) - w(k,j-1,i) + w(k-1,j+1,i) - w(k-1,j-1,i) )
                    dw_dz = ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k)
 
@@ -667,16 +632,14 @@
                    s33 = 0.5_wp * ( dw_dz + dw_dz )
 
-!--                Calculate 3D instantaneous energy dissipation rate after
-!--                Pope (2000): Turbulent flows, p.259. It is defined in the center
-!--                of each grid volume.
-                   dissipation = 2.0_wp * km(k,j,i) *                          &
-                                ( s11*s11 + s21*s21 + s31*s31 +                &
-                                 s12*s12 + s22*s22 + s32*s32 +                 &
-                                s13*s13 + s23*s23 + s33*s33 )
+!--                Calculate 3D instantaneous energy dissipation rate following Pope (2000):
+!--                Turbulent flows, p.259. It is defined in the center of each grid volume.
+                   dissipation = 2.0_wp * km(k,j,i) *                                              &
+                                ( s11*s11 + s21*s21 + s31*s31 +                                    &
+                                  s12*s12 + s22*s22 + s32*s32 +                                    &
+                                  s13*s13 + s23*s23 + s33*s33 )
                    eta         = ( km(k,j,i)**3.0_wp / ( dissipation+1.0E-12 ) )**(1.0_wp/4.0_wp)
 
                    !$ACC ATOMIC
-                   sums_l(k,121,tn) = sums_l(k,121,tn) + eta * rmask(j,i,sr)   &
-                                                                * flag
+                   sums_l(k,121,tn) = sums_l(k,121,tn) + eta * rmask(j,i,sr) * flag
 
 
@@ -685,35 +648,33 @@
              ENDDO !k-loop
 !
-!--          Total and perturbation energy for the total domain (being
-!--          collected in the last column of sums_l). Summation of these
-!--          quantities is seperated from the previous loop in order to
-!--          allow vectorization of that loop.
+!--          Total and perturbation energy for the total domain (being collected in the last column
+!--          of sums_l). Summation of these quantities is seperated from the previous loop in order
+!--          to allow vectorization of that loop.
              !$ACC ATOMIC
              sums_l(nzb+4,pr_palm,tn) = sums_l(nzb+4,pr_palm,tn) + sums_l_etot
 !
 !--          2D-arrays (being collected in the last column of sums_l)
-             IF ( surf_def_h(0)%end_index(j,i) >=                              &
-                  surf_def_h(0)%start_index(j,i) )  THEN
+             IF ( surf_def_h(0)%end_index(j,i) >= surf_def_h(0)%start_index(j,i) )  THEN
                 m = surf_def_h(0)%start_index(j,i)
                 !$ACC ATOMIC
-                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +            &
-                                        surf_def_h(0)%us(m)   * rmask(j,i,sr)
-                !$ACC ATOMIC
-                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +          &
-                                        surf_def_h(0)%usws(m) * rmask(j,i,sr)
-                !$ACC ATOMIC
-                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +          &
-                                        surf_def_h(0)%vsws(m) * rmask(j,i,sr)
-                !$ACC ATOMIC
-                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +          &
-                                        surf_def_h(0)%ts(m)   * rmask(j,i,sr)
+                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +                                &
+                                           surf_def_h(0)%us(m)   * rmask(j,i,sr)
+                !$ACC ATOMIC
+                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +                              &
+                                           surf_def_h(0)%usws(m) * rmask(j,i,sr)
+                !$ACC ATOMIC
+                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +                              &
+                                           surf_def_h(0)%vsws(m) * rmask(j,i,sr)
+                !$ACC ATOMIC
+                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +                              &
+                                           surf_def_h(0)%ts(m)   * rmask(j,i,sr)
 #ifndef _OPENACC
                 IF ( humidity )  THEN
-                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +     &
-                                            surf_def_h(0)%qs(m)   * rmask(j,i,sr)
+                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +                         &
+                                               surf_def_h(0)%qs(m)   * rmask(j,i,sr)
                 ENDIF
                 IF ( passive_scalar )  THEN
-                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +     &
-                                            surf_def_h(0)%ss(m)   * rmask(j,i,sr)
+                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +                         &
+                                               surf_def_h(0)%ss(m)   * rmask(j,i,sr)
                 ENDIF
 #endif
@@ -721,30 +682,29 @@
 !--             Summation of surface temperature.
                 !$ACC ATOMIC
-                sums_l(nzb+14,pr_palm,tn) = sums_l(nzb+14,pr_palm,tn)   +      &
-                                            surf_def_h(0)%pt_surface(m) *      &
-                                            rmask(j,i,sr)
+                sums_l(nzb+14,pr_palm,tn) = sums_l(nzb+14,pr_palm,tn)   +                          &
+                                            surf_def_h(0)%pt_surface(m) * rmask(j,i,sr)
              ENDIF
              IF ( surf_lsm_h%end_index(j,i) >= surf_lsm_h%start_index(j,i) )  THEN
                 m = surf_lsm_h%start_index(j,i)
                 !$ACC ATOMIC
-                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +            &
-                                        surf_lsm_h%us(m)   * rmask(j,i,sr)
-                !$ACC ATOMIC
-                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +          &
-                                        surf_lsm_h%usws(m) * rmask(j,i,sr)
-                !$ACC ATOMIC
-                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +          &
-                                        surf_lsm_h%vsws(m) * rmask(j,i,sr)
-                !$ACC ATOMIC
-                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +          &
-                                        surf_lsm_h%ts(m)   * rmask(j,i,sr)
+                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +                                &
+                                           surf_lsm_h%us(m)   * rmask(j,i,sr)
+                !$ACC ATOMIC
+                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +                              &
+                                           surf_lsm_h%usws(m) * rmask(j,i,sr)
+                !$ACC ATOMIC
+                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +                              &
+                                           surf_lsm_h%vsws(m) * rmask(j,i,sr)
+                !$ACC ATOMIC
+                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +                              &
+                                           surf_lsm_h%ts(m)   * rmask(j,i,sr)
 #ifndef _OPENACC
                 IF ( humidity )  THEN
-                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +     &
-                                            surf_lsm_h%qs(m)   * rmask(j,i,sr)
+                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +                         &
+                                               surf_lsm_h%qs(m)   * rmask(j,i,sr)
                 ENDIF
                 IF ( passive_scalar )  THEN
-                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +     &
-                                            surf_lsm_h%ss(m)   * rmask(j,i,sr)
+                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +                         &
+                                               surf_lsm_h%ss(m)   * rmask(j,i,sr)
                 ENDIF
 #endif
@@ -752,30 +712,29 @@
 !--             Summation of surface temperature.
                 !$ACC ATOMIC
-                sums_l(nzb+14,pr_palm,tn) = sums_l(nzb+14,pr_palm,tn)   +      &
-                                            surf_lsm_h%pt_surface(m)    *      &
-                                            rmask(j,i,sr)
+                sums_l(nzb+14,pr_palm,tn) = sums_l(nzb+14,pr_palm,tn) +                            &
+                                            surf_lsm_h%pt_surface(m) * rmask(j,i,sr)
              ENDIF
              IF ( surf_usm_h%end_index(j,i) >= surf_usm_h%start_index(j,i) )  THEN
                 m = surf_usm_h%start_index(j,i)
                 !$ACC ATOMIC
-                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +            &
-                                        surf_usm_h%us(m)   * rmask(j,i,sr)
-                !$ACC ATOMIC
-                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +          &
-                                        surf_usm_h%usws(m) * rmask(j,i,sr)
-                !$ACC ATOMIC
-                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +          &
-                                        surf_usm_h%vsws(m) * rmask(j,i,sr)
-                !$ACC ATOMIC
-                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +          &
-                                        surf_usm_h%ts(m)   * rmask(j,i,sr)
+                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +                                &
+                                           surf_usm_h%us(m)   * rmask(j,i,sr)
+                !$ACC ATOMIC
+                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +                              &
+                                           surf_usm_h%usws(m) * rmask(j,i,sr)
+                !$ACC ATOMIC
+                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +                              &
+                                           surf_usm_h%vsws(m) * rmask(j,i,sr)
+                !$ACC ATOMIC
+                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +                              &
+                                           surf_usm_h%ts(m)   * rmask(j,i,sr)
 #ifndef _OPENACC
                 IF ( humidity )  THEN
-                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +     &
-                                            surf_usm_h%qs(m)   * rmask(j,i,sr)
+                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +                         &
+                                               surf_usm_h%qs(m)   * rmask(j,i,sr)
                 ENDIF
                 IF ( passive_scalar )  THEN
-                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +     &
-                                            surf_usm_h%ss(m)   * rmask(j,i,sr)
+                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +                         &
+                                               surf_usm_h%ss(m) * rmask(j,i,sr)
                 ENDIF
 #endif
@@ -783,7 +742,6 @@
 !--             Summation of surface temperature.
                 !$ACC ATOMIC
-                sums_l(nzb+14,pr_palm,tn) = sums_l(nzb+14,pr_palm,tn)   +      &
-                                            surf_usm_h%pt_surface(m)    *      &
-                                            rmask(j,i,sr)
+                sums_l(nzb+14,pr_palm,tn) = sums_l(nzb+14,pr_palm,tn) +                            &
+                                            surf_usm_h%pt_surface(m)  * rmask(j,i,sr)
              ENDIF
           ENDDO !j-loop
@@ -798,6 +756,5 @@
 !--    Computation of statistics when ws-scheme is not used. Else these
 !--    quantities are evaluated in the advection routines.
-       IF ( .NOT. ws_scheme_mom .OR. sr /= 0 .OR. simulated_time == 0.0_wp )   &
-       THEN
+       IF ( .NOT. ws_scheme_mom .OR. sr /= 0 .OR. simulated_time == 0.0_wp )  THEN
           !$OMP DO
           DO  i = nxl, nxr
@@ -812,16 +769,11 @@
                    vst2 = ( v(k,j,i) - hom(k,1,2,sr) )**2
 
-                   sums_l(k,30,tn) = sums_l(k,30,tn) + ust2 * rmask(j,i,sr)    &
-                                                            * flag
-                   sums_l(k,31,tn) = sums_l(k,31,tn) + vst2 * rmask(j,i,sr)    &
-                                                            * flag
-                   sums_l(k,32,tn) = sums_l(k,32,tn) + w2   * rmask(j,i,sr)    &
-                                                            * flag
+                   sums_l(k,30,tn) = sums_l(k,30,tn) + ust2 * rmask(j,i,sr) * flag
+                   sums_l(k,31,tn) = sums_l(k,31,tn) + vst2 * rmask(j,i,sr) * flag
+                   sums_l(k,32,tn) = sums_l(k,32,tn) + w2   * rmask(j,i,sr) * flag
 !
 !--                Perturbation energy
-
-                   sums_l(k,34,tn) = sums_l(k,34,tn) + 0.5_wp *                &
-                                  ( ust2 + vst2 + w2 )      * rmask(j,i,sr)    &
-                                                            * flag
+                   sums_l(k,34,tn) = sums_l(k,34,tn) +                                             &
+                                     0.5_wp * ( ust2 + vst2 + w2 ) * rmask(j,i,sr) * flag
                 ENDDO
              ENDDO
@@ -829,8 +781,7 @@
        ENDIF
 !
-!--    Computaion of domain-averaged perturbation energy. Please note,
-!--    to prevent that perturbation energy is larger (even if only slightly)
-!--    than the total kinetic energy, calculation is based on deviations from
-!--    the horizontal mean, instead of spatial descretization of the advection
+!--    Computaion of domain-averaged perturbation energy. Please note, to prevent that perturbation
+!--    energy is larger (even if only slightly) than the total kinetic energy, calculation is based
+!--    on deviations from the horizontal mean, instead of spatial descretization of the advection
 !--    term.
        !$OMP DO
@@ -849,8 +800,6 @@
 
                 !$ACC ATOMIC
-                sums_l(nzb+5,pr_palm,tn) = sums_l(nzb+5,pr_palm,tn)            &
-                                 + 0.5_wp * ( ust2 + vst2 + w2 )               &
-                                 * rmask(j,i,sr)                               &
-                                 * flag
+                sums_l(nzb+5,pr_palm,tn) = sums_l(nzb+5,pr_palm,tn)                                &
+                                           + 0.5_wp * ( ust2 + vst2 + w2 ) * rmask(j,i,sr) * flag
 
              ENDDO
@@ -861,5 +810,4 @@
 !
 !--    Horizontally averaged profiles of the vertical fluxes
-
        !$OMP DO
        !$ACC PARALLEL LOOP COLLAPSE(2) PRIVATE(i, j, k, l, m) &
@@ -873,51 +821,47 @@
           DO  j = nys, nyn
 !
-!--          Subgridscale fluxes (without Prandtl layer from k=nzb,
-!--          oterwise from k=nzb+1)
-!--          NOTE: for simplicity, nzb_diff_s_inner is used below, although
-!--          ----  strictly speaking the following k-loop would have to be
-!--                split up according to the staggered grid.
-!--                However, this implies no error since staggered velocity
-!--                components are zero at the walls and inside buildings.
-!--          Flag 23 is used to mask surface fluxes as well as model-top fluxes,
-!--          which are added further below.
+!--          Subgridscale fluxes (without Prandtl layer from k=nzb, oterwise from k=nzb+1)
+!--          NOTE: for simplicity, nzb_diff_s_inner is used below, although strictly speaking the
+!--          ----  following k-loop would have to be split up according to the staggered grid.
+!--                However, this implies no error since staggered velocity components are zero at
+!--                the walls and inside buildings.
+!--          Flag 23 is used to mask surface fluxes as well as model-top fluxes, which are added
+!--          further below.
              DO  k = nzb, nzt
-                flag = MERGE( 1.0_wp, 0.0_wp,                                  &
-                              BTEST( wall_flags_total_0(k,j,i), 23 ) ) *       &
-                       MERGE( 1.0_wp, 0.0_wp,                                  &
-                              BTEST( wall_flags_total_0(k,j,i), 9  ) )
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 23 ) ) *           &
+                       MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 9  ) )
 !
 !--             Momentum flux w"u"
                 !$ACC ATOMIC
-                sums_l(k,12,tn) = sums_l(k,12,tn) - 0.25_wp * (                &
-                               km(k,j,i)+km(k+1,j,i)+km(k,j,i-1)+km(k+1,j,i-1) &
-                                                           ) * (               &
-                                   ( u(k+1,j,i) - u(k,j,i)   ) * ddzu(k+1)     &
-                                 + ( w(k,j,i)   - w(k,j,i-1) ) * ddx           &
-                                                           ) * rmask(j,i,sr)   &
-                                         * rho_air_zw(k)                       &
-                                         * momentumflux_output_conversion(k)   &
-                                         * flag
+                sums_l(k,12,tn) = sums_l(k,12,tn) - 0.25_wp * (                                    &
+                                  km(k,j,i) + km(k+1,j,i) + km(k,j,i-1) + km(k+1,j,i-1)            &
+                                                              ) * (                                &
+                                      ( u(k+1,j,i) - u(k,j,i)   ) * ddzu(k+1)                      &
+                                    + ( w(k,j,i)   - w(k,j,i-1) ) * ddx                            &
+                                                                  ) * rmask(j,i,sr)                &
+                                            * rho_air_zw(k)                                        &
+                                            * momentumflux_output_conversion(k)                    &
+                                            * flag
 !
 !--             Momentum flux w"v"
                 !$ACC ATOMIC
-                sums_l(k,14,tn) = sums_l(k,14,tn) - 0.25_wp * (                &
-                               km(k,j,i)+km(k+1,j,i)+km(k,j-1,i)+km(k+1,j-1,i) &
-                                                           ) * (               &
-                                   ( v(k+1,j,i) - v(k,j,i)   ) * ddzu(k+1)     &
-                                 + ( w(k,j,i)   - w(k,j-1,i) ) * ddy           &
-                                                           ) * rmask(j,i,sr)   &
-                                         * rho_air_zw(k)                       &
-                                         * momentumflux_output_conversion(k)   &
-                                         * flag
+                sums_l(k,14,tn) = sums_l(k,14,tn) - 0.25_wp * (                                    &
+                                  km(k,j,i) + km(k+1,j,i) + km(k,j-1,i) + km(k+1,j-1,i)            &
+                                                              ) * (                                &
+                                      ( v(k+1,j,i) - v(k,j,i)   ) * ddzu(k+1)                      &
+                                    + ( w(k,j,i)   - w(k,j-1,i) ) * ddy                            &
+                                                                  ) * rmask(j,i,sr)                &
+                                            * rho_air_zw(k)                                        &
+                                            * momentumflux_output_conversion(k)                    &
+                                            * flag
 !
 !--             Heat flux w"pt"
                 !$ACC ATOMIC
-                sums_l(k,16,tn) = sums_l(k,16,tn)                              &
-                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )&
-                                               * ( pt(k+1,j,i) - pt(k,j,i) )   &
-                                               * rho_air_zw(k)                 &
-                                               * heatflux_output_conversion(k) &
-                                               * ddzu(k+1) * rmask(j,i,sr)     &
+                sums_l(k,16,tn) = sums_l(k,16,tn)                                                  &
+                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )                    &
+                                               * ( pt(k+1,j,i) - pt(k,j,i) )                       &
+                                               * rho_air_zw(k)                                     &
+                                               * heatflux_output_conversion(k)                     &
+                                               * ddzu(k+1) * rmask(j,i,sr)                         &
                                                * flag
 
@@ -926,8 +870,8 @@
 #ifndef _OPENACC
                 IF ( ocean_mode )  THEN
-                   sums_l(k,65,tn) = sums_l(k,65,tn)                           &
-                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )&
-                                               * ( sa(k+1,j,i) - sa(k,j,i) )   &
-                                               * ddzu(k+1) * rmask(j,i,sr)     &
+                   sums_l(k,65,tn) = sums_l(k,65,tn)                                               &
+                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )                    &
+                                               * ( sa(k+1,j,i) - sa(k,j,i) )                       &
+                                               * ddzu(k+1) * rmask(j,i,sr)                         &
                                                * flag
                 ENDIF
@@ -936,24 +880,24 @@
 !--             Buoyancy flux, water flux (humidity flux) w"q"
                 IF ( humidity ) THEN
-                   sums_l(k,45,tn) = sums_l(k,45,tn)                           &
-                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )&
-                                               * ( vpt(k+1,j,i) - vpt(k,j,i) ) &
-                                               * rho_air_zw(k)                 &
-                                               * heatflux_output_conversion(k) &
+                   sums_l(k,45,tn) = sums_l(k,45,tn)                                               &
+                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )                    &
+                                               * ( vpt(k+1,j,i) - vpt(k,j,i) )                     &
+                                               * rho_air_zw(k)                                     &
+                                               * heatflux_output_conversion(k)                     &
                                                * ddzu(k+1) * rmask(j,i,sr) * flag
-                   sums_l(k,48,tn) = sums_l(k,48,tn)                           &
-                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )&
-                                               * ( q(k+1,j,i) - q(k,j,i) )     &
-                                               * rho_air_zw(k)                 &
-                                               * waterflux_output_conversion(k)&
+                   sums_l(k,48,tn) = sums_l(k,48,tn)                                               &
+                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )                    &
+                                               * ( q(k+1,j,i) - q(k,j,i) )                         &
+                                               * rho_air_zw(k)                                     &
+                                               * waterflux_output_conversion(k)                    &
                                                * ddzu(k+1) * rmask(j,i,sr) * flag
 
                    IF ( bulk_cloud_model ) THEN
-                      sums_l(k,51,tn) = sums_l(k,51,tn)                        &
-                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )&
-                                               * ( ( q(k+1,j,i) - ql(k+1,j,i) )&
-                                                - ( q(k,j,i) - ql(k,j,i) ) )   &
-                                               * rho_air_zw(k)                 &
-                                               * waterflux_output_conversion(k)&
+                      sums_l(k,51,tn) = sums_l(k,51,tn)                                            &
+                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )                    &
+                                               * ( ( q(k+1,j,i) - ql(k+1,j,i) )                    &
+                                                - ( q(k,j,i) - ql(k,j,i) ) )                       &
+                                               * rho_air_zw(k)                                     &
+                                               * waterflux_output_conversion(k)                    &
                                                * ddzu(k+1) * rmask(j,i,sr) * flag
                    ENDIF
@@ -963,8 +907,8 @@
 !--             Passive scalar flux
                 IF ( passive_scalar )  THEN
-                   sums_l(k,117,tn) = sums_l(k,117,tn)                         &
-                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )&
-                                                  * ( s(k+1,j,i) - s(k,j,i) )  &
-                                                  * ddzu(k+1) * rmask(j,i,sr)  &
+                   sums_l(k,117,tn) = sums_l(k,117,tn)                                             &
+                                         - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )                    &
+                                                  * ( s(k+1,j,i) - s(k,j,i) )                      &
+                                                  * ddzu(k+1) * rmask(j,i,sr)                      &
                                                               * flag
                 ENDIF
@@ -983,58 +927,59 @@
                    ki = -1 + l
                    IF ( surf_def_h(l)%ns >= 1 )  THEN
-                      DO  m = surf_def_h(l)%start_index(j,i),                  &
+                      DO  m = surf_def_h(l)%start_index(j,i),                                      &
                               surf_def_h(l)%end_index(j,i)
                          k = surf_def_h(l)%k(m)
 
                          !$ACC ATOMIC
-                         sums_l(k+ki,12,tn) = sums_l(k+ki,12,tn) + &
-                                    momentumflux_output_conversion(k+ki) * &
-                                    surf_def_h(l)%usws(m) * rmask(j,i,sr)     ! w"u"
+                         sums_l(k+ki,12,tn) = sums_l(k+ki,12,tn) +                                 &
+                                              momentumflux_output_conversion(k+ki) *               &
+                                              surf_def_h(l)%usws(m) * rmask(j,i,sr)     ! w"u"
                          !$ACC ATOMIC
-                         sums_l(k+ki,14,tn) = sums_l(k+ki,14,tn) + &
-                                    momentumflux_output_conversion(k+ki) * &
-                                    surf_def_h(l)%vsws(m) * rmask(j,i,sr)     ! w"v"
+                         sums_l(k+ki,14,tn) = sums_l(k+ki,14,tn) +                                 &
+                                              momentumflux_output_conversion(k+ki) *               &
+                                              surf_def_h(l)%vsws(m) * rmask(j,i,sr)     ! w"v"
                          !$ACC ATOMIC
-                         sums_l(k+ki,16,tn) = sums_l(k+ki,16,tn) + &
-                                    heatflux_output_conversion(k+ki) * &
-                                    surf_def_h(l)%shf(m)  * rmask(j,i,sr)     ! w"pt"
+                         sums_l(k+ki,16,tn) = sums_l(k+ki,16,tn) +                                 &
+                                              heatflux_output_conversion(k+ki) *                   &
+                                              surf_def_h(l)%shf(m)  * rmask(j,i,sr)     ! w"pt"
 #if 0
-                         sums_l(k+ki,58,tn) = sums_l(k+ki,58,tn) + &
-                                    0.0_wp * rmask(j,i,sr)        ! u"pt"
-                         sums_l(k+ki,61,tn) = sums_l(k+ki,61,tn) + &
-                                    0.0_wp * rmask(j,i,sr)        ! v"pt"
+                         sums_l(k+ki,58,tn) = sums_l(k+ki,58,tn) +                                 &
+                                              0.0_wp * rmask(j,i,sr)                    ! u"pt"
+                         sums_l(k+ki,61,tn) = sums_l(k+ki,61,tn) +                                 &
+                                              0.0_wp * rmask(j,i,sr)                    ! v"pt"
 #endif
 #ifndef _OPENACC
                          IF ( ocean_mode )  THEN
-                            sums_l(k+ki,65,tn) = sums_l(k+ki,65,tn) + &
-                                       surf_def_h(l)%sasws(m) * rmask(j,i,sr)  ! w"sa"
+                            sums_l(k+ki,65,tn) = sums_l(k+ki,65,tn) +                              &
+                                                 surf_def_h(l)%sasws(m) * rmask(j,i,sr)  ! w"sa"
                          ENDIF
                          IF ( humidity )  THEN
-                            sums_l(k+ki,48,tn) = sums_l(k+ki,48,tn) +                     &
-                                       waterflux_output_conversion(k+ki) *      &
-                                       surf_def_h(l)%qsws(m) * rmask(j,i,sr)  ! w"q" (w"qv")
-                            sums_l(k+ki,45,tn) = sums_l(k+ki,45,tn) + (                   &
-                                       ( 1.0_wp + 0.61_wp * q(k+ki,j,i) ) *     &
-                                       surf_def_h(l)%shf(m) + 0.61_wp * pt(k+ki,j,i) *      &
-                                                  surf_def_h(l)%qsws(m) )                  &
-                                       * heatflux_output_conversion(k+ki)
+                            sums_l(k+ki,48,tn) = sums_l(k+ki,48,tn) +                              &
+                                                 waterflux_output_conversion(k+ki) *               &
+                                                 surf_def_h(l)%qsws(m) * rmask(j,i,sr)  ! w"q" (w"qv")
+                            sums_l(k+ki,45,tn) = sums_l(k+ki,45,tn) +  (                           &
+                                                 ( 1.0_wp + 0.61_wp * q(k+ki,j,i) ) *              &
+                                                 surf_def_h(l)%shf(m) + 0.61_wp * pt(k+ki,j,i) *   &
+                                                 surf_def_h(l)%qsws(m) )                           &
+                                                 * heatflux_output_conversion(k+ki)
                             IF ( cloud_droplets )  THEN
-                               sums_l(k+ki,45,tn) = sums_l(k+ki,45,tn) + (                &
-                                         ( 1.0_wp + 0.61_wp * q(k+ki,j,i) -     &
-                                           ql(k+ki,j,i) ) * surf_def_h(l)%shf(m) +          &
-                                           0.61_wp * pt(k+ki,j,i) * surf_def_h(l)%qsws(m) ) &
-                                          * heatflux_output_conversion(k+ki)
+                               sums_l(k+ki,45,tn) = sums_l(k+ki,45,tn) +      (                    &
+                                                    ( 1.0_wp + 0.61_wp * q(k+ki,j,i) -             &
+                                                      ql(k+ki,j,i) ) * surf_def_h(l)%shf(m) +      &
+                                                      0.61_wp * pt(k+ki,j,i)                       &
+                                                      * surf_def_h(l)%qsws(m) )                    &
+                                                    * heatflux_output_conversion(k+ki)
                             ENDIF
                             IF ( bulk_cloud_model )  THEN
 !
 !--                            Formula does not work if ql(k+ki) /= 0.0
-                               sums_l(k+ki,51,tn) = sums_l(k+ki,51,tn) +                  &
-                                          waterflux_output_conversion(k+ki) *   &
-                                          surf_def_h(l)%qsws(m) * rmask(j,i,sr) ! w"q" (w"qv")
+                               sums_l(k+ki,51,tn) = sums_l(k+ki,51,tn) +                           &
+                                                    waterflux_output_conversion(k+ki) *            &
+                                                    surf_def_h(l)%qsws(m) * rmask(j,i,sr) ! w"q" (w"qv")
                             ENDIF
                          ENDIF
                          IF ( passive_scalar )  THEN
-                            sums_l(k+ki,117,tn) = sums_l(k+ki,117,tn) +                     &
-                                        surf_def_h(l)%ssws(m) * rmask(j,i,sr) ! w"s"
+                            sums_l(k+ki,117,tn) = sums_l(k+ki,117,tn) +                            &
+                                                  surf_def_h(l)%ssws(m) * rmask(j,i,sr) ! w"s"
                          ENDIF
 #endif
@@ -1044,114 +989,109 @@
                    ENDIF
                 ENDDO
-                IF ( surf_lsm_h%end_index(j,i) >=                              &
-                     surf_lsm_h%start_index(j,i) )  THEN
+                IF ( surf_lsm_h%end_index(j,i) >= surf_lsm_h%start_index(j,i) )  THEN
                    m = surf_lsm_h%start_index(j,i)
                    !$ACC ATOMIC
-                   sums_l(nzb,12,tn) = sums_l(nzb,12,tn) + &
-                                    momentumflux_output_conversion(nzb) * &
-                                    surf_lsm_h%usws(m) * rmask(j,i,sr)     ! w"u"
+                   sums_l(nzb,12,tn) = sums_l(nzb,12,tn) +                                         &
+                                       momentumflux_output_conversion(nzb) *                       &
+                                       surf_lsm_h%usws(m) * rmask(j,i,sr)     ! w"u"
                    !$ACC ATOMIC
-                   sums_l(nzb,14,tn) = sums_l(nzb,14,tn) + &
-                                    momentumflux_output_conversion(nzb) * &
-                                    surf_lsm_h%vsws(m) * rmask(j,i,sr)     ! w"v"
+                   sums_l(nzb,14,tn) = sums_l(nzb,14,tn) +                                         &
+                                       momentumflux_output_conversion(nzb) *                       &
+                                       surf_lsm_h%vsws(m) * rmask(j,i,sr)     ! w"v"
                    !$ACC ATOMIC
-                   sums_l(nzb,16,tn) = sums_l(nzb,16,tn) + &
-                                    heatflux_output_conversion(nzb) * &
-                                    surf_lsm_h%shf(m)  * rmask(j,i,sr)     ! w"pt"
+                   sums_l(nzb,16,tn) = sums_l(nzb,16,tn) +                                         &
+                                       heatflux_output_conversion(nzb) *                           &
+                                       surf_lsm_h%shf(m)  * rmask(j,i,sr)     ! w"pt"
 #if 0
-                   sums_l(nzb,58,tn) = sums_l(nzb,58,tn) + &
-                                    0.0_wp * rmask(j,i,sr)        ! u"pt"
-                   sums_l(nzb,61,tn) = sums_l(nzb,61,tn) + &
-                                    0.0_wp * rmask(j,i,sr)        ! v"pt"
+                   sums_l(nzb,58,tn) = sums_l(nzb,58,tn) +                                         &
+                                       0.0_wp * rmask(j,i,sr)        ! u"pt"
+                   sums_l(nzb,61,tn) = sums_l(nzb,61,tn) +                                         &
+                                       0.0_wp * rmask(j,i,sr)        ! v"pt"
 #endif
 #ifndef _OPENACC
                    IF ( ocean_mode )  THEN
-                      sums_l(nzb,65,tn) = sums_l(nzb,65,tn) + &
-                                       surf_lsm_h%sasws(m) * rmask(j,i,sr)  ! w"sa"
+                      sums_l(nzb,65,tn) = sums_l(nzb,65,tn) +                                      &
+                                          surf_lsm_h%sasws(m) * rmask(j,i,sr)  ! w"sa"
                    ENDIF
                    IF ( humidity )  THEN
-                      sums_l(nzb,48,tn) = sums_l(nzb,48,tn) +                     &
-                                       waterflux_output_conversion(nzb) *      &
-                                       surf_lsm_h%qsws(m) * rmask(j,i,sr)  ! w"q" (w"qv")
-                      sums_l(nzb,45,tn) = sums_l(nzb,45,tn) + (                   &
-                                       ( 1.0_wp + 0.61_wp * q(nzb,j,i) ) *     &
-                                       surf_lsm_h%shf(m) + 0.61_wp * pt(nzb,j,i) *      &
-                                                  surf_lsm_h%qsws(m) )                  &
-                                       * heatflux_output_conversion(nzb)
+                      sums_l(nzb,48,tn) = sums_l(nzb,48,tn) +                                      &
+                                          waterflux_output_conversion(nzb) *                       &
+                                          surf_lsm_h%qsws(m) * rmask(j,i,sr)  ! w"q" (w"qv")
+                      sums_l(nzb,45,tn) = sums_l(nzb,45,tn) + (                                    &
+                                          ( 1.0_wp + 0.61_wp * q(nzb,j,i) ) * surf_lsm_h%shf(m) +  &
+                                            0.61_wp * pt(nzb,j,i) * surf_lsm_h%qsws(m) )           &
+                                          * heatflux_output_conversion(nzb)
                       IF ( cloud_droplets )  THEN
-                         sums_l(nzb,45,tn) = sums_l(nzb,45,tn) + (                &
-                                         ( 1.0_wp + 0.61_wp * q(nzb,j,i) -     &
-                                           ql(nzb,j,i) ) * surf_lsm_h%shf(m) +          &
-                                           0.61_wp * pt(nzb,j,i) * surf_lsm_h%qsws(m) ) &
-                                          * heatflux_output_conversion(nzb)
+                         sums_l(nzb,45,tn) = sums_l(nzb,45,tn) + (                                 &
+                                             ( 1.0_wp + 0.61_wp * q(nzb,j,i) -                     &
+                                               ql(nzb,j,i) ) * surf_lsm_h%shf(m) +                 &
+                                               0.61_wp * pt(nzb,j,i) * surf_lsm_h%qsws(m) )        &
+                                             * heatflux_output_conversion(nzb)
                       ENDIF
                       IF ( bulk_cloud_model )  THEN
 !
 !--                      Formula does not work if ql(nzb) /= 0.0
-                         sums_l(nzb,51,tn) = sums_l(nzb,51,tn) +                  &
-                                          waterflux_output_conversion(nzb) *   &
-                                          surf_lsm_h%qsws(m) * rmask(j,i,sr) ! w"q" (w"qv")
+                         sums_l(nzb,51,tn) = sums_l(nzb,51,tn) +                                   &
+                                             waterflux_output_conversion(nzb) *                    &
+                                             surf_lsm_h%qsws(m) * rmask(j,i,sr) ! w"q" (w"qv")
                       ENDIF
                    ENDIF
                    IF ( passive_scalar )  THEN
-                      sums_l(nzb,117,tn) = sums_l(nzb,117,tn) +                     &
-                                        surf_lsm_h%ssws(m) * rmask(j,i,sr) ! w"s"
+                      sums_l(nzb,117,tn) = sums_l(nzb,117,tn) +                                    &
+                                           surf_lsm_h%ssws(m) * rmask(j,i,sr) ! w"s"
                    ENDIF
 #endif
 
                 ENDIF
-                IF ( surf_usm_h%end_index(j,i) >=                              &
-                     surf_usm_h%start_index(j,i) )  THEN
+                IF ( surf_usm_h%end_index(j,i) >= surf_usm_h%start_index(j,i) )  THEN
                    m = surf_usm_h%start_index(j,i)
                    !$ACC ATOMIC
-                   sums_l(nzb,12,tn) = sums_l(nzb,12,tn) + &
-                                    momentumflux_output_conversion(nzb) * &
-                                    surf_usm_h%usws(m) * rmask(j,i,sr)     ! w"u"
+                   sums_l(nzb,12,tn) = sums_l(nzb,12,tn) +                                         &
+                                       momentumflux_output_conversion(nzb) *                       &
+                                       surf_usm_h%usws(m) * rmask(j,i,sr)                ! w"u"
                    !$ACC ATOMIC
-                   sums_l(nzb,14,tn) = sums_l(nzb,14,tn) + &
-                                    momentumflux_output_conversion(nzb) * &
-                                    surf_usm_h%vsws(m) * rmask(j,i,sr)     ! w"v"
+                   sums_l(nzb,14,tn) = sums_l(nzb,14,tn) +                                         &
+                                       momentumflux_output_conversion(nzb) *                       &
+                                       surf_usm_h%vsws(m) * rmask(j,i,sr)                ! w"v"
                    !$ACC ATOMIC
-                   sums_l(nzb,16,tn) = sums_l(nzb,16,tn) + &
-                                    heatflux_output_conversion(nzb) * &
-                                    surf_usm_h%shf(m)  * rmask(j,i,sr)     ! w"pt"
+                   sums_l(nzb,16,tn) = sums_l(nzb,16,tn) +                                         &
+                                       heatflux_output_conversion(nzb) *                           &
+                                       surf_usm_h%shf(m)  * rmask(j,i,sr)                ! w"pt"
 #if 0
-                   sums_l(nzb,58,tn) = sums_l(nzb,58,tn) + &
-                                    0.0_wp * rmask(j,i,sr)        ! u"pt"
-                   sums_l(nzb,61,tn) = sums_l(nzb,61,tn) + &
-                                    0.0_wp * rmask(j,i,sr)        ! v"pt"
+                   sums_l(nzb,58,tn) = sums_l(nzb,58,tn) + 0.0_wp * rmask(j,i,sr)        ! u"pt"
+                   sums_l(nzb,61,tn) = sums_l(nzb,61,tn) + 0.0_wp * rmask(j,i,sr)        ! v"pt"
 #endif
 #ifndef _OPENACC
                    IF ( ocean_mode )  THEN
-                      sums_l(nzb,65,tn) = sums_l(nzb,65,tn) + &
-                                       surf_usm_h%sasws(m) * rmask(j,i,sr)  ! w"sa"
+                      sums_l(nzb,65,tn) = sums_l(nzb,65,tn) +                                      &
+                                          surf_usm_h%sasws(m) * rmask(j,i,sr)            ! w"sa"
                    ENDIF
                    IF ( humidity )  THEN
-                      sums_l(nzb,48,tn) = sums_l(nzb,48,tn) +                     &
-                                       waterflux_output_conversion(nzb) *      &
-                                       surf_usm_h%qsws(m) * rmask(j,i,sr)  ! w"q" (w"qv")
-                      sums_l(nzb,45,tn) = sums_l(nzb,45,tn) + (                   &
-                                       ( 1.0_wp + 0.61_wp * q(nzb,j,i) ) *     &
-                                       surf_usm_h%shf(m) + 0.61_wp * pt(nzb,j,i) *      &
-                                                  surf_usm_h%qsws(m) )                  &
-                                       * heatflux_output_conversion(nzb)
+                      sums_l(nzb,48,tn) = sums_l(nzb,48,tn) +                                      &
+                                          waterflux_output_conversion(nzb) *                       &
+                                          surf_usm_h%qsws(m) * rmask(j,i,sr)             ! w"q" (w"qv")
+                      sums_l(nzb,45,tn) = sums_l(nzb,45,tn) + (                                    &
+                                          ( 1.0_wp + 0.61_wp * q(nzb,j,i) ) *                      &
+                                          surf_usm_h%shf(m) + 0.61_wp * pt(nzb,j,i) *              &
+                                          surf_usm_h%qsws(m)  )                                    &
+                                          * heatflux_output_conversion(nzb)
                       IF ( cloud_droplets )  THEN
-                         sums_l(nzb,45,tn) = sums_l(nzb,45,tn) + (                &
-                                         ( 1.0_wp + 0.61_wp * q(nzb,j,i) -     &
-                                           ql(nzb,j,i) ) * surf_usm_h%shf(m) +          &
-                                           0.61_wp * pt(nzb,j,i) * surf_usm_h%qsws(m) ) &
-                                          * heatflux_output_conversion(nzb)
+                         sums_l(nzb,45,tn) = sums_l(nzb,45,tn) + (                                 &
+                                             ( 1.0_wp + 0.61_wp * q(nzb,j,i) -                     &
+                                              ql(nzb,j,i) ) * surf_usm_h%shf(m) +                  &
+                                              0.61_wp * pt(nzb,j,i) * surf_usm_h%qsws(m) )         &
+                                             * heatflux_output_conversion(nzb)
                       ENDIF
                       IF ( bulk_cloud_model )  THEN
 !
 !--                      Formula does not work if ql(nzb) /= 0.0
-                         sums_l(nzb,51,tn) = sums_l(nzb,51,tn) +                  &
-                                          waterflux_output_conversion(nzb) *   &
-                                          surf_usm_h%qsws(m) * rmask(j,i,sr) ! w"q" (w"qv")
+                         sums_l(nzb,51,tn) = sums_l(nzb,51,tn) +                                   &
+                                             waterflux_output_conversion(nzb) *                    &
+                                             surf_usm_h%qsws(m) * rmask(j,i,sr)          ! w"q" (w"qv")
                       ENDIF
                    ENDIF
                    IF ( passive_scalar )  THEN
-                      sums_l(nzb,117,tn) = sums_l(nzb,117,tn) +                     &
-                                        surf_usm_h%ssws(m) * rmask(j,i,sr) ! w"s"
+                      sums_l(nzb,117,tn) = sums_l(nzb,117,tn) +                                    &
+                                           surf_usm_h%ssws(m) * rmask(j,i,sr)            ! w"s"
                    ENDIF
 #endif
@@ -1163,65 +1103,56 @@
 #ifndef _OPENACC
              IF ( .NOT. neutral )  THEN
-                IF ( surf_def_h(0)%end_index(j,i) >=                           &
-                     surf_def_h(0)%start_index(j,i) )  THEN
+                IF ( surf_def_h(0)%end_index(j,i) >= surf_def_h(0)%start_index(j,i) )  THEN
                    m = surf_def_h(0)%start_index(j,i)
-                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) +                   &
-                                        surf_def_h(0)%ol(m)  * rmask(j,i,sr) ! L
-                ENDIF
-                IF ( surf_lsm_h%end_index(j,i) >=                              &
-                     surf_lsm_h%start_index(j,i) )  THEN
+                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) + surf_def_h(0)%ol(m) * rmask(j,i,sr) ! L
+                ENDIF
+                IF ( surf_lsm_h%end_index(j,i) >= surf_lsm_h%start_index(j,i) )  THEN
                    m = surf_lsm_h%start_index(j,i)
-                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) +                   &
-                                        surf_lsm_h%ol(m)  * rmask(j,i,sr) ! L
-                ENDIF
-                IF ( surf_usm_h%end_index(j,i) >=                              &
-                     surf_usm_h%start_index(j,i) )  THEN
+                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) + surf_lsm_h%ol(m)    * rmask(j,i,sr) ! L
+                ENDIF
+                IF ( surf_usm_h%end_index(j,i) >= surf_usm_h%start_index(j,i) )  THEN
                    m = surf_usm_h%start_index(j,i)
-                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) +                   &
-                                        surf_usm_h%ol(m)  * rmask(j,i,sr) ! L
+                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) + surf_usm_h%ol(m)    * rmask(j,i,sr) ! L
                 ENDIF
              ENDIF
 
              IF ( radiation )  THEN
-                IF ( surf_def_h(0)%end_index(j,i) >=                           &
-                     surf_def_h(0)%start_index(j,i) )  THEN
+                IF ( surf_def_h(0)%end_index(j,i) >= surf_def_h(0)%start_index(j,i) )  THEN
                    m = surf_def_h(0)%start_index(j,i)
-                   sums_l(nzb,99,tn)  = sums_l(nzb,99,tn)  +                   &
-                                        surf_def_h(0)%rad_net(m) * rmask(j,i,sr)
-                   sums_l(nzb,100,tn) = sums_l(nzb,100,tn)  +                  &
-                                        surf_def_h(0)%rad_lw_in(m) * rmask(j,i,sr)
-                   sums_l(nzb,101,tn) = sums_l(nzb,101,tn)  +                  &
+                   sums_l(nzb,99,tn)  = sums_l(nzb,99,tn)   +                                      &
+                                        surf_def_h(0)%rad_net(m)    * rmask(j,i,sr)
+                   sums_l(nzb,100,tn) = sums_l(nzb,100,tn)  +                                      &
+                                        surf_def_h(0)%rad_lw_in(m)  * rmask(j,i,sr)
+                   sums_l(nzb,101,tn) = sums_l(nzb,101,tn)  +                                      &
                                         surf_def_h(0)%rad_lw_out(m) * rmask(j,i,sr)
-                   sums_l(nzb,102,tn) = sums_l(nzb,102,tn)  +                  &
-                                        surf_def_h(0)%rad_sw_in(m) * rmask(j,i,sr)
-                   sums_l(nzb,103,tn) = sums_l(nzb,103,tn)  +                  &
+                   sums_l(nzb,102,tn) = sums_l(nzb,102,tn)  +                                      &
+                                        surf_def_h(0)%rad_sw_in(m)  * rmask(j,i,sr)
+                   sums_l(nzb,103,tn) = sums_l(nzb,103,tn)  +                                      &
                                         surf_def_h(0)%rad_sw_out(m) * rmask(j,i,sr)
                 ENDIF
-                IF ( surf_lsm_h%end_index(j,i) >=                              &
-                     surf_lsm_h%start_index(j,i) )  THEN
+                IF ( surf_lsm_h%end_index(j,i) >= surf_lsm_h%start_index(j,i) )  THEN
                    m = surf_lsm_h%start_index(j,i)
-                   sums_l(nzb,99,tn)  = sums_l(nzb,99,tn)  +                   &
-                                        surf_lsm_h%rad_net(m) * rmask(j,i,sr)
-                   sums_l(nzb,100,tn) = sums_l(nzb,100,tn)  +                  &
-                                        surf_lsm_h%rad_lw_in(m) * rmask(j,i,sr)
-                   sums_l(nzb,101,tn) = sums_l(nzb,101,tn)  +                  &
+                   sums_l(nzb,99,tn)  = sums_l(nzb,99,tn)   +                                      &
+                                        surf_lsm_h%rad_net(m)    * rmask(j,i,sr)
+                   sums_l(nzb,100,tn) = sums_l(nzb,100,tn)  +                                      &
+                                        surf_lsm_h%rad_lw_in(m)  * rmask(j,i,sr)
+                   sums_l(nzb,101,tn) = sums_l(nzb,101,tn)  +                                      &
                                         surf_lsm_h%rad_lw_out(m) * rmask(j,i,sr)
-                   sums_l(nzb,102,tn) = sums_l(nzb,102,tn)  +                  &
-                                        surf_lsm_h%rad_sw_in(m) * rmask(j,i,sr)
-                   sums_l(nzb,103,tn) = sums_l(nzb,103,tn)  +                  &
+                   sums_l(nzb,102,tn) = sums_l(nzb,102,tn)  +                                      &
+                                        surf_lsm_h%rad_sw_in(m)  * rmask(j,i,sr)
+                   sums_l(nzb,103,tn) = sums_l(nzb,103,tn)  +                                      &
                                         surf_lsm_h%rad_sw_out(m) * rmask(j,i,sr)
                 ENDIF
-                IF ( surf_usm_h%end_index(j,i) >=                              &
-                     surf_usm_h%start_index(j,i) )  THEN
+                IF ( surf_usm_h%end_index(j,i) >= surf_usm_h%start_index(j,i) )  THEN
                    m = surf_usm_h%start_index(j,i)
-                   sums_l(nzb,99,tn)  = sums_l(nzb,99,tn)  +                   &
-                                        surf_usm_h%rad_net(m) * rmask(j,i,sr)
-                   sums_l(nzb,100,tn) = sums_l(nzb,100,tn)  +                  &
-                                        surf_usm_h%rad_lw_in(m) * rmask(j,i,sr)
-                   sums_l(nzb,101,tn) = sums_l(nzb,101,tn)  +                  &
+                   sums_l(nzb,99,tn)  = sums_l(nzb,99,tn)   +                                      &
+                                        surf_usm_h%rad_net(m)    * rmask(j,i,sr)
+                   sums_l(nzb,100,tn) = sums_l(nzb,100,tn)  +                                      &
+                                        surf_usm_h%rad_lw_in(m)  * rmask(j,i,sr)
+                   sums_l(nzb,101,tn) = sums_l(nzb,101,tn)  +                                      &
                                         surf_usm_h%rad_lw_out(m) * rmask(j,i,sr)
-                   sums_l(nzb,102,tn) = sums_l(nzb,102,tn)  +                  &
-                                        surf_usm_h%rad_sw_in(m) * rmask(j,i,sr)
-                   sums_l(nzb,103,tn) = sums_l(nzb,103,tn)  +                  &
+                   sums_l(nzb,102,tn) = sums_l(nzb,102,tn)  +                                      &
+                                        surf_usm_h%rad_sw_in(m)  * rmask(j,i,sr)
+                   sums_l(nzb,103,tn) = sums_l(nzb,103,tn)  +                                      &
                                         surf_usm_h%rad_sw_out(m) * rmask(j,i,sr)
                 ENDIF
@@ -1230,47 +1161,44 @@
                 IF ( radiation_scheme == 'rrtmg' )  THEN
 
-                   IF ( surf_def_h(0)%end_index(j,i) >=                        &
-                        surf_def_h(0)%start_index(j,i) )  THEN
+                   IF ( surf_def_h(0)%end_index(j,i) >= surf_def_h(0)%start_index(j,i) )  THEN
                       m = surf_def_h(0)%start_index(j,i)
-                      sums_l(nzb,108,tn)  = sums_l(nzb,108,tn)  +              &
-                                   surf_def_h(0)%rrtm_aldif(m,0) * rmask(j,i,sr)
-                      sums_l(nzb,109,tn) = sums_l(nzb,109,tn)  +               &
-                                   surf_def_h(0)%rrtm_aldir(m,0) * rmask(j,i,sr)
-                      sums_l(nzb,110,tn) = sums_l(nzb,110,tn)  +               &
-                                   surf_def_h(0)%rrtm_asdif(m,0) * rmask(j,i,sr)
-                      sums_l(nzb,111,tn) = sums_l(nzb,111,tn)  +               &
-                                   surf_def_h(0)%rrtm_asdir(m,0) * rmask(j,i,sr)
+                      sums_l(nzb,108,tn)  = sums_l(nzb,108,tn)  +                                  &
+                                            surf_def_h(0)%rrtm_aldif(m,0) * rmask(j,i,sr)
+                      sums_l(nzb,109,tn) = sums_l(nzb,109,tn)  +                                   &
+                                           surf_def_h(0)%rrtm_aldir(m,0) * rmask(j,i,sr)
+                      sums_l(nzb,110,tn) = sums_l(nzb,110,tn)  +                                   &
+                                           surf_def_h(0)%rrtm_asdif(m,0) * rmask(j,i,sr)
+                      sums_l(nzb,111,tn) = sums_l(nzb,111,tn)  +                                   &
+                                           surf_def_h(0)%rrtm_asdir(m,0) * rmask(j,i,sr)
                    ENDIF
-                   IF ( surf_lsm_h%end_index(j,i) >=                           &
-                        surf_lsm_h%start_index(j,i) )  THEN
+                   IF ( surf_lsm_h%end_index(j,i) >= surf_lsm_h%start_index(j,i) )  THEN
                       m = surf_lsm_h%start_index(j,i)
-                      sums_l(nzb,108,tn)  = sums_l(nzb,108,tn)  +              &
-                               SUM( surf_lsm_h%frac(m,:) *                     &
-                                    surf_lsm_h%rrtm_aldif(m,:) ) * rmask(j,i,sr)
-                      sums_l(nzb,109,tn) = sums_l(nzb,109,tn)  +               &
-                               SUM( surf_lsm_h%frac(m,:) *                     &
-                                    surf_lsm_h%rrtm_aldir(m,:) ) * rmask(j,i,sr)
-                      sums_l(nzb,110,tn) = sums_l(nzb,110,tn)  +               &
-                               SUM( surf_lsm_h%frac(m,:) *                     &
-                                    surf_lsm_h%rrtm_asdif(m,:) ) * rmask(j,i,sr)
-                      sums_l(nzb,111,tn) = sums_l(nzb,111,tn)  +               &
-                               SUM( surf_lsm_h%frac(m,:) *                     &
-                                    surf_lsm_h%rrtm_asdir(m,:) ) * rmask(j,i,sr)
+                      sums_l(nzb,108,tn)  = sums_l(nzb,108,tn)  +                                  &
+                                            SUM( surf_lsm_h%frac(m,:) *                            &
+                                                 surf_lsm_h%rrtm_aldif(m,:) ) * rmask(j,i,sr)
+                      sums_l(nzb,109,tn) = sums_l(nzb,109,tn)  +                                   &
+                                           SUM( surf_lsm_h%frac(m,:) *                             &
+                                                surf_lsm_h%rrtm_aldir(m,:) ) * rmask(j,i,sr)
+                      sums_l(nzb,110,tn) = sums_l(nzb,110,tn)  +                                   &
+                                           SUM( surf_lsm_h%frac(m,:) *                             &
+                                                surf_lsm_h%rrtm_asdif(m,:) ) * rmask(j,i,sr)
+                      sums_l(nzb,111,tn) = sums_l(nzb,111,tn)  +                                   &
+                                           SUM( surf_lsm_h%frac(m,:) *                             &
+                                                surf_lsm_h%rrtm_asdir(m,:) ) * rmask(j,i,sr)
                    ENDIF
-                   IF ( surf_usm_h%end_index(j,i) >=                           &
-                        surf_usm_h%start_index(j,i) )  THEN
+                   IF ( surf_usm_h%end_index(j,i) >= surf_usm_h%start_index(j,i) )  THEN
                       m = surf_usm_h%start_index(j,i)
-                      sums_l(nzb,108,tn)  = sums_l(nzb,108,tn)  +              &
-                               SUM( surf_usm_h%frac(m,:) *                     &
-                                    surf_usm_h%rrtm_aldif(m,:) ) * rmask(j,i,sr)
-                      sums_l(nzb,109,tn) = sums_l(nzb,109,tn)  +               &
-                               SUM( surf_usm_h%frac(m,:) *                     &
-                                    surf_usm_h%rrtm_aldir(m,:) ) * rmask(j,i,sr)
-                      sums_l(nzb,110,tn) = sums_l(nzb,110,tn)  +               &
-                               SUM( surf_usm_h%frac(m,:) *                     &
-                                    surf_usm_h%rrtm_asdif(m,:) ) * rmask(j,i,sr)
-                      sums_l(nzb,111,tn) = sums_l(nzb,111,tn)  +               &
-                               SUM( surf_usm_h%frac(m,:) *                     &
-                                    surf_usm_h%rrtm_asdir(m,:) ) * rmask(j,i,sr)
+                      sums_l(nzb,108,tn)  = sums_l(nzb,108,tn)  +                                  &
+                                            SUM( surf_usm_h%frac(m,:) *                            &
+                                                 surf_usm_h%rrtm_aldif(m,:) ) * rmask(j,i,sr)
+                      sums_l(nzb,109,tn) = sums_l(nzb,109,tn)  +                                   &
+                                           SUM( surf_usm_h%frac(m,:) *                             &
+                                                surf_usm_h%rrtm_aldir(m,:) ) * rmask(j,i,sr)
+                      sums_l(nzb,110,tn) = sums_l(nzb,110,tn)  +                                   &
+                                           SUM( surf_usm_h%frac(m,:) *                             &
+                                                surf_usm_h%rrtm_asdif(m,:) ) * rmask(j,i,sr)
+                      sums_l(nzb,111,tn) = sums_l(nzb,111,tn)  +                                   &
+                                           SUM( surf_usm_h%frac(m,:) *                             &
+                                                surf_usm_h%rrtm_asdir(m,:) ) * rmask(j,i,sr)
                    ENDIF
 
@@ -1284,32 +1212,32 @@
                 m = surf_def_h(2)%start_index(j,i)
                 !$ACC ATOMIC
-                sums_l(nzt,12,tn) = sums_l(nzt,12,tn) + &
-                                    momentumflux_output_conversion(nzt) * &
+                sums_l(nzt,12,tn) = sums_l(nzt,12,tn) +                                            &
+                                    momentumflux_output_conversion(nzt) *                          &
                                     surf_def_h(2)%usws(m) * rmask(j,i,sr)    ! w"u"
                 !$ACC ATOMIC
-                sums_l(nzt+1,12,tn) = sums_l(nzt+1,12,tn) + &
-                                    momentumflux_output_conversion(nzt+1) * &
-                                    surf_def_h(2)%usws(m) * rmask(j,i,sr)    ! w"u"
-                !$ACC ATOMIC
-                sums_l(nzt,14,tn) = sums_l(nzt,14,tn) + &
-                                    momentumflux_output_conversion(nzt) * &
+                sums_l(nzt+1,12,tn) = sums_l(nzt+1,12,tn) +                                        &
+                                      momentumflux_output_conversion(nzt+1) *                      &
+                                      surf_def_h(2)%usws(m) * rmask(j,i,sr)  ! w"u"
+                !$ACC ATOMIC
+                sums_l(nzt,14,tn) = sums_l(nzt,14,tn) +                                            &
+                                    momentumflux_output_conversion(nzt) *                          &
                                     surf_def_h(2)%vsws(m) * rmask(j,i,sr)    ! w"v"
                 !$ACC ATOMIC
-                sums_l(nzt+1,14,tn) = sums_l(nzt+1,14,tn) + &
-                                    momentumflux_output_conversion(nzt+1) * &
-                                    surf_def_h(2)%vsws(m) * rmask(j,i,sr)    ! w"v"
-                !$ACC ATOMIC
-                sums_l(nzt,16,tn) = sums_l(nzt,16,tn) + &
-                                    heatflux_output_conversion(nzt) * &
-                                    surf_def_h(2)%shf(m)  * rmask(j,i,sr)   ! w"pt"
-                !$ACC ATOMIC
-                sums_l(nzt+1,16,tn) = sums_l(nzt+1,16,tn) + &
-                                    heatflux_output_conversion(nzt+1) * &
-                                    surf_def_h(2)%shf(m)  * rmask(j,i,sr)   ! w"pt"
+                sums_l(nzt+1,14,tn) = sums_l(nzt+1,14,tn) +                                        &
+                                      momentumflux_output_conversion(nzt+1) *                      &
+                                      surf_def_h(2)%vsws(m) * rmask(j,i,sr)  ! w"v"
+                !$ACC ATOMIC
+                sums_l(nzt,16,tn) = sums_l(nzt,16,tn) +                                            &
+                                    heatflux_output_conversion(nzt) *                              &
+                                    surf_def_h(2)%shf(m)  * rmask(j,i,sr)    ! w"pt"
+                !$ACC ATOMIC
+                sums_l(nzt+1,16,tn) = sums_l(nzt+1,16,tn) +                                        &
+                                      heatflux_output_conversion(nzt+1) *                          &
+                                      surf_def_h(2)%shf(m)  * rmask(j,i,sr)  ! w"pt"
 #if 0
-                sums_l(nzt:nzt+1,58,tn) = sums_l(nzt:nzt+1,58,tn) + &
-                                    0.0_wp * rmask(j,i,sr)        ! u"pt"
-                sums_l(nzt:nzt+1,61,tn) = sums_l(nzt:nzt+1,61,tn) + &
-                                    0.0_wp * rmask(j,i,sr)        ! v"pt"
+                sums_l(nzt:nzt+1,58,tn) = sums_l(nzt:nzt+1,58,tn) +                                &
+                                          0.0_wp * rmask(j,i,sr)             ! u"pt"
+                sums_l(nzt:nzt+1,61,tn) = sums_l(nzt:nzt+1,61,tn) +                                &
+                                          0.0_wp * rmask(j,i,sr)             ! v"pt"
 #endif
 #ifndef _OPENACC
@@ -1319,20 +1247,20 @@
                 ENDIF
                 IF ( humidity )  THEN
-                   sums_l(nzt,48,tn) = sums_l(nzt,48,tn) +                     &
-                                       waterflux_output_conversion(nzt) *      &
+                   sums_l(nzt,48,tn) = sums_l(nzt,48,tn) +                                         &
+                                       waterflux_output_conversion(nzt) *                          &
                                        surf_def_h(2)%qsws(m) * rmask(j,i,sr) ! w"q" (w"qv")
-                   sums_l(nzt,45,tn) = sums_l(nzt,45,tn) + (                   &
-                                       ( 1.0_wp + 0.61_wp * q(nzt,j,i) ) *     &
-                                       surf_def_h(2)%shf(m) +                  &
-                                       0.61_wp * pt(nzt,j,i) *    &
-                                       surf_def_h(2)%qsws(m) )      &
+                   sums_l(nzt,45,tn) = sums_l(nzt,45,tn) +   (                                     &
+                                       ( 1.0_wp + 0.61_wp * q(nzt,j,i) ) *                         &
+                                       surf_def_h(2)%shf(m) +                                      &
+                                       0.61_wp * pt(nzt,j,i) *                                     &
+                                       surf_def_h(2)%qsws(m) )                                     &
                                        * heatflux_output_conversion(nzt)
                    IF ( cloud_droplets )  THEN
-                      sums_l(nzt,45,tn) = sums_l(nzt,45,tn) + (                &
-                                          ( 1.0_wp + 0.61_wp * q(nzt,j,i) -    &
-                                            ql(nzt,j,i) ) *                    &
-                                            surf_def_h(2)%shf(m) +             &
-                                           0.61_wp * pt(nzt,j,i) *             &
-                                           surf_def_h(2)%qsws(m) )&
+                      sums_l(nzt,45,tn) = sums_l(nzt,45,tn) +    (                                 &
+                                          ( 1.0_wp + 0.61_wp * q(nzt,j,i) -                        &
+                                            ql(nzt,j,i) ) *                                        &
+                                            surf_def_h(2)%shf(m) +                                 &
+                                           0.61_wp * pt(nzt,j,i) *                                 &
+                                           surf_def_h(2)%qsws(m) )                                 &
                                            * heatflux_output_conversion(nzt)
                    ENDIF
@@ -1340,11 +1268,11 @@
 !
 !--                   Formula does not work if ql(nzb) /= 0.0
-                      sums_l(nzt,51,tn) = sums_l(nzt,51,tn) + &   ! w"q" (w"qv")
-                                          waterflux_output_conversion(nzt) *   &
+                      sums_l(nzt,51,tn) = sums_l(nzt,51,tn) +              &  ! w"q" (w"qv")
+                                          waterflux_output_conversion(nzt) *                       &
                                           surf_def_h(2)%qsws(m) * rmask(j,i,sr)
                    ENDIF
                 ENDIF
                 IF ( passive_scalar )  THEN
-                   sums_l(nzt,117,tn) = sums_l(nzt,117,tn) + &
+                   sums_l(nzt,117,tn) = sums_l(nzt,117,tn) +                                       &
                                         surf_def_h(2)%ssws(m) * rmask(j,i,sr) ! w"s"
                 ENDIF
@@ -1354,113 +1282,91 @@
 !
 !--          Resolved fluxes (can be computed for all horizontal points)
-!--          NOTE: for simplicity, nzb_s_inner is used below, although strictly
-!--          ----  speaking the following k-loop would have to be split up and
-!--                rearranged according to the staggered grid.
+!--          NOTE: for simplicity, nzb_s_inner is used below, although strictly speaking the
+!--          ----  following k-loop would have to be split up and rearranged according to the
+!--                staggered grid.
              DO  k = nzb, nzt
                 flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 22 ) )
-                ust = 0.5_wp * ( u(k,j,i)   - hom(k,1,1,sr) +                  &
+                ust = 0.5_wp * ( u(k,j,i)   - hom(k,1,1,sr) +                                      &
                                  u(k+1,j,i) - hom(k+1,1,1,sr) )
-                vst = 0.5_wp * ( v(k,j,i)   - hom(k,1,2,sr) +                  &
+                vst = 0.5_wp * ( v(k,j,i)   - hom(k,1,2,sr) +                                      &
                                  v(k+1,j,i) - hom(k+1,1,2,sr) )
-                pts = 0.5_wp * ( pt(k,j,i)   - hom(k,1,4,sr) +                 &
+                pts = 0.5_wp * ( pt(k,j,i)   - hom(k,1,4,sr) +                                     &
                                  pt(k+1,j,i) - hom(k+1,1,4,sr) )
-
+!
 !--             Higher moments
                 !$ACC ATOMIC
-                sums_l(k,35,tn) = sums_l(k,35,tn) + pts * w(k,j,i)**2 *        &
-                                                    rmask(j,i,sr) * flag
-                !$ACC ATOMIC
-                sums_l(k,36,tn) = sums_l(k,36,tn) + pts**2 * w(k,j,i) *        &
-                                                    rmask(j,i,sr) * flag
-
-!
-!--             Salinity flux and density (density does not belong to here,
-!--             but so far there is no other suitable place to calculate)
+                sums_l(k,35,tn) = sums_l(k,35,tn) + pts * w(k,j,i)**2 * rmask(j,i,sr) * flag
+                !$ACC ATOMIC
+                sums_l(k,36,tn) = sums_l(k,36,tn) + pts**2 * w(k,j,i) * rmask(j,i,sr) * flag
+
+!
+!--             Salinity flux and density (density does not belong to here, but so far there is no
+!--             other suitable place to calculate)
 #ifndef _OPENACC
                 IF ( ocean_mode )  THEN
                    IF( .NOT. ws_scheme_sca .OR. sr /= 0 )  THEN
-                      pts = 0.5_wp * ( sa(k,j,i)   - hom(k,1,23,sr) +          &
+                      pts = 0.5_wp * ( sa(k,j,i)   - hom(k,1,23,sr) +                              &
                                        sa(k+1,j,i) - hom(k+1,1,23,sr) )
-                      sums_l(k,66,tn) = sums_l(k,66,tn) + pts * w(k,j,i) *     &
+                      sums_l(k,66,tn) = sums_l(k,66,tn) + pts * w(k,j,i) *                         &
                                         rmask(j,i,sr) * flag
                    ENDIF
-                   sums_l(k,64,tn) = sums_l(k,64,tn) + rho_ocean(k,j,i) *      &
-                                                       rmask(j,i,sr) * flag
-                   sums_l(k,71,tn) = sums_l(k,71,tn) + prho(k,j,i) *           &
-                                                       rmask(j,i,sr) * flag
-                ENDIF
-
-!
-!--             Buoyancy flux, water flux, humidity flux, liquid water
-!--             content, rain drop concentration and rain water content
+                   sums_l(k,64,tn) = sums_l(k,64,tn) + rho_ocean(k,j,i) * rmask(j,i,sr) * flag
+                   sums_l(k,71,tn) = sums_l(k,71,tn) + prho(k,j,i)      * rmask(j,i,sr) * flag
+                ENDIF
+
+!
+!--             Buoyancy flux, water flux, humidity flux, liquid water content, rain drop
+!--             concentration and rain water content
                 IF ( humidity )  THEN
-                   IF ( bulk_cloud_model .OR. cloud_droplets )  THEN
-                      pts = 0.5_wp * ( vpt(k,j,i)   - hom(k,1,44,sr) +         &
-                                    vpt(k+1,j,i) - hom(k+1,1,44,sr) )
-                      sums_l(k,46,tn) = sums_l(k,46,tn) + pts * w(k,j,i) *     &
-                                               rho_air_zw(k) *                 &
-                                               heatflux_output_conversion(k) * &
+                   IF ( bulk_cloud_model  .OR.  cloud_droplets )  THEN
+                      pts = 0.5_wp * ( vpt(k,j,i)   - hom(k,1,44,sr) +                             &
+                                       vpt(k+1,j,i) - hom(k+1,1,44,sr) )
+                      sums_l(k,46,tn) = sums_l(k,46,tn) + pts * w(k,j,i) *                         &
+                                                          rho_air_zw(k) *                          &
+                                                          heatflux_output_conversion(k) *          &
                                                           rmask(j,i,sr) * flag
-                      sums_l(k,54,tn) = sums_l(k,54,tn) + ql(k,j,i) * rmask(j,i,sr) &
-                                                                    * flag
+                      sums_l(k,54,tn) = sums_l(k,54,tn) + ql(k,j,i) * rmask(j,i,sr) * flag
 
                       IF ( .NOT. cloud_droplets )  THEN
-                         pts = 0.5_wp *                                        &
-                              ( ( q(k,j,i) - ql(k,j,i) ) -                     &
-                              hom(k,1,42,sr) +                                 &
-                              ( q(k+1,j,i) - ql(k+1,j,i) ) -                   &
-                              hom(k+1,1,42,sr) )
-                         sums_l(k,52,tn) = sums_l(k,52,tn) + pts * w(k,j,i) *  &
-                                             rho_air_zw(k) *                   &
-                                             waterflux_output_conversion(k) *  &
-                                                             rmask(j,i,sr)  *  &
-                                                             flag
-                         sums_l(k,75,tn) = sums_l(k,75,tn) + qc(k,j,i) *       &
-                                                             rmask(j,i,sr) *   &
-                                                             flag
-                         sums_l(k,76,tn) = sums_l(k,76,tn) + prr(k,j,i) *      &
-                                                             rmask(j,i,sr) *   &
-                                                             flag
+                         pts = 0.5_wp *                                                            &
+                               ( ( q(k,j,i) - ql(k,j,i) ) -                                        &
+                               hom(k,1,42,sr) +                                                    &
+                               ( q(k+1,j,i) - ql(k+1,j,i) ) -                                      &
+                               hom(k+1,1,42,sr) )
+                         sums_l(k,52,tn) = sums_l(k,52,tn) + pts * w(k,j,i) *                      &
+                                             rho_air_zw(k) *                                       &
+                                             waterflux_output_conversion(k) *                      &
+                                             rmask(j,i,sr) * flag
+                         sums_l(k,75,tn) = sums_l(k,75,tn) + qc(k,j,i)  * rmask(j,i,sr) * flag
+                         sums_l(k,76,tn) = sums_l(k,76,tn) + prr(k,j,i) * rmask(j,i,sr) * flag
                          IF ( microphysics_morrison )  THEN
-                            sums_l(k,123,tn) = sums_l(k,123,tn) + nc(k,j,i) *  &
-                                                                rmask(j,i,sr) *&
-                                                                flag
+                            sums_l(k,123,tn) = sums_l(k,123,tn) + nc(k,j,i) * rmask(j,i,sr) * flag
                          ENDIF
                          IF ( microphysics_ice_phase )  THEN
-                            sums_l(k,124,tn) = sums_l(k,124,tn) + ni(k,j,i) *  &
-                                                                rmask(j,i,sr) *&
-                                                                flag
-                            sums_l(k,125,tn) = sums_l(k,125,tn) + qi(k,j,i) *  &
-                                                                rmask(j,i,sr) *&
-                                                                flag
+                            sums_l(k,124,tn) = sums_l(k,124,tn) + ni(k,j,i) * rmask(j,i,sr) * flag
+                            sums_l(k,125,tn) = sums_l(k,125,tn) + qi(k,j,i) * rmask(j,i,sr) * flag
                          ENDIF
 
                          IF ( microphysics_seifert )  THEN
-                            sums_l(k,73,tn) = sums_l(k,73,tn) + nr(k,j,i) *    &
-                                                                rmask(j,i,sr) *&
-                                                                flag
-                            sums_l(k,74,tn) = sums_l(k,74,tn) + qr(k,j,i) *    &
-                                                                rmask(j,i,sr) *&
-                                                                flag
+                            sums_l(k,73,tn) = sums_l(k,73,tn) + nr(k,j,i) * rmask(j,i,sr) * flag
+                            sums_l(k,74,tn) = sums_l(k,74,tn) + qr(k,j,i) * rmask(j,i,sr) * flag
                          ENDIF
                       ENDIF
 
                    ELSE
-                      IF( .NOT. ws_scheme_sca .OR. sr /= 0 )  THEN
-                         pts = 0.5_wp * ( vpt(k,j,i)   - hom(k,1,44,sr) +      &
+                      IF( .NOT. ws_scheme_sca  .OR.  sr /= 0 )  THEN
+                         pts = 0.5_wp * ( vpt(k,j,i)   - hom(k,1,44,sr) +                          &
                                           vpt(k+1,j,i) - hom(k+1,1,44,sr) )
-                         sums_l(k,46,tn) = sums_l(k,46,tn) + pts * w(k,j,i) *  &
-                                              rho_air_zw(k) *                  &
-                                              heatflux_output_conversion(k) *  &
-                                                             rmask(j,i,sr)  *  &
-                                                             flag
-                      ELSE IF ( ws_scheme_sca .AND. sr == 0 )  THEN
-                         sums_l(k,46,tn) = ( ( 1.0_wp + 0.61_wp *              &
-                                               hom(k,1,41,sr) ) *              &
-                                             sums_l(k,17,tn) +                 &
-                                             0.61_wp * hom(k,1,4,sr) *         &
-                                             sums_l(k,49,tn)                   &
-                                           ) * heatflux_output_conversion(k) * &
-                                               flag
+                         sums_l(k,46,tn) = sums_l(k,46,tn) + pts * w(k,j,i) *                      &
+                                                             rho_air_zw(k)  *                      &
+                                                             heatflux_output_conversion(k) *       &
+                                                             rmask(j,i,sr)  * flag
+                      ELSE IF ( ws_scheme_sca  .AND.  sr == 0 )  THEN
+                         sums_l(k,46,tn) = ( ( 1.0_wp + 0.61_wp *                                  &
+                                               hom(k,1,41,sr) ) *                                  &
+                                             sums_l(k,17,tn) +                                     &
+                                             0.61_wp * hom(k,1,4,sr) *                             &
+                                             sums_l(k,49,tn)                                       &
+                                           ) * heatflux_output_conversion(k) * flag
                       END IF
                    END IF
@@ -1468,10 +1374,8 @@
 !
 !--             Passive scalar flux
-                IF ( passive_scalar .AND. ( .NOT. ws_scheme_sca                &
-                     .OR. sr /= 0 ) )  THEN
-                   pts = 0.5_wp * ( s(k,j,i)   - hom(k,1,115,sr) +             &
+                IF ( passive_scalar  .AND.  ( .NOT. ws_scheme_sca .OR. sr /= 0 ) )  THEN
+                   pts = 0.5_wp * ( s(k,j,i)   - hom(k,1,115,sr) +                                 &
                                     s(k+1,j,i) - hom(k+1,1,115,sr) )
-                   sums_l(k,114,tn) = sums_l(k,114,tn) + pts * w(k,j,i) *      &
-                                                       rmask(j,i,sr) * flag
+                   sums_l(k,114,tn) = sums_l(k,114,tn) + pts * w(k,j,i) * rmask(j,i,sr) * flag
                 ENDIF
 #endif
@@ -1481,9 +1385,9 @@
 !--             has to be adjusted
                 !$ACC ATOMIC
-                sums_l(k,37,tn) = sums_l(k,37,tn) + w(k,j,i) * 0.5_wp *        &
-                                             ( ust**2 + vst**2 + w(k,j,i)**2 ) &
-                                           * rho_air_zw(k)                     &
-                                           * momentumflux_output_conversion(k) &
-                                           * rmask(j,i,sr) * flag
+                sums_l(k,37,tn) = sums_l(k,37,tn) + w(k,j,i) * 0.5_wp *                            &
+                                                    ( ust**2 + vst**2 + w(k,j,i)**2 )              &
+                                                    * rho_air_zw(k)                                &
+                                                    * momentumflux_output_conversion(k)            &
+                                                    * rmask(j,i,sr) * flag
              ENDDO
           ENDDO
@@ -1505,6 +1409,5 @@
              j = surf_lsm_h%j(m)
 
-             IF ( i >= nxl  .AND.  i <= nxr  .AND.                             &
-                  j >= nys  .AND.  j <= nyn )  THEN
+             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%ghf(m)       * rmask(j,i,sr)
                 sums_l(nzb,94,tn)  = sums_l(nzb,94,tn) + surf_lsm_h%qsws_liq(m)  * rmask(j,i,sr)
@@ -1526,12 +1429,9 @@
              j = surf_lsm_h%j(m)
 
-             IF ( i >= nxl  .AND.  i <= nxr  .AND.                             &
-                  j >= nys  .AND.  j <= nyn )  THEN
+             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%var_2d(k,m)  &
-                                      * rmask(j,i,sr)
-                   sums_l(k,91,tn)  = sums_l(k,91,tn)  + m_soil_h%var_2d(k,m)  &
-                                      * rmask(j,i,sr)
+                   sums_l(k,89,tn)  = sums_l(k,89,tn)  + t_soil_h%var_2d(k,m) * rmask(j,i,sr)
+                   sums_l(k,91,tn)  = sums_l(k,91,tn)  + m_soil_h%var_2d(k,m) * rmask(j,i,sr)
                 ENDDO
              ENDIF
@@ -1540,6 +1440,6 @@
        ENDIF
 !
-!--    For speed optimization fluxes which have been computed in part directly
-!--    inside the WS advection routines are treated seperatly
+!--    For speed optimization fluxes which have been computed in part directly inside the WS
+!--    advection routines are treated seperatly.
 !--    Momentum fluxes first:
 
@@ -1553,30 +1453,27 @@
                 DO  k = nzb, nzt
 !
-!--                Flag 23 is used to mask surface fluxes as well as model-top
-!--                fluxes, which are added further below.
-                   flag = MERGE( 1.0_wp, 0.0_wp,                               &
-                                 BTEST( wall_flags_total_0(k,j,i), 23 ) ) *    &
-                          MERGE( 1.0_wp, 0.0_wp,                               &
-                                 BTEST( wall_flags_total_0(k,j,i), 9  ) )
-
-                   ust = 0.5_wp * ( u(k,j,i)   - hom(k,1,1,sr) +               &
+!--                Flag 23 is used to mask surface fluxes as well as model-top fluxes, which are
+!--                added further below.
+                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 23 ) ) *        &
+                          MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 9  ) )
+
+                   ust = 0.5_wp * ( u(k,j,i)   - hom(k,1,1,sr) +                                   &
                                     u(k+1,j,i) - hom(k+1,1,1,sr) )
-                   vst = 0.5_wp * ( v(k,j,i)   - hom(k,1,2,sr) +               &
+                   vst = 0.5_wp * ( v(k,j,i)   - hom(k,1,2,sr) +                                   &
                                     v(k+1,j,i) - hom(k+1,1,2,sr) )
 !
 !--                Momentum flux w*u*
-                   sums_l(k,13,tn) = sums_l(k,13,tn) + 0.5_wp *                &
-                                                     ( w(k,j,i-1) + w(k,j,i) ) &
-                                           * rho_air_zw(k)                     &
-                                           * momentumflux_output_conversion(k) &
-                                                     * ust * rmask(j,i,sr)     &
+                   sums_l(k,13,tn) = sums_l(k,13,tn) + 0.5_wp *                                    &
+                                                     ( w(k,j,i-1) + w(k,j,i) )                     &
+                                                     * rho_air_zw(k)                               &
+                                                     * momentumflux_output_conversion(k)           &
+                                                     * ust * rmask(j,i,sr)                         &
                                                            * flag
 !
 !--                Momentum flux w*v*
-                   sums_l(k,15,tn) = sums_l(k,15,tn) + 0.5_wp *                &
-                                                     ( w(k,j-1,i) + w(k,j,i) ) &
-                                           * rho_air_zw(k)                     &
-                                           * momentumflux_output_conversion(k) &
-                                                     * vst * rmask(j,i,sr)     &
+                   sums_l(k,15,tn) = sums_l(k,15,tn) + 0.5_wp * ( w(k,j-1,i) + w(k,j,i) )          &
+                                                     * rho_air_zw(k)                               &
+                                                     * momentumflux_output_conversion(k)           &
+                                                     * vst * rmask(j,i,sr)                         &
                                                            * flag
                 ENDDO
@@ -1590,29 +1487,26 @@
              DO  j = nys, nyn
                 DO  k = nzb, nzt
-                   flag = MERGE( 1.0_wp, 0.0_wp,                               &
-                                 BTEST( wall_flags_total_0(k,j,i), 23 ) ) *    &
-                          MERGE( 1.0_wp, 0.0_wp,                               &
-                                 BTEST( wall_flags_total_0(k,j,i), 9  ) )
+                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 23 ) ) *        &
+                          MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 9  ) )
 !
 !--                Vertical heat flux
-                   sums_l(k,17,tn) = sums_l(k,17,tn) + 0.5_wp *                &
-                           ( pt(k,j,i)   - hom(k,1,4,sr) +                     &
-                             pt(k+1,j,i) - hom(k+1,1,4,sr) )                   &
-                           * rho_air_zw(k)                                     &
-                           * heatflux_output_conversion(k)                     &
-                           * w(k,j,i) * rmask(j,i,sr) * flag
+                   sums_l(k,17,tn) = sums_l(k,17,tn) + 0.5_wp *                                    &
+                                     ( pt(k,j,i)   - hom(k,1,4,sr) +                               &
+                                       pt(k+1,j,i) - hom(k+1,1,4,sr) )                             &
+                                     * rho_air_zw(k)                                               &
+                                     * heatflux_output_conversion(k)                               &
+                                     * w(k,j,i) * rmask(j,i,sr) * flag
                    IF ( humidity )  THEN
-                      pts = 0.5_wp * ( q(k,j,i)   - hom(k,1,41,sr) +           &
-                                      q(k+1,j,i) - hom(k+1,1,41,sr) )
-                      sums_l(k,49,tn) = sums_l(k,49,tn) + pts * w(k,j,i) *     &
-                                       rho_air_zw(k) *                         &
-                                       waterflux_output_conversion(k) *        &
-                                       rmask(j,i,sr) * flag
+                      pts = 0.5_wp * ( q(k,j,i)   - hom(k,1,41,sr) +                               &
+                                       q(k+1,j,i) - hom(k+1,1,41,sr) )
+                      sums_l(k,49,tn) = sums_l(k,49,tn) + pts * w(k,j,i) *                         &
+                                                          rho_air_zw(k)  *                         &
+                                                          waterflux_output_conversion(k) *         &
+                                                          rmask(j,i,sr)  * flag
                    ENDIF
                    IF ( passive_scalar )  THEN
-                      pts = 0.5_wp * ( s(k,j,i)   - hom(k,1,115,sr) +           &
-                                      s(k+1,j,i) - hom(k+1,1,115,sr) )
-                      sums_l(k,114,tn) = sums_l(k,114,tn) + pts * w(k,j,i) *    &
-                                        rmask(j,i,sr) * flag
+                      pts = 0.5_wp * ( s(k,j,i)   - hom(k,1,115,sr) +                              &
+                                       s(k+1,j,i) - hom(k+1,1,115,sr) )
+                      sums_l(k,114,tn) = sums_l(k,114,tn) + pts * w(k,j,i) *  rmask(j,i,sr) * flag
                    ENDIF
                 ENDDO
@@ -1630,10 +1524,9 @@
 
 !
-!--    Divergence of vertical flux of resolved scale energy and pressure
-!--    fluctuations as well as flux of pressure fluctuation itself (68).
+!--    Divergence of vertical flux of resolved scale energy and pressure fluctuations as well as
+!--    flux of pressure fluctuation itself (68).
 !--    First calculate the products, then the divergence.
 !--    Calculation is time consuming. Do it only, if profiles shall be plotted.
-       IF ( hom(nzb+1,2,55,0) /= 0.0_wp  .OR.  hom(nzb+1,2,68,0) /= 0.0_wp )   &
-       THEN
+       IF ( hom(nzb+1,2,55,0) /= 0.0_wp  .OR.  hom(nzb+1,2,68,0) /= 0.0_wp )  THEN
           sums_ll = 0.0_wp  ! local array
 
@@ -1644,14 +1537,14 @@
                    flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
 
-                   sums_ll(k,1) = sums_ll(k,1) + 0.5_wp * w(k,j,i) * (         &
-                  ( 0.25_wp * ( u(k,j,i)+u(k+1,j,i)+u(k,j,i+1)+u(k+1,j,i+1) )  &
-                            - 0.5_wp * ( hom(k,1,1,sr) + hom(k+1,1,1,sr) ) )**2&
-                + ( 0.25_wp * ( v(k,j,i)+v(k+1,j,i)+v(k,j+1,i)+v(k+1,j+1,i) )  &
-                            - 0.5_wp * ( hom(k,1,2,sr) + hom(k+1,1,2,sr) ) )**2&
-                + w(k,j,i)**2                                        ) * flag * rmask(j,i,sr)
-
-                   sums_ll(k,2) = sums_ll(k,2) + 0.5_wp * w(k,j,i)             &
-                                       * ( ( p(k,j,i) + p(k+1,j,i) )           &
-                                         / momentumflux_output_conversion(k) ) &
+                   sums_ll(k,1) = sums_ll(k,1) + 0.5_wp * w(k,j,i) * (                             &
+                                    ( 0.25_wp * ( u(k,j,i)+u(k+1,j,i)+u(k,j,i+1)+u(k+1,j,i+1) )    &
+                                              - 0.5_wp * ( hom(k,1,1,sr) + hom(k+1,1,1,sr) ) )**2  &
+                                  + ( 0.25_wp * ( v(k,j,i)+v(k+1,j,i)+v(k,j+1,i)+v(k+1,j+1,i) )    &
+                                              - 0.5_wp * ( hom(k,1,2,sr) + hom(k+1,1,2,sr) ) )**2  &
+                                  + w(k,j,i)**2                      ) * flag * rmask(j,i,sr)
+
+                   sums_ll(k,2) = sums_ll(k,2) + 0.5_wp * w(k,j,i)                                 &
+                                       * ( ( p(k,j,i) + p(k+1,j,i) )                               &
+                                         / momentumflux_output_conversion(k) )                     &
                                        * flag * rmask(j,i,sr)
 
@@ -1677,6 +1570,5 @@
 !
 !--    Divergence of vertical flux of SGS TKE and the flux itself (69)
-       IF ( hom(nzb+1,2,57,0) /= 0.0_wp  .OR.  hom(nzb+1,2,69,0) /= 0.0_wp )   &
-       THEN
+       IF ( hom(nzb+1,2,57,0) /= 0.0_wp  .OR.  hom(nzb+1,2,69,0) /= 0.0_wp )  THEN
           !$OMP DO
           DO  i = nxl, nxr
@@ -1686,13 +1578,14 @@
                    flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
 
-                   sums_l(k,57,tn) = sums_l(k,57,tn) - 0.5_wp * (              &
-                   (km(k,j,i)+km(k+1,j,i)) * (e(k+1,j,i)-e(k,j,i)) * ddzu(k+1) &
-                 - (km(k-1,j,i)+km(k,j,i)) * (e(k,j,i)-e(k-1,j,i)) * ddzu(k)   &
-                                                                ) * ddzw(k)    &
+                   sums_l(k,57,tn) = sums_l(k,57,tn) - 0.5_wp * (                                  &
+                                       (km(k,j,i)+km(k+1,j,i)) * (e(k+1,j,i)-e(k,j,i)) * ddzu(k+1) &
+                                     - (km(k-1,j,i)+km(k,j,i)) * (e(k,j,i)-e(k-1,j,i)) * ddzu(k)   &
+                                                                ) * ddzw(k)                        &
                                                                   * flag * rmask(j,i,sr)
 
-                   sums_l(k,69,tn) = sums_l(k,69,tn) - 0.5_wp * (              &
-                   (km(k,j,i)+km(k+1,j,i)) * (e(k+1,j,i)-e(k,j,i)) * ddzu(k+1) &
-                                                                )  * flag * rmask(j,i,sr)
+                   sums_l(k,69,tn) = sums_l(k,69,tn) - 0.5_wp * (                                  &
+                                        ( km(k,j,i) + km(k+1,j,i) ) *                              &
+                                        ( e(k+1,j,i) - e(k,j,i) ) * ddzu(k+1)                      &
+                                                                ) * flag * rmask(j,i,sr)
 
                 ENDDO
@@ -1716,32 +1609,30 @@
 !
 !--                Subgrid horizontal heat fluxes u"pt", v"pt"
-                   sums_l(k,58,tn) = sums_l(k,58,tn) - 0.5_wp *                &
-                                                   ( kh(k,j,i) + kh(k,j,i-1) ) &
-                                                 * ( pt(k,j,i-1) - pt(k,j,i) ) &
-                                               * rho_air_zw(k)                 &
-                                               * heatflux_output_conversion(k) &
-                                                 * ddx * rmask(j,i,sr) * flag
-                   sums_l(k,61,tn) = sums_l(k,61,tn) - 0.5_wp *                &
-                                                   ( kh(k,j,i) + kh(k,j-1,i) ) &
-                                                 * ( pt(k,j-1,i) - pt(k,j,i) ) &
-                                               * rho_air_zw(k)                 &
-                                               * heatflux_output_conversion(k) &
-                                                 * ddy * rmask(j,i,sr) * flag
+                   sums_l(k,58,tn) = sums_l(k,58,tn) - 0.5_wp *                                    &
+                                                        ( kh(k,j,i) + kh(k,j,i-1) )                &
+                                                      * ( pt(k,j,i-1) - pt(k,j,i) )                &
+                                                      * rho_air_zw(k)                              &
+                                                      * heatflux_output_conversion(k)              &
+                                                      * ddx * rmask(j,i,sr) * flag
+                   sums_l(k,61,tn) = sums_l(k,61,tn) - 0.5_wp *                                    &
+                                                        ( kh(k,j,i) + kh(k,j-1,i) )                &
+                                                      * ( pt(k,j-1,i) - pt(k,j,i) )                &
+                                                      * rho_air_zw(k)                              &
+                                                      * heatflux_output_conversion(k)              &
+                                                      * ddy * rmask(j,i,sr) * flag
 !
 !--                Resolved horizontal heat fluxes u*pt*, v*pt*
-                   sums_l(k,59,tn) = sums_l(k,59,tn) +                         &
-                                                  ( u(k,j,i) - hom(k,1,1,sr) ) &
-                                    * 0.5_wp * ( pt(k,j,i-1) - hom(k,1,4,sr) + &
-                                                 pt(k,j,i)   - hom(k,1,4,sr) ) &
-                                               * heatflux_output_conversion(k) &
-                                               * flag
-                   pts = 0.5_wp * ( pt(k,j-1,i) - hom(k,1,4,sr) +              &
+                   sums_l(k,59,tn) = sums_l(k,59,tn) +              ( u(k,j,i) - hom(k,1,1,sr) )   &
+                                                      * 0.5_wp * ( pt(k,j,i-1) - hom(k,1,4,sr) +   &
+                                                                   pt(k,j,i)   - hom(k,1,4,sr) )   &
+                                                                 * heatflux_output_conversion(k)   &
+                                                                 * flag
+                   pts = 0.5_wp * ( pt(k,j-1,i) - hom(k,1,4,sr) +                                  &
                                     pt(k,j,i)   - hom(k,1,4,sr) )
-                   sums_l(k,62,tn) = sums_l(k,62,tn) +                         &
-                                                  ( v(k,j,i) - hom(k,1,2,sr) ) &
-                                    * 0.5_wp * ( pt(k,j-1,i) - hom(k,1,4,sr) + &
-                                                 pt(k,j,i)   - hom(k,1,4,sr) ) &
-                                               * heatflux_output_conversion(k) &
-                                               * flag
+                   sums_l(k,62,tn) = sums_l(k,62,tn) +              ( v(k,j,i) - hom(k,1,2,sr) )   &
+                                                      * 0.5_wp * ( pt(k,j-1,i) - hom(k,1,4,sr) +   &
+                                                                   pt(k,j,i)   - hom(k,1,4,sr) )   &
+                                                                 * heatflux_output_conversion(k)   &
+                                                                 * flag
                 ENDDO
              ENDDO
@@ -1773,13 +1664,10 @@
           ENDIF
 
-          fac = ( simulated_time - dt_3d - time_vert(nt) )                     &
-                / ( time_vert(nt+1)-time_vert(nt) )
+          fac = ( simulated_time - dt_3d - time_vert(nt) ) / ( time_vert(nt+1)-time_vert(nt) )
 
 
           DO  k = nzb, nzt
-             sums_ls_l(k,0) = td_lsa_lpt(k,nt)                                 &
-                              + fac * ( td_lsa_lpt(k,nt+1) - td_lsa_lpt(k,nt) )
-             sums_ls_l(k,1) = td_lsa_q(k,nt)                                   &
-                              + fac * ( td_lsa_q(k,nt+1) - td_lsa_q(k,nt) )
+             sums_ls_l(k,0) = td_lsa_lpt(k,nt) + fac * ( td_lsa_lpt(k,nt+1) - td_lsa_lpt(k,nt) )
+             sums_ls_l(k,1) = td_lsa_q(k,nt)   + fac * ( td_lsa_q(k,nt+1)   - td_lsa_q(k,nt) )
           ENDDO
 
@@ -1787,11 +1675,9 @@
           sums_ls_l(nzt+1,1) = sums_ls_l(nzt,1)
 
-          IF ( large_scale_subsidence .AND. use_subsidence_tendencies )  THEN
+          IF ( large_scale_subsidence  .AND.  use_subsidence_tendencies )  THEN
 
              DO  k = nzb, nzt
-                sums_ls_l(k,2) = td_sub_lpt(k,nt) + fac *                      &
-                                 ( td_sub_lpt(k,nt+1) - td_sub_lpt(k,nt) )
-                sums_ls_l(k,3) = td_sub_q(k,nt) + fac *                        &
-                                 ( td_sub_q(k,nt+1) - td_sub_q(k,nt) )
+                sums_ls_l(k,2) = td_sub_lpt(k,nt) + fac * ( td_sub_lpt(k,nt+1) - td_sub_lpt(k,nt) )
+                sums_ls_l(k,3) = td_sub_q(k,nt)   + fac * ( td_sub_q(k,nt+1)   - td_sub_q(k,nt) )
              ENDDO
 
@@ -1806,5 +1692,5 @@
        !$OMP PARALLEL PRIVATE( i, j, k, tn )
        !$ tn = omp_get_thread_num()
-       IF ( radiation .AND. radiation_scheme == 'rrtmg' )  THEN
+       IF ( radiation  .AND.  radiation_scheme == 'rrtmg' )  THEN
           !$OMP DO
           DO  i = nxl, nxr
@@ -1813,20 +1699,12 @@
                    flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
 
-                   sums_l(k,100,tn)  = sums_l(k,100,tn)  + rad_lw_in(k,j,i)    &
-                                       * rmask(j,i,sr) * flag
-                   sums_l(k,101,tn)  = sums_l(k,101,tn)  + rad_lw_out(k,j,i)   &
-                                       * rmask(j,i,sr) * flag
-                   sums_l(k,102,tn)  = sums_l(k,102,tn)  + rad_sw_in(k,j,i)    &
-                                       * rmask(j,i,sr) * flag
-                   sums_l(k,103,tn)  = sums_l(k,103,tn)  + rad_sw_out(k,j,i)   &
-                                       * rmask(j,i,sr) * flag
-                   sums_l(k,104,tn)  = sums_l(k,104,tn)  + rad_lw_cs_hr(k,j,i) &
-                                       * rmask(j,i,sr) * flag
-                   sums_l(k,105,tn)  = sums_l(k,105,tn)  + rad_lw_hr(k,j,i)    &
-                                       * rmask(j,i,sr) * flag
-                   sums_l(k,106,tn)  = sums_l(k,106,tn)  + rad_sw_cs_hr(k,j,i) &
-                                       * rmask(j,i,sr) * flag
-                   sums_l(k,107,tn)  = sums_l(k,107,tn)  + rad_sw_hr(k,j,i)    &
-                                       * rmask(j,i,sr) * flag
+                   sums_l(k,100,tn)  = sums_l(k,100,tn) + rad_lw_in(k,j,i)    * rmask(j,i,sr) * flag
+                   sums_l(k,101,tn)  = sums_l(k,101,tn) + rad_lw_out(k,j,i)   * rmask(j,i,sr) * flag
+                   sums_l(k,102,tn)  = sums_l(k,102,tn) + rad_sw_in(k,j,i)    * rmask(j,i,sr) * flag
+                   sums_l(k,103,tn)  = sums_l(k,103,tn) + rad_sw_out(k,j,i)   * rmask(j,i,sr) * flag
+                   sums_l(k,104,tn)  = sums_l(k,104,tn) + rad_lw_cs_hr(k,j,i) * rmask(j,i,sr) * flag
+                   sums_l(k,105,tn)  = sums_l(k,105,tn) + rad_lw_hr(k,j,i)    * rmask(j,i,sr) * flag
+                   sums_l(k,106,tn)  = sums_l(k,106,tn) + rad_sw_cs_hr(k,j,i) * rmask(j,i,sr) * flag
+                   sums_l(k,107,tn)  = sums_l(k,107,tn) + rad_sw_hr(k,j,i)    * rmask(j,i,sr) * flag
                 ENDDO
              ENDDO
@@ -1848,7 +1726,7 @@
                                       sums_l(:,45:pr_palm,i)
              IF ( max_pr_user > 0 )  THEN
-                sums_l(:,pr_palm+1:pr_palm+max_pr_user,0) = &
-                                   sums_l(:,pr_palm+1:pr_palm+max_pr_user,0) + &
-                                   sums_l(:,pr_palm+1:pr_palm+max_pr_user,i)
+                sums_l(:,pr_palm+1:pr_palm+max_pr_user,0) =                                        &
+                                                       sums_l(:,pr_palm+1:pr_palm+max_pr_user,0) + &
+                                                       sums_l(:,pr_palm+1:pr_palm+max_pr_user,i)
              ENDIF
 
@@ -1877,9 +1755,8 @@
 !--    Compute total sum from local sums
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( sums_l(nzb,1,0), sums(nzb,1), ngp_sums, MPI_REAL,   &
-                           MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( sums_l(nzb,1,0), sums(nzb,1), ngp_sums, MPI_REAL, MPI_SUM, comm2d, ierr )
        IF ( large_scale_forcing )  THEN
-          CALL MPI_ALLREDUCE( sums_ls_l(nzb,2), sums(nzb,83), ngp_sums_ls,     &
-                              MPI_REAL, MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( sums_ls_l(nzb,2), sums(nzb,83), ngp_sums_ls, MPI_REAL, MPI_SUM,      &
+                              comm2d, ierr )
        ENDIF
 
@@ -1887,6 +1764,6 @@
           IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
           DO  i = 1, max_pr_cs
-             CALL MPI_ALLREDUCE( sums_l(nzb,pr_palm+max_pr_user+i,0),          &
-                                 sums(nzb,pr_palm+max_pr_user+i),              &
+             CALL MPI_ALLREDUCE( sums_l(nzb,pr_palm+max_pr_user+i,0),                              &
+                                 sums(nzb,pr_palm+max_pr_user+i),                                  &
                                  nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d, ierr )
           ENDDO
@@ -1910,9 +1787,9 @@
 
 !
-!--    Final values are obtained by division by the total number of grid points
-!--    used for summation. After that store profiles.
-!--    Check, if statistical regions do contain at least one grid point at the
-!--    respective k-level, otherwise division by zero will lead to undefined
-!--    values, which may cause e.g. problems with NetCDF output
+!--    Final values are obtained by division by the total number of grid points used for summation.
+!--    After that store profiles.
+!--    Check, if statistical regions do contain at least one grid point at the respective k-level,
+!--    otherwise division by zero will lead to undefined values, which may cause e.g. problems with
+!--    NetCDF output.
 !--    Profiles:
        DO  k = nzb, nzt+1
@@ -1942,42 +1819,36 @@
 
 !--    u* and so on
-!--    As sums(nzb:nzb+3,pr_palm) are full 2D arrays (us, usws, vsws, ts) whose
-!--    size is always ( nx + 1 ) * ( ny + 1 ), defined at the first grid layer
-!--    above the topography, they are being divided by ngp_2dh(sr)
-       sums(nzb:nzb+3,pr_palm)    = sums(nzb:nzb+3,pr_palm)    / &
-                                    ngp_2dh(sr)
-       sums(nzb+12,pr_palm)       = sums(nzb+12,pr_palm)       / &    ! qs
-                                    ngp_2dh(sr)
-       sums(nzb+13,pr_palm)       = sums(nzb+13,pr_palm)       / &    ! ss
-                                    ngp_2dh(sr)
-       sums(nzb+14,pr_palm)       = sums(nzb+14,pr_palm)       / &    ! surface temperature
-                                    ngp_2dh(sr)
+!--    As sums(nzb:nzb+3,pr_palm) are full 2D arrays (us, usws, vsws, ts) whose size is always
+!--    ( nx + 1 ) * ( ny + 1 ), defined at the first grid layer above the topography, they are
+!--    divided by ngp_2dh(sr)
+       sums(nzb:nzb+3,pr_palm)    = sums(nzb:nzb+3,pr_palm)  /  ngp_2dh(sr)
+       sums(nzb+12,pr_palm)       = sums(nzb+12,pr_palm)     /  ngp_2dh(sr)    ! qs
+       sums(nzb+13,pr_palm)       = sums(nzb+13,pr_palm)     /  ngp_2dh(sr)    ! ss
+       sums(nzb+14,pr_palm)       = sums(nzb+14,pr_palm)     /  ngp_2dh(sr)    ! surface temperature
+
 !--    eges, e*
-       sums(nzb+4:nzb+5,pr_palm)  = sums(nzb+4:nzb+5,pr_palm)  / &
-                                    ngp_3d(sr)
+       sums(nzb+4:nzb+5,pr_palm)  = sums(nzb+4:nzb+5,pr_palm)  /  ngp_3d(sr)
 !--    Old and new divergence
-       sums(nzb+9:nzb+10,pr_palm) = sums(nzb+9:nzb+10,pr_palm) / &
-                                    ngp_3d_inner(sr)
+       sums(nzb+9:nzb+10,pr_palm) = sums(nzb+9:nzb+10,pr_palm) /  ngp_3d_inner(sr)
 
 !--    User-defined profiles
        IF ( max_pr_user > 0 )  THEN
           DO  k = nzb, nzt+1
-             sums(k,pr_palm+1:pr_palm+max_pr_user) = &
-                                    sums(k,pr_palm+1:pr_palm+max_pr_user) / &
-                                    ngp_2dh_s_inner(k,sr)
-          ENDDO
-       ENDIF
-
-       IF ( air_chemistry ) THEN
+             sums(k,pr_palm+1:pr_palm+max_pr_user) =  sums(k,pr_palm+1:pr_palm+max_pr_user) /      &
+                                                      ngp_2dh_s_inner(k,sr)
+          ENDDO
+       ENDIF
+
+       IF ( air_chemistry )  THEN
           IF ( max_pr_cs > 0 )  THEN
              DO k = nzb, nzt+1
-                sums(k, pr_palm+1:pr_palm+max_pr_user+max_pr_cs) = &
-                                 sums(k, pr_palm+1:pr_palm+max_pr_user+max_pr_cs) / &
-                                 ngp_2dh_s_inner(k,sr)
+                sums(k, pr_palm+1:pr_palm+max_pr_user+max_pr_cs) =                                 &
+                                                sums(k, pr_palm+1:pr_palm+max_pr_user+max_pr_cs) / &
+                                                ngp_2dh_s_inner(k,sr)
              ENDDO
           ENDIF
        ENDIF
 
-       IF ( salsa ) THEN
+       IF ( salsa )  THEN
           IF ( max_pr_salsa > 0 )  THEN
              DO k = nzb, nzt+1
@@ -2020,5 +1891,5 @@
        hom(:,1,37,sr) = sums(:,37)     ! w*e*
        hom(:,1,38,sr) = sums(:,38)     ! w*3
-       hom(:,1,39,sr) = sums(:,38) / ( abs( sums(:,32) ) + 1E-20_wp )**1.5_wp   ! Sw
+       hom(:,1,39,sr) = sums(:,38) / ( ABS( sums(:,32) ) + 1E-20_wp )**1.5_wp   ! Sw
        hom(:,1,40,sr) = sums(:,40)     ! p
        hom(:,1,45,sr) = sums(:,45)     ! w"vpt"
@@ -2124,5 +1995,5 @@
        hom(:,1,120,sr) = rho_air_zw    ! rho_air_zw in Kg/m^3
 
-       IF ( kolmogorov_length_scale ) THEN
+       IF ( kolmogorov_length_scale )  THEN
           hom(:,1,121,sr) = sums(:,121) * 1E3_wp  ! eta in mm
        ENDIF
@@ -2152,14 +2023,13 @@
 !
 !--    Determine the boundary layer height using two different schemes.
-!--    First scheme: Starting from the Earth's (Ocean's) surface, look for the
-!--    first relative minimum (maximum) of the total heat flux.
-!--    The corresponding height is assumed as the boundary layer height, if it
-!--    is less than 1.5 times the height where the heat flux becomes negative
-!--    (positive) for the first time. Attention: the resolved vertical sensible
-!--    heat flux (hom(:,1,17,sr) = w*pt*) is not known at the beginning because
-!--    the calculation happens in advec_s_ws which is called after
-!--    flow_statistics. Therefore z_i is directly taken from restart data at
-!--    the beginning of restart runs.
-       IF ( TRIM( initializing_actions ) /= 'read_restart_data' .OR.           &
+!--    First scheme: Starting from the Earth's (Ocean's) surface, look for the first relative
+!--    minimum (maximum) of the total heat flux.
+!--    The corresponding height is assumed as the boundary layer height, if it is less than 1.5
+!--    times the height where the heat flux becomes negative (positive) for the first time.
+!--    Attention: the resolved vertical sensible heat flux (hom(:,1,17,sr) = w*pt*) is not known at
+!--    the beginning because the calculation happens in advec_s_ws which is called after
+!--    flow_statistics. Therefore z_i is directly taken from restart data at the beginning of
+!--    restart runs.
+       IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .OR.                              &
             simulated_time_at_begin /= simulated_time ) THEN
 
@@ -2173,6 +2043,5 @@
                    height = zw(k)
                 ENDIF
-                IF ( hom(k,1,18,sr) < -1.0E-8_wp  .AND.                        &
-                     hom(k-1,1,18,sr) > hom(k,1,18,sr) )  THEN
+                IF ( hom(k,1,18,sr) < -1.0E-8_wp  .AND.  hom(k-1,1,18,sr) > hom(k,1,18,sr) )  THEN
                    IF ( zw(k) < 1.5_wp * height )  THEN
                       z_i(1) = zw(k)
@@ -2189,6 +2058,5 @@
                    height = zw(k)
                 ENDIF
-                IF ( hom(k,1,18,sr) < -1.0E-8_wp  .AND.                        &
-                     hom(k+1,1,18,sr) > hom(k,1,18,sr) )  THEN
+                IF ( hom(k,1,18,sr) < -1.0E-8_wp  .AND.  hom(k+1,1,18,sr) > hom(k,1,18,sr) )  THEN
                    IF ( zw(k) < 1.5_wp * height )  THEN
                       z_i(1) = zw(k)
@@ -2202,9 +2070,8 @@
 
 !
-!--       Second scheme: Gradient scheme from Sullivan et al. (1998), modified
-!--       by Uhlenbrock(2006). The boundary layer height is the height with the
-!--       maximal local temperature gradient: starting from the second (the
-!--       last but one) vertical gridpoint, the local gradient must be at least
-!--       0.2K/100m and greater than the next four gradients.
+!--       Second scheme: Gradient scheme from Sullivan et al. (1998), modified by Uhlenbrock(2006).
+!--       The boundary layer height is the height with the maximal local temperature gradient:
+!--       starting from the second (the last but one) vertical gridpoint, the local gradient must be
+!--       at least 0.2K/100m and greater than the next four gradients.
 !--       WARNING: The threshold value of 0.2K/100m must be adjusted for the
 !--       ocean case!
@@ -2217,6 +2084,6 @@
           IF ( ocean_mode )  THEN
              DO  k = nzt+1, nzb+5, -1
-                IF ( dptdz(k) > dptdz_threshold  .AND.                         &
-                     dptdz(k) > dptdz(k-1)  .AND.  dptdz(k) > dptdz(k-2)  .AND.&
+                IF ( dptdz(k) > dptdz_threshold  .AND.                                             &
+                     dptdz(k) > dptdz(k-1)  .AND.  dptdz(k) > dptdz(k-2)  .AND.                    &
                      dptdz(k) > dptdz(k-3)  .AND.  dptdz(k) > dptdz(k-4) )  THEN
                    z_i(2) = zw(k-1)
@@ -2226,6 +2093,6 @@
           ELSE
              DO  k = nzb+1, nzt-3
-                IF ( dptdz(k) > dptdz_threshold  .AND.                         &
-                     dptdz(k) > dptdz(k+1)  .AND.  dptdz(k) > dptdz(k+2)  .AND.&
+                IF ( dptdz(k) > dptdz_threshold  .AND.                                             &
+                     dptdz(k) > dptdz(k+1)  .AND.  dptdz(k) > dptdz(k+2)  .AND.                    &
                      dptdz(k) > dptdz(k+3)  .AND.  dptdz(k) > dptdz(k+4) )  THEN
                    z_i(2) = zw(k-1)
@@ -2241,6 +2108,6 @@
 
 !
-!--    Determine vertical index which is nearest to the mean surface level
-!--    height of the respective statistic region
+!--    Determine vertical index which is nearest to the mean surface level height of the respective
+!--    statistic region
        DO  k = nzb, nzt
           IF ( zw(k) >= mean_surface_level_height(sr) )  THEN
@@ -2251,17 +2118,15 @@
 
 !
-!--    Computation of both the characteristic vertical velocity and
-!--    the characteristic convective boundary layer temperature.
-!--    The inversion height entering into the equation is defined with respect
-!--    to the mean surface level height of the respective statistic region.
-!--    The horizontal average at surface level index + 1 is input for the
-!--    average temperature.
-       IF ( hom(k_surface_level,1,18,sr) > 1.0E-8_wp  .AND.  z_i(1) /= 0.0_wp )&
-       THEN
-          hom(nzb+8,1,pr_palm,sr) =                                            &
-             ( g / hom(k_surface_level+1,1,4,sr) *                             &
-             ( hom(k_surface_level,1,18,sr) /                                  &
-             ( heatflux_output_conversion(nzb) * rho_air(nzb) ) )              &
-             * ABS( z_i(1) - mean_surface_level_height(sr) ) )**0.333333333_wp
+!--    Computation of both the characteristic vertical velocity and the characteristic convective
+!--    boundary layer temperature.
+!--    The inversion height entering into the equation is defined with respect to the mean surface
+!--    level height of the respective statistic region.
+!--    The horizontal average at surface level index + 1 is input for the average temperature.
+       IF ( hom(k_surface_level,1,18,sr) > 1.0E-8_wp  .AND.  z_i(1) /= 0.0_wp )  THEN
+          hom(nzb+8,1,pr_palm,sr) =                                                                &
+                                   ( g / hom(k_surface_level+1,1,4,sr) *                           &
+                                   ( hom(k_surface_level,1,18,sr) /                                &
+                                   ( heatflux_output_conversion(nzb) * rho_air(nzb) ) )            &
+                                   * ABS( z_i(1) - mean_surface_level_height(sr) ) )**0.333333333_wp
        ELSE
           hom(nzb+8,1,pr_palm,sr)  = 0.0_wp
@@ -2269,9 +2134,8 @@
 
 !
-!--    Collect the time series quantities. Please note, timeseries quantities
-!--    which are collected from horizontally averaged profiles, e.g. wpt
-!--    or pt(zp), are treated specially. In case of elevated model surfaces,
-!--    index nzb+1 might be within topography and data will be zero. Therefore,
-!--    take value for the first atmosphere index, which is topo_min_level+1.
+!--    Collect the time series quantities. Please note, timeseries quantities which are collected
+!--    from horizontally averaged profiles, e.g. wpt or pt(zp), are treated specially. In case of
+!--    elevated model surfaces, index nzb+1 might be within topography and data will be zero.
+!--    Therefore, take value for the first atmosphere index, which is topo_min_level+1.
        ts_value(1,sr) = hom(nzb+4,1,pr_palm,sr)        ! E
        ts_value(2,sr) = hom(nzb+5,1,pr_palm,sr)        ! E*
Index: palm/trunk/SOURCE/global_min_max.f90
===================================================================
--- palm/trunk/SOURCE/global_min_max.f90	(revision 4645)
+++ palm/trunk/SOURCE/global_min_max.f90	(revision 4646)
@@ -1,36 +1,37 @@
-!> @file global_min_max.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! ------------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4429 2020-02-27 15:24:30Z raasch
 ! bugfix: cpp-directives added for serial mode
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! OpenACC support added
-! 
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! Corrected "Former revisions" section
@@ -43,14 +44,14 @@
 ! ------------
 !> Determine the array minimum/maximum and the corresponding indices.
-!------------------------------------------------------------------------------!
- SUBROUTINE global_min_max( i1, i2, j1, j2, k1, k2, ar, mode, offset, value, &
-                            value_ijk, value1, value1_ijk )
- 
-
-    USE indices,                                                               &
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE global_min_max( i1, i2, j1, j2, k1, k2, ar, mode, offset, value, value_ijk, value1,    &
+                            value1_ijk )
+
+
+    USE indices,                                                                                   &
         ONLY:  nbgp, ny, nx
-        
+
     USE kinds
-    
+
     USE pegrid
 
@@ -72,16 +73,19 @@
     INTEGER(iwp) ::  k1             !<
     INTEGER(iwp) ::  k2             !<
-    INTEGER(iwp) ::  fmax_ijk(3)    !<
-    INTEGER(iwp) ::  fmax_ijk_l(3)  !<
-    INTEGER(iwp) ::  fmin_ijk(3)    !<
-    INTEGER(iwp) ::  fmin_ijk_l(3)  !<
     INTEGER(iwp) ::  value_ijk(3)   !<
-    
-    INTEGER(iwp), OPTIONAL ::  value1_ijk(3)  !<
-    
-    REAL(wp) ::  offset                 !<
-    REAL(wp) ::  value                  !<
+
+    INTEGER(iwp), DIMENSION(3) ::  fmax_ijk    !<
+    INTEGER(iwp), DIMENSION(3) ::  fmax_ijk_l  !<
+    INTEGER(iwp), DIMENSION(3) ::  fmin_ijk    !<
+    INTEGER(iwp), DIMENSION(3) ::  fmin_ijk_l  !<
+
+    INTEGER(iwp), DIMENSION(3), OPTIONAL ::  value1_ijk  !<
+
+    REAL(wp) ::  offset            !<
+    REAL(wp) ::  value             !<
+    REAL(wp), OPTIONAL ::  value1  !<
+
     REAL(wp) ::  ar(i1:i2,j1:j2,k1:k2)  !<
-    
+
 #if defined( __ibm )
     REAL(sp) ::  fmax(2)    !<
@@ -89,17 +93,17 @@
     REAL(sp) ::  fmin(2)    !<
     REAL(sp) ::  fmin_l(2)  !<
-             ! on 32bit-machines MPI_2REAL must not be replaced 
+             ! on 32bit-machines MPI_2REAL must not be replaced
              ! by MPI_2DOUBLE_PRECISION
 #else
-    REAL(wp) ::  fmax(2)    !<
-    REAL(wp) ::  fmax_l(2)  !<
-    REAL(wp) ::  fmin(2)    !<
-    REAL(wp) ::  fmin_l(2)  !<
-#endif
+    REAL(wp), DIMENSION(2) ::  fmax    !<
+    REAL(wp), DIMENSION(2) ::  fmax_l  !<
+    REAL(wp), DIMENSION(2) ::  fmin    !<
+    REAL(wp), DIMENSION(2) ::  fmin_l  !<
+#endif
+
 #if defined( _OPENACC )
+    INTEGER(iwp) ::  count_eq   !< counter for locations of maximum
     REAL(wp)     ::  red        !< scalar for reduction with OpenACC
-    INTEGER(iwp) ::  count_eq   !< counter for locations of maximum
-#endif
-    REAL(wp), OPTIONAL ::  value1  !<
+#endif
 
 
@@ -119,6 +123,5 @@
        fmin_l(2)  = myid
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( fmin_l, fmin, 1, MPI_2REAL, MPI_MINLOC, comm2d, &
-                           ierr )
+       CALL MPI_ALLREDUCE( fmin_l, fmin, 1, MPI_2REAL, MPI_MINLOC, comm2d, ierr )
 
 !
@@ -127,6 +130,5 @@
        IF ( id_fmin /= 0 )  THEN
           IF ( myid == 0 )  THEN
-             CALL MPI_RECV( fmin_ijk, 3, MPI_INTEGER, id_fmin, 0, comm2d, &
-                            status, ierr )
+             CALL MPI_RECV( fmin_ijk, 3, MPI_INTEGER, id_fmin, 0, comm2d, status, ierr )
           ELSEIF ( myid == id_fmin )  THEN
              CALL MPI_SEND( fmin_ijk_l, 3, MPI_INTEGER, 0, 0, comm2d, ierr )
@@ -160,6 +162,5 @@
        fmax_l(2)  = myid
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, &
-                           ierr )
+       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, ierr )
 
 !
@@ -168,6 +169,5 @@
        IF ( id_fmax /= 0 )  THEN
           IF ( myid == 0 )  THEN
-             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, &
-                            status, ierr )
+             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, status, ierr )
           ELSEIF ( myid == id_fmax )  THEN
              CALL MPI_SEND( fmax_ijk_l, 3, MPI_INTEGER, 0, 0, comm2d, ierr )
@@ -177,5 +177,5 @@
        ENDIF
 !
-!--    send the indices of the just determined array maximum to other PEs
+!--    Send the indices of the just determined array maximum to other PEs
        CALL MPI_BCAST( fmax_ijk, 3, MPI_INTEGER, 0, comm2d, ierr )
 #else
@@ -226,6 +226,6 @@
        IF ( count_eq == 1 ) THEN
 !
-!--       We found a single maximum element and correctly got its position. Transfer its
-!--       value to handle the negative case correctly.
+!--       We found a single maximum element and correctly got its position. Transfer its value to
+!--       handle the negative case correctly.
           !$ACC UPDATE HOST(ar(fmax_ijk_l(1):fmax_ijk_l(1),fmax_ijk_l(2),fmax_ijk_l(3)))
        ELSE
@@ -257,5 +257,5 @@
 #if defined( _OPENACC )
 !
-!--       Close ELSE case from above
+!--    Close ELSE case from above
        ENDIF
 #endif
@@ -263,6 +263,5 @@
 !
 !--    Set a flag in case that the determined value is negative.
-!--    A constant offset has to be subtracted in order to handle the special
-!--    case i=0 correctly
+!--    A constant offset has to be subtracted in order to handle the special case i=0 correctly.
        IF ( ar(fmax_ijk_l(1),fmax_ijk_l(2),fmax_ijk_l(3)) < 0.0_wp )  THEN
           fmax_ijk_l(1) = -fmax_ijk_l(1) - 10
@@ -272,6 +271,5 @@
        fmax_l(2)  = myid
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, &
-                           ierr )
+       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, ierr )
 
 !
@@ -280,6 +278,5 @@
        IF ( id_fmax /= 0 )  THEN
           IF ( myid == 0 )  THEN
-             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, &
-                            status, ierr )
+             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, status, ierr )
           ELSEIF ( myid == id_fmax )  THEN
              CALL MPI_SEND( fmax_ijk_l, 3, MPI_INTEGER, 0, 0, comm2d, ierr )
@@ -311,7 +308,7 @@
           DO  j = j1, j2
 !
-!--          Attention: the lowest gridpoint is excluded here, because there
-!--          ---------  is no advection at nzb=0 and mode 'absoff' is only
-!--                     used for calculating u,v extrema for CFL-criteria
+!--          Attention: the lowest gridpoint is excluded here, because there is no advection at
+!--          ---------- nzb=0 and mode 'absoff' is only used for calculating u,v extrema for
+!--                     CFL-criteria.
              DO  i = i1+1, i2
                 IF ( ABS( ar(i,j,k) - offset ) > fmax_l(1) )  THEN
@@ -327,6 +324,5 @@
 !
 !--    Set a flag in case that the determined value is negative.
-!--    A constant offset has to be subtracted in order to handle the special
-!--    case i=0 correctly
+!--    A constant offset has to be subtracted in order to handle the special case i=0 correctly.
        IF ( ar(fmax_ijk_l(1),fmax_ijk_l(2),fmax_ijk_l(3)) < 0.0_wp )  THEN
           fmax_ijk_l(1) = -fmax_ijk_l(1) - 10
@@ -336,6 +332,5 @@
        fmax_l(2)  = myid
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, &
-                           ierr )
+       CALL MPI_ALLREDUCE( fmax_l, fmax, 1, MPI_2REAL, MPI_MAXLOC, comm2d, ierr )
 
 !
@@ -344,6 +339,5 @@
        IF ( id_fmax /= 0 )  THEN
           IF ( myid == 0 )  THEN
-             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, &
-                            status, ierr )
+             CALL MPI_RECV( fmax_ijk, 3, MPI_INTEGER, id_fmax, 0, comm2d, status, ierr )
           ELSEIF ( myid == id_fmax )  THEN
              CALL MPI_SEND( fmax_ijk_l, 3, MPI_INTEGER, 0, 0, comm2d, ierr )
Index: palm/trunk/SOURCE/gust_mod.f90
===================================================================
--- palm/trunk/SOURCE/gust_mod.f90	(revision 4645)
+++ palm/trunk/SOURCE/gust_mod.f90	(revision 4646)
@@ -1,65 +1,67 @@
 !> @file gust_mod.f90
-!------------------------------------------------------------------------------!
-! This file is part of PALM.
-!
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+!--------------------------------------------------------------------------------------------------!
+! This file is part of the PALM model system.
+!
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4535 2020-05-15 12:07:23Z raasch
 ! bugfix for restart data format query
-! 
+!
 ! 4517 2020-05-03 14:29:30Z raasch
 ! added restart with MPI-IO for reading local arrays
-! 
+!
 ! 4495 2020-04-13 20:11:20Z raasch
 ! restart data handling with MPI-IO added
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
-! CASE statement for dummy variable u2_av in gust_rrd_local changed to avoid 
-! unintended interdependencies with user-defined variables 
-! 
+! CASE statement for dummy variable u2_av in gust_rrd_local changed to avoid unintended
+! interdependencies with user-defined variables
+!
 ! 3837 2019-03-28 16:55:58Z knoop
 ! unused variable for file index removed from rrd-subroutines parameter list
-! 
+!
 ! 3725 2019-02-07 10:11:02Z raasch
 ! dummy statement modified to avoid compiler warnings about unused variables
-! 
+!
 ! 3685 2019-01-21 01:02:11Z knoop
 ! Some interface calls moved to module_interface + cleanup
-! 
+!
 ! 3665 2019-01-10 08:28:24Z raasch
 ! dummy statements added to avoid compiler warnings about unused variables
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! Bugfix: domain bounds of local_pf corrected
-! 
-! 
+!
+!
 ! Interfaces concerning data output updated
-! 
-! 
+!
+!
 ! renamed gust_par to gust_parameters
-! 
-! 
+!
+!
 ! Initial interface definition
 !
-! 
+!
 ! Description:
 ! ------------
@@ -67,5 +69,5 @@
 !>
 !> @todo This is just a dummy module. The actual module ist not released yet.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  MODULE gust_mod
 
@@ -73,5 +75,5 @@
         ONLY:  restart_data_format_output
 
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  nxl, nxlg, nxr, nxrg, nys, nysg, nyn, nyng, nzb, nzt
 
@@ -94,27 +96,27 @@
 !
 !-- Public functions
-    PUBLIC &
-       gust_parin, &
-       gust_check_parameters, &
-       gust_check_data_output_pr, &
-       gust_check_data_output, &
-       gust_init_arrays, &
-       gust_init, &
-       gust_define_netcdf_grid, &
-       gust_header, &
-       gust_actions, &
-       gust_prognostic_equations, &
-       gust_swap_timelevel, &
-       gust_3d_data_averaging, &
-       gust_data_output_2d, &
-       gust_data_output_3d, &
-       gust_statistics, &
-       gust_rrd_global, &
-       gust_wrd_global, &
-       gust_rrd_local, &
+    PUBLIC                                                                                         &
+       gust_parin,                                                                                 &
+       gust_check_parameters,                                                                      &
+       gust_check_data_output_pr,                                                                  &
+       gust_check_data_output,                                                                     &
+       gust_init_arrays,                                                                           &
+       gust_init,                                                                                  &
+       gust_define_netcdf_grid,                                                                    &
+       gust_header,                                                                                &
+       gust_actions,                                                                               &
+       gust_prognostic_equations,                                                                  &
+       gust_swap_timelevel,                                                                        &
+       gust_3d_data_averaging,                                                                     &
+       gust_data_output_2d,                                                                        &
+       gust_data_output_3d,                                                                        &
+       gust_statistics,                                                                            &
+       gust_rrd_global,                                                                            &
+       gust_wrd_global,                                                                            &
+       gust_rrd_local,                                                                             &
        gust_wrd_local
 !
 !-- Public parameters, constants and initial values
-    PUBLIC &
+    PUBLIC                                                                                         &
        gust_module_enabled
 
@@ -203,9 +205,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Parin for &gust_parameters for gust module
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_parin
 
@@ -215,5 +217,5 @@
        CHARACTER (LEN=80)  ::  line  !< dummy string that contains the current line of the parameter file
 
-       NAMELIST /gust_parameters/  &
+       NAMELIST /gust_parameters/                                                                  &
           gust_module_enabled
 
@@ -240,9 +242,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Check parameters routine for gust module
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_check_parameters
 
@@ -254,9 +256,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Check data output of profiles for gust module
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_check_data_output_pr( variable, var_count, unit, dopr_unit )
 
@@ -264,7 +266,7 @@
        IMPLICIT NONE
 
+       CHARACTER (LEN=*) ::  dopr_unit !< local value of dopr_unit
        CHARACTER (LEN=*) ::  unit      !<
        CHARACTER (LEN=*) ::  variable  !<
-       CHARACTER (LEN=*) ::  dopr_unit !< local value of dopr_unit
 
        INTEGER(iwp) ::  var_count      !<
@@ -276,9 +278,9 @@
     END SUBROUTINE gust_check_data_output_pr
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Check data output for gust module
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_check_data_output( var, unit )
 
@@ -296,9 +298,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Allocate gust module arrays and define pointers
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_init_arrays
 
@@ -310,9 +312,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Initialization of the gust module
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_init
 
@@ -324,5 +326,5 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Description:
@@ -330,5 +332,5 @@
 !> Subroutine defining appropriate grid for netcdf variables.
 !> It is called out from subroutine netcdf.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_define_netcdf_grid( var, found, grid_x, grid_y, grid_z )
 
@@ -336,9 +338,10 @@
        IMPLICIT NONE
 
-       CHARACTER (LEN=*), INTENT(IN)  ::  var         !<
-       LOGICAL, INTENT(IN)           ::  found       !<
        CHARACTER (LEN=*), INTENT(IN) ::  grid_x      !<
        CHARACTER (LEN=*), INTENT(IN) ::  grid_y      !<
        CHARACTER (LEN=*), INTENT(IN) ::  grid_z      !<
+       CHARACTER (LEN=*), INTENT(IN) ::  var         !<
+
+       LOGICAL, INTENT(IN)           ::  found       !<
 
 !
@@ -349,9 +352,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Header output for gust module
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_header ( io )
 
@@ -368,9 +371,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Call for all grid points
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_actions( location )
 
@@ -387,9 +390,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Call for grid point i,j
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_actions_ij( i, j, location )
 
@@ -409,9 +412,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Call for all grid points
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_prognostic_equations()
 
@@ -423,15 +426,15 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Call for grid point i,j
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_prognostic_equations_ij( i, j, i_omp_start, tn )
 
 
        INTEGER(iwp), INTENT(IN) ::  i            !< grid index in x-direction
+       INTEGER(iwp), INTENT(IN) ::  i_omp_start  !< first loop index of i-loop in prognostic_equations
        INTEGER(iwp), INTENT(IN) ::  j            !< grid index in y-direction
-       INTEGER(iwp), INTENT(IN) ::  i_omp_start  !< first loop index of i-loop in prognostic_equations
        INTEGER(iwp), INTENT(IN) ::  tn           !< task number of openmp task
 
@@ -443,9 +446,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Swapping of timelevels
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_swap_timelevel ( mod_count )
 
@@ -462,10 +465,10 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Description:
 ! ------------
 !> Subroutine for averaging 3D data
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_3d_data_averaging( mode, variable )
 
@@ -474,5 +477,5 @@
 
        CHARACTER (LEN=*) ::  mode    !<
-       CHARACTER (LEN=*) :: variable !<
+       CHARACTER (LEN=*) ::  variable !<
 
 !
@@ -482,12 +485,12 @@
     END SUBROUTINE gust_3d_data_averaging
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Description:
 ! ------------
 !> Subroutine defining 2D output variables
-!------------------------------------------------------------------------------!
-    SUBROUTINE gust_data_output_2d( av, variable, found, grid, mode, local_pf, &
-                                    two_d, nzb_do, nzt_do, fill_value )
+!--------------------------------------------------------------------------------------------------!
+    SUBROUTINE gust_data_output_2d( av, variable, found, grid, mode, local_pf, two_d, nzb_do,      &
+                                    nzt_do, fill_value )
 
 
@@ -495,6 +498,6 @@
 
        CHARACTER (LEN=*), INTENT(INOUT) ::  grid       !< name of vertical grid
-       CHARACTER (LEN=*), INTENT(IN) ::  mode       !< either 'xy', 'xz' or 'yz'
-       CHARACTER (LEN=*), INTENT(IN) ::  variable   !< name of variable
+       CHARACTER (LEN=*), INTENT(IN)    ::  mode       !< either 'xy', 'xz' or 'yz'
+       CHARACTER (LEN=*), INTENT(IN)    ::  variable   !< name of variable
 
        INTEGER(iwp), INTENT(IN) ::  av        !< flag for (non-)average output
@@ -508,5 +511,5 @@
 
        REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do), INTENT(INOUT) ::  local_pf !< local
-          !< array to which output data is resorted to
+                                                                                      !< array to which output data is resorted to
 
 !
@@ -519,10 +522,10 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Description:
 ! ------------
 !> Subroutine defining 3D output variables
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_data_output_3d( av, variable, found, local_pf, fill_value, nzb_do, nzt_do )
 
@@ -550,9 +553,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> This routine computes profile and timeseries data for the gust module.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_statistics( mode, sr, tn, dots_max )
 
@@ -573,13 +576,13 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific global restart data (Fortran binary format).
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_rrd_global_ftn( found )
 
 
-       USE control_parameters,                                                 &
+       USE control_parameters,                                                                     &
            ONLY: length, restart_string
 
@@ -608,9 +611,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific global restart data (MPI-IO).
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_rrd_global_mpi
 
@@ -622,12 +625,11 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific local restart data arrays (Fortran binary format).
-!------------------------------------------------------------------------------!
-    SUBROUTINE gust_rrd_local_ftn( k, nxlf, nxlc, nxl_on_file, nxrf, nxrc,         &
-                                   nxr_on_file, nynf, nync, nyn_on_file, nysf,     &
-                                   nysc, nys_on_file, tmp_2d, tmp_3d, found )
+!--------------------------------------------------------------------------------------------------!
+    SUBROUTINE gust_rrd_local_ftn( k, nxlf, nxlc, nxl_on_file, nxrf, nxrc, nxr_on_file, nynf, nync,&
+                                   nyn_on_file, nysf, nysc, nys_on_file, tmp_2d, tmp_3d, found )
 
 
@@ -696,9 +698,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific local restart data arrays (MPI-IO).
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_rrd_local_mpi
 
@@ -709,9 +711,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> This routine writes the respective restart data for the gust module.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_wrd_global
 
@@ -742,9 +744,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> This routine writes the respective restart data for the gust module.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE gust_wrd_local
 
Index: palm/trunk/SOURCE/header.f90
===================================================================
--- palm/trunk/SOURCE/header.f90	(revision 4645)
+++ palm/trunk/SOURCE/header.f90	(revision 4646)
@@ -1,20 +1,19 @@
 ! !> @file header.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
@@ -25,4 +24,7 @@
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4586 2020-07-01 16:16:43Z gronemeier
 ! Renamed rif to Ri (gradient Richardson number, 1D model)
 ! and zeta (= z_mo / ol, stability parameter, 3D model)
@@ -67,6 +69,6 @@
 !
 ! 4069 2019-07-01 14:05:51Z Giersch
-! Masked output running index mid has been introduced as a local variable to
-! avoid runtime error (Loop variable has been modified) in time_integration
+! Masked output running index mid has been introduced as a local variable to avoid runtime error
+! (Loop variable has been modified) in time_integration
 !
 ! 4023 2019-06-12 13:20:01Z maronga
@@ -86,50 +88,49 @@
 ! ------------
 !> Writing a header with all important information about the current run.
-!> This subroutine is called three times, two times at the beginning
-!> (writing information on files RUN_CONTROL and HEADER) and one time at the
-!> end of the run, then writing additional information about CPU-usage on file
+!> This subroutine is called three times, two times at the beginning (writing information on
+!> files RUN_CONTROL and HEADER) and one time at the end of the run, then writing
+!> additional information about CPU-usage on file
 !> header.
-!-----------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE header
 
 
-    USE arrays_3d,                                                             &
+    USE arrays_3d,                                                                                 &
         ONLY:  pt_init, q_init, s_init, sa_init, ug, vg, w_subs, zu, zw
 
-    USE basic_constants_and_equations_mod,                                     &
+    USE basic_constants_and_equations_mod,                                                         &
         ONLY:  g, kappa
 
-    USE bulk_cloud_model_mod,                                                  &
+    USE bulk_cloud_model_mod,                                                                      &
         ONLY:  bulk_cloud_model
 
     USE control_parameters
 
-    USE cpulog,                                                                &
+    USE cpulog,                                                                                    &
         ONLY:  log_point_s
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                                            &
         ONLY:  dx, dy
 
-    USE indices,                                                               &
-        ONLY:  mg_loc_ind, nnx, nny, nnz, nx, ny, nxl_mg, nxr_mg, nyn_mg,      &
-               nys_mg, nzt, nzt_mg, topo_top_ind
+    USE indices,                                                                                   &
+        ONLY:  mg_loc_ind, nnx, nny, nnz, nx, ny, nxl_mg, nxr_mg, nyn_mg, nys_mg, nzt, nzt_mg,     &
+               topo_top_ind
 
     USE kinds
 
-    USE model_1d_mod,                                                          &
+    USE model_1d_mod,                                                                              &
         ONLY:  damp_level_ind_1d, dt_pr_1d, dt_run_control_1d, end_time_1d
 
-    USE module_interface,                                                      &
+    USE module_interface,                                                                          &
         ONLY:  module_interface_header
 
-    USE netcdf_interface,                                                      &
+    USE netcdf_interface,                                                                          &
         ONLY:  netcdf_data_format, netcdf_data_format_string, netcdf_deflate
 
-    USE ocean_mod,                                                             &
-        ONLY:  ibc_sa_t, prho_reference, sa_surface,                           &
-               sa_vertical_gradient, sa_vertical_gradient_level,               &
-               sa_vertical_gradient_level_ind
-
-    USE palm_date_time_mod,                                                    &
+    USE ocean_mod,                                                                                 &
+        ONLY:  ibc_sa_t, prho_reference, sa_surface, sa_vertical_gradient,                         &
+               sa_vertical_gradient_level, sa_vertical_gradient_level_ind
+
+    USE palm_date_time_mod,                                                                        &
         ONLY:  get_date_time
 
@@ -137,15 +138,15 @@
 
 #if defined( __parallel )
-    USE pmc_handle_communicator,                                               &
+    USE pmc_handle_communicator,                                                                   &
         ONLY:  pmc_get_model_info
 
-    USE pmc_interface,                                                         &
+    USE pmc_interface,                                                                             &
         ONLY:  nested_run, nesting_datatransfer_mode, nesting_mode
 #endif
 
-    USE surface_mod,                                                           &
+    USE surface_mod,                                                                               &
         ONLY:  surf_def_h
 
-    USE turbulence_closure_mod,                                                &
+    USE turbulence_closure_mod,                                                                    &
         ONLY:  rans_const_c, rans_const_sigma
 
@@ -161,4 +162,6 @@
     CHARACTER (LEN=16) ::  begin_chr           !< string indication start time for the data output
     CHARACTER (LEN=16) ::  coor_chr            !< dummy string
+
+    CHARACTER (LEN=23) ::  date_time_str       !< string for date and time information
 
     CHARACTER (LEN=26) ::  ver_rev             !< string for run identification
@@ -171,6 +174,6 @@
 
     CHARACTER (LEN=70) ::  char1               !< dummy varialbe used for various strings
-    CHARACTER (LEN=70) ::  char2               !< string containing informating about the advected distance in case of Galilei transformation
-    CHARACTER (LEN=23) ::  date_time_str       !< string for date and time information
+    CHARACTER (LEN=70) ::  char2               !< string containing informating about the advected distance in case of Galilei
+                                               !< transformation
     CHARACTER (LEN=70) ::  dopr_chr            !< string indicating profile output variables
     CHARACTER (LEN=70) ::  do2d_xy             !< string indicating 2D-xy output variables
@@ -185,5 +188,6 @@
 
     CHARACTER (LEN=86) ::  coordinates         !< string indicating height coordinates for profile-prescribed variables
-    CHARACTER (LEN=86) ::  gradients           !< string indicating gradients of profile-prescribed variables between the prescribed height coordinates
+    CHARACTER (LEN=86) ::  gradients           !< string indicating gradients of profile-prescribed variables between the
+                                               !< prescribed height coordinates
     CHARACTER (LEN=86) ::  slices              !< string indicating grid coordinates of profile-prescribed subsidence velocity
     CHARACTER (LEN=86) ::  temperatures        !< string indicating profile-prescribed subsidence velocities
@@ -231,7 +235,6 @@
 
 !
-!-- Open the output file. At the end of the simulation, output is directed
-!-- to unit 19.
-    IF ( ( runnr == 0 .OR. force_print_header )  .AND. &
+!-- Open the output file. At the end of the simulation, output is directed to unit 19.
+    IF ( ( runnr == 0 .OR. force_print_header )  .AND.                                             &
          .NOT. simulated_time_at_begin /= simulated_time )  THEN
        io = 15   !  header output on file RUN_CONTROL
@@ -242,6 +245,5 @@
 
 !
-!-- At the end of the run, output file (HEADER) will be rewritten with
-!-- new information
+!-- At the end of the run, output file (HEADER) will be rewritten with new information
     IF ( io == 19 .AND. simulated_time_at_begin /= simulated_time ) REWIND( 19 )
 
@@ -295,9 +297,8 @@
 #endif
     IF ( ensemble_member_nr /= 0 )  THEN
-       WRITE ( io, 512 )  run_date, run_identifier, run_time, runnr,           &
-                       ADJUSTR( host_chr ), ensemble_member_nr
+       WRITE ( io, 512 )  run_date, run_identifier, run_time, runnr, ADJUSTR( host_chr ),          &
+                          ensemble_member_nr
     ELSE
-       WRITE ( io, 102 )  run_date, run_identifier, run_time, runnr,           &
-                       ADJUSTR( host_chr )
+       WRITE ( io, 102 )  run_date, run_identifier, run_time, runnr, ADJUSTR( host_chr )
     ENDIF
 #if defined( __parallel )
@@ -310,6 +311,6 @@
        WRITE ( io, 103 )  numprocs, pdims(1), pdims(2), TRIM( char1 )
     ELSE
-       WRITE ( io, 104 )  numprocs*threads_per_task, numprocs, &
-                          threads_per_task, pdims(1), pdims(2), TRIM( char1 )
+       WRITE ( io, 104 )  numprocs*threads_per_task, numprocs, threads_per_task, pdims(1),         &
+                          pdims(2), TRIM( char1 )
     ENDIF
 
@@ -329,13 +330,12 @@
     IF ( nested_run )  THEN
 
-       WRITE ( io, 600 )  TRIM( nesting_mode ),                                &
-                          TRIM( nesting_datatransfer_mode )
+       WRITE ( io, 600 )  TRIM( nesting_mode ), TRIM( nesting_datatransfer_mode )
        CALL pmc_get_model_info( ncpl = ncpl, cpl_id = my_cpl_id )
 
        DO  n = 1, ncpl
-          CALL pmc_get_model_info( request_for_cpl_id = n, cpl_name = cpl_name,&
-                                   cpl_parent_id = cpl_parent_id,              &
-                                   lower_left_x = lower_left_coord_x,          &
-                                   lower_left_y = lower_left_coord_y,          &
+          CALL pmc_get_model_info( request_for_cpl_id = n, cpl_name = cpl_name,                    &
+                                   cpl_parent_id = cpl_parent_id,                                  &
+                                   lower_left_x = lower_left_coord_x,                              &
+                                   lower_left_y = lower_left_coord_y,                              &
                                    npe_total = npe_total )
           IF ( n == my_cpl_id )  THEN
@@ -344,7 +344,6 @@
              char1 = ' '
           ENDIF
-          WRITE ( io, 601 )  TRIM( char1 ), n, cpl_parent_id, npe_total,       &
-                             lower_left_coord_x, lower_left_coord_y,           &
-                             TRIM( cpl_name )
+          WRITE ( io, 601 )  TRIM( char1 ), n, cpl_parent_id, npe_total, lower_left_coord_x,       &
+                             lower_left_coord_y, TRIM( cpl_name )
        ENDDO
 
@@ -376,18 +375,16 @@
        ENDIF
        IF ( mg_switch_to_pe0_level == 0 )  THEN
-          WRITE ( io, 136 )  nxr_mg(1)-nxl_mg(1)+1, nyn_mg(1)-nys_mg(1)+1, &
+          WRITE ( io, 136 )  nxr_mg(1)-nxl_mg(1)+1, nyn_mg(1)-nys_mg(1)+1, nzt_mg(1)
+       ELSEIF (  mg_switch_to_pe0_level /= -1 )  THEN
+          WRITE ( io, 137 )  mg_switch_to_pe0_level,                                               &
+                             mg_loc_ind(2,0)-mg_loc_ind(1,0)+1,                                    &
+                             mg_loc_ind(4,0)-mg_loc_ind(3,0)+1,                                    &
+                             nzt_mg(mg_switch_to_pe0_level),                                       &
+                             nxr_mg(1)-nxl_mg(1)+1, nyn_mg(1)-nys_mg(1)+1,                         &
                              nzt_mg(1)
-       ELSEIF (  mg_switch_to_pe0_level /= -1 )  THEN
-          WRITE ( io, 137 )  mg_switch_to_pe0_level,            &
-                             mg_loc_ind(2,0)-mg_loc_ind(1,0)+1, &
-                             mg_loc_ind(4,0)-mg_loc_ind(3,0)+1, &
-                             nzt_mg(mg_switch_to_pe0_level),    &
-                             nxr_mg(1)-nxl_mg(1)+1, nyn_mg(1)-nys_mg(1)+1, &
-                             nzt_mg(1)
-       ENDIF
-       IF ( psolver == 'multigrid_noopt' .AND. masking_method )  WRITE ( io, 144 )
-    ENDIF
-    IF ( call_psolver_at_all_substeps  .AND. timestep_scheme(1:5) == 'runge' ) &
-    THEN
+       ENDIF
+       IF ( psolver == 'multigrid_noopt'  .AND.  masking_method )  WRITE ( io, 144 )
+    ENDIF
+    IF ( call_psolver_at_all_substeps  .AND.  timestep_scheme(1:5) == 'runge' )  THEN
        WRITE ( io, 142 )
     ENDIF
@@ -419,6 +416,5 @@
           char2 = 'at the end of the run'
        ENDIF
-       WRITE ( io, 119 )  TRIM( char1 ), TRIM( char2 ),                        &
-                          advected_distance_x/1000.0_wp,                       &
+       WRITE ( io, 119 )  TRIM( char1 ), TRIM( char2 ), advected_distance_x/1000.0_wp,             &
                           advected_distance_y/1000.0_wp
     ENDIF
@@ -427,9 +423,7 @@
     IF ( rayleigh_damping_factor /= 0.0_wp )  THEN
        IF ( .NOT. ocean_mode )  THEN
-          WRITE ( io, 123 )  'above', rayleigh_damping_height, &
-               rayleigh_damping_factor
-       ELSE
-          WRITE ( io, 123 )  'below', rayleigh_damping_height, &
-               rayleigh_damping_factor
+          WRITE ( io, 123 )  'above', rayleigh_damping_height, rayleigh_damping_factor
+       ELSE
+          WRITE ( io, 123 )  'below', rayleigh_damping_height, rayleigh_damping_factor
        ENDIF
     ENDIF
@@ -467,6 +461,5 @@
     WRITE ( io, 203 )  simulated_time_at_begin, end_time
 
-    IF ( time_restart /= 9999999.9_wp  .AND. &
-         simulated_time_at_begin == simulated_time )  THEN
+    IF ( time_restart /= 9999999.9_wp  .AND.  simulated_time_at_begin == simulated_time )  THEN
        IF ( dt_restart == 9999999.9_wp )  THEN
           WRITE ( io, 204 )  ' Restart at:       ',time_restart
@@ -481,11 +474,9 @@
           cpuseconds_per_simulated_second = 0.0_wp
        ELSE
-          cpuseconds_per_simulated_second = log_point_s(10)%sum / &
-                                            ( simulated_time -    &
-                                              simulated_time_at_begin )
-       ENDIF
-       WRITE ( io, 206 )  simulated_time, log_point_s(10)%sum,      &
-                          log_point_s(10)%sum / REAL( i, KIND=wp ), &
-                          cpuseconds_per_simulated_second
+          cpuseconds_per_simulated_second = log_point_s(10)%sum /                                  &
+                                            ( simulated_time - simulated_time_at_begin )
+       ENDIF
+       WRITE ( io, 206 )  simulated_time, log_point_s(10)%sum,                                     &
+                          log_point_s(10)%sum / REAL( i, KIND=wp ), cpuseconds_per_simulated_second
        IF ( time_restart /= 9999999.9_wp  .AND.  time_restart < end_time )  THEN
           IF ( dt_restart == 9999999.9_wp )  THEN
@@ -499,7 +490,7 @@
 
 !
-!-- Start time for coupled runs, if independent precursor runs for atmosphere
-!-- and ocean are used or have been used. In this case, coupling_start_time
-!-- defines the time when the coupling is switched on.
+!-- Start time for coupled runs, if independent precursor runs for atmosphere and ocean are used or
+!-- have been used. In this case, coupling_start_time defines the time when the coupling is
+!-- switched on.
     IF ( coupling_start_time /= 0.0_wp )  THEN
        WRITE ( io, 207 )  coupling_start_time
@@ -571,10 +562,9 @@
        ENDIF
     ENDIF
-    WRITE ( io, 254 )  nx, ny, nzt+1, MIN( nnx, nx+1 ), MIN( nny, ny+1 ),      &
-                       MIN( nnz+2, nzt+2 )
+    WRITE ( io, 254 )  nx, ny, nzt+1, MIN( nnx, nx+1 ), MIN( nny, ny+1 ), MIN( nnz+2, nzt+2 )
     IF ( sloping_surface )  WRITE ( io, 260 )  alpha_surface
 
 !
-!-- Profile for the large scale vertial velocity
+!-- Profile for the large scale vertial velocity.
 !-- Building output strings, starting with surface value
     IF ( large_scale_subsidence )  THEN
@@ -609,12 +599,12 @@
 
        IF ( .NOT. large_scale_forcing )  THEN
-          WRITE ( io, 426 )  TRIM( coordinates ), TRIM( temperatures ), &
-                             TRIM( gradients ), TRIM( slices )
-       ENDIF
-
-
-    ENDIF
-
-!-- Profile of the geostrophic wind (component ug)
+          WRITE ( io, 426 )  TRIM( coordinates ), TRIM( temperatures ), TRIM( gradients ),         &
+                             TRIM( slices )
+       ENDIF
+
+
+    ENDIF
+
+!-- Profile of the geostrophic wind (component ug).
 !-- Building output strings
     WRITE ( ugcomponent, '(F6.2)' )  ug_surface
@@ -646,9 +636,9 @@
 
     IF ( .NOT. large_scale_forcing )  THEN
-       WRITE ( io, 423 )  TRIM( coordinates ), TRIM( ugcomponent ), &
-                          TRIM( gradients ), TRIM( slices )
-    ENDIF
-
-!-- Profile of the geostrophic wind (component vg)
+       WRITE ( io, 423 )  TRIM( coordinates ), TRIM( ugcomponent ), TRIM( gradients ),             &
+                          TRIM( slices )
+    ENDIF
+
+!-- Profile of the geostrophic wind (component vg).
 !-- Building output strings
     WRITE ( vgcomponent, '(F6.2)' )  vg_surface
@@ -680,6 +670,6 @@
 
     IF ( .NOT. large_scale_forcing )  THEN
-       WRITE ( io, 424 )  TRIM( coordinates ), TRIM( vgcomponent ), &
-                          TRIM( gradients ), TRIM( slices )
+       WRITE ( io, 424 )  TRIM( coordinates ), TRIM( vgcomponent ), TRIM( gradients ),             &
+                          TRIM( slices )
     ENDIF
 
@@ -711,6 +701,6 @@
           byn = bys + bly
 
-          WRITE ( io, 271 )  building_length_x, building_length_y, &
-                             building_height, bxl, bxr, bys, byn
+          WRITE ( io, 271 )  building_length_x, building_length_y, building_height, bxl, bxr, bys, &
+                             byn
 
        CASE ( 'single_street_canyon' )
@@ -745,11 +735,9 @@
 !
 !--          Tunnel axis in y direction
-             IF ( tunnel_length == 9999999.9_wp  .OR.                          &
-                  tunnel_length >= ( nx + 1 ) * dx )  THEN
-                WRITE ( io, 273 )  'y', tunnel_height, tunnel_wall_depth,      &
-                                        tunnel_width_x
+             IF ( tunnel_length == 9999999.9_wp  .OR.  tunnel_length >= ( nx + 1 ) * dx )  THEN
+                WRITE ( io, 273 )  'y', tunnel_height, tunnel_wall_depth, tunnel_width_x
              ELSE
-                WRITE ( io, 274 )  'y', tunnel_height, tunnel_wall_depth,      &
-                                        tunnel_width_x, tunnel_length
+                WRITE ( io, 274 )  'y', tunnel_height, tunnel_wall_depth, tunnel_width_x,          &
+                                        tunnel_length
              ENDIF
 
@@ -757,11 +745,9 @@
 !
 !--          Tunnel axis in x direction
-             IF ( tunnel_length == 9999999.9_wp  .OR.                          &
-                  tunnel_length >= ( ny + 1 ) * dy )  THEN
-                WRITE ( io, 273 )  'x', tunnel_height, tunnel_wall_depth,      &
-                                        tunnel_width_y
+             IF ( tunnel_length == 9999999.9_wp  .OR.  tunnel_length >= ( ny + 1 ) * dy )  THEN
+                WRITE ( io, 273 )  'x', tunnel_height, tunnel_wall_depth, tunnel_width_y
              ELSE
-                WRITE ( io, 274 )  'x', tunnel_height, tunnel_wall_depth,      &
-                                        tunnel_width_y, tunnel_length
+                WRITE ( io, 274 )  'x', tunnel_height, tunnel_wall_depth, tunnel_width_y,          &
+                                        tunnel_length
              ENDIF
           ENDIF
@@ -771,5 +757,5 @@
     IF ( TRIM( topography ) /= 'flat' )  THEN
        IF ( TRIM( topography_grid_convention ) == ' ' )  THEN
-          IF ( TRIM( topography ) == 'single_building' .OR.  &
+          IF ( TRIM( topography ) == 'single_building' .OR.                                        &
                TRIM( topography ) == 'single_street_canyon' )  THEN
              WRITE ( io, 278 )
@@ -931,14 +917,11 @@
           WRITE ( io, 316 )
        ENDIF
-       IF ( ocean_mode  .AND.  constant_top_salinityflux )                          &
-          WRITE ( io, 309 )  top_salinityflux
+       IF ( ocean_mode  .AND.  constant_top_salinityflux )  WRITE ( io, 309 )  top_salinityflux
        IF ( humidity       )  WRITE ( io, 315 )
-       IF ( passive_scalar .AND.  constant_top_scalarflux )                    &
-          WRITE ( io, 302 ) top_scalarflux
+       IF ( passive_scalar  .AND.  constant_top_scalarflux )  WRITE ( io, 302 ) top_scalarflux
     ENDIF
 
     IF ( constant_flux_layer )  THEN
-       WRITE ( io, 305 )  (zu(1)-zu(0)), roughness_length,                     &
-                          z0h_factor*roughness_length, kappa,                  &
+       WRITE ( io, 305 )  (zu(1)-zu(0)), roughness_length, z0h_factor*roughness_length, kappa,     &
                           zeta_min, zeta_max
        IF ( .NOT. constant_heatflux )  WRITE ( io, 308 )
@@ -950,5 +933,5 @@
        ENDIF
     ELSE
-       IF ( INDEX(initializing_actions, 'set_1d-model_profiles') /= 0 )  THEN
+       IF ( INDEX( initializing_actions, 'set_1d-model_profiles') /= 0 )  THEN
           WRITE ( io, 310 )  zeta_min, zeta_max
        ENDIF
@@ -959,14 +942,14 @@
        WRITE ( io, 318 )  use_cmax, pt_damping_width, pt_damping_factor
        IF ( turbulent_inflow )  THEN
-          IF ( y_shift == 0 ) THEN
-             WRITE ( io, 319 )  recycling_width, recycling_plane, &
+          IF ( y_shift == 0 )  THEN
+             WRITE ( io, 319 )  recycling_width, recycling_plane,                                  &
                                 inflow_damping_height, inflow_damping_width
           ELSE
-             WRITE ( io, 322 )  y_shift, recycling_width, recycling_plane, &
+             WRITE ( io, 322 )  y_shift, recycling_width, recycling_plane,                         &
                                 inflow_damping_height, inflow_damping_width
           END IF
        ENDIF
        IF ( turbulent_outflow )  THEN
-          WRITE ( io, 323 )  outflow_source_plane, INT(outflow_source_plane/dx)
+          WRITE ( io, 323 )  outflow_source_plane, INT( outflow_source_plane / dx )
        ENDIF
     ENDIF
@@ -989,14 +972,14 @@
     DO  WHILE ( pt_vertical_gradient_level_ind(i) /= -9999 )
 
-       WRITE (coor_chr,'(F7.2)')  pt_init(pt_vertical_gradient_level_ind(i))
+       WRITE ( coor_chr, '(F7.2)' )  pt_init(pt_vertical_gradient_level_ind(i))
        temperatures = TRIM( temperatures ) // ' ' // TRIM( coor_chr )
 
-       WRITE (coor_chr,'(F7.2)')  pt_vertical_gradient(i)
+       WRITE ( coor_chr, '(F7.2)' )  pt_vertical_gradient(i)
        gradients = TRIM( gradients ) // ' ' // TRIM( coor_chr )
 
-       WRITE (coor_chr,'(I7)')  pt_vertical_gradient_level_ind(i)
+       WRITE ( coor_chr, '(I7)' )  pt_vertical_gradient_level_ind(i)
        slices = TRIM( slices ) // ' ' // TRIM( coor_chr )
 
-       WRITE (coor_chr,'(F7.1)')  pt_vertical_gradient_level(i)
+       WRITE ( coor_chr, '(F7.1)' )  pt_vertical_gradient_level(i)
        coordinates = TRIM( coordinates ) // ' '  // TRIM( coor_chr )
 
@@ -1010,6 +993,6 @@
 
     IF ( .NOT. nudging )  THEN
-       WRITE ( io, 420 )  TRIM( coordinates ), TRIM( temperatures ), &
-                          TRIM( gradients ), TRIM( slices )
+       WRITE ( io, 420 )  TRIM( coordinates ), TRIM( temperatures ), TRIM( gradients ),            &
+                          TRIM( slices )
     ELSE
        WRITE ( io, 428 )
@@ -1027,14 +1010,14 @@
        DO  WHILE ( q_vertical_gradient_level_ind(i) /= -9999 )
 
-          WRITE (coor_chr,'(E8.1,4X)')  q_init(q_vertical_gradient_level_ind(i))
+          WRITE ( coor_chr, '(E8.1,4X)' )  q_init(q_vertical_gradient_level_ind(i))
           temperatures = TRIM( temperatures ) // '  ' // TRIM( coor_chr )
 
-          WRITE (coor_chr,'(E8.1,4X)')  q_vertical_gradient(i)
+          WRITE ( coor_chr, '(E8.1,4X)' )  q_vertical_gradient(i)
           gradients = TRIM( gradients ) // '  ' // TRIM( coor_chr )
 
-          WRITE (coor_chr,'(I8,4X)')  q_vertical_gradient_level_ind(i)
+          WRITE ( coor_chr, '(I8,4X)' )  q_vertical_gradient_level_ind(i)
           slices = TRIM( slices ) // '  ' // TRIM( coor_chr )
 
-          WRITE (coor_chr,'(F8.1,4X)')  q_vertical_gradient_level(i)
+          WRITE ( coor_chr, '(F8.1,4X)' )  q_vertical_gradient_level(i)
           coordinates = TRIM( coordinates ) // '  '  // TRIM( coor_chr )
 
@@ -1048,6 +1031,6 @@
 
        IF ( .NOT. nudging )  THEN
-          WRITE ( io, 421 )  TRIM( coordinates ), TRIM( temperatures ),        &
-                             TRIM( gradients ), TRIM( slices )
+          WRITE ( io, 421 )  TRIM( coordinates ), TRIM( temperatures ), TRIM( gradients ),         &
+                             TRIM( slices )
        ENDIF
     ENDIF
@@ -1063,14 +1046,14 @@
        DO  WHILE ( s_vertical_gradient_level_ind(i) /= -9999 )
 
-          WRITE (coor_chr,'(E8.1,4X)')  s_init(s_vertical_gradient_level_ind(i))
+          WRITE ( coor_chr, '(E8.1,4X)' )  s_init(s_vertical_gradient_level_ind(i))
           temperatures = TRIM( temperatures ) // '  ' // TRIM( coor_chr )
 
-          WRITE (coor_chr,'(E8.1,4X)')  s_vertical_gradient(i)
+          WRITE ( coor_chr, '(E8.1,4X)' )  s_vertical_gradient(i)
           gradients = TRIM( gradients ) // '  ' // TRIM( coor_chr )
 
-          WRITE (coor_chr,'(I8,4X)')  s_vertical_gradient_level_ind(i)
+          WRITE ( coor_chr, '(I8,4X)' )  s_vertical_gradient_level_ind(i)
           slices = TRIM( slices ) // '  ' // TRIM( coor_chr )
 
-          WRITE (coor_chr,'(F8.1,4X)')  s_vertical_gradient_level(i)
+          WRITE ( coor_chr, '(F8.1,4X)' )  s_vertical_gradient_level(i)
           coordinates = TRIM( coordinates ) // '  '  // TRIM( coor_chr )
 
@@ -1083,6 +1066,6 @@
        ENDDO
 
-       WRITE ( io, 422 )  TRIM( coordinates ), TRIM( temperatures ),           &
-                          TRIM( gradients ), TRIM( slices )
+       WRITE ( io, 422 )  TRIM( coordinates ), TRIM( temperatures ), TRIM( gradients ),            &
+                          TRIM( slices )
     ENDIF
 
@@ -1098,14 +1081,14 @@
        DO  WHILE ( sa_vertical_gradient_level_ind(i) /= -9999 )
 
-          WRITE (coor_chr,'(F7.2)')  sa_init(sa_vertical_gradient_level_ind(i))
+          WRITE ( coor_chr, '(F7.2)' )  sa_init(sa_vertical_gradient_level_ind(i))
           temperatures = TRIM( temperatures ) // ' ' // TRIM( coor_chr )
 
-          WRITE (coor_chr,'(F7.2)')  sa_vertical_gradient(i)
+          WRITE ( coor_chr, '(F7.2)' )  sa_vertical_gradient(i)
           gradients = TRIM( gradients ) // ' ' // TRIM( coor_chr )
 
-          WRITE (coor_chr,'(I7)')  sa_vertical_gradient_level_ind(i)
+          WRITE ( coor_chr, '(I7)' )  sa_vertical_gradient_level_ind(i)
           slices = TRIM( slices ) // ' ' // TRIM( coor_chr )
 
-          WRITE (coor_chr,'(F7.1)')  sa_vertical_gradient_level(i)
+          WRITE ( coor_chr, '(F7.1)' )  sa_vertical_gradient_level(i)
           coordinates = TRIM( coordinates ) // ' '  // TRIM( coor_chr )
 
@@ -1118,6 +1101,6 @@
        ENDDO
 
-       WRITE ( io, 425 )  TRIM( coordinates ), TRIM( temperatures ), &
-                          TRIM( gradients ), TRIM( slices )
+       WRITE ( io, 425 )  TRIM( coordinates ), TRIM( temperatures ), TRIM( gradients ),            &
+                          TRIM( slices )
     ENDIF
 
@@ -1195,6 +1178,6 @@
        ENDDO
 
-       IF ( ( ( do2d_xy /= ''  .AND.  section(1,1) /= -9999 )  .OR.    &
-              ( do2d_xz /= ''  .AND.  section(1,2) /= -9999 )  .OR.    &
+       IF ( ( ( do2d_xy /= ''  .AND.  section(1,1) /= -9999 )  .OR.                                &
+              ( do2d_xz /= ''  .AND.  section(1,2) /= -9999 )  .OR.                                &
               ( do2d_yz /= ''  .AND.  section(1,3) /= -9999 ) ) )  THEN
 
@@ -1224,6 +1207,5 @@
              coordinates = '/'
 !
-!--          Building strings with index and coordinate information of the
-!--          slices
+!--          Building strings with index and coordinate information of the slices
              DO  WHILE ( section(i,1) /= -9999 )
 
@@ -1233,7 +1215,7 @@
 
                 IF ( section(i,1) == -1 )  THEN
-                   WRITE (coor_chr,'(F10.1)')  -1.0_wp
+                   WRITE ( coor_chr, '(F10.1)' )  -1.0_wp
                 ELSE
-                   WRITE (coor_chr,'(F10.1)')  zu(section(i,1))
+                   WRITE ( coor_chr, '(F10.1)' )  zu(section(i,1))
                 ENDIF
                 coor_chr = ADJUSTL( coor_chr )
@@ -1243,14 +1225,12 @@
              ENDDO
              IF ( av == 0 )  THEN
-                WRITE ( io, 335 )  'XY', do2d_xy, dt_do2d_xy, &
-                                   TRIM( begin_chr ), 'k', TRIM( slices ), &
-                                   TRIM( coordinates )
+                WRITE ( io, 335 )  'XY', do2d_xy, dt_do2d_xy, TRIM( begin_chr ), 'k',              &
+                                   TRIM( slices ), TRIM( coordinates )
                 IF ( skip_time_do2d_xy /= 0.0_wp )  THEN
                    WRITE ( io, 339 )  skip_time_do2d_xy
                 ENDIF
              ELSE
-                WRITE ( io, 342 )  'XY', do2d_xy, dt_data_output_av, &
-                                   TRIM( begin_chr ), averaging_interval, &
-                                   dt_averaging_input, 'k', TRIM( slices ), &
+                WRITE ( io, 342 )  'XY', do2d_xy, dt_data_output_av, TRIM( begin_chr ),            &
+                                   averaging_interval, dt_averaging_input, 'k', TRIM( slices ),    &
                                    TRIM( coordinates )
                 IF ( skip_time_data_output_av /= 0.0_wp )  THEN
@@ -1270,6 +1250,5 @@
              coordinates = '/'
 !
-!--          Building strings with index and coordinate information of the
-!--          slices
+!--          Building strings with index and coordinate information of the slices
              DO  WHILE ( section(i,2) /= -9999 )
 
@@ -1285,14 +1264,12 @@
              ENDDO
              IF ( av == 0 )  THEN
-                WRITE ( io, 335 )  'XZ', do2d_xz, dt_do2d_xz, &
-                                   TRIM( begin_chr ), 'j', TRIM( slices ), &
-                                   TRIM( coordinates )
+                WRITE ( io, 335 )  'XZ', do2d_xz, dt_do2d_xz, TRIM( begin_chr ), 'j',              &
+                                   TRIM( slices ), TRIM( coordinates )
                 IF ( skip_time_do2d_xz /= 0.0_wp )  THEN
                    WRITE ( io, 339 )  skip_time_do2d_xz
                 ENDIF
              ELSE
-                WRITE ( io, 342 )  'XZ', do2d_xz, dt_data_output_av, &
-                                   TRIM( begin_chr ), averaging_interval, &
-                                   dt_averaging_input, 'j', TRIM( slices ), &
+                WRITE ( io, 342 )  'XZ', do2d_xz, dt_data_output_av, TRIM( begin_chr ),            &
+                                   averaging_interval, dt_averaging_input, 'j', TRIM( slices ),    &
                                    TRIM( coordinates )
                 IF ( skip_time_data_output_av /= 0.0_wp )  THEN
@@ -1312,6 +1289,5 @@
              coordinates = '/'
 !
-!--          Building strings with index and coordinate information of the
-!--          slices
+!--          Building strings with index and coordinate information of the slices
              DO  WHILE ( section(i,3) /= -9999 )
 
@@ -1327,14 +1303,12 @@
              ENDDO
              IF ( av == 0 )  THEN
-                WRITE ( io, 335 )  'YZ', do2d_yz, dt_do2d_yz, &
-                                   TRIM( begin_chr ), 'i', TRIM( slices ), &
-                                   TRIM( coordinates )
+                WRITE ( io, 335 )  'YZ', do2d_yz, dt_do2d_yz, TRIM( begin_chr ), 'i',              &
+                                   TRIM( slices ), TRIM( coordinates )
                 IF ( skip_time_do2d_yz /= 0.0_wp )  THEN
                    WRITE ( io, 339 )  skip_time_do2d_yz
                 ENDIF
              ELSE
-                WRITE ( io, 342 )  'YZ', do2d_yz, dt_data_output_av, &
-                                   TRIM( begin_chr ), averaging_interval, &
-                                   dt_averaging_input, 'i', TRIM( slices ), &
+                WRITE ( io, 342 )  'YZ', do2d_yz, dt_data_output_av, TRIM( begin_chr ),            &
+                                   averaging_interval, dt_averaging_input, 'i', TRIM( slices ),    &
                                    TRIM( coordinates )
                 IF ( skip_time_data_output_av /= 0.0_wp )  THEN
@@ -1386,9 +1360,7 @@
           ENDIF
           IF ( av == 0 )  THEN
-             WRITE ( io, 337 )  do3d_chr, dt_do3d, TRIM( begin_chr ), &
-                                zu(nz_do3d), nz_do3d
+             WRITE ( io, 337 )  do3d_chr, dt_do3d, TRIM( begin_chr ), zu(nz_do3d), nz_do3d
           ELSE
-             WRITE ( io, 343 )  do3d_chr, dt_data_output_av,           &
-                                TRIM( begin_chr ), averaging_interval, &
+             WRITE ( io, 343 )  do3d_chr, dt_data_output_av, TRIM( begin_chr ), averaging_interval,&
                                 dt_averaging_input, zu(nz_do3d), nz_do3d
           ENDIF
@@ -1415,7 +1387,6 @@
 
 !
-!-- masked arrays
-    IF ( masks > 0 )  WRITE ( io, 345 )  &
-         mask_scale_x, mask_scale_y, mask_scale_z
+!-- Masked arrays
+    IF ( masks > 0 )  WRITE ( io, 345 )  mask_scale_x, mask_scale_y, mask_scale_z
     DO  mid = 1, masks
        DO  av = 0, 1
@@ -1424,6 +1395,5 @@
           domask_chr = ''
           DO  WHILE ( domask(mid,av,i) /= ' ' )
-             domask_chr = TRIM( domask_chr ) // ' ' //  &
-                          TRIM( domask(mid,av,i) ) // ','
+             domask_chr = TRIM( domask_chr ) // ' ' // TRIM( domask(mid,av,i) ) // ','
              i = i + 1
           ENDDO
@@ -1437,6 +1407,6 @@
 
              output_format = netcdf_data_format_string
-!--          Parallel output not implemented for mask data, hence
-!--          output_format must be adjusted.
+!
+!--          Parallel output not implemented for mask data, hence output_format must be adjusted.
              IF ( netcdf_data_format == 5 ) output_format = 'netCDF4/HDF5'
              IF ( netcdf_data_format == 6 ) output_format = 'netCDF4/HDF5 classic'
@@ -1450,6 +1420,6 @@
                 WRITE ( io, 347 )  domask_chr, dt_domask(mid)
              ELSE
-                WRITE ( io, 348 )  domask_chr, dt_data_output_av, &
-                                   averaging_interval, dt_averaging_input
+                WRITE ( io, 348 )  domask_chr, dt_data_output_av, averaging_interval,              &
+                                   dt_averaging_input
              ENDIF
 
@@ -1464,5 +1434,5 @@
              ENDIF
 !
-!--          output locations
+!--          Output locations
              DO  dim = 1, 3
                 IF ( mask(mid,dim,1) >= 0.0_wp )  THEN
@@ -1471,16 +1441,13 @@
                       count = count + 1
                    ENDDO
-                   WRITE ( io, 349 )  dir(dim), dir(dim), mid, dir(dim), &
-                                      mask(mid,dim,:count)
-                ELSEIF ( mask_loop(mid,dim,1) < 0.0_wp .AND.  &
-                         mask_loop(mid,dim,2) < 0.0_wp .AND.  &
+                   WRITE ( io, 349 )  dir(dim), dir(dim), mid, dir(dim), mask(mid,dim,:count)
+                ELSEIF ( mask_loop(mid,dim,1) <  0.0_wp .AND.                                      &
+                         mask_loop(mid,dim,2) <  0.0_wp .AND.                                      &
                          mask_loop(mid,dim,3) == 0.0_wp )  THEN
                    WRITE ( io, 350 )  dir(dim), dir(dim)
                 ELSEIF ( mask_loop(mid,dim,3) == 0.0_wp )  THEN
-                   WRITE ( io, 351 )  dir(dim), dir(dim), mid, dir(dim), &
-                                      mask_loop(mid,dim,1:2)
+                   WRITE ( io, 351 )  dir(dim), dir(dim), mid, dir(dim), mask_loop(mid,dim,1:2)
                 ELSE
-                   WRITE ( io, 351 )  dir(dim), dir(dim), mid, dir(dim), &
-                                      mask_loop(mid,dim,1:3)
+                   WRITE ( io, 351 )  dir(dim), dir(dim), mid, dir(dim), mask_loop(mid,dim,1:3)
                 ENDIF
              ENDDO
@@ -1545,7 +1512,7 @@
 
 !
-!-- Cloud physcis parameters / quantities / numerical methods
+!-- Cloud physics parameters / quantities / numerical methods
     WRITE ( io, 430 )
-    IF ( humidity .AND. .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets)  THEN
+    IF ( humidity  .AND.  .NOT. bulk_cloud_model  .AND.  .NOT. cloud_droplets)  THEN
        WRITE ( io, 431 )
     ENDIF
@@ -1558,10 +1525,9 @@
 !--
     IF ( constant_diffusion )  THEN
-       WRITE ( io, 451 )  km_constant, km_constant/prandtl_number, &
-                          prandtl_number
+       WRITE ( io, 451 )  km_constant, km_constant/prandtl_number, prandtl_number
     ENDIF
     IF ( .NOT. constant_diffusion)  THEN
        IF ( e_init > 0.0_wp )  WRITE ( io, 455 )  e_init
-       IF ( e_min > 0.0_wp )  WRITE ( io, 454 )  e_min
+       IF ( e_min  > 0.0_wp )  WRITE ( io, 454 )  e_min
        IF ( wall_adjustment )  WRITE ( io, 453 )
     ENDIF
@@ -1573,6 +1539,6 @@
     WRITE ( io, 470 )
     IF ( create_disturbances )  THEN
-       WRITE ( io, 471 )  dt_disturb, disturbance_amplitude,                   &
-                          zu(disturbance_level_ind_b), disturbance_level_ind_b,&
+       WRITE ( io, 471 )  dt_disturb, disturbance_amplitude,                                       &
+                          zu(disturbance_level_ind_b), disturbance_level_ind_b,                    &
                           zu(disturbance_level_ind_t), disturbance_level_ind_t
        IF ( .NOT. bc_lr_cyc  .OR.  .NOT. bc_ns_cyc )  THEN
@@ -1599,6 +1565,5 @@
 !-- Parameters of 1D-model
     IF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
-       WRITE ( io, 500 )  end_time_1d, dt_run_control_1d, dt_pr_1d, &
-                          mixing_length_1d, dissipation_1d
+       WRITE ( io, 500 )  end_time_1d, dt_run_control_1d, dt_pr_1d, mixing_length_1d, dissipation_1d
        IF ( damp_level_ind_1d /= nzt+1 )  THEN
           WRITE ( io, 502 )  zu(damp_level_ind_1d), damp_level_ind_1d
@@ -1621,143 +1586,127 @@
 
  99 FORMAT (1X,78('-'))
-100 FORMAT (/1X,'******************************',4X,44('-')/        &
-            1X,'* ',A,' *',4X,A/                               &
+100 FORMAT (/1X,'******************************',4X,44('-')/                                       &
+            1X,'* ',A,' *',4X,A/                                                                   &
             1X,'******************************',4X,44('-'))
-101 FORMAT (35X,'coupled run: ',A/ &
+101 FORMAT (35X,'coupled run: ',A/                                                                 &
             35X,42('-'))
-102 FORMAT (/' Date:               ',A10,4X,'Run:       ',A34/      &
-            ' Time:                 ',A8,4X,'Run-No.:   ',I2.2/     &
+102 FORMAT (/' Date:               ',A10,4X,'Run:       ',A34/                                     &
+            ' Time:                 ',A8,4X,'Run-No.:   ',I2.2/                                    &
             ' Run on host:        ',A10)
 #if defined( __parallel )
-103 FORMAT (' Number of PEs:',10X,I6,4X,'Processor grid (x,y): (',I4,',',I4, &
-              ')',1X,A)
-104 FORMAT (' Number of PEs:',10X,I6,4X,'Tasks:',I4,'   threads per task:',I4/ &
+103 FORMAT (' Number of PEs:',10X,I6,4X,'Processor grid (x,y): (',I4,',',I4,')',1X,A)
+104 FORMAT (' Number of PEs:',10X,I6,4X,'Tasks:',I4,'   threads per task:',I4/                     &
               35X,'Processor grid (x,y): (',I4,',',I4,')',1X,A)
 107 FORMAT (35X,'A 1d-decomposition along ',A,' is used')
 108 FORMAT (35X,'Max. # of parallel I/O streams is ',I5)
-109 FORMAT (35X,'Precursor run for coupled atmos-ocean run'/ &
+109 FORMAT (35X,'Precursor run for coupled atmos-ocean run'/                                       &
             35X,42('-'))
-114 FORMAT (35X,'Coupled atmosphere-ocean run following'/ &
-            35X,'independent precursor runs'/             &
+114 FORMAT (35X,'Coupled atmosphere-ocean run following'/                                          &
+            35X,'independent precursor runs'/                                                      &
             35X,42('-'))
 #endif
-110 FORMAT (/' Numerical Schemes:'/ &
+110 FORMAT (/' Numerical Schemes:'/                                                                &
              ' -----------------'/)
 124 FORMAT (' --> Use the ',A,' turbulence closure (',A,' mode).')
 121 FORMAT (' --> Use the ',A,' approximation for the model equations.')
 111 FORMAT (' --> Solve perturbation pressure via FFT using ',A,' routines')
-112 FORMAT (' --> Solve perturbation pressure via SOR-Red/Black-Schema'/ &
+112 FORMAT (' --> Solve perturbation pressure via SOR-Red/Black-Schema'/                           &
             '     Iterations (initial/other): ',I3,'/',I3,'  omega =',F6.3)
-113 FORMAT (' --> Momentum advection via Piascek-Williams-Scheme (Form C3)', &
-                  ' or Upstream')
+113 FORMAT (' --> Momentum advection via Piascek-Williams-Scheme (Form C3)',' or Upstream')
 115 FORMAT ('     FFT and transpositions are overlapping')
-116 FORMAT (' --> Scalar advection via Piascek-Williams-Scheme (Form C3)', &
-                  ' or Upstream')
+116 FORMAT (' --> Scalar advection via Piascek-Williams-Scheme (Form C3)',' or Upstream')
 118 FORMAT (' --> Scalar advection via Bott-Chlond-Scheme')
-119 FORMAT (' --> Galilei-Transform applied to horizontal advection:'/ &
-            '     translation velocity = ',A/ &
+119 FORMAT (' --> Galilei-Transform applied to horizontal advection:'/                             &
+            '     translation velocity = ',A/                                                      &
             '     distance advected ',A,':  ',F8.3,' km(x)  ',F8.3,' km(y)')
 122 FORMAT (' --> Time differencing scheme: ',A)
-123 FORMAT (' --> Rayleigh-Damping active, starts ',A,' z = ',F8.2,' m'/ &
+123 FORMAT (' --> Rayleigh-Damping active, starts ',A,' z = ',F8.2,' m'/                           &
             '     maximum damping coefficient:',F6.3, ' 1/s')
 129 FORMAT (' --> Additional prognostic equation for the specific humidity')
 130 FORMAT (' --> Additional prognostic equation for the total water content')
-131 FORMAT (' --> No pt-equation solved. Neutral stratification with pt = ', &
-                  F6.2, ' K assumed')
+131 FORMAT (' --> No pt-equation solved. Neutral stratification with pt = ',F6.2,' K assumed')
 134 FORMAT (' --> Additional prognostic equation for a passive scalar')
-135 FORMAT (' --> Solve perturbation pressure via ',A,' method (', &
-                  A,'-cycle)'/ &
-            '     number of grid levels:                   ',I2/ &
+135 FORMAT (' --> Solve perturbation pressure via ',A,' method (',A,'-cycle)'/                     &
+            '     number of grid levels:                   ',I2/                                   &
             '     Gauss-Seidel red/black iterations:       ',I2)
-136 FORMAT ('     gridpoints of coarsest subdomain (x,y,z): (',I3,',',I3,',', &
-                  I3,')')
-137 FORMAT ('     level data gathered on PE0 at level:     ',I2/ &
-            '     gridpoints of coarsest subdomain (x,y,z): (',I3,',',I3,',', &
-                  I3,')'/ &
-            '     gridpoints of coarsest domain (x,y,z):    (',I3,',',I3,',', &
-                  I3,')')
+136 FORMAT ('     gridpoints of coarsest subdomain (x,y,z): (',I3,',',I3,',', I3,')')
+137 FORMAT ('     level data gathered on PE0 at level:     ',I2/                                   &
+            '     gridpoints of coarsest subdomain (x,y,z): (',I3,',',I3,',', I3,')'/              &
+            '     gridpoints of coarsest domain (x,y,z):    (',I3,',',I3,',', I3,')')
 139 FORMAT (' --> Loop optimization method: ',A)
 140 FORMAT ('     maximum residual allowed:                ',E10.3)
 141 FORMAT ('     fixed number of multigrid cycles:        ',I4)
-142 FORMAT ('     perturbation pressure is calculated at every Runge-Kutta ', &
-                  'step')
-143 FORMAT ('     Euler/upstream scheme is used for the SGS turbulent ', &
-                  'kinetic energy')
+142 FORMAT ('     perturbation pressure is calculated at every Runge-Kutta ','step')
+143 FORMAT ('     Euler/upstream scheme is used for the SGS turbulent ','kinetic energy')
 144 FORMAT ('     masking method is used')
-150 FORMAT (' --> Volume flow at the right and north boundary will be ', &
-                  'conserved'/ &
+150 FORMAT (' --> Volume flow at the right and north boundary will be ','conserved'/               &
             '     using the ',A,' mode')
 151 FORMAT ('     with u_bulk = ',F7.3,' m/s and v_bulk = ',F7.3,' m/s')
-152 FORMAT (' --> External pressure gradient directly prescribed by the user:',&
-           /'     ',2(1X,E12.5),'Pa/m in x/y direction', &
-           /'     starting from dp_level_b =', F8.3, 'm', A /)
-200 FORMAT (//' Run time and time step information:'/ &
-             ' ----------------------------------'/)
-201 FORMAT ( ' Timestep:             variable     maximum value: ',F6.3,' s', &
-             '    CFL-factor:',F5.2)
-202 FORMAT ( ' Timestep:          dt = ',F6.3,' s'/)
-203 FORMAT ( ' Start time:        ',F11.3,' s'/ &
+152 FORMAT (' --> External pressure gradient directly prescribed by the user:',                    &
+           /'     ',2(1X,E12.5),'Pa/m in x/y direction',                                           &
+           /'     starting from dp_level_b =',F8.3,'m',A/)
+200 FORMAT (//' Run time and time step information:'/                                              &
+            ' ----------------------------------'/)
+201 FORMAT (' Timestep:             variable     maximum value: ',F6.3,' s',                       &
+            '    CFL-factor:',F5.2)
+202 FORMAT (' Timestep:          dt = ',F6.3,' s'/)
+203 FORMAT (' Start time:        ',F11.3,' s'/                                                     &
              ' End time:          ',F11.3,' s')
-204 FORMAT ( A,F11.3,' s')
-205 FORMAT ( A,F11.3,' s',5X,'restart every',17X,F11.3,' s')
-206 FORMAT (/' Time reached:      ',F11.3,' s'/ &
-             ' CPU-time used:       ',F9.3,' s     per timestep:                 ',F9.3,' s'/ &
+204 FORMAT (A,F11.3,' s')
+205 FORMAT (A,F11.3,' s',5X,'restart every',17X,F11.3,' s')
+206 FORMAT (/' Time reached:      ',F11.3,' s'/                                                    &
+             ' CPU-time used:       ',F9.3,' s     per timestep:                 ',F9.3,' s'/      &
              '                                      per second of simulated time: ',F9.3,' s')
-207 FORMAT ( ' Spinup time:       ',F11.3,' s')
-250 FORMAT (//' Computational grid and domain size:'/ &
-              ' ----------------------------------'// &
-              ' Grid length:      dx =    ',F8.3,' m    dy =    ',F8.3, ' m')
-251 FORMAT (  /' Domain size:       x = ',F10.3,' m     y = ',F10.3, &
-              ' m  z(u) = ',F10.3,' m'/)
-253 FORMAT ( '                dz(',I1,') =    ', F8.3, ' m')
-254 FORMAT (//' Number of gridpoints (x,y,z):  (0:',I4,', 0:',I4,', 0:',I4,')'/ &
+207 FORMAT (' Spinup time:       ',F11.3,' s')
+250 FORMAT (//' Computational grid and domain size:'/                                              &
+              ' ----------------------------------'//                                              &
+              ' Grid length:      dx =    ',F8.3,' m    dy =    ',F8.3,' m')
+251 FORMAT (/' Domain size:       x = ',F10.3,' m     y = ',F10.3,' m  z(u) = ',F10.3,' m'/)
+253 FORMAT ('                dz(',I1,') =    ', F8.3, ' m')
+254 FORMAT (//' Number of gridpoints (x,y,z):  (0:',I4,', 0:',I4,', 0:',I4,')'/                    &
             ' Subdomain size (x,y,z):        (  ',I4,',   ',I4,',   ',I4,')'/)
-260 FORMAT (/' The model has a slope in x-direction. Inclination angle: ',F6.2,&
-             ' degrees')
-270 FORMAT (//' Topography information:'/ &
-              ' ----------------------'// &
+260 FORMAT (/' The model has a slope in x-direction. Inclination angle: ',F6.2,' degrees')
+270 FORMAT (//' Topography information:'/                                                          &
+              ' ----------------------'//                                                          &
               1X,'Topography: ',A)
-271 FORMAT (  ' Building size (x/y/z) in m: ',F5.1,' / ',F5.1,' / ',F5.1/ &
-              ' Horizontal index bounds (l/r/s/n): ',I4,' / ',I4,' / ',I4, &
-                ' / ',I4)
-272 FORMAT (  ' Single quasi-2D street canyon of infinite length in ',A, &
-              ' direction' / &
-              ' Canyon height: ', F6.2, 'm, ch = ', I4, '.'      / &
-              ' Canyon position (',A,'-walls): cxl = ', I4,', cxr = ', I4, '.')
-273 FORMAT (  ' Tunnel of infinite length in ',A, &
-              ' direction' / &
-              ' Tunnel height: ', F6.2, / &
-              ' Tunnel-wall depth: ', F6.2      / &
-              ' Tunnel width: ', F6.2 )
-274 FORMAT (  ' Tunnel in ', A, ' direction.' / &
-              ' Tunnel height: ', F6.2, / &
-              ' Tunnel-wall depth: ', F6.2      / &
-              ' Tunnel width: ', F6.2, / &
-              ' Tunnel length: ', F6.2 )
-278 FORMAT (' Topography grid definition convention:'/ &
-            ' cell edge (staggered grid points'/  &
+271 FORMAT (' Building size (x/y/z) in m: ',F5.1,' / ',F5.1,' / ',F5.1/                            &
+            ' Horizontal index bounds (l/r/s/n): ',I4,' / ',I4,' / ',I4,' / ',I4)
+272 FORMAT (' Single quasi-2D street canyon of infinite length in ',A,' direction' /               &
+            ' Canyon height: ', F6.2, 'm, ch = ', I4, '.'      /                                   &
+            ' Canyon position (',A,'-walls): cxl = ', I4,', cxr = ', I4, '.')
+273 FORMAT (' Tunnel of infinite length in ',A,                                                    &
+            ' direction' /                                                                         &
+            ' Tunnel height: ', F6.2, /                                                            &
+            ' Tunnel-wall depth: ', F6.2      /                                                    &
+            ' Tunnel width: ', F6.2 )
+274 FORMAT (' Tunnel in ', A, ' direction.' /                                                      &
+            ' Tunnel height: ', F6.2, /                                                            &
+            ' Tunnel-wall depth: ', F6.2      /                                                    &
+            ' Tunnel width: ', F6.2, /                                                             &
+            ' Tunnel length: ', F6.2 )
+278 FORMAT (' Topography grid definition convention:'/                                             &
+            ' cell edge (staggered grid points'/                                                   &
             ' (u in x-direction, v in y-direction))' /)
-279 FORMAT (' Topography grid definition convention:'/ &
+279 FORMAT (' Topography grid definition convention:'/                                             &
             ' cell center (scalar grid points)' /)
 280 FORMAT (' Complex terrain simulation is activated.')
-281 FORMAT ('    --> Mean inflow profiles are adjusted.' / &
+281 FORMAT ('    --> Mean inflow profiles are adjusted.' /                                         &
             '    --> Elevation of inflow boundary: ', F7.1, ' m' )
-282 FORMAT ('    --> Initial data from 3D-precursor run is shifted' / &
+282 FORMAT ('    --> Initial data from 3D-precursor run is shifted' /                              &
             '        vertically depending on local surface height.')
-300 FORMAT (//' Boundary conditions:'/ &
-             ' -------------------'// &
-             '                     p                    uv             ', &
-             '                     pt'// &
-             ' B. bound.: ',A/ &
+300 FORMAT (//' Boundary conditions:'/                                                             &
+             ' -------------------'//                                                              &
+             '                     p                    uv             ',                          &
+             '                     pt'//                                                           &
+             ' B. bound.: ',A/                                                                     &
              ' T. bound.: ',A)
-301 FORMAT (/'                     ',A// &
-             ' B. bound.: ',A/ &
+301 FORMAT (/'                     ',A//                                                           &
+             ' B. bound.: ',A/                                                                     &
              ' T. bound.: ',A)
 303 FORMAT (/' Bottom surface fluxes are used in diffusion terms at k=1')
 304 FORMAT (/' Top surface fluxes are used in diffusion terms at k=nzt')
-305 FORMAT (//'    Constant flux layer between bottom surface and first ',     &
-              'computational u,v-level:'// &
-             '       z_mo = ',F6.2,' m   z0 =',F7.4,' m   z0h =',F8.5,&
-             ' m   kappa =',F5.2/ &
+305 FORMAT (//'    Constant flux layer between bottom surface and first ',                         &
+              'computational u,v-level:'//                                                         &
+             '       z_mo = ',F6.2,' m   z0 =',F7.4,' m   z0h =',F8.5,' m   kappa =',F5.2/         &
              '       zeta value range:   ',F8.2,' <= zeta <=',F6.2)
 306 FORMAT ('       Predefined constant heatflux:   ',F9.6,' K m/s')
@@ -1765,5 +1714,5 @@
 308 FORMAT ('       Predefined surface temperature')
 309 FORMAT ('       Predefined constant salinityflux:   ',F9.6,' psu m/s')
-310 FORMAT (//'    1D-Model:'// &
+310 FORMAT (//'    1D-Model:'//                                                                    &
              '       Ri value range:   ',F6.2,' <= Ri <=',F6.2)
 311 FORMAT ('       Predefined constant humidity flux: ',E10.3,' kg/kg m/s')
@@ -1773,95 +1722,92 @@
 302 FORMAT ('       Predefined constant scalarflux:   ',F9.6,' kg/(m**2 s)')
 315 FORMAT ('       Humidity flux at top surface is 0.0')
-316 FORMAT ('       Sensible heatflux and momentum flux from coupled ', &
-                    'atmosphere model')
-317 FORMAT (//' Lateral boundaries:'/ &
-            '       left/right:  ',A/    &
+316 FORMAT ('       Sensible heatflux and momentum flux from coupled ', 'atmosphere model')
+317 FORMAT (//' Lateral boundaries:'/                                                              &
+            '       left/right:  ',A/                                                              &
             '       north/south: ',A)
-318 FORMAT (/'       use_cmax: ',L1 / &
-            '       pt damping layer width = ',F8.2,' m, pt ', &
-                    'damping factor =',F7.4)
-319 FORMAT ('       turbulence recycling at inflow switched on'/ &
-            '       width of recycling domain: ',F7.1,' m   grid index: ',I4/ &
+318 FORMAT (/'       use_cmax: ',L1 /                                                              &
+            '       pt damping layer width = ',F8.2,' m, pt ','damping factor =',F7.4)
+319 FORMAT ('       turbulence recycling at inflow switched on'/                                   &
+            '       width of recycling domain: ',F7.1,' m   grid index: ',I4/                      &
             '       inflow damping height: ',F6.1,' m   width: ',F6.1,' m')
-320 FORMAT ('       Predefined constant momentumflux:  u: ',F9.6,' m**2/s**2'/ &
+320 FORMAT ('       Predefined constant momentumflux:  u: ',F9.6,' m**2/s**2'/                     &
             '                                          v: ',F9.6,' m**2/s**2')
-321 FORMAT (//' Initial profiles:'/ &
+321 FORMAT (//' Initial profiles:'/                                                                &
               ' ----------------')
-322 FORMAT ('       turbulence recycling at inflow switched on'/ &
-            '       y-shift of the recycled inflow turbulence is',I3,' PE'/ &
-            '       width of recycling domain: ',F7.1,' m   grid index: ',I4/ &
+322 FORMAT ('       turbulence recycling at inflow switched on'/                                   &
+            '       y-shift of the recycled inflow turbulence is',I3,' PE'/                        &
+            '       width of recycling domain: ',F7.1,' m   grid index: ',I4/                      &
             '       inflow damping height: ',F6.1,' m   width: ',F6.1,' m'/)
-323 FORMAT ('       turbulent outflow conditon switched on'/ &
-            '       position of outflow source plane: ',F7.1,' m   ', &
-                    'grid index: ', I4)
-325 FORMAT (//' List output:'/ &
-             ' -----------'//  &
-            '    1D-Profiles:'/    &
+323 FORMAT ('       turbulent outflow conditon switched on'/                                       &
+            '       position of outflow source plane: ',F7.1,' m   ','grid index: ', I4)
+325 FORMAT (//' List output:'/                                                                     &
+             ' -----------'//                                                                      &
+            '    1D-Profiles:'/                                                                    &
             '       Output every             ',F10.2,' s')
-326 FORMAT ('       Time averaged over       ',F8.2,' s'/ &
+326 FORMAT ('       Time averaged over       ',F8.2,' s'/                                          &
             '       Averaging input every    ',F8.2,' s')
-330 FORMAT (//' Data output:'/ &
+330 FORMAT (//' Data output:'/                                                                     &
              ' -----------'/)
 331 FORMAT (/'    1D-Profiles:')
 332 FORMAT (/'       ',A)
-333 FORMAT ('       Output every             ',F8.2,' s',/ &
-            '       Time averaged over       ',F8.2,' s'/ &
+333 FORMAT ('       Output every             ',F8.2,' s',/                                         &
+            '       Time averaged over       ',F8.2,' s'/                                          &
             '       Averaging input every    ',F8.2,' s')
 334 FORMAT (/'    2D-Arrays',A,':')
-335 FORMAT (/'       ',A2,'-cross-section  Arrays: ',A/ &
-            '       Output every             ',F8.2,' s  ',A/ &
-            '       Cross sections at ',A1,' = ',A/ &
+335 FORMAT (/'       ',A2,'-cross-section  Arrays: ',A/                                            &
+            '       Output every             ',F8.2,' s  ',A/                                      &
+            '       Cross sections at ',A1,' = ',A/                                                &
             '       scalar-coordinates:   ',A,' m'/)
 336 FORMAT (/'    3D-Arrays',A,':')
 337 FORMAT (/'       Arrays: ',A/ &
-            '       Output every             ',F8.2,' s  ',A/ &
+            '       Output every             ',F8.2,' s  ',A/                                      &
             '       Upper output limit at    ',F8.2,' m  (GP ',I4,')'/)
 339 FORMAT ('       No output during initial ',F8.2,' s')
 340 FORMAT (/'    Time series:')
 341 FORMAT ('       Output every             ',F8.2,' s'/)
-342 FORMAT (/'       ',A2,'-cross-section  Arrays: ',A/ &
-            '       Output every             ',F8.2,' s  ',A/ &
-            '       Time averaged over       ',F8.2,' s'/ &
-            '       Averaging input every    ',F8.2,' s'/ &
-            '       Cross sections at ',A1,' = ',A/ &
+342 FORMAT (/'       ',A2,'-cross-section  Arrays: ',A/                                            &
+            '       Output every             ',F8.2,' s  ',A/                                      &
+            '       Time averaged over       ',F8.2,' s'/                                          &
+            '       Averaging input every    ',F8.2,' s'/                                          &
+            '       Cross sections at ',A1,' = ',A/                                                &
             '       scalar-coordinates:   ',A,' m'/)
-343 FORMAT (/'       Arrays: ',A/ &
-            '       Output every             ',F8.2,' s  ',A/ &
-            '       Time averaged over       ',F8.2,' s'/ &
-            '       Averaging input every    ',F8.2,' s'/ &
+343 FORMAT (/'       Arrays: ',A/                                                                  &
+            '       Output every             ',F8.2,' s  ',A/                                      &
+            '       Time averaged over       ',F8.2,' s'/                                          &
+            '       Averaging input every    ',F8.2,' s'/                                          &
             '       Upper output limit at    ',F8.2,' m  (GP ',I4,')'/)
 344 FORMAT ('       Output format: ',A/)
-345 FORMAT (/'    Scaling lengths for output locations of all subsequent mask IDs:',/ &
-            '       mask_scale_x (in x-direction): ',F9.3, ' m',/ &
-            '       mask_scale_y (in y-direction): ',F9.3, ' m',/ &
+345 FORMAT (/'    Scaling lengths for output locations of all subsequent mask IDs:',/              &
+            '       mask_scale_x (in x-direction): ',F9.3, ' m',/                                  &
+            '       mask_scale_y (in y-direction): ',F9.3, ' m',/                                  &
             '       mask_scale_z (in z-direction): ',F9.3, ' m' )
 346 FORMAT (/'    Masked data output',A,' for mask ID ',I2, ':')
-347 FORMAT ('       Variables: ',A/ &
+347 FORMAT ('       Variables: ',A/                                                                &
             '       Output every             ',F8.2,' s')
 348 FORMAT ('       Variables: ',A/ &
-            '       Output every             ',F8.2,' s'/ &
-            '       Time averaged over       ',F8.2,' s'/ &
+            '       Output every             ',F8.2,' s'/                                          &
+            '       Time averaged over       ',F8.2,' s'/                                          &
             '       Averaging input every    ',F8.2,' s')
-349 FORMAT (/'       Output locations in ',A,'-direction in multiples of ', &
-            'mask_scale_',A,' predefined by array mask_',I2.2,'_',A,':'/ &
+349 FORMAT (/'       Output locations in ',A,'-direction in multiples of ',                        &
+            'mask_scale_',A,' predefined by array mask_',I2.2,'_',A,':'/                           &
             13('       ',8(F8.2,',')/) )
-350 FORMAT (/'       Output locations in ',A,'-direction: ', &
+350 FORMAT (/'       Output locations in ',A,'-direction: ',                                       &
             'all gridpoints along ',A,'-direction (default).' )
-351 FORMAT (/'       Output locations in ',A,'-direction in multiples of ', &
-            'mask_scale_',A,' constructed from array mask_',I2.2,'_',A,'_loop:'/ &
+351 FORMAT (/'       Output locations in ',A,'-direction in multiples of ',                        &
+            'mask_scale_',A,' constructed from array mask_',I2.2,'_',A,'_loop:'/                   &
             '          loop begin:',F8.2,', end:',F8.2,', stride:',F8.2 )
-352 FORMAT  (/'       Number of output time levels allowed: ',I3 /)
-353 FORMAT  (/'       Number of output time levels allowed: unlimited' /)
+352 FORMAT (/'       Number of output time levels allowed: ',I3 /)
+353 FORMAT (/'       Number of output time levels allowed: unlimited'/)
 354 FORMAT ('       Output format: ',A, '   compressed with level: ',I1/)
 355 FORMAT (/'    Restart data format(s):')
 356 FORMAT ('    Input format:  ',A)
 357 FORMAT ('    Output format: ',A)
-400 FORMAT (//' Physical quantities:'/ &
+400 FORMAT (//' Physical quantities:'/                                                             &
               ' -------------------'/)
-410 FORMAT ('    Geograph. latitude  :   latitude  = ',F5.1,' degr'/   &
-            '    Geograph. longitude :   longitude = ',F5.1,' degr'/   &
-            '    Rotation angle      :   rotation_angle = ',F5.1,' degr'/   &
-            '    Angular velocity    :   omega  =',E10.3,' rad/s'/  &
-            '    Coriolis parameter  :   f      = ',F9.6,' 1/s'/    &
+410 FORMAT ('    Geograph. latitude  :   latitude  = ',F5.1,' degr'/                               &
+            '    Geograph. longitude :   longitude = ',F5.1,' degr'/                               &
+            '    Rotation angle      :   rotation_angle = ',F5.1,' degr'/                          &
+            '    Angular velocity    :   omega  =',E10.3,' rad/s'/                                 &
+            '    Coriolis parameter  :   f      = ',F9.6,' 1/s'/                                   &
             '                            f*     = ',F9.6,' 1/s')
 411 FORMAT (/'    Gravity             :   g      = ',F4.1,' m/s**2')
@@ -1869,49 +1815,49 @@
 413 FORMAT ('       Reference density in buoyancy terms: ',F8.3,' kg/m**3')
 414 FORMAT ('       Reference temperature in buoyancy terms: ',F8.4,' K')
-420 FORMAT (/'    Characteristic levels of the initial temperature profile:'// &
-            '       Height:        ',A,'  m'/ &
-            '       Temperature:   ',A,'  K'/ &
-            '       Gradient:      ',A,'  K/100m'/ &
+420 FORMAT (/'    Characteristic levels of the initial temperature profile:'//                     &
+            '       Height:        ',A,'  m'/                                                      &
+            '       Temperature:   ',A,'  K'/                                                      &
+            '       Gradient:      ',A,'  K/100m'/                                                 &
             '       Gridpoint:     ',A)
-421 FORMAT (/'    Characteristic levels of the initial humidity profile:'// &
-            '       Height:      ',A,'  m'/ &
-            '       Humidity:    ',A,'  kg/kg'/ &
-            '       Gradient:    ',A,'  (kg/kg)/100m'/ &
+421 FORMAT (/'    Characteristic levels of the initial humidity profile:'//                        &
+            '       Height:      ',A,'  m'/                                                        &
+            '       Humidity:    ',A,'  kg/kg'/                                                    &
+            '       Gradient:    ',A,'  (kg/kg)/100m'/                                             &
             '       Gridpoint:   ',A)
-422 FORMAT (/'    Characteristic levels of the initial scalar profile:'// &
-            '       Height:                  ',A,'  m'/ &
-            '       Scalar concentration:    ',A,'  kg/m**3'/ &
-            '       Gradient:                ',A,'  (kg/m**3)/100m'/ &
+422 FORMAT (/'    Characteristic levels of the initial scalar profile:'//                          &
+            '       Height:                  ',A,'  m'/                                            &
+            '       Scalar concentration:    ',A,'  kg/m**3'/                                      &
+            '       Gradient:                ',A,'  (kg/m**3)/100m'/                               &
             '       Gridpoint:               ',A)
-423 FORMAT (/'    Characteristic levels of the geo. wind component ug:'// &
-            '       Height:      ',A,'  m'/ &
-            '       ug:          ',A,'  m/s'/ &
-            '       Gradient:    ',A,'  1/100s'/ &
+423 FORMAT (/'    Characteristic levels of the geo. wind component ug:'//                          &
+            '       Height:      ',A,'  m'/                                                        &
+            '       ug:          ',A,'  m/s'/                                                      &
+            '       Gradient:    ',A,'  1/100s'/                                                   &
             '       Gridpoint:   ',A)
-424 FORMAT (/'    Characteristic levels of the geo. wind component vg:'// &
-            '       Height:      ',A,'  m'/ &
-            '       vg:          ',A,'  m/s'/ &
-            '       Gradient:    ',A,'  1/100s'/ &
+424 FORMAT (/'    Characteristic levels of the geo. wind component vg:'//                          &
+            '       Height:      ',A,'  m'/                                                        &
+            '       vg:          ',A,'  m/s'/                                                      &
+            '       Gradient:    ',A,'  1/100s'/                                                   &
             '       Gridpoint:   ',A)
-425 FORMAT (/'    Characteristic levels of the initial salinity profile:'// &
-            '       Height:     ',A,'  m'/ &
-            '       Salinity:   ',A,'  psu'/ &
-            '       Gradient:   ',A,'  psu/100m'/ &
+425 FORMAT (/'    Characteristic levels of the initial salinity profile:'//                        &
+            '       Height:     ',A,'  m'/                                                         &
+            '       Salinity:   ',A,'  psu'/                                                       &
+            '       Gradient:   ',A,'  psu/100m'/                                                  &
             '       Gridpoint:  ',A)
-426 FORMAT (/'    Characteristic levels of the subsidence/ascent profile:'// &
-            '       Height:      ',A,'  m'/ &
-            '       w_subs:      ',A,'  m/s'/ &
-            '       Gradient:    ',A,'  (m/s)/100m'/ &
+426 FORMAT (/'    Characteristic levels of the subsidence/ascent profile:'//                       &
+            '       Height:      ',A,'  m'/                                                        &
+            '       w_subs:      ',A,'  m/s'/                                                      &
+            '       Gradient:    ',A,'  (m/s)/100m'/                                               &
             '       Gridpoint:   ',A)
-427 FORMAT (/'    Initial wind profiles (u,v) are interpolated from given'// &
+427 FORMAT (/'    Initial wind profiles (u,v) are interpolated from given'//                       &
                   ' profiles')
-428 FORMAT (/'    Initial profiles (u, v, pt, q) are taken from file '/ &
+428 FORMAT (/'    Initial profiles (u, v, pt, q) are taken from file '/                            &
              '    NUDGING_DATA')
-430 FORMAT (//' Cloud physics quantities / methods:'/ &
+430 FORMAT (//' Cloud physics quantities / methods:'/                                              &
               ' ----------------------------------'/)
 431 FORMAT ('    Humidity is considered, bu no condensation')
-450 FORMAT (//' LES / Turbulence quantities:'/ &
+450 FORMAT (//' LES / Turbulence quantities:'/                                                     &
               ' ---------------------------'/)
-451 FORMAT ('    Diffusion coefficients are constant:'/ &
+451 FORMAT ('    Diffusion coefficients are constant:'/                                            &
             '    Km = ',F6.2,' m**2/s   Kh = ',F6.2,' m**2/s   Pr = ',F5.2)
 453 FORMAT ('    Mixing length is limited close to surfaces')
@@ -1919,58 +1865,49 @@
 455 FORMAT ('    initial TKE is prescribed as ',E9.2,' (m/s)**2')
 456 FORMAT (/'    Date and time at model start : ',A)
-457 FORMAT ('    RANS-mode constants: c_0 = ',F9.5/         &
-            '                         c_1 = ',F9.5/         &
-            '                         c_2 = ',F9.5/         &
-            '                         c_3 = ',F9.5/         &
-            '                         c_4 = ',F9.5/         &
-            '                         sigma_e    = ',F9.5/  &
+457 FORMAT ('    RANS-mode constants: c_0 = ',F9.5/                                                &
+            '                         c_1 = ',F9.5/                                                &
+            '                         c_2 = ',F9.5/                                                &
+            '                         c_3 = ',F9.5/                                                &
+            '                         c_4 = ',F9.5/                                                &
+            '                         sigma_e    = ',F9.5/                                         &
             '                         sigma_diss = ',F9.5)
-470 FORMAT (//' Actions during the simulation:'/ &
+470 FORMAT (//' Actions during the simulation:'/                                                   &
               ' -----------------------------'/)
-471 FORMAT ('    Disturbance impulse (u,v) every :   ',F6.2,' s'/            &
-            '    Disturbance amplitude           :    ',F5.2, ' m/s'/       &
-            '    Lower disturbance level         : ',F8.2,' m (GP ',I4,')'/  &
+471 FORMAT ('    Disturbance impulse (u,v) every :   ',F6.2,' s'/                                  &
+            '    Disturbance amplitude           :    ',F5.2, ' m/s'/                              &
+            '    Lower disturbance level         : ',F8.2,' m (GP ',I4,')'/                        &
             '    Upper disturbance level         : ',F8.2,' m (GP ',I4,')')
-472 FORMAT ('    Disturbances continued during the run from i/j =',I4, &
-                 ' to i/j =',I4)
-473 FORMAT ('    Disturbances cease as soon as the disturbance energy exceeds',&
-                 F6.3, ' m**2/s**2')
+472 FORMAT ('    Disturbances continued during the run from i/j =',I4,' to i/j =',I4)
+473 FORMAT ('    Disturbances cease as soon as the disturbance energy exceeds',F6.3, ' m**2/s**2')
 474 FORMAT ('    Random number generator used    : ',A/)
-475 FORMAT ('    The surface temperature is increased (or decreased, ', &
-                 'respectively, if'/ &
-            '    the value is negative) by ',F5.2,' K at the beginning of the',&
-                 ' 3D-simulation'/)
-476 FORMAT ('    The surface temperature increases (or decreases, ', &
-                 'respectively, if'/ &
-            '    the value is negative) by ',F8.4,' K/h during the', &
-                 ' 3D-simulation'/)
-477 FORMAT ('    The surface humidity is increased (or decreased, ',&
-                 'respectively, if the'/ &
-            '    value is negative) by ',E8.1,' kg/kg at the beginning of', &
-                 ' the 3D-simulation'/)
-478 FORMAT ('    The scalar value is increased at the surface (or decreased, ',&
-                 'respectively, if the'/ &
-            '    value is negative) by ',E8.1,' kg/m**3 at the beginning of', &
-                 ' the 3D-simulation'/)
-500 FORMAT (//' 1D-Model parameters:'/                           &
-              ' -------------------'//                           &
-            '    Simulation time:                   ',F8.1,' s'/ &
-            '    Run-controll output every:         ',F8.1,' s'/ &
-            '    Vertical profile output every:     ',F8.1,' s'/ &
-            '    Mixing length calculation:         ',A/         &
+475 FORMAT ('    The surface temperature is increased (or decreased, ','respectively, if'/         &
+            '    the value is negative) by ',F5.2,' K at the beginning of the',' 3D-simulation'/)
+476 FORMAT ('    The surface temperature increases (or decreases, ','respectively, if'/            &
+            '    the value is negative) by ',F8.4,' K/h during the',' 3D-simulation'/)
+477 FORMAT ('    The surface humidity is increased (or decreased, ','respectively, if the'/        &
+            '    value is negative) by ',E8.1,' kg/kg at the beginning of',' the 3D-simulation'/)
+478 FORMAT ('    The scalar value is increased at the surface (or decreased, ',                    &
+                 'respectively, if the'/                                                           &
+            '    value is negative) by ',E8.1,' kg/m**3 at the beginning of',' the 3D-simulation'/)
+500 FORMAT (//' 1D-Model parameters:'/                                                             &
+              ' -------------------'//                                                             &
+            '    Simulation time:                   ',F8.1,' s'/                                   &
+            '    Run-controll output every:         ',F8.1,' s'/                                   &
+            '    Vertical profile output every:     ',F8.1,' s'/                                   &
+            '    Mixing length calculation:         ',A/                                           &
             '    Dissipation calculation:           ',A/)
 502 FORMAT ('    Damping layer starts from ',F7.1,' m (GP ',I4,')'/)
 503 FORMAT (' --> Momentum advection via Wicker-Skamarock-Scheme 5th order')
 504 FORMAT (' --> Scalar advection via Wicker-Skamarock-Scheme 5th order')
-512 FORMAT (/' Date:               ',A10,6X,'Run:       ',A34/      &
-            ' Time:                 ',A8,6X,'Run-No.:   ',I2.2/     &
+512 FORMAT (/' Date:               ',A10,6X,'Run:       ',A34/                                     &
+            ' Time:                 ',A8,6X,'Run-No.:   ',I2.2/                                    &
             ' Run on host:        ',A10,6X,'En-No.:    ',I2.2)
 #if defined( __parallel )
-600 FORMAT (/' Nesting informations:'/ &
-            ' --------------------'/ &
-            ' Nesting mode:                     ',A/ &
-            ' Nesting-datatransfer mode:        ',A// &
-            ' Nest id  parent  number   lower left coordinates   name'/ &
-            ' (*=me)     id    of PEs      x (m)     y (m)' )
+600 FORMAT (/' Nesting informations:'/                                                             &
+            ' --------------------'/                                                               &
+            ' Nesting mode:                     ',A/                                               &
+            ' Nesting-datatransfer mode:        ',A//                                              &
+            ' Nest id  parent  number   lower left coordinates   name'/                            &
+            ' (*=me)     id    of PEs      x (m)     y (m)')
 601 FORMAT (2X,A1,1X,I2.2,6X,I2.2,5X,I5,5X,F8.2,2X,F8.2,5X,A)
 #endif
Index: palm/trunk/SOURCE/indoor_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/indoor_model_mod.f90	(revision 4645)
+++ palm/trunk/SOURCE/indoor_model_mod.f90	(revision 4646)
@@ -1,67 +1,67 @@
 !> @file indoor_model_mod.f90
-!--------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 2018-2020 Leibniz Universitaet Hannover
 ! Copyright 2018-2020 Hochschule Offenburg
-!--------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
-! Change order of dimension in surface array %frac to allow for better 
-! vectorization.
-! 
+! file re-formatted to follow the PALM coding standard
+!
+! 4481 2020-03-31 18:55:54Z maronga
+! Change order of dimension in surface array %frac to allow for better vectorization.
+!
 ! 4441 2020-03-04 19:20:35Z suehring
-! Major bugfix in calculation of energy demand - floor-area-per-facade was wrongly
-! calculated leading to unrealistically high energy demands and thus to
-! unreallistically high waste-heat fluxes.
-! 
+! Major bugfix in calculation of energy demand - floor-area-per-facade was wrongly calculated
+! leading to unrealistically high energy demands and thus to unreallistically high waste-heat
+! fluxes.
+!
 ! 4346 2019-12-18 11:55:56Z motisi
-! Introduction of wall_flags_total_0, which currently sets bits based on static
-! topography information used in wall_flags_static_0
-! 
+! Introduction of wall_flags_total_0, which currently sets bits based on static topography
+! information used in wall_flags_static_0
+!
 ! 4329 2019-12-10 15:46:36Z motisi
 ! Renamed wall_flags_0 to wall_flags_static_0
-! 
+!
 ! 4310 2019-11-26 19:01:28Z suehring
-! Remove dt_indoor from namelist input. The indoor model is an hourly-based 
-! model, calling it more/less often lead to inaccurate results.
-! 
+! Remove dt_indoor from namelist input. The indoor model is an hourly-based model, calling it
+! more/less often lead to inaccurate results.
+!
 ! 4299 2019-11-22 10:13:38Z suehring
-! Output of indoor temperature revised (to avoid non-defined values within 
-! buildings)
-! 
+! Output of indoor temperature revised (to avoid non-defined values within buildings)
+!
 ! 4267 2019-10-16 18:58:49Z suehring
 ! Bugfix in initialization, some indices to access building_pars where wrong.
 ! Introduction of seasonal parameters.
-! 
+!
 ! 4246 2019-09-30 09:27:52Z pavelkrc
-! 
-! 
+!
+!
 ! 4242 2019-09-27 12:59:10Z suehring
 ! Bugfix in array index
-! 
+!
 ! 4238 2019-09-25 16:06:01Z suehring
 ! - Bugfix in determination of minimum facade height and in location message
 ! - Bugfix, avoid division by zero
-! - Some optimization 
-! 
+! - Some optimization
+!
 ! 4227 2019-09-10 18:04:34Z gronemeier
 ! implement new palm_date_time_mod
@@ -72,13 +72,12 @@
 ! 4209 2019-09-02 12:00:03Z suehring
 ! - Bugfix in initialization of indoor temperature
-! - Prescibe default indoor temperature in case it is not given in the 
-!   namelist input
+! - Prescibe default indoor temperature in case it is not given in the namelist input
 !
 ! 4182 2019-08-21 14:37:54Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 4148 2019-08-08 11:26:00Z suehring
-! Bugfix in case of non grid-resolved buildings. Further, vertical grid spacing
-! is now considered at the correct level.  
+! Bugfix in case of non grid-resolved buildings. Further, vertical grid spacing is now considered at
+! the correct level.
 ! - change calculation of a_m and c_m
 ! - change calculation of u-values (use h_es in building array)
@@ -93,22 +92,22 @@
 !   in building array
 ! - change calculation of q_waste_heat
-! - bugfix in averaging mean indoor temperature 
-! 
+! - bugfix in averaging mean indoor temperature
+!
 ! 3759 2019-02-21 15:53:45Z suehring
 ! - Calculation of total building volume
 ! - Several bugfixes
 ! - Calculation of building height revised
-! 
+!
 ! 3745 2019-02-15 18:57:56Z suehring
 ! - remove building_type from module
-! - initialize parameters for each building individually instead of a bulk 
-!   initializaion with  identical building type for all
+! - initialize parameters for each building individually instead of a bulk initializaion with
+!   identical building type for all
 ! - output revised
 ! - add missing _wp
 ! - some restructuring of variables in building data structure
-! 
+!
 ! 3744 2019-02-15 18:38:58Z suehring
 ! Some interface calls moved to module_interface + cleanup
-! 
+!
 ! 3469 2018-10-30 20:05:07Z kanani
 ! Initial revision (tlang, suehring, kanani, srissman)!
@@ -125,13 +124,14 @@
 ! Description:
 ! ------------
-!> <Description of the new module>
 !> Module for Indoor Climate Model (ICM)
 !> The module is based on the DIN EN ISO 13790 with simplified hour-based procedure.
 !> This model is a equivalent circuit diagram of a three-point RC-model (5R1C).
-!> This module differ between indoor-air temperature an average temperature of indoor surfaces which make it prossible to determine thermal comfort
-!> the heat transfer between indoor and outdoor is simplified 
-
+!> This module differs between indoor-air temperature an average temperature of indoor surfaces which make it prossible to determine
+!> thermal comfort
+!> the heat transfer between indoor and outdoor is simplified
+
+!> @todo Many statement comments that are given as doxygen comments need to be changed to normal comments
 !> @todo Replace window_area_per_facade by %frac(1,m) for window
-!> @todo emissivity change for window blinds if solar_protection_on=1 
+!> @todo emissivity change for window blinds if solar_protection_on=1
 
 !> @note Do we allow use of integer flags, or only logical flags? (concerns e.g. cooling_on, heating_on)
@@ -139,25 +139,24 @@
 !>
 !> @bug  <Enter known bugs here>
-!------------------------------------------------------------------------------!
- MODULE indoor_model_mod 
-
-    USE arrays_3d,                                                             &
-        ONLY:  ddzw,                                                           &
-               dzw,                                                            &
+!--------------------------------------------------------------------------------------------------!
+ MODULE indoor_model_mod
+
+    USE arrays_3d,                                                                                 &
+        ONLY:  ddzw,                                                                               &
+               dzw,                                                                                &
                pt
 
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  initializing_actions
 
     USE kinds
-    
-    USE netcdf_data_input_mod,                                                 &
+
+    USE netcdf_data_input_mod,                                                                     &
         ONLY:  building_id_f, building_type_f
 
-    USE palm_date_time_mod,                                                    &
-        ONLY:  get_date_time, northward_equinox, seconds_per_hour,             &
-               southward_equinox
-
-    USE surface_mod,                                                           &
+    USE palm_date_time_mod,                                                                        &
+        ONLY:  get_date_time, northward_equinox, seconds_per_hour, southward_equinox
+
+    USE surface_mod,                                                                               &
         ONLY:  surf_usm_h, surf_usm_v
 
@@ -170,6 +169,6 @@
 
        INTEGER(iwp) ::  id                                !< building ID
+       INTEGER(iwp) ::  kb_max                            !< highest vertical index of a building
        INTEGER(iwp) ::  kb_min                            !< lowest vertical index of a building
-       INTEGER(iwp) ::  kb_max                            !< highest vertical index of a building
        INTEGER(iwp) ::  num_facades_per_building_h = 0    !< total number of horizontal facades elements
        INTEGER(iwp) ::  num_facades_per_building_h_l = 0  !< number of horizontal facade elements on local subdomain
@@ -179,17 +178,17 @@
 
        INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  l_v            !< index array linking surface-element orientation index
-                                                                  !< for vertical surfaces with building 
+                                                                  !< for vertical surfaces with building
        INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  m_h            !< index array linking surface-element index for
                                                                   !< horizontal surfaces with building
-       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  m_v            !< index array linking surface-element index for 
+       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  m_v            !< index array linking surface-element index for
                                                                   !< vertical surfaces with building
-       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facade_h   !< number of horizontal facade elements per buidling 
+       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facade_h   !< number of horizontal facade elements per buidling
                                                                   !< and height level
        INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facade_v   !< number of vertical facades elements per buidling
                                                                   !< and height level
-                                                                 
+
 
        LOGICAL ::  on_pe = .FALSE.   !< flag indicating whether a building with certain ID is on local subdomain
-       
+
        REAL(wp) ::  air_change_high       !< [1/h] air changes per time_utc_hour
        REAL(wp) ::  air_change_low        !< [1/h] air changes per time_utc_hour
@@ -199,14 +198,15 @@
        REAL(wp) ::  factor_a              !< [-] Dynamic parameters specific effective surface according to Table 12; 2.5
                                           !< (very light, light and medium), 3.0 (heavy), 3.5 (very heavy)
-       REAL(wp) ::  factor_c              !< [J/(m2 K)] Dynamic parameters inner heatstorage according to Table 12; 80000 
+       REAL(wp) ::  factor_c              !< [J/(m2 K)] Dynamic parameters inner heatstorage according to Table 12; 80000
                                           !< (very light), 110000 (light), 165000 (medium), 260000 (heavy), 370000 (very heavy)
        REAL(wp) ::  f_c_win               !< [-] shading factor
        REAL(wp) ::  fapf                  !< [m2/m2] floor area per facade
        REAL(wp) ::  g_value_win           !< [-] SHGC factor
-       REAL(wp) ::  h_es                  !< [W/(m2 K)] surface-related heat transfer coefficient between extern and surface 
+       REAL(wp) ::  h_es                  !< [W/(m2 K)] surface-related heat transfer coefficient between extern and surface
        REAL(wp) ::  height_cei_con        !< [m] ceiling construction heigth
        REAL(wp) ::  height_storey         !< [m] storey heigth
        REAL(wp) ::  params_waste_heat_c   !< [-] anthropogenic heat outputs for cooling e.g. 1.33 for KKM with COP = 3
-       REAL(wp) ::  params_waste_heat_h   !< [-] anthropogenic heat outputs for heating e.g. 1 - 0.9 = 0.1 for combustion with eta = 0.9 or -2 for WP with COP = 3
+       REAL(wp) ::  params_waste_heat_h   !< [-] anthropogenic heat outputs for heating e.g. 1 - 0.9 = 0.1 for combustion with
+                                          !< eta = 0.9 or -2 for WP with COP = 3
        REAL(wp) ::  phi_c_max             !< [W] Max. Cooling capacity (negative)
        REAL(wp) ::  phi_h_max             !< [W] Max. Heating capacity (positive)
@@ -229,5 +229,5 @@
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  vol_frac   !< fraction of local on total building volume, height dependent
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  vpf        !< building volume volume per facade element, height dependent
-       
+
     END TYPE build
 
@@ -237,4 +237,20 @@
 !
 !-- Declare all global variables within the module
+
+    REAL(wp), PARAMETER ::  dt_indoor = 3600.0_wp                  !< [s] time interval for indoor-model application, fixed to
+                                                                   !< 3600.0 due to model requirements
+    REAL(wp), PARAMETER ::  h_is                     = 3.45_wp     !< [W/(m2 K)] surface-related heat transfer coefficient between
+                                                                   !< surface and air (chap. 7.2.2.2)
+    REAL(wp), PARAMETER ::  h_ms                     = 9.1_wp      !< [W/(m2 K)] surface-related heat transfer coefficient between
+                                                                   !< component and surface (chap. 12.2.2)
+    REAL(wp), PARAMETER ::  params_f_f               = 0.3_wp      !< [-] frame ratio chap. 8.3.2.1.1 for buildings with mostly
+                                                                   !< cooling 2.0_wp
+    REAL(wp), PARAMETER ::  params_f_w               = 0.9_wp      !< [-] correction factor (fuer nicht senkrechten Stahlungseinfall
+                                                                   !< DIN 4108-2 chap.8, (hier konstant, keine WinkelabhÃ€ngigkeit)
+    REAL(wp), PARAMETER ::  params_f_win             = 0.5_wp      !< [-] proportion of window area, Database A_win aus
+                                                                   !< Datenbank 27 window_area_per_facade_percent
+    REAL(wp), PARAMETER ::  params_solar_protection  = 300.0_wp    !< [W/m2] chap. G.5.3.1 sun protection closed, if the radiation
+                                                                   !< on facade exceeds this value
+
     INTEGER(iwp) ::  cooling_on              !< Indoor cooling flag (0=off, 1=on)
     INTEGER(iwp) ::  heating_on              !< Indoor heating flag (0=off, 1=on)
@@ -242,5 +258,4 @@
     INTEGER(iwp) ::  solar_protection_on     !< Solar protection on
 
-    REAL(wp), PARAMETER ::  dt_indoor = 3600.0_wp    !< [s] time interval for indoor-model application, fixed to 3600.0 due to model requirements
 
     REAL(wp) ::  a_m                                 !< [m2] the effective mass-related area
@@ -251,12 +266,13 @@
     REAL(wp) ::  h_t_1                               !< [W/K] Heat transfer coefficient auxiliary variable 1
     REAL(wp) ::  h_t_2                               !< [W/K] Heat transfer coefficient auxiliary variable 2
-    REAL(wp) ::  h_t_3                               !< [W/K] Heat transfer coefficient auxiliary variable 3 
-    REAL(wp) ::  h_t_wm                              !< [W/K] Heat transfer coefficient of the emmision (got with h_t_ms the thermal mass)
+    REAL(wp) ::  h_t_3                               !< [W/K] Heat transfer coefficient auxiliary variable 3
+    REAL(wp) ::  h_t_es                              !< [W/K] heat transfer coefficient of doors, windows, curtain walls and
+                                                     !< glazed walls (assumption: thermal mass=0)
     REAL(wp) ::  h_t_is                              !< [W/K] thermal coupling conductance (Thermischer Kopplungsleitwert)
     REAL(wp) ::  h_t_ms                              !< [W/K] Heat transfer conductance term (got with h_t_wm the thermal mass)
     REAL(wp) ::  h_t_wall                            !< [W/K] heat transfer coefficient of opaque components (assumption: got all
                                                      !< thermal mass) contains of h_t_wm and h_t_ms
-    REAL(wp) ::  h_t_es                              !< [W/K] heat transfer coefficient of doors, windows, curtain walls and 
-                                                     !< glazed walls (assumption: thermal mass=0)
+    REAL(wp) ::  h_t_wm                              !< [W/K] Heat transfer coefficient of the emmision (got with h_t_ms the
+                                                     !< thermal mass)
     REAL(wp) ::  h_v                                 !< [W/K] heat transfer of ventilation
     REAL(wp) ::  indoor_volume_per_facade            !< [m3] indoor air volume per facade element
@@ -264,30 +280,31 @@
     REAL(wp) ::  net_sw_in                           !< [W/m2] net short-wave radiation
     REAL(wp) ::  phi_hc_nd                           !< [W] heating demand and/or cooling demand
-    REAL(wp) ::  phi_hc_nd_10                        !< [W] heating demand and/or cooling demand for heating or cooling 
+    REAL(wp) ::  phi_hc_nd_10                        !< [W] heating demand and/or cooling demand for heating or cooling
     REAL(wp) ::  phi_hc_nd_ac                        !< [W] actual heating demand and/or cooling demand
     REAL(wp) ::  phi_hc_nd_un                        !< [W] unlimited heating demand and/or cooling demand which is necessary to
-                                                     !< reach the demanded required temperature (heating is positive, 
-                                                     !< cooling is negative) 
+                                                     !< reach the demanded required temperature (heating is positive,
+                                                     !< cooling is negative)
     REAL(wp) ::  phi_ia                              !< [W] internal air load = internal loads * 0.5, Eq. (C.1)
     REAL(wp) ::  phi_m                               !< [W] mass specific thermal load (internal and external)
     REAL(wp) ::  phi_mtot                            !< [W] total mass specific thermal load (internal and external)
     REAL(wp) ::  phi_sol                             !< [W] solar loads
-    REAL(wp) ::  phi_st                              !< [W] mass specific thermal load implied non thermal mass 
+    REAL(wp) ::  phi_st                              !< [W] mass specific thermal load implied non thermal mass
     REAL(wp) ::  q_wall_win                          !< [W/m2]heat flux from indoor into wall/window
     REAL(wp) ::  q_waste_heat                        !< [W/m2]waste heat, sum of waste heat over the roof to Palm
-                                                     
+
     REAL(wp) ::  q_c_m                               !< [W] Energy of thermal storage mass specific thermal load for internal
                                                      !< and external heatsources (for energy bilanz)
-    REAL(wp) ::  q_c_st                              !< [W] Energy of thermal storage mass specific thermal load implied non thermal mass (for energy bilanz)
+    REAL(wp) ::  q_c_st                              !< [W] Energy of thermal storage mass specific thermal load implied non
+                                                     !< thermal mass (for energy bilanz)
     REAL(wp) ::  q_int                               !< [W] Energy of internal air load (for energy bilanz)
     REAL(wp) ::  q_sol                               !< [W] Energy of solar (for energy bilanz)
     REAL(wp) ::  q_trans                             !< [W] Energy of transmission (for energy bilanz)
     REAL(wp) ::  q_vent                              !< [W] Energy of ventilation (for energy bilanz)
-                                                     
+
     REAL(wp) ::  schedule_d                          !< [-] activation for internal loads (low or high + low)
     REAL(wp) ::  skip_time_do_indoor = 0.0_wp        !< [s] Indoor model is not called before this time
     REAL(wp) ::  theta_air                           !< [degree_C] air temperature of the RC-node
     REAL(wp) ::  theta_air_0                         !< [degree_C] air temperature of the RC-node in equilibrium
-    REAL(wp) ::  theta_air_10                        !< [degree_C] air temperature of the RC-node from a heating capacity 
+    REAL(wp) ::  theta_air_10                        !< [degree_C] air temperature of the RC-node from a heating capacity
                                                      !< of 10 W/m2
     REAL(wp) ::  theta_air_ac                        !< [degree_C] actual room temperature after heating/cooling
@@ -301,49 +318,51 @@
     REAL(wp) ::  total_area                          !< [m2] area of all surfaces pointing to zone
     REAL(wp) ::  window_area_per_facade              !< [m2] window area per facade element
-    
-    REAL(wp), PARAMETER ::  h_is                     = 3.45_wp     !< [W/(m2 K)] surface-related heat transfer coefficient between
-                                                                   !< surface and air (chap. 7.2.2.2)
-    REAL(wp), PARAMETER ::  h_ms                     = 9.1_wp      !< [W/(m2 K)] surface-related heat transfer coefficient between component and surface (chap. 12.2.2)
-    REAL(wp), PARAMETER ::  params_f_f               = 0.3_wp      !< [-] frame ratio chap. 8.3.2.1.1 for buildings with mostly cooling 2.0_wp
-    REAL(wp), PARAMETER ::  params_f_w               = 0.9_wp      !< [-] correction factor (fuer nicht senkrechten Stahlungseinfall
-                                                                   !< DIN 4108-2 chap.8, (hier konstant, keine WinkelabhÃ€ngigkeit) 
-    REAL(wp), PARAMETER ::  params_f_win             = 0.5_wp      !< [-] proportion of window area, Database A_win aus 
-                                                                   !< Datenbank 27 window_area_per_facade_percent
-    REAL(wp), PARAMETER ::  params_solar_protection  = 300.0_wp    !< [W/m2] chap. G.5.3.1 sun protection closed, if the radiation 
-                                                                   !< on facade exceeds this value
+
 !
 !-- Definition of seasonal parameters, summer and winter, for different building types
-    REAL(wp), DIMENSION(0:1,1:7) ::  summer_pars = RESHAPE( (/               & ! building_type 1
-                                          0.5_wp,                              & ! basical airflow without occupancy of the room
-                                          2.0_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.5_wp,                              & ! building_type 2: basical airflow without occupancy of the room
-                                          2.0_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.8_wp,                              & ! building_type 3: basical airflow without occupancy of the room
-                                          2.0_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.1_wp,                              & ! building_type 4: basical airflow without occupancy of the room
-                                          1.5_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.1_wp,                              & ! building_type 5: basical airflow without occupancy of the room
-                                          1.5_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.1_wp,                              & ! building_type 6: basical airflow without occupancy of the room
-                                          1.5_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.1_wp,                              & ! building_type 7: basical airflow without occupancy of the room
-                                          1.5_wp                               & ! additional airflow depend of occupancy of the room
+    REAL(wp), DIMENSION(0:1,1:7) ::  summer_pars = RESHAPE( (/                & ! building_type 1
+                                          0.5_wp,                             & ! basical airflow without occupancy of the room
+                                          2.0_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.5_wp,                             & ! building_type 2: basical airflow without occupancy
+                                                                                ! of the room
+                                          2.0_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.8_wp,                             & ! building_type 3: basical airflow without occupancy
+                                                                                ! of the room
+                                          2.0_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.1_wp,                             & ! building_type 4: basical airflow without occupancy
+                                                                                ! of the room
+                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.1_wp,                             & ! building_type 5: basical airflow without occupancy
+                                                                                ! of the room
+                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.1_wp,                             & ! building_type 6: basical airflow without occupancy
+                                                                                ! of the room
+                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.1_wp,                             & ! building_type 7: basical airflow without occupancy
+                                                                                ! of the room
+                                          1.5_wp                              & ! additional airflow depend of occupancy of the room
                                                            /), (/ 2, 7 /) )
 
-    REAL(wp), DIMENSION(0:1,1:7) ::  winter_pars = RESHAPE( (/               & ! building_type 1
-                                          0.1_wp,                              & ! basical airflow without occupancy of the room
-                                          0.5_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.1_wp,                              & ! building_type 2: basical airflow without occupancy of the room
-                                          0.5_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.1_wp,                              & ! building_type 3: basical airflow without occupancy of the room
-                                          0.5_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.1_wp,                              & ! building_type 4: basical airflow without occupancy of the room
-                                          1.5_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.1_wp,                              & ! building_type 5: basical airflow without occupancy of the room
-                                          1.5_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.1_wp,                              & ! building_type 6: basical airflow without occupancy of the room
-                                          1.5_wp,                              & ! additional airflow depend of occupancy of the room
-                                          0.1_wp,                              & ! building_type 7: basical airflow without occupancy of the room
-                                          1.5_wp                               & ! additional airflow depend of occupancy of the room
+    REAL(wp), DIMENSION(0:1,1:7) ::  winter_pars = RESHAPE( (/                & ! building_type 1
+                                          0.1_wp,                             & ! basical airflow without occupancy of the room
+                                          0.5_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.1_wp,                             & ! building_type 2: basical airflow without occupancy
+                                                                                ! of the room
+                                          0.5_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.1_wp,                             & ! building_type 3: basical airflow without occupancy
+                                                                                ! of the room
+                                          0.5_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.1_wp,                             & ! building_type 4: basical airflow without occupancy
+                                                                                ! of the room
+                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.1_wp,                             & ! building_type 5: basical airflow without occupancy
+                                                                                ! of the room
+                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.1_wp,                             & ! building_type 6: basical airflow without occupancy
+                                                                                ! of the room
+                                          1.5_wp,                             & ! additional airflow depend of occupancy of the room
+                                          0.1_wp,                             & ! building_type 7: basical airflow without occupancy
+                                                                                ! of the room
+                                          1.5_wp                              & ! additional airflow depend of occupancy of the room
                                                            /), (/ 2, 7 /) )
 
@@ -352,10 +371,10 @@
 
     PRIVATE
-    
+
 !
 !-- Add INTERFACES that must be available to other modules
-    PUBLIC im_init, im_main_heatcool, im_parin, im_define_netcdf_grid,          &
-           im_check_data_output, im_data_output_3d, im_check_parameters
-    
+    PUBLIC im_init, im_main_heatcool, im_parin, im_define_netcdf_grid, im_check_data_output,       &
+           im_data_output_3d, im_check_parameters
+
 
 !
@@ -385,5 +404,5 @@
         MODULE PROCEDURE im_define_netcdf_grid
      END INTERFACE im_define_netcdf_grid
-! 
+!
 ! !
 ! !-- Output of information to the header file
@@ -392,15 +411,15 @@
 !     END INTERFACE im_header
 !
-!-- Calculations for indoor temperatures  
+!-- Calculations for indoor temperatures
     INTERFACE im_calc_temperatures
        MODULE PROCEDURE im_calc_temperatures
     END INTERFACE im_calc_temperatures
 !
-!-- Initialization actions  
+!-- Initialization actions
     INTERFACE im_init
        MODULE PROCEDURE im_init
     END INTERFACE im_init
 !
-!-- Main part of indoor model  
+!-- Main part of indoor model
     INTERFACE im_main_heatcool
        MODULE PROCEDURE im_main_heatcool
@@ -414,12 +433,12 @@
  CONTAINS
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!< Calculation of the air temperatures and mean radiation temperature
-!< This is basis for the operative temperature
-!< Based on a Crank-Nicholson scheme with a timestep of a hour
-!------------------------------------------------------------------------------!
- SUBROUTINE im_calc_temperatures ( i, j, k, indoor_wall_window_temperature,    &
+!< Calculation of the air temperatures and mean radiation temperature.
+!< This is basis for the operative temperature.
+!< Based on a Crank-Nicholson scheme with a timestep of a hour.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE im_calc_temperatures ( i, j, k, indoor_wall_window_temperature,                        &
                                    near_facade_temperature, phi_hc_nd_dummy )
 
@@ -427,5 +446,5 @@
     INTEGER(iwp) ::  j
     INTEGER(iwp) ::  k
-    
+
     REAL(wp) ::  indoor_wall_window_temperature  !< weighted temperature of innermost wall/window layer
     REAL(wp) ::  near_facade_temperature
@@ -433,45 +452,46 @@
 !
 !-- Calculation of total mass specific thermal load (internal and external)
-    phi_mtot = ( phi_m + h_t_wm * indoor_wall_window_temperature               &
-                       + h_t_3  * ( phi_st + h_t_es * pt(k,j,i)                &
-                                            + h_t_1 *                          &
-                                    ( ( ( phi_ia + phi_hc_nd_dummy ) / h_v )   &
-                                                 + near_facade_temperature )   &
-                                   ) / h_t_2                                   &
+    phi_mtot = ( phi_m + h_t_wm * indoor_wall_window_temperature                                   &
+                       + h_t_3  * ( phi_st + h_t_es * pt(k,j,i)                                    &
+                                            + h_t_1 *                                              &
+                                    ( ( ( phi_ia + phi_hc_nd_dummy ) / h_v )                       &
+                                                 + near_facade_temperature )                       &
+                                  ) / h_t_2                                                        &
                )                                                                !< [degree_C] Eq. (C.5)
-! 
+!
 !-- Calculation of component temperature at factual timestep
-    theta_m_t = ( ( theta_m_t_prev                                             &
-                    * ( ( c_m / 3600.0_wp ) - 0.5_wp * ( h_t_3 + h_t_wm ) )    &
-                     + phi_mtot                                                &
-                  )                                                            &
-                  /   ( ( c_m / 3600.0_wp ) + 0.5_wp * ( h_t_3 + h_t_wm ) )    &
+    theta_m_t = ( ( theta_m_t_prev                                                                 &
+                    * ( ( c_m / 3600.0_wp ) - 0.5_wp * ( h_t_3 + h_t_wm ) )                        &
+                     + phi_mtot                                                                    &
+                  )                                                                                &
+                  /   ( ( c_m / 3600.0_wp ) + 0.5_wp * ( h_t_3 + h_t_wm ) )                        &
                 )                                                               !< [degree_C] Eq. (C.4)
 !
 !-- Calculation of mean inner temperature for the RC-node in actual timestep
     theta_m = ( theta_m_t + theta_m_t_prev ) * 0.5_wp                           !< [degree_C] Eq. (C.9)
-    
+
 !
 !-- Calculation of mean surface temperature of the RC-node in actual timestep
-    theta_s = ( (   h_t_ms * theta_m + phi_st + h_t_es * pt(k,j,i)             &
-                  + h_t_1  * ( near_facade_temperature                         &
-                           + ( phi_ia + phi_hc_nd_dummy ) / h_v )              &
-                )                                                              &
-                / ( h_t_ms + h_t_es + h_t_1 )                                  &
+    theta_s = ( (   h_t_ms * theta_m + phi_st + h_t_es * pt(k,j,i)                                 &
+                  + h_t_1  * ( near_facade_temperature                                             &
+                           + ( phi_ia + phi_hc_nd_dummy ) / h_v )                                  &
+                )                                                                                  &
+                / ( h_t_ms + h_t_es + h_t_1 )                                                      &
               )                                                                 !< [degree_C] Eq. (C.10)
-    
+
 !
 !-- Calculation of the air temperature of the RC-node
-    theta_air = ( h_t_is * theta_s + h_v * near_facade_temperature             &
-                + phi_ia + phi_hc_nd_dummy ) / ( h_t_is + h_v )                 !< [degree_C] Eq. (C.11)
+    theta_air = ( h_t_is * theta_s + h_v * near_facade_temperature + phi_ia + phi_hc_nd_dummy ) /  &
+                ( h_t_is + h_v )                                                !< [degree_C] Eq. (C.11)
 
  END SUBROUTINE im_calc_temperatures
 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Initialization of the indoor model.
-!> Static information are calculated here, e.g. building parameters and
-!> geometrical information, everything that doesn't change in time.
+!> Static information are calculated here, e.g. building parameters and geometrical information,
+!> anything that doesn't change in time.
 !
 !-- Input values
@@ -480,25 +500,26 @@
 !     theta_e              -->  pt(k,j,i)                         !< undisturbed outside temperature, 1. PALM volume, for windows
 !     theta_sup = theta_f  -->  surf_usm_h%pt_10cm(m)
-!                               surf_usm_v(l)%pt_10cm(m)          !< Air temperature, facade near (10cm) air temperature from 1. Palm volume
+!                               surf_usm_v(l)%pt_10cm(m)          !< Air temperature, facade near (10cm) air temperature from
+                                                                  !< 1. Palm volume
 !     theta_node           -->  t_wall_h(nzt_wall,m)
 !                               t_wall_v(l)%t(nzt_wall,m)         !< Temperature of innermost wall layer, for opaque wall
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE im_init
 
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  message_string, time_since_reference_point
 
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  nxl, nxr, nyn, nys, nzb, nzt, wall_flags_total_0
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                                            &
         ONLY:  dx, dy
 
     USE pegrid
 
-    USE surface_mod,                                                           &
+    USE surface_mod,                                                                               &
         ONLY:  surf_usm_h, surf_usm_v
-        
-    USE urban_surface_mod,                                                     &
+
+    USE urban_surface_mod,                                                                         &
         ONLY:  building_pars, building_type
 
@@ -514,6 +535,6 @@
 
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids           !< building IDs on entire model domain
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_final     !< building IDs on entire model domain, 
-                                                                    !< multiple occurences are sorted out 
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_final     !< building IDs on entire model domain,
+                                                                    !< multiple occurences are sorted out
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_final_tmp !< temporary array used for resizing
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_l         !< building IDs on local subdomain
@@ -523,14 +544,14 @@
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  k_min_l             !< lowest vertical index of a building on subdomain
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  n_fa                !< counting array
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facades_h       !< dummy array used for summing-up total number of 
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facades_h       !< dummy array used for summing-up total number of
                                                                     !< horizontal facade elements
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facades_v       !< dummy array used for summing-up total number of 
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facades_v       !< dummy array used for summing-up total number of
                                                                     !< vertical facade elements
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  receive_dum_h       !< dummy array used for MPI_ALLREDUCE  
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  receive_dum_v       !< dummy array used for MPI_ALLREDUCE  
-    
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  receive_dum_h       !< dummy array used for MPI_ALLREDUCE
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  receive_dum_v       !< dummy array used for MPI_ALLREDUCE
+
     INTEGER(iwp), DIMENSION(0:numprocs-1) ::  num_buildings         !< number of buildings with different ID on entire model domain
     INTEGER(iwp), DIMENSION(0:numprocs-1) ::  num_buildings_l       !< number of buildings with different ID on local subdomain
-                                                              
+
     REAL(wp) ::  u_tmp                                     !< dummy for temporary calculation of u-value without h_is
     REAL(wp) ::  du_tmp                                    !< 1/u_tmp
@@ -544,6 +565,5 @@
     CALL location_message( 'initializing indoor model', 'start' )
 !
-!-- Initializing of indoor model is only possible if buildings can be 
-!-- distinguished by their IDs.
+!-- Initializing of indoor model is only possible if buildings can be distinguished by their IDs.
     IF ( .NOT. building_id_f%from_file )  THEN
        message_string = 'Indoor model requires information about building_id'
@@ -559,5 +579,5 @@
           IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
              IF ( num_buildings_l(myid) > 0 )  THEN
-                IF ( ANY( building_id_f%var(j,i) .EQ.  build_ids_l ) )  THEN 
+                IF ( ANY( building_id_f%var(j,i) == build_ids_l ) )  THEN
                    CYCLE
                 ELSE
@@ -569,12 +589,12 @@
                    DEALLOCATE( build_ids_l )
                    ALLOCATE( build_ids_l(1:num_buildings_l(myid)) )
-                   build_ids_l(1:num_buildings_l(myid)-1) =                 &
-                               build_ids_l_tmp(1:num_buildings_l(myid)-1)
+                   build_ids_l(1:num_buildings_l(myid)-1) =                                        &
+                                                          build_ids_l_tmp(1:num_buildings_l(myid)-1)
                    build_ids_l(num_buildings_l(myid)) = building_id_f%var(j,i)
                    DEALLOCATE( build_ids_l_tmp )
                 ENDIF
 !
-!--          First occuring building id on PE 
-             ELSE 
+!--          First occuring building id on PE
+             ELSE
                 num_buildings_l(myid) = num_buildings_l(myid) + 1
                 build_ids_l(1) = building_id_f%var(j,i)
@@ -584,10 +604,9 @@
     ENDDO
 !
-!-- Determine number of building IDs for the entire domain. (Note, building IDs
-!-- can appear multiple times as buildings might be distributed over several
-!-- PEs.) 
-#if defined( __parallel ) 
-    CALL MPI_ALLREDUCE( num_buildings_l, num_buildings, numprocs,              &
-                        MPI_INTEGER, MPI_SUM, comm2d, ierr ) 
+!-- Determine number of building IDs for the entire domain. (Note, building IDs can appear multiple
+!-- times as buildings might be distributed over several PEs.)
+#if defined( __parallel )
+    CALL MPI_ALLREDUCE( num_buildings_l, num_buildings, numprocs, MPI_INTEGER, MPI_SUM, comm2d,    &
+                        ierr )
 #else
     num_buildings = num_buildings_l
@@ -595,6 +614,6 @@
     ALLOCATE( build_ids(1:SUM(num_buildings)) )
 !
-!-- Gather building IDs. Therefore, first, determine displacements used 
-!-- required for MPI_GATHERV call.
+!-- Gather building IDs. Therefore, first, determine displacements used required for MPI_GATHERV
+!-- call.
     ALLOCATE( displace_dum(0:numprocs-1) )
     displace_dum(0) = 0
@@ -603,13 +622,13 @@
     ENDDO
 
-#if defined( __parallel ) 
-    CALL MPI_ALLGATHERV( build_ids_l(1:num_buildings_l(myid)),                 &
-                         num_buildings(myid),                                  &
-                         MPI_INTEGER,                                          &
-                         build_ids,                                            &
-                         num_buildings,                                        &
-                         displace_dum,                                         & 
-                         MPI_INTEGER,                                          &
-                         comm2d, ierr )   
+#if defined( __parallel )
+    CALL MPI_ALLGATHERV( build_ids_l(1:num_buildings_l(myid)),                                     &
+                         num_buildings(myid),                                                      &
+                         MPI_INTEGER,                                                              &
+                         build_ids,                                                                &
+                         num_buildings,                                                            &
+                         displace_dum,                                                             &
+                         MPI_INTEGER,                                                              &
+                         comm2d, ierr )
 
     DEALLOCATE( displace_dum )
@@ -619,7 +638,6 @@
 #endif
 !
-!-- Note: in parallel mode, building IDs can occur mutliple times, as 
-!-- each PE has send its own ids. Therefore, sort out building IDs which 
-!-- appear multiple times. 
+!-- Note: in parallel mode, building IDs can occur mutliple times, as each PE has send its own ids.
+!-- Therefore, sort out building IDs which appear multiple times.
     num_build = 0
     DO  n = 1, SIZE(build_ids)
@@ -639,5 +657,5 @@
              build_ids_final(num_build) = build_ids(n)
              DEALLOCATE( build_ids_final_tmp )
-          ENDIF             
+          ENDIF
        ELSE
           num_build = num_build + 1
@@ -648,34 +666,31 @@
 
 !
-!-- Allocate building-data structure array. Note, this is a global array
-!-- and all building IDs on domain are known by each PE. Further attributes, 
-!-- e.g. height-dependent arrays, however, are only allocated on PEs where 
-!-- the respective building is present (in order to reduce memory demands).
+!-- Allocate building-data structure array. Note, this is a global array and all building IDs on
+!-- domain are known by each PE. Further attributes, e.g. height-dependent arrays, however, are only
+!-- allocated on PEs where  the respective building is present (in order to reduce memory demands).
     ALLOCATE( buildings(1:num_build) )
 
 !
-!-- Store building IDs and check if building with certain ID is present on
-!-- subdomain. 
+!-- Store building IDs and check if building with certain ID is present on subdomain.
     DO  nb = 1, num_build
        buildings(nb)%id = build_ids_final(nb)
 
-       IF ( ANY( building_id_f%var(nys:nyn,nxl:nxr) == buildings(nb)%id ) )    &
+       IF ( ANY( building_id_f%var(nys:nyn,nxl:nxr) == buildings(nb)%id ) )                        &
           buildings(nb)%on_pe = .TRUE.
-    ENDDO 
-!
-!-- Determine the maximum vertical dimension occupied by each building. 
+    ENDDO
+!
+!-- Determine the maximum vertical dimension occupied by each building.
     ALLOCATE( k_min_l(1:num_build) )
     ALLOCATE( k_max_l(1:num_build) )
     k_min_l = nzt + 1
-    k_max_l = 0    
+    k_max_l = 0
 
     DO  i = nxl, nxr
        DO  j = nys, nyn
           IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
-             nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ),    &
-                         DIM = 1 )
+             nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
              DO  k = nzb, nzt+1
 !
-!--             Check if grid point belongs to a building. 
+!--             Check if grid point belongs to a building.
                 IF ( BTEST( wall_flags_total_0(k,j,i), 6 ) )  THEN
                    k_min_l(nb) = MIN( k_min_l(nb), k )
@@ -688,9 +703,9 @@
     ENDDO
 
-#if defined( __parallel ) 
-    CALL MPI_ALLREDUCE( k_min_l(:), buildings(:)%kb_min, num_build,            &
-                        MPI_INTEGER, MPI_MIN, comm2d, ierr )
-    CALL MPI_ALLREDUCE( k_max_l(:), buildings(:)%kb_max, num_build,            &
-                        MPI_INTEGER, MPI_MAX, comm2d, ierr )
+#if defined( __parallel )
+    CALL MPI_ALLREDUCE( k_min_l(:), buildings(:)%kb_min, num_build, MPI_INTEGER, MPI_MIN, comm2d,  &
+                        ierr )
+    CALL MPI_ALLREDUCE( k_max_l(:), buildings(:)%kb_max, num_build, MPI_INTEGER, MPI_MAX, comm2d,  &
+                        ierr )
 #else
     buildings(:)%kb_min = k_min_l(:)
@@ -705,6 +720,5 @@
        buildings(nb)%building_height = 0.0_wp
        DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
-          buildings(nb)%building_height = buildings(nb)%building_height        &
-                                        + dzw(k+1)
+          buildings(nb)%building_height = buildings(nb)%building_height + dzw(k+1)
        ENDDO
     ENDDO
@@ -719,6 +733,5 @@
        volume_l = 0.0_wp
 !
-!--    Calculate building volume per height level on each PE where 
-!--    these building is present. 
+!--    Calculate building volume per height level on each PE where these building is present.
        IF ( buildings(nb)%on_pe )  THEN
 
@@ -727,11 +740,10 @@
           buildings(nb)%volume   = 0.0_wp
           buildings(nb)%vol_frac = 0.0_wp
-          
-          IF ( ANY( building_id_f%var(nys:nyn,nxl:nxr) == buildings(nb)%id ) ) &
-          THEN
+
+          IF ( ANY( building_id_f%var(nys:nyn,nxl:nxr) == buildings(nb)%id ) )  THEN
              DO  i = nxl, nxr
                 DO  j = nys, nyn
                    DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
-                      IF ( building_id_f%var(j,i) /= building_id_f%fill )      &
+                      IF ( building_id_f%var(j,i) /= building_id_f%fill )                          &
                          volume_l(k) = volume_l(k) + dx * dy * dzw(k+1)
                    ENDDO
@@ -742,13 +754,11 @@
 !
 !--    Sum-up building volume from all subdomains
-#if defined( __parallel ) 
-       CALL MPI_ALLREDUCE( volume_l, volume, SIZE(volume), MPI_REAL, MPI_SUM,  &
-                           comm2d, ierr )
+#if defined( __parallel )
+       CALL MPI_ALLREDUCE( volume_l, volume, SIZE(volume), MPI_REAL, MPI_SUM, comm2d, ierr )
 #else
        volume = volume_l
 #endif
 !
-!--    Save total building volume as well as local fraction on volume on 
-!--    building data structure.
+!--    Save total building volume as well as local fraction on volume on building data structure.
        IF ( ALLOCATED( buildings(nb)%volume ) )  buildings(nb)%volume = volume
 !
@@ -757,6 +767,5 @@
 !
 !--    Calculate total building volume
-       IF ( ALLOCATED( buildings(nb)%volume ) )                                &
-          buildings(nb)%vol_tot = SUM( buildings(nb)%volume )
+       IF ( ALLOCATED( buildings(nb)%volume ) )  buildings(nb)%vol_tot = SUM( buildings(nb)%volume )
 
        DEALLOCATE( volume   )
@@ -765,5 +774,5 @@
     ENDDO
 !
-!-- Allocate arrays for indoor temperature.  
+!-- Allocate arrays for indoor temperature.
     DO  nb = 1, num_build
        IF ( buildings(nb)%on_pe )  THEN
@@ -775,6 +784,6 @@
     ENDDO
 !
-!-- Allocate arrays for number of facades per height level. Distinguish between
-!-- horizontal and vertical facades. 
+!-- Allocate arrays for number of facades per height level. Distinguish between horizontal and
+!-- vertical facades.
     DO  nb = 1, num_build
        IF ( buildings(nb)%on_pe )  THEN
@@ -795,22 +804,22 @@
 !
 !--    For the current facade element determine corresponding building index.
-!--    First, obtain j,j,k indices of the building. Please note the
-!--    offset between facade/surface element and building location (for 
-!--    horizontal surface elements the horizontal offsets are zero).
+!--    First, obtain j,j,k indices of the building. Please note the offset between facade/surface
+!--    element and building location (for horizontal surface elements the horizontal offsets are
+!--    zero).
        i = surf_usm_h%i(m) + surf_usm_h%ioff
        j = surf_usm_h%j(m) + surf_usm_h%joff
        k = surf_usm_h%k(m) + surf_usm_h%koff
 !
-!--    Determine building index and check whether building is on PE
-       nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM = 1 )
+!--    Determine building index and check whether building is on PE.
+       nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
 
        IF ( buildings(nb)%on_pe )  THEN
 !
 !--       Count number of facade elements at each height level.
-          buildings(nb)%num_facade_h(k) = buildings(nb)%num_facade_h(k) + 1 
+          buildings(nb)%num_facade_h(k) = buildings(nb)%num_facade_h(k) + 1
 !
 !--       Moreover, sum up number of local facade elements per building.
-          buildings(nb)%num_facades_per_building_h_l =                         &
-                                buildings(nb)%num_facades_per_building_h_l + 1
+          buildings(nb)%num_facades_per_building_h_l =                                             &
+                                                      buildings(nb)%num_facades_per_building_h_l + 1
        ENDIF
     ENDDO
@@ -822,28 +831,26 @@
 !
 !--       For the current facade element determine corresponding building index.
-!--       First, obtain j,j,k indices of the building. Please note the
-!--       offset between facade/surface element and building location (for 
-!--       vertical surface elements the vertical offsets are zero).
+!--       First, obtain j,j,k indices of the building. Please note the offset between facade/surface
+!--       element and building location (for vertical surface elements the vertical offsets are
+!--       zero).
           i = surf_usm_v(l)%i(m) + surf_usm_v(l)%ioff
           j = surf_usm_v(l)%j(m) + surf_usm_v(l)%joff
           k = surf_usm_v(l)%k(m) + surf_usm_v(l)%koff
 
-          nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ),        &
-                       DIM = 1 )
+          nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
           IF ( buildings(nb)%on_pe )  THEN
-             buildings(nb)%num_facade_v(k) = buildings(nb)%num_facade_v(k) + 1 
-             buildings(nb)%num_facades_per_building_v_l =                      &
-                                buildings(nb)%num_facades_per_building_v_l + 1
+             buildings(nb)%num_facade_v(k) = buildings(nb)%num_facade_v(k) + 1
+             buildings(nb)%num_facades_per_building_v_l =                                          &
+                                                      buildings(nb)%num_facades_per_building_v_l + 1
           ENDIF
        ENDDO
     ENDDO
 !
-!-- Determine total number of facade elements per building and assign number to 
-!-- building data type.
+!-- Determine total number of facade elements per building and assign number to building data type.
     DO  nb = 1, num_build
 !
-!--    Allocate dummy array used for summing-up facade elements. 
-!--    Please note, dummy arguments are necessary as building-date type
-!--    arrays are not necessarily allocated on all PEs.
+!--    Allocate dummy array used for summing-up facade elements.
+!--    Please note, dummy arguments are necessary as building-date type arrays are not necessarily
+!--    allocated on all PEs.
        ALLOCATE( num_facades_h(buildings(nb)%kb_min:buildings(nb)%kb_max) )
        ALLOCATE( num_facades_v(buildings(nb)%kb_min:buildings(nb)%kb_max) )
@@ -860,24 +867,22 @@
        ENDIF
 
-#if defined( __parallel ) 
-       CALL MPI_ALLREDUCE( num_facades_h,                                      &
-                           receive_dum_h,                                      &
-                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,    &
-                           MPI_INTEGER,                                        &
-                           MPI_SUM,                                            &
-                           comm2d,                                             &
+#if defined( __parallel )
+       CALL MPI_ALLREDUCE( num_facades_h,                                                          &
+                           receive_dum_h,                                                          &
+                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,                        &
+                           MPI_INTEGER,                                                            &
+                           MPI_SUM,                                                                &
+                           comm2d,                                                                 &
                            ierr )
 
-       CALL MPI_ALLREDUCE( num_facades_v,                                      &
-                           receive_dum_v,                                      &
-                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,    &
-                           MPI_INTEGER,                                        &
-                           MPI_SUM,                                            &
-                           comm2d,                                             &
+       CALL MPI_ALLREDUCE( num_facades_v,                                                          &
+                           receive_dum_v,                                                          &
+                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,                        &
+                           MPI_INTEGER,                                                            &
+                           MPI_SUM,                                                                &
+                           comm2d,                                                                 &
                            ierr )
-       IF ( ALLOCATED( buildings(nb)%num_facade_h ) )                          &
-           buildings(nb)%num_facade_h = receive_dum_h
-       IF ( ALLOCATED( buildings(nb)%num_facade_v ) )                          &
-           buildings(nb)%num_facade_v = receive_dum_v
+       IF ( ALLOCATED( buildings(nb)%num_facade_h ) )  buildings(nb)%num_facade_h = receive_dum_h
+       IF ( ALLOCATED( buildings(nb)%num_facade_v ) )  buildings(nb)%num_facade_v = receive_dum_v
 #else
        buildings(nb)%num_facade_h = num_facades_h
@@ -893,6 +898,6 @@
 !
 !--    Allocate index arrays which link facade elements with surface-data type.
-!--    Please note, no height levels are considered here (information is stored
-!--    in surface-data type itself).
+!--    Please note, no height levels are considered here (information is stored in surface-data type
+!--    itself).
        IF ( buildings(nb)%on_pe )  THEN
 !
@@ -901,9 +906,8 @@
           buildings(nb)%num_facades_per_building_v = SUM( buildings(nb)%num_facade_v )
 !
-!--       Allocate arrays which link the building with the horizontal and vertical
-!--       urban-type surfaces. Please note, linking arrays are allocated over all
-!--       facade elements, which is required in case a building is located at the
-!--       subdomain boundaries, where the building and the corresponding surface
-!--       elements are located on different subdomains. 
+!--       Allocate arrays which link the building with the horizontal and vertical urban-type
+!--       surfaces. Please note, linking arrays are allocated over all facade elements, which is
+!--       required in case a building is located at the subdomain boundaries, where the building and
+!--       the corresponding surface elements are located on different subdomains.
           ALLOCATE( buildings(nb)%m_h(1:buildings(nb)%num_facades_per_building_h_l) )
 
@@ -916,27 +920,24 @@
           buildings(nb)%vpf = 0.0_wp
 
-          facade_area_v = 0.0_wp          
+          facade_area_v = 0.0_wp
           DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
-             facade_area_v = facade_area_v + buildings(nb)%num_facade_v(k)     &
-                             * dzw(k+1) * dx
+             facade_area_v = facade_area_v + buildings(nb)%num_facade_v(k) * dzw(k+1) * dx
           ENDDO
 !
-!--       Determine volume per total facade area (vpf). For the horizontal facade
-!--       area num_facades_per_building_h can be taken, multiplied with dx*dy. 
-!--       However, due to grid stretching, vertical facade elements must be
-!--       summed-up vertically. Please note, if dx /= dy, an error is made!
-          buildings(nb)%vpf = buildings(nb)%vol_tot /                          &
-                        ( buildings(nb)%num_facades_per_building_h * dx * dy + &
-                          facade_area_v )
+!--       Determine volume per total facade area (vpf). For the horizontal facade area
+!--       num_facades_per_building_h can be taken, multiplied with dx*dy.
+!--       However, due to grid stretching, vertical facade elements must be summed-up vertically.
+!--       Please note, if dx /= dy, an error is made!
+          buildings(nb)%vpf = buildings(nb)%vol_tot /                                              &
+                              ( buildings(nb)%num_facades_per_building_h * dx * dy + facade_area_v )
 !
 !--       Determine floor-area-per-facade.
-          buildings(nb)%fapf = buildings(nb)%num_facades_per_building_h        &
-                             * dx * dy                                         &
-                             / ( buildings(nb)%num_facades_per_building_h      &
-                               * dx * dy + facade_area_v )
+          buildings(nb)%fapf = buildings(nb)%num_facades_per_building_h     * dx * dy              &
+                               / ( buildings(nb)%num_facades_per_building_h * dx * dy              &
+                                   + facade_area_v )
        ENDIF
     ENDDO
 !
-!-- Link facade elements with surface data type. 
+!-- Link facade elements with surface data type.
 !-- Allocate array for counting.
     ALLOCATE( n_fa(1:num_build) )
@@ -947,9 +948,9 @@
        j = surf_usm_h%j(m) + surf_usm_h%joff
 
-       nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM = 1 )
+       nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
 
        IF ( buildings(nb)%on_pe )  THEN
           buildings(nb)%m_h(n_fa(nb)) = m
-          n_fa(nb) = n_fa(nb) + 1  
+          n_fa(nb) = n_fa(nb) + 1
        ENDIF
     ENDDO
@@ -961,10 +962,10 @@
           j = surf_usm_v(l)%j(m) + surf_usm_v(l)%joff
 
-          nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM = 1 )
+          nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
 
           IF ( buildings(nb)%on_pe )  THEN
              buildings(nb)%l_v(n_fa(nb)) = l
              buildings(nb)%m_v(n_fa(nb)) = m
-             n_fa(nb) = n_fa(nb) + 1   
+             n_fa(nb) = n_fa(nb) + 1
           ENDIF
        ENDDO
@@ -972,21 +973,21 @@
     DEALLOCATE( n_fa )
 !
-!-- Initialize building parameters, first by mean building type. Note,
-!-- in this case all buildings have the same type. 
-!-- In a second step initialize with building tpyes from static input file, 
-!-- where building types can be individual for each building.
+!-- Initialize building parameters, first by mean building type. Note, in this case all buildings
+!-- have the same type.
+!-- In a second step initialize with building tpyes from static input file, where building types can
+!-- be individual for each building.
     buildings(:)%lambda_layer3       = building_pars(31,building_type)
     buildings(:)%s_layer3            = building_pars(44,building_type)
     buildings(:)%f_c_win             = building_pars(119,building_type)
-    buildings(:)%g_value_win         = building_pars(120,building_type)    
-    buildings(:)%u_value_win         = building_pars(121,building_type)       
-    buildings(:)%eta_ve              = building_pars(124,building_type)    
-    buildings(:)%factor_a            = building_pars(125,building_type)    
+    buildings(:)%g_value_win         = building_pars(120,building_type)
+    buildings(:)%u_value_win         = building_pars(121,building_type)
+    buildings(:)%eta_ve              = building_pars(124,building_type)
+    buildings(:)%factor_a            = building_pars(125,building_type)
     buildings(:)%factor_c            = building_pars(126,building_type)
-    buildings(:)%lambda_at           = building_pars(127,building_type)    
-    buildings(:)%theta_int_h_set     = building_pars(13,building_type)    
+    buildings(:)%lambda_at           = building_pars(127,building_type)
+    buildings(:)%theta_int_h_set     = building_pars(13,building_type)
     buildings(:)%theta_int_c_set     = building_pars(12,building_type)
-    buildings(:)%q_h_max             = building_pars(128,building_type)    
-    buildings(:)%q_c_max             = building_pars(129,building_type)          
+    buildings(:)%q_h_max             = building_pars(128,building_type)
+    buildings(:)%q_c_max             = building_pars(129,building_type)
     buildings(:)%qint_high           = building_pars(130,building_type)
     buildings(:)%qint_low            = building_pars(131,building_type)
@@ -997,34 +998,33 @@
 !
 !-- Initialize seasonal dependent parameters, depending on day of the year.
-!-- First, calculated day of the year. 
+!-- First, calculated day of the year.
     CALL get_date_time( time_since_reference_point, day_of_year = day_of_year )
 !
-!-- Summer is defined in between northward- and southward equinox. 
-    IF ( day_of_year >= northward_equinox  .AND.                               &
-         day_of_year <= southward_equinox )  THEN
-       buildings(:)%air_change_low      = summer_pars(0,building_type)    
+!-- Summer is defined in between northward- and southward equinox.
+    IF ( day_of_year >= northward_equinox  .AND.  day_of_year <= southward_equinox )  THEN
+       buildings(:)%air_change_low      = summer_pars(0,building_type)
        buildings(:)%air_change_high     = summer_pars(1,building_type)
     ELSE
-       buildings(:)%air_change_low      = winter_pars(0,building_type)    
+       buildings(:)%air_change_low      = winter_pars(0,building_type)
        buildings(:)%air_change_high     = winter_pars(1,building_type)
     ENDIF
 !
-!-- Initialize ventilaation load. Please note, building types > 7 are actually
-!-- not allowed (check already in urban_surface_mod and netcdf_data_input_mod. 
-!-- However, the building data base may be later extended. 
-    IF ( building_type ==  1  .OR.  building_type ==  2  .OR.                  &
-         building_type ==  3  .OR.  building_type == 10  .OR.                  &
+!-- Initialize ventilation load. Please note, building types > 7 are actually not allowed (check
+!-- already in urban_surface_mod and netcdf_data_input_mod.
+!-- However, the building data base may be later extended.
+    IF ( building_type ==  1  .OR.  building_type ==  2  .OR.                                      &
+         building_type ==  3  .OR.  building_type == 10  .OR.                                      &
          building_type == 11  .OR.  building_type == 12 )  THEN
        buildings(:)%ventilation_int_loads = 1
 !
 !-- Office, building with large windows
-    ELSEIF ( building_type ==  4  .OR.  building_type ==  5  .OR.              &
-             building_type ==  6  .OR.  building_type ==  7  .OR.              &
+    ELSEIF ( building_type ==  4  .OR.  building_type ==  5  .OR.                                  &
+             building_type ==  6  .OR.  building_type ==  7  .OR.                                  &
              building_type ==  8  .OR.  building_type ==  9)  THEN
        buildings(:)%ventilation_int_loads = 2
 !
 !-- Industry, hospitals
-    ELSEIF ( building_type == 13  .OR.  building_type == 14  .OR.              &
-             building_type == 15  .OR.  building_type == 16  .OR.              &
+    ELSEIF ( building_type == 13  .OR.  building_type == 14  .OR.                                  &
+             building_type == 15  .OR.  building_type == 16  .OR.                                  &
              building_type == 17  .OR.  building_type == 18 )  THEN
        buildings(:)%ventilation_int_loads = 3
@@ -1036,56 +1036,54 @@
           DO  j = nys, nyn
               IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
-                 nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), &
-                              DIM = 1 )
+                 nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
                  bt = building_type_f%var(j,i)
-                 
+
                  buildings(nb)%lambda_layer3       = building_pars(31,bt)
                  buildings(nb)%s_layer3            = building_pars(44,bt)
                  buildings(nb)%f_c_win             = building_pars(119,bt)
-                 buildings(nb)%g_value_win         = building_pars(120,bt)    
-                 buildings(nb)%u_value_win         = building_pars(121,bt)    
-                 buildings(nb)%eta_ve              = building_pars(124,bt)    
-                 buildings(nb)%factor_a            = building_pars(125,bt)    
+                 buildings(nb)%g_value_win         = building_pars(120,bt)
+                 buildings(nb)%u_value_win         = building_pars(121,bt)
+                 buildings(nb)%eta_ve              = building_pars(124,bt)
+                 buildings(nb)%factor_a            = building_pars(125,bt)
                  buildings(nb)%factor_c            = building_pars(126,bt)
-                 buildings(nb)%lambda_at           = building_pars(127,bt)    
-                 buildings(nb)%theta_int_h_set     = building_pars(13,bt)    
+                 buildings(nb)%lambda_at           = building_pars(127,bt)
+                 buildings(nb)%theta_int_h_set     = building_pars(13,bt)
                  buildings(nb)%theta_int_c_set     = building_pars(12,bt)
-                 buildings(nb)%q_h_max             = building_pars(128,bt)    
-                 buildings(nb)%q_c_max             = building_pars(129,bt)          
+                 buildings(nb)%q_h_max             = building_pars(128,bt)
+                 buildings(nb)%q_c_max             = building_pars(129,bt)
                  buildings(nb)%qint_high           = building_pars(130,bt)
                  buildings(nb)%qint_low            = building_pars(131,bt)
                  buildings(nb)%height_storey       = building_pars(132,bt)
-                 buildings(nb)%height_cei_con      = building_pars(133,bt) 
+                 buildings(nb)%height_cei_con      = building_pars(133,bt)
                  buildings(nb)%params_waste_heat_h = building_pars(134,bt)
                  buildings(nb)%params_waste_heat_c = building_pars(135,bt)
 
-              IF ( day_of_year >= northward_equinox  .AND.                     &
-                   day_of_year <= southward_equinox )  THEN
-                 buildings(nb)%air_change_low      = summer_pars(0,bt)    
+              IF ( day_of_year >= northward_equinox  .AND.  day_of_year <= southward_equinox )  THEN
+                 buildings(nb)%air_change_low      = summer_pars(0,bt)
                  buildings(nb)%air_change_high     = summer_pars(1,bt)
               ELSE
-                 buildings(nb)%air_change_low      = winter_pars(0,bt)    
+                 buildings(nb)%air_change_low      = winter_pars(0,bt)
                  buildings(nb)%air_change_high     = winter_pars(1,bt)
               ENDIF
 
 !
-!--              Initialize ventilaation load. Please note, building types > 7 
-!--              are actually not allowed (check already in urban_surface_mod  
-!--              and netcdf_data_input_mod. However, the building data base may 
-!--              be later extended. 
-                 IF ( bt ==  1  .OR.  bt ==  2  .OR.                           &
-                      bt ==  3  .OR.  bt == 10  .OR.                           &
+!--              Initialize ventilaation load. Please note, building types > 7
+!--              are actually not allowed (check already in urban_surface_mod
+!--              and netcdf_data_input_mod. However, the building data base may
+!--              be later extended.
+                 IF ( bt ==  1  .OR.  bt ==  2  .OR.                                               &
+                      bt ==  3  .OR.  bt == 10  .OR.                                               &
                       bt == 11  .OR.  bt == 12 )  THEN
                     buildings(nb)%ventilation_int_loads = 1
-!                    
+!
 !--              Office, building with large windows
-                 ELSEIF ( bt ==  4  .OR.  bt ==  5  .OR.                       &
-                          bt ==  6  .OR.  bt ==  7  .OR.                       &
+                 ELSEIF ( bt ==  4  .OR.  bt ==  5  .OR.                                           &
+                          bt ==  6  .OR.  bt ==  7  .OR.                                           &
                           bt ==  8  .OR.  bt ==  9)  THEN
                     buildings(nb)%ventilation_int_loads = 2
 !
 !--              Industry, hospitals
-                 ELSEIF ( bt == 13  .OR.  bt == 14  .OR.                       &
-                          bt == 15  .OR.  bt == 16  .OR.                       &
+                 ELSEIF ( bt == 13  .OR.  bt == 14  .OR.                                           &
+                          bt == 15  .OR.  bt == 16  .OR.                                           &
                           bt == 17  .OR.  bt == 18 )  THEN
                     buildings(nb)%ventilation_int_loads = 3
@@ -1096,16 +1094,16 @@
     ENDIF
 !
-!-- Calculation of surface-related heat transfer coeffiecient
-!-- out of standard u-values from building database 
-!-- only amount of extern and surface is used
-!-- otherwise amount between air and surface taken account twice
+!-- Calculation of surface-related heat transfer coeffiecient out of standard u-values from building
+!-- database.
+!-- Only amount of extern and surface is used.
+!-- Otherwise amount between air and surface taken account twice.
     DO nb = 1, num_build
-       IF ( buildings(nb)%on_pe ) THEN   
+       IF ( buildings(nb)%on_pe ) THEN
           du_win_tmp = 1.0_wp / buildings(nb)%u_value_win
-          u_tmp = buildings(nb)%u_value_win * ( du_win_tmp / ( du_win_tmp -    &
+          u_tmp = buildings(nb)%u_value_win * ( du_win_tmp / ( du_win_tmp -                        &
                   0.125_wp + ( 1.0_wp / h_is ) ) )
-                  
+
           du_tmp = 1.0_wp / u_tmp
-          
+
           buildings(nb)%h_es = 1.0_wp / ( du_tmp - ( 1.0_wp / h_is ) )
 
@@ -1119,6 +1117,5 @@
 !-- Initialize indoor temperature. Actually only for output at initial state.
     DO  nb = 1, num_build
-       IF ( buildings(nb)%on_pe )                                              &
-          buildings(nb)%t_in(:) = initial_indoor_temperature
+       IF ( buildings(nb)%on_pe )  buildings(nb)%t_in(:) = initial_indoor_temperature
     ENDDO
 
@@ -1128,10 +1125,10 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Main part of the indoor model.
 !> Calculation of .... (kanani: Please describe)
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE im_main_heatcool
 
@@ -1139,19 +1136,20 @@
 !         ONLY:  c_p
 
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  time_since_reference_point
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                                            &
         ONLY:  dx, dy
 
     USE pegrid
-    
-    USE surface_mod,                                                           &
+
+    USE surface_mod,                                                                               &
         ONLY:  ind_veg_wall, ind_wat_win, surf_usm_h, surf_usm_v
 
-    USE urban_surface_mod,                                                     &
-        ONLY:  nzt_wall, t_wall_h, t_wall_v, t_window_h, t_window_v,           &
-               building_type
-
+    USE urban_surface_mod,                                                                         &
+        ONLY:  building_type, nzt_wall, t_wall_h, t_wall_v, t_window_h, t_window_v
+
+
+    INTEGER(iwp) ::  fa   !< running index for facade elements of each building
     INTEGER(iwp) ::  i    !< index of facade-adjacent atmosphere grid point in x-direction
     INTEGER(iwp) ::  j    !< index of facade-adjacent atmosphere grid point in y-direction
@@ -1161,5 +1159,4 @@
     INTEGER(iwp) ::  m    !< running index surface elements
     INTEGER(iwp) ::  nb   !< running index for buildings
-    INTEGER(iwp) ::  fa   !< running index for facade elements of each building
 
     REAL(wp) ::  indoor_wall_window_temperature   !< weighted temperature of innermost wall/window layer
@@ -1171,5 +1168,5 @@
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_in_recv     !< dummy recv buffer used for summing-up indoor temperature per kk-level
 !
-!-- Determine time of day in hours. 
+!-- Determine time of day in hours.
     CALL get_date_time( time_since_reference_point, second_of_day=second_of_day )
     time_utc_hour = second_of_day / seconds_per_hour
@@ -1178,9 +1175,9 @@
     DO  nb = 1, num_build
 !
-!--    First, check whether building is present on local subdomain. 
+!--    First, check whether building is present on local subdomain.
        IF ( buildings(nb)%on_pe )  THEN
 !
 !--       Determine daily schedule. 08:00-18:00 = 1, other hours = 0.
-!--       Residental Building, panel WBS 70    
+!--       Residental Building, panel WBS 70
           IF ( buildings(nb)%ventilation_int_loads == 1 )  THEN
              IF ( time_utc_hour >= 8.0_wp  .AND.  time_utc_hour <= 18.0_wp )  THEN
@@ -1199,5 +1196,5 @@
              ENDIF
           ENDIF
-!       
+!
 !--       Industry, hospitals
           IF ( buildings(nb)%ventilation_int_loads == 3 )  THEN
@@ -1210,58 +1207,64 @@
 !
 !--       Initialize/reset indoor temperature
-          buildings(nb)%t_in_l = 0.0_wp 
+          buildings(nb)%t_in_l = 0.0_wp
 !
 !--       Horizontal surfaces
           DO  fa = 1, buildings(nb)%num_facades_per_building_h_l
 !
-!--          Determine index where corresponding surface-type information 
-!--          is stored. 
+!--          Determine index where corresponding surface-type information is stored.
              m = buildings(nb)%m_h(fa)
 !
-!--          Determine building height level index. 
+!--          Determine building height level index.
              kk = surf_usm_h%k(m) + surf_usm_h%koff
 !
 !--          Building geometries --> not time-dependent
-             facade_element_area          = dx * dy                               !< [m2] surface area per facade element    
+             facade_element_area          = dx * dy                               !< [m2] surface area per facade element
              floor_area_per_facade        = buildings(nb)%fapf                    !< [m2/m2] floor area per facade area
-             indoor_volume_per_facade     = buildings(nb)%vpf(kk)                 !< [m3/m2] indoor air volume per facade area 
-             buildings(nb)%area_facade    = facade_element_area *                                   &
-                                          ( buildings(nb)%num_facades_per_building_h +              &
-                                            buildings(nb)%num_facades_per_building_v )                !< [m2] area of total facade
-             window_area_per_facade       = surf_usm_h%frac(m,ind_wat_win)  * facade_element_area     !< [m2] window area per facade element
+             indoor_volume_per_facade     = buildings(nb)%vpf(kk)                 !< [m3/m2] indoor air volume per facade area
+             buildings(nb)%area_facade    = facade_element_area *                                  &
+                                            ( buildings(nb)%num_facades_per_building_h +           &
+                                              buildings(nb)%num_facades_per_building_v )              !< [m2] area of total facade
+             window_area_per_facade       = surf_usm_h%frac(m,ind_wat_win)  * facade_element_area     !< [m2] window area per facade
+                                                                                                      !< element
 
              buildings(nb)%net_floor_area = buildings(nb)%vol_tot / ( buildings(nb)%height_storey )
-             total_area                   = buildings(nb)%net_floor_area                              !< [m2] area of all surfaces pointing to zone  Eq. (9) according to section 7.2.2.2
-             a_m                          = buildings(nb)%factor_a * total_area *                   &
-                                          ( facade_element_area / buildings(nb)%area_facade ) *     &
-                                            buildings(nb)%lambda_at                                   !< [m2] standard values according to Table 12 section 12.3.1.2  (calculate over Eq. (65) according to section 12.3.1.2)
-             c_m                          = buildings(nb)%factor_c * total_area *                   &
-                                          ( facade_element_area / buildings(nb)%area_facade )         !< [J/K] standard values according to table 12 section 12.3.1.2 (calculate over Eq. (66) according to section 12.3.1.2)             
+             total_area                   = buildings(nb)%net_floor_area                            !< [m2] area of all surfaces
+                                                                                                    !< pointing to zone  Eq. (9) according to section 7.2.2.2
+             a_m                          = buildings(nb)%factor_a * total_area *                  &
+                                            ( facade_element_area / buildings(nb)%area_facade ) *  &
+                                            buildings(nb)%lambda_at                                 !< [m2] standard values
+                                                                                                    !< according to Table 12 section 12.3.1.2  (calculate over Eq. (65) according to section 12.3.1.2)
+             c_m                          = buildings(nb)%factor_c * total_area *                  &
+                                            ( facade_element_area / buildings(nb)%area_facade )     !< [J/K] standard values
+                                                                                                    !< according to table 12 section 12.3.1.2 (calculate over Eq. (66) according to section 12.3.1.2)
 !
 !--          Calculation of heat transfer coefficient for transmission --> not time-dependent
              h_t_es   = window_area_per_facade * buildings(nb)%h_es                                   !< [W/K] only for windows
 
-             h_t_is  = buildings(nb)%area_facade  * h_is                                                             !< [W/K] with h_is = 3.45 W / (m2 K) between surface and air, Eq. (9)
-             h_t_ms  = a_m * h_ms                                                                     !< [W/K] with h_ms = 9.10 W / (m2 K) between component and surface, Eq. (64)
-             h_t_wall  = 1.0_wp / ( 1.0_wp / ( ( facade_element_area - window_area_per_facade )     & !< [W/K] 
+             h_t_is  = buildings(nb)%area_facade * h_is                                               !< [W/K] with h_is = 3.45 W /
+                                                                                                      !< (m2 K) between surface and air, Eq. (9)
+             h_t_ms  = a_m * h_ms                                                                     !< [W/K] with h_ms = 9.10 W /
+                                                                                                      !< (m2 K) between component and surface, Eq. (64)
+             h_t_wall  = 1.0_wp / ( 1.0_wp / ( ( facade_element_area - window_area_per_facade )    &  !< [W/K]
                                     * buildings(nb)%lambda_layer3 / buildings(nb)%s_layer3 * 0.5_wp &
                                              ) + 1.0_wp / h_t_ms )                                    !< [W/K] opaque components
-             h_t_wm  = 1.0_wp / ( 1.0_wp / h_t_wall - 1.0_wp / h_t_ms )                               !< [W/K] emmision Eq. (63), Section 12.2.2
-!
-!--          internal air loads dependent on the occupacy of the room
-!--          basical internal heat gains (qint_low) with additional internal heat gains by occupancy (qint_high) (0,5*phi_int)
-             phi_ia = 0.5_wp * ( ( buildings(nb)%qint_high * schedule_d + buildings(nb)%qint_low )  &
-                              * floor_area_per_facade ) 
+             h_t_wm  = 1.0_wp / ( 1.0_wp / h_t_wall - 1.0_wp / h_t_ms )                               !< [W/K] emmision Eq. (63),
+                                                                                                      !< Section 12.2.2
+!
+!--          Internal air loads dependent on the occupacy of the room.
+!--          Basical internal heat gains (qint_low) with additional internal heat gains by occupancy (qint_high) (0,5*phi_int).
+             phi_ia = 0.5_wp * ( ( buildings(nb)%qint_high * schedule_d + buildings(nb)%qint_low ) &
+                              * floor_area_per_facade )
              q_int = phi_ia / total_area
 !
-!--          Airflow dependent on the occupacy of the room
-!--          basical airflow (air_change_low) with additional airflow gains by occupancy (air_change_high)
-             air_change = ( buildings(nb)%air_change_high * schedule_d + buildings(nb)%air_change_low )  !< [1/h]? 
-!
-!--          Heat transfer of ventilation 
-!--          not less than 0.01 W/K to provide division by 0 in further calculations
-!--          with heat capacity of air 0.33 Wh/m2K
-             h_v   = MAX( 0.01_wp , ( air_change * indoor_volume_per_facade *      &
-                                    0.33_wp * (1.0_wp - buildings(nb)%eta_ve ) ) )    !< [W/K] from ISO 13789 Eq.(10)
+!--          Airflow dependent on the occupacy of the room.
+!--          Basical airflow (air_change_low) with additional airflow gains by occupancy (air_change_high)
+             air_change = ( buildings(nb)%air_change_high * schedule_d + buildings(nb)%air_change_low )  !< [1/h]?
+!
+!--          Heat transfer of ventilation.
+!--          Not less than 0.01 W/K to avoid division by 0 in further calculations with heat
+!--          capacity of air 0.33 Wh/m2K.
+             h_v   = MAX( 0.01_wp , ( air_change * indoor_volume_per_facade *                      &
+                                      0.33_wp * (1.0_wp - buildings(nb)%eta_ve ) ) )    !< [W/K] from ISO 13789 Eq.(10)
 
 !--          Heat transfer coefficient auxiliary variables
@@ -1278,47 +1281,53 @@
              k = surf_usm_h%k(m)
              near_facade_temperature = surf_usm_h%pt_10cm(m)
-             indoor_wall_window_temperature =                                  &
-                  surf_usm_h%frac(m,ind_veg_wall) * t_wall_h(nzt_wall,m)       &
-                + surf_usm_h%frac(m,ind_wat_win)  * t_window_h(nzt_wall,m)
-!
-!--          Solar thermal gains. If net_sw_in larger than sun-protection 
-!--          threshold parameter (params_solar_protection), sun protection will 
-!--          be activated
-             IF ( net_sw_in <= params_solar_protection )  THEN 
+             indoor_wall_window_temperature =                                                      &
+                                            surf_usm_h%frac(m,ind_veg_wall) * t_wall_h(nzt_wall,m) &
+                                          + surf_usm_h%frac(m,ind_wat_win)  * t_window_h(nzt_wall,m)
+!
+!--          Solar thermal gains. If net_sw_in larger than sun-protection threshold parameter
+!--          (params_solar_protection), sun protection will be activated.
+             IF ( net_sw_in <= params_solar_protection )  THEN
                 solar_protection_off = 1
                 solar_protection_on  = 0
-             ELSE 
+             ELSE
                 solar_protection_off = 0
                 solar_protection_on  = 1
              ENDIF
 !
-!--          Calculation of total heat gains from net_sw_in through windows [W] in respect on automatic sun protection 
+!--          Calculation of total heat gains from net_sw_in through windows [W] in respect on
+!--          automatic sun protection.
 !--          DIN 4108 - 2 chap.8
-             phi_sol = (   window_area_per_facade * net_sw_in * solar_protection_off                           &
-                         + window_area_per_facade * net_sw_in * buildings(nb)%f_c_win * solar_protection_on )  &
+             phi_sol = (   window_area_per_facade * net_sw_in * solar_protection_off               &
+                         + window_area_per_facade * net_sw_in * buildings(nb)%f_c_win *            &
+                           solar_protection_on )                                                   &
                        * buildings(nb)%g_value_win * ( 1.0_wp - params_f_f ) * params_f_w
-             q_sol = phi_sol           
-!
-!--          Calculation of the mass specific thermal load for internal and external heatsources of the inner node
-             phi_m   = (a_m / total_area) * ( phi_ia + phi_sol )                                    !< [W] Eq. (C.2) with phi_ia=0,5*phi_int
+             q_sol = phi_sol
+!
+!--          Calculation of the mass specific thermal load for internal and external heatsources of
+!--          the inner node.
+             phi_m   = (a_m / total_area) * ( phi_ia + phi_sol )                                    !< [W] Eq. (C.2) with
+                                                                                                    !< phi_ia=0,5*phi_int
              q_c_m = phi_m
 !
-!--          Calculation mass specific thermal load implied non thermal mass 
-             phi_st  =   ( 1.0_wp - ( a_m / total_area ) - ( h_t_es / ( 9.1_wp * total_area ) ) ) &
-                       * ( phi_ia + phi_sol )                                                       !< [W] Eq. (C.3) with phi_ia=0,5*phi_int
-             q_c_st = phi_st            
+!--          Calculation mass specific thermal load implied non thermal mass
+             phi_st  =   ( 1.0_wp - ( a_m / total_area ) - ( h_t_es / ( 9.1_wp * total_area ) ) )  &
+                       * ( phi_ia + phi_sol )                                                       !< [W] Eq. (C.3) with
+                                                                                                    !< phi_ia=0,5*phi_int
+             q_c_st = phi_st
 !
 !--          Calculations for deriving indoor temperature and heat flux into the wall
-!--          Step 1: Indoor temperature without heating and cooling
+!--          Step 1: indoor temperature without heating and cooling
 !--          section C.4.1 Picture C.2 zone 3)
              phi_hc_nd = 0.0_wp
-             
-             CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
-                                         near_facade_temperature, phi_hc_nd )
-!
-!--          If air temperature between border temperatures of heating and cooling, assign output variable, then ready   
-             IF ( buildings(nb)%theta_int_h_set <= theta_air  .AND.  theta_air <= buildings(nb)%theta_int_c_set )  THEN
+
+             CALL  im_calc_temperatures ( i, j, k, indoor_wall_window_temperature,                 &
+                                          near_facade_temperature, phi_hc_nd )
+!
+!--          If air temperature between border temperatures of heating and cooling, assign output
+!--          variable, then ready.
+             IF ( buildings(nb)%theta_int_h_set <= theta_air  .AND.                                &
+                  theta_air <= buildings(nb)%theta_int_c_set )  THEN
                 phi_hc_nd_ac = 0.0_wp
-                phi_hc_nd    = phi_hc_nd_ac            
+                phi_hc_nd    = phi_hc_nd_ac
                 theta_air_ac = theta_air
 !
@@ -1328,46 +1337,48 @@
 !
 !--             Temperature not correct, calculation method according to section C4.2
-                theta_air_0 = theta_air                                                  !< temperature without heating/cooling  
+                theta_air_0 = theta_air                                                  !< temperature without heating/cooling
 !
 !--             Heating or cooling?
                 IF ( theta_air_0 > buildings(nb)%theta_int_c_set )  THEN
                    theta_air_set = buildings(nb)%theta_int_c_set
-                ELSE 
-                   theta_air_set = buildings(nb)%theta_int_h_set 
+                ELSE
+                   theta_air_set = buildings(nb)%theta_int_h_set
                 ENDIF
 !
-!--             Calculate the temperature with phi_hc_nd_10 
+!--             Calculate the temperature with phi_hc_nd_10
                 phi_hc_nd_10 = 10.0_wp * floor_area_per_facade
                 phi_hc_nd    = phi_hc_nd_10
-                
-                CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
-                                            near_facade_temperature, phi_hc_nd )
+
+                CALL  im_calc_temperatures ( i, j, k, indoor_wall_window_temperature,              &
+                                             near_facade_temperature, phi_hc_nd )
                 theta_air_10 = theta_air                                                !< temperature with 10 W/m2 of heating
-                phi_hc_nd_un = phi_hc_nd_10 * (theta_air_set - theta_air_0)          &
+                phi_hc_nd_un = phi_hc_nd_10 * (theta_air_set - theta_air_0)                        &
                                             / (theta_air_10  - theta_air_0)             !< Eq. (C.13)
 !
-!--             Step 3: With temperature ratio to determine the heating or cooling capacity    
-!--             If necessary, limit the power to maximum power
+!--             Step 3: with temperature ratio to determine the heating or cooling capacity.
+!--             If necessary, limit the power to maximum power.
 !--             section C.4.1 Picture C.2 zone 2) and 4)
-                buildings(nb)%phi_c_max = buildings(nb)%q_c_max * floor_area_per_facade              
+                buildings(nb)%phi_c_max = buildings(nb)%q_c_max * floor_area_per_facade
                 buildings(nb)%phi_h_max = buildings(nb)%q_h_max * floor_area_per_facade
-                IF ( buildings(nb)%phi_c_max < phi_hc_nd_un  .AND.  phi_hc_nd_un < buildings(nb)%phi_h_max )  THEN
+                IF ( buildings(nb)%phi_c_max < phi_hc_nd_un  .AND.                                 &
+                     phi_hc_nd_un < buildings(nb)%phi_h_max )  THEN
                    phi_hc_nd_ac = phi_hc_nd_un
-                   phi_hc_nd = phi_hc_nd_un  
+                   phi_hc_nd = phi_hc_nd_un
                 ELSE
 !
-!--             Step 4: Inner temperature with maximum heating (phi_hc_nd_un positive) or cooling (phi_hc_nd_un negative)
+!--             Step 4: inner temperature with maximum heating (phi_hc_nd_un positive) or cooling
+!--                     (phi_hc_nd_un negative)
 !--             section C.4.1 Picture C.2 zone 1) and 5)
                    IF ( phi_hc_nd_un > 0.0_wp )  THEN
                       phi_hc_nd_ac = buildings(nb)%phi_h_max                            !< Limit heating
-                   ELSE 
+                   ELSE
                       phi_hc_nd_ac = buildings(nb)%phi_c_max                            !< Limit cooling
                    ENDIF
                 ENDIF
-                phi_hc_nd = phi_hc_nd_ac   
+                phi_hc_nd = phi_hc_nd_ac
 !
 !--             Calculate the temperature with phi_hc_nd_ac (new)
-                CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
-                                            near_facade_temperature, phi_hc_nd )
+                CALL  im_calc_temperatures ( i, j, k, indoor_wall_window_temperature,              &
+                                             near_facade_temperature, phi_hc_nd )
                 theta_air_ac = theta_air
              ENDIF
@@ -1375,19 +1386,19 @@
 !--          Update theta_m_t_prev
              theta_m_t_prev = theta_m_t
-             
+
              q_vent = h_v * ( theta_air - near_facade_temperature )
 !
-!--          Calculate the operating temperature with weighted mean temperature of air and mean solar temperature
-!--          Will be used for thermal comfort calculations 
+!--          Calculate the operating temperature with weighted mean temperature of air and mean
+!--          solar temperature.
+!--          Will be used for thermal comfort calculations.
              theta_op     = 0.3_wp * theta_air_ac + 0.7_wp * theta_s          !< [degree_C] operative Temperature Eq. (C.12)
 !              surf_usm_h%t_indoor(m) = theta_op                               !< not integrated now
 !
-!--          Heat flux into the wall. Value needed in urban_surface_mod to 
+!--          Heat flux into the wall. Value needed in urban_surface_mod to
 !--          calculate heat transfer through wall layers towards the facade
 !--          (use c_p * rho_surface to convert [W/m2] into [K m/s])
-             q_wall_win = h_t_ms * ( theta_s - theta_m )                       &
-                                    / (   facade_element_area                  &
-                                        - window_area_per_facade )
-             q_trans = q_wall_win * facade_element_area                                        
+             q_wall_win = h_t_ms * ( theta_s - theta_m )                                           &
+                                    / ( facade_element_area - window_area_per_facade )
+             q_trans = q_wall_win * facade_element_area
 !
 !--          Transfer q_wall_win back to USM (innermost wall/window layer)
@@ -1395,23 +1406,23 @@
              surf_usm_h%iwghf_eb_window(m) = q_wall_win
 !
-!--          Sum up operational indoor temperature per kk-level. Further below,
-!--          this temperature is reduced by MPI to one temperature per kk-level
-!--          and building (processor overlapping)
+!--          Sum up operational indoor temperature per kk-level. Further below, this temperature is
+!--          reduced by MPI to one temperature per kk-level and building (processor overlapping).
              buildings(nb)%t_in_l(kk) = buildings(nb)%t_in_l(kk) + theta_op
 !
-!--          Calculation of waste heat
-!--          Anthropogenic heat output
-             IF ( phi_hc_nd_ac > 0.0_wp )  THEN 
+!--          Calculation of waste heat.
+!--          Anthropogenic heat output.
+             IF ( phi_hc_nd_ac > 0.0_wp )  THEN
                 heating_on = 1
                 cooling_on = 0
-             ELSE 
+             ELSE
                 heating_on = 0
                 cooling_on = -1
              ENDIF
 
-             q_waste_heat = ( phi_hc_nd * (                                    &
-                              buildings(nb)%params_waste_heat_h * heating_on + &
-                              buildings(nb)%params_waste_heat_c * cooling_on ) &
-                            ) / facade_element_area                                               !< [W/m2] , observe the directional convention in PALM!
+             q_waste_heat = ( phi_hc_nd * (                                                        &
+                              buildings(nb)%params_waste_heat_h * heating_on +                     &
+                              buildings(nb)%params_waste_heat_c * cooling_on )                     &
+                            ) / facade_element_area                                             !< [W/m2] , observe the directional
+                                                                                                !< convention in PALM!
              surf_usm_h%waste_heat(m) = q_waste_heat
           ENDDO !< Horizontal surfaces loop
@@ -1420,13 +1431,12 @@
           DO  fa = 1, buildings(nb)%num_facades_per_building_v_l
 !
-!--          Determine indices where corresponding surface-type information 
-!--          is stored. 
+!--          Determine indices where corresponding surface-type information is stored.
              l = buildings(nb)%l_v(fa)
              m = buildings(nb)%m_v(fa)
 !
-!--          Determine building height level index. 
+!--          Determine building height level index.
              kk = surf_usm_v(l)%k(m) + surf_usm_v(l)%koff
 !
-!--          (SOME OF THE FOLLOWING (not time-dependent COULD PROBABLY GO INTO A FUNCTION
+!--          (SOME OF THE FOLLOWING (not time-dependent) COULD PROBABLY GO INTO A FUNCTION
 !--          EXCEPT facade_element_area, EVERYTHING IS CALCULATED EQUALLY)
 !--          Building geometries  --> not time-dependent
@@ -1435,45 +1445,55 @@
 
              floor_area_per_facade        = buildings(nb)%fapf                  !< [m2/m2] floor area per facade area
-             indoor_volume_per_facade     = buildings(nb)%vpf(kk)               !< [m3/m2] indoor air volume per facade area 
-             buildings(nb)%area_facade    = facade_element_area *                                   &
-                                          ( buildings(nb)%num_facades_per_building_h +              &
-                                            buildings(nb)%num_facades_per_building_v )                !< [m2] area of total facade
-             window_area_per_facade       = surf_usm_v(l)%frac(m,ind_wat_win)  * facade_element_area  !< [m2] window area per facade element
+             indoor_volume_per_facade     = buildings(nb)%vpf(kk)               !< [m3/m2] indoor air volume per facade area
+             buildings(nb)%area_facade    = facade_element_area *                                  &
+                                            ( buildings(nb)%num_facades_per_building_h +           &
+                                              buildings(nb)%num_facades_per_building_v )              !< [m2] area of total facade
+             window_area_per_facade       = surf_usm_v(l)%frac(m,ind_wat_win) * facade_element_area   !< [m2] window area per
+                                                                                                      !< facade element
 
              buildings(nb)%net_floor_area = buildings(nb)%vol_tot / ( buildings(nb)%height_storey )
-             total_area                   = buildings(nb)%net_floor_area                              !< [m2] area of all surfaces pointing to zone  Eq. (9) according to section 7.2.2.2
-             a_m                          = buildings(nb)%factor_a * total_area *                   &
-                                          ( facade_element_area / buildings(nb)%area_facade ) *     &
-                                            buildings(nb)%lambda_at                                   !< [m2] standard values according to Table 12 section 12.3.1.2  (calculate over Eq. (65) according to section 12.3.1.2)
+             total_area                   = buildings(nb)%net_floor_area                              !< [m2] area of all surfaces
+                                                                                                      !< pointing to zone  Eq. (9) according to section 7.2.2.2
+             a_m                          = buildings(nb)%factor_a * total_area *                  &
+                                            ( facade_element_area / buildings(nb)%area_facade ) *  &
+                                              buildings(nb)%lambda_at                                 !< [m2] standard values
+                                                                                                      !< according to Table 12 section 12.3.1.2  (calculate over Eq. (65) according to section 12.3.1.2)
              c_m                          = buildings(nb)%factor_c * total_area *                   &
-                                          ( facade_element_area / buildings(nb)%area_facade )         !< [J/K] standard values according to table 12 section 12.3.1.2 (calculate over Eq. (66) according to section 12.3.1.2)
+                                            ( facade_element_area / buildings(nb)%area_facade )       !< [J/K] standard values
+                                                                                                      !< according to table 12 section 12.3.1.2 (calculate over Eq. (66) according to section 12.3.1.2)
 !
 !--          Calculation of heat transfer coefficient for transmission --> not time-dependent
              h_t_es   = window_area_per_facade * buildings(nb)%h_es                                   !< [W/K] only for windows
 
-             h_t_is  = buildings(nb)%area_facade  * h_is                                                             !< [W/K] with h_is = 3.45 W / (m2 K) between surface and air, Eq. (9)
-             h_t_ms  = a_m * h_ms                                                                     !< [W/K] with h_ms = 9.10 W / (m2 K) between component and surface, Eq. (64)
-             h_t_wall  = 1.0_wp / ( 1.0_wp / ( ( facade_element_area - window_area_per_facade )     & !< [W/K] 
+             h_t_is  = buildings(nb)%area_facade  * h_is                                              !< [W/K] with h_is = 3.45 W /
+                                                                                                      !< (m2 K) between surface and air, Eq. (9)
+             h_t_ms  = a_m * h_ms                                                                     !< [W/K] with h_ms = 9.10 W /
+                                                                                                      !< (m2 K) between component and surface, Eq. (64)
+             h_t_wall  = 1.0_wp / ( 1.0_wp / ( ( facade_element_area - window_area_per_facade )    &  !< [W/K]
                                     * buildings(nb)%lambda_layer3 / buildings(nb)%s_layer3 * 0.5_wp &
                                              ) + 1.0_wp / h_t_ms )                                    !< [W/K] opaque components
              h_t_wm  = 1.0_wp / ( 1.0_wp / h_t_wall - 1.0_wp / h_t_ms )                               !< [W/K] emmision Eq. (63), Section 12.2.2
 !
-!--          internal air loads dependent on the occupacy of the room
-!--          basical internal heat gains (qint_low) with additional internal heat gains by occupancy (qint_high) (0,5*phi_int)
-             phi_ia = 0.5_wp * ( ( buildings(nb)%qint_high * schedule_d + buildings(nb)%qint_low )  &
-                              * floor_area_per_facade )
+!--          Internal air loads dependent on the occupacy of the room.
+!--          Basical internal heat gains (qint_low) with additional internal heat gains by occupancy
+!--          (qint_high) (0,5*phi_int)
+             phi_ia = 0.5_wp * ( ( buildings(nb)%qint_high * schedule_d + buildings(nb)%qint_low ) &
+                             * floor_area_per_facade )
              q_int = phi_ia
 
 !
-!--          Airflow dependent on the occupacy of the room
-!--          basical airflow (air_change_low) with additional airflow gains by occupancy (air_change_high)
-             air_change = ( buildings(nb)%air_change_high * schedule_d + buildings(nb)%air_change_low )  
-!
-!--          Heat transfer of ventilation 
-!--          not less than 0.01 W/K to provide division by 0 in further calculations
-!--          with heat capacity of air 0.33 Wh/m2K
-             h_v   = MAX( 0.01_wp , ( air_change * indoor_volume_per_facade *                       &
-                                    0.33_wp * (1.0_wp - buildings(nb)%eta_ve ) ) )                    !< [W/K] from ISO 13789 Eq.(10)
-                                    
+!--          Airflow dependent on the occupacy of the room.
+!--          Basical airflow (air_change_low) with additional airflow gains by occupancy
+!--          (air_change_high)
+             air_change = ( buildings(nb)%air_change_high * schedule_d +                           &
+                          buildings(nb)%air_change_low )
+!
+!--          Heat transfer of ventilation.
+!--          Not less than 0.01 W/K to avoid division by 0 in further calculations with heat
+!--          capacity of air 0.33 Wh/m2K
+             h_v   = MAX( 0.01_wp , ( air_change * indoor_volume_per_facade *                      &
+                                    0.33_wp * (1.0_wp - buildings(nb)%eta_ve ) ) )                    !< [W/K] from ISO 13789
+                                                                                                      !< Eq.(10)
+
 !--          Heat transfer coefficient auxiliary variables
              h_t_1 = 1.0_wp / ( ( 1.0_wp / h_v )   + ( 1.0_wp / h_t_is ) )                            !< [W/K] Eq. (C.6)
@@ -1486,47 +1506,52 @@
 !--          Quantities needed for im_calc_temperatures
              i = surf_usm_v(l)%i(m)
-             j = surf_usm_v(l)%j(m)   
+             j = surf_usm_v(l)%j(m)
              k = surf_usm_v(l)%k(m)
              near_facade_temperature = surf_usm_v(l)%pt_10cm(m)
-             indoor_wall_window_temperature =                                                       &
-                  surf_usm_v(l)%frac(m,ind_veg_wall) * t_wall_v(l)%t(nzt_wall,m)                    &
-                + surf_usm_v(l)%frac(m,ind_wat_win)  * t_window_v(l)%t(nzt_wall,m)
-!
-!--          Solar thermal gains. If net_sw_in larger than sun-protection 
-!--          threshold parameter (params_solar_protection), sun protection will 
+             indoor_wall_window_temperature =                                                      &
+                                    surf_usm_v(l)%frac(m,ind_veg_wall) * t_wall_v(l)%t(nzt_wall,m) &
+                                  + surf_usm_v(l)%frac(m,ind_wat_win)  * t_window_v(l)%t(nzt_wall,m)
+!
+!--          Solar thermal gains. If net_sw_in larger than sun-protection
+!--          threshold parameter (params_solar_protection), sun protection will
 !--          be activated
-             IF ( net_sw_in <= params_solar_protection )  THEN 
+             IF ( net_sw_in <= params_solar_protection )  THEN
                 solar_protection_off = 1
-                solar_protection_on  = 0 
-             ELSE 
+                solar_protection_on  = 0
+             ELSE
                 solar_protection_off = 0
-                solar_protection_on  = 1 
+                solar_protection_on  = 1
              ENDIF
 !
-!--          Calculation of total heat gains from net_sw_in through windows [W] in respect on automatic sun protection
+!--          Calculation of total heat gains from net_sw_in through windows [W] in respect on
+!--          automatic sun protection.
 !--          DIN 4108 - 2 chap.8
-             phi_sol = (   window_area_per_facade * net_sw_in * solar_protection_off                             &
-                         + window_area_per_facade * net_sw_in * buildings(nb)%f_c_win * solar_protection_on )    &
+             phi_sol = (   window_area_per_facade * net_sw_in * solar_protection_off               &
+                         + window_area_per_facade * net_sw_in * buildings(nb)%f_c_win *            &
+                           solar_protection_on )                                                   &
                        * buildings(nb)%g_value_win * ( 1.0_wp - params_f_f ) * params_f_w
              q_sol = phi_sol
 !
-!--          Calculation of the mass specific thermal load for internal and external heatsources
+!--          Calculation of the mass specific thermal load for internal and external heatsources.
              phi_m   = (a_m / total_area) * ( phi_ia + phi_sol )          !< [W] Eq. (C.2) with phi_ia=0,5*phi_int
              q_c_m = phi_m
 !
-!--          Calculation mass specific thermal load implied non thermal mass 
-             phi_st  =   ( 1.0_wp - ( a_m / total_area ) - ( h_t_es / ( 9.1_wp * total_area ) ) )                &
-                       * ( phi_ia + phi_sol )                                                                       !< [W] Eq. (C.3) with phi_ia=0,5*phi_int
-             q_c_st = phi_st 
-!
-!--          Calculations for deriving indoor temperature and heat flux into the wall
-!--          Step 1: Indoor temperature without heating and cooling
+!--          Calculation mass specific thermal load implied non thermal mass.
+             phi_st  =   ( 1.0_wp - ( a_m / total_area ) - ( h_t_es / ( 9.1_wp * total_area ) ) )  &
+                       * ( phi_ia + phi_sol )                                                       !< [W] Eq. (C.3) with
+                                                                                                    !< phi_ia=0,5*phi_int
+             q_c_st = phi_st
+!
+!--          Calculations for deriving indoor temperature and heat flux into the wall.
+!--          Step 1: indoor temperature without heating and cooling.
 !--          section C.4.1 Picture C.2 zone 3)
              phi_hc_nd = 0.0_wp
-             CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
+             CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature,                  &
                                          near_facade_temperature, phi_hc_nd )
 !
-!--          If air temperature between border temperatures of heating and cooling, assign output variable, then ready  
-             IF ( buildings(nb)%theta_int_h_set <= theta_air  .AND.  theta_air <= buildings(nb)%theta_int_c_set )  THEN
+!--          If air temperature between border temperatures of heating and cooling, assign output
+!--          variable, then ready.
+             IF ( buildings(nb)%theta_int_h_set <= theta_air  .AND.                                &
+                  theta_air <= buildings(nb)%theta_int_c_set )  THEN
                 phi_hc_nd_ac = 0.0_wp
                 phi_hc_nd    = phi_hc_nd_ac
@@ -1543,6 +1568,6 @@
                 IF ( theta_air_0 > buildings(nb)%theta_int_c_set )  THEN
                    theta_air_set = buildings(nb)%theta_int_c_set
-                ELSE 
-                   theta_air_set = buildings(nb)%theta_int_h_set 
+                ELSE
+                   theta_air_set = buildings(nb)%theta_int_h_set
                 ENDIF
 
@@ -1550,36 +1575,38 @@
                 phi_hc_nd_10 = 10.0_wp * floor_area_per_facade
                 phi_hc_nd    = phi_hc_nd_10
-       
-                CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
-                                            near_facade_temperature, phi_hc_nd )
+
+                CALL  im_calc_temperatures ( i, j, k, indoor_wall_window_temperature,              &
+                                             near_facade_temperature, phi_hc_nd )
 
                 theta_air_10 = theta_air !< Note the temperature with 10 W/m2 of heating
 
-                phi_hc_nd_un = phi_hc_nd_10 * ( theta_air_set - theta_air_0 )  &
+                phi_hc_nd_un = phi_hc_nd_10 * ( theta_air_set - theta_air_0 )                      &
                                             / ( theta_air_10  - theta_air_0 )            !< Eq. (C.13)
 !
-!--             Step 3: With temperature ratio to determine the heating or cooling capacity    
-!--             If necessary, limit the power to maximum power
+!--             Step 3: with temperature ratio to determine the heating or cooling capacity
+!--             If necessary, limit the power to maximum power.
 !--             section C.4.1 Picture C.2 zone 2) and 4)
                 buildings(nb)%phi_c_max = buildings(nb)%q_c_max * floor_area_per_facade
                 buildings(nb)%phi_h_max = buildings(nb)%q_h_max * floor_area_per_facade
-                IF ( buildings(nb)%phi_c_max < phi_hc_nd_un  .AND.  phi_hc_nd_un < buildings(nb)%phi_h_max )  THEN
+                IF ( buildings(nb)%phi_c_max < phi_hc_nd_un  .AND.                                 &
+                     phi_hc_nd_un < buildings(nb)%phi_h_max )  THEN
                    phi_hc_nd_ac = phi_hc_nd_un
                    phi_hc_nd = phi_hc_nd_un
                 ELSE
 !
-!--             Step 4: Inner temperature with maximum heating (phi_hc_nd_un positive) or cooling (phi_hc_nd_un negative)
+!--             Step 4: inner temperature with maximum heating (phi_hc_nd_un positive) or cooling
+!--                     (phi_hc_nd_un negative)
 !--             section C.4.1 Picture C.2 zone 1) and 5)
                    IF ( phi_hc_nd_un > 0.0_wp )  THEN
                       phi_hc_nd_ac = buildings(nb)%phi_h_max                                         !< Limit heating
-                   ELSE 
+                   ELSE
                       phi_hc_nd_ac = buildings(nb)%phi_c_max                                         !< Limit cooling
                    ENDIF
                 ENDIF
-                phi_hc_nd = phi_hc_nd_ac  
+                phi_hc_nd = phi_hc_nd_ac
 !
 !--             Calculate the temperature with phi_hc_nd_ac (new)
-                CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
-                                            near_facade_temperature, phi_hc_nd )
+                CALL  im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
+                                             near_facade_temperature, phi_hc_nd )
                 theta_air_ac = theta_air
              ENDIF
@@ -1587,17 +1614,16 @@
 !--          Update theta_m_t_prev
              theta_m_t_prev = theta_m_t
-             
+
              q_vent = h_v * ( theta_air - near_facade_temperature )
 !
-!--          Calculate the operating temperature with weighted mean of temperature of air and mean
-!--          Will be used for thermal comfort calculations 
+!--          Calculate the operating temperature with weighted mean of temperature of air and mean.
+!--          Will be used for thermal comfort calculations.
              theta_op     = 0.3_wp * theta_air_ac + 0.7_wp * theta_s
 !              surf_usm_v(l)%t_indoor(m) = theta_op                  !< not integrated yet
 !
-!--          Heat flux into the wall. Value needed in urban_surface_mod to 
+!--          Heat flux into the wall. Value needed in urban_surface_mod to
 !--          calculate heat transfer through wall layers towards the facade
-             q_wall_win = h_t_ms * ( theta_s - theta_m )                       &
-                                    / (   facade_element_area                  &
-                                        - window_area_per_facade )
+             q_wall_win = h_t_ms * ( theta_s - theta_m )                                           &
+                                    / ( facade_element_area - window_area_per_facade )
              q_trans = q_wall_win * facade_element_area
 !
@@ -1606,23 +1632,22 @@
              surf_usm_v(l)%iwghf_eb_window(m) = q_wall_win
 !
-!--          Sum up operational indoor temperature per kk-level. Further below,
-!--          this temperature is reduced by MPI to one temperature per kk-level
-!--          and building (processor overlapping)
+!--          Sum up operational indoor temperature per kk-level. Further below, this temperature is
+!--          reduced by MPI to one temperature per kk-level and building (processor overlapping).
              buildings(nb)%t_in_l(kk) = buildings(nb)%t_in_l(kk) + theta_op
 !
-!--          Calculation of waste heat
-!--          Anthropogenic heat output
-             IF ( phi_hc_nd_ac > 0.0_wp )  THEN 
+!--          Calculation of waste heat.
+!--          Anthropogenic heat output.
+             IF ( phi_hc_nd_ac > 0.0_wp )  THEN
                 heating_on = 1
                 cooling_on = 0
-             ELSE 
+             ELSE
                 heating_on = 0
                 cooling_on = -1
              ENDIF
 
-             q_waste_heat = ( phi_hc_nd * (                                    &
-                    buildings(nb)%params_waste_heat_h * heating_on +           &
-                    buildings(nb)%params_waste_heat_c * cooling_on )           &
-                            ) / facade_element_area !< [W/m2] , observe the directional convention in PALM!
+             q_waste_heat = ( phi_hc_nd * ( buildings(nb)%params_waste_heat_h * heating_on +       &
+                                            buildings(nb)%params_waste_heat_c * cooling_on )       &
+                                                    ) / facade_element_area  !< [W/m2] , observe the directional convention in
+                                                                             !< PALM!
              surf_usm_v(l)%waste_heat(m) = q_waste_heat
           ENDDO !< Vertical surfaces loop
@@ -1631,10 +1656,10 @@
 
 !
-!-- Determine the mean building temperature. 
+!-- Determine the mean building temperature.
     DO  nb = 1, num_build
 !
-!--    Allocate dummy array used for summing-up facade elements. 
-!--    Please note, dummy arguments are necessary as building-date type
-!--    arrays are not necessarily allocated on all PEs.
+!--    Allocate dummy array used for summing-up facade elements.
+!--    Please note, dummy arguments are necessary as building-date type arrays are not necessarily
+!--    allocated on all PEs.
        ALLOCATE( t_in_l_send(buildings(nb)%kb_min:buildings(nb)%kb_max) )
        ALLOCATE( t_in_recv(buildings(nb)%kb_min:buildings(nb)%kb_max) )
@@ -1647,47 +1672,42 @@
 
 
-#if defined( __parallel ) 
-       CALL MPI_ALLREDUCE( t_in_l_send,                                        &
-                           t_in_recv,                                          &
-                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,    &
-                           MPI_REAL,                                           &
-                           MPI_SUM,                                            &
-                           comm2d,                                             &
+#if defined( __parallel )
+       CALL MPI_ALLREDUCE( t_in_l_send,                                                            &
+                           t_in_recv,                                                              &
+                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,                        &
+                           MPI_REAL,                                                               &
+                           MPI_SUM,                                                                &
+                           comm2d,                                                                 &
                            ierr )
 
-       IF ( ALLOCATED( buildings(nb)%t_in ) )                                  &
-           buildings(nb)%t_in = t_in_recv
+       IF ( ALLOCATED( buildings(nb)%t_in ) )  buildings(nb)%t_in = t_in_recv
 #else
-       IF ( ALLOCATED( buildings(nb)%t_in ) )                                  &
-          buildings(nb)%t_in = buildings(nb)%t_in_l
+       IF ( ALLOCATED( buildings(nb)%t_in ) )  buildings(nb)%t_in = buildings(nb)%t_in_l
 #endif
 
        IF ( ALLOCATED( buildings(nb)%t_in ) )  THEN
 !
-!--       Average indoor temperature. Note, in case a building is completely
-!--       surrounded by higher buildings, it may have no facade elements
-!--       at some height levels, which will lead to a divide by zero.
+!--       Average indoor temperature. Note, in case a building is completely surrounded by higher
+!--       buildings, it may have no facade elements at some height levels, which will lead to a
+!--       division by zero.
           DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
-             IF ( buildings(nb)%num_facade_h(k) +                              &
-                  buildings(nb)%num_facade_v(k) > 0 )  THEN
-                buildings(nb)%t_in(k) = buildings(nb)%t_in(k) /                &
-                               REAL( buildings(nb)%num_facade_h(k) +           &
-                                     buildings(nb)%num_facade_v(k), KIND = wp )
+             IF ( buildings(nb)%num_facade_h(k) + buildings(nb)%num_facade_v(k) > 0 )  THEN
+                buildings(nb)%t_in(k) = buildings(nb)%t_in(k) /                                    &
+                                        REAL( buildings(nb)%num_facade_h(k) +                      &
+                                              buildings(nb)%num_facade_v(k), KIND = wp )
              ENDIF
           ENDDO
 !
-!--       If indoor temperature is not defined because of missing facade 
-!--       elements, the values from the above-lying level will be taken.
-!--       At least at the top of the buildings facades are defined, so that
-!--       at least there an indoor temperature is defined. This information
-!--       will propagate downwards the building.
+!--       If indoor temperature is not defined because of missing facade elements, the values from
+!--       the above-lying level will be taken.
+!--       At least at the top of the buildings facades are defined, so that at least there an indoor
+!--       temperature is defined. This information will propagate downwards the building.
           DO  k = buildings(nb)%kb_max-1, buildings(nb)%kb_min, -1
-             IF ( buildings(nb)%num_facade_h(k) +                              &
-                  buildings(nb)%num_facade_v(k) <= 0 )  THEN
+             IF ( buildings(nb)%num_facade_h(k) + buildings(nb)%num_facade_v(k) <= 0 )  THEN
                 buildings(nb)%t_in(k) = buildings(nb)%t_in(k+1)
              ENDIF
           ENDDO
        ENDIF
-       
+
 
 !
@@ -1697,78 +1717,80 @@
 
     ENDDO
-    
+
  END SUBROUTINE im_main_heatcool
 
-!-----------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 !-------------
 !> Check data output for plant canopy model
-!-----------------------------------------------------------------------------! 
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE im_check_data_output( var, unit )
 
     CHARACTER (LEN=*) ::  unit   !<
     CHARACTER (LEN=*) ::  var    !<
-        
+
     SELECT CASE ( TRIM( var ) )
-    
-    
+
+
         CASE ( 'im_hf_roof')
            unit = 'W m-2'
-        
+
         CASE ( 'im_hf_wall_win' )
            unit = 'W m-2'
-           
+
         CASE ( 'im_hf_wall_win_waste' )
            unit = 'W m-2'
-           
+
         CASE ( 'im_hf_roof_waste' )
            unit = 'W m-2'
-        
+
         CASE ( 'im_t_indoor_mean' )
            unit = 'K'
-           
+
         CASE ( 'im_t_indoor_roof' )
            unit = 'K'
-           
+
         CASE ( 'im_t_indoor_wall_win' )
            unit = 'K'
-        
+
         CASE DEFAULT
            unit = 'illegal'
-           
+
     END SELECT
-    
+
  END SUBROUTINE
 
 
-!-----------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 !-------------
 !> Check parameters routine for plant canopy model
-!-----------------------------------------------------------------------------! 
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE im_check_parameters
 
 !   USE control_parameters,
 !       ONLY: message_string
-   
+
  END SUBROUTINE im_check_parameters
 
-!-----------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 !-------------
 !> Subroutine defining appropriate grid for netcdf variables.
 !> It is called from subroutine netcdf.
-!-----------------------------------------------------------------------------! 
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE im_define_netcdf_grid( var, found, grid_x, grid_y, grid_z )
 
-   
-   CHARACTER (LEN=*), INTENT(IN)  ::  var
-   LOGICAL, INTENT(OUT)           ::  found
-   CHARACTER (LEN=*), INTENT(OUT) ::  grid_x
-   CHARACTER (LEN=*), INTENT(OUT) ::  grid_y
-   CHARACTER (LEN=*), INTENT(OUT) ::  grid_z
-   
-   found   = .TRUE.
-   
+    CHARACTER (LEN=*), INTENT(OUT) ::  grid_x
+    CHARACTER (LEN=*), INTENT(OUT) ::  grid_y
+    CHARACTER (LEN=*), INTENT(OUT) ::  grid_z
+    CHARACTER (LEN=*), INTENT(IN)  ::  var
+
+    LOGICAL, INTENT(OUT)           ::  found
+
+
+    found   = .TRUE.
 !
 !-- Check for the grid
@@ -1790,5 +1812,5 @@
           grid_y = 'y'
           grid_z = 'zw'
-          
+
        CASE DEFAULT
           found  = .FALSE.
@@ -1797,14 +1819,14 @@
           grid_z = 'none'
     END SELECT
-    
+
  END SUBROUTINE im_define_netcdf_grid
 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Subroutine defining 3D output variables
-!------------------------------------------------------------------------------!
- SUBROUTINE im_data_output_3d( av, variable, found, local_pf, fill_value,      &
-                               nzb_do, nzt_do )
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE im_data_output_3d( av, variable, found, local_pf, fill_value, nzb_do, nzt_do )
 
     USE indices
@@ -1812,30 +1834,30 @@
     USE kinds
 
-    CHARACTER (LEN=*) ::  variable !< 
-
-    INTEGER(iwp) ::  av    !< 
-    INTEGER(iwp) ::  i     !< 
-    INTEGER(iwp) ::  j     !< 
-    INTEGER(iwp) ::  k     !< 
+    CHARACTER (LEN=*) ::  variable !<
+
+    INTEGER(iwp) ::  av    !<
+    INTEGER(iwp) ::  i     !<
+    INTEGER(iwp) ::  j     !<
+    INTEGER(iwp) ::  k     !<
     INTEGER(iwp) ::  l     !<
-    INTEGER(iwp) ::  m     !< 
-    INTEGER(iwp) ::  nb    !< index of the building in the building data structure 
+    INTEGER(iwp) ::  m     !<
+    INTEGER(iwp) ::  nb    !< index of the building in the building data structure
     INTEGER(iwp) ::  nzb_do !< lower limit of the data output (usually 0)
     INTEGER(iwp) ::  nzt_do !< vertical upper limit of the data output (usually nz_do3d)
-    
-    LOGICAL      ::  found !< 
+
+    LOGICAL      ::  found !<
 
     REAL(wp), INTENT(IN) ::  fill_value !< value for the _FillValue attribute
 
-    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !< 
-    
+    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !<
+
     local_pf = fill_value
-    
+
     found = .TRUE.
-    
+
     SELECT CASE ( TRIM( variable ) )
 !
-!--     Output of indoor temperature. All grid points within the building are
-!--     filled with values, while atmospheric grid points are set to _FillValues.
+!--     Output of indoor temperature. All grid points within the building are filled with values,
+!--     while atmospheric grid points are set to _FillValues.
         CASE ( 'im_t_indoor_mean' )
            IF ( av == 0 ) THEN
@@ -1844,13 +1866,12 @@
                     IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
 !
-!--                    Determine index of the building within the building data structure. 
-                       nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ),   &
-                                    DIM = 1 )
+!--                    Determine index of the building within the building data structure.
+                       nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM=1 )
                        IF ( buildings(nb)%on_pe )  THEN
 !
-!--                       Write mean building temperature onto output array. Please note,
-!--                       in contrast to many other loops in the output, the vertical 
-!--                       bounds are determined by the lowest and hightest vertical index
-!--                       occupied by the building. 
+!--                       Write mean building temperature onto output array. Please note, in
+!--                       contrast to many other loops in the output, the vertical bounds are
+!--                       determined by the lowest and hightest vertical index occupied by the
+!--                       building.
                           DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
                              local_pf(i,j,k) = buildings(nb)%t_in(k)
@@ -1860,8 +1881,8 @@
                  ENDDO
               ENDDO
-           ENDIF  
+           ENDIF
 
         CASE ( 'im_hf_roof' )
-           IF ( av == 0 ) THEN
+           IF ( av == 0 )  THEN
               DO  m = 1, surf_usm_h%ns
                  i = surf_usm_h%i(m) !+ surf_usm_h%ioff
@@ -1870,9 +1891,9 @@
                  local_pf(i,j,k) = surf_usm_h%iwghf_eb(m)
               ENDDO
-           ENDIF 
+           ENDIF
 
         CASE ( 'im_hf_roof_waste' )
-           IF ( av == 0 ) THEN
-              DO m = 1, surf_usm_h%ns 
+           IF ( av == 0 )  THEN
+              DO m = 1, surf_usm_h%ns
                  i = surf_usm_h%i(m) !+ surf_usm_h%ioff
                  j = surf_usm_h%j(m) !+ surf_usm_h%joff
@@ -1883,5 +1904,5 @@
 
        CASE ( 'im_hf_wall_win' )
-           IF ( av == 0 ) THEN
+           IF ( av == 0 )  THEN
               DO l = 0, 3
                  DO m = 1, surf_usm_v(l)%ns
@@ -1895,11 +1916,11 @@
 
         CASE ( 'im_hf_wall_win_waste' )
-           IF ( av == 0 ) THEN
+           IF ( av == 0 )  THEN
               DO l = 0, 3
-                 DO m = 1, surf_usm_v(l)%ns 
+                 DO m = 1, surf_usm_v(l)%ns
                     i = surf_usm_v(l)%i(m) !+ surf_usm_v(l)%ioff
                     j = surf_usm_v(l)%j(m) !+ surf_usm_v(l)%joff
                     k = surf_usm_v(l)%k(m) !+ surf_usm_v(l)%koff
-                    local_pf(i,j,k) =  surf_usm_v(l)%waste_heat(m) 
+                    local_pf(i,j,k) =  surf_usm_v(l)%waste_heat(m)
                  ENDDO
               ENDDO
@@ -1910,5 +1931,5 @@
 
 !         CASE ( 'im_t_indoor_roof' )
-!            IF ( av == 0 ) THEN
+!            IF ( av == 0 )  THEN
 !               DO  m = 1, surf_usm_h%ns
 !                   i = surf_usm_h%i(m) !+ surf_usm_h%ioff
@@ -1918,7 +1939,7 @@
 !               ENDDO
 !            ENDIF
-! 
+!
 !         CASE ( 'im_t_indoor_wall_win' )
-!            IF ( av == 0 ) THEN           
+!            IF ( av == 0 )  THEN
 !               DO l = 0, 3
 !                  DO m = 1, surf_usm_v(l)%ns
@@ -1933,16 +1954,18 @@
         CASE DEFAULT
            found = .FALSE.
-           
-    END SELECT    
-
- END SUBROUTINE im_data_output_3d          
-!------------------------------------------------------------------------------!
+
+    END SELECT
+
+ END SUBROUTINE im_data_output_3d
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Parin for &indoor_parameters for indoor model
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE im_parin
-    
-    USE control_parameters,                                                    &
+
+    USE control_parameters,                                                                        &
         ONLY:  indoor_model
 
@@ -1951,4 +1974,5 @@
 
     NAMELIST /indoor_parameters/  initial_indoor_temperature
+
 
 !
@@ -1956,5 +1980,5 @@
     REWIND ( 11 )
     line = ' '
-    DO   WHILE ( INDEX( line, '&indoor_parameters' ) == 0 )
+    DO  WHILE ( INDEX( line, '&indoor_parameters' ) == 0 )
        READ ( 11, '(A)', END=10 )  line
     ENDDO
@@ -1980,5 +2004,5 @@
 
  10 CONTINUE
-    
+
  END SUBROUTINE im_parin
 
Index: palm/trunk/SOURCE/inflow_turbulence.f90
===================================================================
--- palm/trunk/SOURCE/inflow_turbulence.f90	(revision 4645)
+++ palm/trunk/SOURCE/inflow_turbulence.f90	(revision 4646)
@@ -1,47 +1,49 @@
 !> @file inflow_turbulence.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4429 2020-02-27 15:24:30Z raasch
 ! bugfix: cpp-directives added for serial mode
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! use y_shift instead of old parameter recycling_yshift
-! 
+!
 ! 4297 2019-11-21 10:37:50Z oliver.maas
-! changed recycling_yshift so that the y-shift can be a multiple of PE
-! instead of y-shift of a half domain width
-! 
+! changed recycling_yshift so that the y-shift can be a multiple of PE instead of y-shift of a half
+! domain width
+!
 ! 4183 2019-08-23 07:33:16Z oliver.maas
-! simplified steering of recycling of absolute values by initialization 
-! parameter recycling_method_for_thermodynamic_quantities
-! 
+! simplified steering of recycling of absolute values by initialization parameter
+! recycling_method_for_thermodynamic_quantities
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 4172 2019-08-20 11:55:33Z oliver.maas
 ! added optional recycling of absolute values for pt and q
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! Corrected "Former revisions" section
@@ -51,36 +53,38 @@
 ! Description:
 ! ------------
-!> Imposing turbulence at the respective inflow using the turbulence
-!> recycling method of Kataoka and Mizuno (2002).
-!------------------------------------------------------------------------------!
+!> Imposing turbulence at the respective inflow using the turbulence recycling method of
+!> Kataoka and Mizuno (2002).
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE inflow_turbulence
- 
-
-    USE arrays_3d,                                                             &
+
+
+    USE arrays_3d,                                                                                 &
         ONLY:  e, inflow_damping_factor, mean_inflow_profiles, pt, q, s, u, v, w
-        
-#if defined( __parallel )
-    USE control_parameters,                                                    &
-        ONLY:  humidity, passive_scalar, recycling_plane, y_shift,             &
-               recycling_method_for_thermodynamic_quantities
+
+#if defined( __parallel )
+    USE control_parameters,                                                                        &
+        ONLY:  humidity, passive_scalar, recycling_method_for_thermodynamic_quantities,            &
+               recycling_plane, y_shift
+
 #else
-    USE control_parameters,                                                    &
-        ONLY:  humidity, passive_scalar, recycling_plane,                      &
-               recycling_method_for_thermodynamic_quantities
-#endif
-        
-    USE cpulog,                                                                &
+    USE control_parameters,                                                                        &
+        ONLY:  humidity, passive_scalar, recycling_method_for_thermodynamic_quantities,            &
+               recycling_plane
+
+#endif
+
+    USE cpulog,                                                                                    &
         ONLY:  cpu_log, log_point
-        
-    USE indices,                                                               &
+
+    USE indices,                                                                                   &
         ONLY:  nbgp, nxl, ny, nyn, nys, nyng, nysg, nzb, nzt
-        
+
     USE kinds
-    
+
     USE pegrid
 
 
     IMPLICIT NONE
-    
+
     INTEGER(iwp) ::  i        !< loop index
     INTEGER(iwp) ::  j        !< loop index
@@ -94,17 +98,14 @@
 #endif
 
-    REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp)           ::                         &
-       avpr               !< stores averaged profiles at recycling plane
-    REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp)           ::                         &
-       avpr_l             !< auxiliary variable to calculate avpr
-    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) ::                         &
-       inflow_dist        !< turbulence signal of vars, added at inflow boundary
-#if defined( __parallel )
-    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) ::                         &
-       local_inflow_dist  !< auxiliary variable for inflow_dist, used for y-shift
-#endif
-    
+    REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp) ::  avpr               !< stores averaged profiles at recycling plane
+    REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp) ::  avpr_l             !< auxiliary variable to calculate avpr
+
+    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) ::  inflow_dist        !< turbulence signal of vars, added at inflow boundary
+#if defined( __parallel )
+    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) ::  local_inflow_dist  !< auxiliary variable for inflow_dist, used for y-shift
+#endif
+
     CALL cpu_log( log_point(40), 'inflow_turbulence', 'start' )
-    
+
 !
 !-- Carry out spanwise averaging in the recycling plane
@@ -119,5 +120,5 @@
 #if defined( __parallel )
     IF ( myidx == id_recycling )  THEN
-       
+
        DO  l = 1, nbgp
           DO  j = nys, nyn
@@ -129,8 +130,6 @@
                 avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i)
                 avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i)
-                IF ( humidity )                                                &
-                   avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
-                IF ( passive_scalar )                                          &
-                   avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i)
+                IF ( humidity )  avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
+                IF ( passive_scalar )  avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i)
 
              ENDDO
@@ -143,6 +142,5 @@
 !-- Now, averaging over all PEs
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( avpr_l(nzb,1,1), avpr(nzb,1,1), ngp_pr, MPI_REAL,      &
-                        MPI_SUM, comm2d, ierr )
+    CALL MPI_ALLREDUCE( avpr_l(nzb,1,1), avpr(nzb,1,1), ngp_pr, MPI_REAL, MPI_SUM, comm2d, ierr )
 
 #else
@@ -156,14 +154,12 @@
              avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i)
              avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i)
-             IF ( humidity )                                                   &
-                avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
-             IF ( passive_scalar )                                             &
-                avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i)
-
-          ENDDO
-       ENDDO
-       i = i + 1 
+             IF ( humidity )  avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
+             IF ( passive_scalar )  avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i)
+
+          ENDDO
+       ENDDO
+       i = i + 1
     ENDDO
-    
+
     avpr = avpr_l
 #endif
@@ -171,7 +167,6 @@
     avpr = avpr / ( ny + 1 )
 !
-!-- Calculate the disturbances at the recycling plane
-!-- for recycling of absolute quantities, the disturbance is defined as the absolute value
-!-- (and not as the deviation from the mean profile)
+!-- Calculate the disturbances at the recycling plane for recycling of absolute quantities, the
+!-- disturbance is defined as the absolute value (and not as the deviation from the mean profile).
     i = recycling_plane
 
@@ -184,22 +179,22 @@
                 inflow_dist(k,j,2,l) = v(k,j,i)   - avpr(k,2,l)
                 inflow_dist(k,j,3,l) = w(k,j,i)   - avpr(k,3,l)
-                IF ( TRIM( recycling_method_for_thermodynamic_quantities )     &
-                   == 'turbulent_fluctuation' )  THEN
+                IF ( TRIM( recycling_method_for_thermodynamic_quantities )                         &
+                     == 'turbulent_fluctuation' )  THEN
                    inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l)
-                ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) &
-                   == 'absolute_value' )  THEN
+                ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )                     &
+                         == 'absolute_value' )  THEN
                    inflow_dist(k,j,4,l) = pt(k,j,i)
                 ENDIF
                 inflow_dist(k,j,5,l) = e(k,j,i)   - avpr(k,5,l)
                 IF ( humidity ) THEN
-                   IF ( TRIM( recycling_method_for_thermodynamic_quantities )  &
-                      == 'turbulent_fluctuation' )  THEN
+                   IF ( TRIM( recycling_method_for_thermodynamic_quantities )                      &
+                        == 'turbulent_fluctuation' )  THEN
                       inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l)
-                   ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )  &
-                      == 'absolute_value' )  THEN
+                   ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )                  &
+                            == 'absolute_value' )  THEN
                       inflow_dist(k,j,6,l) = q(k,j,i)
                    ENDIF
                 ENDIF
-                IF ( passive_scalar )                                          &
+                IF ( passive_scalar )                                                              &
                    inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l)
             ENDDO
@@ -216,24 +211,24 @@
              inflow_dist(k,j,2,l) = v(k,j,i)   - avpr(k,2,l)
              inflow_dist(k,j,3,l) = w(k,j,i)   - avpr(k,3,l)
-             IF ( TRIM( recycling_method_for_thermodynamic_quantities )        &
+             IF ( TRIM( recycling_method_for_thermodynamic_quantities )                            &
                    == 'turbulent_fluctuation' )  THEN
                 inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l)
-             ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )    &
-                   == 'absolute_value' )  THEN
+             ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )                        &
+                      == 'absolute_value' )  THEN
                 inflow_dist(k,j,4,l) = pt(k,j,i)
              ENDIF
              inflow_dist(k,j,5,l) = e(k,j,i)   - avpr(k,5,l)
              IF ( humidity )  THEN
-                IF ( TRIM( recycling_method_for_thermodynamic_quantities )     &
-                      == 'turbulent_fluctuation' )  THEN
+                IF ( TRIM( recycling_method_for_thermodynamic_quantities )                         &
+                     == 'turbulent_fluctuation' )  THEN
                    inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l)
-                ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) &
-                      == 'absolute_value' )  THEN
+                ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )                     &
+                         == 'absolute_value' )  THEN
                    inflow_dist(k,j,6,l) = q(k,j,i)
                 ENDIF
              ENDIF
-             IF ( passive_scalar )                                             &
+             IF ( passive_scalar )                                                                 &
                 inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l)
-              
+
           ENDDO
        ENDDO
@@ -247,12 +242,11 @@
     IF ( myidx == id_recycling  .AND.  myidx /= id_inflow )  THEN
 
-       CALL MPI_SEND( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL,            &
-                      id_inflow, 1, comm1dx, ierr )
+       CALL MPI_SEND( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, id_inflow, 1, comm1dx, ierr )
 
     ELSEIF ( myidx /= id_recycling  .AND.  myidx == id_inflow )  THEN
 
        inflow_dist = 0.0_wp
-       CALL MPI_RECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL,            &
-                      id_recycling, 1, comm1dx, status, ierr )
+       CALL MPI_RECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, id_recycling, 1, comm1dx,      &
+                      status, ierr )
 
     ENDIF
@@ -262,17 +256,17 @@
 !-- Shift inflow_dist in positive y direction by a number of
 !-- PEs equal to y_shift
-    IF ( ( y_shift /= 0 ) .AND. myidx == id_inflow ) THEN
-
-!
-!--    Calculate the ID of the PE which sends data to this PE (prev) and of the
-!--    PE which receives data from this PE (next).
+    IF ( ( y_shift /= 0 )  .AND.  myidx == id_inflow )  THEN
+
+!
+!--    Calculate the ID of the PE which sends data to this PE (prev) and of the PE which receives
+!--    data from this PE (next).
        prev = MODULO(myidy - y_shift , pdims(2))
        next = MODULO(myidy + y_shift , pdims(2))
-       
+
        local_inflow_dist = 0.0_wp
 
-       CALL MPI_SENDRECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL,        &
-                          next, 1, local_inflow_dist(nzb,nysg,1,1), ngp_ifd,   &
-                          MPI_REAL, prev, 1, comm1dy, status, ierr )
+       CALL MPI_SENDRECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, next, 1,                   &
+                          local_inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, prev, 1, comm1dy,    &
+                          status, ierr )
 
        inflow_dist = local_inflow_dist
@@ -289,42 +283,41 @@
           DO  k = nzb, nzt + 1
 
-             u(k,j,-nbgp+1:0) = mean_inflow_profiles(k,1) +                    &
-                        inflow_dist(k,j,1,1:nbgp) * inflow_damping_factor(k)
-             v(k,j,-nbgp:-1)  = mean_inflow_profiles(k,2) +                    &
-                        inflow_dist(k,j,2,1:nbgp) * inflow_damping_factor(k)
-             w(k,j,-nbgp:-1)  =                                                &
-                        inflow_dist(k,j,3,1:nbgp) * inflow_damping_factor(k)
-             IF ( TRIM( recycling_method_for_thermodynamic_quantities )        &
+             u(k,j,-nbgp+1:0) = mean_inflow_profiles(k,1) +                                        &
+                                inflow_dist(k,j,1,1:nbgp) * inflow_damping_factor(k)
+             v(k,j,-nbgp:-1)  = mean_inflow_profiles(k,2) +                                        &
+                                inflow_dist(k,j,2,1:nbgp) * inflow_damping_factor(k)
+             w(k,j,-nbgp:-1)  = inflow_dist(k,j,3,1:nbgp) * inflow_damping_factor(k)
+             IF ( TRIM( recycling_method_for_thermodynamic_quantities )                            &
                    == 'turbulent_fluctuation' )  THEN
-                pt(k,j,-nbgp:-1) = mean_inflow_profiles(k,4) +                 &
-                inflow_dist(k,j,4,1:nbgp) * inflow_damping_factor(k)
-             ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )    &
-                   == 'absolute_value' )  THEN
+                pt(k,j,-nbgp:-1) = mean_inflow_profiles(k,4) +                                     &
+                                   inflow_dist(k,j,4,1:nbgp) * inflow_damping_factor(k)
+             ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )                        &
+                      == 'absolute_value' )  THEN
                 pt(k,j,-nbgp:-1) = inflow_dist(k,j,4,1:nbgp)
              ENDIF
-             e(k,j,-nbgp:-1)  = mean_inflow_profiles(k,5) +                    &
-                        inflow_dist(k,j,5,1:nbgp) * inflow_damping_factor(k)
+             e(k,j,-nbgp:-1)  = mean_inflow_profiles(k,5) +                                        &
+                                inflow_dist(k,j,5,1:nbgp) * inflow_damping_factor(k)
              e(k,j,-nbgp:-1)  = MAX( e(k,j,-nbgp:-1), 0.0_wp )
              IF ( humidity )  THEN
-                IF ( TRIM( recycling_method_for_thermodynamic_quantities )     &
+                IF ( TRIM( recycling_method_for_thermodynamic_quantities )                         &
                       == 'turbulent_fluctuation' )  THEN
-                   q(k,j,-nbgp:-1)  = mean_inflow_profiles(k,6) +              & 
-                      inflow_dist(k,j,6,1:nbgp) * inflow_damping_factor(k)
-                ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) &
-                      == 'absolute_value' )  THEN
+                   q(k,j,-nbgp:-1)  = mean_inflow_profiles(k,6) +                                  &
+                                      inflow_dist(k,j,6,1:nbgp) * inflow_damping_factor(k)
+                ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )                     &
+                         == 'absolute_value' )  THEN
                    q(k,j,-nbgp:-1)  = inflow_dist(k,j,6,1:nbgp)
                 ENDIF
              ENDIF
-             IF ( passive_scalar )                                             &
-                s(k,j,-nbgp:-1)  = mean_inflow_profiles(k,7) +                 &
-                        inflow_dist(k,j,7,1:nbgp) * inflow_damping_factor(k)
-                        
-          ENDDO
-       ENDDO
-
-    ENDIF
-
-
-    CALL cpu_log( log_point(40), 'inflow_turbulence', 'stop' )
+             IF ( passive_scalar )                                                                 &
+                s(k,j,-nbgp:-1)  = mean_inflow_profiles(k,7) +                                     &
+                                   inflow_dist(k,j,7,1:nbgp) * inflow_damping_factor(k)
+
+          ENDDO
+       ENDDO
+
+    ENDIF
+
+
+    CALL  cpu_log( log_point(40), 'inflow_turbulence', 'stop' )
 
 
