Index: /palm/trunk/SOURCE/tridia_solver_mod.f90
===================================================================
--- /palm/trunk/SOURCE/tridia_solver_mod.f90	(revision 4509)
+++ /palm/trunk/SOURCE/tridia_solver_mod.f90	(revision 4510)
@@ -1,23 +1,23 @@
 !> @file tridia_solver_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:
-! ------------------
+! -----------------
 ! 
 ! 
@@ -25,12 +25,15 @@
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4360 2020-01-07 11:25:50Z suehring
 ! Added missing OpenMP directives
-! 
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 3761 2019-02-25 15:31:42Z raasch
 ! OpenACC modification to prevent compiler warning about unused variable
-! 
+!
 ! 3690 2019-01-22 22:56:42Z knoop
 ! OpenACC port for SPEC
@@ -38,39 +41,43 @@
 ! 1212 2013-08-15 08:46:27Z raasch
 ! Initial revision.
-! Routines have been moved to seperate module from former file poisfft to here.
-! The tridiagonal matrix coefficients of array tri are calculated only once at
-! the beginning, i.e. routine split is called within tridia_init.
-!
-!
-! Description:
-! ------------
-!> solves the linear system of equations:
+! Routines have been moved to seperate module from former file poisfft to here. The tridiagonal
+! matrix coefficients of array tri are calculated only once at the beginning, i.e. routine split is
+! called within tridia_init.
+!
+!
+! Description:
+! ------------
+!> Solves the linear system of equations:
 !>
-!> -(4 pi^2(i^2/(dx^2*nnx^2)+j^2/(dy^2*nny^2))+
-!>   1/(dzu(k)*dzw(k))+1/(dzu(k-1)*dzw(k)))*p(i,j,k)+
+!> -(4 pi^2(i^2/(dx^2*nnx^2)+j^2/(dy^2*nny^2))+ 1/(dzu(k)*dzw(k))+1/(dzu(k-1)*dzw(k)))*p(i,j,k)+
 !> 1/(dzu(k)*dzw(k))*p(i,j,k+1)+1/(dzu(k-1)*dzw(k))*p(i,j,k-1)=d(i,j,k)
 !>
 !> by using the Thomas algorithm
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 
 #define __acc_fft_device ( defined( _OPENACC ) && ( defined ( __cuda_fft ) ) )
 
  MODULE tridia_solver
- 
-
-    USE basic_constants_and_equations_mod,                                     &
+
+
+    USE basic_constants_and_equations_mod,                                                         &
         ONLY:  pi
 
-    USE indices,                                                               &
-        ONLY:  nx, ny, nz
+    USE indices,                                                                                   &
+        ONLY:  nx,                                                                                 &
+               ny,                                                                                 &
+               nz
 
     USE kinds
 
-    USE transpose_indices,                                                     &
-        ONLY:  nxl_z, nyn_z, nxr_z, nys_z
-
-    IMPLICIT NONE
-
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ddzuw !< 
+    USE transpose_indices,                                                                         &
+        ONLY:  nxl_z,                                                                              &
+               nyn_z,                                                                              &
+               nxr_z,                                                                              &
+               nys_z
+
+    IMPLICIT NONE
+
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ddzuw  !<
 
     PRIVATE
@@ -89,569 +96,567 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
-    SUBROUTINE tridia_init
-
-       USE arrays_3d,                                                          &
-           ONLY:  ddzu_pres, ddzw, rho_air_zw
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE tridia_init
+
+    USE arrays_3d,                                                                                 &
+        ONLY:  ddzu_pres,                                                                          &
+               ddzw,                                                                               &
+               rho_air_zw
 
 #if defined( _OPENACC )
-       USE arrays_3d,                                                          &
+       USE arrays_3d,                                                                              &
            ONLY:  tri
 #endif
 
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  k !< 
-
-       ALLOCATE( ddzuw(0:nz-1,3) )
-
-       DO  k = 0, nz-1
-          ddzuw(k,1) = ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k)
-          ddzuw(k,2) = ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1)
-          ddzuw(k,3) = -1.0_wp * &
-                       ( ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1) +        &
-                         ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k) )
-       ENDDO
-!
-!--    Calculate constant coefficients of the tridiagonal matrix
-       CALL maketri
-       CALL split
-
-#if __acc_fft_device
-       !$ACC ENTER DATA &
-       !$ACC COPYIN(ddzuw(0:nz-1,1:3)) &
-       !$ACC COPYIN(tri(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1,1:2))
-#endif
-
-    END SUBROUTINE tridia_init
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Computes the i- and j-dependent component of the matrix
-!> Provide the constant coefficients of the tridiagonal matrix for solution
-!> of the Poisson equation in Fourier space.
-!> The coefficients are computed following the method of
-!> Schmidt et al. (DFVLR-Mitteilung 84-15), which departs from Stephan
-!> Siano's original version by discretizing the Poisson equation,
-!> before it is Fourier-transformed.
-!------------------------------------------------------------------------------!
-    SUBROUTINE maketri
-
-
-          USE arrays_3d,                                                       &
-              ONLY:  tric, rho_air
-
-          USE control_parameters,                                              &
-              ONLY:  ibc_p_b, ibc_p_t
-
-          USE grid_variables,                                                  &
-              ONLY:  dx, dy
-
-
-          IMPLICIT NONE
-
-          INTEGER(iwp) ::  i    !< 
-          INTEGER(iwp) ::  j    !< 
-          INTEGER(iwp) ::  k    !< 
-          INTEGER(iwp) ::  nnxh !< 
-          INTEGER(iwp) ::  nnyh !< 
-
-          REAL(wp)    ::  ll(nxl_z:nxr_z,nys_z:nyn_z) !< 
-
-
-          nnxh = ( nx + 1 ) / 2
-          nnyh = ( ny + 1 ) / 2
-
-          DO  j = nys_z, nyn_z
-             DO  i = nxl_z, nxr_z
-                IF ( j >= 0  .AND.  j <= nnyh )  THEN
-                   IF ( i >= 0  .AND.  i <= nnxh )  THEN
-                      ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * i ) / &
-                                            REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) + &
-                                2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) / &
-                                            REAL( ny+1, KIND=wp ) ) ) / ( dy * dy )
-                   ELSE
-                      ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( nx+1-i ) ) / &
-                                            REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) + &
-                                2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) / &
-                                            REAL( ny+1, KIND=wp ) ) ) / ( dy * dy )
-                   ENDIF
-                ELSE
-                   IF ( i >= 0  .AND.  i <= nnxh )  THEN
-                      ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * i ) / &
-                                            REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) + &
-                                2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( ny+1-j ) ) / &
-                                            REAL( ny+1, KIND=wp ) ) ) / ( dy * dy )
-                   ELSE
-                      ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( nx+1-i ) ) / &
-                                            REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) + &
-                                2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( ny+1-j ) ) / &
-                                            REAL( ny+1, KIND=wp ) ) ) / ( dy * dy )
-                   ENDIF
-                ENDIF
-             ENDDO
-          ENDDO
-
-          DO  k = 0, nz-1
-             DO  j = nys_z, nyn_z
-                DO  i = nxl_z, nxr_z
-                   tric(i,j,k) = ddzuw(k,3) - ll(i,j) * rho_air(k+1)
-                ENDDO
-             ENDDO
-          ENDDO
-
-          IF ( ibc_p_b == 1 )  THEN
-             DO  j = nys_z, nyn_z
-                DO  i = nxl_z, nxr_z
-                   tric(i,j,0) = tric(i,j,0) + ddzuw(0,1)
-                ENDDO
-             ENDDO
-          ENDIF
-          IF ( ibc_p_t == 1 )  THEN
-             DO  j = nys_z, nyn_z
-                DO  i = nxl_z, nxr_z
-                   tric(i,j,nz-1) = tric(i,j,nz-1) + ddzuw(nz-1,2)
-                ENDDO
-             ENDDO
-          ENDIF
-
-    END SUBROUTINE maketri
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Substitution (Forward and Backward) (Thomas algorithm)
-!------------------------------------------------------------------------------!
-    SUBROUTINE tridia_substi( ar )
-
-
-          USE arrays_3d,                                                       & 
-              ONLY:  tri
-
-          USE control_parameters,                                              &
-              ONLY:  ibc_p_b, ibc_p_t
-
-          IMPLICIT NONE
-
-          INTEGER(iwp) ::  i !< 
-          INTEGER(iwp) ::  j !< 
-          INTEGER(iwp) ::  k !< 
-
-          REAL(wp)     ::  ar(nxl_z:nxr_z,nys_z:nyn_z,1:nz) !< 
-
-          REAL(wp), DIMENSION(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1)   ::  ar1 !< 
-#if __acc_fft_device
-          !$ACC DECLARE CREATE(ar1)
-#endif
-
-          !$OMP PARALLEL PRIVATE(i,j,k)
-
-!
-!--       Forward substitution
-#if __acc_fft_device
-          !$ACC PARALLEL PRESENT(ar, ar1, tri) PRIVATE(i,j,k)
-#endif
-          DO  k = 0, nz - 1
-#if __acc_fft_device
-             !$ACC LOOP COLLAPSE(2)
-#endif
-             !$OMP DO
-             DO  j = nys_z, nyn_z
-                DO  i = nxl_z, nxr_z
-
-                   IF ( k == 0 )  THEN
-                      ar1(i,j,k) = ar(i,j,k+1)
-                   ELSE
-                      ar1(i,j,k) = ar(i,j,k+1) - tri(i,j,k,2) * ar1(i,j,k-1)
-                   ENDIF
-
-                ENDDO
-             ENDDO
-          ENDDO
-#if __acc_fft_device
-          !$ACC END PARALLEL
-#endif
-
-!
-!--       Backward substitution
-!--       Note, the 1.0E-20 in the denominator is due to avoid divisions
-!--       by zero appearing if the pressure bc is set to neumann at the top of
-!--       the model domain.
-#if __acc_fft_device
-          !$ACC PARALLEL PRESENT(ar, ar1, ddzuw, tri) PRIVATE(i,j,k)
-#endif
-          DO  k = nz-1, 0, -1
-#if __acc_fft_device
-             !$ACC LOOP COLLAPSE(2)
-#endif
-             !$OMP DO
-             DO  j = nys_z, nyn_z
-                DO  i = nxl_z, nxr_z
-
-                   IF ( k == nz-1 )  THEN
-                      ar(i,j,k+1) = ar1(i,j,k) / ( tri(i,j,k,1) + 1.0E-20_wp )
-                   ELSE
-                      ar(i,j,k+1) = ( ar1(i,j,k) - ddzuw(k,2) * ar(i,j,k+2) ) &
-                              / tri(i,j,k,1)
-                   ENDIF
-                ENDDO
-             ENDDO
-          ENDDO
-#if __acc_fft_device
-          !$ACC END PARALLEL
-#endif
-
-          !$OMP END PARALLEL
-
-!
-!--       Indices i=0, j=0 correspond to horizontally averaged pressure.
-!--       The respective values of ar should be zero at all k-levels if
-!--       acceleration of horizontally averaged vertical velocity is zero.
-          IF ( ibc_p_b == 1  .AND.  ibc_p_t == 1 )  THEN
-             IF ( nys_z == 0  .AND.  nxl_z == 0 )  THEN
-#if __acc_fft_device
-                !$ACC PARALLEL LOOP PRESENT(ar)
-#endif
-                DO  k = 1, nz
-                   ar(nxl_z,nys_z,k) = 0.0_wp
-                ENDDO
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  k  !<
+
+    ALLOCATE( ddzuw(0:nz-1,3) )
+
+    DO  k = 0, nz-1
+       ddzuw(k,1) = ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k)
+       ddzuw(k,2) = ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1)
+       ddzuw(k,3) = -1.0_wp * ( ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1) +                     &
+                                ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k) )
+    ENDDO
+!
+!-- Calculate constant coefficients of the tridiagonal matrix
+    CALL maketri
+    CALL split
+
+#if __acc_fft_device
+    !$ACC ENTER DATA &
+    !$ACC COPYIN(ddzuw(0:nz-1,1:3)) &
+    !$ACC COPYIN(tri(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1,1:2))
+#endif
+
+ END SUBROUTINE tridia_init
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Computes the i- and j-dependent component of the matrix.
+!> Provide the constant coefficients of the tridiagonal matrix for solution of the Poisson equation
+!> in Fourier space. The coefficients are computed following the method of Schmidt et al.
+!> (DFVLR-Mitteilung 84-15), which departs from Stephan Siano's original version by discretizing the
+!> Poisson equation, before it is Fourier-transformed.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE maketri
+
+
+    USE arrays_3d,                                                                                 &
+        ONLY:  tric,                                                                               &
+               rho_air
+
+    USE control_parameters,                                                                        &
+        ONLY:  ibc_p_b,                                                                            &
+               ibc_p_t
+
+    USE grid_variables,                                                                            &
+        ONLY:  dx,                                                                                 &
+               dy
+
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i     !<
+    INTEGER(iwp) ::  j     !<
+    INTEGER(iwp) ::  k     !<
+    INTEGER(iwp) ::  nnxh  !<
+    INTEGER(iwp) ::  nnyh  !<
+
+    REAL(wp)    ::  ll(nxl_z:nxr_z,nys_z:nyn_z)  !<
+
+
+    nnxh = ( nx + 1 ) / 2
+    nnyh = ( ny + 1 ) / 2
+
+    DO  j = nys_z, nyn_z
+       DO  i = nxl_z, nxr_z
+          IF ( j >= 0  .AND.  j <= nnyh )  THEN
+             IF ( i >= 0  .AND.  i <= nnxh )  THEN
+                ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * i ) /                           &
+                                     REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) +                     &
+                          2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) /                           &
+                                     REAL( ny+1, KIND=wp ) ) ) / ( dy * dy )
+             ELSE
+                ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( nx+1-i ) ) /                  &
+                                     REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) +                     &
+                          2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) /                           &
+                                     REAL( ny+1, KIND=wp ) ) ) / ( dy * dy )
+             ENDIF
+          ELSE
+             IF ( i >= 0  .AND.  i <= nnxh )  THEN
+                ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * i ) /                           &
+                                     REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) +                     &
+                          2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( ny+1-j ) ) /                  &
+                                     REAL( ny+1, KIND=wp ) ) ) / ( dy * dy )
+             ELSE
+                ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( nx+1-i ) ) /                  &
+                                     REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) +                     &
+                          2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( ny+1-j ) ) /                  &
+                                     REAL( ny+1, KIND=wp ) ) ) / ( dy * dy )
              ENDIF
           ENDIF
-
-    END SUBROUTINE tridia_substi
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Substitution (Forward and Backward) (Thomas algorithm)
-!------------------------------------------------------------------------------!
-    SUBROUTINE tridia_substi_overlap( ar, jj )
-
-
-          USE arrays_3d,                                                       &
-              ONLY:  tri
-
-          USE control_parameters,                                              &
-              ONLY:  ibc_p_b, ibc_p_t
-
-          IMPLICIT NONE
-
-          INTEGER(iwp) ::  i  !< 
-          INTEGER(iwp) ::  j  !< 
-          INTEGER(iwp) ::  jj !< 
-          INTEGER(iwp) ::  k  !< 
-
-          REAL(wp)     ::  ar(nxl_z:nxr_z,nys_z:nyn_z,1:nz) !< 
-
-          REAL(wp), DIMENSION(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1) ::  ar1 !<
-
-!
-!--       Forward substitution
-          DO  k = 0, nz - 1
-             DO  j = nys_z, nyn_z
-                DO  i = nxl_z, nxr_z
-
-                   IF ( k == 0 )  THEN
-                      ar1(i,j,k) = ar(i,j,k+1)
-                   ELSE
-                      ar1(i,j,k) = ar(i,j,k+1) - tri(i,jj,k,2) * ar1(i,j,k-1)
-                   ENDIF
-
-                ENDDO
-             ENDDO
-          ENDDO
-
-!
-!--       Backward substitution
-!--       Note, the 1.0E-20 in the denominator is due to avoid divisions
-!--       by zero appearing if the pressure bc is set to neumann at the top of
-!--       the model domain.
-          DO  k = nz-1, 0, -1
-             DO  j = nys_z, nyn_z
-                DO  i = nxl_z, nxr_z
-
-                   IF ( k == nz-1 )  THEN
-                      ar(i,j,k+1) = ar1(i,j,k) / ( tri(i,jj,k,1) + 1.0E-20_wp )
-                   ELSE
-                      ar(i,j,k+1) = ( ar1(i,j,k) - ddzuw(k,2) * ar(i,j,k+2) ) &
-                              / tri(i,jj,k,1)
-                   ENDIF
-                ENDDO
-             ENDDO
-          ENDDO
-
-!
-!--       Indices i=0, j=0 correspond to horizontally averaged pressure.
-!--       The respective values of ar should be zero at all k-levels if
-!--       acceleration of horizontally averaged vertical velocity is zero.
-          IF ( ibc_p_b == 1  .AND.  ibc_p_t == 1 )  THEN
-             IF ( nys_z == 0  .AND.  nxl_z == 0 )  THEN
-                DO  k = 1, nz
-                   ar(nxl_z,nys_z,k) = 0.0_wp
-                ENDDO
+       ENDDO
+    ENDDO
+
+    DO  k = 0, nz-1
+       DO  j = nys_z, nyn_z
+          DO  i = nxl_z, nxr_z
+             tric(i,j,k) = ddzuw(k,3) - ll(i,j) * rho_air(k+1)
+          ENDDO
+       ENDDO
+    ENDDO
+
+    IF ( ibc_p_b == 1 )  THEN
+       DO  j = nys_z, nyn_z
+          DO  i = nxl_z, nxr_z
+             tric(i,j,0) = tric(i,j,0) + ddzuw(0,1)
+          ENDDO
+       ENDDO
+    ENDIF
+    IF ( ibc_p_t == 1 )  THEN
+       DO  j = nys_z, nyn_z
+          DO  i = nxl_z, nxr_z
+             tric(i,j,nz-1) = tric(i,j,nz-1) + ddzuw(nz-1,2)
+          ENDDO
+       ENDDO
+    ENDIF
+
+ END SUBROUTINE maketri
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Substitution (Forward and Backward) (Thomas algorithm).
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE tridia_substi( ar )
+
+
+    USE arrays_3d,                                                                                 &
+        ONLY:  tri
+
+    USE control_parameters,                                                                        &
+        ONLY:  ibc_p_b,                                                                            &
+               ibc_p_t
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i !<
+    INTEGER(iwp) ::  j !<
+    INTEGER(iwp) ::  k !<
+
+    REAL(wp)     ::  ar(nxl_z:nxr_z,nys_z:nyn_z,1:nz)  !<
+
+    REAL(wp), DIMENSION(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1) ::  ar1  !<
+#if __acc_fft_device
+    !$ACC DECLARE CREATE(ar1)
+#endif
+
+    !$OMP PARALLEL PRIVATE(i,j,k)
+
+!
+!-- Forward substitution
+#if __acc_fft_device
+    !$ACC PARALLEL PRESENT(ar, ar1, tri) PRIVATE(i,j,k)
+#endif
+    DO  k = 0, nz - 1
+#if __acc_fft_device
+       !$ACC LOOP COLLAPSE(2)
+#endif
+       !$OMP DO
+       DO  j = nys_z, nyn_z
+          DO  i = nxl_z, nxr_z
+
+             IF ( k == 0 )  THEN
+                ar1(i,j,k) = ar(i,j,k+1)
+             ELSE
+                ar1(i,j,k) = ar(i,j,k+1) - tri(i,j,k,2) * ar1(i,j,k-1)
              ENDIF
-          ENDIF
-
-    END SUBROUTINE tridia_substi_overlap
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Splitting of the tridiagonal matrix (Thomas algorithm)
-!------------------------------------------------------------------------------!
-    SUBROUTINE split
-
-
-          USE arrays_3d,                                                       & 
-              ONLY:  tri, tric
-
-          IMPLICIT NONE
-
-          INTEGER(iwp) ::  i !< 
-          INTEGER(iwp) ::  j !< 
-          INTEGER(iwp) ::  k !< 
-!
-!--       Splitting
-          DO  j = nys_z, nyn_z
-             DO  i = nxl_z, nxr_z
-                tri(i,j,0,1) = tric(i,j,0)
-             ENDDO
-          ENDDO
-
-          DO  k = 1, nz-1
-             DO  j = nys_z, nyn_z
-                DO  i = nxl_z, nxr_z
-                   tri(i,j,k,2) = ddzuw(k,1) / tri(i,j,k-1,1)
-                   tri(i,j,k,1) = tric(i,j,k) - ddzuw(k-1,2) * tri(i,j,k,2)
-                ENDDO
-             ENDDO
-          ENDDO
-
-    END SUBROUTINE split
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Solves the linear system of equations for a 1d-decomposition along x (see
-!> tridia)
+
+          ENDDO
+       ENDDO
+    ENDDO
+#if __acc_fft_device
+    !$ACC END PARALLEL
+#endif
+
+!
+!-- Backward substitution
+!-- Note, the 1.0E-20 in the denominator is due to avoid divisions by zero appearing if the
+!-- pressure bc is set to neumann at the top of the model domain.
+#if __acc_fft_device
+    !$ACC PARALLEL PRESENT(ar, ar1, ddzuw, tri) PRIVATE(i,j,k)
+#endif
+    DO  k = nz-1, 0, -1
+#if __acc_fft_device
+       !$ACC LOOP COLLAPSE(2)
+#endif
+       !$OMP DO
+       DO  j = nys_z, nyn_z
+          DO  i = nxl_z, nxr_z
+
+             IF ( k == nz-1 )  THEN
+                ar(i,j,k+1) = ar1(i,j,k) / ( tri(i,j,k,1) + 1.0E-20_wp )
+             ELSE
+                ar(i,j,k+1) = ( ar1(i,j,k) - ddzuw(k,2) * ar(i,j,k+2) ) / tri(i,j,k,1)
+             ENDIF
+          ENDDO
+       ENDDO
+    ENDDO
+#if __acc_fft_device
+    !$ACC END PARALLEL
+#endif
+
+    !$OMP END PARALLEL
+
+!
+!-- Indices i=0, j=0 correspond to horizontally averaged pressure. The respective values of ar
+!-- should be zero at all k-levels if acceleration of horizontally averaged vertical velocity
+!-- is zero.
+    IF ( ibc_p_b == 1  .AND.  ibc_p_t == 1 )  THEN
+       IF ( nys_z == 0  .AND.  nxl_z == 0 )  THEN
+#if __acc_fft_device
+             !$ACC PARALLEL LOOP PRESENT(ar)
+#endif
+          DO  k = 1, nz
+             ar(nxl_z,nys_z,k) = 0.0_wp
+          ENDDO
+       ENDIF
+    ENDIF
+
+ END SUBROUTINE tridia_substi
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Substitution (Forward and Backward) (Thomas algorithm).
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE tridia_substi_overlap( ar, jj )
+
+
+    USE arrays_3d,                                                                                 &
+        ONLY:  tri
+
+    USE control_parameters,                                                                        &
+        ONLY:  ibc_p_b,                                                                            &
+               ibc_p_t
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i  !<
+    INTEGER(iwp) ::  j  !<
+    INTEGER(iwp) ::  jj !<
+    INTEGER(iwp) ::  k  !<
+
+    REAL(wp)     ::  ar(nxl_z:nxr_z,nys_z:nyn_z,1:nz)  !<
+
+    REAL(wp), DIMENSION(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1) ::  ar1  !<
+
+!
+!-- Forward substitution
+    DO  k = 0, nz - 1
+       DO  j = nys_z, nyn_z
+          DO  i = nxl_z, nxr_z
+
+             IF ( k == 0 )  THEN
+                ar1(i,j,k) = ar(i,j,k+1)
+             ELSE
+                ar1(i,j,k) = ar(i,j,k+1) - tri(i,jj,k,2) * ar1(i,j,k-1)
+             ENDIF
+
+          ENDDO
+       ENDDO
+    ENDDO
+
+!
+!-- Backward substitution
+!-- Note, the 1.0E-20 in the denominator is due to avoid divisions by zero appearing if the
+!-- pressure bc is set to neumann at the top of the model domain.
+    DO  k = nz-1, 0, -1
+       DO  j = nys_z, nyn_z
+          DO  i = nxl_z, nxr_z
+
+             IF ( k == nz-1 )  THEN
+                ar(i,j,k+1) = ar1(i,j,k) / ( tri(i,jj,k,1) + 1.0E-20_wp )
+             ELSE
+                ar(i,j,k+1) = ( ar1(i,j,k) - ddzuw(k,2) * ar(i,j,k+2) ) / tri(i,jj,k,1)
+             ENDIF
+          ENDDO
+       ENDDO
+    ENDDO
+
+!
+!-- Indices i=0, j=0 correspond to horizontally averaged pressure. The respective values of ar
+!-- should be zero at all k-levels if acceleration of horizontally averaged vertical velocity
+!-- is zero.
+    IF ( ibc_p_b == 1  .AND.  ibc_p_t == 1 )  THEN
+       IF ( nys_z == 0  .AND.  nxl_z == 0 )  THEN
+          DO  k = 1, nz
+             ar(nxl_z,nys_z,k) = 0.0_wp
+          ENDDO
+       ENDIF
+    ENDIF
+
+ END SUBROUTINE tridia_substi_overlap
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Splitting of the tridiagonal matrix (Thomas algorithm).
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE split
+
+
+    USE arrays_3d,                                                                                 &
+        ONLY:  tri,                                                                                &
+               tric
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i  !<
+    INTEGER(iwp) ::  j  !<
+    INTEGER(iwp) ::  k  !<
+!
+!   Splitting
+    DO  j = nys_z, nyn_z
+       DO  i = nxl_z, nxr_z
+          tri(i,j,0,1) = tric(i,j,0)
+       ENDDO
+    ENDDO
+
+    DO  k = 1, nz-1
+       DO  j = nys_z, nyn_z
+          DO  i = nxl_z, nxr_z
+             tri(i,j,k,2) = ddzuw(k,1) / tri(i,j,k-1,1)
+             tri(i,j,k,1) = tric(i,j,k) - ddzuw(k-1,2) * tri(i,j,k,2)
+          ENDDO
+       ENDDO
+    ENDDO
+
+ END SUBROUTINE split
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Solves the linear system of equations for a 1d-decomposition along x (see tridia).
 !>
-!> @attention when using the intel compilers older than 12.0, array tri must
-!>            be passed as an argument to the contained subroutines. Otherwise
-!>            addres faults will occur. This feature can be activated with
-!>            cpp-switch __intel11
-!>            On NEC, tri should not be passed (except for routine substi_1dd)
-!>            because this causes very bad performance.
-!------------------------------------------------------------------------------!
- 
-    SUBROUTINE tridia_1dd( ddx2, ddy2, nx, ny, j, ar, tri_for_1d )
-
-
-       USE arrays_3d,                                                          &
-           ONLY:  ddzu_pres, ddzw, rho_air, rho_air_zw
-
-       USE control_parameters,                                                 &
-           ONLY:  ibc_p_b, ibc_p_t
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                  !< 
-       INTEGER(iwp) ::  j                  !< 
-       INTEGER(iwp) ::  k                  !< 
-       INTEGER(iwp) ::  nnyh               !< 
-       INTEGER(iwp) ::  nx                 !< 
-       INTEGER(iwp) ::  ny                 !< 
-
-       REAL(wp)     ::  ddx2 !< 
-       REAL(wp)     ::  ddy2 !< 
-
-       REAL(wp), DIMENSION(0:nx,1:nz)     ::  ar         !< 
-       REAL(wp), DIMENSION(5,0:nx,0:nz-1) ::  tri_for_1d !< 
-
-
-       nnyh = ( ny + 1 ) / 2
-
-!
-!--    Define constant elements of the tridiagonal matrix.
-!--    The compiler on SX6 does loop exchange. If 0:nx is a high power of 2,
-!--    the exchanged loops create bank conflicts. The following directive
-!--    prohibits loop exchange and the loops perform much better.
+!> @attention When using intel compilers older than 12.0, array tri must be passed as an argument to
+!>            the contained subroutines. Otherwise address faults will occur. This feature can be
+!>            activated with cpp-switch __intel11. On NEC, tri should not be passed
+!>            (except for routine substi_1dd) because this causes very bad performance.
+!--------------------------------------------------------------------------------------------------!
+
+ SUBROUTINE tridia_1dd( ddx2, ddy2, nx, ny, j, ar, tri_for_1d )
+
+
+    USE arrays_3d,                                                                                 &
+        ONLY:  ddzu_pres,                                                                          &
+               ddzw,                                                                               &
+               rho_air,                                                                            &
+               rho_air_zw
+
+    USE control_parameters,                                                                        &
+        ONLY:  ibc_p_b,                                                                            &
+               ibc_p_t
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i     !<
+    INTEGER(iwp) ::  j     !<
+    INTEGER(iwp) ::  k     !<
+    INTEGER(iwp) ::  nnyh  !<
+    INTEGER(iwp) ::  nx    !<
+    INTEGER(iwp) ::  ny    !<
+
+    REAL(wp)     ::  ddx2  !<
+    REAL(wp)     ::  ddy2  !<
+
+    REAL(wp), DIMENSION(0:nx,1:nz)     ::  ar          !<
+    REAL(wp), DIMENSION(5,0:nx,0:nz-1) ::  tri_for_1d  !<
+
+
+    nnyh = ( ny + 1 ) / 2
+
+!
+!-- Define constant elements of the tridiagonal matrix. The compiler on SX6 does loop exchange.
+!-- If 0:nx is a high power of 2, the exchanged loops create bank conflicts. The following directive
+!-- prohibits loop exchange and the loops perform much better.
 !CDIR NOLOOPCHG
-       DO  k = 0, nz-1
-          DO  i = 0,nx
-             tri_for_1d(2,i,k) = ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k)
-             tri_for_1d(3,i,k) = ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1)
-          ENDDO
-       ENDDO
-
-       IF ( j <= nnyh )  THEN
-          CALL maketri_1dd( j )
+    DO  k = 0, nz-1
+       DO  i = 0,nx
+          tri_for_1d(2,i,k) = ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k)
+          tri_for_1d(3,i,k) = ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1)
+       ENDDO
+    ENDDO
+
+    IF ( j <= nnyh )  THEN
+       CALL maketri_1dd( j )
+    ELSE
+       CALL maketri_1dd( ny+1-j )
+    ENDIF
+
+    CALL split_1dd
+    CALL substi_1dd( ar, tri_for_1d )
+
+ CONTAINS
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Computes the i- and j-dependent component of the matrix.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE maketri_1dd( j )
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i    !<
+    INTEGER(iwp) ::  j    !<
+    INTEGER(iwp) ::  k    !<
+    INTEGER(iwp) ::  nnxh !<
+
+    REAL(wp)     ::  a !<
+    REAL(wp)     ::  c !<
+
+    REAL(wp), DIMENSION(0:nx) ::  l !<
+
+
+    nnxh = ( nx + 1 ) / 2
+!
+!-- Provide the tridiagonal matrix for solution of the Poisson equation in Fourier space.
+!-- The coefficients are computed following the method of Schmidt et al. (DFVLR-Mitteilung 84-15),
+!-- which departs from Stephan Siano's original version by discretizing the Poisson equation,
+!-- before it is Fourier-transformed.
+    DO  i = 0, nx
+       IF ( i >= 0 .AND. i <= nnxh ) THEN
+          l(i) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * i ) /                                    &
+                            REAL( nx+1, KIND=wp ) ) ) * ddx2 +                                     &
+                 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) /                                    &
+                            REAL( ny+1, KIND=wp ) ) ) * ddy2
        ELSE
-          CALL maketri_1dd( ny+1-j )
+          l(i) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( nx+1-i ) ) /                           &
+                            REAL( nx+1, KIND=wp ) ) ) * ddx2 +                                     &
+                 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) /                                    &
+                            REAL( ny+1, KIND=wp ) ) ) * ddy2
        ENDIF
-
-       CALL split_1dd
-       CALL substi_1dd( ar, tri_for_1d )
-
-    CONTAINS
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> computes the i- and j-dependent component of the matrix
-!------------------------------------------------------------------------------!
-       SUBROUTINE maketri_1dd( j )
-
-          IMPLICIT NONE
-
-          INTEGER(iwp) ::  i    !< 
-          INTEGER(iwp) ::  j    !< 
-          INTEGER(iwp) ::  k    !< 
-          INTEGER(iwp) ::  nnxh !< 
-
-          REAL(wp)     ::  a !< 
-          REAL(wp)     ::  c !< 
-
-          REAL(wp), DIMENSION(0:nx) ::  l !< 
-
-
-          nnxh = ( nx + 1 ) / 2
-!
-!--       Provide the tridiagonal matrix for solution of the Poisson equation in
-!--       Fourier space. The coefficients are computed following the method of
-!--       Schmidt et al. (DFVLR-Mitteilung 84-15), which departs from Stephan
-!--       Siano's original version by discretizing the Poisson equation,
-!--       before it is Fourier-transformed
-          DO  i = 0, nx
-             IF ( i >= 0 .AND. i <= nnxh ) THEN
-                l(i) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * i ) / &
-                                   REAL( nx+1, KIND=wp ) ) ) * ddx2 + &
-                       2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) / &
-                                   REAL( ny+1, KIND=wp ) ) ) * ddy2
-             ELSE
-                l(i) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( nx+1-i ) ) / &
-                                   REAL( nx+1, KIND=wp ) ) ) * ddx2 + &
-                       2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) / &
-                                   REAL( ny+1, KIND=wp ) ) ) * ddy2
-             ENDIF
-          ENDDO
-
-          DO  k = 0, nz-1
-             DO  i = 0, nx
-                a = -1.0_wp * ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1)
-                c = -1.0_wp * ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k)
-                tri_for_1d(1,i,k) = a + c - l(i) * rho_air(k+1)
-             ENDDO
-          ENDDO
-          IF ( ibc_p_b == 1 )  THEN
-             DO  i = 0, nx
-                tri_for_1d(1,i,0) = tri_for_1d(1,i,0) + tri_for_1d(2,i,0)
-             ENDDO
-          ENDIF
-          IF ( ibc_p_t == 1 )  THEN
-             DO  i = 0, nx
-                tri_for_1d(1,i,nz-1) = tri_for_1d(1,i,nz-1) + tri_for_1d(3,i,nz-1)
-             ENDDO
-          ENDIF
-
-       END SUBROUTINE maketri_1dd
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Splitting of the tridiagonal matrix (Thomas algorithm)
-!------------------------------------------------------------------------------!
-       SUBROUTINE split_1dd
-
-          IMPLICIT NONE
-
-          INTEGER(iwp) ::  i !< 
-          INTEGER(iwp) ::  k !< 
-
-
-!
-!--       Splitting
-          DO  i = 0, nx
-             tri_for_1d(4,i,0) = tri_for_1d(1,i,0)
-          ENDDO
-          DO  k = 1, nz-1
-             DO  i = 0, nx
-                tri_for_1d(5,i,k) = tri_for_1d(2,i,k) / tri_for_1d(4,i,k-1)
-                tri_for_1d(4,i,k) = tri_for_1d(1,i,k) - tri_for_1d(3,i,k-1) * tri_for_1d(5,i,k)
-             ENDDO
-          ENDDO
-
-       END SUBROUTINE split_1dd
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Substitution (Forward and Backward) (Thomas algorithm)
-!------------------------------------------------------------------------------!
-       SUBROUTINE substi_1dd( ar, tri_for_1d )
-
-
-          IMPLICIT NONE
-
-          INTEGER(iwp) ::  i !< 
-          INTEGER(iwp) ::  k !< 
-
-          REAL(wp), DIMENSION(0:nx,nz)       ::  ar         !< 
-          REAL(wp), DIMENSION(0:nx,0:nz-1)   ::  ar1        !< 
-          REAL(wp), DIMENSION(5,0:nx,0:nz-1) ::  tri_for_1d !< 
-
-!
-!--       Forward substitution
-          DO  i = 0, nx
-             ar1(i,0) = ar(i,1)
-          ENDDO
-          DO  k = 1, nz-1
-             DO  i = 0, nx
-                ar1(i,k) = ar(i,k+1) - tri_for_1d(5,i,k) * ar1(i,k-1)
-             ENDDO
-          ENDDO
-
-!
-!--       Backward substitution
-!--       Note, the add of 1.0E-20 in the denominator is due to avoid divisions
-!--       by zero appearing if the pressure bc is set to neumann at the top of
-!--       the model domain.
-          DO  i = 0, nx
-             ar(i,nz) = ar1(i,nz-1) / ( tri_for_1d(4,i,nz-1) + 1.0E-20_wp )
-          ENDDO
-          DO  k = nz-2, 0, -1
-             DO  i = 0, nx
-                ar(i,k+1) = ( ar1(i,k) - tri_for_1d(3,i,k) * ar(i,k+2) ) &
-                            / tri_for_1d(4,i,k)
-             ENDDO
-          ENDDO
-
-!
-!--       Indices i=0, j=0 correspond to horizontally averaged pressure.
-!--       The respective values of ar should be zero at all k-levels if
-!--       acceleration of horizontally averaged vertical velocity is zero.
-          IF ( ibc_p_b == 1  .AND.  ibc_p_t == 1 )  THEN
-             IF ( j == 0 )  THEN
-                DO  k = 1, nz
-                   ar(0,k) = 0.0_wp
-                ENDDO
-             ENDIF
-          ENDIF
-
-       END SUBROUTINE substi_1dd
-
-    END SUBROUTINE tridia_1dd
+    ENDDO
+
+    DO  k = 0, nz-1
+       DO  i = 0, nx
+          a = -1.0_wp * ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1)
+          c = -1.0_wp * ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k)
+          tri_for_1d(1,i,k) = a + c - l(i) * rho_air(k+1)
+       ENDDO
+    ENDDO
+    IF ( ibc_p_b == 1 )  THEN
+       DO  i = 0, nx
+          tri_for_1d(1,i,0) = tri_for_1d(1,i,0) + tri_for_1d(2,i,0)
+       ENDDO
+    ENDIF
+    IF ( ibc_p_t == 1 )  THEN
+       DO  i = 0, nx
+          tri_for_1d(1,i,nz-1) = tri_for_1d(1,i,nz-1) + tri_for_1d(3,i,nz-1)
+       ENDDO
+    ENDIF
+
+ END SUBROUTINE maketri_1dd
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Splitting of the tridiagonal matrix (Thomas algorithm).
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE split_1dd
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i  !<
+    INTEGER(iwp) ::  k  !<
+
+
+!
+!-- Splitting
+    DO  i = 0, nx
+       tri_for_1d(4,i,0) = tri_for_1d(1,i,0)
+    ENDDO
+    DO  k = 1, nz-1
+       DO  i = 0, nx
+          tri_for_1d(5,i,k) = tri_for_1d(2,i,k) / tri_for_1d(4,i,k-1)
+          tri_for_1d(4,i,k) = tri_for_1d(1,i,k) - tri_for_1d(3,i,k-1) * tri_for_1d(5,i,k)
+       ENDDO
+    ENDDO
+
+ END SUBROUTINE split_1dd
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Substitution (Forward and Backward) (Thomas algorithm).
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE substi_1dd( ar, tri_for_1d )
+
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i  !<
+    INTEGER(iwp) ::  k  !<
+
+    REAL(wp), DIMENSION(0:nx,nz)       ::  ar          !<
+    REAL(wp), DIMENSION(0:nx,0:nz-1)   ::  ar1         !<
+    REAL(wp), DIMENSION(5,0:nx,0:nz-1) ::  tri_for_1d  !<
+
+!
+!-- Forward substitution
+    DO  i = 0, nx
+       ar1(i,0) = ar(i,1)
+    ENDDO
+    DO  k = 1, nz-1
+       DO  i = 0, nx
+          ar1(i,k) = ar(i,k+1) - tri_for_1d(5,i,k) * ar1(i,k-1)
+       ENDDO
+    ENDDO
+
+!
+!-- Backward substitution
+!-- Note, the add of 1.0E-20 in the denominator is due to avoid divisions by zero appearing if the
+!-- pressure bc is set to neumann at the top of the model domain.
+    DO  i = 0, nx
+       ar(i,nz) = ar1(i,nz-1) / ( tri_for_1d(4,i,nz-1) + 1.0E-20_wp )
+    ENDDO
+    DO  k = nz-2, 0, -1
+       DO  i = 0, nx
+          ar(i,k+1) = ( ar1(i,k) - tri_for_1d(3,i,k) * ar(i,k+2) ) / tri_for_1d(4,i,k)
+       ENDDO
+    ENDDO
+
+!
+!-- Indices i=0, j=0 correspond to horizontally averaged pressure. The respective values of ar
+!-- should be zero at all k-levels if acceleration of horizontally averaged vertical velocity is
+!-- zero.
+    IF ( ibc_p_b == 1  .AND.  ibc_p_t == 1 )  THEN
+       IF ( j == 0 )  THEN
+          DO  k = 1, nz
+             ar(0,k) = 0.0_wp
+          ENDDO
+       ENDIF
+    ENDIF
+
+ END SUBROUTINE substi_1dd
+
+ END SUBROUTINE tridia_1dd
 
 
Index: /palm/trunk/SOURCE/turbulence_closure_mod.f90
===================================================================
--- /palm/trunk/SOURCE/turbulence_closure_mod.f90	(revision 4509)
+++ /palm/trunk/SOURCE/turbulence_closure_mod.f90	(revision 4510)
@@ -1,20 +1,20 @@
 !> @file turbulence_closure_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/>.
-!
-! Copyright 2017-2020 Leibniz Universitaet Hannover
-!--------------------------------------------------------------------------------!
+! 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,17 +25,19 @@
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4495 2020-04-13 20:11:20Z raasch
 ! workaround for Intel14 compiler added
-! 
+!
 ! 4486 2020-04-02 20:45:12Z maronga
-! Bugfix: include topography in calculation of distance_to_wall (1.5-order-dai
-! closure)
-! 
+! Bugfix: include topography in calculation of distance_to_wall (1.5-order-dai closure)
+!
 ! 4481 2020-03-31 18:55:54Z maronga
-! - added new LES closure after Dai et al. (2020), which provides much better grid
-!   convergence in stable boundary layer runs. The implementation is experimental
-!   at the moment and should be used with special care. The new SGS closure can be
-!   switched on via turbulence_closure = '1.5-order-dai'
-! - variable ml_wall_adjusted renamed to delta as it represents a grid size and
-!   not a mixing length (see Equations 14 and 18 in Maronga et al. 2015, GMD)
+! - added new LES closure after Dai et al. (2020), which provides much better grid convergence in
+!   stable boundary layer runs. The implementation is experimental at the moment and should be used
+!   with special care. The new SGS closure can be switched on via
+!   turbulence_closure = '1.5-order-dai'
+! - variable ml_wall_adjusted renamed to delta as it represents a grid size and not a mixing length
+!   (see Equations 14 and 18 in Maronga et al. 2015, GMD)
 ! - nameing of turbulence closures revised:
 !        'Moeng_Wyngaard' to '1.5-order'
@@ -44,5 +46,5 @@
 ! - LOGICAL steering variable renamed:
 !        les_mw to les_default
-! 
+!
 ! 4473 2020-03-25 21:04:07Z gronemeier
 ! - rename l-grid to gridsize-geometric-mean
@@ -54,6 +56,5 @@
 !          l to ml
 ! - adjust some comments
-! - corrected definition of wall-adjusted mixing length to include
-!   gridsize-geometric-mean
+! - corrected definition of wall-adjusted mixing length to include gridsize-geometric-mean
 ! - moved definition of wall_adjustment_factor to this module
 !
@@ -68,6 +69,6 @@
 !
 ! 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
@@ -81,6 +82,6 @@
 !
 ! 4170 2019-08-19 17:12:31Z gronemeier
-! - add performance optimizations according to K. Ketelsen
-!   to diffusion_e and tcm_diffusivities_default
+! - add performance optimizations according to K. Ketelsen to diffusion_e and
+!   tcm_diffusivities_default
 ! - bugfix in calculating l_wall for vertical walls
 ! - bugfix in using l_wall in initialization (consider wall_adjustment_factor)
@@ -91,15 +92,12 @@
 !
 ! 4110 2019-07-22 17:05:21Z suehring
-! pass integer flag array as well as boundary flags to WS scalar advection
-! routine
+! pass integer flag array as well as boundary flags to WS scalar advection routine
 !
 ! 4109 2019-07-22 17:00:34Z suehring
 ! - Modularize setting of boundary conditions for TKE and dissipation
 ! - Neumann boundary condition for TKE at model top is set also in child domain
-! - Revise setting of Neumann boundary conditions at non-cyclic lateral
-!   boundaries
-! - Bugfix, set Neumann boundary condition for TKE at vertical wall instead of
-!   an implicit Dirichlet boundary condition which implied a sink of TKE
-!   at vertical walls
+! - Revise setting of Neumann boundary conditions at non-cyclic lateral boundaries
+! - Bugfix, set Neumann boundary condition for TKE at vertical wall instead of an implicit Dirichlet
+!   boundary condition which implied a sink of TKE at vertical walls
 !
 ! 4048 2019-06-21 21:00:21Z knoop
@@ -113,6 +111,6 @@
 !
 ! 3719 2019-02-06 13:10:18Z kanani
-! Changed log_point to log_point_s, otherwise this overlaps with
-! 'all progn.equations' cpu measurement.
+! Changed log_point to log_point_s, otherwise this overlaps with 'all progn.equations' cpu
+! measurement.
 !
 ! 3684 2019-01-20 20:20:58Z knoop
@@ -136,78 +134,131 @@
 !> @todo Check for random disturbances
 !> @note <Enter notes on the module>
-!-----------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  MODULE turbulence_closure_mod
 
 
-    USE arrays_3d,                                                            &
-        ONLY:  diss, diss_1, diss_2, diss_3, diss_p, dzu, e, e_1, e_2, e_3,   &
-               e_p, kh, km, mean_inflow_profiles, prho, pt, tdiss_m,          &
-               te_m, tend, u, v, vpt, w
-
-    USE basic_constants_and_equations_mod,                                    &
-        ONLY:  g, kappa, lv_d_cp, lv_d_rd, rd_d_rv
-
-    USE control_parameters,                                                   &
-        ONLY:  bc_dirichlet_l,                                                &
-               bc_dirichlet_n,                                                &
-               bc_dirichlet_r,                                                &
-               bc_dirichlet_s,                                                &
-               bc_radiation_l,                                                &
-               bc_radiation_n,                                                &
-               bc_radiation_r,                                                &
-               bc_radiation_s,                                                &
-               child_domain,                                                  &
-               constant_diffusion, dt_3d, e_init, humidity,                   &
-               initializing_actions, intermediate_timestep_count,             &
-               intermediate_timestep_count_max, km_constant,                  &
-               les_dai, les_dynamic, les_default,                             &
-               ocean_mode, plant_canopy, prandtl_number,                      &
-               pt_reference, rans_mode, rans_tke_e, rans_tke_l,               &
-               timestep_scheme, turbulence_closure,                           &
-               turbulent_inflow, use_upstream_for_tke, vpt_reference,         &
-               ws_scheme_sca, current_timestep_number
-
-    USE advec_ws,                                                             &
+    USE arrays_3d,                                                                                 &
+        ONLY:  diss,                                                                               &
+               diss_1,                                                                             &
+               diss_2,                                                                             &
+               diss_3,                                                                             &
+               diss_p,                                                                             &
+               dzu,                                                                                &
+               e,                                                                                  &
+               e_1,                                                                                &
+               e_2,                                                                                &
+               e_3,                                                                                &
+               e_p,                                                                                &
+               kh,                                                                                 &
+               km,                                                                                 &
+               mean_inflow_profiles,                                                               &
+               prho,                                                                               &
+               pt,                                                                                 &
+               tdiss_m,                                                                            &
+               te_m,                                                                               &
+               tend,                                                                               &
+               u,                                                                                  &
+               v,                                                                                  &
+               vpt,                                                                                &
+               w
+
+    USE basic_constants_and_equations_mod,                                                         &
+        ONLY:  g,                                                                                  &
+               kappa,                                                                              &
+               lv_d_cp,                                                                            &
+               lv_d_rd,                                                                            &
+               rd_d_rv
+
+    USE control_parameters,                                                                        &
+        ONLY:  bc_dirichlet_l,                                                                     &
+               bc_dirichlet_n,                                                                     &
+               bc_dirichlet_r,                                                                     &
+               bc_dirichlet_s,                                                                     &
+               bc_radiation_l,                                                                     &
+               bc_radiation_n,                                                                     &
+               bc_radiation_r,                                                                     &
+               bc_radiation_s,                                                                     &
+               child_domain,                                                                       &
+               constant_diffusion,                                                                 &
+               current_timestep_number,                                                            &
+               dt_3d,                                                                              &
+               e_init,                                                                             &
+               humidity,                                                                           &
+               initializing_actions,                                                               &
+               intermediate_timestep_count,                                                        &
+               intermediate_timestep_count_max,                                                    &
+               km_constant,                                                                        &
+               les_dai,                                                                            &
+               les_dynamic,                                                                        &
+               les_default,                                                                        &
+               ocean_mode,                                                                         &
+               plant_canopy,                                                                       &
+               prandtl_number,                                                                     &
+               pt_reference,                                                                       &
+               rans_mode,                                                                          &
+               rans_tke_e,                                                                         &
+               rans_tke_l,                                                                         &
+               timestep_scheme,                                                                    &
+               turbulence_closure,                                                                 &
+               turbulent_inflow,                                                                   &
+               use_upstream_for_tke,                                                               &
+               vpt_reference,                                                                      &
+               ws_scheme_sca
+
+
+    USE advec_ws,                                                                                  &
         ONLY:  advec_s_ws
 
-    USE advec_s_bc_mod,                                                       &
+    USE advec_s_bc_mod,                                                                            &
         ONLY:  advec_s_bc
 
-    USE advec_s_pw_mod,                                                       &
+    USE advec_s_pw_mod,                                                                            &
         ONLY:  advec_s_pw
 
-    USE advec_s_up_mod,                                                       &
+    USE advec_s_up_mod,                                                                            &
         ONLY:  advec_s_up
 
-    USE cpulog,                                                               &
+    USE cpulog,                                                                                    &
         ONLY:  cpu_log, log_point_s
 
-    USE indices,                                                              &
-        ONLY:  advc_flags_s,                                                  &
-               nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt,    &
-               topo_top_ind,                                                  &
+    USE indices,                                                                                   &
+        ONLY:  advc_flags_s,                                                                       &
+               nbgp,                                                                               &
+               nxl,                                                                                &
+               nxlg,                                                                               &
+               nxr,                                                                                &
+               nxrg,                                                                               &
+               nyn,                                                                                &
+               nyng,                                                                               &
+               nys,                                                                                &
+               nysg,                                                                               &
+               nzb,                                                                                &
+               nzt,                                                                                &
+               topo_top_ind,                                                                       &
                wall_flags_total_0
 
     USE kinds
 
-    USE ocean_mod,                                                            &
+    USE ocean_mod,                                                                                 &
         ONLY:  prho_reference
 
     USE pegrid
 
-    USE plant_canopy_model_mod,                                               &
+    USE plant_canopy_model_mod,                                                                    &
         ONLY:  pcm_tendency
 
-    USE statistics,                                                           &
-        ONLY:  hom, hom_sum, statistic_regions
-
-    USE surface_mod,                                                          &
-        ONLY:  bc_h,                                                          &
-               bc_v,                                                          &
-               surf_def_h,                                                    &
-               surf_def_v,                                                    &
-               surf_lsm_h,                                                    &
-               surf_lsm_v,                                                    &
-               surf_usm_h,                                                    &
+    USE statistics,                                                                                &
+        ONLY:  hom,                                                                                &
+               hom_sum,                                                                            &
+               statistic_regions
+
+    USE surface_mod,                                                                               &
+        ONLY:  bc_h,                                                                               &
+               bc_v,                                                                               &
+               surf_def_h,                                                                         &
+               surf_def_v,                                                                         &
+               surf_lsm_h,                                                                         &
+               surf_lsm_v,                                                                         &
+               surf_usm_h,                                                                         &
                surf_usm_v
 
@@ -225,17 +276,19 @@
     REAL(wp) ::  wall_adjustment_factor = 1.8_wp  !< adjustment factor for mixing length
 
-    REAL(wp), DIMENSION(0:4) :: rans_const_c = &        !< model constants for RANS mode (namelist param)
-       (/ 0.55_wp, 1.44_wp, 1.92_wp, 1.44_wp, 0.0_wp /) !> default values fit for standard-tke-e closure
-
-    REAL(wp), DIMENSION(2) :: rans_const_sigma = &      !< model constants for RANS mode, sigma values (namelist param)
-       (/ 1.0_wp, 1.30_wp /)                            !> (sigma_e, sigma_diss)
-
-    REAL(wp), ALLOCATABLE, DIMENSION(:)     ::  ml_blackadar             !< mixing length according to Blackadar
-    REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::  delta                    !< grid size, possibly limited by wall adjustment factor
-    REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::  distance_to_wall         !< distance to the surface/wall
+    REAL(wp), DIMENSION(0:4) ::  rans_const_c = &        !< model constants for RANS mode (namelist param)
+       (/ 0.55_wp, 1.44_wp, 1.92_wp, 1.44_wp, 0.0_wp /)  !> default values fit for standard-tke-e closure
+
+    REAL(wp), DIMENSION(2) ::  rans_const_sigma = &      !< model constants for RANS mode, sigma values (namelist param)
+       (/ 1.0_wp, 1.30_wp /)                             !> (sigma_e, sigma_diss)
+
+    REAL(wp), ALLOCATABLE, DIMENSION(:)     ::  ml_blackadar      !< mixing length according to Blackadar
+    REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::  delta             !< grid size, possibly limited by wall adjustment factor
+    REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::  distance_to_wall  !< distance to the surface/wall
 
 !
 !-- Public variables
-    PUBLIC c_0, rans_const_c, rans_const_sigma
+    PUBLIC c_0,                                                                                    &
+           rans_const_c,                                                                           &
+           rans_const_sigma
 
     SAVE
@@ -244,18 +297,20 @@
 !
 !-- Public subroutines
-    PUBLIC                                                                     &
-       tcm_boundary_conds,                                                     &
-       tcm_check_parameters,                                                   &
-       tcm_check_data_output,                                                  &
-       tcm_define_netcdf_grid,                                                 &
-       tcm_init_arrays,                                                        &
-       tcm_init,                                                               &
-       tcm_actions,                                                            &
-       tcm_prognostic_equations,                                               &
-       tcm_swap_timelevel,                                                     &
-       tcm_3d_data_averaging,                                                  &
-       tcm_data_output_2d,                                                     &
-       tcm_data_output_3d,                                                     &
-       tcm_diffusivities
+    PUBLIC  tcm_actions,                                                                           &
+            tcm_boundary_conds,                                                                    &
+            tcm_check_parameters,                                                                  &
+            tcm_check_data_output,                                                                 &
+            tcm_data_output_2d,                                                                    &
+            tcm_data_output_3d,                                                                    &
+            tcm_define_netcdf_grid,                                                                &
+            tcm_diffusivities,                                                                     &
+            tcm_init_arrays,                                                                       &
+            tcm_init,                                                                              &
+            tcm_prognostic_equations,                                                              &
+            tcm_swap_timelevel,                                                                    &
+            tcm_3d_data_averaging
+
+
+
 
 !
@@ -342,12 +397,12 @@
  CONTAINS
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Check parameters routine for turbulence closure module.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_boundary_conds
 
-    USE pmc_interface,                                                         &
+    USE pmc_interface,                                                                             &
         ONLY : rans_mode_parent
 
@@ -364,6 +419,5 @@
 !
 !--    In LES mode, Neumann conditions with de/x_i=0 are assumed at solid walls.
-!--    Note, only TKE is prognostic in this case and dissipation is only
-!--    a diagnostic quantity.
+!--    Note, only TKE is prognostic in this case and dissipation is only a diagnostic quantity.
        IF ( .NOT. rans_mode )  THEN
 !
@@ -384,9 +438,8 @@
           DO  l = 0, 3
 !
-!--          Note concerning missing ACC directive for this loop: Even though
-!--          the data structure bc_v is present, it may not contain any
-!--          allocated arrays in the flat but also in a topography case,
-!--          leading to a runtime error. Therefore, omit ACC directives
-!--          for this loop, in contrast to the bc_h loop.
+!--          Note concerning missing ACC directive for this loop: Even though the data structure
+!--          bc_v is present, it may not contain any allocated arrays in the flat but also in a
+!--          topography case, leading to a runtime error. Therefore, omit ACC directives for this
+!--          loop, in contrast to the bc_h loop.
              !$OMP PARALLEL DO PRIVATE( i, j, k )
              DO  m = 1, bc_v(l)%ns
@@ -402,6 +455,6 @@
 !
 !--       Use wall function within constant-flux layer
-!--       Note, grid points listed in bc_h are not included in any calculations in RANS mode and
-!--       are therefore not set here.
+!--       Note, grid points listed in bc_h are not included in any calculations in RANS mode and are
+!--       therefore not set here.
 !
 !--       Upward-facing surfaces
@@ -459,15 +512,13 @@
        ENDIF
 !
-!--    Set Neumann boundary condition for TKE at model top. Do this also
-!--    in case of a nested run.
+!--    Set Neumann boundary condition for TKE at model top. Do this also in case of a nested run.
        !$ACC KERNELS PRESENT(e_p)
        e_p(nzt+1,:,:) = e_p(nzt,:,:)
        !$ACC END KERNELS
 !
-!--    Nesting case: if parent operates in RANS mode and child in LES mode,
-!--    no TKE is transfered. This case, set Neumann conditions at lateral and
-!--    top child boundaries.
-!--    If not ( both either in RANS or in LES mode ), TKE boundary condition
-!--    is treated in the nesting.
+!--    Nesting case: if parent operates in RANS mode and child in LES mode, no TKE is transfered.
+!--    This case, set Neumann conditions at lateral and top child boundaries.
+!--    If not ( both either in RANS or in LES mode ), TKE boundary condition is treated in the
+!--    nesting.
        If ( child_domain )  THEN
           IF ( rans_mode_parent  .AND.  .NOT. rans_mode )  THEN
@@ -482,11 +533,9 @@
        ENDIF
 !
-!--    At in- and outflow boundaries also set Neumann boundary conditions
-!--    for the SGS-TKE. An exception is made for the child domain if
-!--    both parent and child operate in RANS mode. This case no
-!--    lateral Neumann boundary conditions will be set but Dirichlet
-!--    conditions will be set in the nesting.
-       IF ( .NOT. child_domain  .AND.  .NOT. rans_mode_parent  .AND.           &
-            .NOT. rans_mode )  THEN
+!--    At in- and outflow boundaries also set Neumann boundary conditions for the SGS-TKE. An
+!--    exception is made for the child domain if both parent and child operate in RANS mode. This
+!--    case no lateral Neumann boundary conditions will be set but Dirichlet conditions will be set
+!--    in the nesting.
+       IF ( .NOT. child_domain  .AND.  .NOT. rans_mode_parent  .AND.  .NOT. rans_mode )  THEN
           IF ( bc_dirichlet_s  .OR.  bc_radiation_s )  THEN
              e_p(:,nys-1,:) = e_p(:,nys,:)
@@ -519,6 +568,5 @@
           j = surf_def_h(0)%j(m)
           k = surf_def_h(0)%k(m)
-          diss_p(k,j,i) = surf_def_h(0)%us(m)**3          &
-                        / ( kappa * surf_def_h(0)%z_mo(m) )
+          diss_p(k,j,i) = surf_def_h(0)%us(m)**3 / ( kappa * surf_def_h(0)%z_mo(m) )
        ENDDO
 !
@@ -528,6 +576,5 @@
           j = surf_lsm_h%j(m)
           k = surf_lsm_h%k(m)
-          diss_p(k,j,i) = surf_lsm_h%us(m)**3          &
-                        / ( kappa * surf_lsm_h%z_mo(m) )
+          diss_p(k,j,i) = surf_lsm_h%us(m)**3 / ( kappa * surf_lsm_h%z_mo(m) )
        ENDDO
 !
@@ -537,6 +584,5 @@
           j = surf_usm_h%j(m)
           k = surf_usm_h%k(m)
-          diss_p(k,j,i) = surf_usm_h%us(m)**3          &
-                        / ( kappa * surf_usm_h%z_mo(m) )
+          diss_p(k,j,i) = surf_usm_h%us(m)**3 / ( kappa * surf_usm_h%z_mo(m) )
        ENDDO
 !
@@ -549,6 +595,5 @@
              j = surf_def_v(l)%j(m)
              k = surf_def_v(l)%k(m)
-             diss_p(k,j,i) = surf_def_v(l)%us(m)**3          &
-                           / ( kappa * surf_def_v(l)%z_mo(m) )
+             diss_p(k,j,i) = surf_def_v(l)%us(m)**3 / ( kappa * surf_def_v(l)%z_mo(m) )
           ENDDO
 !
@@ -558,6 +603,5 @@
              j = surf_lsm_v(l)%j(m)
              k = surf_lsm_v(l)%k(m)
-             diss_p(k,j,i) = surf_lsm_v(l)%us(m)**3          &
-                           / ( kappa * surf_lsm_v(l)%z_mo(m) )
+             diss_p(k,j,i) = surf_lsm_v(l)%us(m)**3 / ( kappa * surf_lsm_v(l)%z_mo(m) )
           ENDDO
 !
@@ -567,18 +611,14 @@
              j = surf_usm_v(l)%j(m)
              k = surf_usm_v(l)%k(m)
-             diss_p(k,j,i) = surf_usm_v(l)%us(m)**3          &
-                           / ( kappa * surf_usm_v(l)%z_mo(m) )
+             diss_p(k,j,i) = surf_usm_v(l)%us(m)**3 / ( kappa * surf_usm_v(l)%z_mo(m) )
           ENDDO
        ENDDO
 !
-!--    Limit change of diss to be between -90% and +100%. Also, set an absolute
-!--    minimum value
+!--    Limit change of diss to be between -90% and +100%. Also, set an absolute minimum value
        DO  i = nxl, nxr
           DO  j = nys, nyn
              DO  k = nzb, nzt+1
-                diss_p(k,j,i) = MAX( MIN( diss_p(k,j,i),          &
-                                          2.0_wp * diss(k,j,i) ), &
-                                     0.1_wp * diss(k,j,i),        &
-                                     0.0001_wp )
+                diss_p(k,j,i) = MAX( MIN( diss_p(k,j,i), 2.0_wp * diss(k,j,i) ),                   &
+                                          0.1_wp * diss(k,j,i), 0.0001_wp )
              ENDDO
           ENDDO
@@ -591,13 +631,15 @@
  END SUBROUTINE tcm_boundary_conds
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Check parameters routine for turbulence closure module.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_check_parameters
 
-    USE control_parameters,                                                    &
-        ONLY:  message_string, turbulent_inflow, turbulent_outflow
+    USE control_parameters,                                                                        &
+        ONLY:  message_string,                                                                     &
+               turbulent_inflow,                                                                   &
+               turbulent_outflow
 
     IMPLICIT NONE
@@ -625,6 +667,5 @@
 
        CASE DEFAULT
-          message_string = 'Unknown turbulence closure: ' //                &
-                           TRIM( turbulence_closure )
+          message_string = 'Unknown turbulence closure: ' // TRIM( turbulence_closure )
           CALL message( 'tcm_check_parameters', 'PA0500', 1, 2, 0, 6, 0 )
 
@@ -641,10 +682,9 @@
        c_1 = rans_const_c(1)
        c_2 = rans_const_c(2)
-       c_3 = rans_const_c(3)   !> @todo clarify how to switch between different models
+       c_3 = rans_const_c(3)   !> @todo Clarify how to switch between different models
        c_4 = rans_const_c(4)
 
        IF ( turbulent_inflow .OR. turbulent_outflow )  THEN
-          message_string = 'turbulent inflow/outflow is not yet '//            &
-                           'implemented for RANS mode'
+          message_string = 'turbulent inflow/outflow is not yet '// 'implemented for RANS mode'
           CALL message( 'tcm_check_parameters', 'PA0501', 1, 2, 0, 6, 0 )
        ENDIF
@@ -653,8 +693,7 @@
 !
 !--    LES mode
-       c_0 = 0.1_wp    !according to Lilly (1967) and Deardorff (1980)
-
-       dsig_e = 1.0_wp !assure to use K_m to calculate TKE instead
-                       !of K_e which is used in RANS mode
+       c_0 = 0.1_wp    !According to Lilly (1967) and Deardorff (1980)
+
+       dsig_e = 1.0_wp !Assure to use K_m to calculate TKE instead of K_e which is used in RANS mode
 
     ENDIF
@@ -662,15 +701,15 @@
  END SUBROUTINE tcm_check_parameters
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Check data output.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_check_data_output( var, unit )
 
     IMPLICIT NONE
 
-    CHARACTER (LEN=*) ::  unit     !< unit of output variable
-    CHARACTER (LEN=*) ::  var      !< name of output variable
+    CHARACTER(LEN=*) ::  unit  !< unit of output variable
+    CHARACTER(LEN=*) ::  var   !< name of output variable
 
 
@@ -691,18 +730,17 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Define appropriate grid for netcdf variables.
-!> It is called out from subroutine netcdf.
-!------------------------------------------------------------------------------!
+!> Define appropriate grid for netcdf variables. It is called out from subroutine netcdf.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_define_netcdf_grid( var, found, grid_x, grid_y, grid_z )
 
     IMPLICIT NONE
 
-    CHARACTER (LEN=*), INTENT(OUT) ::  grid_x   !< x grid of output variable
-    CHARACTER (LEN=*), INTENT(OUT) ::  grid_y   !< y grid of output variable
-    CHARACTER (LEN=*), INTENT(OUT) ::  grid_z   !< z grid of output variable
-    CHARACTER (LEN=*), INTENT(IN)  ::  var      !< name of output variable
+    CHARACTER(LEN=*), INTENT(OUT) ::  grid_x  !< x grid of output variable
+    CHARACTER(LEN=*), INTENT(OUT) ::  grid_y  !< y grid of output variable
+    CHARACTER(LEN=*), INTENT(OUT) ::  grid_z  !< z grid of output variable
+    CHARACTER(LEN=*), INTENT(IN)  ::  var     !< name of output variable
 
     LOGICAL, INTENT(OUT) ::  found   !< flag if output variable is found
@@ -740,26 +778,28 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Average 3D data.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_3d_data_averaging( mode, variable )
 
 
-    USE averaging,                                                             &
-        ONLY:  diss_av, kh_av, km_av
-
-    USE control_parameters,                                                    &
+    USE averaging,                                                                                 &
+        ONLY:  diss_av,                                                                            &
+               kh_av,                                                                              &
+               km_av
+
+    USE control_parameters,                                                                        &
         ONLY:  average_count_3d
 
     IMPLICIT NONE
 
-    CHARACTER (LEN=*) ::  mode       !< flag defining mode 'allocate', 'sum' or 'average'
-    CHARACTER (LEN=*) ::  variable   !< name of variable
-
-    INTEGER(iwp) ::  i   !< loop index
-    INTEGER(iwp) ::  j   !< loop index
-    INTEGER(iwp) ::  k   !< loop index
+    CHARACTER(LEN=*) ::  mode      !< flag defining mode 'allocate', 'sum' or 'average'
+    CHARACTER(LEN=*) ::  variable  !< name of variable
+
+    INTEGER(iwp) ::  i  !< loop index
+    INTEGER(iwp) ::  j  !< loop index
+    INTEGER(iwp) ::  k  !< loop index
 
     IF ( mode == 'allocate' )  THEN
@@ -841,6 +881,5 @@
                    DO  j = nysg, nyng
                       DO  k = nzb, nzt+1
-                         diss_av(k,j,i) = diss_av(k,j,i)                       &
-                                        / REAL( average_count_3d, KIND=wp )
+                         diss_av(k,j,i) = diss_av(k,j,i) / REAL( average_count_3d, KIND = wp )
                       ENDDO
                    ENDDO
@@ -853,6 +892,5 @@
                    DO  j = nysg, nyng
                       DO  k = nzb, nzt+1
-                         kh_av(k,j,i) = kh_av(k,j,i)                           &
-                                        / REAL( average_count_3d, KIND=wp )
+                         kh_av(k,j,i) = kh_av(k,j,i) / REAL( average_count_3d, KIND = wp )
                       ENDDO
                    ENDDO
@@ -865,6 +903,5 @@
                    DO  j = nysg, nyng
                       DO  k = nzb, nzt+1
-                         km_av(k,j,i) = km_av(k,j,i)                           &
-                                        / REAL( average_count_3d, KIND=wp )
+                         km_av(k,j,i) = km_av(k,j,i) / REAL( average_count_3d, KIND = wp )
                       ENDDO
                    ENDDO
@@ -879,28 +916,29 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Define 2D output variables.
-!------------------------------------------------------------------------------!
- SUBROUTINE tcm_data_output_2d( av, variable, found, grid, mode, local_pf,     &
-                                nzb_do, nzt_do )
-
-    USE averaging,                                                             &
-        ONLY:  diss_av, kh_av, km_av
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE tcm_data_output_2d( av, variable, found, grid, mode, local_pf, nzb_do, nzt_do )
+
+    USE averaging,                                                                                 &
+        ONLY:  diss_av,                                                                            &
+               kh_av,                                                                              &
+               km_av
 
     IMPLICIT NONE
 
-    CHARACTER (LEN=*) ::  grid       !< name of vertical grid
-    CHARACTER (LEN=*) ::  mode       !< either 'xy', 'xz' or 'yz'
-    CHARACTER (LEN=*) ::  variable   !< name of variable
-
-    INTEGER(iwp) ::  av        !< flag for (non-)average output
-    INTEGER(iwp) ::  flag_nr   !< number of masking flag
-    INTEGER(iwp) ::  i         !< loop index
-    INTEGER(iwp) ::  j         !< loop index
-    INTEGER(iwp) ::  k         !< loop index
-    INTEGER(iwp) ::  nzb_do    !< vertical output index (bottom)
-    INTEGER(iwp) ::  nzt_do    !< vertical output index (top)
+    CHARACTER(LEN=*) ::  grid      !< name of vertical grid
+    CHARACTER(LEN=*) ::  mode      !< either 'xy', 'xz' or 'yz'
+    CHARACTER(LEN=*) ::  variable  !< name of variable
+
+    INTEGER(iwp) ::  av       !< flag for (non-)average output
+    INTEGER(iwp) ::  flag_nr  !< number of masking flag
+    INTEGER(iwp) ::  i        !< loop index
+    INTEGER(iwp) ::  j        !< loop index
+    INTEGER(iwp) ::  k        !< loop index
+    INTEGER(iwp) ::  nzb_do   !< vertical output index (bottom)
+    INTEGER(iwp) ::  nzt_do   !< vertical output index (top)
 
     LOGICAL ::  found     !< flag if output variable is found
@@ -909,6 +947,6 @@
     REAL(wp) ::  fill_value = -9999.0_wp  !< value for the _FillValue attribute
 
-    REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !< local
-       !< array to which output data is resorted to
+    REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf  !< local
+     !< array to which output data is resorted to
 
     REAL(wp), DIMENSION(:,:,:), POINTER ::  to_be_resorted  !< points to selected output variable
@@ -926,5 +964,5 @@
              to_be_resorted => diss
           ELSE
-             IF ( .NOT. ALLOCATED( diss_av ) ) THEN
+             IF ( .NOT. ALLOCATED( diss_av ) )  THEN
                 ALLOCATE( diss_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
                 diss_av = REAL( fill_value, KIND = wp )
@@ -938,5 +976,5 @@
              to_be_resorted => kh
           ELSE
-             IF ( .NOT. ALLOCATED( kh_av ) ) THEN
+             IF ( .NOT. ALLOCATED( kh_av ) )  THEN
                 ALLOCATE( kh_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
                 kh_av = REAL( fill_value, KIND = wp )
@@ -950,5 +988,5 @@
              to_be_resorted => km
           ELSE
-             IF ( .NOT. ALLOCATED( km_av ) ) THEN
+             IF ( .NOT. ALLOCATED( km_av ) )  THEN
                 ALLOCATE( km_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
                 km_av = REAL( fill_value, KIND = wp )
@@ -964,10 +1002,9 @@
     END SELECT
 
-    IF ( found .AND. .NOT. resorted )  THEN
+    IF ( found  .AND.  .NOT.  resorted )  THEN
        DO  i = nxl, nxr
           DO  j = nys, nyn
              DO  k = nzb_do, nzt_do
-                local_pf(i,j,k) = MERGE( to_be_resorted(k,j,i),                &
-                                  REAL( fill_value, KIND = wp ),               &
+                local_pf(i,j,k) = MERGE( to_be_resorted(k,j,i), REAL( fill_value, KIND = wp ),     &
                                   BTEST( wall_flags_total_0(k,j,i), flag_nr ) )
              ENDDO
@@ -979,26 +1016,28 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Define 3D output variables.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
 
 
-    USE averaging,                                                             &
-        ONLY:  diss_av, kh_av, km_av
+    USE averaging,                                                                                 &
+        ONLY:  diss_av,                                                                            &
+               kh_av,                                                                              &
+               km_av
 
     IMPLICIT NONE
 
-    CHARACTER (LEN=*) ::  variable   !< name of variable
-
-    INTEGER(iwp) ::  av        !< flag for (non-)average output
-    INTEGER(iwp) ::  flag_nr   !< number of masking flag
-    INTEGER(iwp) ::  i         !< loop index
-    INTEGER(iwp) ::  j         !< loop index
-    INTEGER(iwp) ::  k         !< loop index
-    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)
+    CHARACTER(LEN=*) ::  variable  !< name of variable
+
+    INTEGER(iwp) ::  av       !< flag for (non-)average output
+    INTEGER(iwp) ::  flag_nr  !< number of masking flag
+    INTEGER(iwp) ::  i        !< loop index
+    INTEGER(iwp) ::  j        !< loop index
+    INTEGER(iwp) ::  k        !< loop index
+    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     !< flag if output variable is found
@@ -1007,5 +1046,5 @@
     REAL(wp) ::  fill_value = -9999.0_wp  !< value for the _FillValue attribute
 
-    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf   !< local
+    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf  !< local
        !< array to which output data is resorted to
 
@@ -1024,5 +1063,5 @@
              to_be_resorted => diss
           ELSE
-             IF ( .NOT. ALLOCATED( diss_av ) ) THEN
+             IF ( .NOT. ALLOCATED( diss_av ) )  THEN
                 ALLOCATE( diss_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
                 diss_av = REAL( fill_value, KIND = wp )
@@ -1035,5 +1074,5 @@
              to_be_resorted => kh
           ELSE
-             IF ( .NOT. ALLOCATED( kh_av ) ) THEN
+             IF ( .NOT. ALLOCATED( kh_av ) )  THEN
                 ALLOCATE( kh_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
                 kh_av = REAL( fill_value, KIND = wp )
@@ -1046,5 +1085,5 @@
              to_be_resorted => km
           ELSE
-             IF ( .NOT. ALLOCATED( km_av ) ) THEN
+             IF ( .NOT. ALLOCATED( km_av ) )  THEN
                 ALLOCATE( km_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
                 km_av = REAL( fill_value, KIND = wp )
@@ -1059,12 +1098,10 @@
 
 
-    IF ( found .AND. .NOT. resorted )  THEN
+    IF ( found  .AND.  .NOT.  resorted )  THEN
        DO  i = nxl, nxr
           DO  j = nys, nyn
              DO  k = nzb_do, nzt_do
-                local_pf(i,j,k) = MERGE(                                 &
-                                   to_be_resorted(k,j,i),                &
-                                   REAL( fill_value, KIND = wp ),        &
-                                   BTEST( wall_flags_total_0(k,j,i), flag_nr ) )
+                local_pf(i,j,k) = MERGE( to_be_resorted(k,j,i), REAL( fill_value, KIND = wp ),     &
+                                  BTEST( wall_flags_total_0(k,j,i), flag_nr ) )
              ENDDO
           ENDDO
@@ -1076,15 +1113,15 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Allocate arrays and assign pointers.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_init_arrays
 
-    USE bulk_cloud_model_mod,                                                  &
+    USE bulk_cloud_model_mod,                                                                      &
         ONLY:  collision_turbulence
 
-    USE pmc_interface,                                                         &
+    USE pmc_interface,                                                                             &
         ONLY:  nested_run
 
@@ -1100,7 +1137,7 @@
 !
 !-- Allocate arrays required for dissipation.
-!-- Please note, if it is a nested run, arrays need to be allocated even if
-!-- they do not necessarily need to be transferred, which is attributed to
-!-- the design of the model coupler which allocates memory for each variable.
+!-- Please note, if it is a nested run, arrays need to be allocated even if they do not necessarily
+!-- need to be transferred, which is attributed to the design of the model coupler which allocates
+!-- memory for each variable.
     ALLOCATE( diss_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 
@@ -1122,24 +1159,28 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Initialization of turbulence closure module.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_init
 
-    USE control_parameters,                                                    &
-        ONLY:  bc_dirichlet_l, complex_terrain, topography
-
-    USE model_1d_mod,                                                          &
-        ONLY:  e1d, kh1d, km1d
+    USE control_parameters,                                                                        &
+        ONLY:  bc_dirichlet_l,                                                                     &
+               complex_terrain,                                                                    &
+               topography
+
+    USE model_1d_mod,                                                                              &
+        ONLY:  e1d,                                                                                &
+               kh1d,                                                                               &
+               km1d
 
     IMPLICIT NONE
 
-    INTEGER(iwp) :: i            !< loop index
-    INTEGER(iwp) :: j            !< loop index
-    INTEGER(iwp) :: k            !< loop index
-    INTEGER(iwp) :: nz_s_shift   !< lower shift index for scalars
-    INTEGER(iwp) :: nz_s_shift_l !< local lower shift index in case of turbulent inflow
+    INTEGER(iwp) :: i             !< loop index
+    INTEGER(iwp) :: j             !< loop index
+    INTEGER(iwp) :: k             !< loop index
+    INTEGER(iwp) :: nz_s_shift    !< lower shift index for scalars
+    INTEGER(iwp) :: nz_s_shift_l  !< local lower shift index in case of turbulent inflow
 
 !
@@ -1149,10 +1190,10 @@
 !
 !-- Actions for initial runs
-    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
+    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.                                &
          TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
 
        IF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
 
-          IF ( .NOT. rans_tke_e ) THEN
+          IF ( .NOT. rans_tke_e )  THEN
 !
 !--          Transfer initial profiles to the arrays of the 3D model
@@ -1173,6 +1214,6 @@
           ELSE
 !
-!--          In case of TKE-e closure in RANS mode, do not use e, diss, and km
-!--          profiles from 1D model. Instead, initialize with constant profiles
+!--          In case of TKE-e closure in RANS mode, do not use e, diss, and km profiles from 1D
+!--          model. Instead, initialize with constant profiles
              IF ( constant_diffusion )  THEN
                 km = km_constant
@@ -1183,6 +1224,5 @@
                    DO  j = nysg, nyng
                       DO  k = nzb+1, nzt
-                         km(k,j,i) = c_0 * SQRT( e_init ) * MIN( delta(k,j,i), &
-                                                                 ml_blackadar(k) )
+                         km(k,j,i) = c_0 * SQRT( e_init ) * MIN( delta(k,j,i), ml_blackadar(k) )
                       ENDDO
                    ENDDO
@@ -1194,8 +1234,7 @@
              ELSE
                 IF ( .NOT. ocean_mode )  THEN
-                   kh   = 0.01_wp   ! there must exist an initial diffusion, because
-                   km   = 0.01_wp   ! otherwise no TKE would be produced by the
-                                    ! production terms, as long as not yet
-                                    ! e = (u*/cm)**2 at k=nzb+1
+                   kh   = 0.01_wp   ! There must exist an initial diffusion, because otherwise no
+                   km   = 0.01_wp   ! TKE would be produced by the production terms, as long as not
+                                    ! yet e = (u*/cm)**2 at k=nzb+1
                 ELSE
                    kh   = 0.00001_wp
@@ -1217,5 +1256,5 @@
           ENDIF
 
-       ELSEIF ( INDEX( initializing_actions, 'set_constant_profiles' ) /= 0 .OR. &
+       ELSEIF ( INDEX( initializing_actions, 'set_constant_profiles' ) /= 0 .OR.                   &
                 INDEX( initializing_actions, 'inifor' ) /= 0 )  THEN
 
@@ -1238,7 +1277,6 @@
           ELSE
              IF ( .NOT. ocean_mode )  THEN
-                kh   = 0.01_wp   ! there must exist an initial diffusion, because
-                km   = 0.01_wp   ! otherwise no TKE would be produced by the
-                                 ! production terms, as long as not yet
+                kh   = 0.01_wp   ! There must exist an initial diffusion, because otherwise no TKE
+                km   = 0.01_wp   ! would be produced by the production terms, as long as not yet
                                  ! e = (u*/cm)**2 at k=nzb+1
              ELSE
@@ -1277,14 +1315,11 @@
        ENDIF
 
-    ELSEIF ( TRIM( initializing_actions ) == 'read_restart_data'  .OR.         &
-             TRIM( initializing_actions ) == 'cyclic_fill' )                   &
-    THEN
-
-!
-!--    In case of complex terrain and cyclic fill method as initialization,
-!--    shift initial data in the vertical direction for each point in the
-!--    x-y-plane depending on local surface height
-       IF ( complex_terrain  .AND.                                             &
-            TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
+    ELSEIF ( TRIM( initializing_actions ) == 'read_restart_data'  .OR.                             &
+             TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
+
+!
+!--    In case of complex terrain and cyclic fill method as initialization, shift initial data in
+!--    the vertical direction for each point in the x-y-plane depending on local surface height
+       IF ( complex_terrain  .AND.  TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
           DO  i = nxlg, nxrg
              DO  j = nysg, nyng
@@ -1311,13 +1346,11 @@
 !
 !--    Initialization of the turbulence recycling method
-       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.               &
-            turbulent_inflow )  THEN
+       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.  turbulent_inflow )  THEN
           mean_inflow_profiles(:,5) = hom_sum(:,8,0)   ! e
 !
-!--       In case of complex terrain, determine vertical displacement at inflow
-!--       boundary and adjust mean inflow profiles
+!--       In case of complex terrain, determine vertical displacement at inflow boundary and adjust
+!--       mean inflow profiles
           IF ( complex_terrain )  THEN
-             IF ( nxlg <= 0 .AND. nxrg >= 0 .AND.  &
-                  nysg <= 0 .AND. nyng >= 0        )  THEN
+             IF ( nxlg <= 0  .AND.  nxrg >= 0  .AND.  nysg <= 0  .AND.  nyng >= 0 )  THEN
                 nz_s_shift_l = topo_top_ind(0,0,0)
              ELSE
@@ -1325,15 +1358,12 @@
              ENDIF
 #if defined( __parallel )
-             CALL MPI_ALLREDUCE(nz_s_shift_l, nz_s_shift, 1, MPI_INTEGER,      &
-                                MPI_MAX, comm2d, ierr)
+             CALL MPI_ALLREDUCE(nz_s_shift_l, nz_s_shift, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr)
 #else
              nz_s_shift = nz_s_shift_l
 #endif
-             mean_inflow_profiles(nz_s_shift:nzt+1,5) =  &
-                hom_sum(0:nzt+1-nz_s_shift,8,0)  ! e
+             mean_inflow_profiles(nz_s_shift:nzt+1,5) = hom_sum(0:nzt+1-nz_s_shift,8,0)  ! e
           ENDIF
 !
-!--       Use these mean profiles at the inflow (provided that Dirichlet
-!--       conditions are used)
+!--       Use these mean profiles at the inflow (provided that Dirichlet conditions are used)
           IF ( bc_dirichlet_l )  THEN
              DO  j = nysg, nyng
@@ -1346,15 +1376,12 @@
 !
 !--    Inside buildings set TKE back to zero
-       IF ( TRIM( initializing_actions ) == 'cyclic_fill' .AND.                &
-            topography /= 'flat' )  THEN
+       IF ( TRIM( initializing_actions ) == 'cyclic_fill' .AND. topography /= 'flat' )  THEN
 !
 !--       Inside buildings set TKE back to zero.
-!--       Other scalars (km, kh,...) are ignored at present,
-!--       maybe revise later.
+!--       Other scalars (km, kh,...) are ignored at present, maybe revise later.
           DO  i = nxlg, nxrg
              DO  j = nysg, nyng
                 DO  k = nzb, nzt
-                   e(k,j,i)     = MERGE( e(k,j,i), 0.0_wp,                     &
-                                         BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                   e(k,j,i) = MERGE( e(k,j,i), 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
                 ENDDO
              ENDDO
@@ -1365,6 +1392,6 @@
                 DO  j = nysg, nyng
                    DO  k = nzb, nzt
-                      diss(k,j,i)    = MERGE( diss(k,j,i), 0.0_wp,             &
-                                         BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                      diss(k,j,i) = MERGE( diss(k,j,i), 0.0_wp,                                    &
+                                    BTEST( wall_flags_total_0(k,j,i), 0 ) )
                    ENDDO
                 ENDDO
@@ -1373,11 +1400,9 @@
        ENDIF
 !
-!--    Initialize new time levels (only done in order to set boundary values
-!--    including ghost points)
+!--    Initialize new time levels (only done in order to set boundary values including ghost points)
        e_p = e
 !
-!--    Allthough tendency arrays are set in prognostic_equations, they have
-!--    to be predefined here because there they are used (but multiplied with 0)
-!--    before they are set.
+!--    Although tendency arrays are set in prognostic_equations, they have to be predefined here
+!--    because there they are used (but multiplied with 0) before they are set.
        te_m = 0.0_wp
 
@@ -1392,28 +1417,48 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Pre-computation of grid-dependent and near-wall mixing length.
-!> @todo consider walls in horizontal direction at a distance further than a
-!>       single grid point (RANS mode)
-!------------------------------------------------------------------------------!
+!> @todo consider walls in horizontal direction at a distance further than a single grid point
+!> (RANS mode)
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_init_mixing_length
 
-    USE arrays_3d,                                                             &
-        ONLY:  dzw, ug, vg, zu, zw
-
-    USE control_parameters,                                                    &
-        ONLY:  f, message_string, wall_adjustment
-
-    USE exchange_horiz_mod,                                                    &
-        ONLY:  exchange_horiz, exchange_horiz_int
-
-    USE grid_variables,                                                        &
-        ONLY:  dx, dy
-
-    USE indices,                                                               &
-        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb,  &
-               nzt, wall_flags_total_0
+    USE arrays_3d,                                                                                 &
+        ONLY:  dzw,                                                                                &
+               ug,                                                                                 &
+               vg,                                                                                 &
+               zu,                                                                                 &
+               zw
+
+    USE control_parameters,                                                                        &
+        ONLY:  f,                                                                                  &
+               message_string,                                                                     &
+               wall_adjustment
+
+    USE exchange_horiz_mod,                                                                        &
+        ONLY:  exchange_horiz,                                                                     &
+               exchange_horiz_int
+
+    USE grid_variables,                                                                            &
+        ONLY:  dx,                                                                                 &
+               dy
+
+    USE indices,                                                                                   &
+        ONLY:  nbgp,                                                                               &
+               nx,                                                                                 &
+               nxl,                                                                                &
+               nxlg,                                                                               &
+               nxr,                                                                                &
+               nxrg,                                                                               &
+               ny,                                                                                 &
+               nyn,                                                                                &
+               nyng,                                                                               &
+               nys,                                                                                &
+               nysg,                                                                               &
+               nzb,                                                                                &
+               nzt,                                                                                &
+               wall_flags_total_0
 
     USE kinds
@@ -1422,37 +1467,37 @@
     IMPLICIT NONE
 
-    INTEGER(iwp) :: dist_dx     !< found distance devided by dx
-    INTEGER(iwp) :: i           !< index variable along x
-    INTEGER(iwp) :: ii          !< index variable along x
-    INTEGER(iwp) :: j           !< index variable along y
-    INTEGER(iwp) :: k           !< index variable along z
-    INTEGER(iwp) :: k_max_topo  !< index of maximum topography height
-    INTEGER(iwp) :: kk          !< index variable along z
-    INTEGER(iwp) :: rad_i       !< search radius in grid points along x
-    INTEGER(iwp) :: rad_i_l     !< possible search radius to the left
-    INTEGER(iwp) :: rad_i_r     !< possible search radius to the right
-    INTEGER(iwp) :: rad_j       !< search radius in grid points along y
-    INTEGER(iwp) :: rad_j_n     !< possible search radius to north
-    INTEGER(iwp) :: rad_j_s     !< possible search radius to south
-    INTEGER(iwp) :: rad_k       !< search radius in grid points along z
-    INTEGER(iwp) :: rad_k_b     !< search radius in grid points along negative z
-    INTEGER(iwp) :: rad_k_t     !< search radius in grid points along positive z
-
-    INTEGER(KIND=1), DIMENSION(:,:), ALLOCATABLE :: vic_yz !< contains a quarter of a single yz-slice of vicinity
-
-    INTEGER(KIND=1), DIMENSION(:,:,:), ALLOCATABLE :: vicinity !< contains topography information of the vicinity of (i/j/k)
-
-    REAL(wp) :: distance_up            !< distance of grid box center to its boundary in upper direction
-    REAL(wp) :: distance_down          !< distance of grid box center to its boundary in lower direction
-    REAL(wp) :: distance_ns            !< distance of grid box center to its boundary in y direction
-    REAL(wp) :: distance_lr            !< distance of grid box center to its boundary in x direction
-    REAL(wp) :: distance_edge_yz_down  !< distance of grid box center to its boundary along yz diagonal (down)
-    REAL(wp) :: distance_edge_yz_up    !< distance of grid box center to its boundary along yz diagonal (up)
-    REAL(wp) :: distance_edge_xz_down  !< distance of grid box center to its boundary along xz diagonal
-    REAL(wp) :: distance_edge_xz_up    !< distance of grid box center to its boundary along xz diagonal (up)
-    REAL(wp) :: distance_edge_xy       !< distance of grid box center to its boundary along xy diagonal
-    REAL(wp) :: distance_corners_down  !< distance of grid box center to its upper corners
-    REAL(wp) :: distance_corners_up    !< distance of grid box center to its lower corners
-    REAL(wp) :: radius                 !< search radius in meter
+    INTEGER(iwp) ::  dist_dx     !< found distance devided by dx
+    INTEGER(iwp) ::  i           !< index variable along x
+    INTEGER(iwp) ::  ii          !< index variable along x
+    INTEGER(iwp) ::  j           !< index variable along y
+    INTEGER(iwp) ::  k           !< index variable along z
+    INTEGER(iwp) ::  k_max_topo  !< index of maximum topography height
+    INTEGER(iwp) ::  kk          !< index variable along z
+    INTEGER(iwp) ::  rad_i       !< search radius in grid points along x
+    INTEGER(iwp) ::  rad_i_l     !< possible search radius to the left
+    INTEGER(iwp) ::  rad_i_r     !< possible search radius to the right
+    INTEGER(iwp) ::  rad_j       !< search radius in grid points along y
+    INTEGER(iwp) ::  rad_j_n     !< possible search radius to north
+    INTEGER(iwp) ::  rad_j_s     !< possible search radius to south
+    INTEGER(iwp) ::  rad_k       !< search radius in grid points along z
+    INTEGER(iwp) ::  rad_k_b     !< search radius in grid points along negative z
+    INTEGER(iwp) ::  rad_k_t     !< search radius in grid points along positive z
+
+    INTEGER(KIND=1), DIMENSION(:,:), ALLOCATABLE ::  vic_yz  !< contains a quarter of a single yz-slice of vicinity
+
+    INTEGER(KIND=1), DIMENSION(:,:,:), ALLOCATABLE ::  vicinity  !< contains topography information of the vicinity of (i/j/k)
+
+    REAL(wp) ::  distance_up            !< distance of grid box center to its boundary in upper direction
+    REAL(wp) ::  distance_down          !< distance of grid box center to its boundary in lower direction
+    REAL(wp) ::  distance_ns            !< distance of grid box center to its boundary in y direction
+    REAL(wp) ::  distance_lr            !< distance of grid box center to its boundary in x direction
+    REAL(wp) ::  distance_edge_yz_down  !< distance of grid box center to its boundary along yz diagonal (down)
+    REAL(wp) ::  distance_edge_yz_up    !< distance of grid box center to its boundary along yz diagonal (up)
+    REAL(wp) ::  distance_edge_xz_down  !< distance of grid box center to its boundary along xz diagonal
+    REAL(wp) ::  distance_edge_xz_up    !< distance of grid box center to its boundary along xz diagonal (up)
+    REAL(wp) ::  distance_edge_xy       !< distance of grid box center to its boundary along xy diagonal
+    REAL(wp) ::  distance_corners_down  !< distance of grid box center to its upper corners
+    REAL(wp) ::  distance_corners_up    !< distance of grid box center to its lower corners
+    REAL(wp) ::  radius                 !< search radius in meter
 
     REAL(wp), DIMENSION(nzb:nzt+1) ::  gridsize_geometric_mean  !< geometric mean of grid sizes dx, dy, dz
@@ -1476,9 +1521,8 @@
        gridsize_geometric_mean(nzt+1) = gridsize_geometric_mean(nzt)
 
-       IF ( ANY( gridsize_geometric_mean > 1.5_wp * dx * wall_adjustment_factor ) .OR. &
+       IF ( ANY( gridsize_geometric_mean > 1.5_wp * dx * wall_adjustment_factor )  .OR.            &
             ANY( gridsize_geometric_mean > 1.5_wp * dy * wall_adjustment_factor ) )  THEN
-            WRITE( message_string, * ) 'grid anisotropy exceeds threshold',    &
-                                      ' &starting from height level k = ', k, &
-                                      '.'
+            WRITE( message_string, * ) 'grid anisotropy exceeds threshold',                        &
+                                       ' &starting from height level k = ', k, '.'
            CALL message( 'init_grid', 'PA0202', 0, 1, 0, 6, 0 )
        ENDIF
@@ -1491,6 +1535,6 @@
 
 !
-!--    If Dai et al. (2020) closure is used, the distance to the wall (distance to nearest upward facing surface)
-!--    must be stored
+!--    If Dai et al. (2020) closure is used, the distance to the wall (distance to nearest upward
+!--    facing surface) must be stored
        IF ( les_dai )  THEN
           DO  i = nxl, nxr
@@ -1505,6 +1549,6 @@
        IF ( wall_adjustment )  THEN
 !
-!--       In case of topography, adjust mixing length if there is any wall at
-!--       the surrounding grid boxes:
+!--       In case of topography, adjust mixing length if there is any wall at the surrounding grid
+!--       boxes:
           !> @todo check if this is correct also for the ocean case
           DO  i = nxl, nxr
@@ -1515,6 +1559,6 @@
                    IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )  THEN
 !
-!--                   First, check if grid points directly next to current grid point
-!--                   are surface grid points
+!--                   First, check if grid points directly next to current grid point are surface
+!--                   grid points
 !--                   Check along...
 !--                   ...vertical direction, down
@@ -1533,5 +1577,5 @@
 !
 !--                   ...y-direction (north/south)
-                      IF ( .NOT. BTEST( wall_flags_total_0(k,j-1,i), 0 )  .OR. &
+                      IF ( .NOT. BTEST( wall_flags_total_0(k,j-1,i), 0 )  .OR.                     &
                            .NOT. BTEST( wall_flags_total_0(k,j+1,i), 0 ) )  THEN
                          distance_ns = 0.5_wp * dy
@@ -1541,5 +1585,5 @@
 !
 !--                   ...x-direction (left/right)
-                      IF ( .NOT. BTEST( wall_flags_total_0(k,j,i-1), 0 )  .OR. &
+                      IF ( .NOT. BTEST( wall_flags_total_0(k,j,i-1), 0 )  .OR.                     &
                            .NOT. BTEST( wall_flags_total_0(k,j,i+1), 0 ) )  THEN
                          distance_lr = 0.5_wp * dx
@@ -1550,5 +1594,5 @@
 !--                   Now, check the edges along...
 !--                   ...yz-direction (vertical edges, down)
-                      IF ( .NOT. BTEST( wall_flags_total_0(k-1,j-1,i), 0 )  .OR.  &
+                      IF ( .NOT. BTEST( wall_flags_total_0(k-1,j-1,i), 0 )  .OR.                   &
                            .NOT. BTEST( wall_flags_total_0(k-1,j+1,i), 0 )  )  THEN
                          distance_edge_yz_down = SQRT( 0.25_wp * dy**2 + ( zu(k) - zw(k-1) )**2 )
@@ -1558,5 +1602,5 @@
 !
 !--                   ...yz-direction (vertical edges, up)
-                      IF ( .NOT. BTEST( wall_flags_total_0(k+1,j-1,i), 0 )  .OR.  &
+                      IF ( .NOT. BTEST( wall_flags_total_0(k+1,j-1,i), 0 )  .OR.                   &
                            .NOT. BTEST( wall_flags_total_0(k+1,j+1,i), 0 )  )  THEN
                          distance_edge_yz_up = SQRT( 0.25_wp * dy**2 + ( zw(k) - zu(k) )**2 )
@@ -1566,5 +1610,5 @@
 !
 !--                   ...xz-direction (vertical edges, down)
-                      IF ( .NOT. BTEST( wall_flags_total_0(k-1,j,i-1), 0 )  .OR.  &
+                      IF ( .NOT. BTEST( wall_flags_total_0(k-1,j,i-1), 0 )  .OR.                   &
                            .NOT. BTEST( wall_flags_total_0(k-1,j,i+1), 0 )  )  THEN
                          distance_edge_xz_down = SQRT( 0.25_wp * dx**2 + ( zu(k) - zw(k-1) )**2 )
@@ -1574,5 +1618,5 @@
 !
 !--                   ...xz-direction (vertical edges, up)
-                      IF ( .NOT. BTEST( wall_flags_total_0(k+1,j,i-1), 0 )  .OR.  &
+                      IF ( .NOT. BTEST( wall_flags_total_0(k+1,j,i-1), 0 )  .OR.                   &
                            .NOT. BTEST( wall_flags_total_0(k+1,j,i+1), 0 )  )  THEN
                          distance_edge_xz_up = SQRT( 0.25_wp * dx**2 + ( zw(k) - zu(k) )**2 )
@@ -1582,7 +1626,7 @@
 !
 !--                   ...xy-direction (horizontal edges)
-                      IF ( .NOT. BTEST( wall_flags_total_0(k,j-1,i-1), 0 )  .OR. &
-                           .NOT. BTEST( wall_flags_total_0(k,j+1,i-1), 0 )  .OR. &
-                           .NOT. BTEST( wall_flags_total_0(k,j-1,i+1), 0 )  .OR. &
+                      IF ( .NOT. BTEST( wall_flags_total_0(k,j-1,i-1), 0 )  .OR.                   &
+                           .NOT. BTEST( wall_flags_total_0(k,j+1,i-1), 0 )  .OR.                   &
+                           .NOT. BTEST( wall_flags_total_0(k,j-1,i+1), 0 )  .OR.                   &
                            .NOT. BTEST( wall_flags_total_0(k,j+1,i+1), 0 ) )  THEN
                          distance_edge_xy = SQRT( 0.25_wp * ( dx**2 + dy**2 ) )
@@ -1593,9 +1637,9 @@
 !--                   Now, check the corners...
 !--                   ...lower four corners
-                      IF ( .NOT. BTEST( wall_flags_total_0(k-1,j-1,i-1), 0 )  .OR. &
-                           .NOT. BTEST( wall_flags_total_0(k-1,j+1,i-1), 0 )  .OR. &
-                           .NOT. BTEST( wall_flags_total_0(k-1,j-1,i+1), 0 )  .OR. &
+                      IF ( .NOT. BTEST( wall_flags_total_0(k-1,j-1,i-1), 0 )  .OR.                 &
+                           .NOT. BTEST( wall_flags_total_0(k-1,j+1,i-1), 0 )  .OR.                 &
+                           .NOT. BTEST( wall_flags_total_0(k-1,j-1,i+1), 0 )  .OR.                 &
                            .NOT. BTEST( wall_flags_total_0(k-1,j+1,i+1), 0 ) )  THEN
-                         distance_corners_down = SQRT( 0.25_wp * ( dx**2 + dy**2 ) &
+                         distance_corners_down = SQRT( 0.25_wp * ( dx**2 + dy**2 )                 &
                                                        + ( zu(k) - zw(k-1) )**2 )
                       ELSE
@@ -1604,9 +1648,9 @@
 !
 !--                   ...upper four corners
-                      IF ( .NOT. BTEST( wall_flags_total_0(k+1,j-1,i-1), 0 )  .OR. &
-                           .NOT. BTEST( wall_flags_total_0(k+1,j+1,i-1), 0 )  .OR. &
-                           .NOT. BTEST( wall_flags_total_0(k+1,j-1,i+1), 0 )  .OR. &
+                      IF ( .NOT. BTEST( wall_flags_total_0(k+1,j-1,i-1), 0 )  .OR.                 &
+                           .NOT. BTEST( wall_flags_total_0(k+1,j+1,i-1), 0 )  .OR.                 &
+                           .NOT. BTEST( wall_flags_total_0(k+1,j-1,i+1), 0 )  .OR.                 &
                            .NOT. BTEST( wall_flags_total_0(k+1,j+1,i+1), 0 ) )  THEN
-                         distance_corners_up = SQRT( 0.25_wp * ( dx**2 + dy**2 )   &
+                         distance_corners_up = SQRT( 0.25_wp * ( dx**2 + dy**2 )                   &
                                                      + ( zw(k) - zu(k) )**2 )
                       ELSE
@@ -1615,16 +1659,15 @@
 
 !
-!--                   Calculate the minimum distance from the wall and store it
-!--                   temporarily in the array delta
-                      delta(k,j,i) = MIN(                                      &
-                         distance_up, distance_down, distance_ns, distance_lr, &
-                         distance_edge_yz_down, distance_edge_yz_up,           &
-                         distance_edge_xz_down, distance_edge_xz_up,           &
-                         distance_edge_xy,                                     &
-                         distance_corners_down, distance_corners_up )
-
-!
-!--                   If Dai et al. (2020) closure is used, the distance to the wall
-!--                   must be permanently stored
+!--                   Calculate the minimum distance from the wall and store it temporarily in the
+!--                   array delta
+                      delta(k,j,i) = MIN( distance_up, distance_down, distance_ns, distance_lr,    &
+                                          distance_edge_yz_down, distance_edge_yz_up,              &
+                                          distance_edge_xz_down, distance_edge_xz_up,              &
+                                          distance_edge_xy, distance_corners_down,                 &
+                                          distance_corners_up )
+
+!
+!--                   If Dai et al. (2020) closure is used, the distance to the wall must be
+!--                   permanently stored
                       IF ( les_dai  .AND.  delta(k,j,i) /= 9999999.9_wp )  THEN
                          distance_to_wall(k,j,i) = delta(k,j,i)
@@ -1635,11 +1678,11 @@
                       delta(k,j,i) = wall_adjustment_factor * delta(k,j,i)
 
-                  ENDIF  !if grid point belongs to atmosphere
-
-
-
-!
-!--               The grid size (delta) is defined as the the minimum of the distance to
-!--               the nearest wall * 1.8 and the geometric mean grid size.
+                  ENDIF  ! If grid point belongs to atmosphere
+
+
+
+!
+!--               The grid size (delta) is defined as the the minimum of the distance to the nearest
+!--               wall * 1.8 and the geometric mean grid size.
                   delta(k,j,i) = MIN( delta(k,j,i), gridsize_geometric_mean(k) )
 
@@ -1659,6 +1702,5 @@
 !--    Calculate mixing length according to Blackadar (1962)
        IF ( f /= 0.0_wp )  THEN
-          length_scale_max = 2.7E-4_wp * SQRT( ug(nzt+1)**2 + vg(nzt+1)**2 )   &
-                           / ABS( f ) + 1.0E-10_wp
+          length_scale_max = 2.7E-4_wp * SQRT( ug(nzt+1)**2 + vg(nzt+1)**2 ) / ABS( f ) + 1.0E-10_wp
        ELSE
           length_scale_max = 30.0_wp
@@ -1677,6 +1719,5 @@
           DO  j = nysg, nyng
              DO  k = nzb+1, nzt-1
-                IF ( .NOT. BTEST( wall_flags_total_0(k,j,i), 0 ) .AND.  &
-                     k > k_max_topo )  &
+                IF ( .NOT. BTEST( wall_flags_total_0(k,j,i), 0 )  .AND.  k > k_max_topo )          &
                    k_max_topo = k
              ENDDO
@@ -1687,9 +1728,8 @@
        delta(nzt+1,:,:) = ml_blackadar(nzt+1)
 !
-!--    Limit mixing length to either nearest wall or Blackadar mixing length.
-!--    For that, analyze each grid point (i/j/k) ("analysed grid point") and
-!--    search within its vicinity for the shortest distance to a wall by cal-
-!--    culating the distance between the analysed grid point and the "viewed
-!--    grid point" if it contains a wall (belongs to topography).
+!--    Limit mixing length to either nearest wall or Blackadar mixing length. For that, analyze each
+!--    grid point (i/j/k) ("analysed grid point") and search within its vicinity for the shortest
+!--    distance to a wall by calculating the distance between the analysed grid point and the
+!--    "viewed grid point" if it contains a wall (belongs to topography).
        DO  k = nzb+1, nzt
 
@@ -1720,7 +1760,7 @@
           rad_k = MAX( rad_k_b, rad_k_t )
 !
-!--       When analysed grid point lies above maximum topography, set search
-!--       radius to 0 if the distance between the analysed grid point and max
-!--       topography height is larger than the maximum search radius
+!--       When analysed grid point lies above maximum topography, set search radius to 0 if the
+!--       distance between the analysed grid point and max topography height is larger than the
+!--       maximum search radius
           IF ( zu(k-rad_k_b) > zu(k_max_topo) )  rad_k_b = 0
 !
@@ -1729,8 +1769,7 @@
 
              !> @note shape of vicinity is larger in z direction
-             !>   Shape of vicinity is two grid points larger than actual search
-             !>   radius in vertical direction. The first and last grid point is
-             !>   always set to 1 to asure correct detection of topography. See
-             !>   function "shortest_distance" for details.
+             !>   Shape of vicinity is two grid points larger than actual search radius in vertical
+             !>   direction. The first and last grid point is always set to 1 to asure correct
+             !>   detection of topography. See function "shortest_distance" for details.
              !>   2018-03-16, gronemeier
              ALLOCATE( vicinity(-rad_k-1:rad_k+1,-rad_j:rad_j,-rad_i:rad_i) )
@@ -1748,14 +1787,11 @@
                       vicinity(-rad_k:rad_k,:,:) = 0
 !
-!--                   Copy area surrounding analysed grid point into vicinity.
-!--                   First, limit size of data copied to vicinity by the domain
-!--                   border
+!--                   Copy area surrounding analysed grid point into vicinity. First, limit size of
+!--                   data copied to vicinity by the domain border
                       !> @note limit copied area to 1 grid point in hor. dir.
-                      !>   Ignore walls in horizontal direction which are
-                      !>   further away than a single grid point. This allows to
-                      !>   only search within local subdomain without the need
-                      !>   of global topography information.
-                      !>   The error made by this assumption are acceptable at
-                      !>   the moment.
+                      !>   Ignore walls in horizontal direction which are further away than a single
+                      !>   grid point. This allows to only search within local subdomain without the
+                      !>   need of global topography information. The error made by this assumption
+                      !>   are acceptable at the moment.
                       !>   2018-10-01, gronemeier
                       rad_i_l = MIN( 1, rad_i, i )
@@ -1765,16 +1801,13 @@
                       rad_j_n = MIN( 1, rad_j, ny-j )
 
-                      CALL copy_into_vicinity( k, j, i,           &
-                                               -rad_k_b, rad_k_t, &
-                                               -rad_j_s, rad_j_n, &
+                      CALL copy_into_vicinity( k, j, i, -rad_k_b, rad_k_t, -rad_j_s, rad_j_n,      &
                                                -rad_i_l, rad_i_r  )
-                      !> @note in case of cyclic boundaries, those parts of the
-                      !>   topography which lies beyond the domain borders but
-                      !>   still within the search radius still needs to be
-                      !>   copied into 'vicinity'. As the effective search
-                      !>   radius is limited to 1 at the moment, no further
-                      !>   copying is needed. Old implementation (prior to
-                      !>   2018-10-01) had this covered but used a global array.
-                      !>   2018-10-01, gronemeier
+                      !> @note in case of cyclic boundaries, those parts of the topography which
+                      !> lies beyond the domain borders but still within the search radius still
+                      !> needs to be copied into 'vicinity'. As the effective search radius is
+                      !> limited to 1 at the moment, no further copying is needed. Old
+                      !> implementation (prior to 2018-10-01) had this covered but used a global
+                      !> array.
+                      !> 2018-10-01, gronemeier
 
 !
@@ -1786,20 +1819,18 @@
                          DO  ii = 0, dist_dx
 !
-!--                         Search along vertical direction only if below
-!--                         maximum topography
-                            IF ( rad_k_t > 0 ) THEN
+!--                         Search along vertical direction only if below maximum topography
+                            IF ( rad_k_t > 0 )  THEN
 !
 !--                            Search for walls within octant (+++)
                                vic_yz = vicinity(0:rad_k+1,0:rad_j,ii)
-                               delta(k,j,i) = MIN( delta(k,j,i),             &
-                                       shortest_distance( vic_yz, .TRUE., ii ) )
+                               delta(k,j,i) = MIN( delta(k,j,i),                                   &
+                                                   shortest_distance( vic_yz, .TRUE., ii ) )
 !
 !--                            Search for walls within octant (+-+)
-!--                            Switch order of array so that the analysed grid
-!--                            point is always located at (0/0) (required by
-!--                            shortest_distance").
+!--                            Switch order of array so that the analysed grid point is always
+!--                            located at (0/0) (required by shortest_distance").
                                vic_yz = vicinity(0:rad_k+1,0:-rad_j:-1,ii)
-                               delta(k,j,i) = MIN( delta(k,j,i),             &
-                                       shortest_distance( vic_yz, .TRUE., ii ) )
+                               delta(k,j,i) = MIN( delta(k,j,i),                                   &
+                                                   shortest_distance( vic_yz, .TRUE., ii ) )
 
                             ENDIF
@@ -1807,11 +1838,11 @@
 !--                         Search for walls within octant (+--)
                             vic_yz = vicinity(0:-rad_k-1:-1,0:-rad_j:-1,ii)
-                            delta(k,j,i) = MIN( delta(k,j,i),                &
-                                      shortest_distance( vic_yz, .FALSE., ii ) )
+                            delta(k,j,i) = MIN( delta(k,j,i),                                      &
+                                                shortest_distance( vic_yz, .FALSE., ii ) )
 !
 !--                         Search for walls within octant (++-)
                             vic_yz = vicinity(0:-rad_k-1:-1,0:rad_j,ii)
-                            delta(k,j,i) = MIN( delta(k,j,i),                &
-                                      shortest_distance( vic_yz, .FALSE., ii ) )
+                            delta(k,j,i) = MIN( delta(k,j,i),                                      &
+                                                shortest_distance( vic_yz, .FALSE., ii ) )
 !
 !--                         Reduce search along x by already found distance
@@ -1823,20 +1854,18 @@
                          DO  ii = 0, -dist_dx, -1
 !
-!--                         Search along vertical direction only if below
-!--                         maximum topography
-                            IF ( rad_k_t > 0 ) THEN
+!--                         Search along vertical direction only if below maximum topography
+                            IF ( rad_k_t > 0 )  THEN
 !
 !--                            Search for walls within octant (-++)
                                vic_yz = vicinity(0:rad_k+1,0:rad_j,ii)
-                               delta(k,j,i) = MIN( delta(k,j,i),             &
-                                      shortest_distance( vic_yz, .TRUE., -ii ) )
+                               delta(k,j,i) = MIN( delta(k,j,i),                                   &
+                                                   shortest_distance( vic_yz, .TRUE., -ii ) )
 !
 !--                            Search for walls within octant (--+)
-!--                            Switch order of array so that the analysed grid
-!--                            point is always located at (0/0) (required by
-!--                            shortest_distance").
+!--                            Switch order of array so that the analysed grid point is always
+!--                            located at (0/0) (required by shortest_distance").
                                vic_yz = vicinity(0:rad_k+1,0:-rad_j:-1,ii)
-                               delta(k,j,i) = MIN( delta(k,j,i),             &
-                                      shortest_distance( vic_yz, .TRUE., -ii ) )
+                               delta(k,j,i) = MIN( delta(k,j,i),                                   &
+                                                   shortest_distance( vic_yz, .TRUE., -ii ) )
 
                             ENDIF
@@ -1844,11 +1873,11 @@
 !--                         Search for walls within octant (---)
                             vic_yz = vicinity(0:-rad_k-1:-1,0:-rad_j:-1,ii)
-                            delta(k,j,i) = MIN( delta(k,j,i),                &
-                                     shortest_distance( vic_yz, .FALSE., -ii ) )
+                            delta(k,j,i) = MIN( delta(k,j,i),                                      &
+                                                shortest_distance( vic_yz, .FALSE., -ii ) )
 !
 !--                         Search for walls within octant (-+-)
                             vic_yz = vicinity(0:-rad_k-1:-1,0:rad_j,ii)
-                            delta(k,j,i) = MIN( delta(k,j,i),                &
-                                     shortest_distance( vic_yz, .FALSE., -ii ) )
+                            delta(k,j,i) = MIN( delta(k,j,i),                                      &
+                                                shortest_distance( vic_yz, .FALSE., -ii ) )
 !
 !--                         Reduce search along x by already found distance
@@ -1871,5 +1900,5 @@
              DEALLOCATE( vic_yz )
 
-          ENDIF  !check vertical size of vicinity
+          ENDIF  !Check vertical size of vicinity
 
        ENDDO  !k loop
@@ -1892,32 +1921,31 @@
 
     CONTAINS
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Calculate the shortest distance between position (i/j/k)=(0/0/0) and
-!> (pos_i/jj/kk), where (jj/kk) is the position of the maximum of 'array'
-!> closest to the origin (0/0) of 'array'.
-!------------------------------------------------------------------------------!
+!> Calculate the shortest distance between position (i/j/k)=(0/0/0) and (pos_i/jj/kk), where (jj/kk)
+!> is the position of the maximum of 'array' closest to the origin (0/0) of 'array'.
+!--------------------------------------------------------------------------------------------------!
     REAL(wp) FUNCTION shortest_distance( array, orientation, pos_i )
 
        IMPLICIT NONE
 
-       LOGICAL, INTENT(IN) :: orientation    !< flag if array represents an array oriented upwards (true) or downwards (false)
-
-       INTEGER(iwp), INTENT(IN) :: pos_i     !< x position of the yz-plane 'array'
-
-       INTEGER(iwp) :: a                     !< loop index
-       INTEGER(iwp) :: b                     !< loop index
-       INTEGER(iwp) :: jj                    !< loop index
-
-       INTEGER(KIND=1) :: maximum            !< maximum of array along z dimension
-
-       INTEGER(iwp), DIMENSION(0:rad_j) :: loc_k !< location of closest wall along vertical dimension
-
-       INTEGER(KIND=1), DIMENSION(0:rad_k+1,0:rad_j), INTENT(IN) :: array !< array containing a yz-plane at position pos_i
-
-!
-!--    Get coordinate of first maximum along vertical dimension
-!--    at each y position of array (similar to function maxloc but more stable).
+       INTEGER(iwp), INTENT(IN) ::  pos_i  !< x position of the yz-plane 'array'
+
+       INTEGER(iwp) ::  a   !< loop index
+       INTEGER(iwp) ::  b   !< loop index
+       INTEGER(iwp) ::  jj  !< loop index
+
+       INTEGER(KIND=1) ::  maximum  !< maximum of array along z dimension
+
+       INTEGER(iwp), DIMENSION(0:rad_j) ::  loc_k  !< location of closest wall along vertical dimension
+
+       INTEGER(KIND=1), DIMENSION(0:rad_k+1,0:rad_j), INTENT(IN) ::  array  !< array containing a yz-plane at position pos_i
+
+       LOGICAL, INTENT(IN) ::  orientation  !< flag if array represents an array oriented upwards (true) or downwards (false)
+
+!
+!--    Get coordinate of first maximum along vertical dimension at each y position of array
+!--    (similar to function maxloc but more stable).
        DO  a = 0, rad_j
           loc_k(a) = rad_k+1
@@ -1934,28 +1962,28 @@
        shortest_distance = radius
 !
-!--    Calculate distance between position (0/0/0) and
-!--    position (pos_i/jj/loc(jj)) and only save the shortest distance.
-       IF ( orientation ) THEN  !if array is oriented upwards
+!--    Calculate distance between position (0/0/0) and position (pos_i/jj/loc(jj)) and only save the
+!--    shortest distance.
+       IF ( orientation )  THEN  !if array is oriented upwards
           DO  jj = 0, rad_j
-             shortest_distance =                                               &
-                MIN( shortest_distance,                                        &
-                     SQRT( MAX(REAL(pos_i, KIND=wp)*dx-0.5_wp*dx, 0.0_wp)**2   &
-                         + MAX(REAL(jj, KIND=wp)*dy-0.5_wp*dy, 0.0_wp)**2      &
-                         + MAX(zw(loc_k(jj)+k-1)-zu(k), 0.0_wp)**2             &
-                         )                                                     &
-                   )
+             shortest_distance =                                                                   &
+               MIN( shortest_distance,                                                             &
+                    SQRT( MAX( REAL( pos_i, KIND = wp ) * dx - 0.5_wp * dx, 0.0_wp)**2             &
+                        + MAX( REAL( jj, KIND = wp ) * dy - 0.5_wp * dy, 0.0_wp)**2                &
+                        + MAX( zw(loc_k(jj)+k-1) - zu(k), 0.0_wp)**2                               &
+                        )                                                                          &
+                  )
           ENDDO
        ELSE  !if array is oriented downwards
           !> @note MAX within zw required to circumvent error at domain border
-          !>   At the domain border, if non-cyclic boundary is present, the
-          !>   index for zw could be -1, which will be errorneous (zw(-1) does
-          !>   not exist). The MAX function limits the index to be at least 0.
+          !>   At the domain border, if non-cyclic boundary is present, the index for zw could be
+          !>   -1, which will be errorneous (zw(-1) does not exist). The MAX function limits the
+          !>   index to be at least 0.
           DO  jj = 0, rad_j
-             shortest_distance =                                               &
-                MIN( shortest_distance,                                        &
-                     SQRT( MAX(REAL(pos_i, KIND=wp)*dx-0.5_wp*dx, 0.0_wp)**2   &
-                         + MAX(REAL(jj, KIND=wp)*dy-0.5_wp*dy, 0.0_wp)**2      &
-                         + MAX(zu(k)-zw(MAX(k-loc_k(jj),0_iwp)), 0.0_wp)**2    &
-                         )                                                     &
+             shortest_distance =                                                                   &
+                MIN( shortest_distance,                                                            &
+                     SQRT( MAX(REAL(pos_i, KIND=wp)*dx-0.5_wp*dx, 0.0_wp)**2                       &
+                         + MAX(REAL(jj, KIND=wp)*dy-0.5_wp*dy, 0.0_wp)**2                          &
+                         + MAX(zu(k)-zw(MAX(k-loc_k(jj),0_iwp)), 0.0_wp)**2                        &
+                         )                                                                         &
                    )
           ENDDO
@@ -1964,34 +1992,33 @@
     END FUNCTION
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Copy a subarray of size (kb:kt,js:jn,il:ir) centered around grid point
-!> (kp,jp,ip) containing the first bit of wall_flags_total_0 into the array
-!> 'vicinity'. Only copy first bit as this indicates the presence of topography.
-!------------------------------------------------------------------------------!
+!> Copy a subarray of size (kb:kt,js:jn,il:ir) centered around grid point (kp,jp,ip) containing the
+!> first bit of wall_flags_total_0 into the array 'vicinity'. Only copy first bit as this indicates
+!> the presence of topography.
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE copy_into_vicinity( kp, jp, ip, kb, kt, js, jn, il, ir )
 
        IMPLICIT NONE
 
-       INTEGER(iwp), INTENT(IN) :: il !< left loop boundary
-       INTEGER(iwp), INTENT(IN) :: ip !< center position in x-direction
-       INTEGER(iwp), INTENT(IN) :: ir !< right loop boundary
-       INTEGER(iwp), INTENT(IN) :: jn !< northern loop boundary
-       INTEGER(iwp), INTENT(IN) :: jp !< center position in y-direction
-       INTEGER(iwp), INTENT(IN) :: js !< southern loop boundary
-       INTEGER(iwp), INTENT(IN) :: kb !< bottom loop boundary
-       INTEGER(iwp), INTENT(IN) :: kp !< center position in z-direction
-       INTEGER(iwp), INTENT(IN) :: kt !< top loop boundary
-
-       INTEGER(iwp) :: i   !< loop index
-       INTEGER(iwp) :: j   !< loop index
-       INTEGER(iwp) :: k   !< loop index
+       INTEGER(iwp), INTENT(IN) ::  il  !< left loop boundary
+       INTEGER(iwp), INTENT(IN) ::  ip  !< center position in x-direction
+       INTEGER(iwp), INTENT(IN) ::  ir  !< right loop boundary
+       INTEGER(iwp), INTENT(IN) ::  jn  !< northern loop boundary
+       INTEGER(iwp), INTENT(IN) ::  jp  !< center position in y-direction
+       INTEGER(iwp), INTENT(IN) ::  js  !< southern loop boundary
+       INTEGER(iwp), INTENT(IN) ::  kb  !< bottom loop boundary
+       INTEGER(iwp), INTENT(IN) ::  kp  !< center position in z-direction
+       INTEGER(iwp), INTENT(IN) ::  kt  !< top loop boundary
+
+       INTEGER(iwp) ::  i  !< loop index
+       INTEGER(iwp) ::  j  !< loop index
+       INTEGER(iwp) ::  k  !< loop index
 
        DO  i = il, ir
           DO  j = js, jn
              DO  k = kb, kt
-                vicinity(k,j,i) = MERGE( 0, 1,               &
-                       BTEST( wall_flags_total_0(kp+k,jp+j,ip+i), 0 ) )
+                vicinity(k,j,i) = MERGE( 0, 1, BTEST( wall_flags_total_0(kp+k,jp+j,ip+i), 0 ) )
              ENDDO
           ENDDO
@@ -2003,39 +2030,37 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Initialize virtual velocities used later in production_e.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE production_e_init
 
-    USE arrays_3d,                                                             &
-        ONLY:  drho_air_zw, zu
-
-    USE control_parameters,                                                    &
+    USE arrays_3d,                                                                                 &
+        ONLY:  drho_air_zw,                                                                        &
+               zu
+
+    USE control_parameters,                                                                        &
         ONLY:  constant_flux_layer
 
-    USE surface_layer_fluxes_mod,                                              &
+    USE surface_layer_fluxes_mod,                                                                  &
         ONLY:  phi_m
 
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i      !< grid index x-direction
-    INTEGER(iwp) ::  j      !< grid index y-direction
-    INTEGER(iwp) ::  k      !< grid index z-direction
-    INTEGER(iwp) ::  m      !< running index surface elements
-
-    REAL(wp) ::  km_sfc     !< diffusion coefficient, used to compute virtual velocities
+    INTEGER(iwp) ::  i  !< grid index x-direction
+    INTEGER(iwp) ::  j  !< grid index y-direction
+    INTEGER(iwp) ::  k  !< grid index z-direction
+    INTEGER(iwp) ::  m  !< running index surface elements
+
+    REAL(wp) ::  km_sfc  !< diffusion coefficient, used to compute virtual velocities
 
     IF ( constant_flux_layer )  THEN
 !
-!--    Calculate a virtual velocity at the surface in a way that the
-!--    vertical velocity gradient at k = 1 (u(k+1)-u_0) matches the
-!--    Prandtl law (-w'u'/km). This gradient is used in the TKE shear
-!--    production term at k=1 (see production_e_ij).
-!--    The velocity gradient has to be limited in case of too small km
-!--    (otherwise the timestep may be significantly reduced by large
-!--    surface winds).
-!--    not available in case of non-cyclic boundary conditions.
+!--    Calculate a virtual velocity at the surface in a way that the vertical velocity gradient at
+!--    k = 1 (u(k+1)-u_0) matches the Prandtl law (-w'u'/km). This gradient is used in the TKE shear
+!--    production term at k=1 (see production_e_ij). The velocity gradient has to be limited in case
+!--    of too small km (otherwise the timestep may be significantly reduced by large surface winds).
+!--    Not available in case of non-cyclic boundary conditions.
 !--    Default surfaces, upward-facing
        !$OMP PARALLEL DO PRIVATE(i,j,k,m)
@@ -2048,27 +2073,20 @@
           k = surf_def_h(0)%k(m)
 !
-!--       Note, calculation of u_0 and v_0 is not fully accurate, as u/v
-!--       and km are not on the same grid. Actually, a further
-!--       interpolation of km onto the u/v-grid is necessary. However, the
+!--       Note, calculation of u_0 and v_0 is not fully accurate, as u/v and km are not on the same
+!--       grid. Actually, a further interpolation of km onto the u/v-grid is necessary. However, the
 !--       effect of this error is negligible.
-          km_sfc = kappa * surf_def_h(0)%us(m) * surf_def_h(0)%z_mo(m) /       &
+          km_sfc = kappa * surf_def_h(0)%us(m) * surf_def_h(0)%z_mo(m) /                           &
                    phi_m( surf_def_h(0)%z_mo(m) / surf_def_h(0)%ol(m) )
 
-          surf_def_h(0)%u_0(m) = u(k+1,j,i) + surf_def_h(0)%usws(m) *          &
-                                     drho_air_zw(k-1)               *          &
-                                     ( zu(k+1) - zu(k-1)    )       /          &
-                                     ( km_sfc  + 1.0E-20_wp )
-          surf_def_h(0)%v_0(m) = v(k+1,j,i) + surf_def_h(0)%vsws(m) *          &
-                                     drho_air_zw(k-1)               *          &
-                                     ( zu(k+1) - zu(k-1)    )       /          &
-                                     ( km_sfc  + 1.0E-20_wp )
-
-          IF ( ABS( u(k+1,j,i) - surf_def_h(0)%u_0(m) )  >                     &
-               ABS( u(k+1,j,i) - u(k-1,j,i)           )                        &
-             )  surf_def_h(0)%u_0(m) = u(k-1,j,i)
-
-          IF ( ABS( v(k+1,j,i) - surf_def_h(0)%v_0(m) )  >                     &
-               ABS( v(k+1,j,i) - v(k-1,j,i)           )                        &
-             )  surf_def_h(0)%v_0(m) = v(k-1,j,i)
+          surf_def_h(0)%u_0(m) = u(k+1,j,i) + surf_def_h(0)%usws(m) * drho_air_zw(k-1) *           &
+                                 ( zu(k+1) - zu(k-1) ) / ( km_sfc  + 1.0E-20_wp )
+          surf_def_h(0)%v_0(m) = v(k+1,j,i) + surf_def_h(0)%vsws(m) * drho_air_zw(k-1) *           &
+                                 ( zu(k+1) - zu(k-1) ) / ( km_sfc  + 1.0E-20_wp )
+
+          IF ( ABS( u(k+1,j,i) - surf_def_h(0)%u_0(m) ) > ABS( u(k+1,j,i) - u(k-1,j,i) ) )         &
+             surf_def_h(0)%u_0(m) = u(k-1,j,i)
+
+          IF ( ABS( v(k+1,j,i) - surf_def_h(0)%v_0(m) ) > ABS( v(k+1,j,i) - v(k-1,j,i) ) )         &
+             surf_def_h(0)%v_0(m) = v(k-1,j,i)
 
        ENDDO
@@ -2084,24 +2102,17 @@
           k = surf_def_h(1)%k(m)
 !
-!--       Note, calculation of u_0 and v_0 is not fully accurate, as u/v
-!--       and km are not on the same grid. Actually, a further
-!--       interpolation of km onto the u/v-grid is necessary. However, the
+!--       Note, calculation of u_0 and v_0 is not fully accurate, as u/v and km are not on the same
+!--       grid. Actually, a further interpolation of km onto the u/v-grid is necessary. However, the
 !--       effect of this error is negligible.
-          surf_def_h(1)%u_0(m) = u(k-1,j,i) - surf_def_h(1)%usws(m) *          &
-                                     drho_air_zw(k-1) *                        &
-                                     ( zu(k+1)    - zu(k-1)    )  /            &
-                                     ( km(k,j,i)  + 1.0E-20_wp )
-          surf_def_h(1)%v_0(m) = v(k-1,j,i) - surf_def_h(1)%vsws(m) *          &
-                                     drho_air_zw(k-1) *                        &
-                                     ( zu(k+1)    - zu(k-1)    )  /            &
-                                     ( km(k,j,i)  + 1.0E-20_wp )
-
-          IF ( ABS( surf_def_h(1)%u_0(m) - u(k-1,j,i) )  >                     &
-               ABS( u(k+1,j,i)           - u(k-1,j,i) )                        &
-             )  surf_def_h(1)%u_0(m) = u(k+1,j,i)
-
-          IF ( ABS( surf_def_h(1)%v_0(m) - v(k-1,j,i) )  >                     &
-               ABS( v(k+1,j,i)           - v(k-1,j,i) )                        &
-             )  surf_def_h(1)%v_0(m) = v(k+1,j,i)
+          surf_def_h(1)%u_0(m) = u(k-1,j,i) - surf_def_h(1)%usws(m) * drho_air_zw(k-1) *           &
+                                     ( zu(k+1) - zu(k-1) ) / ( km(k,j,i) + 1.0E-20_wp )
+          surf_def_h(1)%v_0(m) = v(k-1,j,i) - surf_def_h(1)%vsws(m) * drho_air_zw(k-1) *           &
+                                     ( zu(k+1) - zu(k-1) ) / (km(k,j,i) + 1.0E-20_wp )
+
+          IF ( ABS( surf_def_h(1)%u_0(m) - u(k-1,j,i) ) > ABS( u(k+1,j,i) - u(k-1,j,i) ) )         &
+             surf_def_h(1)%u_0(m) = u(k+1,j,i)
+
+          IF ( ABS( surf_def_h(1)%v_0(m) - v(k-1,j,i) ) > ABS( v(k+1,j,i) - v(k-1,j,i) ) )         &
+             surf_def_h(1)%v_0(m) = v(k+1,j,i)
 
        ENDDO
@@ -2117,27 +2128,20 @@
           k = surf_lsm_h%k(m)
 !
-!--       Note, calculation of u_0 and v_0 is not fully accurate, as u/v
-!--       and km are not on the same grid. Actually, a further
-!--       interpolation of km onto the u/v-grid is necessary. However, the
+!--       Note, calculation of u_0 and v_0 is not fully accurate, as u/v and km are not on the same
+!--       grid. Actually, a further interpolation of km onto the u/v-grid is necessary. However, the
 !--       effect of this error is negligible.
-          km_sfc = kappa * surf_lsm_h%us(m) * surf_lsm_h%z_mo(m) /             &
+          km_sfc = kappa * surf_lsm_h%us(m) * surf_lsm_h%z_mo(m) /                                 &
                    phi_m( surf_lsm_h%z_mo(m) / surf_lsm_h%ol(m) )
 
-          surf_lsm_h%u_0(m) = u(k+1,j,i) + surf_lsm_h%usws(m)    *             &
-                                        drho_air_zw(k-1)         *             &
-                                        ( zu(k+1) - zu(k-1)    ) /             &
-                                        ( km_sfc  + 1.0E-20_wp )
-          surf_lsm_h%v_0(m) = v(k+1,j,i) + surf_lsm_h%vsws(m)    *             &
-                                        drho_air_zw(k-1)         *             &
-                                        ( zu(k+1) - zu(k-1)    ) /             &
-                                        ( km_sfc  + 1.0E-20_wp )
-
-          IF ( ABS( u(k+1,j,i) - surf_lsm_h%u_0(m) )  >                        &
-               ABS( u(k+1,j,i) - u(k-1,j,i)   )                                &
-             )  surf_lsm_h%u_0(m) = u(k-1,j,i)
-
-          IF ( ABS( v(k+1,j,i) - surf_lsm_h%v_0(m) )  >                        &
-               ABS( v(k+1,j,i) - v(k-1,j,i)   )                                &
-             )  surf_lsm_h%v_0(m) = v(k-1,j,i)
+          surf_lsm_h%u_0(m) = u(k+1,j,i) + surf_lsm_h%usws(m) * drho_air_zw(k-1) *                 &
+                              ( zu(k+1) - zu(k-1) ) / ( km_sfc  + 1.0E-20_wp )
+          surf_lsm_h%v_0(m) = v(k+1,j,i) + surf_lsm_h%vsws(m) * drho_air_zw(k-1) *                 &
+                                        ( zu(k+1) - zu(k-1)) / ( km_sfc  + 1.0E-20_wp )
+
+          IF ( ABS( u(k+1,j,i) - surf_lsm_h%u_0(m) ) > ABS( u(k+1,j,i) - u(k-1,j,i) ) )            &
+             surf_lsm_h%u_0(m) = u(k-1,j,i)
+
+          IF ( ABS( v(k+1,j,i) - surf_lsm_h%v_0(m) ) > ABS( v(k+1,j,i) - v(k-1,j,i) ) )            &
+             surf_lsm_h%v_0(m) = v(k-1,j,i)
 
        ENDDO
@@ -2153,27 +2157,20 @@
           k = surf_usm_h%k(m)
 !
-!--       Note, calculation of u_0 and v_0 is not fully accurate, as u/v
-!--       and km are not on the same grid. Actually, a further
-!--       interpolation of km onto the u/v-grid is necessary. However, the
+!--       Note, calculation of u_0 and v_0 is not fully accurate, as u/v and km are not on the same
+!--       grid. Actually, a further interpolation of km onto the u/v-grid is necessary. However, the
 !--       effect of this error is negligible.
-          km_sfc = kappa * surf_usm_h%us(m) * surf_usm_h%z_mo(m) /             &
+          km_sfc = kappa * surf_usm_h%us(m) * surf_usm_h%z_mo(m) /                                 &
                    phi_m( surf_usm_h%z_mo(m) / surf_usm_h%ol(m) )
 
-          surf_usm_h%u_0(m) = u(k+1,j,i) + surf_usm_h%usws(m)    *             &
-                                        drho_air_zw(k-1)         *             &
-                                        ( zu(k+1) - zu(k-1)    ) /             &
-                                        ( km_sfc  + 1.0E-20_wp )
-          surf_usm_h%v_0(m) = v(k+1,j,i) + surf_usm_h%vsws(m)    *             &
-                                        drho_air_zw(k-1)         *             &
-                                        ( zu(k+1) - zu(k-1)    ) /             &
-                                        ( km_sfc  + 1.0E-20_wp )
-
-          IF ( ABS( u(k+1,j,i) - surf_usm_h%u_0(m) )  >                        &
-               ABS( u(k+1,j,i) - u(k-1,j,i)   )                                &
-             )  surf_usm_h%u_0(m) = u(k-1,j,i)
-
-          IF ( ABS( v(k+1,j,i) - surf_usm_h%v_0(m) )  >                        &
-               ABS( v(k+1,j,i) - v(k-1,j,i)   )                                &
-             )  surf_usm_h%v_0(m) = v(k-1,j,i)
+          surf_usm_h%u_0(m) = u(k+1,j,i) + surf_usm_h%usws(m) * drho_air_zw(k-1) *                 &
+                                        ( zu(k+1) - zu(k-1) ) / ( km_sfc  + 1.0E-20_wp )
+          surf_usm_h%v_0(m) = v(k+1,j,i) + surf_usm_h%vsws(m) * drho_air_zw(k-1) *                 &
+                                        ( zu(k+1) - zu(k-1) ) / ( km_sfc  + 1.0E-20_wp )
+
+          IF ( ABS( u(k+1,j,i) - surf_usm_h%u_0(m) ) > ABS( u(k+1,j,i) - u(k-1,j,i) ) )            &
+             surf_usm_h%u_0(m) = u(k-1,j,i)
+
+          IF ( ABS( v(k+1,j,i) - surf_usm_h%v_0(m) ) > ABS( v(k+1,j,i) - v(k-1,j,i) ) )            &
+             surf_usm_h%v_0(m) = v(k-1,j,i)
 
        ENDDO
@@ -2192,5 +2189,5 @@
 
 
-    CHARACTER (LEN=*) ::  location !<
+    CHARACTER(LEN=*) ::  location !<
 
 !    INTEGER(iwp) ::  i !<
@@ -2200,6 +2197,6 @@
 !
 !-- Here the module-specific actions follow
-!-- No calls for single grid points are allowed at locations before and
-!-- after the timestep, since these calls are not within an i,j-loop
+!-- No calls for single grid points are allowed at locations before and after the timestep, since
+!-- these calls are not within an i, j-loop
     SELECT CASE ( location )
 
@@ -2258,8 +2255,8 @@
 
 
-    CHARACTER (LEN=*) ::  location
-
-    INTEGER(iwp) ::  i
-    INTEGER(iwp) ::  j
+    CHARACTER(LEN=*) ::  location  !<
+
+    INTEGER(iwp) ::  i  !<
+    INTEGER(iwp) ::  j  !<
 
 !
@@ -2301,26 +2298,25 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Prognostic equation for subgrid-scale TKE and TKE dissipation rate.
-!> Vector-optimized version
-!------------------------------------------------------------------------------!
+!> Prognostic equation for subgrid-scale TKE and TKE dissipation rate. Vector-optimized version
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_prognostic_equations
 
-    USE control_parameters,                                                    &
-        ONLY:  scalar_advec, tsc
+    USE control_parameters,                                                                        &
+        ONLY:  scalar_advec,                                                                       &
+               tsc
 
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i       !< loop index
-    INTEGER(iwp) ::  j       !< loop index
-    INTEGER(iwp) ::  k       !< loop index
-
-    REAL(wp)     ::  sbt     !< wheighting factor for sub-time step
-
-!
-!-- If required, compute prognostic equation for turbulent kinetic
-!-- energy (TKE)
+    INTEGER(iwp) ::  i  !< loop index
+    INTEGER(iwp) ::  j  !< loop index
+    INTEGER(iwp) ::  k  !< loop index
+
+    REAL(wp)     ::  sbt  !< wheighting factor for sub-time step
+
+!
+!-- If required, compute prognostic equation for turbulent kinetic energy (TKE)
     IF ( .NOT. constant_diffusion )  THEN
 
@@ -2354,9 +2350,8 @@
              IF ( timestep_scheme(1:5) == 'runge' )  THEN
                 IF ( ws_scheme_sca )  THEN
-                   CALL advec_s_ws( advc_flags_s, e, 'e',                      &
-                                    bc_dirichlet_l  .OR.  bc_radiation_l,      &
-                                    bc_dirichlet_n  .OR.  bc_radiation_n,      &
-                                    bc_dirichlet_r  .OR.  bc_radiation_r,      &
-                                    bc_dirichlet_s  .OR.  bc_radiation_s )
+                   CALL advec_s_ws( advc_flags_s, e, 'e', bc_dirichlet_l  .OR.  bc_radiation_l,    &
+                                                          bc_dirichlet_n  .OR.  bc_radiation_n,    &
+                                                          bc_dirichlet_r  .OR.  bc_radiation_r,    &
+                                                          bc_dirichlet_s  .OR.  bc_radiation_s )
                 ELSE
                    CALL advec_s_pw( e )
@@ -2389,7 +2384,6 @@
 !
 !--    Prognostic equation for TKE.
-!--    Eliminate negative TKE values, which can occur due to numerical
-!--    reasons in the course of the integration. In such cases the old TKE
-!--    value is reduced by 90%.
+!--    Eliminate negative TKE values, which can occur due to numerical reasons in the course of the
+!--    integration. In such cases the old TKE value is reduced by 90%.
        !$ACC PARALLEL LOOP COLLAPSE(3) PRIVATE(i, j, k) &
        !$ACC PRESENT(e, tend, te_m, wall_flags_total_0) &
@@ -2398,13 +2392,9 @@
        DO  i = nxl, nxr
           DO  j = nys, nyn
-             !following directive is required to vectorize on Intel19
+             !Following directive is required to vectorize on Intel19
              !DIR$ IVDEP
              DO  k = nzb+1, nzt
-                e_p(k,j,i) = e(k,j,i) + ( dt_3d * ( sbt * tend(k,j,i) +        &
-                                                 tsc(3) * te_m(k,j,i) )        &
-                                        )                                      &
-                                   * MERGE( 1.0_wp, 0.0_wp,                    &
-                                       BTEST( wall_flags_total_0(k,j,i), 0 )   &
-                                          )
+                e_p(k,j,i) = e(k,j,i) + ( dt_3d * ( sbt * tend(k,j,i) + tsc(3) * te_m(k,j,i) ) )   &
+                             * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
                 IF ( e_p(k,j,i) < 0.0_wp )  e_p(k,j,i) = 0.1_wp * e(k,j,i)
              ENDDO
@@ -2425,6 +2415,5 @@
                 ENDDO
              ENDDO
-          ELSEIF ( intermediate_timestep_count < &
-                   intermediate_timestep_count_max )  THEN
+          ELSEIF ( intermediate_timestep_count < intermediate_timestep_count_max )  THEN
              !$ACC PARALLEL LOOP COLLAPSE(3) PRIVATE(i, j, k) &
              !$ACC PRESENT(tend, te_m)
@@ -2432,6 +2421,5 @@
                 DO  j = nys, nyn
                    DO  k = nzb+1, nzt
-                      te_m(k,j,i) =   -9.5625_wp * tend(k,j,i)                 &
-                                     + 5.3125_wp * te_m(k,j,i)
+                      te_m(k,j,i) = -9.5625_wp * tend(k,j,i) + 5.3125_wp * te_m(k,j,i)
                    ENDDO
                 ENDDO
@@ -2466,5 +2454,5 @@
 
 !
-!--    dissipation-tendency terms with no communication
+!--    Dissipation-tendency terms with no communication
        IF ( scalar_advec /= 'bc-scheme'  .OR.  use_upstream_for_tke )  THEN
           IF ( use_upstream_for_tke )  THEN
@@ -2475,8 +2463,8 @@
              IF ( timestep_scheme(1:5) == 'runge' )  THEN
                 IF ( ws_scheme_sca )  THEN
-                   CALL advec_s_ws( advc_flags_s, diss, 'diss',                &
-                                    bc_dirichlet_l  .OR.  bc_radiation_l,      &
-                                    bc_dirichlet_n  .OR.  bc_radiation_n,      &
-                                    bc_dirichlet_r  .OR.  bc_radiation_r,      &
+                   CALL advec_s_ws( advc_flags_s, diss, 'diss',                                    &
+                                    bc_dirichlet_l  .OR.  bc_radiation_l,                          &
+                                    bc_dirichlet_n  .OR.  bc_radiation_n,                          &
+                                    bc_dirichlet_r  .OR.  bc_radiation_r,                          &
                                     bc_dirichlet_s  .OR.  bc_radiation_s )
                 ELSE
@@ -2502,18 +2490,13 @@
 !
 !--    Prognostic equation for TKE dissipation.
-!--    Eliminate negative dissipation values, which can occur due to numerical
-!--    reasons in the course of the integration. In such cases the old
-!--    dissipation value is reduced by 90%.
+!--    Eliminate negative dissipation values, which can occur due to numerical reasons in the course
+!--    of the integration. In such cases the old dissipation value is reduced by 90%.
        DO  i = nxl, nxr
           DO  j = nys, nyn
              DO  k = nzb+1, nzt
-                diss_p(k,j,i) = diss(k,j,i) + ( dt_3d * ( sbt * tend(k,j,i) +  &
-                                                 tsc(3) * tdiss_m(k,j,i) )     &
-                                        )                                      &
-                                   * MERGE( 1.0_wp, 0.0_wp,                    &
-                                       BTEST( wall_flags_total_0(k,j,i), 0 )   &
-                                          )
-                IF ( diss_p(k,j,i) < 0.0_wp )                                  &
-                   diss_p(k,j,i) = 0.1_wp * diss(k,j,i)
+                diss_p(k,j,i) = diss(k,j,i) + ( dt_3d * ( sbt * tend(k,j,i) + tsc(3)               &
+                                                          * tdiss_m(k,j,i) ) )                     &
+                                * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                IF ( diss_p(k,j,i) < 0.0_wp )  diss_p(k,j,i) = 0.1_wp * diss(k,j,i)
              ENDDO
           ENDDO
@@ -2531,11 +2514,9 @@
                 ENDDO
              ENDDO
-          ELSEIF ( intermediate_timestep_count < &
-                   intermediate_timestep_count_max )  THEN
+          ELSEIF ( intermediate_timestep_count < intermediate_timestep_count_max )  THEN
              DO  i = nxl, nxr
                 DO  j = nys, nyn
                    DO  k = nzb+1, nzt
-                      tdiss_m(k,j,i) =   -9.5625_wp * tend(k,j,i)              &
-                                        + 5.3125_wp * tdiss_m(k,j,i)
+                      tdiss_m(k,j,i) = -9.5625_wp * tend(k,j,i) + 5.3125_wp * tdiss_m(k,j,i)
                    ENDDO
                 ENDDO
@@ -2551,30 +2532,34 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Prognostic equation for subgrid-scale TKE and TKE dissipation rate.
-!> Cache-optimized version
-!------------------------------------------------------------------------------!
+!> Prognostic equation for subgrid-scale TKE and TKE dissipation rate. Cache-optimized version
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_prognostic_equations_ij( i, j, i_omp, tn )
 
-    USE arrays_3d,                                                             &
-        ONLY:  diss_l_diss, diss_l_e, diss_s_diss, diss_s_e, flux_l_diss,      &
-               flux_l_e, flux_s_diss, flux_s_e
-
-    USE control_parameters,                                                    &
+    USE arrays_3d,                                                                                 &
+        ONLY:  diss_l_diss,                                                                        &
+               diss_l_e,                                                                           &
+               diss_s_diss,                                                                        &
+               diss_s_e,                                                                           &
+               flux_l_diss,                                                                        &
+               flux_l_e,                                                                           &
+               flux_s_diss,                                                                        &
+               flux_s_e
+
+    USE control_parameters,                                                                        &
         ONLY:  tsc
 
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i       !< loop index x direction
-    INTEGER(iwp) ::  i_omp   !< first loop index of i-loop in prognostic_equations
-    INTEGER(iwp) ::  j       !< loop index y direction
-    INTEGER(iwp) ::  k       !< loop index z direction
-    INTEGER(iwp) ::  tn      !< task number of openmp task
-
-!
-!-- If required, compute prognostic equation for turbulent kinetic
-!-- energy (TKE)
+    INTEGER(iwp) ::  i      !< loop index x direction
+    INTEGER(iwp) ::  i_omp  !< first loop index of i-loop in prognostic_equations
+    INTEGER(iwp) ::  j      !< loop index y direction
+    INTEGER(iwp) ::  k      !< loop index z direction
+    INTEGER(iwp) ::  tn     !< task number of openmp task
+
+!
+!-- If required, compute prognostic equation for turbulent kinetic energy (TKE)
     IF ( .NOT. constant_diffusion )  THEN
 
@@ -2582,13 +2567,11 @@
 !--    Tendency-terms for TKE
        tend(:,j,i) = 0.0_wp
-       IF ( timestep_scheme(1:5) == 'runge'  &
-           .AND.  .NOT. use_upstream_for_tke )  THEN
+       IF ( timestep_scheme(1:5) == 'runge'  .AND.  .NOT. use_upstream_for_tke )  THEN
            IF ( ws_scheme_sca )  THEN
-               CALL advec_s_ws( advc_flags_s,                                  &
-                                i, j, e, 'e', flux_s_e, diss_s_e,              &
-                                flux_l_e, diss_l_e , i_omp, tn,                &
-                                bc_dirichlet_l  .OR.  bc_radiation_l,          &
-                                bc_dirichlet_n  .OR.  bc_radiation_n,          &
-                                bc_dirichlet_r  .OR.  bc_radiation_r,          &
+               CALL advec_s_ws( advc_flags_s, i, j, e, 'e', flux_s_e, diss_s_e, flux_l_e,          &
+                                diss_l_e , i_omp, tn,                                              &
+                                bc_dirichlet_l  .OR.  bc_radiation_l,                              &
+                                bc_dirichlet_n  .OR.  bc_radiation_n,                              &
+                                bc_dirichlet_r  .OR.  bc_radiation_r,                              &
                                 bc_dirichlet_s  .OR.  bc_radiation_s )
            ELSE
@@ -2619,14 +2602,9 @@
 !
 !--    Prognostic equation for TKE.
-!--    Eliminate negative TKE values, which can occur due to numerical
-!--    reasons in the course of the integration. In such cases the old
-!--    TKE value is reduced by 90%.
+!--    Eliminate negative TKE values, which can occur due to numerical reasons in the course of the
+!--    integration. In such cases the old TKE value is reduced by 90%.
        DO  k = nzb+1, nzt
-          e_p(k,j,i) = e(k,j,i) + ( dt_3d * ( tsc(2) * tend(k,j,i) +           &
-                                              tsc(3) * te_m(k,j,i) )           &
-                                  )                                            &
-                                 * MERGE( 1.0_wp, 0.0_wp,                      &
-                                    BTEST( wall_flags_total_0(k,j,i), 0 )      &
-                                        )
+          e_p(k,j,i) = e(k,j,i) + ( dt_3d * ( tsc(2) * tend(k,j,i) + tsc(3) * te_m(k,j,i) ) )      &
+                       * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
           IF ( e_p(k,j,i) <= 0.0_wp )  e_p(k,j,i) = 0.1_wp * e(k,j,i)
        ENDDO
@@ -2639,9 +2617,7 @@
                 te_m(k,j,i) = tend(k,j,i)
              ENDDO
-          ELSEIF ( intermediate_timestep_count < &
-                   intermediate_timestep_count_max )  THEN
+          ELSEIF ( intermediate_timestep_count < intermediate_timestep_count_max )  THEN
              DO  k = nzb+1, nzt
-                te_m(k,j,i) =   -9.5625_wp * tend(k,j,i) +                     &
-                                 5.3125_wp * te_m(k,j,i)
+                te_m(k,j,i) = -9.5625_wp * tend(k,j,i) + 5.3125_wp * te_m(k,j,i)
              ENDDO
           ENDIF
@@ -2656,13 +2632,11 @@
 !--    Tendency-terms for dissipation
        tend(:,j,i) = 0.0_wp
-       IF ( timestep_scheme(1:5) == 'runge'  &
-           .AND.  .NOT. use_upstream_for_tke )  THEN
+       IF ( timestep_scheme(1:5) == 'runge'  .AND.  .NOT. use_upstream_for_tke )  THEN
            IF ( ws_scheme_sca )  THEN
-               CALL advec_s_ws( advc_flags_s,                                  &
-                                i, j, diss, 'diss', flux_s_diss, diss_s_diss,  &
-                                flux_l_diss, diss_l_diss, i_omp, tn,           &
-                                bc_dirichlet_l  .OR.  bc_radiation_l,          &
-                                bc_dirichlet_n  .OR.  bc_radiation_n,          &
-                                bc_dirichlet_r  .OR.  bc_radiation_r,          &
+               CALL advec_s_ws( advc_flags_s, i, j, diss, 'diss', flux_s_diss, diss_s_diss,        &
+                                flux_l_diss, diss_l_diss, i_omp, tn,                               &
+                                bc_dirichlet_l  .OR.  bc_radiation_l,                              &
+                                bc_dirichlet_n  .OR.  bc_radiation_n,                              &
+                                bc_dirichlet_r  .OR.  bc_radiation_r,                              &
                                 bc_dirichlet_s  .OR.  bc_radiation_s )
            ELSE
@@ -2686,14 +2660,10 @@
 !
 !--    Prognostic equation for TKE dissipation
-!--    Eliminate negative dissipation values, which can occur due to
-!--    numerical reasons in the course of the integration. In such cases
-!--    the old dissipation value is reduced by 90%.
+!--    Eliminate negative dissipation values, which can occur due to numerical reasons in the course
+!--    of the integration. In such cases the old dissipation value is reduced by 90%.
        DO  k = nzb+1, nzt
-          diss_p(k,j,i) = diss(k,j,i) + ( dt_3d * ( tsc(2) * tend(k,j,i) +     &
-                                                    tsc(3) * tdiss_m(k,j,i) )  &
-                                        )                                      &
-                                        * MERGE( 1.0_wp, 0.0_wp,               &
-                                          BTEST( wall_flags_total_0(k,j,i), 0 )&
-                                               )
+          diss_p(k,j,i) = diss(k,j,i) + ( dt_3d * ( tsc(2) * tend(k,j,i) + tsc(3)                  &
+                          * tdiss_m(k,j,i) ) )                                                     &
+                          * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
        ENDDO
 
@@ -2705,54 +2675,66 @@
                 tdiss_m(k,j,i) = tend(k,j,i)
              ENDDO
-          ELSEIF ( intermediate_timestep_count < &
-                   intermediate_timestep_count_max )  THEN
+          ELSEIF ( intermediate_timestep_count < intermediate_timestep_count_max )  THEN
              DO  k = nzb+1, nzt
-                tdiss_m(k,j,i) =   -9.5625_wp * tend(k,j,i) +                  &
-                                    5.3125_wp * tdiss_m(k,j,i)
+                tdiss_m(k,j,i) = -9.5625_wp * tend(k,j,i) + 5.3125_wp * tdiss_m(k,j,i)
              ENDDO
           ENDIF
        ENDIF
 
-    ENDIF   ! dissipation equation
+    ENDIF   ! Dissipation equation
 
  END SUBROUTINE tcm_prognostic_equations_ij
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Production terms (shear + buoyancy) of the TKE.
 !> Vector-optimized version
-!> @warning The case with constant_flux_layer = F and use_surface_fluxes = T is
-!>          not considered well!
-!------------------------------------------------------------------------------!
+!> @warning The case with constant_flux_layer = F and use_surface_fluxes = T is not considered well!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE production_e( diss_production )
 
-    USE arrays_3d,                                                             &
-        ONLY:  ddzw, dd2zu, drho_air_zw, q, ql, d_exner, exner
-
-    USE control_parameters,                                                    &
-        ONLY:  cloud_droplets, constant_flux_layer, neutral,                   &
-               rho_reference, use_single_reference_value, use_surface_fluxes,  &
+    USE arrays_3d,                                                                                 &
+        ONLY:  ddzw,                                                                               &
+               dd2zu,                                                                              &
+               d_exner,                                                                            &
+               drho_air_zw,                                                                        &
+               exner,                                                                              &
+               q,                                                                                  &
+               ql
+
+
+
+    USE control_parameters,                                                                        &
+        ONLY:  cloud_droplets,                                                                     &
+               constant_flux_layer,                                                                &
+               neutral,                                                                            &
+               rho_reference,                                                                      &
+               use_single_reference_value,                                                         &
+               use_surface_fluxes,                                                                 &
                use_top_fluxes
 
-    USE grid_variables,                                                        &
-        ONLY:  ddx, dx, ddy, dy
-
-    USE bulk_cloud_model_mod,                                                  &
+    USE grid_variables,                                                                            &
+        ONLY:  ddx,                                                                                &
+               dx,                                                                                 &
+               ddy,                                                                                &
+               dy
+
+    USE bulk_cloud_model_mod,                                                                      &
         ONLY:  bulk_cloud_model
 
     IMPLICIT NONE
 
-    LOGICAL :: diss_production
-
-    INTEGER(iwp) ::  i       !< running index x-direction
-    INTEGER(iwp) ::  j       !< running index y-direction
-    INTEGER(iwp) ::  k       !< running index z-direction
-    INTEGER(iwp) ::  l       !< running index for different surface type orientation
-    INTEGER(iwp) ::  m       !< running index surface elements
-    INTEGER(iwp) ::  surf_e  !< end index of surface elements at given i-j position
-    INTEGER(iwp) ::  surf_s  !< start index of surface elements at given i-j position
-    INTEGER(iwp) ::  flag_nr !< number of masking flag
+    LOGICAL ::  diss_production  !<
+
+    INTEGER(iwp) ::  flag_nr  !< number of masking flag
+    INTEGER(iwp) ::  i        !< running index x-direction
+    INTEGER(iwp) ::  j        !< running index y-direction
+    INTEGER(iwp) ::  k        !< running index z-direction
+    INTEGER(iwp) ::  l        !< running index for different surface type orientation
+    INTEGER(iwp) ::  m        !< running index surface elements
+    INTEGER(iwp) ::  surf_e   !< end index of surface elements at given i-j position
+    INTEGER(iwp) ::  surf_s   !< start index of surface elements at given i-j position
 
     REAL(wp)     ::  def         !< ( du_i/dx_j + du_j/dx_i ) * du_i/dx_j
@@ -2761,7 +2743,7 @@
     REAL(wp)     ::  k2          !< temporary factor
     REAL(wp)     ::  km_neutral  !< diffusion coefficient assuming neutral conditions - used to compute shear production at surfaces
+    REAL(wp)     ::  sign_dir    !< sign of wall-tke flux, depending on wall orientation
     REAL(wp)     ::  theta       !< virtual potential temperature
     REAL(wp)     ::  temp        !< theta * Exner-function
-    REAL(wp)     ::  sign_dir    !< sign of wall-tke flux, depending on wall orientation
     REAL(wp)     ::  usvs        !< momentum flux u"v"
     REAL(wp)     ::  vsus        !< momentum flux v"u"
@@ -2769,13 +2751,13 @@
     REAL(wp)     ::  wsvs        !< momentum flux w"v"
 
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudx  !< Gradient of u-component in x-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudy  !< Gradient of u-component in y-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudz  !< Gradient of u-component in z-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdx  !< Gradient of v-component in x-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdy  !< Gradient of v-component in y-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdz  !< Gradient of v-component in z-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdx  !< Gradient of w-component in x-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdy  !< Gradient of w-component in y-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdz  !< Gradient of w-component in z-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudx      !< Gradient of u-component in x-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudy      !< Gradient of u-component in y-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudz      !< Gradient of u-component in z-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdx      !< Gradient of v-component in x-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdy      !< Gradient of v-component in y-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdz      !< Gradient of v-component in z-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdx      !< Gradient of w-component in x-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdy      !< Gradient of w-component in y-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdz      !< Gradient of w-component in z-direction
     REAL(wp), DIMENSION(nzb+1:nzt) ::  tmp_flux  !< temporary flux-array in z-direction
 
@@ -2783,7 +2765,6 @@
 
 !
-!-- Calculate TKE production by shear. Calculate gradients at all grid
-!-- points first, gradients at surface-bounded grid points will be
-!-- overwritten further below.
+!-- Calculate TKE production by shear. Calculate gradients at all grid points first, gradients at
+!-- surface-bounded grid points will be overwritten further below.
     !$ACC PARALLEL LOOP COLLAPSE(2) PRIVATE(i, j, l) &
     !$ACC PRIVATE(surf_s, surf_e) &
@@ -2800,19 +2781,13 @@
 
              dudx(k) =           ( u(k,j,i+1) - u(k,j,i)     ) * ddx
-             dudy(k) = 0.25_wp * ( u(k,j+1,i) + u(k,j+1,i+1) -                 &
-                                   u(k,j-1,i) - u(k,j-1,i+1) ) * ddy
-             dudz(k) = 0.5_wp  * ( u(k+1,j,i) + u(k+1,j,i+1) -                 &
-                                   u(k-1,j,i) - u(k-1,j,i+1) ) * dd2zu(k)
-
-             dvdx(k) = 0.25_wp * ( v(k,j,i+1) + v(k,j+1,i+1) -                 &
-                                   v(k,j,i-1) - v(k,j+1,i-1) ) * ddx
+             dudy(k) = 0.25_wp * ( u(k,j+1,i) + u(k,j+1,i+1) - u(k,j-1,i) - u(k,j-1,i+1) ) * ddy
+             dudz(k) = 0.5_wp  * ( u(k+1,j,i) + u(k+1,j,i+1) - u(k-1,j,i) - u(k-1,j,i+1) ) * dd2zu(k)
+
+             dvdx(k) = 0.25_wp * ( v(k,j,i+1) + v(k,j+1,i+1) - v(k,j,i-1) - v(k,j+1,i-1) ) * ddx
              dvdy(k) =           ( v(k,j+1,i) - v(k,j,i)     ) * ddy
-             dvdz(k) = 0.5_wp  * ( v(k+1,j,i) + v(k+1,j+1,i) -                 &
-                                     v(k-1,j,i) - v(k-1,j+1,i) ) * dd2zu(k)
-
-             dwdx(k) = 0.25_wp * ( w(k,j,i+1) + w(k-1,j,i+1) -                 &
-                                   w(k,j,i-1) - w(k-1,j,i-1) ) * ddx
-             dwdy(k) = 0.25_wp * ( w(k,j+1,i) + w(k-1,j+1,i) -                 &
-                                   w(k,j-1,i) - w(k-1,j-1,i) ) * ddy
+             dvdz(k) = 0.5_wp  * ( v(k+1,j,i) + v(k+1,j+1,i) - v(k-1,j,i) - v(k-1,j+1,i) ) * dd2zu(k)
+
+             dwdx(k) = 0.25_wp * ( w(k,j,i+1) + w(k-1,j,i+1) - w(k,j,i-1) - w(k-1,j,i-1) ) * ddx
+             dwdy(k) = 0.25_wp * ( w(k,j+1,i) + w(k-1,j+1,i) - w(k,j-1,i) - w(k-1,j-1,i) ) * ddy
              dwdz(k) =           ( w(k,j,i)   - w(k-1,j,i)   ) * ddzw(k)
 
@@ -2832,7 +2807,6 @@
 !--          'bottom and wall: use u_0,v_0 and wall functions'
 !
-!--          Compute gradients at north- and south-facing surfaces.
-!--          First, for default surfaces, then for urban surfaces.
-!--          Note, so far no natural vertical surfaces implemented
+!--          Compute gradients at north- and south-facing surfaces. First, for default surfaces,
+!--          then for urban surfaces. Note, so far no natural vertical surfaces implemented
              DO  l = 0, 1
                 surf_s = surf_def_v(l)%start_index(j,i)
@@ -2844,10 +2818,8 @@
                    wsvs        = surf_def_v(l)%mom_flux_tke(1,m)
 
-                   km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp         &
-                                      * 0.5_wp * dy
+                   km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp * 0.5_wp * dy
 !
 !--                -1.0 for right-facing wall, 1.0 for left-facing wall
-                   sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                              BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
+                   sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
                    dudy(k) = sign_dir * usvs / ( km_neutral + 1E-10_wp )
                    dwdy(k) = sign_dir * wsvs / ( km_neutral + 1E-10_wp )
@@ -2863,10 +2835,8 @@
                    wsvs        = surf_lsm_v(l)%mom_flux_tke(1,m)
 
-                   km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp         &
-                                      * 0.5_wp * dy
+                   km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp * 0.5_wp * dy
 !
 !--                -1.0 for right-facing wall, 1.0 for left-facing wall
-                   sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                              BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
+                   sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
                    dudy(k) = sign_dir * usvs / ( km_neutral + 1E-10_wp )
                    dwdy(k) = sign_dir * wsvs / ( km_neutral + 1E-10_wp )
@@ -2882,10 +2852,8 @@
                    wsvs        = surf_usm_v(l)%mom_flux_tke(1,m)
 
-                   km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp         &
-                                      * 0.5_wp * dy
+                   km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp * 0.5_wp * dy
 !
 !--                -1.0 for right-facing wall, 1.0 for left-facing wall
-                   sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                              BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
+                   sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
                    dudy(k) = sign_dir * usvs / ( km_neutral + 1E-10_wp )
                    dwdy(k) = sign_dir * wsvs / ( km_neutral + 1E-10_wp )
@@ -2903,10 +2871,8 @@
                    wsus  = surf_def_v(l)%mom_flux_tke(1,m)
 
-                   km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp         &
-                                      * 0.5_wp * dx
+                   km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp * 0.5_wp * dx
 !
 !--                -1.0 for right-facing wall, 1.0 for left-facing wall
-                   sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                              BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
+                   sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
                    dvdx(k) = sign_dir * vsus / ( km_neutral + 1E-10_wp )
                    dwdx(k) = sign_dir * wsus / ( km_neutral + 1E-10_wp )
@@ -2922,10 +2888,8 @@
                    wsus  = surf_lsm_v(l)%mom_flux_tke(1,m)
 
-                   km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp         &
-                                      * 0.5_wp * dx
+                   km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp * 0.5_wp * dx
 !
 !--                -1.0 for right-facing wall, 1.0 for left-facing wall
-                   sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                              BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
+                   sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
                    dvdx(k) = sign_dir * vsus / ( km_neutral + 1E-10_wp )
                    dwdx(k) = sign_dir * wsus / ( km_neutral + 1E-10_wp )
@@ -2941,10 +2905,8 @@
                    wsus  = surf_usm_v(l)%mom_flux_tke(1,m)
 
-                   km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp         &
-                                      * 0.5_wp * dx
+                   km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp * 0.5_wp * dx
 !
 !--                -1.0 for right-facing wall, 1.0 for left-facing wall
-                   sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                              BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
+                   sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
                    dvdx(k) = sign_dir * vsus / ( km_neutral + 1E-10_wp )
                    dwdx(k) = sign_dir * wsus / ( km_neutral + 1E-10_wp )
@@ -2959,9 +2921,8 @@
                 k = surf_def_h(0)%k(m)
 !
-!--             Please note, actually, an interpolation of u_0 and v_0
-!--             onto the grid center would be required. However, this
-!--             would require several data transfers between 2D-grid and
-!--             wall type. The effect of this missing interpolation is
-!--             negligible. (See also production_e_init).
+!--             Please note, actually, an interpolation of u_0 and v_0 onto the grid center would be
+!--             required. However, this would require several data transfers between 2D-grid and
+!--             wall type. The effect of this missing interpolation is negligible.
+!--            (See also production_e_init).
                 dudz(k) = ( u(k+1,j,i) - surf_def_h(0)%u_0(m) ) * dd2zu(k)
                 dvdz(k) = ( v(k+1,j,i) - surf_def_h(0)%v_0(m) ) * dd2zu(k)
@@ -2993,6 +2954,5 @@
              ENDDO
 !
-!--          Compute gradients at downward-facing walls, only for
-!--          non-natural default surfaces
+!--          Compute gradients at downward-facing walls, only for non-natural default surfaces
              surf_s = surf_def_h(1)%start_index(j,i)
              surf_e = surf_def_h(1)%end_index(j,i)
@@ -3013,9 +2973,7 @@
           DO  k = nzb+1, nzt
 
-             def = 2.0_wp * ( dudx(k)**2 + dvdy(k)**2 + dwdz(k)**2 ) +         &
-                              dudy(k)**2 + dvdx(k)**2 + dwdx(k)**2 +           &
-                              dwdy(k)**2 + dudz(k)**2 + dvdz(k)**2 +           &
-                   2.0_wp * ( dvdx(k)*dudy(k) + dwdx(k)*dudz(k) +              &
-                              dwdy(k)*dvdz(k) )
+             def = 2.0_wp * ( dudx(k)**2 + dvdy(k)**2 + dwdz(k)**2 ) + dudy(k)**2 + dvdx(k)**2 +   &
+                   dwdx(k)**2 + dwdy(k)**2 + dudz(k)**2 + dvdz(k)**2 +                             &
+                   2.0_wp * ( dvdx(k)*dudy(k) + dwdx(k)*dudz(k) + dwdy(k)*dvdz(k) )
 
              IF ( def < 0.0_wp )  def = 0.0_wp
@@ -3031,6 +2989,6 @@
 
 !--             RANS mode: Compute tendency for dissipation-rate-production from shear
-                tend(k,j,i) = tend(k,j,i) + km(k,j,i) * def * flag *           &
-                              diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) * c_1
+                tend(k,j,i) = tend(k,j,i) + km(k,j,i) * def * flag * diss(k,j,i) /                 &
+                              ( e(k,j,i) + 1.0E-20_wp ) * c_1
 
              ENDIF
@@ -3050,6 +3008,6 @@
           IF ( ocean_mode )  THEN
 !
-!--          So far in the ocean no special treatment of density flux
-!--          in the bottom and top surface layer
+!--          So far in the ocean no special treatment of density flux in the bottom and top surface
+!--          layer
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -3059,6 +3017,5 @@
                    ENDDO
 !
-!--                Treatment of near-surface grid points, at up- and down-
-!--                ward facing surfaces
+!--                Treatment of near-surface grid points, at up- and down-ward facing surfaces
                    IF ( use_surface_fluxes )  THEN
                       DO  l = 0, 1
@@ -3085,7 +3042,7 @@
 !--                   Compute tendency for TKE-production from shear
                       DO  k = nzb+1, nzt
-                         flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                         tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g / &
-                                       MERGE( rho_reference, prho(k,j,i),       &
+                         flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                         tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /                    &
+                                       MERGE( rho_reference, prho(k,j,i),                          &
                                               use_single_reference_value ) )
                       ENDDO
@@ -3095,10 +3052,9 @@
 !--                   RANS mode: Compute tendency for dissipation-rate-production from shear
                       DO  k = nzb+1, nzt
-                         flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                         tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g / &
-                                       MERGE( rho_reference, prho(k,j,i),       &
-                                              use_single_reference_value ) ) *  &
-                                       diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) *  &
-                                       c_3
+                         flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                         tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /                    &
+                                       MERGE( rho_reference, prho(k,j,i),                          &
+                                              use_single_reference_value ) ) *                     &
+                                       diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) *  c_3
                       ENDDO
 
@@ -3173,7 +3129,7 @@
                      !$ACC LOOP PRIVATE(k, flag)
                       DO  k = nzb+1, nzt
-                         flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                         tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g / &
-                                       MERGE( pt_reference, pt(k,j,i),          &
+                         flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                         tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /                    &
+                                       MERGE( pt_reference, pt(k,j,i),                             &
                                               use_single_reference_value ) )
                       ENDDO
@@ -3183,10 +3139,9 @@
 !--                   RANS mode: Compute tendency for dissipation-rate-production from shear
                       DO  k = nzb+1, nzt
-                         flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                         tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g / &
-                                       MERGE( pt_reference, pt(k,j,i),          &
-                                              use_single_reference_value ) ) *  &
-                                       diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) *  &
-                                       c_3
+                         flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                         tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /                    &
+                                       MERGE( pt_reference, pt(k,j,i),                             &
+                                              use_single_reference_value ) ) *                     &
+                                       diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) * c_3
                       ENDDO
 
@@ -3196,7 +3151,7 @@
              ENDDO
 
-          ENDIF ! from IF ( .NOT. ocean_mode )
-
-       ELSE ! or IF ( humidity )  THEN
+          ENDIF ! From IF ( .NOT. ocean_mode )
+
+       ELSE ! Or IF ( humidity )  THEN
 
           DO  i = nxl, nxr
@@ -3205,11 +3160,10 @@
                 DO  k = nzb+1, nzt
 
-                   IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
+                   IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets )  THEN
                       k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                       k2 = 0.61_wp * pt(k,j,i)
-                      tmp_flux(k) = -1.0_wp * kh(k,j,i) *                      &
-                                      ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +   &
-                                        k2 * ( q(k+1,j,i)  - q(k-1,j,i) )      &
-                                      ) * dd2zu(k)
+                      tmp_flux(k) = -1.0_wp * kh(k,j,i) * ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +   &
+                                                            k2 * ( q(k+1,j,i)  - q(k-1,j,i) ) )    &
+                                    * dd2zu(k)
                    ELSE IF ( bulk_cloud_model )  THEN
                       IF ( ql(k,j,i) == 0.0_wp )  THEN
@@ -3219,23 +3173,20 @@
                          theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
                          temp  = theta * exner(k)
-                         k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *                  &
-                                       ( q(k,j,i) - ql(k,j,i) ) *              &
-                              ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /        &
-                              ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *         &
+                         k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp * ( q(k,j,i) - ql(k,j,i) ) *           &
+                              ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /                            &
+                              ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *                             &
                               ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
                          k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                       ENDIF
-                      tmp_flux(k) = -1.0_wp * kh(k,j,i) *                      &
-                                      ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +   &
-                                        k2 * ( q(k+1,j,i)  - q(k-1,j,i) )      &
-                                      ) * dd2zu(k)
+                      tmp_flux(k) = -1.0_wp * kh(k,j,i) * ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +   &
+                                                            k2 * ( q(k+1,j,i)  - q(k-1,j,i) ) )    &
+                                    * dd2zu(k)
                    ELSE IF ( cloud_droplets )  THEN
                       k1 = 1.0_wp + 0.61_wp * q(k,j,i) - ql(k,j,i)
                       k2 = 0.61_wp * pt(k,j,i)
-                      tmp_flux(k) = -1.0_wp * kh(k,j,i) * &
-                                      ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +   &
-                                        k2 * ( q(k+1,j,i)  - q(k-1,j,i) ) -    &
-                                        pt(k,j,i) * ( ql(k+1,j,i) -            &
-                                        ql(k-1,j,i) ) ) * dd2zu(k)
+                      tmp_flux(k) = -1.0_wp * kh(k,j,i) * ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +   &
+                                                            k2 * ( q(k+1,j,i)  - q(k-1,j,i) ) -    &
+                                                            pt(k,j,i) * ( ql(k+1,j,i) -            &
+                                                            ql(k-1,j,i) ) ) * dd2zu(k)
                    ENDIF
 
@@ -3251,5 +3202,5 @@
                          k = surf_def_h(l)%k(m)
 
-                         IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
+                         IF (  .NOT.  bulk_cloud_model  .AND.  .NOT.  cloud_droplets )  THEN
                             k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                             k2 = 0.61_wp * pt(k,j,i)
@@ -3261,9 +3212,8 @@
                                theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
                                temp  = theta * exner(k)
-                               k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *            &
-                                          ( q(k,j,i) - ql(k,j,i) ) *           &
-                                 ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /     &
-                                 ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *      &
-                                 ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
+                               k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp * ( q(k,j,i) - ql(k,j,i) ) *     &
+                                    ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /                      &
+                                    ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *                       &
+                                    ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
                                k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                             ENDIF
@@ -3273,7 +3223,6 @@
                          ENDIF
 
-                         tmp_flux(k) = ( k1 * surf_def_h(l)%shf(m) +           &
-                                         k2 * surf_def_h(l)%qsws(m)            &
-                                       ) * drho_air_zw(k-1)
+                         tmp_flux(k) = ( k1 * surf_def_h(l)%shf(m) + k2 * surf_def_h(l)%qsws(m) )  &
+                                         * drho_air_zw(k-1)
                       ENDDO
                    ENDDO
@@ -3285,5 +3234,5 @@
                       k = surf_lsm_h%k(m)
 
-                      IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
+                      IF (  .NOT.  bulk_cloud_model  .AND.  .NOT.  cloud_droplets )  THEN
                          k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                          k2 = 0.61_wp * pt(k,j,i)
@@ -3295,8 +3244,7 @@
                             theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
                             temp  = theta * exner(k)
-                            k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *               &
-                                          ( q(k,j,i) - ql(k,j,i) ) *           &
-                                 ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /     &
-                                 ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *      &
+                            k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp * ( q(k,j,i) - ql(k,j,i) ) *        &
+                                 ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /                         &
+                                 ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *                          &
                                  ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
                             k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
@@ -3307,7 +3255,6 @@
                       ENDIF
 
-                      tmp_flux(k) = ( k1 * surf_lsm_h%shf(m) +                 &
-                                      k2 * surf_lsm_h%qsws(m)                  &
-                                    ) * drho_air_zw(k-1)
+                      tmp_flux(k) = ( k1 * surf_lsm_h%shf(m) + k2 * surf_lsm_h%qsws(m) )           &
+                                    * drho_air_zw(k-1)
                    ENDDO
 !
@@ -3318,5 +3265,5 @@
                       k = surf_usm_h%k(m)
 
-                      IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
+                      IF ( .NOT. bulk_cloud_model  .AND.  .NOT. cloud_droplets )  THEN
                          k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                          k2 = 0.61_wp * pt(k,j,i)
@@ -3328,8 +3275,7 @@
                             theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
                             temp  = theta * exner(k)
-                            k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *               &
-                                          ( q(k,j,i) - ql(k,j,i) ) *           &
-                                 ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /     &
-                                 ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *      &
+                            k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp * ( q(k,j,i) - ql(k,j,i) ) *        &
+                                 ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /                         &
+                                 ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *                          &
                                  ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
                             k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
@@ -3340,10 +3286,9 @@
                       ENDIF
 
-                      tmp_flux(k) = ( k1 * surf_usm_h%shf(m) +                 &
-                                      k2 * surf_usm_h%qsws(m)                  &
-                                    ) * drho_air_zw(k-1)
+                      tmp_flux(k) = ( k1 * surf_usm_h%shf(m) + k2 * surf_usm_h%qsws(m) )           &
+                                    * drho_air_zw(k-1)
                    ENDDO
 
-                ENDIF ! from IF ( use_surface_fluxes )  THEN
+                ENDIF ! From IF ( use_surface_fluxes )  THEN
 
                 IF ( use_top_fluxes )  THEN
@@ -3354,5 +3299,5 @@
                       k = surf_def_h(2)%k(m)
 
-                      IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
+                      IF ( .NOT. bulk_cloud_model  .AND.  .NOT. cloud_droplets )  THEN
                          k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                          k2 = 0.61_wp * pt(k,j,i)
@@ -3364,8 +3309,7 @@
                             theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
                             temp  = theta * exner(k)
-                            k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *               &
-                                       ( q(k,j,i) - ql(k,j,i) ) *              &
-                              ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /        &
-                              ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *         &
+                            k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp * ( q(k,j,i) - ql(k,j,i) ) *        &
+                              ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /                            &
+                              ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *                             &
                               ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
                             k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
@@ -3376,11 +3320,10 @@
                       ENDIF
 
-                      tmp_flux(k) = ( k1 * surf_def_h(2)%shf(m) +              &
-                                      k2 * surf_def_h(2)%qsws(m)               &
-                                    ) * drho_air_zw(k)
+                      tmp_flux(k) = ( k1 * surf_def_h(2)%shf(m) + k2 * surf_def_h(2)%qsws(m) )     &
+                                    * drho_air_zw(k)
 
                    ENDDO
 
-                ENDIF ! from IF ( use_top_fluxes )  THEN
+                ENDIF ! From IF ( use_top_fluxes )  THEN
 
                 IF ( .NOT. diss_production )  THEN
@@ -3388,8 +3331,7 @@
 !--                Compute tendency for TKE-production from shear
                    DO  k = nzb+1, nzt
-                      flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                      tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g / &
-                                    MERGE( vpt_reference, vpt(k,j,i),          &
-                                           use_single_reference_value ) )
+                      flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                      tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /                       &
+                                    MERGE( vpt_reference, vpt(k,j,i), use_single_reference_value ) )
                    ENDDO
 
@@ -3398,10 +3340,9 @@
 !--                RANS mode: Compute tendency for dissipation-rate-production from shear
                    DO  k = nzb+1, nzt
-                      flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                      tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /   &
-                                    MERGE( vpt_reference, vpt(k,j,i),          &
-                                           use_single_reference_value ) ) *    &
-                                    diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) *    &
-                                    c_3
+                      flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                      tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) *                             &
+                                    ( g / MERGE( vpt_reference, vpt(k,j,i),                        &
+                                                  use_single_reference_value ) )                   &
+                                   * diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) * c_3
                    ENDDO
 
@@ -3418,40 +3359,54 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Production terms (shear + buoyancy) of the TKE.
 !> Cache-optimized version
-!> @warning The case with constant_flux_layer = F and use_surface_fluxes = T is
-!>          not considered well!
-!------------------------------------------------------------------------------!
+!> @warning The case with constant_flux_layer = F and use_surface_fluxes = T is not considered well!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE production_e_ij( i, j, diss_production )
 
-    USE arrays_3d,                                                             &
-        ONLY:  ddzw, dd2zu, drho_air_zw, q, ql, d_exner, exner
-
-    USE control_parameters,                                                    &
-        ONLY:  cloud_droplets, constant_flux_layer, neutral,                   &
-               rho_reference, use_single_reference_value, use_surface_fluxes,  &
+    USE arrays_3d,                                                                                 &
+        ONLY:  ddzw,                                                                               &
+               dd2zu,                                                                              &
+               drho_air_zw,                                                                        &
+               d_exner,                                                                            &
+               exner,                                                                              &
+               q,                                                                                  &
+               ql
+
+
+
+    USE control_parameters,                                                                        &
+        ONLY:  cloud_droplets,                                                                     &
+               constant_flux_layer,                                                                &
+               neutral,                                                                            &
+               rho_reference,                                                                      &
+               use_single_reference_value,                                                         &
+               use_surface_fluxes,                                                                 &
                use_top_fluxes
 
-    USE grid_variables,                                                        &
-        ONLY:  ddx, dx, ddy, dy
-
-    USE bulk_cloud_model_mod,                                                  &
+    USE grid_variables,                                                                            &
+        ONLY:  ddx,                                                                                &
+               dx,                                                                                 &
+               ddy,                                                                                &
+               dy
+
+    USE bulk_cloud_model_mod,                                                                      &
         ONLY:  bulk_cloud_model
 
     IMPLICIT NONE
 
-    LOGICAL :: diss_production
-
-    INTEGER(iwp) ::  i       !< running index x-direction
-    INTEGER(iwp) ::  j       !< running index y-direction
-    INTEGER(iwp) ::  k       !< running index z-direction
-    INTEGER(iwp) ::  l       !< running index for different surface type orientation
-    INTEGER(iwp) ::  m       !< running index surface elements
-    INTEGER(iwp) ::  surf_e  !< end index of surface elements at given i-j position
-    INTEGER(iwp) ::  surf_s  !< start index of surface elements at given i-j position
-    INTEGER(iwp) ::  flag_nr !< number of masking flag
+    LOGICAL ::  diss_production  !<
+
+    INTEGER(iwp) ::  flag_nr  !< number of masking flag
+    INTEGER(iwp) ::  i        !< running index x-direction
+    INTEGER(iwp) ::  j        !< running index y-direction
+    INTEGER(iwp) ::  k        !< running index z-direction
+    INTEGER(iwp) ::  l        !< running index for different surface type orientation
+    INTEGER(iwp) ::  m        !< running index surface elements
+    INTEGER(iwp) ::  surf_e   !< end index of surface elements at given i-j position
+    INTEGER(iwp) ::  surf_s   !< start index of surface elements at given i-j position
 
     REAL(wp)     ::  def         !< ( du_i/dx_j + du_j/dx_i ) * du_i/dx_j
@@ -3460,7 +3415,7 @@
     REAL(wp)     ::  k2          !< temporary factor
     REAL(wp)     ::  km_neutral  !< diffusion coefficient assuming neutral conditions - used to compute shear production at surfaces
+    REAL(wp)     ::  sign_dir    !< sign of wall-tke flux, depending on wall orientation
     REAL(wp)     ::  theta       !< virtual potential temperature
     REAL(wp)     ::  temp        !< theta * Exner-function
-    REAL(wp)     ::  sign_dir    !< sign of wall-tke flux, depending on wall orientation
     REAL(wp)     ::  usvs        !< momentum flux u"v"
     REAL(wp)     ::  vsus        !< momentum flux v"u"
@@ -3468,13 +3423,13 @@
     REAL(wp)     ::  wsvs        !< momentum flux w"v"
 
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudx  !< Gradient of u-component in x-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudy  !< Gradient of u-component in y-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudz  !< Gradient of u-component in z-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdx  !< Gradient of v-component in x-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdy  !< Gradient of v-component in y-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdz  !< Gradient of v-component in z-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdx  !< Gradient of w-component in x-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdy  !< Gradient of w-component in y-direction
-    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdz  !< Gradient of w-component in z-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudx      !< Gradient of u-component in x-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudy      !< Gradient of u-component in y-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dudz      !< Gradient of u-component in z-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdx      !< Gradient of v-component in x-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdy      !< Gradient of v-component in y-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dvdz      !< Gradient of v-component in z-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdx      !< Gradient of w-component in x-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdy      !< Gradient of w-component in y-direction
+    REAL(wp), DIMENSION(nzb+1:nzt) ::  dwdz      !< Gradient of w-component in z-direction
     REAL(wp), DIMENSION(nzb+1:nzt) ::  tmp_flux  !< temporary flux-array in z-direction
 
@@ -3482,25 +3437,18 @@
 
 !
-!-- Calculate TKE production by shear. Calculate gradients at all grid
-!-- points first, gradients at surface-bounded grid points will be
-!-- overwritten further below.
+!-- Calculate TKE production by shear. Calculate gradients at all grid points first, gradients at
+!-- surface-bounded grid points will be overwritten further below.
     DO  k = nzb+1, nzt
 
        dudx(k) =           ( u(k,j,i+1) - u(k,j,i)     ) * ddx
-       dudy(k) = 0.25_wp * ( u(k,j+1,i) + u(k,j+1,i+1) -                 &
-                             u(k,j-1,i) - u(k,j-1,i+1) ) * ddy
-       dudz(k) = 0.5_wp  * ( u(k+1,j,i) + u(k+1,j,i+1) -                 &
-                             u(k-1,j,i) - u(k-1,j,i+1) ) * dd2zu(k)
-
-       dvdx(k) = 0.25_wp * ( v(k,j,i+1) + v(k,j+1,i+1) -                 &
-                             v(k,j,i-1) - v(k,j+1,i-1) ) * ddx
+       dudy(k) = 0.25_wp * ( u(k,j+1,i) + u(k,j+1,i+1) - u(k,j-1,i) - u(k,j-1,i+1) ) * ddy
+       dudz(k) = 0.5_wp  * ( u(k+1,j,i) + u(k+1,j,i+1) - u(k-1,j,i) - u(k-1,j,i+1) ) * dd2zu(k)
+
+       dvdx(k) = 0.25_wp * ( v(k,j,i+1) + v(k,j+1,i+1) - v(k,j,i-1) - v(k,j+1,i-1) ) * ddx
        dvdy(k) =           ( v(k,j+1,i) - v(k,j,i)     ) * ddy
-       dvdz(k) = 0.5_wp  * ( v(k+1,j,i) + v(k+1,j+1,i) -                 &
-                             v(k-1,j,i) - v(k-1,j+1,i) ) * dd2zu(k)
-
-       dwdx(k) = 0.25_wp * ( w(k,j,i+1) + w(k-1,j,i+1) -                 &
-                             w(k,j,i-1) - w(k-1,j,i-1) ) * ddx
-       dwdy(k) = 0.25_wp * ( w(k,j+1,i) + w(k-1,j+1,i) -                 &
-                             w(k,j-1,i) - w(k-1,j-1,i) ) * ddy
+       dvdz(k) = 0.5_wp  * ( v(k+1,j,i) + v(k+1,j+1,i) - v(k-1,j,i) - v(k-1,j+1,i) ) * dd2zu(k)
+
+       dwdx(k) = 0.25_wp * ( w(k,j,i+1) + w(k-1,j,i+1) - w(k,j,i-1) - w(k-1,j,i-1) ) * ddx
+       dwdy(k) = 0.25_wp * ( w(k,j+1,i) + w(k-1,j+1,i) - w(k,j-1,i) - w(k-1,j-1,i) ) * ddy
        dwdz(k) =           ( w(k,j,i)   - w(k-1,j,i)   ) * ddzw(k)
 
@@ -3517,7 +3465,6 @@
 !--    'bottom and wall: use u_0,v_0 and wall functions'
 !
-!--    Compute gradients at north- and south-facing surfaces.
-!--    First, for default surfaces, then for urban surfaces.
-!--    Note, so far no natural vertical surfaces implemented
+!--    Compute gradients at north- and south-facing surfaces. First, for default surfaces, then for
+!--    urban surfaces. Note, so far no natural vertical surfaces implemented
        DO  l = 0, 1
           surf_s = surf_def_v(l)%start_index(j,i)
@@ -3528,10 +3475,8 @@
              wsvs        = surf_def_v(l)%mom_flux_tke(1,m)
 
-             km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp         &
-                                * 0.5_wp * dy
+             km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp * 0.5_wp * dy
 !
 !--          -1.0 for right-facing wall, 1.0 for left-facing wall
-             sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                        BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
+             sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
              dudy(k) = sign_dir * usvs / ( km_neutral + 1E-10_wp )
              dwdy(k) = sign_dir * wsvs / ( km_neutral + 1E-10_wp )
@@ -3546,10 +3491,8 @@
              wsvs        = surf_lsm_v(l)%mom_flux_tke(1,m)
 
-             km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp         &
-                                * 0.5_wp * dy
+             km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp * 0.5_wp * dy
 !
 !--          -1.0 for right-facing wall, 1.0 for left-facing wall
-             sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                        BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
+             sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
              dudy(k) = sign_dir * usvs / ( km_neutral + 1E-10_wp )
              dwdy(k) = sign_dir * wsvs / ( km_neutral + 1E-10_wp )
@@ -3564,10 +3507,8 @@
              wsvs        = surf_usm_v(l)%mom_flux_tke(1,m)
 
-             km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp         &
-                                * 0.5_wp * dy
+             km_neutral = kappa * ( usvs**2 + wsvs**2 )**0.25_wp * 0.5_wp * dy
 !
 !--          -1.0 for right-facing wall, 1.0 for left-facing wall
-             sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                        BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
+             sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j-1,i), flag_nr ) )
              dudy(k) = sign_dir * usvs / ( km_neutral + 1E-10_wp )
              dwdy(k) = sign_dir * wsvs / ( km_neutral + 1E-10_wp )
@@ -3584,10 +3525,8 @@
              wsus  = surf_def_v(l)%mom_flux_tke(1,m)
 
-             km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp         &
-                                * 0.5_wp * dx
+             km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp * 0.5_wp * dx
 !
 !--          -1.0 for right-facing wall, 1.0 for left-facing wall
-             sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                        BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
+             sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
              dvdx(k) = sign_dir * vsus / ( km_neutral + 1E-10_wp )
              dwdx(k) = sign_dir * wsus / ( km_neutral + 1E-10_wp )
@@ -3602,10 +3541,8 @@
              wsus  = surf_lsm_v(l)%mom_flux_tke(1,m)
 
-             km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp         &
-                                * 0.5_wp * dx
+             km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp * 0.5_wp * dx
 !
 !--          -1.0 for right-facing wall, 1.0 for left-facing wall
-             sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                        BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
+             sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
              dvdx(k) = sign_dir * vsus / ( km_neutral + 1E-10_wp )
              dwdx(k) = sign_dir * wsus / ( km_neutral + 1E-10_wp )
@@ -3620,10 +3557,8 @@
              wsus  = surf_usm_v(l)%mom_flux_tke(1,m)
 
-             km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp         &
-                                * 0.5_wp * dx
+             km_neutral = kappa * ( vsus**2 + wsus**2 )**0.25_wp * 0.5_wp * dx
 !
 !--          -1.0 for right-facing wall, 1.0 for left-facing wall
-             sign_dir = MERGE( 1.0_wp, -1.0_wp,                          &
-                        BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
+             sign_dir = MERGE( 1.0_wp, -1.0_wp, BTEST( wall_flags_total_0(k,j,i-1), flag_nr ) )
              dvdx(k) = sign_dir * vsus / ( km_neutral + 1E-10_wp )
              dwdx(k) = sign_dir * wsus / ( km_neutral + 1E-10_wp )
@@ -3637,9 +3572,7 @@
           k = surf_def_h(0)%k(m)
 !
-!--       Please note, actually, an interpolation of u_0 and v_0
-!--       onto the grid center would be required. However, this
-!--       would require several data transfers between 2D-grid and
-!--       wall type. The effect of this missing interpolation is
-!--       negligible. (See also production_e_init).
+!--       Please note, actually, an interpolation of u_0 and v_0 onto the grid center would be
+!--       required. However, this would require several data transfers between 2D-grid and wall
+!--       type. The effect of this missing interpolation is negligible. (See also production_e_init).
           dudz(k) = ( u(k+1,j,i) - surf_def_h(0)%u_0(m) ) * dd2zu(k)
           dvdz(k) = ( v(k+1,j,i) - surf_def_h(0)%v_0(m) ) * dd2zu(k)
@@ -3669,6 +3602,5 @@
        ENDDO
 !
-!--    Compute gradients at downward-facing walls, only for
-!--    non-natural default surfaces
+!--    Compute gradients at downward-facing walls, only for non-natural default surfaces
        surf_s = surf_def_h(1)%start_index(j,i)
        surf_e = surf_def_h(1)%end_index(j,i)
@@ -3685,9 +3617,8 @@
     DO  k = nzb+1, nzt
 
-       def = 2.0_wp * ( dudx(k)**2 + dvdy(k)**2 + dwdz(k)**2 ) +         &
-                        dudy(k)**2 + dvdx(k)**2 + dwdx(k)**2 +           &
-                        dwdy(k)**2 + dudz(k)**2 + dvdz(k)**2 +           &
-             2.0_wp * ( dvdx(k)*dudy(k) + dwdx(k)*dudz(k) +              &
-                        dwdy(k)*dvdz(k) )
+       def = 2.0_wp * ( dudx(k)**2 + dvdy(k)**2 + dwdz(k)**2 ) +                                   &
+                        dudy(k)**2 + dvdx(k)**2 + dwdx(k)**2 +                                     &
+                        dwdy(k)**2 + dudz(k)**2 + dvdz(k)**2 +                                     &
+             2.0_wp * ( dvdx(k)*dudy(k) + dwdx(k)*dudz(k) + dwdy(k)*dvdz(k) )
 
        IF ( def < 0.0_wp )  def = 0.0_wp
@@ -3703,6 +3634,6 @@
 
 !--       RANS mode: Compute tendency for dissipation-rate-production from shear
-          tend(k,j,i) = tend(k,j,i) + km(k,j,i) * def * flag *           &
-                        diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) * c_1
+          tend(k,j,i) = tend(k,j,i) + km(k,j,i) * def * flag *                                     &
+                        diss(k,j,i) / ( e(k,j,i) + 1.0E-20_wp ) * c_1
 
        ENDIF
@@ -3718,12 +3649,11 @@
           IF ( ocean_mode )  THEN
 !
-!--          So far in the ocean no special treatment of density flux
-!--          in the bottom and top surface layer
+!--          So far in the ocean no special treatment of density flux in the bottom and top surface
+!--          layer
              DO  k = nzb+1, nzt
                 tmp_flux(k) = kh(k,j,i) * ( prho(k+1,j,i) - prho(k-1,j,i) ) * dd2zu(k)
              ENDDO
 !
-!--          Treatment of near-surface grid points, at up- and down-
-!--          ward facing surfaces
+!--          Treatment of near-surface grid points, at up- and down- ward facing surfaces
              IF ( use_surface_fluxes )  THEN
                 DO  l = 0, 1
@@ -3750,8 +3680,7 @@
 !--             Compute tendency for TKE-production from shear
                 DO  k = nzb+1, nzt
-                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                   tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g / &
-                                 MERGE( rho_reference, prho(k,j,i),       &
-                                        use_single_reference_value ) )
+                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                   tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /                          &
+                                 MERGE( rho_reference, prho(k,j,i), use_single_reference_value ) )
                 ENDDO
 
@@ -3760,10 +3689,9 @@
 !--             RANS mode: Compute tendency for dissipation-rate-production from shear
                 DO  k = nzb+1, nzt
-                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                   tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g / &
-                                 MERGE( rho_reference, prho(k,j,i),       &
-                                        use_single_reference_value ) ) *  &
-                                 diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) *  &
-                                 c_3
+                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                   tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /                          &
+                                 MERGE( rho_reference, prho(k,j,i),                                &
+                                 use_single_reference_value ) ) *                                  &
+                                 diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) * c_3
                 ENDDO
 
@@ -3819,8 +3747,7 @@
 !--             Compute tendency for TKE-production from shear
                 DO  k = nzb+1, nzt
-                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                   tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g / &
-                                 MERGE( pt_reference, pt(k,j,i),          &
-                                        use_single_reference_value ) )
+                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                   tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /                          &
+                                 MERGE( pt_reference, pt(k,j,i), use_single_reference_value ) )
                 ENDDO
 
@@ -3829,27 +3756,24 @@
 !--             RANS mode: Compute tendency for dissipation-rate-production from shear
                 DO  k = nzb+1, nzt
-                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                   tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g / &
-                                 MERGE( pt_reference, pt(k,j,i),          &
-                                        use_single_reference_value ) ) *  &
-                                 diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) *  &
-                                 c_3
+                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                   tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /                          &
+                                 MERGE( pt_reference, pt(k,j,i),                                   &
+                                        use_single_reference_value ) ) *                           &
+                                 diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) * c_3
                 ENDDO
 
              ENDIF
 
-          ENDIF ! from IF ( .NOT. ocean_mode )
-
-       ELSE ! or IF ( humidity )  THEN
+          ENDIF ! From IF ( .NOT. ocean_mode )
+
+       ELSE ! Or IF ( humidity )  THEN
 
           DO  k = nzb+1, nzt
 
-             IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
+             IF ( .NOT. bulk_cloud_model  .AND.  .NOT. cloud_droplets )  THEN
                 k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                 k2 = 0.61_wp * pt(k,j,i)
-                tmp_flux(k) = -1.0_wp * kh(k,j,i) *                      &
-                                ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +   &
-                                  k2 * ( q(k+1,j,i)  - q(k-1,j,i) )      &
-                                ) * dd2zu(k)
+                tmp_flux(k) = -1.0_wp * kh(k,j,i) * ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +         &
+                                                      k2 * ( q(k+1,j,i)  - q(k-1,j,i) ) ) * dd2zu(k)
              ELSE IF ( bulk_cloud_model )  THEN
                 IF ( ql(k,j,i) == 0.0_wp )  THEN
@@ -3859,23 +3783,19 @@
                    theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
                    temp  = theta * exner(k)
-                   k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *                  &
-                                 ( q(k,j,i) - ql(k,j,i) ) *              &
-                        ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /        &
-                        ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *         &
+                   k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp * ( q(k,j,i) - ql(k,j,i) ) *                 &
+                        ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /                                  &
+                        ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *                                   &
                         ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
                    k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                 ENDIF
-                tmp_flux(k) = -1.0_wp * kh(k,j,i) *                      &
-                                ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +   &
-                                  k2 * ( q(k+1,j,i)  - q(k-1,j,i) )      &
-                                ) * dd2zu(k)
+                tmp_flux(k) = -1.0_wp * kh(k,j,i) * ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +         &
+                                                      k2 * ( q(k+1,j,i)  - q(k-1,j,i) ) ) * dd2zu(k)
              ELSE IF ( cloud_droplets )  THEN
                 k1 = 1.0_wp + 0.61_wp * q(k,j,i) - ql(k,j,i)
                 k2 = 0.61_wp * pt(k,j,i)
-                tmp_flux(k) = -1.0_wp * kh(k,j,i) * &
-                                ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +   &
-                                  k2 * ( q(k+1,j,i)  - q(k-1,j,i) ) -    &
-                                  pt(k,j,i) * ( ql(k+1,j,i) -            &
-                                  ql(k-1,j,i) ) ) * dd2zu(k)
+                tmp_flux(k) = -1.0_wp * kh(k,j,i) * ( k1 * ( pt(k+1,j,i) - pt(k-1,j,i) ) +         &
+                                                      k2 * ( q(k+1,j,i)  - q(k-1,j,i) ) -          &
+                                                      pt(k,j,i) * ( ql(k+1,j,i) -                  &
+                                                      ql(k-1,j,i) ) ) * dd2zu(k)
              ENDIF
 
@@ -3891,5 +3811,5 @@
                    k = surf_def_h(l)%k(m)
 
-                   IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
+                   IF ( .NOT. bulk_cloud_model  .AND.  .NOT. cloud_droplets )  THEN
                       k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                       k2 = 0.61_wp * pt(k,j,i)
@@ -3901,9 +3821,8 @@
                          theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
                          temp  = theta * exner(k)
-                         k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *            &
-                                    ( q(k,j,i) - ql(k,j,i) ) *           &
-                           ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /     &
-                           ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *      &
-                           ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
+                         k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp * ( q(k,j,i) - ql(k,j,i) ) *           &
+                              ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /                            &
+                              ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *                             &
+                              ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
                          k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                       ENDIF
@@ -3913,7 +3832,6 @@
                    ENDIF
 
-                   tmp_flux(k) = ( k1 * surf_def_h(l)%shf(m) +           &
-                                   k2 * surf_def_h(l)%qsws(m)            &
-                                 ) * drho_air_zw(k-1)
+                   tmp_flux(k) = ( k1 * surf_def_h(l)%shf(m) + k2 * surf_def_h(l)%qsws(m) ) *      &
+                                 drho_air_zw(k-1)
                 ENDDO
              ENDDO
@@ -3925,5 +3843,5 @@
                 k = surf_lsm_h%k(m)
 
-                IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
+                IF ( .NOT. bulk_cloud_model  .AND.  .NOT. cloud_droplets )  THEN
                    k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                    k2 = 0.61_wp * pt(k,j,i)
@@ -3935,8 +3853,7 @@
                       theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
                       temp  = theta * exner(k)
-                      k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *               &
-                                    ( q(k,j,i) - ql(k,j,i) ) *           &
-                           ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /     &
-                           ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *      &
+                      k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp * ( q(k,j,i) - ql(k,j,i) ) *              &
+                           ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /                               &
+                           ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *                                &
                            ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
                       k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
@@ -3947,7 +3864,6 @@
                 ENDIF
 
-                tmp_flux(k) = ( k1 * surf_lsm_h%shf(m) +                 &
-                                k2 * surf_lsm_h%qsws(m)                  &
-                              ) * drho_air_zw(k-1)
+                tmp_flux(k) = ( k1 * surf_lsm_h%shf(m) + k2 * surf_lsm_h%qsws(m) ) *               &
+                              drho_air_zw(k-1)
              ENDDO
 !
@@ -3958,5 +3874,5 @@
                 k = surf_usm_h%k(m)
 
-                IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
+                IF ( .NOT. bulk_cloud_model  .AND.  .NOT. cloud_droplets )  THEN
                    k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                    k2 = 0.61_wp * pt(k,j,i)
@@ -3968,8 +3884,7 @@
                       theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
                       temp  = theta * exner(k)
-                      k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *               &
-                                    ( q(k,j,i) - ql(k,j,i) ) *           &
-                           ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /     &
-                           ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *      &
+                      k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp * ( q(k,j,i) - ql(k,j,i) ) *              &
+                           ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /                               &
+                           ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *                                &
                            ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
                       k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
@@ -3980,10 +3895,9 @@
                 ENDIF
 
-                tmp_flux(k) = ( k1 * surf_usm_h%shf(m) +                 &
-                                k2 * surf_usm_h%qsws(m)                  &
-                              ) * drho_air_zw(k-1)
-             ENDDO
-
-          ENDIF ! from IF ( use_surface_fluxes )  THEN
+                tmp_flux(k) = ( k1 * surf_usm_h%shf(m) + k2 * surf_usm_h%qsws(m) ) *               &
+                              drho_air_zw(k-1)
+             ENDDO
+
+          ENDIF ! From IF ( use_surface_fluxes )  THEN
 
           IF ( use_top_fluxes )  THEN
@@ -3994,5 +3908,5 @@
                 k = surf_def_h(2)%k(m)
 
-                IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
+                IF ( .NOT. bulk_cloud_model  .AND.  .NOT. cloud_droplets )  THEN
                    k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                    k2 = 0.61_wp * pt(k,j,i)
@@ -4004,8 +3918,7 @@
                       theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
                       temp  = theta * exner(k)
-                      k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *               &
-                                 ( q(k,j,i) - ql(k,j,i) ) *              &
-                        ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /        &
-                        ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *         &
+                      k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp * ( q(k,j,i) - ql(k,j,i) ) *              &
+                        ( 1.0_wp + rd_d_rv * lv_d_rd / temp ) ) /                                  &
+                        ( 1.0_wp + rd_d_rv * lv_d_rd * lv_d_cp *                                   &
                         ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
                       k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
@@ -4016,11 +3929,10 @@
                 ENDIF
 
-                tmp_flux(k) = ( k1 * surf_def_h(2)%shf(m) +              &
-                                k2 * surf_def_h(2)%qsws(m)               &
-                              ) * drho_air_zw(k)
-
-             ENDDO
-
-          ENDIF ! from IF ( use_top_fluxes )  THEN
+                tmp_flux(k) = ( k1 * surf_def_h(2)%shf(m) + k2 * surf_def_h(2)%qsws(m) ) *         &
+                              drho_air_zw(k)
+
+             ENDDO
+
+          ENDIF ! From IF ( use_top_fluxes )  THEN
 
           IF ( .NOT. diss_production )  THEN
@@ -4029,7 +3941,6 @@
              DO  k = nzb+1, nzt
                 flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g / &
-                              MERGE( vpt_reference, vpt(k,j,i),        &
-                                     use_single_reference_value ) )
+                tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /                             &
+                              MERGE( vpt_reference, vpt(k,j,i), use_single_reference_value ) )
              ENDDO
 
@@ -4039,9 +3950,8 @@
              DO  k = nzb+1, nzt
                 flag = MERGE( 1.0_wp, 0.0_wp, BTEST(wall_flags_total_0(k,j,i),0) )
-                tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /   &
-                              MERGE( vpt_reference, vpt(k,j,i),          &
-                                     use_single_reference_value ) ) *    &
-                              diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) *    &
-                              c_3
+                tend(k,j,i) = tend(k,j,i) + flag * tmp_flux(k) * ( g /                             &
+                              MERGE( vpt_reference, vpt(k,j,i),                                    &
+                                     use_single_reference_value ) ) *                              &
+                              diss(k,j,i)/( e(k,j,i) + 1.0E-20_wp ) * c_3
              ENDDO
 
@@ -4055,36 +3965,42 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Diffusion and dissipation terms for the TKE.
 !> Vector-optimized version
-!> @todo Try to avoid the usage of the 3d-array 'diss' where possible (case les
-!>       and rans_tke_l if not wang_kernel, use_sgs_for_particles, or
-!>       collision_turbulence).
-!------------------------------------------------------------------------------!
+!> @todo Try to avoid the usage of the 3d-array 'diss' where possible (case les and rans_tke_l if
+!> not wang_kernel, use_sgs_for_particles, or collision_turbulence).
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE diffusion_e( var, var_reference )
 
-    USE arrays_3d,                                                             &
-        ONLY:  dd2zu, ddzu, ddzw, drho_air, rho_air_zw
-
-    USE control_parameters,                                                    &
-        ONLY:  atmos_ocean_sign, use_single_reference_value
-
-    USE grid_variables,                                                        &
-        ONLY:  ddx2, ddy2
-
-    USE bulk_cloud_model_mod,                                                  &
+    USE arrays_3d,                                                                                 &
+        ONLY:  dd2zu,                                                                              &
+               ddzu,                                                                               &
+               ddzw,                                                                               &
+               drho_air,                                                                           &
+               rho_air_zw
+
+    USE control_parameters,                                                                        &
+        ONLY:  atmos_ocean_sign,                                                                   &
+               use_single_reference_value
+
+    USE grid_variables,                                                                            &
+        ONLY:  ddx2,                                                                               &
+               ddy2
+
+    USE bulk_cloud_model_mod,                                                                      &
         ONLY:  collision_turbulence
 
-    USE particle_attributes,                                                   &
-        ONLY:  use_sgs_for_particles, wang_kernel
+    USE particle_attributes,                                                                       &
+        ONLY:  use_sgs_for_particles,                                                              &
+               wang_kernel
 
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i              !< running index x direction
-    INTEGER(iwp) ::  j              !< running index y direction
-    INTEGER(iwp) ::  k              !< running index z direction
-    INTEGER(iwp) ::  m              !< running index surface elements
+    INTEGER(iwp) ::  i  !< running index x direction
+    INTEGER(iwp) ::  j  !< running index y direction
+    INTEGER(iwp) ::  k  !< running index z direction
+    INTEGER(iwp) ::  m  !< running index surface elements
 
     REAL(wp)     ::  duv2_dz2       !< squared vertical gradient of wind vector
@@ -4112,11 +4028,11 @@
 
                 dvar_dz = atmos_ocean_sign * ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k)
-                IF ( dvar_dz > 0.0_wp ) THEN
+                IF ( dvar_dz > 0.0_wp )  THEN
                    IF ( use_single_reference_value )  THEN
-                     ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )         &
-                                 / SQRT( g / var_reference * dvar_dz ) + 1E-5_wp
+                     ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) ) /                           &
+                                            SQRT( g / var_reference * dvar_dz ) + 1E-5_wp
                    ELSE
-                     ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )         &
-                                 / SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp
+                     ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) ) /                           &
+                                            SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp
                    ENDIF
                 ELSE
@@ -4127,6 +4043,7 @@
 
 !
-!--          ATTENTION: Don't merge the following loop with the previous one, because this would prohibit proper vectorization by
-!--          the Intel18 compiler. This behaviour might change for future compiler versions.
+!--          ATTENTION: Don't merge the following loop with the previous one, because this would
+!--          prohibit proper vectorization by the Intel18 compiler. This behaviour might change for
+!--          future compiler versions.
              !$ACC LOOP PRIVATE(k)
              !DIR$ IVDEP
@@ -4135,6 +4052,6 @@
                 ml = MIN( delta(k,j,i), ml_stratification(k) )
 
-                diss(k,j,i) = ( 0.19_wp + 0.74_wp * ml / delta(k,j,i) )           &
-                              * e(k,j,i) * SQRT( e(k,j,i) ) / ml                             &
+                diss(k,j,i) = ( 0.19_wp + 0.74_wp * ml / delta(k,j,i) ) * e(k,j,i)                 &
+                              * SQRT( e(k,j,i) ) / ml                                              &
                               * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
 
@@ -4155,17 +4072,16 @@
              DO  k = nzb+1, nzt
                 dvar_dz = atmos_ocean_sign * ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k)
-                IF ( dvar_dz > 0.0_wp ) THEN
-!
-!--                The mixing length is calculated as 1/l = 1/(kappa*z) + 1/Lb, where Lb is
-!--                the stratification term. 1E-5 is added as l is zero at the beginning of
-!--                the simulation.
+                IF ( dvar_dz > 0.0_wp )  THEN
+!
+!--                The mixing length is calculated as 1/l = 1/(kappa*z) + 1/Lb, where Lb is the
+!--                stratification term. 1E-5 is added as l is zero at the beginning of the simulation.
                    IF ( use_single_reference_value )  THEN
-                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) ) &
+                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                            &
                                              / SQRT( g / var_reference * dvar_dz ) + 1E-5_wp
                    ELSE
-                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) ) &
+                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                            &
                                              / SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp
                    ENDIF
-                   ml_stratification(k) = 1.0_wp / ( 1.0_wp / ( kappa * distance_to_wall(k,j,i) ) &
+                   ml_stratification(k) = 1.0_wp / ( 1.0_wp / ( kappa * distance_to_wall(k,j,i) )  &
                                                    + 1.0_wp / ml_stratification(k) )
                 ELSE
@@ -4176,6 +4092,7 @@
 
 !
-!--          ATTENTION: Don't merge the following loop with the previous one, because this would prohibit proper vectorization by
-!--          the Intel18 compiler. This behaviour might change for future compiler versions.
+!--          ATTENTION: Don't merge the following loop with the previous one, because this would
+!--          prohibit proper vectorization by the Intel18 compiler. This behaviour might change for
+!--          future compiler versions.
              !$ACC LOOP PRIVATE(k)
              !DIR$ IVDEP
@@ -4183,6 +4100,6 @@
 
                 ml          = ml_stratification(k)
-                diss(k,j,i) = ( 0.19_wp + 0.74_wp * ml / delta(k,j,i) )                      &
-                              * e(k,j,i) * SQRT( e(k,j,i) ) / ml                             &
+                diss(k,j,i) = ( 0.19_wp + 0.74_wp * ml / delta(k,j,i) )                            &
+                              * e(k,j,i) * SQRT( e(k,j,i) ) / ml                                   &
                               * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
 
@@ -4208,7 +4125,6 @@
                    dvar_dz = atmos_ocean_sign * ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k)
 
-                   duv2_dz2 =   ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2  &
-                              + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2  &
-                              + 1E-30_wp
+                   duv2_dz2 = ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2                        &
+                            + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2 + 1E-30_wp
 
                    rif(k) = MIN( MAX( g / var_reference * dvar_dz / duv2_dz2, -5.0_wp ),  1.0_wp )
@@ -4216,6 +4132,7 @@
              ELSE
 !
-!--             ATTENTION: Don't merge the following loops with the previous one, because this would prohibit proper vectorization
-!--             by the Intel18 compiler. This behaviour might change for future compiler versions.
+!--             ATTENTION: Don't merge the following loops with the previous one, because this would
+!--             prohibit proper vectorization by the Intel18 compiler. This behaviour might change
+!--             for future compiler versions.
                 !$ACC LOOP PRIVATE(k)
                 DO  k = nzb+1, nzt
@@ -4223,7 +4140,6 @@
                    dvar_dz = atmos_ocean_sign * ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k)
 
-                   duv2_dz2 =   ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2  &
-                              + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2  &
-                              + 1E-30_wp
+                   duv2_dz2 = ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2                        &
+                            + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2 + 1E-30_wp
 
                    rif(k) = MIN( MAX( g / var(k,j,i) * dvar_dz / duv2_dz2, -5.0_wp ),  1.0_wp )
@@ -4245,6 +4161,6 @@
              DO  k = nzb+1, nzt
 
-                diss(k,j,i) = c_0**3 * e(k,j,i) * SQRT( e(k,j,i) )                         &
-                            / MIN( ml_stratification(k), delta(k,j,i) )                    &
+                diss(k,j,i) = c_0**3 * e(k,j,i) * SQRT( e(k,j,i) )                                 &
+                            / MIN( ml_stratification(k), delta(k,j,i) )                            &
                             * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
 
@@ -4254,6 +4170,5 @@
        ENDDO
 
-!-- Note, in case of rans_tke_e, the dissipation is already calculated
-!-- in prognostic_equations
+!-- Note, in case of rans_tke_e, the dissipation is already calculated in prognostic_equations
     ENDIF
 
@@ -4265,22 +4180,17 @@
           DO  k = nzb+1, nzt
 
-             tend(k,j,i) = tend(k,j,i) + (                                            &
-                                           (                                          &
-                       ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) )            &
-                     - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) )            &
-                                           ) * ddx2                                   &
-                                         + (                                          &
-                       ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) )            &
-                     - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) )            &
-                                           ) * ddy2                                   &
-                                         + (                                          &
-            ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) ) * ddzu(k+1)           &
-                                                          * rho_air_zw(k)             &
-          - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) ) * ddzu(k)             &
-                                                          * rho_air_zw(k-1)           &
-                                           ) * ddzw(k) * drho_air(k)                  &
-                                         ) * dsig_e                                   &
-                                           * MERGE( 1.0_wp, 0.0_wp,                   &
-                                             BTEST( wall_flags_total_0(k,j,i), 0 ) )  &
+             tend(k,j,i) = tend(k,j,i) + ( ( ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) )   &
+                                           - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) )   &
+                                           ) * ddx2                                                &
+                                         + ( ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) )   &
+                                           - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) )   &
+                                           ) * ddy2                                                &
+                                         + ( ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) )   &
+                                               * ddzu(k+1) * rho_air_zw(k)                         &
+                                         - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) )     &
+                                             * ddzu(k) * rho_air_zw(k-1)                           &
+                                           ) * ddzw(k) * drho_air(k)                               &
+                                         ) * dsig_e * MERGE( 1.0_wp, 0.0_wp,                       &
+                                                      BTEST( wall_flags_total_0(k,j,i), 0 ) )      &
                           - diss(k,j,i)
 
@@ -4291,8 +4201,8 @@
 !
 !-- Neumann boundary condition for dissipation diss(nzb,:,:) = diss(nzb+1,:,:).
-!-- Note, bc cannot be set in tcm_boundary conditions as the dissipation
-!-- in LES mode is only a diagnostic quantity.
-    IF ( .NOT. rans_tke_e .AND. ( use_sgs_for_particles  .OR.                  &
-         wang_kernel  .OR.  collision_turbulence  ) )  THEN
+!-- Note, bc cannot be set in tcm_boundary conditions as the dissipation in LES mode is only a
+!-- diagnostic quantity.
+    IF ( .NOT. rans_tke_e  .AND.                                                                   &
+         ( use_sgs_for_particles  .OR.  wang_kernel  .OR.  collision_turbulence  ) )  THEN
 !
 !--    Upward facing surfaces
@@ -4317,38 +4227,44 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Diffusion and dissipation terms for the TKE.
 !> Cache-optimized version
-!> @todo Try to avoid the usage of the 3d-array 'diss' where possible (case les
-!>       and rans_tke_l if not wang_kernel, use_sgs_for_particles, or
-!>       collision_turbulence).
-!------------------------------------------------------------------------------!
+!> @todo Try to avoid the usage of the 3d-array 'diss' where possible (case les and rans_tke_l if
+!>  not wang_kernel, use_sgs_for_particles, or collision_turbulence).
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE diffusion_e_ij( i, j, var, var_reference )
 
-    USE arrays_3d,                                                             &
-        ONLY:  dd2zu, ddzu, ddzw, drho_air, rho_air_zw
-
-    USE control_parameters,                                                    &
-        ONLY:  atmos_ocean_sign, use_single_reference_value
-
-    USE grid_variables,                                                        &
-        ONLY:  ddx2, ddy2
-
-    USE bulk_cloud_model_mod,                                                  &
+    USE arrays_3d,                                                                                 &
+        ONLY:  dd2zu,                                                                              &
+               ddzu,                                                                               &
+               ddzw,                                                                               &
+               drho_air,                                                                           &
+               rho_air_zw
+
+    USE control_parameters,                                                                        &
+        ONLY:  atmos_ocean_sign,                                                                   &
+               use_single_reference_value
+
+    USE grid_variables,                                                                            &
+        ONLY:  ddx2,                                                                               &
+               ddy2
+
+    USE bulk_cloud_model_mod,                                                                      &
         ONLY:  collision_turbulence
 
-    USE particle_attributes,                                                   &
-        ONLY:  use_sgs_for_particles, wang_kernel
+    USE particle_attributes,                                                                       &
+        ONLY:  use_sgs_for_particles,                                                              &
+               wang_kernel
 
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i              !< running index x direction
-    INTEGER(iwp) ::  j              !< running index y direction
-    INTEGER(iwp) ::  k              !< running index z direction
-    INTEGER(iwp) ::  m              !< running index surface elements
-    INTEGER(iwp) ::  surf_e         !< End index of surface elements at (j,i)-gridpoint
-    INTEGER(iwp) ::  surf_s         !< Start index of surface elements at (j,i)-gridpoint
+    INTEGER(iwp) ::  i       !< running index x direction
+    INTEGER(iwp) ::  j       !< running index y direction
+    INTEGER(iwp) ::  k       !< running index z direction
+    INTEGER(iwp) ::  m       !< running index surface elements
+    INTEGER(iwp) ::  surf_e  !< End index of surface elements at (j,i)-gridpoint
+    INTEGER(iwp) ::  surf_s  !< Start index of surface elements at (j,i)-gridpoint
 
     REAL(wp)     ::  duv2_dz2       !< squared vertical gradient of wind vector
@@ -4371,9 +4287,9 @@
           IF ( dvar_dz > 0.0_wp ) THEN
              IF ( use_single_reference_value )  THEN
-                ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )              &
-                            / SQRT( g / var_reference * dvar_dz ) + 1E-5_wp
+                ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                                  &
+                                       / SQRT( g / var_reference * dvar_dz ) + 1E-5_wp
              ELSE
-                ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )              &
-                            / SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp
+                ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                                  &
+                                       / SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp
              ENDIF
           ELSE
@@ -4386,6 +4302,6 @@
           ml  = MIN( delta(k,j,i), ml_stratification(k) )
 
-          diss(k,j,i) = ( 0.19_wp + 0.74_wp * ml / delta(k,j,i) )                      &
-                        * e(k,j,i) * SQRT( e(k,j,i) ) / ml                             &
+          diss(k,j,i) = ( 0.19_wp + 0.74_wp * ml / delta(k,j,i) )                                  &
+                        * e(k,j,i) * SQRT( e(k,j,i) ) / ml                                         &
                         * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
        ENDDO
@@ -4397,16 +4313,15 @@
           IF ( dvar_dz > 0.0_wp ) THEN
 !
-!--          The mixing length is calculated as 1/l = 1/(kappa*z) + 1/Lb, where Lb is
-!--          the stratification term. 1E-5 is added as l is zero at the beginning of
-!--          the simulation.
+!--          The mixing length is calculated as 1/l = 1/(kappa*z) + 1/Lb, where Lb is the
+!--          stratification term. 1E-5 is added as l is zero at the beginning of the simulation.
              IF ( use_single_reference_value )  THEN
-                ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                           &
+                ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                                  &
                                        / SQRT( g / var_reference * dvar_dz ) + 1E-5_wp
              ELSE
-                ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                           &
+                ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                                  &
                                        / SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp
              ENDIF
 
-             ml_stratification(k) = 1.0_wp / ( 1.0_wp / ( kappa * distance_to_wall(k,j,i) ) &
+             ml_stratification(k) = 1.0_wp / ( 1.0_wp / ( kappa * distance_to_wall(k,j,i) )        &
                                              + 1.0_wp / ml_stratification(k) )
 
@@ -4420,6 +4335,6 @@
           ml  = ml_stratification(k)
 
-          diss(k,j,i) = ( 0.19_wp + 0.74_wp * ml / delta(k,j,i) )                      &
-                        * e(k,j,i) * SQRT( e(k,j,i) ) / ml                             &
+          diss(k,j,i) = ( 0.19_wp + 0.74_wp * ml / delta(k,j,i) )                                  &
+                        * e(k,j,i) * SQRT( e(k,j,i) ) / ml                                         &
                         * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
        ENDDO
@@ -4438,7 +4353,6 @@
              dvar_dz = atmos_ocean_sign * ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k)
 
-             duv2_dz2 =   ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2           &
-                        + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2           &
-                        + 1E-30_wp
+             duv2_dz2 = ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2                              &
+                      + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2 + 1E-30_wp
 
              rif(k) = MIN( MAX( g / var_reference * dvar_dz / duv2_dz2, -5.0_wp ),  1.0_wp )
@@ -4448,7 +4362,6 @@
              dvar_dz = atmos_ocean_sign * ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k)
 
-             duv2_dz2 =   ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2           &
-                        + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2           &
-                        + 1E-30_wp
+             duv2_dz2 = ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2                              &
+                      + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2 + 1E-30_wp
 
              rif(k) = MIN( MAX( g / var(k,j,i) * dvar_dz / duv2_dz2, -5.0_wp ), 1.0_wp )
@@ -4468,11 +4381,10 @@
        !DIR$ IVDEP
        DO  k = nzb+1, nzt
-          diss(k,j,i) = c_0**3 * e(k,j,i) * SQRT( e(k,j,i) )                         &
-                      / MIN( ml_stratification(k), delta(k,j,i) )                    &
+          diss(k,j,i) = c_0**3 * e(k,j,i) * SQRT( e(k,j,i) )                                       &
+                      / MIN( ml_stratification(k), delta(k,j,i) )                                  &
                       * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
        ENDDO
 
-!-- Note, in case of rans_tke_e, the dissipation is already calculated
-!-- in prognostic_equations
+!-- Note, in case of rans_tke_e, the dissipation is already calculated in prognostic_equations
     ENDIF
 
@@ -4482,36 +4394,29 @@
     DO  k = nzb+1, nzt
 
-       tend(k,j,i) = tend(k,j,i) + (                                           &
-                                      (                                        &
-                      ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) )      &
-                    - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) )      &
-                                      ) * ddx2                                 &
-                                    + (                                        &
-                      ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) )      &
-                    - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) )      &
-                                      ) * ddy2                                 &
-                                    + (                                        &
-           ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) ) * ddzu(k+1)     &
-                                                         * rho_air_zw(k)       &
-         - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) ) * ddzu(k)       &
-                                                         * rho_air_zw(k-1)     &
-                                      ) * ddzw(k) * drho_air(k)                &
-                                   ) * dsig_e                                  &
-                                     * MERGE( 1.0_wp, 0.0_wp,                  &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )&
-                                 - diss(k,j,i)
+       tend(k,j,i) = tend(k,j,i) + ( ( ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) )         &
+                                     - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) )         &
+                                     ) * ddx2                                                      &
+                                   + ( ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) )         &
+                                     - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) )         &
+                                     ) * ddy2                                                      &
+                                   + ( ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) )         &
+                                         * ddzu(k+1) * rho_air_zw(k)                               &
+                                     - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) )         &
+                                         * ddzu(k) * rho_air_zw(k-1) ) * ddzw(k) * drho_air(k)     &
+                                   ) * dsig_e * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                BTEST( wall_flags_total_0(k,j,i), 0 ) )            &
+                     - diss(k,j,i)
 
     ENDDO
 
 !
-!-- Set boundary conditions of dissipation if needed for calculating the sgs
-!-- particle velocities.
+!-- Set boundary conditions of dissipation if needed for calculating the sgs particle velocities.
 !-- Neumann boundary condition for dissipation diss(nzb,:,:) = diss(nzb+1,:,:)
-!-- For each surface type determine start and end index (in case of elevated
-!-- topography several up/downward facing surfaces may exist.
-!-- Note, bc cannot be set in tcm_boundary conditions as the dissipation
-!-- in LES mode is only a diagnostic quantity.
-    IF ( .NOT. rans_tke_e .AND.  ( use_sgs_for_particles  .OR.  wang_kernel    &
-          .OR.  collision_turbulence ) )  THEN
+!-- For each surface type determine start and end index (in case of elevated topography several
+!-- up/downward facing surfaces may exist.
+!-- Note, bc cannot be set in tcm_boundary conditions as the dissipation in LES mode is only a
+!-- diagnostic quantity.
+    IF ( .NOT. rans_tke_e  .AND.                                                                   &
+         ( use_sgs_for_particles  .OR.  wang_kernel  .OR.  collision_turbulence ) )  THEN
        surf_s = bc_h(0)%start_index(j,i)
        surf_e = bc_h(0)%end_index(j,i)
@@ -4533,24 +4438,28 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Diffusion term for the TKE dissipation rate
 !> Vector-optimized version
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE diffusion_diss
-    USE arrays_3d,                                                             &
-        ONLY:  ddzu, ddzw, drho_air, rho_air_zw
-
-    USE grid_variables,                                                        &
-        ONLY:  ddx2, ddy2
+    USE arrays_3d,                                                                                 &
+        ONLY:  ddzu,                                                                               &
+               ddzw,                                                                               &
+               drho_air,                                                                           &
+               rho_air_zw
+
+    USE grid_variables,                                                                            &
+        ONLY:  ddx2,                                                                               &
+               ddy2
 
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i              !< running index x direction
-    INTEGER(iwp) ::  j              !< running index y direction
-    INTEGER(iwp) ::  k              !< running index z direction
-
-    REAL(wp)     ::  flag           !< flag to mask topography
+    INTEGER(iwp) ::  i  !< running index x direction
+    INTEGER(iwp) ::  j  !< running index y direction
+    INTEGER(iwp) ::  k  !< running index z direction
+
+    REAL(wp)     ::  flag  !< flag to mask topography
 
 !
@@ -4564,22 +4473,15 @@
              flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
 
-             tend(k,j,i) = tend(k,j,i) +                                       &
-                         (       (                                             &
-                 ( km(k,j,i)+km(k,j,i+1) ) * ( diss(k,j,i+1)-diss(k,j,i) )     &
-               - ( km(k,j,i)+km(k,j,i-1) ) * ( diss(k,j,i)-diss(k,j,i-1) )     &
-                                 ) * ddx2                                      &
-                               + (                                             &
-                 ( km(k,j,i)+km(k,j+1,i) ) * ( diss(k,j+1,i)-diss(k,j,i) )     &
-               - ( km(k,j,i)+km(k,j-1,i) ) * ( diss(k,j,i)-diss(k,j-1,i) )     &
-                                 ) * ddy2                                      &
-                               + (                                             &
-      ( km(k,j,i)+km(k+1,j,i) ) * ( diss(k+1,j,i)-diss(k,j,i) ) * ddzu(k+1)    &
-                                                    * rho_air_zw(k)            &
-    - ( km(k,j,i)+km(k-1,j,i) ) * ( diss(k,j,i)-diss(k-1,j,i) ) * ddzu(k)      &
-                                                    * rho_air_zw(k-1)          &
-                                 ) * ddzw(k) * drho_air(k)                     &
-                         ) * flag * dsig_diss                                  &
-                         - c_2 * diss(k,j,i)**2                                &
-                               / ( e(k,j,i) + 1.0E-20_wp ) * flag
+             tend(k,j,i) = tend(k,j,i) +                                                           &
+                           ( ( ( km(k,j,i)+km(k,j,i+1) ) * ( diss(k,j,i+1)-diss(k,j,i) )           &
+                             - ( km(k,j,i)+km(k,j,i-1) ) * ( diss(k,j,i)-diss(k,j,i-1) ) ) * ddx2  &
+                           + ( ( km(k,j,i)+km(k,j+1,i) ) * ( diss(k,j+1,i)-diss(k,j,i) )           &
+                             - ( km(k,j,i)+km(k,j-1,i) ) * ( diss(k,j,i)-diss(k,j-1,i) ) ) * ddy2  &
+                           + ( ( km(k,j,i)+km(k+1,j,i) ) * ( diss(k+1,j,i)-diss(k,j,i) )           &
+                               * ddzu(k+1) * rho_air_zw(k)                                         &
+                             - ( km(k,j,i)+km(k-1,j,i) ) * ( diss(k,j,i)-diss(k-1,j,i) ) * ddzu(k) &
+                               * rho_air_zw(k-1) ) * ddzw(k) * drho_air(k)                         &
+                           )  * flag * dsig_diss - c_2 * diss(k,j,i)**2                            &
+                              / ( e(k,j,i) + 1.0E-20_wp ) * flag
 
           ENDDO
@@ -4590,25 +4492,29 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Diffusion term for the TKE dissipation rate
 !> Cache-optimized version
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE diffusion_diss_ij( i, j )
 
-    USE arrays_3d,                                                             &
-        ONLY:  ddzu, ddzw, drho_air, rho_air_zw
-
-    USE grid_variables,                                                        &
-        ONLY:  ddx2, ddy2
+    USE arrays_3d,                                                                                 &
+        ONLY:  ddzu,                                                                               &
+               ddzw,                                                                               &
+               drho_air,                                                                           &
+               rho_air_zw
+
+    USE grid_variables,                                                                            &
+        ONLY:  ddx2,                                                                               &
+               ddy2
 
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i         !< running index x direction
-    INTEGER(iwp) ::  j         !< running index y direction
-    INTEGER(iwp) ::  k         !< running index z direction
-
-    REAL(wp)     ::  flag      !< flag to mask topography
+    INTEGER(iwp) ::  i  !< running index x direction
+    INTEGER(iwp) ::  j  !< running index y direction
+    INTEGER(iwp) ::  k  !< running index z direction
+
+    REAL(wp)     ::  flag  !< flag to mask topography
 
 !
@@ -4622,21 +4528,15 @@
 !
 !--    Calculate the tendency term
-       tend(k,j,i) =  tend(k,j,i) +                                            &
-                   (            (                                              &
-                ( km(k,j,i)+km(k,j,i+1) ) * ( diss(k,j,i+1)-diss(k,j,i) )      &
-              - ( km(k,j,i)+km(k,j,i-1) ) * ( diss(k,j,i)-diss(k,j,i-1) )      &
-                                ) * ddx2                                       &
-                              + (                                              &
-                ( km(k,j,i)+km(k,j+1,i) ) * ( diss(k,j+1,i)-diss(k,j,i) )      &
-              - ( km(k,j,i)+km(k,j-1,i) ) * ( diss(k,j,i)-diss(k,j-1,i) )      &
-                                ) * ddy2                                       &
-                              + (                                              &
-     ( km(k,j,i)+km(k+1,j,i) ) * ( diss(k+1,j,i)-diss(k,j,i) ) * ddzu(k+1)     &
-                                                   * rho_air_zw(k)             &
-   - ( km(k,j,i)+km(k-1,j,i) ) * ( diss(k,j,i)-diss(k-1,j,i) ) * ddzu(k)       &
-                                                   * rho_air_zw(k-1)           &
-                                ) * ddzw(k) * drho_air(k)                      &
-                   ) * flag * dsig_diss                                        &
-                   - c_2 * diss(k,j,i)**2 / ( e(k,j,i) + 1.0E-20_wp ) * flag
+       tend(k,j,i) =  tend(k,j,i) +                                                                &
+                      ( ( ( km(k,j,i)+km(k,j,i+1) ) * ( diss(k,j,i+1)-diss(k,j,i) )                &
+                        - ( km(k,j,i)+km(k,j,i-1) ) * ( diss(k,j,i)-diss(k,j,i-1) ) ) * ddx2       &
+                      + ( ( km(k,j,i)+km(k,j+1,i) ) * ( diss(k,j+1,i)-diss(k,j,i) )                &
+                        - ( km(k,j,i)+km(k,j-1,i) ) * ( diss(k,j,i)-diss(k,j-1,i) ) ) * ddy2       &
+                      + ( ( km(k,j,i)+km(k+1,j,i) ) * ( diss(k+1,j,i)-diss(k,j,i) )                &
+                          * ddzu(k+1) * rho_air_zw(k)                                              &
+                        - ( km(k,j,i)+km(k-1,j,i) ) * ( diss(k,j,i)-diss(k-1,j,i) )                &
+                          * ddzu(k) * rho_air_zw(k-1) ) * ddzw(k) * drho_air(k)                    &
+                      )  * flag * dsig_diss - c_2 * diss(k,j,i)**2 / ( e(k,j,i) + 1.0E-20_wp )     &
+                         * flag
 
     ENDDO
@@ -4645,27 +4545,30 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Computation of the turbulent diffusion coefficients for momentum and heat.
 !> @bug unstable stratification is not properly considered for kh in rans mode.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_diffusivities( var, var_reference )
 
-    USE control_parameters,                                                    &
-        ONLY:  bc_radiation_l, bc_radiation_n, bc_radiation_r, bc_radiation_s, &
+    USE control_parameters,                                                                        &
+        ONLY:  bc_radiation_l,                                                                     &
+               bc_radiation_n,                                                                     &
+               bc_radiation_r,                                                                     &
+               bc_radiation_s,                                                                     &
                e_min
 
-    USE exchange_horiz_mod,                                                    &
+    USE exchange_horiz_mod,                                                                        &
         ONLY:  exchange_horiz
 
-    USE surface_layer_fluxes_mod,                                              &
+    USE surface_layer_fluxes_mod,                                                                  &
         ONLY:  phi_m
 
-    INTEGER(iwp) ::  i          !< loop index
-    INTEGER(iwp) ::  j          !< loop index
-    INTEGER(iwp) ::  k          !< loop index
-    INTEGER(iwp) ::  m          !< loop index
-    INTEGER(iwp) ::  n          !< loop index
+    INTEGER(iwp) ::  i  !< loop index
+    INTEGER(iwp) ::  j  !< loop index
+    INTEGER(iwp) ::  k  !< loop index
+    INTEGER(iwp) ::  m  !< loop index
+    INTEGER(iwp) ::  n  !< loop index
 
     REAL(wp) ::  var_reference  !< reference temperature
@@ -4681,5 +4584,5 @@
           DO  j = nysg, nyng
              DO  k = nzb+1, nzt
-                e(k,j,i) = MAX( e(k,j,i), e_min ) *                            &
+                e(k,j,i) = MAX( e(k,j,i), e_min ) *                                                &
                         MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
              ENDDO
@@ -4709,5 +4612,5 @@
           j = surf_def_h(0)%j(m)
           k = surf_def_h(0)%k(m)
-          km(k,j,i) = kappa * surf_def_h(0)%us(m) * surf_def_h(0)%z_mo(m) /    &
+          km(k,j,i) = kappa * surf_def_h(0)%us(m) * surf_def_h(0)%z_mo(m) /                        &
                       phi_m( surf_def_h(0)%z_mo(m) / surf_def_h(0)%ol(m) )
           kh(k,j,i) = 1.35_wp * km(k,j,i)
@@ -4720,5 +4623,5 @@
           j = surf_lsm_h%j(m)
           k = surf_lsm_h%k(m)
-          km(k,j,i) = kappa * surf_lsm_h%us(m) * surf_lsm_h%z_mo(m) /          &
+          km(k,j,i) = kappa * surf_lsm_h%us(m) * surf_lsm_h%z_mo(m) /                              &
                       phi_m( surf_lsm_h%z_mo(m) / surf_lsm_h%ol(m) )
           kh(k,j,i) = 1.35_wp * km(k,j,i)
@@ -4731,5 +4634,5 @@
           j = surf_usm_h%j(m)
           k = surf_usm_h%k(m)
-          km(k,j,i) = kappa * surf_usm_h%us(m) * surf_usm_h%z_mo(m) /          &
+          km(k,j,i) = kappa * surf_usm_h%us(m) * surf_usm_h%z_mo(m) /                              &
                       phi_m( surf_usm_h%z_mo(m) / surf_usm_h%ol(m) )
           kh(k,j,i) = 1.35_wp * km(k,j,i)
@@ -4814,6 +4717,6 @@
 
 !
-!-- Set Neumann boundary conditions at the outflow boundaries in case of
-!-- non-cyclic lateral boundaries
+!-- Set Neumann boundary conditions at the outflow boundaries in case of non-cyclic lateral
+!-- boundaries
     IF ( bc_radiation_l )  THEN
        km(:,:,nxl-1) = km(:,:,nxl)
@@ -4836,20 +4739,22 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Computation of the turbulent diffusion coefficients for momentum and heat
-!> according to Prandtl-Kolmogorov.
-!------------------------------------------------------------------------------!
+!> Computation of the turbulent diffusion coefficients for momentum and heat according to
+!> Prandtl-Kolmogorov.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_diffusivities_default( var, var_reference )
 
-    USE arrays_3d,                                                             &
+    USE arrays_3d,                                                                                 &
         ONLY:  dd2zu
 
-    USE control_parameters,                                                    &
-        ONLY:  atmos_ocean_sign, use_single_reference_value
-
-    USE statistics,                                                            &
-        ONLY :  rmask, sums_l_l
+    USE control_parameters,                                                                        &
+        ONLY:  atmos_ocean_sign,                                                                   &
+               use_single_reference_value
+
+    USE statistics,                                                                                &
+        ONLY :  rmask,                                                                             &
+                sums_l_l
 
     IMPLICIT NONE
@@ -4901,23 +4806,24 @@
 !
 !--             Determine the mixing length
-!--             @note The following code cannot be transferred to a subroutine
-!--             due to errors when using OpenACC directives. The execution
-!--             crashes reliably if a subroutine is called at this point (the
-!--             reason for this behaviour is unknown, however).
+!--             @note The following code cannot be transferred to a subroutine due to errors when
+!--             using OpenACC directives. The execution crashes reliably if a subroutine is called
+!--             at this point (the reason for this behaviour is unknown, however).
                 dvar_dz = atmos_ocean_sign * ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k)
                 IF ( dvar_dz > 0.0_wp )  THEN
                    IF ( use_single_reference_value )  THEN
-                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )         &
+                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                            &
 #if defined( __imuk_old )
-                             / SQRT( g / var_reference * ( ABS( dvar_dz ) + 1.0E-10_wp ) ) + 1E-5_wp ! required for intel14
+                                             / SQRT( g / var_reference *                           &
+                                             ( ABS( dvar_dz ) + 1.0E-10_wp ) ) + 1E-5_wp ! required for intel14
 #else
-                                  / SQRT( g / var_reference * dvar_dz ) + 1E-5_wp
+                                             / SQRT( g / var_reference * dvar_dz ) + 1E-5_wp
 #endif
                    ELSE
-                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )         &
+                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                            &
 #if defined( __imuk_old )
-                             / SQRT( g / var(k,j,i)    * ( ABS( dvar_dz ) + 1.0E-10_wp ) ) + 1E-5_wp ! required for intel14
+                                             / SQRT( g / var(k,j,i) *                              &
+                                             ( ABS( dvar_dz ) + 1.0E-10_wp ) ) + 1E-5_wp ! required for intel14
 #else
-                                  / SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp
+                                             / SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp
 #endif
                    ENDIF
@@ -4932,5 +4838,5 @@
              DO  k = nzb+1, nzt
 
-                ml = MIN( delta(k,j,i), ml_stratification(k) )                    &
+                ml = MIN( delta(k,j,i), ml_stratification(k) )                                     &
                    * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
                 ml_local_profile(k) = ml
@@ -4967,24 +4873,26 @@
                 IF ( dvar_dz > 0.0_wp ) THEN
 !
-!--                The mixing length is calculated as 1/l = 1/(kappa*z) + 1/Lb, where Lb is
-!--                the stratification term. 1E-5 is added as l is zero at the beginning of
-!--                the simulation.
+!--                The mixing length is calculated as 1/l = 1/(kappa*z) + 1/Lb, where Lb is the
+!--                stratification term. 1E-5 is added as l is zero at the beginning of the
+!--                simulation.
                    IF ( use_single_reference_value )  THEN
-                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                           &
+                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                            &
 #if defined( __imuk_old )
-                             / SQRT( g / var_reference * ( ABS( dvar_dz ) + 1.0E-10_wp ) ) + 1E-5_wp ! required for intel14
+                                             / SQRT( g / var_reference *                           &
+                                             ( ABS( dvar_dz ) + 1.0E-10_wp ) ) + 1E-5_wp ! Required for intel14
 #else
-                                  / SQRT( g / var_reference * dvar_dz ) + 1E-5_wp
+                                             / SQRT( g / var_reference * dvar_dz ) + 1E-5_wp
 #endif
                    ELSE
-                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                           &
+                      ml_stratification(k) = 0.76_wp * SQRT( e(k,j,i) )                            &
 #if defined( __imuk_old )
-                             / SQRT( g / var(k,j,i)    * ( ABS( dvar_dz ) + 1.0E-10_wp ) ) + 1E-5_wp ! required for intel14
+                                             / SQRT( g / var(k,j,i) *                              &
+                                             ( ABS( dvar_dz ) + 1.0E-10_wp ) ) + 1E-5_wp ! Required for intel14
 #else
-                                  / SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp
+                                             / SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp
 #endif
                    ENDIF
 
-                   ml_stratification(k) = 1.0_wp / ( 1.0_wp / ( kappa * distance_to_wall(k,j,i) ) &
+                   ml_stratification(k) = 1.0_wp / ( 1.0_wp / ( kappa * distance_to_wall(k,j,i) )  &
                                         + 1.0_wp / ml_stratification(k) )
                 ELSE
@@ -4998,5 +4906,6 @@
              DO  k = nzb+1, nzt
 
-                ml_local_profile(k) = ml_stratification(k) * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                ml_local_profile(k) = ml_stratification(k) *                                       &
+                                      MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
                 ml  = ml_local_profile(k)
 !
@@ -5005,5 +4914,5 @@
 
                 dvar_dz = atmos_ocean_sign * ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k)
-                IF ( dvar_dz > 0.0_wp ) THEN
+                IF ( dvar_dz > 0.0_wp )  THEN
                    kh(k,j,i) = km(k,j,i)
                 ELSE
@@ -5041,7 +4950,6 @@
                    dvar_dz = atmos_ocean_sign * ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k)
 
-                   duv2_dz2 =   ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2  &
-                              + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2  &
-                              + 1E-30_wp
+                   duv2_dz2 = ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2                        &
+                            + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2 + 1E-30_wp
 
                    rif(k) = MIN( MAX( g / var_reference * dvar_dz / duv2_dz2, -5.0_wp ),  1.0_wp )
@@ -5053,7 +4961,6 @@
                    dvar_dz = atmos_ocean_sign * ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k)
 
-                   duv2_dz2 =   ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2  &
-                              + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2  &
-                              + 1E-30_wp
+                   duv2_dz2 = ( ( u(k+1,j,i) - u(k-1,j,i) ) * dd2zu(k) )**2                        &
+                            + ( ( v(k+1,j,i) - v(k-1,j,i) ) * dd2zu(k) )**2 + 1E-30_wp
 
                    rif(k) = MIN( MAX( g / var(k,j,i) * dvar_dz / duv2_dz2, -5.0_wp ),  1.0_wp )
@@ -5077,5 +4984,5 @@
              !DIR$ IVDEP
              DO  k = nzb+1, nzt
-                ml_local_profile(k) = MIN( ml_stratification(k), delta(k,j,i) ) &
+                ml_local_profile(k) = MIN( ml_stratification(k), delta(k,j,i) )                    &
                                     * MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
                 km(k,j,i) = c_0 * ml_local_profile(k) * SQRT( e(k,j,i) )
@@ -5132,6 +5039,6 @@
 
     !$ACC KERNELS PRESENT(sums_l_l)
-    sums_l_l(nzt+1,:,tn) = sums_l_l(nzt,:,tn)   ! quasi boundary-condition for
-                                                ! data output
+    sums_l_l(nzt+1,:,tn) = sums_l_l(nzt,:,tn)   ! Quasi boundary-condition for
+                                                ! Data output
     !$ACC END KERNELS
 !$OMP END PARALLEL
@@ -5140,48 +5047,58 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Calculates the eddy viscosity dynamically using the linear dynamic model
-!> according to
-!> Heinz, Stefan. "Realizability of dynamic subgrid-scale stress models via
-!> stochastic analysis."
+!> Calculates the eddy viscosity dynamically using the linear dynamic model according to
+!> Heinz, Stefan. "Realizability of dynamic subgrid-scale stress models via stochastic analysis."
 !> Monte Carlo Methods and Applications 14.4 (2008): 311-329.
 !>
-!> Furthermore dynamic bounds are used to limit the absolute value of c* as
-!> described in
-!> Mokhtarpoor, Reza, and Stefan Heinz. "Dynamic large eddy simulation:
-!> Stability via realizability." Physics of Fluids 29.10 (2017): 105104.
+!> Furthermore dynamic bounds are used to limit the absolute value of c* as described in
+!> Mokhtarpoor, Reza, and Stefan Heinz. "Dynamic large eddy simulation: Stability via realizability."
+!> Physics of Fluids 29.10 (2017): 105104.
 !>
 !> @author Hauke Wurps
 !> @author BjÃ¶rn Maronga
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_diffusivities_dynamic
 
-    USE arrays_3d,                                                             &
-        ONLY:  ddzw, dzw, dd2zu, w, ug, vg
-
-    USE grid_variables,                                                        &
-        ONLY : ddx, ddy, dx, dy
+    USE arrays_3d,                                                                                 &
+        ONLY:  ddzw,                                                                               &
+               dzw,                                                                                &
+               dd2zu,                                                                              &
+               ug,                                                                                 &
+               vg,                                                                                 &
+               w
+
+    USE grid_variables,                                                                            &
+        ONLY : ddx,                                                                                &
+               ddy,                                                                                &
+               dx,                                                                                 &
+               dy
 
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i           !< running index x-direction
-    INTEGER(iwp) ::  j           !< running index y-direction
-    INTEGER(iwp) ::  k           !< running index z-direction
-    INTEGER(iwp) ::  l           !< running index
-    INTEGER(iwp) ::  m           !< running index
-
-    REAL(wp)     ::  dudx        !< Gradient of u-component in x-direction
-    REAL(wp)     ::  dudy        !< Gradient of u-component in y-direction
-    REAL(wp)     ::  dudz        !< Gradient of u-component in z-direction
-    REAL(wp)     ::  dvdx        !< Gradient of v-component in x-direction
-    REAL(wp)     ::  dvdy        !< Gradient of v-component in y-direction
-    REAL(wp)     ::  dvdz        !< Gradient of v-component in z-direction
-    REAL(wp)     ::  dwdx        !< Gradient of w-component in x-direction
-    REAL(wp)     ::  dwdy        !< Gradient of w-component in y-direction
-    REAL(wp)     ::  dwdz        !< Gradient of w-component in z-direction
-
-    REAL(wp)     ::  flag        !< topography flag
+    INTEGER(iwp) ::  i     !< running index x-direction
+    INTEGER(iwp) ::  j     !< running index y-direction
+    INTEGER(iwp) ::  k     !< running index z-direction
+    INTEGER(iwp) ::  l     !< running index
+    INTEGER(iwp) ::  m     !< running index
+
+    REAL(wp)     ::  cst        !< c*
+    REAL(wp)     ::  cstnust_t  !< product c*nu*
+    REAL(wp)     ::  cst_max    !< bounds of c*
+    REAL(wp)     ::  delta_max  !< maximum of the grid spacings
+
+    REAL(wp)     ::  dudx  !< Gradient of u-component in x-direction
+    REAL(wp)     ::  dudy  !< Gradient of u-component in y-direction
+    REAL(wp)     ::  dudz  !< Gradient of u-component in z-direction
+    REAL(wp)     ::  dvdx  !< Gradient of v-component in x-direction
+    REAL(wp)     ::  dvdy  !< Gradient of v-component in y-direction
+    REAL(wp)     ::  dvdz  !< Gradient of v-component in z-direction
+    REAL(wp)     ::  dwdx  !< Gradient of w-component in x-direction
+    REAL(wp)     ::  dwdy  !< Gradient of w-component in y-direction
+    REAL(wp)     ::  dwdz  !< Gradient of w-component in z-direction
+
+    REAL(wp)     ::  flag  !< topography flag
 
     REAL(wp)     ::  uc(-1:1,-1:1)  !< u on grid center
@@ -5193,51 +5110,47 @@
     REAL(wp)     ::  wt(nzb:nzt+1,nysg:nyng,nxlg:nxrg)  !< test filtered w
 
-    REAL(wp)     ::  uct         !< test filtered u on grid center
-    REAL(wp)     ::  vct         !< test filtered v on grid center
-    REAL(wp)     ::  wct         !< test filtered w on grid center
-    REAL(wp)     ::  u2t         !< test filtered u**2 on grid center
-    REAL(wp)     ::  v2t         !< test filtered v**2 on grid center
-    REAL(wp)     ::  w2t         !< test filtered w**2 on grid center
-    REAL(wp)     ::  uvt         !< test filtered u*v on grid center
-    REAL(wp)     ::  uwt         !< test filtered u*w on grid center
-    REAL(wp)     ::  vwt         !< test filtered v*w on grid center
-
-    REAL(wp)     ::  sd11        !< deviatoric shear tensor
-    REAL(wp)     ::  sd22        !< deviatoric shear tensor
-    REAL(wp)     ::  sd33        !<f deviatoric shear tensor
-    REAL(wp)     ::  sd12        !< deviatoric shear tensor
-    REAL(wp)     ::  sd13        !< deviatoric shear tensor
-    REAL(wp)     ::  sd23        !< deviatoric shear tensor
-
-    REAL(wp)     ::  sd2         !< sum: sd_ij*sd_ij
-
-    REAL(wp)     ::  sdt11       !< filtered deviatoric shear tensor
-    REAL(wp)     ::  sdt22       !< filtered deviatoric shear tensor
-    REAL(wp)     ::  sdt33       !< filtered deviatoric shear tensor
-    REAL(wp)     ::  sdt12       !< filtered deviatoric shear tensor
-    REAL(wp)     ::  sdt13       !< filtered deviatoric shear tensor
-    REAL(wp)     ::  sdt23       !< filtered deviatoric shear tensor
-
-    REAL(wp)     ::  sdt2        !< sum: sdt_ij*sdt_ij
-
-    REAL(wp)     ::  ld11        !< deviatoric stress tensor
-    REAL(wp)     ::  ld22        !< deviatoric stress tensor
-    REAL(wp)     ::  ld33        !< deviatoric stress tensor
-    REAL(wp)     ::  ld12        !< deviatoric stress tensor
-    REAL(wp)     ::  ld13        !< deviatoric stress tensor
-    REAL(wp)     ::  ld23        !< deviatoric stress tensor
-
-    REAL(wp)     ::  lnn         !< sum ld_nn
-    REAL(wp)     ::  ldsd        !< sum: ld_ij*sd_ij
-
-    REAL(wp)     ::  delta_max   !< maximum of the grid spacings
-    REAL(wp)     ::  cst         !< c*
-    REAL(wp)     ::  cstnust_t   !< product c*nu*
-    REAL(wp)     ::  cst_max     !< bounds of c*
-
-    REAL(wp), PARAMETER :: fac_cmax = 23.0_wp/(24.0_wp*sqrt(3.0_wp))  !< constant
-
-!
-!-- velocities on grid centers:
+    REAL(wp)     ::  uct    !< test filtered u on grid center
+    REAL(wp)     ::  vct    !< test filtered v on grid center
+    REAL(wp)     ::  wct    !< test filtered w on grid center
+    REAL(wp)     ::  u2t    !< test filtered u**2 on grid center
+    REAL(wp)     ::  v2t    !< test filtered v**2 on grid center
+    REAL(wp)     ::  w2t    !< test filtered w**2 on grid center
+    REAL(wp)     ::  uvt    !< test filtered u*v on grid center
+    REAL(wp)     ::  uwt    !< test filtered u*w on grid center
+    REAL(wp)     ::  vwt    !< test filtered v*w on grid center
+
+    REAL(wp)     ::  sd11   !< deviatoric shear tensor
+    REAL(wp)     ::  sd22   !< deviatoric shear tensor
+    REAL(wp)     ::  sd33   !<f deviatoric shear tensor
+    REAL(wp)     ::  sd12   !< deviatoric shear tensor
+    REAL(wp)     ::  sd13   !< deviatoric shear tensor
+    REAL(wp)     ::  sd23   !< deviatoric shear tensor
+
+    REAL(wp)     ::  sd2    !< sum: sd_ij*sd_ij
+
+    REAL(wp)     ::  sdt11  !< filtered deviatoric shear tensor
+    REAL(wp)     ::  sdt22  !< filtered deviatoric shear tensor
+    REAL(wp)     ::  sdt33  !< filtered deviatoric shear tensor
+    REAL(wp)     ::  sdt12  !< filtered deviatoric shear tensor
+    REAL(wp)     ::  sdt13  !< filtered deviatoric shear tensor
+    REAL(wp)     ::  sdt23  !< filtered deviatoric shear tensor
+
+    REAL(wp)     ::  sdt2   !< sum: sdt_ij*sdt_ij
+
+    REAL(wp)     ::  ld11   !< deviatoric stress tensor
+    REAL(wp)     ::  ld22   !< deviatoric stress tensor
+    REAL(wp)     ::  ld33   !< deviatoric stress tensor
+    REAL(wp)     ::  ld12   !< deviatoric stress tensor
+    REAL(wp)     ::  ld13   !< deviatoric stress tensor
+    REAL(wp)     ::  ld23   !< deviatoric stress tensor
+
+    REAL(wp)     ::  lnn    !< sum ld_nn
+    REAL(wp)     ::  ldsd   !< sum: ld_ij*sd_ij
+
+
+    REAL(wp), PARAMETER :: fac_cmax = 23.0_wp / ( 24.0_wp * SQRT (3.0_wp) )  !< constant
+
+!
+!-- Velocities on grid centers:
     CALL tcm_box_filter_2d_array( u, ut )
     CALL tcm_box_filter_2d_array( v, vt )
@@ -5254,19 +5167,13 @@
 !--          s_ij =  0.5 * ( du_i/dx_j + du_j/dx_i )
              dudx  =           ( u(k,j,i+1) - u(k,j,i)     ) * ddx
-             dudy  = 0.25_wp * ( u(k,j+1,i) + u(k,j+1,i+1) - &
-                                 u(k,j-1,i) - u(k,j-1,i+1) ) * ddy
-             dudz  = 0.5_wp  * ( u(k+1,j,i) + u(k+1,j,i+1) - &
-                                 u(k-1,j,i) - u(k-1,j,i+1) ) * dd2zu(k)
-
-             dvdx  = 0.25_wp * ( v(k,j,i+1) + v(k,j+1,i+1) - &
-                                 v(k,j,i-1) - v(k,j+1,i-1) ) * ddx
+             dudy  = 0.25_wp * ( u(k,j+1,i) + u(k,j+1,i+1) - u(k,j-1,i) - u(k,j-1,i+1) ) * ddy
+             dudz  = 0.5_wp  * ( u(k+1,j,i) + u(k+1,j,i+1) - u(k-1,j,i) - u(k-1,j,i+1) ) * dd2zu(k)
+
+             dvdx  = 0.25_wp * ( v(k,j,i+1) + v(k,j+1,i+1) - v(k,j,i-1) - v(k,j+1,i-1) ) * ddx
              dvdy  =           ( v(k,j+1,i) - v(k,j,i)     ) * ddy
-             dvdz  = 0.5_wp  * ( v(k+1,j,i) + v(k+1,j+1,i) - &
-                                 v(k-1,j,i) - v(k-1,j+1,i) ) * dd2zu(k)
-
-             dwdx  = 0.25_wp * ( w(k,j,i+1) + w(k-1,j,i+1) - &
-                                 w(k,j,i-1) - w(k-1,j,i-1) ) * ddx
-             dwdy  = 0.25_wp * ( w(k,j+1,i) + w(k-1,j+1,i) - &
-                                 w(k,j-1,i) - w(k-1,j-1,i) ) * ddy
+             dvdz  = 0.5_wp  * ( v(k+1,j,i) + v(k+1,j+1,i) - v(k-1,j,i) - v(k-1,j+1,i) ) * dd2zu(k)
+
+             dwdx  = 0.25_wp * ( w(k,j,i+1) + w(k-1,j,i+1) - w(k,j,i-1) - w(k-1,j,i-1) ) * ddx
+             dwdy  = 0.25_wp * ( w(k,j+1,i) + w(k-1,j+1,i) - w(k,j-1,i) - w(k-1,j-1,i) ) * ddy
              dwdz  =           ( w(k,j,i)   - w(k-1,j,i)   ) * ddzw(k)
 
@@ -5279,26 +5186,21 @@
 !
 !--          sum: sd_ij*sd_ij
-             sd2 = sd11**2 + sd22**2 + sd33**2                     &
-                   + 2.0_wp * ( sd12**2 + sd13**2 + sd23**2 )
-!
-!--          The filtered velocities are needed to calculate the filtered shear
-!--          tensor: sdt_ij = 0.5 * ( dut_i/dx_j + dut_j/dx_i )
-             dudx  =           ( ut(k,j,i+1) - ut(k,j,i)     ) * ddx
-             dudy  = 0.25_wp * ( ut(k,j+1,i) + ut(k,j+1,i+1) - &
-                                 ut(k,j-1,i) - ut(k,j-1,i+1) ) * ddy
-             dudz  = 0.5_wp  * ( ut(k+1,j,i) + ut(k+1,j,i+1) - &
-                                 ut(k-1,j,i) - ut(k-1,j,i+1) ) * dd2zu(k)
-
-             dvdx  = 0.25_wp * ( vt(k,j,i+1) + vt(k,j+1,i+1) - &
-                                 vt(k,j,i-1) - vt(k,j+1,i-1) ) * ddx
+             sd2 = sd11**2 + sd22**2 + sd33**2 + 2.0_wp * ( sd12**2 + sd13**2 + sd23**2 )
+!
+!--          The filtered velocities are needed to calculate the filtered shear tensor:
+!--          sdt_ij = 0.5 * ( dut_i/dx_j + dut_j/dx_i )
+             dudx  =           ( ut(k,j,i+1) - ut(k,j,i)      ) * ddx
+             dudy  = 0.25_wp * ( ut(k,j+1,i) + ut(k,j+1,i+1) - ut(k,j-1,i) - ut(k,j-1,i+1) ) * ddy
+             dudz  = 0.5_wp  * ( ut(k+1,j,i) + ut(k+1,j,i+1) -                                     &
+                                 ut(k-1,j,i) - ut(k-1,j,i+1)  ) * dd2zu(k)
+
+             dvdx  = 0.25_wp * ( vt(k,j,i+1) + vt(k,j+1,i+1) - vt(k,j,i-1) - vt(k,j+1,i-1) ) * ddx
              dvdy  =           ( vt(k,j+1,i) - vt(k,j,i)     ) * ddy
-             dvdz  = 0.5_wp  * ( vt(k+1,j,i) + vt(k+1,j+1,i) - &
+             dvdz  = 0.5_wp  * ( vt(k+1,j,i) + vt(k+1,j+1,i) -                                     &
                                  vt(k-1,j,i) - vt(k-1,j+1,i) ) * dd2zu(k)
 
-             dwdx  = 0.25_wp * ( wt(k,j,i+1) + wt(k-1,j,i+1) - &
-                                 wt(k,j,i-1) - wt(k-1,j,i-1) ) * ddx
-             dwdy  = 0.25_wp * ( wt(k,j+1,i) + wt(k-1,j+1,i) - &
-                                 wt(k,j-1,i) - wt(k-1,j-1,i) ) * ddy
-             dwdz  =           ( wt(k,j,i)   - wt(k-1,j,i)   ) * ddzw(k)
+             dwdx  = 0.25_wp * ( wt(k,j,i+1) + wt(k-1,j,i+1) - wt(k,j,i-1) - wt(k-1,j,i-1) ) * ddx
+             dwdy  = 0.25_wp * ( wt(k,j+1,i) + wt(k-1,j+1,i) - wt(k,j-1,i) - wt(k-1,j-1,i) ) * ddy
+             dwdz  =           ( wt(k,j,i)   - wt(k-1,j,i)  ) * ddzw(k)
 
              sdt11 = dudx
@@ -5310,11 +5212,9 @@
 !
 !--          sum: sd_ij*sd_ij
-             sdt2 = sdt11**2 + sdt22**2 + sdt33**2         &
-                   + 2.0_wp * ( sdt12**2 + sdt13**2 + sdt23**2 )
-!
-!--          Need filtered velocities and filtered squared velocities on grid
-!--          centers. Substraction of geostrophic velocity helps to avoid
-!--          numerical errors in the expression <u**2> - <u>*<u>, which can be
-!--          very small (<...> means filtered).
+             sdt2 = sdt11**2 + sdt22**2 + sdt33**2 + 2.0_wp * ( sdt12**2 + sdt13**2 + sdt23**2 )
+!
+!--          Need filtered velocities and filtered squared velocities on grid centers. Substraction
+!--          of geostrophic velocity helps to avoid numerical errors in the expression
+!--          <u**2> - <u>*<u>, which can be very small (<...> means filtered).
              DO  l = -1, 1
                 DO  m = -1, 1
@@ -5349,24 +5249,23 @@
              ld33 = ld33 - lnn / 3.0_wp
 
-             ldsd = ld11 * sdt11 + ld22 * sdt22 + ld33 * sdt33 + &
-                    2.0_wp * ( ld12 * sdt12 + ld13 * sdt13 + ld23 * sdt23 )
+             ldsd = ld11 * sdt11 + ld22 * sdt22 + ld33 * sdt33 + 2.0_wp *                          &
+                  ( ld12 * sdt12 + ld13 * sdt13 + ld23 * sdt23 )
 !
 !--          c* nu*^T is SGS viscosity on test filter level:
              cstnust_t = -ldsd / ( sdt2 + 1.0E-20_wp )
 !
-!--          The model was only tested for an isotropic grid. The following
-!--          expression was a recommendation of Stefan Heinz.
+!--          The model was only tested for an isotropic grid. The following expression was a
+!--          recommendation of Stefan Heinz.
              delta_max = MAX( dx, dy, dzw(k) )
 
-             IF ( lnn <= 0.0_wp ) THEN
+             IF ( lnn <= 0.0_wp )  THEN
                 cst = 0.0_wp
              ELSE
-                cst = cstnust_t /                                              &
-                   ( 4.0_wp * delta_max * SQRT( lnn / 2.0_wp ) + 1.0E-20_wp )
+                cst = cstnust_t / ( 4.0_wp * delta_max * SQRT( lnn / 2.0_wp ) + 1.0E-20_wp )
              ENDIF
 
 !
 !--          Calculate border according to Mokhtarpoor and Heinz (2017)
-             cst_max = fac_cmax * SQRT( e(k,j,i) ) /                           &
+             cst_max = fac_cmax * SQRT( e(k,j,i) ) /                                               &
                        ( delta_max * SQRT( 2.0_wp * sd2 ) + 1.0E-20_wp )
 
@@ -5384,56 +5283,51 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> This subroutine acts as a box filter with filter width 2 * dx.
-!> Output is only one point.
-!------------------------------------------------------------------------------!
+!> This subroutine acts as a box filter with filter width 2 * dx. Output is only one point.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_box_filter_2d_single( var, var_fil )
 
     IMPLICIT NONE
 
-    REAL(wp)     ::  var(-1:1,-1:1)      !< variable to be filtered
-    REAL(wp)     ::  var_fil             !< filtered variable
-!
-!-- It is assumed that a box with a side length of 2 * dx and centered at the
-!-- variable*s position contains one half of the four closest neigbours and one
-!-- forth of the diagonally closest neighbours.
-    var_fil = 0.25_wp * ( var(0,0) +                                           &
-                      0.5_wp  * ( var(0,1)  + var(1,0)   +                     &
-                                  var(0,-1) + var(-1,0)  ) +                   &
-                      0.25_wp * ( var(1,1)  + var(1,-1)  +                     &
-                                  var(-1,1) + var(-1,-1) ) )
+    REAL(wp)     ::  var(-1:1,-1:1)  !< variable to be filtered
+    REAL(wp)     ::  var_fil         !< filtered variable
+!
+!-- It is assumed that a box with a side length of 2 * dx and centered at the variable*s position
+!-- contains one half of the four closest neigbours and one forth of the diagonally closest
+!-- neighbours.
+    var_fil = 0.25_wp * ( var(0,0) + 0.5_wp * ( var(0,1) + var(1,0) + var(0,-1) + var(-1,0) ) +    &
+                          0.25_wp * ( var(1,1) + var(1,-1) + var(-1,1) + var(-1,-1) ) )
 
  END SUBROUTINE tcm_box_filter_2d_single
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> This subroutine acts as a box filter with filter width 2 * dx.
-!> The filtered variable var_fil is on the same grid as var.
-!------------------------------------------------------------------------------!
+!> This subroutine acts as a box filter with filter width 2 * dx. The filtered variable var_fil is
+!> on the same grid as var.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_box_filter_2d_array( var, var_fil )
 
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i    !< running index x-direction
-    INTEGER(iwp) ::  j    !< running index y-direction
-    INTEGER(iwp) ::  k    !< running index z-direction
+    INTEGER(iwp) ::  i  !< running index x-direction
+    INTEGER(iwp) ::  j  !< running index y-direction
+    INTEGER(iwp) ::  k  !< running index z-direction
 
     REAL(wp)     ::  var(nzb:nzt+1,nysg:nyng,nxlg:nxrg)      !< variable to be filtered
     REAL(wp)     ::  var_fil(nzb:nzt+1,nysg:nyng,nxlg:nxrg)  !< filtered variable
 !
-!-- It is assumed that a box with a side length of 2 * dx and centered at the
-!-- variable's position contains one half of the four closest neigbours and one
-!-- forth of the diagonally closest neighbours.
+!-- It is assumed that a box with a side length of 2 * dx and centered at the variable's position
+!-- contains one half of the four closest neigbours and one forth of the diagonally closest
+!-- neighbours.
     DO  i = nxlg+1, nxrg-1
        DO  j = nysg+1, nyng-1
           DO  k = nzb, nzt+1
-             var_fil(k,j,i) = 0.25_wp * ( var(k,j,i) +                         &
-                              0.5_wp  * ( var(k,j,i+1)   + var(k,j+1,i)   +    &
-                                          var(k,j,i-1)   + var(k,j-1,i)     ) +&
-                              0.25_wp * ( var(k,j+1,i+1) + var(k,j+1,i-1) +    &
-                                          var(k,j-1,i+1) + var(k,j-1,i-1)   )  )
+             var_fil(k,j,i) = 0.25_wp * ( var(k,j,i) + 0.5_wp * ( var(k,j,i+1) + var(k,j+1,i) +    &
+                                          var(k,j,i-1) + var(k,j-1,i) ) + 0.25_wp *                &
+                                        ( var(k,j+1,i+1) + var(k,j+1,i-1) +                        &
+                                          var(k,j-1,i+1) + var(k,j-1,i-1) ) )
           END DO
        END DO
@@ -5443,9 +5337,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Swapping of timelevels.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE tcm_swap_timelevel ( mod_count )
 
@@ -5453,5 +5347,5 @@
 
 
-    INTEGER, INTENT(IN) ::  mod_count  !< flag defining where pointers point to
+    INTEGER, INTENT(IN) ::  mod_count  !< Flag defining where pointers point to
 
 
Index: /palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 4509)
+++ /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 4510)
@@ -18,4 +18,5 @@
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
 !--------------------------------------------------------------------------------------------------!
+!
 !
 ! Current revisions:
@@ -26,20 +27,23 @@
 ! -----------------
 ! $Id$
-! file re-formatted to follow the PALM coding standard
+! Further re-formatting to follow the PALM coding standard
+!
+! 4509 2020-04-26 15:57:55Z raasch
+! File re-formatted to follow the PALM coding standard
 !
 ! 4500 2020-04-17 10:12:45Z suehring
 ! Allocate array for wall heat flux, which is further used to aggregate tile
 ! fractions in the surface output
-! 
+!
 ! 4495 2020-04-13 20:11:20Z raasch
-! restart data handling with MPI-IO added
+! Restart data handling with MPI-IO added
 !
 ! 4493 2020-04-10 09:49:43Z pavelkrc
 ! J.Resler, 2020/03/19
-! - remove reading of deprecated input parameters c_surface and lambda_surf
-! - and calculate them from parameters of the outer wall/roof layer
+! - Remove reading of deprecated input parameters c_surface and lambda_surf
+! - And calculate them from parameters of the outer wall/roof layer
 !
 ! 4481 2020-03-31 18:55:54Z maronga
-! use statement for exchange horiz added
+! Use statement for exchange horiz added
 !
 ! 4442 2020-03-04 19:21:13Z suehring
@@ -80,5 +84,5 @@
 !
 ! 4227 2019-09-10 18:04:34Z gronemeier
-! implement new palm_date_time_mod
+! Implement new palm_date_time_mod
 !
 ! 4214 2019-09-02 15:57:02Z suehring
@@ -152,5 +156,5 @@
 !
 ! 3832 2019-03-28 13:16:58Z raasch
-! instrumented with openmp directives
+! Instrumented with openmp directives
 !
 ! 3824 2019-03-27 15:56:16Z pavelkrc
@@ -159,11 +163,11 @@
 !
 ! 3814 2019-03-26 08:40:31Z pavelkrc
-! unused subroutine commented out
+! Unused subroutine commented out
 !
 ! 3769 2019-02-28 10:16:49Z moh.hefny
-! removed unused variables
+! Removed unused variables
 !
 ! 3767 2019-02-27 08:18:02Z raasch
-! unused variables removed from rrd-subroutines parameter list
+! Unused variables removed from rrd-subroutines parameter list
 !
 ! 3748 2019-02-18 10:38:31Z suehring
@@ -172,10 +176,10 @@
 ! 3745 2019-02-15 18:57:56Z suehring
 ! - Remove internal flag indoor_model (is a global control parameter)
-! - add waste heat from buildings to the kinmatic heat flux
-! - consider waste heat in restart data
-! - remove unused USE statements
+! - Add waste heat from buildings to the kinmatic heat flux
+! - Consider waste heat in restart data
+! - Remove unused USE statements
 !
 ! 3744 2019-02-15 18:38:58Z suehring
-! fixed surface heat capacity in the building parameters convert the file back to unix format
+! Fixed surface heat capacity in the building parameters convert the file back to unix format
 !
 ! 3730 2019-02-11 11:26:47Z moh.hefny
@@ -186,5 +190,5 @@
 !
 ! 3705 2019-01-29 19:56:39Z suehring
-! make nzb_wall public, required for virtual-measurements
+! Make nzb_wall public, required for virtual-measurements
 !
 ! 3704 2019-01-29 19:51:41Z suehring
@@ -208,10 +212,10 @@
 !> Module for Urban Surface Model (USM)
 !> The module includes:
-!>    1. radiation model with direct/diffuse radiation, shading, reflections and integration with
+!>    1. Radiation model with direct/diffuse radiation, shading, reflections and integration with
 !>       plant canopy
-!>    2. wall and wall surface model
-!>    3. surface layer energy balance
-!>    4. anthropogenic heat (only from transportation so far)
-!>    5. necessary auxiliary subroutines (reading inputs, writing outputs, restart simulations, ...)
+!>    2. Wall and wall surface model
+!>    3. Surface layer energy balance
+!>    4. Anthropogenic heat (only from transportation so far)
+!>    5. Necessary auxiliary subroutines (reading inputs, writing outputs, restart simulations, ...)
 !> It also makes use of standard radiation and integrates it into urban surface model.
 !>
@@ -223,5 +227,5 @@
 !> fraq(0,m) + fraq(1,m) = 0?!
 !> @todo Use unit 90 for OPEN/CLOSE of input files (FK)
-!> @todo remove reading of old csv inputs
+!> @todo Remove reading of old csv inputs
 !--------------------------------------------------------------------------------------------------!
  MODULE urban_surface_mod
@@ -418,6 +422,6 @@
                                  /), (/ 4, 7 /) )
 !
-!-- value 9999999.9_wp -> generic available or user-defined value must be set otherwise
-!-- -> no generic variable and user setting is optional
+!-- Value 9999999.9_wp -> Generic available or user-defined value must be set otherwise
+!-- -> No generic variable and user setting is optional
     REAL(wp) ::  alpha_vangenuchten = 9999999.9_wp      !< NAMELIST alpha_vg
     REAL(wp) ::  field_capacity = 9999999.9_wp          !< NAMELIST fc
@@ -430,5 +434,5 @@
 
 !
-!-- configuration parameters (they can be setup in PALM config)
+!-- Configuration parameters (they can be setup in PALM config)
     LOGICAL ::  force_radiation_call_l = .FALSE.   !< flag parameter for unscheduled radiation model calls
     LOGICAL ::  read_wall_temp_3d = .FALSE.        !<
@@ -645,5 +649,5 @@
     TYPE(surf_type_usm), TARGET   ::  tm_liq_usm_h_m  !< liquid water reservoir tendency (m), horizontal surface elements
 !
-!-- anthropogenic heat sources
+!-- Anthropogenic heat sources
     INTEGER(iwp)                                   ::  naheatlayers = 1  !< number of layers of anthropogenic heat
 
@@ -653,6 +657,6 @@
 
 !
-!-- wall surface model
-!-- wall surface model constants
+!-- Wall surface model
+!-- Wall surface model constants
     INTEGER(iwp), PARAMETER                        ::  nzb_wall = 0  !< inner side of the wall model (to be switched)
     INTEGER(iwp), PARAMETER                        ::  nzt_wall = 3  !< outer side of the wall model (to be switched)
@@ -680,5 +684,5 @@
 
 !
-!-- surface and material model variables for walls, ground, roofs
+!-- Surface and material model variables for walls, ground, roofs
     REAL(wp), DIMENSION(:), ALLOCATABLE            ::  zwn                 !< normalized wall layer depths (m)
     REAL(wp), DIMENSION(:), ALLOCATABLE            ::  zwn_green           !< normalized green layer depths (m)
@@ -715,5 +719,5 @@
 !
 !-- Energy balance variables
-!-- parameters of the land, roof and wall surfaces
+!-- Parameters of the land, roof and wall surfaces
     REAL(wp), DIMENSION(:,:), POINTER                ::  fc_h          !<
     REAL(wp), DIMENSION(:,:), POINTER                ::  rootfr_h      !<
@@ -763,5 +767,5 @@
 !
 !-- Surface and material parameter classes (surface_type)
-!-- albedo, emissivity, lambda_surf, roughness, thickness, volumetric heat capacity, thermal conductivity
+!-- Albedo, emissivity, lambda_surf, roughness, thickness, volumetric heat capacity, thermal conductivity
     CHARACTER(12), DIMENSION(:), ALLOCATABLE  ::  surface_type_names    !< names of wall types (used only for reports)
 
@@ -790,5 +794,5 @@
 
 !
-!-- interfaces of subroutines accessed from outside of this module
+!-- Interfaces of subroutines accessed from outside of this module
     INTERFACE usm_3d_data_averaging
        MODULE PROCEDURE usm_3d_data_averaging
@@ -923,6 +927,6 @@
 !
 !-- Wall surface model
-!-- allocate arrays for wall surface model and define pointers
-!-- allocate array of wall types and wall parameters
+!-- Allocate arrays for wall surface model and define pointers
+!-- Allocate array of wall types and wall parameters
     ALLOCATE ( surf_usm_h%surface_types(1:surf_usm_h%ns)      )
     ALLOCATE ( surf_usm_h%building_type(1:surf_usm_h%ns)      )
@@ -984,5 +988,5 @@
 
 !
-!-- wall and roof surface parameters. First for horizontal surfaces
+!-- Wall and roof surface parameters. First for horizontal surfaces
     ALLOCATE ( surf_usm_h%isroof_surf(1:surf_usm_h%ns)        )
     ALLOCATE ( surf_usm_h%lambda_surf(1:surf_usm_h%ns)        )
@@ -1020,5 +1024,5 @@
 
 !
-!-- allocate wall and roof material parameters. First for horizontal surfaces
+!-- Allocate wall and roof material parameters. First for horizontal surfaces
     ALLOCATE ( surf_usm_h%thickness_wall(1:surf_usm_h%ns)                    )
     ALLOCATE ( surf_usm_h%thickness_window(1:surf_usm_h%ns)                  )
@@ -1055,5 +1059,5 @@
 
 !
-!-- allocate green wall and roof vegetation and soil parameters. First horizontal surfaces
+!-- Allocate green wall and roof vegetation and soil parameters. First horizontal surfaces
     ALLOCATE ( surf_usm_h%g_d(1:surf_usm_h%ns)              )
     ALLOCATE ( surf_usm_h%c_liq(1:surf_usm_h%ns)            )
@@ -1077,5 +1081,5 @@
 
 !
-!-- allocate wall and roof layers sizes. For horizontal surfaces.
+!-- Allocate wall and roof layers sizes. For horizontal surfaces.
     ALLOCATE ( zwn(nzb_wall:nzt_wall)                                        )
     ALLOCATE ( surf_usm_h%dz_wall(nzb_wall:nzt_wall+1,1:surf_usm_h%ns)       )
@@ -1326,8 +1330,8 @@
 
 
-    IF ( variable(1:4) == 'usm_' )  THEN  ! is such a check really required?
-
-!
-!-- find the real name of the variable
+    IF ( variable(1:4) == 'usm_' )  THEN  ! Is such a check really required?
+
+!
+!-- Find the real name of the variable
     ids = -1
     l = -1
@@ -1343,5 +1347,5 @@
        ENDIF
     ENDDO
-    l = idsint - 2  ! horizontal direction index - terrible hack !
+    l = idsint - 2  ! Horizontal direction index - terrible hack !
     IF ( l < 0 .OR. l > 3 )  THEN
        l = -1
@@ -1352,5 +1356,5 @@
     IF ( var(1:11) == 'usm_t_wall_'  .AND.  len( TRIM( var ) ) >= 12 )  THEN
 !
-!--      wall layers
+!--      Wall layers
         READ( var(12:12), '(I1)', iostat=istat ) iwl
         IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
@@ -1358,5 +1362,5 @@
         ELSE
 !
-!--         wrong wall layer index
+!--         Wrong wall layer index
             RETURN
         ENDIF
@@ -1364,5 +1368,5 @@
     IF ( var(1:13) == 'usm_t_window_'  .AND.  len( TRIM(var) ) >= 14 )  THEN
 !
-!--      wall layers
+!--      Wall layers
         READ( var(14:14), '(I1)', iostat=istat ) iwl
         IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
@@ -1370,5 +1374,5 @@
         ELSE
 !
-!--         wrong window layer index
+!--         Wrong window layer index
             RETURN
         ENDIF
@@ -1376,5 +1380,5 @@
     IF ( var(1:12) == 'usm_t_green_'  .AND.  len( TRIM( var ) ) >= 13 )  THEN
 !
-!--      wall layers
+!--      Wall layers
         READ( var(13:13), '(I1)', iostat=istat ) iwl
         IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
@@ -1382,5 +1386,5 @@
         ELSE
 !
-!--         wrong green layer index
+!--         Wrong green layer index
             RETURN
         ENDIF
@@ -1388,5 +1392,5 @@
     IF ( var(1:8) == 'usm_swc_'  .AND.  len( TRIM( var ) ) >= 9 )  THEN
 !
-!--      swc layers
+!--      Swc layers
         READ( var(9:9), '(I1)', iostat=istat ) iwl
         IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
@@ -1394,5 +1398,5 @@
         ELSE
 !
-!--         wrong swc layer index
+!--         Wrong swc layer index
             RETURN
         ENDIF
@@ -1405,6 +1409,6 @@
             CASE ( 'usm_wshf' )
 !
-!--             array of sensible heat flux from surfaces
-!--             land surfaces
+!--             Array of sensible heat flux from surfaces
+!--             Land surfaces
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%wshf_eb_av ) )  THEN
@@ -1421,6 +1425,6 @@
             CASE ( 'usm_qsws' )
 !
-!--             array of latent heat flux from surfaces
-!--             land surfaces
+!--             Array of latent heat flux from surfaces
+!--             Land surfaces
                 IF ( l == -1 .AND. .NOT.  ALLOCATED( surf_usm_h%qsws_av ) )  THEN
                     ALLOCATE ( surf_usm_h%qsws_av(1:surf_usm_h%ns) )
@@ -1435,6 +1439,6 @@
             CASE ( 'usm_qsws_veg' )
 !
-!--             array of latent heat flux from vegetation surfaces
-!--             land surfaces
+!--             Array of latent heat flux from vegetation surfaces
+!--             Land surfaces
                 IF ( l == -1 .AND. .NOT.  ALLOCATED( surf_usm_h%qsws_veg_av ) )  THEN
                     ALLOCATE ( surf_usm_h%qsws_veg_av(1:surf_usm_h%ns) )
@@ -1449,6 +1453,6 @@
             CASE ( 'usm_qsws_liq' )
 !
-!--             array of latent heat flux from surfaces with liquid
-!--             land surfaces
+!--             Array of latent heat flux from surfaces with liquid
+!--             Land surfaces
                 IF ( l == -1 .AND. .NOT.  ALLOCATED( surf_usm_h%qsws_liq_av ) )  THEN
                     ALLOCATE ( surf_usm_h%qsws_liq_av(1:surf_usm_h%ns) )
@@ -1466,5 +1470,5 @@
             CASE ( 'usm_wghf' )
 !
-!--             array of heat flux from ground (wall, roof, land)
+!--             Array of heat flux from ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%wghf_eb_av ) )  THEN
@@ -1481,5 +1485,5 @@
             CASE ( 'usm_wghf_window' )
 !
-!--             array of heat flux from window ground (wall, roof, land)
+!--             Array of heat flux from window ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%wghf_eb_window_av ) )  THEN
@@ -1496,5 +1500,5 @@
             CASE ( 'usm_wghf_green' )
 !
-!--             array of heat flux from green ground (wall, roof, land)
+!--             Array of heat flux from green ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%wghf_eb_green_av ) )  THEN
@@ -1511,5 +1515,5 @@
             CASE ( 'usm_iwghf' )
 !
-!--             array of heat flux from indoor ground (wall, roof, land)
+!--             Array of heat flux from indoor ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%iwghf_eb_av ) )  THEN
@@ -1526,5 +1530,5 @@
             CASE ( 'usm_iwghf_window' )
 !
-!--             array of heat flux from indoor window ground (wall, roof, land)
+!--             Array of heat flux from indoor window ground (wall, roof, land)
                 IF ( l == -1 ) THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%iwghf_eb_window_av ) )  THEN
@@ -1541,5 +1545,5 @@
             CASE ( 'usm_t_surf_wall' )
 !
-!--             surface temperature for surfaces
+!--             Surface temperature for surfaces
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%t_surf_wall_av ) )  THEN
@@ -1556,5 +1560,5 @@
             CASE ( 'usm_t_surf_window' )
 !
-!--             surface temperature for window surfaces
+!--             Surface temperature for window surfaces
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%t_surf_window_av ) )  THEN
@@ -1571,5 +1575,5 @@
             CASE ( 'usm_t_surf_green' )
 !
-!--             surface temperature for green surfaces
+!--             Surface temperature for green surfaces
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%t_surf_green_av ) )  THEN
@@ -1586,5 +1590,5 @@
             CASE ( 'usm_theta_10cm' )
 !
-!--             near surface (10cm) temperature for whole surfaces
+!--             Near surface (10cm) temperature for whole surfaces
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%pt_10cm_av ) )  THEN
@@ -1601,5 +1605,5 @@
             CASE ( 'usm_t_wall' )
 !
-!--             wall temperature for iwl layer of walls and land
+!--             Wall temperature for iwl layer of walls and land
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%t_wall_av ) )  THEN
@@ -1616,5 +1620,5 @@
             CASE ( 'usm_t_window' )
 !
-!--             window temperature for iwl layer of walls and land
+!--             Window temperature for iwl layer of walls and land
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%t_window_av ) )  THEN
@@ -1631,5 +1635,5 @@
             CASE ( 'usm_t_green' )
 !
-!--             green temperature for iwl layer of walls and land
+!--             Green temperature for iwl layer of walls and land
                 IF ( l == -1 )  THEN
                    IF ( .NOT.  ALLOCATED( surf_usm_h%t_green_av ) )  THEN
@@ -1645,5 +1649,5 @@
             CASE ( 'usm_swc' )
 !
-!--             soil water content for iwl layer of walls and land
+!--             Soil water content for iwl layer of walls and land
                 IF ( l == -1 .AND. .NOT.  ALLOCATED( surf_usm_h%swc_av ) )  THEN
                     ALLOCATE ( surf_usm_h%swc_av(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
@@ -1667,5 +1671,5 @@
             CASE ( 'usm_wshf' )
 !
-!--             array of sensible heat flux from surfaces (land, roof, wall)
+!--             Array of sensible heat flux from surfaces (land, roof, wall)
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1681,5 +1685,5 @@
             CASE ( 'usm_qsws' )
 !
-!--             array of latent heat flux from surfaces (land, roof, wall)
+!--             Array of latent heat flux from surfaces (land, roof, wall)
                 IF ( l == -1 ) THEN
                 DO  m = 1, surf_usm_h%ns
@@ -1695,5 +1699,5 @@
             CASE ( 'usm_qsws_veg' )
 !
-!--             array of latent heat flux from vegetation surfaces (land, roof, wall)
+!--             Array of latent heat flux from vegetation surfaces (land, roof, wall)
                 IF ( l == -1 )  THEN
                 DO  m = 1, surf_usm_h%ns
@@ -1709,5 +1713,5 @@
             CASE ( 'usm_qsws_liq' )
 !
-!--             array of latent heat flux from surfaces with liquid (land, roof, wall)
+!--             Array of latent heat flux from surfaces with liquid (land, roof, wall)
                 IF ( l == -1 ) THEN
                 DO  m = 1, surf_usm_h%ns
@@ -1724,5 +1728,5 @@
             CASE ( 'usm_wghf' )
 !
-!--             array of heat flux from ground (wall, roof, land)
+!--             Array of heat flux from ground (wall, roof, land)
                 IF ( l == -1 ) THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1739,5 +1743,5 @@
             CASE ( 'usm_wghf_window' )
 !
-!--             array of heat flux from window ground (wall, roof, land)
+!--             Array of heat flux from window ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1754,5 +1758,5 @@
             CASE ( 'usm_wghf_green' )
 !
-!--             array of heat flux from green ground (wall, roof, land)
+!--             Array of heat flux from green ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1769,5 +1773,5 @@
             CASE ( 'usm_iwghf' )
 !
-!--             array of heat flux from indoor ground (wall, roof, land)
+!--             Array of heat flux from indoor ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1783,5 +1787,5 @@
             CASE ( 'usm_iwghf_window' )
 !
-!--             array of heat flux from indoor window ground (wall, roof, land)
+!--             Array of heat flux from indoor window ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1798,5 +1802,5 @@
             CASE ( 'usm_t_surf_wall' )
 !
-!--             surface temperature for surfaces
+!--             Surface temperature for surfaces
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1812,5 +1816,5 @@
             CASE ( 'usm_t_surf_window' )
 !
-!--             surface temperature for window surfaces
+!--             Surface temperature for window surfaces
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1827,5 +1831,5 @@
             CASE ( 'usm_t_surf_green' )
 !
-!--             surface temperature for green surfaces
+!--             Surface temperature for green surfaces
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1842,5 +1846,5 @@
             CASE ( 'usm_theta_10cm' )
 !
-!--             near surface temperature for whole surfaces
+!--             Near surface temperature for whole surfaces
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1857,5 +1861,5 @@
             CASE ( 'usm_t_wall' )
 !
-!--             wall temperature for  iwl layer of walls and land
+!--             Wall temperature for  iwl layer of walls and land
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1872,5 +1876,5 @@
             CASE ( 'usm_t_window' )
 !
-!--             window temperature for  iwl layer of walls and land
+!--             Window temperature for  iwl layer of walls and land
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1887,5 +1891,5 @@
             CASE ( 'usm_t_green' )
 !
-!--             green temperature for  iwl layer of walls and land
+!--             Green temperature for  iwl layer of walls and land
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1901,5 +1905,5 @@
             CASE ( 'usm_swc' )
 !
-!--             soil water content for  iwl layer of walls and land
+!--             Soil water content for  iwl layer of walls and land
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1920,5 +1924,5 @@
             CASE ( 'usm_wshf' )
 !
-!--             array of sensible heat flux from surfaces (land, roof, wall)
+!--             Array of sensible heat flux from surfaces (land, roof, wall)
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1935,5 +1939,5 @@
             CASE ( 'usm_qsws' )
 !
-!--             array of latent heat flux from surfaces (land, roof, wall)
+!--             Array of latent heat flux from surfaces (land, roof, wall)
                 IF ( l == -1 )  THEN
                 DO  m = 1, surf_usm_h%ns
@@ -1950,5 +1954,5 @@
             CASE ( 'usm_qsws_veg' )
 !
-!--             array of latent heat flux from vegetation surfaces (land, roof, wall)
+!--             Array of latent heat flux from vegetation surfaces (land, roof, wall)
                 IF ( l == -1 )  THEN
                 DO  m = 1, surf_usm_h%ns
@@ -1965,5 +1969,5 @@
             CASE ( 'usm_qsws_liq' )
 !
-!--             array of latent heat flux from surfaces with liquid (land, roof, wall)
+!--             Array of latent heat flux from surfaces with liquid (land, roof, wall)
                 IF ( l == -1 )  THEN
                 DO  m = 1, surf_usm_h%ns
@@ -1980,5 +1984,5 @@
             CASE ( 'usm_wghf' )
 !
-!--             array of heat flux from ground (wall, roof, land)
+!--             Array of heat flux from ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -1995,5 +1999,5 @@
             CASE ( 'usm_wghf_window' )
 !
-!--             array of heat flux from window ground (wall, roof, land)
+!--             Array of heat flux from window ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -2010,5 +2014,5 @@
             CASE ( 'usm_wghf_green' )
 !
-!--             array of heat flux from green ground (wall, roof, land)
+!--             Array of heat flux from green ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -2025,5 +2029,5 @@
             CASE ( 'usm_iwghf' )
 !
-!--             array of heat flux from indoor ground (wall, roof, land)
+!--             Array of heat flux from indoor ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -2040,5 +2044,5 @@
             CASE ( 'usm_iwghf_window' )
 !
-!--             array of heat flux from indoor window ground (wall, roof, land)
+!--             Array of heat flux from indoor window ground (wall, roof, land)
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -2055,5 +2059,5 @@
             CASE ( 'usm_t_surf_wall' )
 !
-!--             surface temperature for surfaces
+!--             Surface temperature for surfaces
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -2070,5 +2074,5 @@
             CASE ( 'usm_t_surf_window' )
 !
-!--             surface temperature for window surfaces
+!--             Surface temperature for window surfaces
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -2085,5 +2089,5 @@
             CASE ( 'usm_t_surf_green' )
 !
-!--             surface temperature for green surfaces
+!--             Surface temperature for green surfaces
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -2100,5 +2104,5 @@
             CASE ( 'usm_theta_10cm' )
 !
-!--             near surface temperature for whole surfaces
+!--             Near surface temperature for whole surfaces
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -2116,5 +2120,5 @@
             CASE ( 'usm_t_wall' )
 !
-!--             wall temperature for  iwl layer of walls and land
+!--             Wall temperature for  iwl layer of walls and land
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -2131,5 +2135,5 @@
             CASE ( 'usm_t_window' )
 !
-!--             window temperature for  iwl layer of walls and land
+!--             Window temperature for  iwl layer of walls and land
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -2146,5 +2150,5 @@
             CASE ( 'usm_t_green' )
 !
-!--             green temperature for  iwl layer of walls and land
+!--             Green temperature for  iwl layer of walls and land
                 IF ( l == -1 )  THEN
                    DO  m = 1, surf_usm_h%ns
@@ -2161,5 +2165,5 @@
             CASE ( 'usm_swc' )
 !
-!--             soil water content for  iwl layer of walls and land
+!--             Soil water content for  iwl layer of walls and land
                 IF ( l == -1 )  THEN
                 DO  m = 1, surf_usm_h%ns
@@ -2281,6 +2285,6 @@
 
 !
-!-- check if variable exists
-!-- directional variables
+!-- Check if variable exists
+!-- Directional variables
     DO  i = 1, nl1
        DO  j = 1, nd
@@ -2294,5 +2298,5 @@
     IF ( lfound )  GOTO 10
 !
-!-- directional layer variables
+!-- Directional layer variables
     DO  i = 1, nl2
        DO  j = 1, nd
@@ -2388,5 +2392,5 @@
     ENDIF
 !
-!-- naheatlayers
+!-- Naheatlayers
     IF ( naheatlayers > nzt )  THEN
        message_string = 'number of anthropogenic heat layers "naheatlayers" can not be larger ' // &
@@ -2473,5 +2477,5 @@
     IF ( var(1:11) == 'usm_t_wall_'  .AND.  len( TRIM( var ) ) >= 12 )  THEN
 !
-!--     wall layers
+!--     Wall layers
         READ( var(12:12), '(I1)', iostat = istat ) iwl
         IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
@@ -2481,5 +2485,5 @@
     IF ( var(1:13) == 'usm_t_window_'  .AND.  len( TRIM( var ) ) >= 14 )  THEN
 !
-!--     window layers
+!--     Window layers
         READ( var(14:14), '(I1)', iostat = istat ) iwl
         IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
@@ -2489,5 +2493,5 @@
     IF ( var(1:12) == 'usm_t_green_'  .AND.  len( TRIM( var ) ) >= 13 )  THEN
 !
-!--     green layers
+!--     Green layers
         READ( var(13:13), '(I1)', iostat = istat ) iwl
         IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
@@ -2497,5 +2501,5 @@
     IF ( var(1:8) == 'usm_swc_'  .AND.  len( TRIM( var ) ) >= 9 )  THEN
 !
-!--     green layers soil water content
+!--     Green layers soil water content
         READ( var(9:9), '(I1)', iostat = istat ) iwl
         IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
@@ -2508,5 +2512,5 @@
       CASE ( 'usm_surfz' )
 !
-!--       array of surface height (z)
+!--       Array of surface height (z)
           IF ( idsint == iup_u )  THEN
              DO  m = 1, surf_usm_h%ns
@@ -2528,5 +2532,5 @@
       CASE ( 'usm_surfcat' )
 !
-!--       surface category
+!--       Surface category
           IF ( idsint == iup_u )  THEN
              DO  m = 1, surf_usm_h%ns
@@ -2548,5 +2552,5 @@
       CASE ( 'usm_surfwintrans' )
 !
-!--       transmissivity window tiles
+!--       Transmissivity window tiles
           IF ( idsint == iup_u )  THEN
              DO  m = 1, surf_usm_h%ns
@@ -2568,5 +2572,5 @@
       CASE ( 'usm_wshf' )
 !
-!--       array of sensible heat flux from surfaces
+!--       Array of sensible heat flux from surfaces
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -2608,5 +2612,5 @@
       CASE ( 'usm_qsws' )
 !
-!--       array of latent heat flux from surfaces
+!--       Array of latent heat flux from surfaces
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -2647,5 +2651,5 @@
       CASE ( 'usm_qsws_veg' )
 !
-!--       array of latent heat flux from vegetation surfaces
+!--       Array of latent heat flux from vegetation surfaces
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -2686,5 +2690,5 @@
       CASE ( 'usm_qsws_liq' )
 !
-!--       array of latent heat flux from surfaces with liquid
+!--       Array of latent heat flux from surfaces with liquid
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -2725,5 +2729,5 @@
       CASE ( 'usm_wghf' )
 !
-!--       array of heat flux from ground (land, wall, roof)
+!--       Array of heat flux from ground (land, wall, roof)
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -2764,5 +2768,5 @@
       CASE ( 'usm_wghf_window' )
 !
-!--       array of heat flux from window ground (land, wall, roof)
+!--       Array of heat flux from window ground (land, wall, roof)
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -2803,5 +2807,5 @@
       CASE ( 'usm_wghf_green' )
 !
-!--       array of heat flux from green ground (land, wall, roof)
+!--       Array of heat flux from green ground (land, wall, roof)
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -2842,5 +2846,5 @@
       CASE ( 'usm_iwghf' )
 !
-!--       array of heat flux from indoor ground (land, wall, roof)
+!--       Array of heat flux from indoor ground (land, wall, roof)
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -2881,5 +2885,5 @@
       CASE ( 'usm_iwghf_window' )
 !
-!--       array of heat flux from indoor window ground (land, wall, roof)
+!--       Array of heat flux from indoor window ground (land, wall, roof)
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -2920,5 +2924,5 @@
       CASE ( 'usm_t_surf_wall' )
 !
-!--       surface temperature for surfaces
+!--       Surface temperature for surfaces
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -2959,5 +2963,5 @@
       CASE ( 'usm_t_surf_window' )
 !
-!--       surface temperature for window surfaces
+!--       Surface temperature for window surfaces
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -3001,5 +3005,5 @@
       CASE ( 'usm_t_surf_green' )
 !
-!--       surface temperature for green surfaces
+!--       Surface temperature for green surfaces
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -3043,5 +3047,5 @@
       CASE ( 'usm_theta_10cm' )
 !
-!--       near surface temperature for whole surfaces
+!--       Near surface temperature for whole surfaces
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -3085,5 +3089,5 @@
       CASE ( 'usm_t_wall' )
 !
-!--       wall temperature for  iwl layer of walls and land
+!--       Wall temperature for  iwl layer of walls and land
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -3124,5 +3128,5 @@
       CASE ( 'usm_t_window' )
 !
-!--       window temperature for iwl layer of walls and land
+!--       Window temperature for iwl layer of walls and land
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -3163,5 +3167,5 @@
       CASE ( 'usm_t_green' )
 !
-!--       green temperature for  iwl layer of walls and land
+!--       Green temperature for  iwl layer of walls and land
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -3202,5 +3206,5 @@
           CASE ( 'usm_swc' )
 !
-!--       soil water content for  iwl layer of walls and land
+!--       Soil water content for  iwl layer of walls and land
           IF ( av == 0 )  THEN
              IF ( idsint == iup_u )  THEN
@@ -3346,6 +3350,6 @@
        IF (surf_usm_h%green_type_roof(m) == 2.0_wp )  THEN
 !
-!-- extensive green roof
-!-- set ratio of substrate layer thickness, soil-type and LAI
+!-- Extensive green roof
+!-- Set ratio of substrate layer thickness, soil-type and LAI
           soil_type = 3
           surf_usm_h%lai(m) = 2.0_wp
@@ -3357,6 +3361,6 @@
        ELSE
 !
-!-- intensiv green roof
-!-- set ratio of substrate layer thickness, soil-type and LAI
+!-- Intensiv green roof
+!-- Set ratio of substrate layer thickness, soil-type and LAI
           soil_type = 6
           surf_usm_h%lai(m) = 4.0_wp
@@ -3560,5 +3564,5 @@
     CALL cpu_log( log_point_s(78), 'usm_init', 'start' )
 !
-!-- surface forcing has to be disabled for LSF in case of enabled urban surface module
+!-- Surface forcing has to be disabled for LSF in case of enabled urban surface module
     IF ( large_scale_forcing )  THEN
         lsf_surf = .FALSE.
@@ -3694,5 +3698,5 @@
         surf_usm_h%target_temp_winter(m)  = building_pars(ind_indoor_target_temp_winter,building_type)
 !
-!--     emissivity of wall-, green- and window fraction
+!--     Emissivity of wall-, green- and window fraction
         surf_usm_h%emissivity(m,ind_veg_wall)  = building_pars(ind_emis_wall_r,building_type)
         surf_usm_h%emissivity(m,ind_pav_green) = building_pars(ind_emis_green_r,building_type)
@@ -3705,5 +3709,5 @@
         surf_usm_h%z0q(m)                      = building_pars(ind_z0qh,building_type)
 !
-!--     albedo type for wall fraction, green fraction, window fraction
+!--     Albedo type for wall fraction, green fraction, window fraction
         surf_usm_h%albedo_type(m,ind_veg_wall)  = INT( building_pars(ind_alb_wall_r,building_type) )
         surf_usm_h%albedo_type(m,ind_pav_green) = INT( building_pars(ind_alb_green_r,building_type) )
@@ -3732,5 +3736,5 @@
         DO  m = 1, surf_usm_v(l)%ns
 
-           surf_usm_v(l)%surface_types(m) = wall_category         !< default category for root surface
+           surf_usm_v(l)%surface_types(m) = wall_category     !< Default category for root surface
 !
 !--        In order to distinguish between ground floor level and above-ground-floor level surfaces,
@@ -3850,5 +3854,5 @@
            surf_usm_v(l)%target_temp_winter(m)  = building_pars(ind_indoor_target_temp_winter,building_type)
 !
-!--        emissivity of wall-, green- and window fraction
+!--        Emissivity of wall-, green- and window fraction
            surf_usm_v(l)%emissivity(m,ind_veg_wall)  = building_pars(ind_emis_wall,building_type)
            surf_usm_v(l)%emissivity(m,ind_pav_green) = building_pars(ind_emis_green,building_type)
@@ -3943,5 +3947,5 @@
               surf_usm_h%target_temp_winter(m)  = building_pars(ind_indoor_target_temp_winter,st)
 !
-!--           emissivity of wall-, green- and window fraction
+!--           Emissivity of wall-, green- and window fraction
               surf_usm_h%emissivity(m,ind_veg_wall)  = building_pars(ind_emis_wall_r,st)
               surf_usm_h%emissivity(m,ind_pav_green) = building_pars(ind_emis_green_r,st)
@@ -3954,5 +3958,5 @@
               surf_usm_h%z0q(m)                 = building_pars(ind_z0qh,st)
 !
-!--           albedo type for wall fraction, green fraction, window fraction
+!--           Albedo type for wall fraction, green fraction, window fraction
               surf_usm_h%albedo_type(m,ind_veg_wall)  = INT( building_pars(ind_alb_wall_r,st) )
               surf_usm_h%albedo_type(m,ind_pav_green) = INT( building_pars(ind_alb_green_r,st) )
@@ -4106,5 +4110,5 @@
                  surf_usm_v(l)%target_temp_winter(m) = building_pars(ind_indoor_target_temp_winter,st)
 !
-!--              emissivity of wall-, green- and window fraction
+!--              Emissivity of wall-, green- and window fraction
                  surf_usm_v(l)%emissivity(m,ind_veg_wall)  = building_pars(ind_emis_wall,st)
                  surf_usm_v(l)%emissivity(m,ind_pav_green) = building_pars(ind_emis_green,st)
@@ -4659,5 +4663,5 @@
                  ENDIF
 
-                 EXIT ! surface was found and processed
+                 EXIT ! Surface was found and processed
               ENDIF
            ENDDO
@@ -4691,5 +4695,5 @@
                        surf_usm_v(l)%frac(m,ind_pav_green) =                                       &
                        building_surface_pars_f%pars(ind_s_green_frac_r,is)
-                       !TODO clarify: why should _w and _r be on the same surface?
+                       !TODO Clarify: why should _w and _r be on the same surface?
 
                     IF ( building_surface_pars_f%pars(ind_s_win_frac,is) /=                        &
@@ -4802,5 +4806,5 @@
                     ENDIF
 
-                    EXIT ! surface was found and processed
+                    EXIT ! Surface was found and processed
                  ENDIF
               ENDDO
@@ -4883,5 +4887,5 @@
      CALL usm_init_material_model()
 
-!--  init skin layer properties (can be done after initialization of wall layers)
+!--  Init skin layer properties (can be done after initialization of wall layers)
 
      DO  m = 1, surf_usm_h%ns
@@ -4924,8 +4928,8 @@
 
 !
-!--  init anthropogenic sources of heat
+!--  Init anthropogenic sources of heat
      IF ( usm_anthropogenic_heat )  THEN
 !
-!--      init anthropogenic sources of heat (from transportation for now)
+!--      Init anthropogenic sources of heat (from transportation for now)
          CALL usm_read_anthropogenic_heat()
      ENDIF
@@ -5031,6 +5035,6 @@
          ENDIF
 !
-!--      initial values for t_wall
-!--      outer value is set to surface temperature, inner value is set to wall_inner_temperature
+!--      Initial values for t_wall
+!--      Outer value is set to surface temperature, inner value is set to wall_inner_temperature
 !--      and profile is logaritmic (linear in nz).
 !--      Horizontal surfaces
@@ -5090,5 +5094,5 @@
 
 !
-!--  initialize prognostic values for the first timestep
+!--  Initialize prognostic values for the first timestep
      t_surf_wall_h_p = t_surf_wall_h
      t_surf_wall_v_p = t_surf_wall_v
@@ -5182,5 +5186,5 @@
        k = surf_usm_h%k(m)
 !
-!--    prognostic equation for ground/roof temperature t_wall_h
+!--    Prognostic equation for ground/roof temperature t_wall_h
        wtend(:) = 0.0_wp
        wtend(nzb_wall) = ( 1.0_wp / surf_usm_h%rho_c_wall(nzb_wall,m) )                            &
@@ -5206,5 +5210,5 @@
                             ) * surf_usm_h%ddz_wall_stag(nzb_wall,m)
 !
-!-- if indoor model is used inner wall layer is calculated by using iwghf (indoor wall ground heat flux)
+!-- If indoor model is used inner wall layer is calculated by using iwghf (indoor wall ground heat flux)
        IF ( indoor_model )  THEN
           DO  kw = nzb_wall+1, nzt_wall-1
@@ -5245,9 +5249,9 @@
 
 !
-!-- during spinup the tempeature inside window layers is not calculated to make larger timesteps possible
+!-- During spinup the tempeature inside window layers is not calculated to make larger timesteps possible
        IF ( .NOT. during_spinup )  THEN
           win_absorp = -log( surf_usm_h%transmissivity(m) ) / surf_usm_h%zw_window(nzt_wall,m)
 !
-!--       prognostic equation for ground/roof window temperature t_window_h takes absorption of
+!--       Prognostic equation for ground/roof window temperature t_window_h takes absorption of
 !--       shortwave radiation into account
           wintend(:) = 0.0_wp
@@ -5312,5 +5316,5 @@
 
 !
-!--    calculate t_wall tendencies for the next Runge-Kutta step
+!--    Calculate t_wall tendencies for the next Runge-Kutta step
        IF ( timestep_scheme(1:5) == 'runge' )  THEN
            IF ( intermediate_timestep_count == 1 )  THEN
@@ -5328,5 +5332,5 @@
        IF ( .NOT. during_spinup )  THEN
 !
-!--       calculate t_window tendencies for the next Runge-Kutta step
+!--       Calculate t_window tendencies for the next Runge-Kutta step
           IF ( timestep_scheme(1:5) == 'runge' )  THEN
               IF ( intermediate_timestep_count == 1 )  THEN
@@ -5356,5 +5360,5 @@
           k = surf_usm_v(l)%k(m)
 !
-!--       prognostic equation for wall temperature t_wall_v
+!--       Prognostic equation for wall temperature t_wall_v
           wtend(:) = 0.0_wp
 
@@ -5425,5 +5429,5 @@
                           surf_usm_v(l)%zw_window(nzt_wall,m)
 !
-!--          prognostic equation for window temperature t_window_v
+!--          Prognostic equation for window temperature t_window_v
              wintend(:) = 0.0_wp
              wintend(nzb_wall) = ( 1.0_wp / surf_usm_v(l)%rho_c_window(nzb_wall,m) )               &
@@ -5492,5 +5496,5 @@
 
 !
-!--       calculate t_wall tendencies for the next Runge-Kutta step
+!--       Calculate t_wall tendencies for the next Runge-Kutta step
           IF ( timestep_scheme(1:5) == 'runge' )  THEN
               IF ( intermediate_timestep_count == 1 )  THEN
@@ -5509,5 +5513,5 @@
           IF ( .NOT. during_spinup )  THEN
 !
-!--          calculate t_window tendencies for the next Runge-Kutta step
+!--          Calculate t_window tendencies for the next Runge-Kutta step
              IF ( timestep_scheme(1:5) == 'runge' )  THEN
                  IF ( intermediate_timestep_count == 1 )  THEN
@@ -5837,5 +5841,5 @@
           IF (surf_usm_v(l)%frac(m,ind_pav_green) > 0.0_wp)  THEN
 !
-!-- no substrate layer for green walls / only groundbase green walls (ivy i.e.) -> green layers get
+!-- No substrate layer for green walls / only groundbase green walls (ivy i.e.) -> Green layers get
 !-- same temperature as first wall layer, therefore no temperature calculations for vertical green
 !-- substrate layers now
@@ -5850,5 +5854,5 @@
 !              t_green_v(l)%t(nzt_wall+1,m) = t_wall_v(l)%t(nzb_wall,m)
 ! !
-! !--          prognostic equation for green temperature t_green_v
+! !--          Prognostic equation for green temperature t_green_v
 !              gtend(:) = 0.0_wp
 !              gtend(nzb_wall) = (1.0_wp / surf_usm_v(l)%rho_c_green(nzb_wall,m)) * &
@@ -5878,5 +5882,5 @@
 !
 ! !
-! !--          calculate t_green tendencies for the next Runge-Kutta step
+! !--          Calculate t_green tendencies for the next Runge-Kutta step
 !              IF ( timestep_scheme(1:5) == 'runge' )  THEN
 !                  IF ( intermediate_timestep_count == 1 )  THEN
@@ -6037,5 +6041,5 @@
         IF ( ii == io_group )  THEN
 
-!--         open anthropogenic heat file
+!--         Open anthropogenic heat file
             OPEN( 151, file = 'ANTHROPOGENIC_HEAT' // TRIM( coupling_char ), action = 'read',      &
                   status = 'old', form = 'formatted', err = 11 )
@@ -6046,5 +6050,5 @@
                 IF ( i >= nxl  .AND.  i <= nxr  .AND.  j >= nys  .AND.  j <= nyn )  THEN
                     IF ( k <= naheatlayers  .AND.  k > topo_top_ind(j,i,0) )  THEN
-!--                     write heat into the array
+!--                     Write heat into the array
                         aheat(k,j,i) = heat
                     ENDIF
@@ -6704,13 +6708,13 @@
 
 !
-!-- read categories of walls and their parameters
+!-- Read categories of walls and their parameters
     DO  ii = 0, io_blocks-1
         IF ( ii == io_group )  THEN
 !
-!--         open urban surface file
+!--         Open urban surface file
             OPEN( 151, file = 'SURFACE_PARAMETERS' // coupling_char,  action = 'read', &
                        status = 'old', form = 'formatted', err = 15 )
 !
-!--         first test and get n_surface_types
+!--         First test and get n_surface_types
             k = 0
             l = 0
@@ -6727,5 +6731,5 @@
             ALLOCATE( surface_params(n_surface_params, n_surface_types) )
 !
-!--         real reading
+!--         Real reading
             rewind( 151 )
             k = 0
@@ -6749,5 +6753,5 @@
 
 !
-!-- read types of surfaces
+!-- Read types of surfaces
     usm_par = 0
     DO  ii = 0, io_blocks-1
@@ -6755,5 +6759,5 @@
 
 !
-!--         open csv urban surface file
+!--         Open csv urban surface file
             OPEN( 151, file = 'URBAN_SURFACE' // TRIM( coupling_char ), action = 'read',           &
                   status = 'old', form = 'formatted', err = 23 )
@@ -6778,10 +6782,10 @@
                IF ( i >= nxlg  .AND.  i <= nxrg  .AND.  j >= nysg  .AND.  j <= nyng )  THEN
 !
-!--                write integer variables into array
+!--                Write integer variables into array
                    usm_par(:,j,i) = (/1, nz, roof, dirwe, dirsn, category,                         &
                                      weheight1, wecat1, weheight2, wecat2, weheight3, wecat3,      &
                                      snheight1, sncat1, snheight2, sncat2, snheight3, sncat3 /)
 !
-!--                write real values into array
+!--                Write real values into array
                    usm_val(:,j,i) = (/ albedo, thick,                                              &
                                       wealbedo1, wethick1, wealbedo2, wethick2,                    &
@@ -6807,5 +6811,5 @@
 
 !
-!-- check completeness and formal correctness of the data
+!-- Check completeness and formal correctness of the data
     DO  i = nxlg, nxrg
         DO  j = nysg, nyng
@@ -6829,5 +6833,5 @@
                 ) )  THEN
 !
-!--             incorrect input data
+!--             Incorrect input data
                 WRITE( message_string, '(A,2I5)' )                                                 &
                 'missing or incorrect data in file URBAN_SURFACE' //  TRIM( coupling_char ) //     &
@@ -6852,8 +6856,8 @@
           IF ( zu(kw) >= roof_height_limit )  THEN
              surf_usm_h%isroof_surf(m)   = .TRUE.
-             surf_usm_h%surface_types(m) = roof_category !< default category for root surface
+             surf_usm_h%surface_types(m) = roof_category !< Default category for root surface
           ELSE
              surf_usm_h%isroof_surf(m)   = .FALSE.
-             surf_usm_h%surface_types(m) = land_category !< default category for land surface
+             surf_usm_h%surface_types(m) = land_category !< Default category for land surface
           ENDIF
 
@@ -6890,5 +6894,5 @@
        IF ( ip == -99999 )  THEN
 !
-!--       land/roof category not found
+!--       Land/roof category not found
           WRITE(9, '(A, I5, A, 3I5)' ) 'land/roof category ', it, ' not found  for i, j, k = ',    &
                                        iw, jw, kw
@@ -6907,5 +6911,5 @@
           IF ( ip == -99999 )  THEN
 !
-!--          default land/roof category not found
+!--          Default land/roof category not found
              WRITE( 9, '(A, I5, A, 3I5)' ) 'Default land/roof category ', category, ' not found!'
              FLUSH( 9 )
@@ -6927,13 +6931,13 @@
        ENDIF
 !
-!--    emissivity of the wall
+!--    Emissivity of the wall
        surf_usm_h%emissivity(m,:) = surface_params(iemiss, ip)
 !
-!--    heat conductivity Î»S between air and wall ( W mâ2 Kâ1 )
+!--    Heat conductivity Î»S between air and wall ( W mâ2 Kâ1 )
        surf_usm_h%lambda_surf(m)        = surface_params(ilambdas,ip)
        surf_usm_h%lambda_surf_window(m) = surface_params(ilambdas,ip)
        surf_usm_h%lambda_surf_green(m)  = surface_params(ilambdas,ip)
 !
-!--    roughness length for momentum, heat and humidity
+!--    Roughness length for momentum, heat and humidity
        surf_usm_h%z0(m)  = surface_params(irough,ip)
        surf_usm_h%z0h(m) = surface_params(iroughh,ip)
@@ -6945,6 +6949,6 @@
        surf_usm_h%c_surface_green(m)  = surface_params(icsurf,ip)
 !
-!--    wall material parameters:
-!--    thickness of the wall (m) missing values are replaced by default value for category
+!--    Wall material parameters:
+!--    Thickness of the wall (m) missing values are replaced by default value for category
        IF ( surf_usm_h%thickness_wall(m) <= 0.001_wp )  THEN
             surf_usm_h%thickness_wall(m) = surface_params(ithick,ip)
@@ -6957,10 +6961,10 @@
        ENDIF
 !
-!--    volumetric heat capacity rho*C of the wall ( J mâ3 Kâ1 )
+!--    Volumetric heat capacity rho*C of the wall ( J mâ3 Kâ1 )
        surf_usm_h%rho_c_wall(:,m)   = surface_params(irhoC,ip)
        surf_usm_h%rho_c_window(:,m) = surface_params(irhoC,ip)
        surf_usm_h%rho_c_green(:,m)  = surface_params(irhoC,ip)
 !
-!--    thermal conductivity Î»H of the wall (W mâ1 Kâ1 )
+!--    Thermal conductivity Î»H of the wall (W mâ1 Kâ1 )
        surf_usm_h%lambda_h(:,m)        = surface_params(ilambdah,ip)
        surf_usm_h%lambda_h_window(:,m) = surface_params(ilambdah,ip)
@@ -6981,5 +6985,5 @@
           kw = surf_usm_v(l)%k(m)
 
-          IF ( l == 3 )  THEN ! westward facing
+          IF ( l == 3 )  THEN ! Westward facing
              iw = i
              jw = j
@@ -7005,9 +7009,9 @@
           IF ( iw < 0 .OR. jw < 0 ) THEN
 !
-!--          wall on west or south border of the domain - assign default category
+!--          Wall on west or south border of the domain - assign default category
              IF ( kw <= roof_height_limit ) THEN
-                 surf_usm_v(l)%surface_types(m) = wall_category   !< default category for wall surface in wall zone
+                 surf_usm_v(l)%surface_types(m) = wall_category   !< Default category for wall surface in wall zone
              ELSE
-                 surf_usm_v(l)%surface_types(m) = roof_category   !< default category for wall surface in roof zone
+                 surf_usm_v(l)%surface_types(m) = roof_category   !< Default category for wall surface in roof zone
              ENDIF
              surf_usm_v(l)%albedo(m,:)         = -1.0_wp
@@ -7018,8 +7022,8 @@
           ELSE IF ( kw <= usm_par(ii,jw,iw) )  THEN
 !
-!--             pedestrian zone
+!--             Pedestrian zone
              IF ( usm_par(ii+1,jw,iw) == 0 )  THEN
-                 surf_usm_v(l)%surface_types(m)  = pedestrian_category   !< default category for wall surface in
-                                                                         !< pedestrian zone
+                 surf_usm_v(l)%surface_types(m)  = pedestrian_category   !< Default category for wall surface in
+                                                                         !< Pedestrian zone
                  surf_usm_v(l)%albedo(m,:)         = -1.0_wp
                  surf_usm_v(l)%thickness_wall(m)   = -1.0_wp
@@ -7037,5 +7041,5 @@
           ELSE IF ( kw <= usm_par(ii+2,jw,iw) )  THEN
 !
-!--          wall zone
+!--          Wall zone
              IF ( usm_par(ii+3,jw,iw) == 0 )  THEN
                  surf_usm_v(l)%surface_types(m)    = wall_category  !< default category for wall surface
@@ -7055,7 +7059,7 @@
           ELSE IF ( kw <= usm_par(ii+4,jw,iw) )  THEN
 !
-!--          roof zone
+!--          Roof zone
              IF ( usm_par(ii+5,jw,iw) == 0 )  THEN
-                 surf_usm_v(l)%surface_types(m)    = roof_category  !< default category for roof surface
+                 surf_usm_v(l)%surface_types(m)    = roof_category  !< Default category for roof surface
                  surf_usm_v(l)%albedo(m,:)         = -1.0_wp
                  surf_usm_v(l)%thickness_wall(m)   = -1.0_wp
@@ -7081,9 +7085,9 @@
              FLUSH( 9 )
 !
-!--          supply the default category
+!--          Supply the default category
              IF ( kw <= roof_height_limit )  THEN
-                 surf_usm_v(l)%surface_types(m) = wall_category  !< default category for wall surface in wall zone
+                 surf_usm_v(l)%surface_types(m) = wall_category  !< Default category for wall surface in wall zone
              ELSE
-                 surf_usm_v(l)%surface_types(m) = roof_category  !< default category for wall surface in roof zone
+                 surf_usm_v(l)%surface_types(m) = roof_category  !< Default category for wall surface in roof zone
              ENDIF
              surf_usm_v(l)%albedo(m,:)         = -1.0_wp
@@ -7105,5 +7109,5 @@
           IF ( ip == -99999 )  THEN
 !
-!--          wall category not found
+!--          Wall category not found
              WRITE( 9, '(A,I7,A,3I5)' ) 'wall category ', it, ' not found  for i,j,k = ', iw, jw, kw
              FLUSH(9)
@@ -7117,5 +7121,5 @@
              IF ( ip == -99999 )  THEN
 !
-!--             default wall category not found
+!--             Default wall category not found
                 WRITE ( 9, '(A,I5,A,3I5)' ) 'Default wall category', category, ' not found!'
                 FLUSH( 9 )
@@ -7136,13 +7140,13 @@
           ENDIF
 !
-!--       emissivity of the wall
+!--       Emissivity of the wall
           surf_usm_v(l)%emissivity(:,m) = surface_params(iemiss,ip)
 !
-!--       heat conductivity lambda S between air and wall ( W m-2 K-1 )
+!--       Heat conductivity lambda S between air and wall ( W m-2 K-1 )
           surf_usm_v(l)%lambda_surf(m)        = surface_params(ilambdas,ip)
           surf_usm_v(l)%lambda_surf_window(m) = surface_params(ilambdas,ip)
           surf_usm_v(l)%lambda_surf_green(m)  = surface_params(ilambdas,ip)
 !
-!--       roughness length
+!--       Roughness length
           surf_usm_v(l)%z0(m)  = surface_params(irough,ip)
           surf_usm_v(l)%z0h(m) = surface_params(iroughh,ip)
@@ -7154,7 +7158,7 @@
           surf_usm_v(l)%c_surface_green(m)  = surface_params(icsurf,ip)
 !
-!--       wall material parameters:
-!--       thickness of the wall (m)
-!--       missing values are replaced by default value for category
+!--       Wall material parameters:
+!--       Thickness of the wall (m)
+!--       Missing values are replaced by default value for category
           IF ( surf_usm_v(l)%thickness_wall(m) <= 0.001_wp )  THEN
                surf_usm_v(l)%thickness_wall(m) = surface_params(ithick,ip)
@@ -7167,10 +7171,10 @@
           ENDIF
 !
-!--       volumetric heat capacity rho*C of the wall ( J m-3 K-1 )
+!--       Volumetric heat capacity rho*C of the wall ( J m-3 K-1 )
           surf_usm_v(l)%rho_c_wall(:,m)   = surface_params(irhoC,ip)
           surf_usm_v(l)%rho_c_window(:,m) = surface_params(irhoC,ip)
           surf_usm_v(l)%rho_c_green(:,m)  = surface_params(irhoC,ip)
 !
-!--       thermal conductivity lambda H of the wall (W m-1 K-1 )
+!--       Thermal conductivity lambda H of the wall (W m-1 K-1 )
           surf_usm_v(l)%lambda_h(:,m)        = surface_params(ilambdah,ip)
           surf_usm_v(l)%lambda_h_window(:,m) = surface_params(ilambdah,ip)
@@ -7189,5 +7193,5 @@
     ENDDO
 !
-!-- apply for all particular surface grids. First for horizontal surfaces
+!-- Apply for all particular surface grids. First for horizontal surfaces
     DO  m = 1, surf_usm_h%ns
        surf_usm_h%zw(:,m)        = zwn(:) * surf_usm_h%thickness_wall(m)
@@ -7264,5 +7268,5 @@
         IF ( ii == io_group )  THEN
 !
-!--         open wall temperature file
+!--         Open wall temperature file
             OPEN( 152, file = 'WALL_TEMPERATURE' // coupling_char, action = 'read', &
                        status = 'old', form = 'formatted', err = 15 )
@@ -7271,8 +7275,8 @@
             iline = 1
             DO
-                rtwall = -9999.0_wp  !< for incomplete lines
+                rtwall = -9999.0_wp  !< For incomplete lines
                 READ( 152, *, err = 13, end = 14 )  i, j, k, d, rtsurf, rtwall
 
-                IF ( nxl <= i .AND. i <= nxr .AND. nys <= j .AND. j <= nyn)  THEN  !< local processor
+                IF ( nxl <= i .AND. i <= nxr .AND. nys <= j .AND. j <= nyn)  THEN  !< Local processor
 !--                 identify surface id
                     isurfl = find_surface( i, j, k, d )
@@ -7284,5 +7288,5 @@
                     ENDIF
 !
-!--                 assign temperatures
+!--                 Assign temperatures
                     IF ( d == 0 )  THEN
                        t_surf_wall_h(isurfl) = rtsurf
@@ -7446,5 +7450,5 @@
        ENDIF
 !
-!--    calculate rho * c_p coefficient at surface layer
+!--    Calculate rho * c_p coefficient at surface layer
        rho_cp  = c_p * hyp(k) / ( r_d * surf_usm_h%pt1(m) * exner(k) )
 
@@ -7486,5 +7490,5 @@
 
 !
-!--    factor for shf_eb
+!--    Factor for shf_eb
        f_shf         = rho_cp / surf_usm_h%r_a(m)
        f_shf_window  = rho_cp / surf_usm_h%r_a_window(m)
@@ -7497,9 +7501,9 @@
 !--       ECMWF documentation
 
-!--       f1: correction for incoming shortwave radiation (stomata close at night)
+!--       f1: Correction for incoming shortwave radiation (stomata close at night)
           f1 = MIN( 1.0_wp, ( 0.004_wp * surf_usm_h%rad_sw_in(m) + 0.05_wp ) /                     &
                     (0.81_wp * ( 0.004_wp * surf_usm_h%rad_sw_in(m) + 1.0_wp ) ) )
 !
-!--       f2: correction for soil moisture availability to plants (the integrated soil moisture must
+!--       f2: Correction for soil moisture availability to plants (the integrated soil moisture must
 !--       thus be considered here) f2 = 0 for very dry soils
           m_total = 0.0_wp
@@ -7521,5 +7525,5 @@
                                            / ( t_surf_green_h(m) - 35.86_wp ) )
 !
-!--       f3: correction for vapour pressure deficit
+!--       f3: Correction for vapour pressure deficit
           IF ( surf_usm_h%g_d(m) /= 0.0_wp )  THEN
 !
@@ -7574,9 +7578,9 @@
        ENDIF
 !
-!--    add LW up so that it can be removed in prognostic equation
+!--    Add LW up so that it can be removed in prognostic equation
        surf_usm_h%rad_net_l(m) = surf_usm_h%rad_sw_in(m)  - surf_usm_h%rad_sw_out(m) +             &
                                  surf_usm_h%rad_lw_in(m)  - surf_usm_h%rad_lw_out(m)
 !
-!--    numerator of the prognostic equation
+!--    Numerator of the prognostic equation
 !--    Todo: Adjust to tile approach. So far, emissivity for wall (element 0) is used
        coef_1 = surf_usm_h%rad_net_l(m) + ( 3.0_wp + 1.0_wp )                                      &
@@ -7603,5 +7607,5 @@
        ENDIF
 !
-!--    denominator of the prognostic equation
+!--    Denominator of the prognostic equation
        coef_2 = 4.0_wp * surf_usm_h%emissivity(m,ind_veg_wall) * sigma_sb * t_surf_wall_h(m)**3    &
                 + lambda_surface + f_shf / exner(k)
@@ -7619,5 +7623,5 @@
        ENDIF
 !
-!--    implicit solution when the surface layer has no heat capacity, otherwise use RK3 scheme.
+!--    Implicit solution when the surface layer has no heat capacity, otherwise use RK3 scheme.
        t_surf_wall_h_p(m) = ( coef_1 * dt_3d * tsc(2) + surf_usm_h%c_surface(m)                    &
                               * t_surf_wall_h(m) )                                                 &
@@ -7632,5 +7636,5 @@
                              /  ( surf_usm_h%c_surface_green(m) + coef_green_2 * dt_3d * tsc(2) )
 !
-!--    add RK3 term
+!--    Add RK3 term
        t_surf_wall_h_p(m) = t_surf_wall_h_p(m) + dt_3d * tsc(3) *  surf_usm_h%tt_surface_wall_m(m)
 
@@ -7650,5 +7654,5 @@
        IF ( humidity )  surf_usm_h%vpt_surface(m) = surf_usm_h%pt_surface(m)
 !
-!--    calculate true tendency
+!--    Calculate true tendency
        stend_wall = ( t_surf_wall_h_p(m) - t_surf_wall_h(m) - dt_3d * tsc(3) *                     &
                       surf_usm_h%tt_surface_wall_m(m) ) / ( dt_3d  * tsc(2) )
@@ -7658,5 +7662,5 @@
                        surf_usm_h%tt_surface_green_m(m) ) / ( dt_3d  * tsc(2) )
 !
-!--    calculate t_surf tendencies for the next Runge-Kutta step
+!--    Calculate t_surf tendencies for the next Runge-Kutta step
        IF ( timestep_scheme(1:5) == 'runge' )  THEN
           IF ( intermediate_timestep_count == 1 )  THEN
@@ -7674,5 +7678,5 @@
        ENDIF
 !
-!--    in case of fast changes in the skin temperature, it is required to update the radiative
+!--    In case of fast changes in the skin temperature, it is required to update the radiative
 !--    fluxes in order to keep the solution stable
        IF ( ( ( ABS( t_surf_wall_h_p(m)   - t_surf_wall_h(m) )   > 1.0_wp )   .OR.                 &
@@ -7683,6 +7687,6 @@
        ENDIF
 !
-!--    calculate fluxes
-!--    rad_net_l is never used!
+!--    Calculate fluxes
+!--    Rad_net_l is never used!
        surf_usm_h%rad_net_l(m) = surf_usm_h%rad_net_l(m) + surf_usm_h%frac(m,ind_veg_wall)         &
                                  * sigma_sb * surf_usm_h%emissivity(m,ind_veg_wall)                &
@@ -7702,5 +7706,5 @@
 
 !
-!--    ground/wall/roof surface heat flux
+!--    Ground/wall/roof surface heat flux
        surf_usm_h%wshf_eb(m)   = - f_shf  * ( surf_usm_h%pt1(m) - t_surf_wall_h_p(m) / exner(k) )  &
                                  * surf_usm_h%frac(m,ind_veg_wall) - f_shf_window                  &
@@ -7710,5 +7714,5 @@
                                  * surf_usm_h%frac(m,ind_pav_green)
 !
-!--    store kinematic surface heat fluxes for utilization in other processes diffusion_s,
+!--    Store kinematic surface heat fluxes for utilization in other processes diffusion_s,
 !--    surface_layer_fluxes,...
        surf_usm_h%shf(m) = surf_usm_h%wshf_eb(m) / c_p
@@ -7862,5 +7866,5 @@
            ENDIF
 !
-!--        calculate rho * c_p coefficient at wall layer
+!--        Calculate rho * c_p coefficient at wall layer
            rho_cp  = c_p * hyp(k) / ( r_d * surf_usm_v(l)%pt1(m) * exner(k) )
 
@@ -7874,5 +7878,5 @@
 !--        Calculation of r_a for vertical surfaces
 !--
-!--        heat transfer coefficient for forced convection along vertical walls follows formulation
+!--        Heat transfer coefficient for forced convection along vertical walls follows formulation
 !--        in TUF3d model (Krayenhoff & Voogt, 2006)
 !--
@@ -7880,13 +7884,13 @@
 !--        httc = rw * (11.8 + 4.2 * Ueff) - 4.0
 !--
-!--             rw: wall patch roughness relative to 1.0 for concrete
-!--             Ueff: effective wind speed
+!--             rw: Wall patch roughness relative to 1.0 for concrete
+!--             Ueff: Effective wind speed
 !--             - 4.0 is a reduction of Rowley et al (1930) formulation based on
 !--             Cole and Sturrock (1977)
 !--
 !--             Ucan: Canyon wind speed
-!--             wstar: convective velocity
-!--             Qs: surface heat flux
-!--             zH: height of the convective layer
+!--             wstar: Convective velocity
+!--             Qs: Surface heat flux
+!--             zH: Height of the convective layer
 !--             wstar = (g/Tcan*Qs*zH)**(1./3.)
 !--        Effective velocity components must always be defined at scalar grid point. The wall
@@ -7917,5 +7921,5 @@
                                 / (0.81_wp * (0.004_wp * surf_usm_v(l)%rad_sw_in(m) + 1.0_wp) ) )
 !
-!--           f2: correction for soil moisture availability to plants (the integrated soil moisture
+!--           f2: Correction for soil moisture availability to plants (the integrated soil moisture
 !--           must thus be considered here) f2 = 0 for very dry soils
               f2=1.0_wp
@@ -7926,5 +7930,5 @@
                                                / (  t_surf_green_v_p(l)%t(m) - 35.86_wp ) )
 !
-!--           f3: correction for vapour pressure deficit
+!--           f3: Correction for vapour pressure deficit
               IF ( surf_usm_v(l)%g_d(m) /= 0.0_wp )  THEN
 !
@@ -7972,10 +7976,10 @@
 
 !
-!--        add LW up so that it can be removed in prognostic equation
+!--        Add LW up so that it can be removed in prognostic equation
            surf_usm_v(l)%rad_net_l(m) = surf_usm_v(l)%rad_sw_in(m) - surf_usm_v(l)%rad_sw_out(m)   &
                                         + surf_usm_v(l)%rad_lw_in(m)  - surf_usm_v(l)%rad_lw_out(m)
 !
-!--        numerator of the prognostic equation
-           coef_1 = surf_usm_v(l)%rad_net_l(m) +                             & ! coef +1 corresponds to -lwout
+!--        Numerator of the prognostic equation
+           coef_1 = surf_usm_v(l)%rad_net_l(m) +                             & ! Coef +1 corresponds to -lwout
                                                                                ! included in calculation of radnet_l
            ( 3.0_wp + 1.0_wp ) * surf_usm_v(l)%emissivity(m,ind_veg_wall) *                        &
@@ -7984,5 +7988,5 @@
                                    lambda_surface * t_wall_v(l)%t(nzb_wall,m)
            IF ( ( .NOT. during_spinup )  .AND.  ( surf_usm_v(l)%frac(m,ind_wat_win) > 0.0_wp ) ) THEN
-              coef_window_1 = surf_usm_v(l)%rad_net_l(m) +                   & ! coef +1 corresponds to -lwout
+              coef_window_1 = surf_usm_v(l)%rad_net_l(m) +                   & ! Coef +1 corresponds to -lwout
                                                                                ! included in calculation of radnet_l
              ( 3.0_wp + 1.0_wp ) * surf_usm_v(l)%emissivity(m,ind_wat_win) *                       &
@@ -7992,5 +7996,5 @@
            ENDIF
            IF ( ( humidity )  .AND.  ( surf_usm_v(l)%frac(m,ind_pav_green) > 0.0_wp ) )  THEN
-              coef_green_1 = surf_usm_v(l)%rad_net_l(m) +                      & ! coef +1 corresponds to -lwout
+              coef_green_1 = surf_usm_v(l)%rad_net_l(m) +                      & ! Coef +1 corresponds to -lwout
                                                                                  ! included in calculation of radnet_l
               ( 3.0_wp + 1.0_wp ) * surf_usm_v(l)%emissivity(m,ind_pav_green) * sigma_sb *         &
@@ -8000,5 +8004,5 @@
                                    lambda_surface_green * t_wall_v(l)%t(nzb_wall,m)
            ELSE
-             coef_green_1 = surf_usm_v(l)%rad_net_l(m) +                       & ! coef +1 corresponds to -lwout included
+             coef_green_1 = surf_usm_v(l)%rad_net_l(m) +                       & ! Coef +1 corresponds to -lwout included
                                                                                  ! in calculation of radnet_l
              ( 3.0_wp + 1.0_wp ) * surf_usm_v(l)%emissivity(m,ind_pav_green) * sigma_sb *          &
@@ -8009,5 +8013,5 @@
 
 !
-!--        denominator of the prognostic equation
+!--        Denominator of the prognostic equation
            coef_2 = 4.0_wp * surf_usm_v(l)%emissivity(m,ind_veg_wall) * sigma_sb                   &
                     * t_surf_wall_v(l)%t(m)**3 + lambda_surface + f_shf / exner(k)
@@ -8025,5 +8029,5 @@
            ENDIF
 !
-!--        implicit solution when the surface layer has no heat capacity, otherwise use RK3 scheme.
+!--        Implicit solution when the surface layer has no heat capacity, otherwise use RK3 scheme.
            t_surf_wall_v_p(l)%t(m) = ( coef_1 * dt_3d * tsc(2) + surf_usm_v(l)%c_surface(m)        &
                                        * t_surf_wall_v(l)%t(m) ) / ( surf_usm_v(l)%c_surface(m)    &
@@ -8042,5 +8046,5 @@
                                         + coef_green_2 * dt_3d * tsc(2) )
 !
-!--        add RK3 term
+!--        Add RK3 term
            t_surf_wall_v_p(l)%t(m)   = t_surf_wall_v_p(l)%t(m) + dt_3d * tsc(3) *                  &
                                        surf_usm_v(l)%tt_surface_wall_m(m)
@@ -8062,5 +8066,5 @@
            IF ( humidity )  surf_usm_v(l)%vpt_surface(m) = surf_usm_v(l)%pt_surface(m)
 !
-!--        calculate true tendency
+!--        Calculate true tendency
            stend_wall = ( t_surf_wall_v_p(l)%t(m) - t_surf_wall_v(l)%t(m) - dt_3d * tsc(3) *       &
                           surf_usm_v(l)%tt_surface_wall_m(m) ) / ( dt_3d  * tsc(2) )
@@ -8071,5 +8075,5 @@
 
 !
-!--        calculate t_surf_* tendencies for the next Runge-Kutta step
+!--        Calculate t_surf_* tendencies for the next Runge-Kutta step
            IF ( timestep_scheme(1:5) == 'runge' )  THEN
               IF ( intermediate_timestep_count == 1 )  THEN
@@ -8088,5 +8092,5 @@
 
 !
-!--        in case of fast changes in the skin temperature, it is required to update the radiative
+!--        In case of fast changes in the skin temperature, it is required to update the radiative
 !--        fluxes in order to keep the solution stable
 
@@ -8099,6 +8103,6 @@
 
 !
-!--        calculate fluxes
-!--        prognostic rad_net_l is used just for output!
+!--        Calculate fluxes
+!--        Prognostic rad_net_l is used just for output!
            surf_usm_v(l)%rad_net_l(m) = surf_usm_v(l)%frac(m,ind_veg_wall) *                       &
                                         ( surf_usm_v(l)%rad_net_l(m) + 3.0_wp * sigma_sb *         &
@@ -8124,5 +8128,5 @@
 
 !
-!--        ground/wall/roof surface heat flux
+!--        Ground/wall/roof surface heat flux
            surf_usm_v(l)%wshf_eb(m) = - f_shf  * ( surf_usm_v(l)%pt1(m) - t_surf_wall_v_p(l)%t(m)  &
                                       / exner(k) ) * surf_usm_v(l)%frac(m,ind_veg_wall)            &
@@ -8134,5 +8138,5 @@
 
 !
-!--        store kinematic surface heat fluxes for utilization in other processes diffusion_s,
+!--        Store kinematic surface heat fluxes for utilization in other processes diffusion_s,
 !--        surface_layer_fluxes,...
            surf_usm_v(l)%shf(m) = surf_usm_v(l)%wshf_eb(m) / c_p
@@ -8221,5 +8225,5 @@
 !--      TO_DO: activate, if testcase is available
 !--      !$OMP PARALLEL DO PRIVATE (i, j, k, acoef, rho_cp)
-!--      it may also improve performance to move topo_top_ind before the k-loop
+!--      It may also improve performance to move topo_top_ind before the k-loop
          DO i = nxl, nxr
             DO j = nys, nyn
@@ -8227,5 +8231,5 @@
                   IF ( k > topo_top_ind(j,i,0) )  THEN
 !
-!--                 increase of pt in box i,j,k in time dt_3d given to anthropogenic heat
+!--                 Increase of pt in box i,j,k in time dt_3d given to anthropogenic heat
 !--                 aheat*acoef (W*m-2)
 !--                 linear interpolation of coeficient
@@ -8236,5 +8240,5 @@
                      IF ( aheat(k,j,i) > 0.0_wp )  THEN
 !
-!--                    calculate rho * c_p coefficient at layer k
+!--                    Calculate rho * c_p coefficient at layer k
                         rho_cp  = c_p * hyp(k) / ( r_d * pt(k+1,j,i) * exner(k) )
                         pt(k,j,i) = pt(k,j,i) + aheat(k,j,i) * acoef * dt_3d / (exner(k) * rho_cp  &
@@ -8303,5 +8307,5 @@
 !!                                 ( surf_usm_h%ts(m) * surf_usm_h%us(m) + 1.0E-10_wp )
 !!
-!! !-    make sure that the resistance does not drop to zero
+!! !-    Make sure that the resistance does not drop to zero
 !!       IF ( ABS(surf_usm_h%r_a_green(m)) < 1.0E-10_wp )  surf_usm_h%r_a_green(m) = 1.0E-10_wp
 !
