Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 4465)
+++ palm/trunk/SOURCE/Makefile	(revision 4466)
@@ -25,41 +25,44 @@
 # -----------------
 # $Id$
+# cpu measures in advec_ws added
+#
+# 4458 2020-03-11 15:37:31Z raasch
 # bugfix for r4457: missing dependency added
-# 
+#
 # 4457 2020-03-11 14:20:43Z raasch
 # exchange horiz has been modularized and exchange horiz 2d has been merged, dependencies updated
 # accordingly
-# 
+#
 # 4453 2020-03-11 08:10:13Z raasch
 # dependencies for exchange horiz modified
-# 
+#
 # 4434 2020-03-03 10:02:18Z oliver.maas
 # Added output control for wind turbine model
-# 
+#
 # 4414 2020-02-19 20:16:04Z suehring
 # Move dependencies for init grid from advection scheme and multigrid solver
 # to module_interface
-# 
+#
 # 4411 2020-02-18 14:28:02Z maronga
 # Added output routines for WTM
-# 
+#
 # 4400 2020-02-10 20:32:41Z suehring
 # Add dependency for data-output module
-# 
+#
 # 4392 2020-01-31 16:14:57Z pavelkrc
 # add dependency on fft for transpose
-# 
+#
 # 4347 2019-12-18 13:18:33Z suehring
 # add dependency to basic_constants_and_equations_mod for dynamics_mod
-# 
+#
 # 4331 2019-12-10 18:25:02Z suehring
 # Move diagnostic surface output to diagnostic_output_quantities
-# 
+#
 # 4309 2019-11-26 18:49:59Z suehring
 # Add dependency to parallel random generator for synthetic turbulence generator
-# 
+#
 # 4286 2019-10-30 16:01:14Z resler
 # delete boundary_conds, added missing dependencies
-# 
+#
 # 4270 2019-10-23 10:46:20Z monakurppa
 # - Implement offline nesting for salsa and add dependency of nesting_offl_mod
@@ -68,11 +71,11 @@
 #   for salsa
 # - Add dependency on basic_constants_and_equations_mod for salsa_mod
-# 
+#
 # 4258 2019-10-07 13:29:08Z suehring
 # Add dependency of land-surface model on pmc_handle_communicator and cpu_log
-# 
+#
 # 4245 2019-09-30 08:40:37Z pavelkrc
 # Remove no longer needed dependencies on surface_mod
-# 
+#
 # 4227 2019-09-10 18:04:34Z gronemeier
 # Add palm_date_time_mod, remove date_and_time_mod
@@ -80,25 +83,25 @@
 # 4223 2019-09-10 09:20:47Z gronemeier
 # Corrected "Former revisions" section
-# 
+#
 # 4174 2019-08-20 12:41:13Z gronemeier
 # bugfix: add missing dependencies for vdi_internal_controls
-# 
+#
 # 4173 2019-08-20 12:04:06Z gronemeier
 # add vdi_internal_controls
-# 
+#
 # 4168 2019-08-16 13:50:17Z suehring
 # Remove some dependencies on surface_mod that are no longer required without
 # get_topography_top_index functions
-# 
+#
 # 4167 2019-08-16 11:01:48Z suehring
 # Remove no longer needed dependencies on surface_mod
-# 
+#
 # 4127 2019-07-30 14:47:10Z suehring
-# Add dependency of data_output_3d on plant_canopy_model_mod 
+# Add dependency of data_output_3d on plant_canopy_model_mod
 # (merge from branch resler)
 #
 # 4106 2019-07-19 08:54:42Z gronemeier
 # Remove dependency on pmc_interface for boundary_conds
-# 
+#
 # 4070 2019-07-03 13:51:40Z gronemeier
 # Add new data output modules
@@ -358,4 +361,5 @@
 	modules.o
 advec_ws.o: \
+	cpulog_mod.o \
 	exchange_horiz_mod.o \
 	mod_kinds.o \
@@ -825,5 +829,5 @@
 	modules.o \
 	netcdf_data_input_mod.o \
-	salsa_mod.o 
+	salsa_mod.o
 netcdf_data_input_mod.o: \
 	chem_modules.o \
Index: palm/trunk/SOURCE/advec_ws.f90
===================================================================
--- palm/trunk/SOURCE/advec_ws.f90	(revision 4465)
+++ palm/trunk/SOURCE/advec_ws.f90	(revision 4466)
@@ -20,103 +20,111 @@
 ! Current revisions:
 ! ------------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! - vector branch further optimized (linear dependencies along z removed and
+!   loops are splitted)
+! - topography closed channel flow with symmetric boundaries also implemented
+!   in vector branch
+! - some formatting adjustments made and comments added
+! - cpu measures for vector branch added
+!
+! 4457 2020-03-11 14:20:43Z raasch
 ! use statement for exchange horiz added
-! 
+!
 ! 4414 2020-02-19 20:16:04Z suehring
 ! Move call for initialization of control flags to ws_init
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Introduction of wall_flags_total_0, which currently sets bits based on static
 ! topography information used in wall_flags_static_0
-! 
+!
 ! 4340 2019-12-16 08:17:03Z Giersch
-! Topography closed channel flow with symmetric boundaries implemented 
-! 
+! Topography closed channel flow with symmetric boundaries implemented
+!
 ! 4330 2019-12-10 16:16:33Z knoop
 ! Bugix: removed syntax error introduced by last commit
-! 
+!
 ! 4329 2019-12-10 15:46:36Z motisi
 ! Renamed wall_flags_0 to wall_flags_static_0
-! 
+!
 ! 4328 2019-12-09 18:53:04Z suehring
 ! Minor formatting adjustments
-! 
+!
 ! 4327 2019-12-06 14:48:31Z Giersch
 ! Setting of advection flags for vertical fluxes of w revised, air density for
 ! vertical flux calculation of w at k=1 is considered now
-! 
+!
 ! 4325 2019-12-06 07:14:04Z Giersch
-! Vertical fluxes of w are now set to zero at nzt and nzt+1, setting of 
+! Vertical fluxes of w are now set to zero at nzt and nzt+1, setting of
 ! advection flags for fluxes in z-direction revised, comments extended
-! 
+!
 ! 4324 2019-12-06 07:11:33Z Giersch
 ! Indirect indexing for calculating vertical fluxes close to boundaries is only
 ! used for loop indizes where it is really necessary
-! 
+!
 ! 4317 2019-12-03 12:43:22Z Giersch
-! Comments revised/added, formatting improved, fluxes for u,v, and scalars are 
+! Comments revised/added, formatting improved, fluxes for u,v, and scalars are
 ! explicitly set to zero at nzt+1, fluxes of w-component are now calculated only
 ! until nzt-1 (Prognostic equation for w-velocity component ends at nzt-1)
-! 
+!
 ! 4204 2019-08-30 12:30:17Z knoop
 ! Bugfix: Changed sk_num initialization default to avoid implicit SAVE-Attribut
-! 
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 4110 2019-07-22 17:05:21Z suehring
 ! - Separate initialization of advection flags for momentum and scalars. In this
-!   context, resort the bits and do some minor formatting. 
-! - Make flag initialization for scalars more flexible, introduce an 
-!   arguemnt list to indicate non-cyclic boundaries (required for decycled 
+!   context, resort the bits and do some minor formatting.
+! - Make flag initialization for scalars more flexible, introduce an
+!   arguemnt list to indicate non-cyclic boundaries (required for decycled
 !   scalars such as chemical species or aerosols)
-! - Introduce extended 'degradation zones', where horizontal advection of 
-!   passive scalars is discretized by first-order scheme at all grid points 
-!   that in the vicinity of buildings (<= 3 grid points). Even though no 
-!   building is within the numerical stencil, first-order scheme is used. 
+! - Introduce extended 'degradation zones', where horizontal advection of
+!   passive scalars is discretized by first-order scheme at all grid points
+!   that in the vicinity of buildings (<= 3 grid points). Even though no
+!   building is within the numerical stencil, first-order scheme is used.
 !   At fourth and fifth grid point the order of the horizontal advection scheme
 !   is successively upgraded.
-!   These extended degradation zones are used to avoid stationary numerical 
+!   These extended degradation zones are used to avoid stationary numerical
 !   oscillations, which are responsible for high concentration maxima that may
-!   appear under shear-free stable conditions. 
-! - Change interface for scalar advection routine. 
+!   appear under shear-free stable conditions.
+! - Change interface for scalar advection routine.
 ! - Bugfix, avoid uninitialized value sk_num in vector version of scalar
 !   advection
-! 
+!
 ! 4109 2019-07-22 17:00:34Z suehring
-! Implementation of a flux limiter according to Skamarock (2006) for the 
-! vertical scalar advection. Please note, this is only implemented for the 
+! Implementation of a flux limiter according to Skamarock (2006) for the
+! vertical scalar advection. Please note, this is only implemented for the
 ! cache-optimized version at the moment. Implementation for the vector-
-! optimized version will follow after critical issues concerning 
+! optimized version will follow after critical issues concerning
 ! vectorization are fixed.
-! 
+!
 ! 3873 2019-04-08 15:44:30Z knoop
 ! Moved ocean_mode specific code to ocean_mod
-! 
+!
 ! 3872 2019-04-08 15:03:06Z knoop
 ! Moved all USE statements to module level + removed salsa dependency
-! 
+!
 ! 3871 2019-04-08 14:38:39Z knoop
 ! Moving initialization of bcm specific flux arrays into bulk_cloud_model_mod
-! 
+!
 ! 3864 2019-04-05 09:01:56Z monakurppa
 ! Remove tailing white spaces
-! 
+!
 ! 3696 2019-01-24 16:37:35Z suehring
 ! Bugfix in degradation height
-! 
+!
 ! 3661 2019-01-08 18:22:50Z suehring
-! - Minor bugfix in divergence correction (only has implications at 
+! - Minor bugfix in divergence correction (only has implications at
 !   downward-facing wall surfaces)
 ! - Remove setting of Neumann condition for horizontal velocity variances
 ! - Split loops for tendency calculation and divergence correction in order to
 !   reduce bit queries
-! - Introduce new parameter nzb_max_l to better control order degradation at 
+! - Introduce new parameter nzb_max_l to better control order degradation at
 !   non-cyclic boundaries
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! OpenACC port for SPEC
@@ -133,6 +141,6 @@
 ! ------------
 !> Advection scheme for scalars and momentum using the flux formulation of
-!> Wicker and Skamarock 5th order. Additionally the module contains of a 
-!> routine using for initialisation and steering of the statical evaluation. 
+!> Wicker and Skamarock 5th order. Additionally the module contains of a
+!> routine using for initialisation and steering of the statical evaluation.
 !> The computation of turbulent fluxes takes place inside the advection
 !> routines.
@@ -140,6 +148,6 @@
 !> degraded.
 !> A divergence correction is applied. It is necessary for topography, since
-!> the divergence is not sufficiently reduced, resulting in erroneous fluxes 
-!> and could lead to numerical instabilities. 
+!> the divergence is not sufficiently reduced, resulting in erroneous fluxes
+!> and could lead to numerical instabilities.
 !>
 !> @todo Implement monotonic flux limiter also for vector version.
@@ -154,15 +162,14 @@
                u_stokes_zu, v_stokes_zu,                                       &
                diss_l_diss, diss_l_e, diss_l_pt, diss_l_q,                     &
-               diss_l_s, diss_l_sa, diss_l_u, diss_l_v, diss_l_w,              &
+               diss_l_s, diss_l_u, diss_l_v, diss_l_w,                         &
                flux_l_diss, flux_l_e, flux_l_pt, flux_l_q, flux_l_s,           &
-               flux_l_sa, flux_l_u, flux_l_v, flux_l_w,                        &
+               flux_l_u, flux_l_v, flux_l_w,                                   &
                diss_s_diss, diss_s_e, diss_s_pt, diss_s_q, diss_s_s,           &
-               diss_s_sa, diss_s_u, diss_s_v, diss_s_w,                        &
+               diss_s_u, diss_s_v, diss_s_w,                                   &
                flux_s_diss, flux_s_e, flux_s_pt, flux_s_q, flux_s_s,           &
-               flux_s_sa, flux_s_u, flux_s_v, flux_s_w
+               flux_s_u, flux_s_v, flux_s_w
 
     USE control_parameters,                                                    &
-        ONLY:  air_chemistry,                                                  &
-               bc_dirichlet_l,                                                 &
+        ONLY:  bc_dirichlet_l,                                                 &
                bc_dirichlet_n,                                                 &
                bc_dirichlet_r,                                                 &
@@ -176,7 +183,4 @@
                passive_scalar,                                                 &
                rans_tke_e,                                                     &
-               momentum_advec,                                                 &
-               salsa,                                                          &
-               scalar_advec,                                                   &
                symmetry_flag,                                                  &
                intermediate_timestep_count,                                    &
@@ -186,4 +190,8 @@
                ws_scheme_sca,                                                  &
                dt_3d
+
+    USE cpulog,                                                                &
+        ONLY:  cpu_log,                                                        &
+               log_point_s
 
     USE exchange_horiz_mod,                                                    &
@@ -198,9 +206,9 @@
                nxlg,                                                           &
                nxlu,                                                           &
-               nxr,                                                            & 
-               nxrg,                                                           & 
+               nxr,                                                            &
+               nxrg,                                                           &
                ny,                                                             &
-               nyn,                                                            & 
-               nyng,                                                           & 
+               nyn,                                                            &
+               nyng,                                                           &
                nys,                                                            &
                nysg,                                                           &
@@ -242,10 +250,10 @@
     INTERFACE ws_init
        MODULE PROCEDURE ws_init
-    END INTERFACE ws_init         
-             
+    END INTERFACE ws_init
+
     INTERFACE ws_init_flags_momentum
        MODULE PROCEDURE ws_init_flags_momentum
     END INTERFACE ws_init_flags_momentum
-    
+
     INTERFACE ws_init_flags_scalar
        MODULE PROCEDURE ws_init_flags_scalar
@@ -287,5 +295,5 @@
 
 !
-!--    Set the appropriate factors for scalar and momentum advection.
+!--    Set factors for scalar and momentum advection.
        adv_sca_5 = 1.0_wp /  60.0_wp
        adv_sca_3 = 1.0_wp /  12.0_wp
@@ -294,5 +302,5 @@
        adv_mom_3 = 1.0_wp /  24.0_wp
        adv_mom_1 = 1.0_wp /   4.0_wp
-!         
+!
 !--    Arrays needed for statical evaluation of fluxes.
        IF ( ws_scheme_mom )  THEN
@@ -330,27 +338,25 @@
 
 !
-!--    Arrays needed for reasons of speed optimization for cache version.
-!--    For the vector version the buffer arrays are not necessary,
-!--    because the the fluxes can swapped directly inside the loops of the 
-!--    advection routines.
+!--    Arrays needed for reasons of speed optimization
+       IF ( ws_scheme_mom )  THEN
+
+          ALLOCATE( flux_s_u(nzb+1:nzt,0:threads_per_task-1),               &
+                    flux_s_v(nzb+1:nzt,0:threads_per_task-1),               &
+                    flux_s_w(nzb+1:nzt,0:threads_per_task-1),               &
+                    diss_s_u(nzb+1:nzt,0:threads_per_task-1),               &
+                    diss_s_v(nzb+1:nzt,0:threads_per_task-1),               &
+                    diss_s_w(nzb+1:nzt,0:threads_per_task-1) )
+          ALLOCATE( flux_l_u(nzb+1:nzt,nys:nyn,0:threads_per_task-1),       &
+                    flux_l_v(nzb+1:nzt,nys:nyn,0:threads_per_task-1),       &
+                    flux_l_w(nzb+1:nzt,nys:nyn,0:threads_per_task-1),       &
+                    diss_l_u(nzb+1:nzt,nys:nyn,0:threads_per_task-1),       &
+                    diss_l_v(nzb+1:nzt,nys:nyn,0:threads_per_task-1),       &
+                    diss_l_w(nzb+1:nzt,nys:nyn,0:threads_per_task-1) )
+
+       ENDIF
+!
+!--    For the vector version the buffer arrays for scalars are not necessary,
+!--    since internal arrays are used in the vector version.
        IF ( loop_optimization /= 'vector' )  THEN
-
-          IF ( ws_scheme_mom )  THEN
-
-             ALLOCATE( flux_s_u(nzb+1:nzt,0:threads_per_task-1),               &
-                       flux_s_v(nzb+1:nzt,0:threads_per_task-1),               &
-                       flux_s_w(nzb+1:nzt,0:threads_per_task-1),               &
-                       diss_s_u(nzb+1:nzt,0:threads_per_task-1),               &
-                       diss_s_v(nzb+1:nzt,0:threads_per_task-1),               &
-                       diss_s_w(nzb+1:nzt,0:threads_per_task-1) )
-             ALLOCATE( flux_l_u(nzb+1:nzt,nys:nyn,0:threads_per_task-1),       &
-                       flux_l_v(nzb+1:nzt,nys:nyn,0:threads_per_task-1),       &
-                       flux_l_w(nzb+1:nzt,nys:nyn,0:threads_per_task-1),       &
-                       diss_l_u(nzb+1:nzt,nys:nyn,0:threads_per_task-1),       &
-                       diss_l_v(nzb+1:nzt,nys:nyn,0:threads_per_task-1),       &
-                       diss_l_w(nzb+1:nzt,nys:nyn,0:threads_per_task-1) )
-
-          ENDIF
-
           IF ( ws_scheme_sca )  THEN
 
@@ -358,5 +364,5 @@
                        flux_s_e(nzb+1:nzt,0:threads_per_task-1),               &
                        diss_s_pt(nzb+1:nzt,0:threads_per_task-1),              &
-                       diss_s_e(nzb+1:nzt,0:threads_per_task-1) ) 
+                       diss_s_e(nzb+1:nzt,0:threads_per_task-1) )
              ALLOCATE( flux_l_pt(nzb+1:nzt,nys:nyn,0:threads_per_task-1),      &
                        flux_l_e(nzb+1:nzt,nys:nyn,0:threads_per_task-1),       &
@@ -386,8 +392,7 @@
 
           ENDIF
-
        ENDIF
 !
-!--    Initialize the flag arrays controlling degradation near walls, i.e. 
+!--    Initialize the flag arrays controlling degradation near walls, i.e.
 !--    to decrease the numerical stencil appropriately. The order of the scheme
 !--    is degraded near solid walls as well as near non-cyclic inflow and outflow
@@ -412,5 +417,5 @@
 !> Initialization of flags to control the order of the advection scheme near
 !> solid walls and non-cyclic inflow boundaries, where the order is sucessively
-!> degraded. 
+!> degraded.
 !------------------------------------------------------------------------------!
     SUBROUTINE ws_init_flags_momentum
@@ -437,9 +442,9 @@
           DO  j = nys, nyn
              DO  k = nzb+1, nzt
-!  
-!--             At first, set flags to WS1. 
-!--             Since fluxes are swapped in advec_ws.f90, this is necessary to 
+!
+!--             At first, set flags to WS1.
+!--             Since fluxes are swapped in advec_ws.f90, this is necessary to
 !--             in order to handle the left/south flux.
-!--             near vertical walls. 
+!--             near vertical walls.
                 advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 0 )
                 advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 3 )
@@ -452,6 +457,6 @@
                          ( ( bc_dirichlet_r .OR. bc_radiation_r )              &
                            .AND. i == nxr   ) )                                &
-                THEN                                                           
-                    advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 0 )      
+                THEN
+                    advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 0 )
                 ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k,j,i+2),1)  .AND.   &
                                  BTEST(wall_flags_total_0(k,j,i+1),1)  .OR.    &
@@ -462,21 +467,21 @@
                          ( ( bc_dirichlet_l .OR. bc_radiation_l )              &
                            .AND. i == nxlu+1) )                                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 1 )       
-!                                                                              
-!--                Clear flag for WS1                                          
-                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 0 )       
-                ELSEIF ( BTEST(wall_flags_total_0(k,j,i+1),1)  .AND.          &
-                         BTEST(wall_flags_total_0(k,j,i+2),1)  .AND.          &
-                         BTEST(wall_flags_total_0(k,j,i-1),1) )               &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 2 )       
-!                                                                              
-!--                Clear flag for WS1                                          
-                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 0 )       
-                ENDIF                                                          
-!                                                                              
-!--             u component - y-direction                                      
-!--             WS1 (3), WS3 (4), WS5 (5)                                       
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 1 )
+!
+!--                Clear flag for WS1
+                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 0 )
+                ELSEIF ( BTEST(wall_flags_total_0(k,j,i+1),1)  .AND.           &
+                         BTEST(wall_flags_total_0(k,j,i+2),1)  .AND.           &
+                         BTEST(wall_flags_total_0(k,j,i-1),1) )                &
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 2 )
+!
+!--                Clear flag for WS1
+                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 0 )
+                ENDIF
+!
+!--             u component - y-direction
+!--             WS1 (3), WS3 (4), WS5 (5)
                 IF ( .NOT. BTEST(wall_flags_total_0(k,j+1,i),1)   .OR.         &
                          ( ( bc_dirichlet_s .OR. bc_radiation_s )              &
@@ -484,6 +489,6 @@
                          ( ( bc_dirichlet_n .OR. bc_radiation_n )              &
                            .AND. j == nyn   ) )                                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 3 )       
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 3 )
                 ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k,j+2,i),1)  .AND.   &
                                  BTEST(wall_flags_total_0(k,j+1,i),1)  .OR.    &
@@ -494,67 +499,67 @@
                          ( ( bc_dirichlet_n .OR. bc_radiation_n )              &
                            .AND. j == nyn-1 ) )                                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 4 )       
-!                                                                              
-!--                Clear flag for WS1                                          
-                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 3 )       
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 4 )
+!
+!--                Clear flag for WS1
+                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 3 )
                 ELSEIF ( BTEST(wall_flags_total_0(k,j+1,i),1)  .AND.          &
                          BTEST(wall_flags_total_0(k,j+2,i),1)  .AND.          &
                          BTEST(wall_flags_total_0(k,j-1,i),1) )               &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 5 )       
-!                                                                              
-!--                Clear flag for WS1                                          
-                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 3 )       
-                ENDIF                                                          
-!                                                                              
-!--             u component - z-direction. Fluxes are calculated on w-grid                                      
-!--             level. Boundary u-values at/within walls aren't used. 
-!--             WS1 (6), WS3 (7), WS5 (8)                                      
-                IF ( k == nzb+1 )  THEN                                        
-                   k_mm = nzb                                                  
-                ELSE                                                           
-                   k_mm = k - 2                                                
-                ENDIF                                                          
-                IF ( k > nzt-1 )  THEN                                         
-                   k_pp = nzt+1                                                
-                ELSE                                                           
-                   k_pp = k + 2                                                
-                ENDIF                                                          
-                IF ( k > nzt-2 )  THEN                                         
-                   k_ppp = nzt+1                                               
-                ELSE                                                           
-                   k_ppp = k + 3                                               
-                ENDIF                                                          
-                                                                               
-                flag_set = .FALSE.                                             
-                IF ( ( .NOT. BTEST(wall_flags_total_0(k-1,j,i),1)       .AND.     &
-                             BTEST(wall_flags_total_0(k,j,i),1)         .AND.     &
-                             BTEST(wall_flags_total_0(k+1,j,i),1) )     .OR.      &
-                     ( .NOT. BTEST(wall_flags_total_0(k_pp,j,i),1)      .AND.     &                              
-                             BTEST(wall_flags_total_0(k+1,j,i),1)       .AND.     &
-                             BTEST(wall_flags_total_0(k,j,i),1) )       .OR.      &
-                     ( k == nzt .AND. symmetry_flag == 0 ) )                      &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 6 )       
-                   flag_set = .TRUE.                                           
-                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k_mm,j,i),1)    .OR.    &
-                           .NOT. BTEST(wall_flags_total_0(k_ppp,j,i),1) ) .AND.   & 
-                                 BTEST(wall_flags_total_0(k-1,j,i),1)     .AND.   &
-                                 BTEST(wall_flags_total_0(k,j,i),1)       .AND.   &
-                                 BTEST(wall_flags_total_0(k+1,j,i),1)     .AND.   &
-                                 BTEST(wall_flags_total_0(k_pp,j,i),1)    .AND.   &
-                           .NOT. flag_set                                  .OR.   & 
-                         ( k == nzt - 1 .AND. symmetry_flag == 0 ) )              &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 7 )       
-                   flag_set = .TRUE.                                           
-                ELSEIF ( BTEST(wall_flags_total_0(k_mm,j,i),1)            .AND.   &
-                         BTEST(wall_flags_total_0(k-1,j,i),1)             .AND.   &
-                         BTEST(wall_flags_total_0(k,j,i),1)               .AND.   &
-                         BTEST(wall_flags_total_0(k+1,j,i),1)             .AND.   &
-                         BTEST(wall_flags_total_0(k_pp,j,i),1)            .AND.   &
-                         BTEST(wall_flags_total_0(k_ppp,j,i),1)           .AND.   &
-                         .NOT. flag_set )                                         &
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 5 )
+!
+!--                Clear flag for WS1
+                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 3 )
+                ENDIF
+!
+!--             u component - z-direction. Fluxes are calculated on w-grid
+!--             level. Boundary u-values at/within walls aren't used.
+!--             WS1 (6), WS3 (7), WS5 (8)
+                IF ( k == nzb+1 )  THEN
+                   k_mm = nzb
+                ELSE
+                   k_mm = k - 2
+                ENDIF
+                IF ( k > nzt-1 )  THEN
+                   k_pp = nzt+1
+                ELSE
+                   k_pp = k + 2
+                ENDIF
+                IF ( k > nzt-2 )  THEN
+                   k_ppp = nzt+1
+                ELSE
+                   k_ppp = k + 3
+                ENDIF
+
+                flag_set = .FALSE.
+                IF ( ( .NOT. BTEST(wall_flags_total_0(k-1,j,i),1)       .AND.  &
+                             BTEST(wall_flags_total_0(k,j,i),1)         .AND.  &
+                             BTEST(wall_flags_total_0(k+1,j,i),1) )     .OR.   &
+                     ( .NOT. BTEST(wall_flags_total_0(k_pp,j,i),1)      .AND.  &
+                             BTEST(wall_flags_total_0(k+1,j,i),1)       .AND.  &
+                             BTEST(wall_flags_total_0(k,j,i),1) )       .OR.   &
+                     ( k == nzt .AND. symmetry_flag == 0 ) )                   &
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 6 )
+                   flag_set = .TRUE.
+                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k_mm,j,i),1)    .OR. &
+                           .NOT. BTEST(wall_flags_total_0(k_ppp,j,i),1) ) .AND.&
+                                 BTEST(wall_flags_total_0(k-1,j,i),1)     .AND.&
+                                 BTEST(wall_flags_total_0(k,j,i),1)       .AND.&
+                                 BTEST(wall_flags_total_0(k+1,j,i),1)     .AND.&
+                                 BTEST(wall_flags_total_0(k_pp,j,i),1)    .AND.&
+                           .NOT. flag_set                                  .OR.&
+                         ( k == nzt - 1 .AND. symmetry_flag == 0 ) )           &
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 7 )
+                   flag_set = .TRUE.
+                ELSEIF ( BTEST(wall_flags_total_0(k_mm,j,i),1)            .AND.&
+                         BTEST(wall_flags_total_0(k-1,j,i),1)             .AND.&
+                         BTEST(wall_flags_total_0(k,j,i),1)               .AND.&
+                         BTEST(wall_flags_total_0(k+1,j,i),1)             .AND.&
+                         BTEST(wall_flags_total_0(k_pp,j,i),1)            .AND.&
+                         BTEST(wall_flags_total_0(k_ppp,j,i),1)           .AND.&
+                         .NOT. flag_set )                                      &
                 THEN
                    advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 8 )
@@ -570,6 +575,6 @@
              DO  k = nzb+1, nzt
 !
-!--             At first, set flags to WS1. 
-!--             Since fluxes are swapped in advec_ws.f90, this is necessary to 
+!--             At first, set flags to WS1.
+!--             Since fluxes are swapped in advec_ws.f90, this is necessary to
 !--             in order to handle the left/south flux.
                 advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 9  )
@@ -583,8 +588,8 @@
                          ( ( bc_dirichlet_r .OR. bc_radiation_r )              &
                            .AND. i == nxr   ) )                                &
-               THEN                                                            
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 9 )       
-!                                                                              
-!--             WS3                                                            
+               THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 9 )
+!
+!--             WS3
                 ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k,j,i+2),2)   .AND.  &
                                  BTEST(wall_flags_total_0(k,j,i+1),2) ) .OR.   &
@@ -595,21 +600,21 @@
                          ( ( bc_dirichlet_l .OR. bc_radiation_l )              &
                            .AND. i == nxlu  ) )                                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 10 )      
-!                                                                              
-!--                Clear flag for WS1                                          
-                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 9 )     
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 10 )
+!
+!--                Clear flag for WS1
+                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 9 )
                 ELSEIF ( BTEST(wall_flags_total_0(k,j,i+1),2)  .AND.           &
                          BTEST(wall_flags_total_0(k,j,i+2),2)  .AND.           &
                          BTEST(wall_flags_total_0(k,j,i-1),2) )                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 11 )      
-!                                                                              
-!--                Clear flag for WS1                                          
-                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 9 )       
-                ENDIF                                                          
-!                                                                              
-!--             v component - y-direction                                      
-!--             WS1 (12), WS3 (13), WS5 (14)                                   
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 11 )
+!
+!--                Clear flag for WS1
+                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 9 )
+                ENDIF
+!
+!--             v component - y-direction
+!--             WS1 (12), WS3 (13), WS5 (14)
                 IF ( .NOT. BTEST(wall_flags_total_0(k,j+1,i),2) .OR.           &
                          ( ( bc_dirichlet_s .OR. bc_radiation_s )              &
@@ -617,6 +622,6 @@
                          ( ( bc_dirichlet_n .OR. bc_radiation_n )              &
                            .AND. j == nyn   ) )                                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 12 )      
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 12 )
                 ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k,j+2,i),2)  .AND.   &
                                  BTEST(wall_flags_total_0(k,j+1,i),2)  .OR.    &
@@ -627,13 +632,13 @@
                          ( (  bc_dirichlet_n .OR. bc_radiation_n )             &
                            .AND. j == nyn-1 ) )                                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 13 )      
-!                                                                              
-!--                Clear flag for WS1                                          
-                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 12 )      
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 13 )
+!
+!--                Clear flag for WS1
+                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 12 )
                 ELSEIF ( BTEST(wall_flags_total_0(k,j+1,i),2)  .AND.           &
                          BTEST(wall_flags_total_0(k,j+2,i),2)  .AND.           &
-                         BTEST(wall_flags_total_0(k,j-1,i),2) )                & 
-                THEN                                                          
+                         BTEST(wall_flags_total_0(k,j-1,i),2) )                &
+                THEN
                    advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 14 )
 !
@@ -641,53 +646,53 @@
                    advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 12 )
                 ENDIF
-!                                                              
-!--             v component - z-direction. Fluxes are calculated on w-grid                                      
-!--             level. Boundary v-values at/within walls aren't used. 
+!
+!--             v component - z-direction. Fluxes are calculated on w-grid
+!--             level. Boundary v-values at/within walls aren't used.
 !--             WS1 (15), WS3 (16), WS5 (17)
                 IF ( k == nzb+1 )  THEN
                    k_mm = nzb
-                ELSE 
+                ELSE
                    k_mm = k - 2
                 ENDIF
                 IF ( k > nzt-1 )  THEN
                    k_pp = nzt+1
-                ELSE 
+                ELSE
                    k_pp = k + 2
                 ENDIF
                 IF ( k > nzt-2 )  THEN
                    k_ppp = nzt+1
-                ELSE 
+                ELSE
                    k_ppp = k + 3
-                ENDIF  
-                
+                ENDIF
+
                 flag_set = .FALSE.
-                IF ( ( .NOT. BTEST(wall_flags_total_0(k-1,j,i),2)          .AND.   &
-                             BTEST(wall_flags_total_0(k,j,i),2)            .AND.   &
-                             BTEST(wall_flags_total_0(k+1,j,i),2) )        .OR.    &
-                     ( .NOT. BTEST(wall_flags_total_0(k_pp,j,i),2)         .AND.   &                              
-                             BTEST(wall_flags_total_0(k+1,j,i),2)          .AND.   &
-                             BTEST(wall_flags_total_0(k,j,i),2) )          .OR.    &
-                     ( k == nzt .AND. symmetry_flag == 0 ) )                       &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 15 )      
-                   flag_set = .TRUE.                                           
-                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k_mm,j,i),2)    .OR.     &
-                           .NOT. BTEST(wall_flags_total_0(k_ppp,j,i),2) ) .AND.    & 
-                                 BTEST(wall_flags_total_0(k-1,j,i),2)     .AND.    &
-                                 BTEST(wall_flags_total_0(k,j,i),2)       .AND.    &
-                                 BTEST(wall_flags_total_0(k+1,j,i),2)     .AND.    &
-                                 BTEST(wall_flags_total_0(k_pp,j,i),2)    .AND.    &
-                           .NOT. flag_set                                  .OR.    & 
-                         ( k == nzt - 1 .AND. symmetry_flag == 0 ) )               &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 16 )      
-                   flag_set = .TRUE.                                           
-                ELSEIF ( BTEST(wall_flags_total_0(k_mm,j,i),2)             .AND.   &
-                         BTEST(wall_flags_total_0(k-1,j,i),2)              .AND.   &
-                         BTEST(wall_flags_total_0(k,j,i),2)                .AND.   &
-                         BTEST(wall_flags_total_0(k+1,j,i),2)              .AND.   &
-                         BTEST(wall_flags_total_0(k_pp,j,i),2)             .AND.   &
-                         BTEST(wall_flags_total_0(k_ppp,j,i),2)            .AND.   &
-                         .NOT. flag_set )                                          &
+                IF ( ( .NOT. BTEST(wall_flags_total_0(k-1,j,i),2)         .AND.&
+                             BTEST(wall_flags_total_0(k,j,i),2)           .AND.&
+                             BTEST(wall_flags_total_0(k+1,j,i),2) )       .OR. &
+                     ( .NOT. BTEST(wall_flags_total_0(k_pp,j,i),2)        .AND.&
+                             BTEST(wall_flags_total_0(k+1,j,i),2)         .AND.&
+                             BTEST(wall_flags_total_0(k,j,i),2) )         .OR. &
+                     ( k == nzt .AND. symmetry_flag == 0 ) )                   &
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 15 )
+                   flag_set = .TRUE.
+                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k_mm,j,i),2)    .OR. &
+                           .NOT. BTEST(wall_flags_total_0(k_ppp,j,i),2) ) .AND.&
+                                 BTEST(wall_flags_total_0(k-1,j,i),2)     .AND.&
+                                 BTEST(wall_flags_total_0(k,j,i),2)       .AND.&
+                                 BTEST(wall_flags_total_0(k+1,j,i),2)     .AND.&
+                                 BTEST(wall_flags_total_0(k_pp,j,i),2)    .AND.&
+                           .NOT. flag_set                                  .OR.&
+                         ( k == nzt - 1 .AND. symmetry_flag == 0 ) )           &
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 16 )
+                   flag_set = .TRUE.
+                ELSEIF ( BTEST(wall_flags_total_0(k_mm,j,i),2)            .AND.&
+                         BTEST(wall_flags_total_0(k-1,j,i),2)             .AND.&
+                         BTEST(wall_flags_total_0(k,j,i),2)               .AND.&
+                         BTEST(wall_flags_total_0(k+1,j,i),2)             .AND.&
+                         BTEST(wall_flags_total_0(k_pp,j,i),2)            .AND.&
+                         BTEST(wall_flags_total_0(k_ppp,j,i),2)           .AND.&
+                         .NOT. flag_set )                                      &
                 THEN
                    advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 17 )
@@ -703,6 +708,6 @@
              DO  k = nzb+1, nzt
 !
-!--             At first, set flags to WS1. 
-!--             Since fluxes are swapped in advec_ws.f90, this is necessary to 
+!--             At first, set flags to WS1.
+!--             Since fluxes are swapped in advec_ws.f90, this is necessary to
 !--             in order to handle the left/south flux.
                 advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 18 )
@@ -716,6 +721,6 @@
                          ( (  bc_dirichlet_r .OR. bc_radiation_r )             &
                            .AND. i == nxr   ) )                                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 18 )     
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 18 )
                 ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k,j,i+2),3)  .AND.   &
                                  BTEST(wall_flags_total_0(k,j,i+1),3)  .OR.    &
@@ -726,21 +731,21 @@
                          ( ( bc_dirichlet_l .OR.  bc_radiation_l )             &
                            .AND. i == nxlu  ) )                                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 19 )      
-!                                                                              
-!--                Clear flag for WS1                                          
-                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 18 )      
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 19 )
+!
+!--                Clear flag for WS1
+                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 18 )
                 ELSEIF ( BTEST(wall_flags_total_0(k,j,i+1),3)  .AND.           &
                          BTEST(wall_flags_total_0(k,j,i+2),3)  .AND.           &
                          BTEST(wall_flags_total_0(k,j,i-1),3) )                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i),20 )       
-!                                                                              
-!--                Clear flag for WS1                                          
-                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 18 )      
-                ENDIF                                                          
-!                                                                              
-!--             w component - y-direction                                      
-!--             WS1 (21), WS3 (22), WS5 (23)                                   
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i),20 )
+!
+!--                Clear flag for WS1
+                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 18 )
+                ENDIF
+!
+!--             w component - y-direction
+!--             WS1 (21), WS3 (22), WS5 (23)
                 IF ( .NOT. BTEST(wall_flags_total_0(k,j+1,i),3) .OR.           &
                          ( ( bc_dirichlet_s .OR. bc_radiation_s )              &
@@ -748,6 +753,6 @@
                          ( ( bc_dirichlet_n .OR. bc_radiation_n )              &
                            .AND. j == nyn   ) )                                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 21 )     
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 21 )
                 ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k,j+2,i),3)  .AND.   &
                                  BTEST(wall_flags_total_0(k,j+1,i),3)  .OR.    &
@@ -758,13 +763,13 @@
                          ( ( bc_dirichlet_n .OR. bc_radiation_n )              &
                            .AND. j == nyn-1 ) )                                &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 22 )      
-!                                                                              
-!--                Clear flag for WS1                                          
-                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 21 )       
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 22 )
+!
+!--                Clear flag for WS1
+                   advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 21 )
                 ELSEIF ( BTEST(wall_flags_total_0(k,j+1,i),3)  .AND.           &
                          BTEST(wall_flags_total_0(k,j+2,i),3)  .AND.           &
                          BTEST(wall_flags_total_0(k,j-1,i),3) )                &
-                THEN                                                           
+                THEN
                    advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 23 )
 !
@@ -772,8 +777,8 @@
                    advc_flags_m(k,j,i) = IBCLR( advc_flags_m(k,j,i), 21 )
                 ENDIF
-!                                                                              
+!
 !--             w component - z-direction. Fluxes are calculated on scalar grid
-!--             level. Boundary w-values at walls are used. Flux at k=i is  
-!--             defined at scalar position k=i+1 with i being an integer. 
+!--             level. Boundary w-values at walls are used. Flux at k=i is
+!--             defined at scalar position k=i+1 with i being an integer.
 !--             WS1 (24), WS3 (25), WS5 (26)
                 IF ( k == nzb+1 )  THEN
@@ -784,23 +789,23 @@
                 IF ( k > nzt-1 )  THEN
                    k_pp = nzt+1
-                ELSE 
+                ELSE
                    k_pp = k + 2
                 ENDIF
                 IF ( k > nzt-2 )  THEN
                    k_ppp = nzt+1
-                ELSE 
+                ELSE
                    k_ppp = k + 3
-                ENDIF  
-                
-                flag_set = .FALSE.                                        
-                IF ( ( .NOT. BTEST(wall_flags_total_0(k,j,i),3)          .AND.   &
-                             BTEST(wall_flags_total_0(k+1,j,i),3) )      .OR.    &
-                     ( .NOT. BTEST(wall_flags_total_0(k+1,j,i),3)        .AND.   &
-                             BTEST(wall_flags_total_0(k,j,i),3) )        .OR.    &        
-                     k == nzt -1 )                                               &
+                ENDIF
+
+                flag_set = .FALSE.
+                IF ( ( .NOT. BTEST(wall_flags_total_0(k,j,i),3)          .AND. &
+                             BTEST(wall_flags_total_0(k+1,j,i),3) )      .OR.  &
+                     ( .NOT. BTEST(wall_flags_total_0(k+1,j,i),3)        .AND. &
+                             BTEST(wall_flags_total_0(k,j,i),3) )        .OR.  &
+                     k == nzt -1 )                                             &
                 THEN
 !
 !--                Please note, at k == nzb_w_inner(j,i) a flag is explicitly
-!--                set, although this is not a prognostic level. However, 
+!--                set, although this is not a prognostic level. However,
 !--                contrary to the advection of u,v and s this is necessary
 !--                because flux_t(nzb_w_inner(j,i)) is used for the tendency
@@ -808,23 +813,23 @@
                    advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 24 )
                    flag_set = .TRUE.
-                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k-1,j,i),3)    .AND.   &
-                                 BTEST(wall_flags_total_0(k,j,i),3)      .AND.   &
-                                 BTEST(wall_flags_total_0(k+1,j,i),3)    .AND.   &
-                                 BTEST(wall_flags_total_0(k_pp,j,i),3) ) .OR.    &
-                         ( .NOT. BTEST(wall_flags_total_0(k_pp,j,i),3)   .AND.   &
-                                 BTEST(wall_flags_total_0(k+1,j,i),3)    .AND.   &
-                                 BTEST(wall_flags_total_0(k,j,i),3)      .AND.   &
-                                 BTEST(wall_flags_total_0(k-1,j,i),3) )  .AND.   &
-                           .NOT. flag_set                          .OR.          & 
-                         k == nzt - 2 )                                          &
-                THEN                                                           
-                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 25 )      
-                   flag_set = .TRUE.                                           
-                ELSEIF ( BTEST(wall_flags_total_0(k-1,j,i),3)            .AND.   &
-                         BTEST(wall_flags_total_0(k,j,i),3)              .AND.   &
-                         BTEST(wall_flags_total_0(k+1,j,i),3)            .AND.   &
-                         BTEST(wall_flags_total_0(k_pp,j,i),3)           .AND.   &
-                         .NOT. flag_set )                                        &
-                THEN                                                                
+                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k-1,j,i),3)    .AND. &
+                                 BTEST(wall_flags_total_0(k,j,i),3)      .AND. &
+                                 BTEST(wall_flags_total_0(k+1,j,i),3)    .AND. &
+                                 BTEST(wall_flags_total_0(k_pp,j,i),3) ) .OR.  &
+                         ( .NOT. BTEST(wall_flags_total_0(k_pp,j,i),3)   .AND. &
+                                 BTEST(wall_flags_total_0(k+1,j,i),3)    .AND. &
+                                 BTEST(wall_flags_total_0(k,j,i),3)      .AND. &
+                                 BTEST(wall_flags_total_0(k-1,j,i),3) )  .AND. &
+                           .NOT. flag_set                          .OR.        &
+                         k == nzt - 2 )                                        &
+                THEN
+                   advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 25 )
+                   flag_set = .TRUE.
+                ELSEIF ( BTEST(wall_flags_total_0(k-1,j,i),3)            .AND. &
+                         BTEST(wall_flags_total_0(k,j,i),3)              .AND. &
+                         BTEST(wall_flags_total_0(k+1,j,i),3)            .AND. &
+                         BTEST(wall_flags_total_0(k_pp,j,i),3)           .AND. &
+                         .NOT. flag_set )                                      &
+                THEN
                    advc_flags_m(k,j,i) = IBSET( advc_flags_m(k,j,i), 26 )
                 ENDIF
@@ -837,5 +842,5 @@
        CALL exchange_horiz_int( advc_flags_m, nys, nyn, nxl, nxr, nzt, nbgp )
 !
-!--    Set boundary flags at inflow and outflow boundary in case of 
+!--    Set boundary flags at inflow and outflow boundary in case of
 !--    non-cyclic boundary conditions.
        IF ( bc_dirichlet_l  .OR.  bc_radiation_l )  THEN
@@ -844,5 +849,5 @@
 
        IF ( bc_dirichlet_r  .OR.  bc_radiation_r )  THEN
-         advc_flags_m(:,:,nxr+1) = advc_flags_m(:,:,nxr)
+          advc_flags_m(:,:,nxr+1) = advc_flags_m(:,:,nxr)
        ENDIF
 
@@ -863,5 +868,5 @@
 !> Initialization of flags to control the order of the advection scheme near
 !> solid walls and non-cyclic inflow boundaries, where the order is sucessively
-!> degraded. 
+!> degraded.
 !------------------------------------------------------------------------------!
     SUBROUTINE ws_init_flags_scalar( non_cyclic_l, non_cyclic_n, non_cyclic_r, &
@@ -885,7 +890,7 @@
        LOGICAL ::  non_cyclic_s !< flag that indicates non-cyclic boundary on the south
 
-       LOGICAL, OPTIONAL ::  extensive_degrad !< flag indicating that extensive degradation is required, e.g. for 
+       LOGICAL, OPTIONAL ::  extensive_degrad !< flag indicating that extensive degradation is required, e.g. for
                                               !< passive scalars nearby topography along the horizontal directions,
-                                              !< as no monotonic limiter can be applied there 
+                                              !< as no monotonic limiter can be applied there
 !
 !--    Set flags to steer the degradation of the advection scheme in advec_ws
@@ -900,77 +905,77 @@
 !--             scalar - x-direction
 !--             WS1 (0), WS3 (1), WS5 (2)
-                IF ( ( .NOT. BTEST(wall_flags_total_0(k,j,i+1),0)      .OR.      &
-                       .NOT. BTEST(wall_flags_total_0(k,j,i+2),0)      .OR.      &   
-                       .NOT. BTEST(wall_flags_total_0(k,j,i-1),0) )    .OR.      &
-                       ( non_cyclic_l  .AND.  i == 0  )                .OR.      &
-                       ( non_cyclic_r  .AND.  i == nx ) )  THEN           
-                 advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 0 )             
-                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k,j,i+3),0)  .AND.     &
-                                 BTEST(wall_flags_total_0(k,j,i+1),0)  .AND.     &
-                                 BTEST(wall_flags_total_0(k,j,i+2),0)  .AND.     &
-                                 BTEST(wall_flags_total_0(k,j,i-1),0)            &
-                         )                       .OR.                            &
-                         ( .NOT. BTEST(wall_flags_total_0(k,j,i-2),0)  .AND.     &
-                                 BTEST(wall_flags_total_0(k,j,i+1),0)  .AND.     &
-                                 BTEST(wall_flags_total_0(k,j,i+2),0)  .AND.     &
-                                 BTEST(wall_flags_total_0(k,j,i-1),0)            &
-                         )                                                       &
-                                                 .OR.                            &
-                         ( non_cyclic_r  .AND.  i == nx-1 )  .OR.                &
-                         ( non_cyclic_l  .AND.  i == 1    ) )  THEN           
-                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 1 )             
-                ELSEIF ( BTEST(wall_flags_total_0(k,j,i+1),0)           .AND.    &
-                         BTEST(wall_flags_total_0(k,j,i+2),0)           .AND.    &
-                         BTEST(wall_flags_total_0(k,j,i+3),0)           .AND.    &
-                         BTEST(wall_flags_total_0(k,j,i-1),0)           .AND.    &
-                         BTEST(wall_flags_total_0(k,j,i-2),0) )                  &
-                THEN                                                           
-                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 2 )             
-                ENDIF                                                          
-!                                                                              
-!--             scalar - y-direction                                           
-!--             WS1 (3), WS3 (4), WS5 (5)                                      
-                IF ( ( .NOT. BTEST(wall_flags_total_0(k,j+1,i),0)        .OR.    &
-                       .NOT. BTEST(wall_flags_total_0(k,j+2,i),0)        .OR.    &   
-                       .NOT. BTEST(wall_flags_total_0(k,j-1,i),0))       .OR.    &
-                     ( non_cyclic_s  .AND.  j == 0  )                    .OR.    &
-                     ( non_cyclic_n  .AND.  j == ny ) )  THEN                                                           
-                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 3 )             
-!                                                                              
-!--             WS3                                                            
-                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k,j+3,i),0)    .AND.   &
-                                 BTEST(wall_flags_total_0(k,j+1,i),0)    .AND.   &
-                                 BTEST(wall_flags_total_0(k,j+2,i),0)    .AND.   &
-                                 BTEST(wall_flags_total_0(k,j-1,i),0)            &
-                         )                       .OR.                            &
-                         ( .NOT. BTEST(wall_flags_total_0(k,j-2,i),0)    .AND.   &
-                                 BTEST(wall_flags_total_0(k,j+1,i),0)    .AND.   &
-                                 BTEST(wall_flags_total_0(k,j+2,i),0)    .AND.   &
-                                 BTEST(wall_flags_total_0(k,j-1,i),0)            &
-                         )                                                       &
-                                                 .OR.                            &
-                         ( non_cyclic_s  .AND.  j == 1    )  .OR.                &
-                         ( non_cyclic_n  .AND.  j == ny-1 ) )  THEN           
-                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 4 )             
-!                                                                              
-!--             WS5                                                            
-                ELSEIF ( BTEST(wall_flags_total_0(k,j+1,i),0)           .AND.    &
-                         BTEST(wall_flags_total_0(k,j+2,i),0)           .AND.    &
-                         BTEST(wall_flags_total_0(k,j+3,i),0)           .AND.    &
-                         BTEST(wall_flags_total_0(k,j-1,i),0)           .AND.    &
-                         BTEST(wall_flags_total_0(k,j-2,i),0) )                  &
-                THEN                                                           
-                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 5 )             
+                IF ( ( .NOT. BTEST(wall_flags_total_0(k,j,i+1),0)      .OR.    &
+                       .NOT. BTEST(wall_flags_total_0(k,j,i+2),0)      .OR.    &
+                       .NOT. BTEST(wall_flags_total_0(k,j,i-1),0) )    .OR.    &
+                       ( non_cyclic_l  .AND.  i == 0  )                .OR.    &
+                       ( non_cyclic_r  .AND.  i == nx ) )  THEN
+                 advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 0 )
+                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k,j,i+3),0)  .AND.   &
+                                 BTEST(wall_flags_total_0(k,j,i+1),0)  .AND.   &
+                                 BTEST(wall_flags_total_0(k,j,i+2),0)  .AND.   &
+                                 BTEST(wall_flags_total_0(k,j,i-1),0)          &
+                         )                       .OR.                          &
+                         ( .NOT. BTEST(wall_flags_total_0(k,j,i-2),0)  .AND.   &
+                                 BTEST(wall_flags_total_0(k,j,i+1),0)  .AND.   &
+                                 BTEST(wall_flags_total_0(k,j,i+2),0)  .AND.   &
+                                 BTEST(wall_flags_total_0(k,j,i-1),0)          &
+                         )                                                     &
+                                                 .OR.                          &
+                         ( non_cyclic_r  .AND.  i == nx-1 )  .OR.              &
+                         ( non_cyclic_l  .AND.  i == 1    ) )  THEN
+                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 1 )
+                ELSEIF ( BTEST(wall_flags_total_0(k,j,i+1),0)           .AND.  &
+                         BTEST(wall_flags_total_0(k,j,i+2),0)           .AND.  &
+                         BTEST(wall_flags_total_0(k,j,i+3),0)           .AND.  &
+                         BTEST(wall_flags_total_0(k,j,i-1),0)           .AND.  &
+                         BTEST(wall_flags_total_0(k,j,i-2),0) )                &
+                THEN
+                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 2 )
                 ENDIF
 !
-!--             Near topography, set horizontal advection scheme to 1st order 
-!--             for passive scalars, even if only one direction may be 
+!--             scalar - y-direction
+!--             WS1 (3), WS3 (4), WS5 (5)
+                IF ( ( .NOT. BTEST(wall_flags_total_0(k,j+1,i),0)        .OR.  &
+                       .NOT. BTEST(wall_flags_total_0(k,j+2,i),0)        .OR.  &
+                       .NOT. BTEST(wall_flags_total_0(k,j-1,i),0))       .OR.  &
+                     ( non_cyclic_s  .AND.  j == 0  )                    .OR.  &
+                     ( non_cyclic_n  .AND.  j == ny ) )  THEN
+                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 3 )
+!
+!--             WS3
+                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k,j+3,i),0)    .AND. &
+                                 BTEST(wall_flags_total_0(k,j+1,i),0)    .AND. &
+                                 BTEST(wall_flags_total_0(k,j+2,i),0)    .AND. &
+                                 BTEST(wall_flags_total_0(k,j-1,i),0)          &
+                         )                       .OR.                          &
+                         ( .NOT. BTEST(wall_flags_total_0(k,j-2,i),0)    .AND. &
+                                 BTEST(wall_flags_total_0(k,j+1,i),0)    .AND. &
+                                 BTEST(wall_flags_total_0(k,j+2,i),0)    .AND. &
+                                 BTEST(wall_flags_total_0(k,j-1,i),0)          &
+                         )                                                     &
+                                                 .OR.                          &
+                         ( non_cyclic_s  .AND.  j == 1    )  .OR.              &
+                         ( non_cyclic_n  .AND.  j == ny-1 ) )  THEN
+                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 4 )
+!
+!--             WS5
+                ELSEIF ( BTEST(wall_flags_total_0(k,j+1,i),0)           .AND.  &
+                         BTEST(wall_flags_total_0(k,j+2,i),0)           .AND.  &
+                         BTEST(wall_flags_total_0(k,j+3,i),0)           .AND.  &
+                         BTEST(wall_flags_total_0(k,j-1,i),0)           .AND.  &
+                         BTEST(wall_flags_total_0(k,j-2,i),0) )                &
+                THEN
+                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 5 )
+                ENDIF
+!
+!--             Near topography, set horizontal advection scheme to 1st order
+!--             for passive scalars, even if only one direction may be
 !--             blocked by topography. These locations will be identified
-!--             by wall_flags_total_0 bit 31. Note, since several modules define 
-!--             advection flags but may apply different scalar boundary 
-!--             conditions, bit 31 is temporarily stored on advc_flags. 
-!--             Moreover, note that this extended degradtion for passive 
-!--             scalars is not required for the vertical direction as there 
-!--             the monotonic limiter can be applied. 
+!--             by wall_flags_total_0 bit 31. Note, since several modules define
+!--             advection flags but may apply different scalar boundary
+!--             conditions, bit 31 is temporarily stored on advc_flags.
+!--             Moreover, note that this extended degradtion for passive
+!--             scalars is not required for the vertical direction as there
+!--             the monotonic limiter can be applied.
                 IF ( PRESENT( extensive_degrad ) )  THEN
                    IF ( extensive_degrad )  THEN
@@ -980,5 +985,5 @@
                       IF( BTEST( advc_flag(k,j,i), 31 ) )  THEN
 !
-!--                      Clear flags that might indicate higher-order 
+!--                      Clear flags that might indicate higher-order
 !--                      advection along x- and y-direction.
                          advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 1 )
@@ -990,21 +995,21 @@
 !--                      x- and y-direction.
                          advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 0 )
-                         advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 3 )  
+                         advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 3 )
                       ENDIF
 !
 !--                   Adjacent to this extended degradation zone, successively
-!--                   upgrade the order of the scheme if this grid point isn't 
-!--                   flagged with bit 31 (indicating extended degradation 
-!--                   zone). 
+!--                   upgrade the order of the scheme if this grid point isn't
+!--                   flagged with bit 31 (indicating extended degradation
+!--                   zone).
                       IF ( .NOT. BTEST( advc_flag(k,j,i), 31 ) )  THEN
 !
 !--                      x-direction. First, clear all previous settings, than
 !--                      set flag for 3rd-order scheme.
-                         IF ( BTEST( advc_flag(k,j,i-1), 31 )  .AND.        &
+                         IF ( BTEST( advc_flag(k,j,i-1), 31 )  .AND.           &
                               BTEST( advc_flag(k,j,i+1), 31 ) )  THEN
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 0 )
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 1 )
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 2 )
-                            
+
                             advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 1 )
                          ENDIF
@@ -1012,12 +1017,12 @@
 !--                      x-direction. First, clear all previous settings, than
 !--                      set flag for 5rd-order scheme.
-                         IF ( .NOT. BTEST( advc_flag(k,j,i-1), 31 )  .AND.  &
-                                    BTEST( advc_flag(k,j,i-2), 31 )  .AND.  &
-                              .NOT. BTEST( advc_flag(k,j,i+1), 31 )  .AND.  &
+                         IF ( .NOT. BTEST( advc_flag(k,j,i-1), 31 )  .AND.     &
+                                    BTEST( advc_flag(k,j,i-2), 31 )  .AND.     &
+                              .NOT. BTEST( advc_flag(k,j,i+1), 31 )  .AND.     &
                                     BTEST( advc_flag(k,j,i+2), 31 ) )  THEN
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 0 )
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 1 )
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 2 )
-                            
+
                             advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 2 )
                          ENDIF
@@ -1025,10 +1030,10 @@
 !--                      y-direction. First, clear all previous settings, than
 !--                      set flag for 3rd-order scheme.
-                         IF ( BTEST( advc_flag(k,j-1,i), 31 )  .AND.        &
+                         IF ( BTEST( advc_flag(k,j-1,i), 31 )  .AND.           &
                               BTEST( advc_flag(k,j+1,i), 31 ) )  THEN
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 3 )
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 4 )
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 5 )
-                            
+
                             advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 4 )
                          ENDIF
@@ -1036,111 +1041,111 @@
 !--                      y-direction. First, clear all previous settings, than
 !--                      set flag for 5rd-order scheme.
-                         IF ( .NOT. BTEST( advc_flag(k,j-1,i), 31 )  .AND.  &
-                                    BTEST( advc_flag(k,j-2,i), 31 )  .AND.  &
-                              .NOT. BTEST( advc_flag(k,j+1,i), 31 )  .AND.  &
+                         IF ( .NOT. BTEST( advc_flag(k,j-1,i), 31 )  .AND.     &
+                                    BTEST( advc_flag(k,j-2,i), 31 )  .AND.     &
+                              .NOT. BTEST( advc_flag(k,j+1,i), 31 )  .AND.     &
                                     BTEST( advc_flag(k,j+2,i), 31 ) )  THEN
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 3 )
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 4 )
                             advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 5 )
-                            
+
                             advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 5 )
                          ENDIF
                       ENDIF
-                   
+
                    ENDIF
-                   
+
 !
 !--                Near lateral boundary flags might be overwritten. Set
-!--                them again. 
+!--                them again.
 !--                x-direction
-                   IF ( ( non_cyclic_l  .AND.  i == 0  )  .OR.             &
+                   IF ( ( non_cyclic_l  .AND.  i == 0  )  .OR.                 &
                         ( non_cyclic_r  .AND.  i == nx ) )  THEN
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 0 )
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 1 )
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 2 )
-                         
+
                       advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 0 )
                    ENDIF
-                   
-                   IF ( ( non_cyclic_l  .AND.  i == 1    )  .OR.           &
+
+                   IF ( ( non_cyclic_l  .AND.  i == 1    )  .OR.               &
                         ( non_cyclic_r  .AND.  i == nx-1 ) )  THEN
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 0 )
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 1 )
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 2 )
-                         
+
                       advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 1 )
                    ENDIF
 !
 !--                y-direction
-                   IF ( ( non_cyclic_n  .AND.  j == 0  )  .OR.             &
+                   IF ( ( non_cyclic_n  .AND.  j == 0  )  .OR.                 &
                         ( non_cyclic_s  .AND.  j == ny ) )  THEN
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 3 )
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 4 )
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 5 )
-                         
+
                       advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 3 )
                    ENDIF
-                   
-                   IF ( ( non_cyclic_n  .AND.  j == 1    )  .OR.           &
+
+                   IF ( ( non_cyclic_n  .AND.  j == 1    )  .OR.               &
                         ( non_cyclic_s  .AND.  j == ny-1 ) )  THEN
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 3 )
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 4 )
                       advc_flag(k,j,i) = IBCLR( advc_flag(k,j,i), 5 )
-                         
+
                       advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 4 )
                    ENDIF
-                   
+
                 ENDIF
-                
-                
-!                                                                              
-!--             scalar - z-direction. Fluxes are calculated on w-grid                                      
-!--             level. Boundary values at/within walls aren't used.                                            
-!--             WS1 (6), WS3 (7), WS5 (8)                                      
-                IF ( k == nzb+1 )  THEN                                        
-                   k_mm = nzb                                                  
-                ELSE                                                           
-                   k_mm = k - 2                                                
-                ENDIF                                                          
-                IF ( k > nzt-1 )  THEN                                         
-                   k_pp = nzt+1                                                
-                ELSE                                                           
-                   k_pp = k + 2                                                
-                ENDIF                                                          
-                IF ( k > nzt-2 )  THEN                                         
-                   k_ppp = nzt+1                                               
-                ELSE                                                           
-                   k_ppp = k + 3                                               
-                ENDIF                                                          
-                                                                               
-                flag_set = .FALSE.                                             
-                IF ( ( .NOT. BTEST(wall_flags_total_0(k-1,j,i),0)          .AND.  &
-                             BTEST(wall_flags_total_0(k,j,i),0)            .AND.  &
-                             BTEST(wall_flags_total_0(k+1,j,i),0) )        .OR.   &
-                     ( .NOT. BTEST(wall_flags_total_0(k_pp,j,i),0)         .AND.  &                              
-                             BTEST(wall_flags_total_0(k+1,j,i),0)          .AND.  &
-                             BTEST(wall_flags_total_0(k,j,i),0) )          .OR.   &
-                     ( k == nzt .AND. symmetry_flag == 0 ) )                      &
-                THEN                                                           
-                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 6 )             
-                   flag_set = .TRUE.                                           
-                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k_mm,j,i),0)    .OR.    &
-                           .NOT. BTEST(wall_flags_total_0(k_ppp,j,i),0) ) .AND.   & 
-                                 BTEST(wall_flags_total_0(k-1,j,i),0)     .AND.   &
-                                 BTEST(wall_flags_total_0(k,j,i),0)       .AND.   &
-                                 BTEST(wall_flags_total_0(k+1,j,i),0)     .AND.   &
-                                 BTEST(wall_flags_total_0(k_pp,j,i),0)    .AND.   &
-                           .NOT. flag_set                                  .OR.   & 
-                         ( k == nzt - 1 .AND. symmetry_flag == 0 ) )              &
-                THEN                                                           
-                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 7 )             
-                   flag_set = .TRUE.                                           
-                ELSEIF ( BTEST(wall_flags_total_0(k_mm,j,i),0)            .AND.   &
-                         BTEST(wall_flags_total_0(k-1,j,i),0)             .AND.   &
-                         BTEST(wall_flags_total_0(k,j,i),0)               .AND.   &
-                         BTEST(wall_flags_total_0(k+1,j,i),0)             .AND.   &
-                         BTEST(wall_flags_total_0(k_pp,j,i),0)            .AND.   &
-                         BTEST(wall_flags_total_0(k_ppp,j,i),0)           .AND.   &
-                        .NOT. flag_set )                                          &
+
+
+!
+!--             scalar - z-direction. Fluxes are calculated on w-grid
+!--             level. Boundary values at/within walls aren't used.
+!--             WS1 (6), WS3 (7), WS5 (8)
+                IF ( k == nzb+1 )  THEN
+                   k_mm = nzb
+                ELSE
+                   k_mm = k - 2
+                ENDIF
+                IF ( k > nzt-1 )  THEN
+                   k_pp = nzt+1
+                ELSE
+                   k_pp = k + 2
+                ENDIF
+                IF ( k > nzt-2 )  THEN
+                   k_ppp = nzt+1
+                ELSE
+                   k_ppp = k + 3
+                ENDIF
+
+                flag_set = .FALSE.
+                IF ( ( .NOT. BTEST(wall_flags_total_0(k-1,j,i),0)       .AND.  &
+                             BTEST(wall_flags_total_0(k,j,i),0)         .AND.  &
+                             BTEST(wall_flags_total_0(k+1,j,i),0) )     .OR.   &
+                     ( .NOT. BTEST(wall_flags_total_0(k_pp,j,i),0)      .AND.  &
+                             BTEST(wall_flags_total_0(k+1,j,i),0)       .AND.  &
+                             BTEST(wall_flags_total_0(k,j,i),0) )       .OR.   &
+                     ( k == nzt .AND. symmetry_flag == 0 ) )                   &
+                THEN
+                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 6 )
+                   flag_set = .TRUE.
+                ELSEIF ( ( .NOT. BTEST(wall_flags_total_0(k_mm,j,i),0)    .OR. &
+                           .NOT. BTEST(wall_flags_total_0(k_ppp,j,i),0) ) .AND.&
+                                 BTEST(wall_flags_total_0(k-1,j,i),0)     .AND.&
+                                 BTEST(wall_flags_total_0(k,j,i),0)       .AND.&
+                                 BTEST(wall_flags_total_0(k+1,j,i),0)     .AND.&
+                                 BTEST(wall_flags_total_0(k_pp,j,i),0)    .AND.&
+                           .NOT. flag_set                                  .OR.&
+                         ( k == nzt - 1 .AND. symmetry_flag == 0 ) )           &
+                THEN
+                   advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 7 )
+                   flag_set = .TRUE.
+                ELSEIF ( BTEST(wall_flags_total_0(k_mm,j,i),0)         .AND.   &
+                         BTEST(wall_flags_total_0(k-1,j,i),0)          .AND.   &
+                         BTEST(wall_flags_total_0(k,j,i),0)            .AND.   &
+                         BTEST(wall_flags_total_0(k+1,j,i),0)          .AND.   &
+                         BTEST(wall_flags_total_0(k_pp,j,i),0)         .AND.   &
+                         BTEST(wall_flags_total_0(k_ppp,j,i),0)        .AND.   &
+                        .NOT. flag_set )                                       &
                 THEN
                    advc_flag(k,j,i) = IBSET( advc_flag(k,j,i), 8 )
@@ -1156,5 +1161,5 @@
        CALL exchange_horiz_int( advc_flag, nys, nyn, nxl, nxr, nzt, nbgp )
 !
-!--    Set boundary flags at inflow and outflow boundary in case of 
+!--    Set boundary flags at inflow and outflow boundary in case of
 !--    non-cyclic boundary conditions.
        IF ( non_cyclic_l )  THEN
@@ -1173,9 +1178,9 @@
           advc_flag(:,nys-1,:) = advc_flag(:,nys,:)
        ENDIF
-  
-
-
-    END SUBROUTINE ws_init_flags_scalar   
-    
+
+
+
+    END SUBROUTINE ws_init_flags_scalar
+
 !------------------------------------------------------------------------------!
 ! Description:
@@ -1187,5 +1192,5 @@
 
 !
-!--    The arrays needed for statistical evaluation are set to to 0 at the 
+!--    The arrays needed for statistical evaluation are set to to 0 at the
 !--    beginning of prognostic_equations.
        IF ( ws_scheme_mom )  THEN
@@ -1225,6 +1230,7 @@
 
 
-       CHARACTER (LEN = *), INTENT(IN) ::  sk_char !< string identifier, used for assign fluxes to the correct dimension in the analysis array 
-       
+       CHARACTER (LEN = *), INTENT(IN) ::  sk_char !< string identifier, used for assign fluxes to the
+                                                   !<correct dimension in the analysis array
+
        INTEGER(iwp) ::  i         !< grid index along x-direction
        INTEGER(iwp) ::  i_omp     !< leftmost index on subdomain, or in case of OpenMP, on thread
@@ -1235,7 +1241,7 @@
        INTEGER(iwp) ::  k_pp      !< k+2 index in disretization, can be modified to avoid segmentation faults
        INTEGER(iwp) ::  k_ppp     !< k+3 index in disretization, can be modified to avoid segmentation faults
-       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms  
+       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms
        INTEGER(iwp) ::  tn        !< number of OpenMP thread
-       
+
        INTEGER(iwp), INTENT(IN), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::   &
                                                   advc_flag !< flag array to control order of scalar advection
@@ -1244,5 +1250,5 @@
        LOGICAL           ::  non_cyclic_n    !< flag that indicates non-cyclic boundary on the north
        LOGICAL           ::  non_cyclic_r    !< flag that indicates non-cyclic boundary on the right
-       LOGICAL           ::  non_cyclic_s    !< flag that indicates non-cyclic boundary on the south                                           
+       LOGICAL           ::  non_cyclic_s    !< flag that indicates non-cyclic boundary on the south
        LOGICAL, OPTIONAL ::  flux_limitation !< flag indicating flux limitation of the vertical advection
        LOGICAL           ::  limiter         !< control flag indicating the application of flux limitation
@@ -1251,5 +1257,5 @@
        REAL(wp) ::  div           !< velocity diverence on scalar grid
        REAL(wp) ::  div_in        !< vertical flux divergence of ingoing fluxes
-       REAL(wp) ::  div_out       !< vertical flux divergence of outgoing fluxes      
+       REAL(wp) ::  div_out       !< vertical flux divergence of outgoing fluxes
        REAL(wp) ::  f_corr_t      !< correction flux at grid-cell top, i.e. the difference between high and low-order flux
        REAL(wp) ::  f_corr_d      !< correction flux at grid-cell bottom, i.e. the difference between high and low-order flux
@@ -1272,31 +1278,30 @@
        REAL(wp) ::  min_val       !< maximum value of the quanitity along the numerical stencil (in vertical direction)
        REAL(wp) ::  mon           !< monotone solution of the advection equation using 1st-order fluxes
-       REAL(wp) ::  u_comp        !< advection velocity along x-direction 
-       REAL(wp) ::  v_comp        !< advection velocity along y-direction 
-!       
-!--    sk is an array from parameter list. It should not be a pointer, because 
-!--    in that case the compiler can not assume a stride 1 and cannot perform 
-!--    a strided one vector load. Adding the CONTIGUOUS keyword makes things 
-!--    even worse, because the compiler cannot assume strided one in the 
+       REAL(wp) ::  u_comp        !< advection velocity along x-direction
+       REAL(wp) ::  v_comp        !< advection velocity along y-direction
+!
+!--    sk is an array from parameter list. It should not be a pointer, because
+!--    in that case the compiler can not assume a stride 1 and cannot perform
+!--    a strided one vector load. Adding the CONTIGUOUS keyword makes things
+!--    even worse, because the compiler cannot assume strided one in the
 !--    caller side.
        REAL(wp), INTENT(IN),DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  sk !<  advected scalar
 
-       REAL(wp), DIMENSION(nzb:nzt+1)         ::  diss_n     !< discretized artificial dissipation at northward-side of the grid box
-       REAL(wp), DIMENSION(nzb:nzt+1)         ::  diss_r     !< discretized artificial dissipation at rightward-side of the grid box
-       REAL(wp), DIMENSION(nzb:nzt+1)         ::  diss_t     !< discretized artificial dissipation at top of the grid box
-       REAL(wp), DIMENSION(nzb:nzt+1)         ::  flux_n     !< discretized 6th-order flux at northward-side of the grid box
-       REAL(wp), DIMENSION(nzb:nzt+1)         ::  flux_r     !< discretized 6th-order flux at rightward-side of the grid box
-       REAL(wp), DIMENSION(nzb:nzt+1)         ::  flux_t     !< discretized 6th-order flux at top of the grid box
-       REAL(wp), DIMENSION(nzb:nzt+1)         ::  flux_t_1st !< discretized 1st-order flux at top of the grid box
-       
-       REAL(wp), DIMENSION(nzb+1:nzt,0:threads_per_task-1) ::  swap_diss_y_local !< discretized artificial dissipation at southward-side of the grid box 
-       REAL(wp), DIMENSION(nzb+1:nzt,0:threads_per_task-1) ::  swap_flux_y_local !< discretized 6th-order flux at northward-side of the grid box
-       
-       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn,0:threads_per_task-1) ::  swap_diss_x_local !< discretized artificial dissipation at leftward-side of the grid box 
-       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn,0:threads_per_task-1) ::  swap_flux_x_local !< discretized 6th-order flux at leftward-side of the grid box
-!
-!--    Used local modified copy of nzb_max (used to degrade order of 
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  diss_n     !< discretized artificial dissipation at northward-side
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  diss_r     !< discretized artificial dissipation at rightward-side
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  diss_t     !< discretized artificial dissipation at top
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  flux_n     !< discretized 6th-order flux at northward-side
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  flux_r     !< discretized 6th-order flux at rightward-side
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  flux_t     !< discretized 6th-order flux at top
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  flux_t_1st !< discretized 1st-order flux at top
+
+       REAL(wp), DIMENSION(nzb+1:nzt,0:threads_per_task-1) ::  swap_diss_y_local !< discretized artificial dissipation at southward-side
+       REAL(wp), DIMENSION(nzb+1:nzt,0:threads_per_task-1) ::  swap_flux_y_local !< discretized 6th-order flux at northward-side
+       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn,0:threads_per_task-1) ::  swap_diss_x_local !< discretized artificial dissipation at leftward-side
+       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn,0:threads_per_task-1) ::  swap_flux_x_local !< discretized 6th-order flux at leftward-side
+!
+!--    Used local modified copy of nzb_max (used to degrade order of
 !--    discretization) at non-cyclic boundaries. Modify only at relevant points
-!--    instead of the entire subdomain. This should lead to better 
+!--    instead of the entire subdomain. This should lead to better
 !--    load balance between boundary and non-boundary PEs.
        IF( non_cyclic_l  .AND.  i <= nxl + 2  .OR.                             &
@@ -1309,5 +1314,5 @@
        END IF
 !
-!--    Set control flag for flux limiter 
+!--    Set control flag for flux limiter
        limiter = .FALSE.
        IF ( PRESENT( flux_limitation) )  limiter = flux_limitation
@@ -1324,32 +1329,32 @@
 
              v_comp                  = v(k,j,i) - v_gtrans + v_stokes_zu(k)
-             swap_flux_y_local(k,tn) = v_comp *         (                     &
-                                               ( 37.0_wp * ibit5 * adv_sca_5  &
-                                            +     7.0_wp * ibit4 * adv_sca_3  &
-                                            +              ibit3 * adv_sca_1  &
-                                               ) *                            &
-                                           ( sk(k,j,i)  + sk(k,j-1,i)     )   &
-                                         -     (  8.0_wp * ibit5 * adv_sca_5  &
-                                            +              ibit4 * adv_sca_3  &
-                                                ) *                           &
-                                           ( sk(k,j+1,i) + sk(k,j-2,i)    )   &
-                                         +     (           ibit5 * adv_sca_5  &
-                                               ) *                            &
-                                           ( sk(k,j+2,i) + sk(k,j-3,i)    )   &
+             swap_flux_y_local(k,tn) = v_comp *         (                      &
+                                               ( 37.0_wp * ibit5 * adv_sca_5   &
+                                            +     7.0_wp * ibit4 * adv_sca_3   &
+                                            +              ibit3 * adv_sca_1   &
+                                               ) *                             &
+                                           ( sk(k,j,i)  + sk(k,j-1,i)     )    &
+                                         -     (  8.0_wp * ibit5 * adv_sca_5   &
+                                            +              ibit4 * adv_sca_3   &
+                                                ) *                            &
+                                           ( sk(k,j+1,i) + sk(k,j-2,i)    )    &
+                                         +     (           ibit5 * adv_sca_5   &
+                                               ) *                             &
+                                           ( sk(k,j+2,i) + sk(k,j-3,i)    )    &
                                                         )
 
-             swap_diss_y_local(k,tn) = -ABS( v_comp ) * (                     &
-                                               ( 10.0_wp * ibit5 * adv_sca_5  &
-                                            +     3.0_wp * ibit4 * adv_sca_3  &
-                                            +              ibit3 * adv_sca_1  &
-                                               ) *                            &
-                                            ( sk(k,j,i)   - sk(k,j-1,i)  )    &
-                                        -      (  5.0_wp * ibit5 * adv_sca_5  &
-                                            +              ibit4 * adv_sca_3  &
-                                            ) *                               &
-                                            ( sk(k,j+1,i) - sk(k,j-2,i)  )    &
-                                        +      (           ibit5 * adv_sca_5  &
-                                               ) *                            &
-                                            ( sk(k,j+2,i) - sk(k,j-3,i)  )    &
+             swap_diss_y_local(k,tn) = -ABS( v_comp ) * (                      &
+                                               ( 10.0_wp * ibit5 * adv_sca_5   &
+                                            +     3.0_wp * ibit4 * adv_sca_3   &
+                                            +              ibit3 * adv_sca_1   &
+                                               ) *                             &
+                                            ( sk(k,j,i)   - sk(k,j-1,i)  )     &
+                                        -      (  5.0_wp * ibit5 * adv_sca_5   &
+                                            +              ibit4 * adv_sca_3   &
+                                            ) *                                &
+                                            ( sk(k,j+1,i) - sk(k,j-2,i)  )     &
+                                        +      (           ibit5 * adv_sca_5   &
+                                               ) *                             &
+                                            ( sk(k,j+2,i) - sk(k,j-3,i)  )     &
                                                         )
 
@@ -1360,13 +1365,13 @@
 
              v_comp                  = v(k,j,i) - v_gtrans + v_stokes_zu(k)
-             swap_flux_y_local(k,tn) = v_comp * (                             &
-                                    37.0_wp * ( sk(k,j,i)   + sk(k,j-1,i) )   &
-                                  -  8.0_wp * ( sk(k,j+1,i) + sk(k,j-2,i) )   &
-                                  +           ( sk(k,j+2,i) + sk(k,j-3,i) )   &
+             swap_flux_y_local(k,tn) = v_comp * (                              &
+                                    37.0_wp * ( sk(k,j,i)   + sk(k,j-1,i) )    &
+                                  -  8.0_wp * ( sk(k,j+1,i) + sk(k,j-2,i) )    &
+                                  +           ( sk(k,j+2,i) + sk(k,j-3,i) )    &
                                                 ) * adv_sca_5
-             swap_diss_y_local(k,tn) = -ABS( v_comp ) * (                     &
-                                    10.0_wp * ( sk(k,j,i)   - sk(k,j-1,i) )   &
-                                  -  5.0_wp * ( sk(k,j+1,i) - sk(k,j-2,i) )   &
-                                  +             sk(k,j+2,i) - sk(k,j-3,i)     &
+             swap_diss_y_local(k,tn) = -ABS( v_comp ) * (                      &
+                                    10.0_wp * ( sk(k,j,i)   - sk(k,j-1,i) )    &
+                                  -  5.0_wp * ( sk(k,j+1,i) - sk(k,j-2,i) )    &
+                                  +             sk(k,j+2,i) - sk(k,j-3,i)      &
                                                         ) * adv_sca_5
 
@@ -1377,5 +1382,5 @@
 !--    Compute leftside fluxes of the respective PE bounds.
        IF ( i == i_omp )  THEN
-        
+
           DO  k = nzb+1, nzb_max_l
 
@@ -1384,33 +1389,33 @@
              ibit0 = REAL( IBITS(advc_flag(k,j,i-1),0,1), KIND = wp )
 
-             u_comp                     = u(k,j,i) - u_gtrans + u_stokes_zu(k)
-             swap_flux_x_local(k,j,tn) = u_comp * (                           &
-                                               ( 37.0_wp * ibit2 * adv_sca_5  &
-                                            +     7.0_wp * ibit1 * adv_sca_3  &
-                                            +              ibit0 * adv_sca_1  &
-                                               ) *                            &
-                                            ( sk(k,j,i)   + sk(k,j,i-1)    )  &
-                                        -      (  8.0_wp * ibit2 * adv_sca_5  &
-                                            +              ibit1 * adv_sca_3  &
-                                               ) *                            &
-                                            ( sk(k,j,i+1) + sk(k,j,i-2)    )  &
-                                        +      (           ibit2 * adv_sca_5  &
-                                               ) *                            &
-                                            ( sk(k,j,i+2) + sk(k,j,i-3)    )  &
+             u_comp                    = u(k,j,i) - u_gtrans + u_stokes_zu(k)
+             swap_flux_x_local(k,j,tn) = u_comp * (                            &
+                                               ( 37.0_wp * ibit2 * adv_sca_5   &
+                                            +     7.0_wp * ibit1 * adv_sca_3   &
+                                            +              ibit0 * adv_sca_1   &
+                                               ) *                             &
+                                            ( sk(k,j,i)   + sk(k,j,i-1)    )   &
+                                        -      (  8.0_wp * ibit2 * adv_sca_5   &
+                                            +              ibit1 * adv_sca_3   &
+                                               ) *                             &
+                                            ( sk(k,j,i+1) + sk(k,j,i-2)    )   &
+                                        +      (           ibit2 * adv_sca_5   &
+                                               ) *                             &
+                                            ( sk(k,j,i+2) + sk(k,j,i-3)    )   &
                                                   )
 
-             swap_diss_x_local(k,j,tn) = -ABS( u_comp ) * (                   &
-                                               ( 10.0_wp * ibit2 * adv_sca_5  &
-                                            +     3.0_wp * ibit1 * adv_sca_3  &
-                                            +              ibit0 * adv_sca_1  &
-                                               ) *                            &
-                                            ( sk(k,j,i)   - sk(k,j,i-1)    )  &
-                                        -      (  5.0_wp * ibit2 * adv_sca_5  &
-                                            +              ibit1 * adv_sca_3  &
-                                               ) *                            &
-                                            ( sk(k,j,i+1) - sk(k,j,i-2)    )  &
-                                        +      (           ibit2 * adv_sca_5  &
-                                               ) *                            &
-                                            ( sk(k,j,i+2) - sk(k,j,i-3)    )  &
+             swap_diss_x_local(k,j,tn) = -ABS( u_comp ) * (                    &
+                                               ( 10.0_wp * ibit2 * adv_sca_5   &
+                                            +     3.0_wp * ibit1 * adv_sca_3   &
+                                            +              ibit0 * adv_sca_1   &
+                                               ) *                             &
+                                            ( sk(k,j,i)   - sk(k,j,i-1)    )   &
+                                        -      (  5.0_wp * ibit2 * adv_sca_5   &
+                                            +              ibit1 * adv_sca_3   &
+                                               ) *                             &
+                                            ( sk(k,j,i+1) - sk(k,j,i-2)    )   &
+                                        +      (           ibit2 * adv_sca_5   &
+                                               ) *                             &
+                                            ( sk(k,j,i+2) - sk(k,j,i-3)    )   &
                                                           )
 
@@ -1419,28 +1424,24 @@
           DO  k = nzb_max_l+1, nzt
 
-             u_comp                 = u(k,j,i) - u_gtrans + u_stokes_zu(k)
-             swap_flux_x_local(k,j,tn) = u_comp * (                           &
-                                      37.0_wp * ( sk(k,j,i)   + sk(k,j,i-1) ) &
-                                    -  8.0_wp * ( sk(k,j,i+1) + sk(k,j,i-2) ) &
-                                    +           ( sk(k,j,i+2) + sk(k,j,i-3) ) &
+             u_comp                    = u(k,j,i) - u_gtrans + u_stokes_zu(k)
+             swap_flux_x_local(k,j,tn) = u_comp * (                            &
+                                      37.0_wp * ( sk(k,j,i)   + sk(k,j,i-1) )  &
+                                    -  8.0_wp * ( sk(k,j,i+1) + sk(k,j,i-2) )  &
+                                    +           ( sk(k,j,i+2) + sk(k,j,i-3) )  &
                                                   ) * adv_sca_5
 
-             swap_diss_x_local(k,j,tn) = -ABS( u_comp ) * (                   &
-                                      10.0_wp * ( sk(k,j,i)   - sk(k,j,i-1) ) &
-                                    -  5.0_wp * ( sk(k,j,i+1) - sk(k,j,i-2) ) &
-                                    +           ( sk(k,j,i+2) - sk(k,j,i-3) ) &
+             swap_diss_x_local(k,j,tn) = -ABS( u_comp ) * (                    &
+                                      10.0_wp * ( sk(k,j,i)   - sk(k,j,i-1) )  &
+                                    -  5.0_wp * ( sk(k,j,i+1) - sk(k,j,i-2) )  &
+                                    +           ( sk(k,j,i+2) - sk(k,j,i-3) )  &
                                                           ) * adv_sca_5
 
           ENDDO
-           
+
        ENDIF
-!        
-!--    Now compute the fluxes and tendency terms for the horizontal and
-!--    vertical parts up to the top of the highest topography.
+!
+!--    Now compute the fluxes for the horizontal termns up to the highest
+!--    topography.
        DO  k = nzb+1, nzb_max_l
-!
-!--       Note: It is faster to conduct all multiplications explicitly, e.g.
-!--       * adv_sca_5 ... than to determine a factor and multiplicate the
-!--       flux at the end. 
 
           ibit2 = REAL( IBITS(advc_flag(k,j,i),2,1), KIND = wp )
@@ -1449,32 +1450,32 @@
 
           u_comp    = u(k,j,i+1) - u_gtrans + u_stokes_zu(k)
-          flux_r(k) = u_comp * (                                              &
-                     ( 37.0_wp * ibit2 * adv_sca_5                            &
-                  +     7.0_wp * ibit1 * adv_sca_3                            &
-                  +              ibit0 * adv_sca_1                            &
-                     ) *                                                      &
-                             ( sk(k,j,i+1) + sk(k,j,i)   )                    &
-              -      (  8.0_wp * ibit2 * adv_sca_5                            &
-                  +              ibit1 * adv_sca_3                            &
-                     ) *                                                      &
-                             ( sk(k,j,i+2) + sk(k,j,i-1) )                    &
-              +      (           ibit2 * adv_sca_5                            &
-                     ) *                                                      &
-                             ( sk(k,j,i+3) + sk(k,j,i-2) )                    &
+          flux_r(k) = u_comp * (                                               &
+                     ( 37.0_wp * ibit2 * adv_sca_5                             &
+                  +     7.0_wp * ibit1 * adv_sca_3                             &
+                  +              ibit0 * adv_sca_1                             &
+                     ) *                                                       &
+                             ( sk(k,j,i+1) + sk(k,j,i)   )                     &
+              -      (  8.0_wp * ibit2 * adv_sca_5                             &
+                  +              ibit1 * adv_sca_3                             &
+                     ) *                                                       &
+                             ( sk(k,j,i+2) + sk(k,j,i-1) )                     &
+              +      (           ibit2 * adv_sca_5                             &
+                     ) *                                                       &
+                             ( sk(k,j,i+3) + sk(k,j,i-2) )                     &
                                )
 
-          diss_r(k) = -ABS( u_comp ) * (                                      &
-                     ( 10.0_wp * ibit2 * adv_sca_5                            &
-                  +     3.0_wp * ibit1 * adv_sca_3                            &
-                  +              ibit0 * adv_sca_1                            &
-                     ) *                                                      &
-                             ( sk(k,j,i+1) - sk(k,j,i)  )                     &
-              -      (  5.0_wp * ibit2 * adv_sca_5                            &
-                  +              ibit1 * adv_sca_3                            &
-                     ) *                                                      &
-                             ( sk(k,j,i+2) - sk(k,j,i-1) )                    &
-              +      (           ibit2 * adv_sca_5                            &
-                     ) *                                                      &
-                             ( sk(k,j,i+3) - sk(k,j,i-2) )                    &
+          diss_r(k) = -ABS( u_comp ) * (                                       &
+                     ( 10.0_wp * ibit2 * adv_sca_5                             &
+                  +     3.0_wp * ibit1 * adv_sca_3                             &
+                  +              ibit0 * adv_sca_1                             &
+                     ) *                                                       &
+                             ( sk(k,j,i+1) - sk(k,j,i)  )                      &
+              -      (  5.0_wp * ibit2 * adv_sca_5                             &
+                  +              ibit1 * adv_sca_3                             &
+                     ) *                                                       &
+                             ( sk(k,j,i+2) - sk(k,j,i-1) )                     &
+              +      (           ibit2 * adv_sca_5                             &
+                     ) *                                                       &
+                             ( sk(k,j,i+3) - sk(k,j,i-2) )                     &
                                        )
 
@@ -1515,7 +1516,7 @@
        ENDDO
 !
-!--    Now compute the fluxes and tendency terms for the horizontal and
-!--    vertical parts above the top of the highest topography. No degradation
-!--    for the horizontal parts, but for the vertical it is stell needed.
+!--    Now compute the fluxes for the horizontal terms above the topography
+!--    where no degradation along the horizontal parts is necessary (except
+!--    for the non-cyclic lateral boundaries treated by nzb_max_l).
        DO  k = nzb_max_l+1, nzt
 
@@ -1542,9 +1543,9 @@
        ENDDO
 !
-!--    Now, compute vertical fluxes. Split loop into a part treating the 
+!--    Now, compute vertical fluxes. Split loop into a part treating the
 !--    lowest grid points with indirect indexing, a main loop without
 !--    indirect indexing, and a loop for the uppermost grip points with
 !--    indirect indexing. This allows better vectorization for the main loop.
-!--    First, compute the flux at model surface, which need has to be 
+!--    First, compute the flux at model surface, which need has to be
 !--    calculated explicetely for the tendency at
 !--    the first w-level. For topography wall this is done implicitely by
@@ -1552,5 +1553,5 @@
        flux_t(nzb) = 0.0_wp
        diss_t(nzb) = 0.0_wp
-       
+
        DO  k = nzb+1, nzb+1
           ibit8 = REAL( IBITS(advc_flag(k,j,i),8,1), KIND = wp )
@@ -1563,82 +1564,4 @@
           k_pp  = k + 2 * ( 1 - ibit6  )
           k_mm  = k - 2 * ibit8
-
-
-          flux_t(k) = w(k,j,i) * rho_air_zw(k) * (                            &
-                     ( 37.0_wp * ibit8 * adv_sca_5                            &
-                  +     7.0_wp * ibit7 * adv_sca_3                            &
-                  +              ibit6 * adv_sca_1                            &
-                     ) *                                                      &
-                             ( sk(k+1,j,i)  + sk(k,j,i)    )                  &
-              -      (  8.0_wp * ibit8 * adv_sca_5                            &
-                  +              ibit7 * adv_sca_3                            &
-                     ) *                                                      &
-                             ( sk(k_pp,j,i) + sk(k-1,j,i)  )                  &
-              +      (           ibit8 * adv_sca_5                            &
-                     ) *     ( sk(k_ppp,j,i)+ sk(k_mm,j,i) )                  &
-                                 )
-
-          diss_t(k) = -ABS( w(k,j,i) ) * rho_air_zw(k) * (                    &
-                     ( 10.0_wp * ibit8 * adv_sca_5                            &
-                  +     3.0_wp * ibit7 * adv_sca_3                            &
-                  +              ibit6 * adv_sca_1                            &
-                     ) *                                                      &
-                             ( sk(k+1,j,i)   - sk(k,j,i)    )                 &
-              -      (  5.0_wp * ibit8 * adv_sca_5                            &
-                  +              ibit7 * adv_sca_3                            &
-                     ) *                                                      &
-                             ( sk(k_pp,j,i)  - sk(k-1,j,i)  )                 &
-              +      (           ibit8 * adv_sca_5                            &
-                     ) *                                                      &
-                             ( sk(k_ppp,j,i) - sk(k_mm,j,i) )                 &
-                                         )
-       ENDDO 
-       
-       DO  k = nzb+2, nzt-2
-          ibit8 = REAL( IBITS(advc_flag(k,j,i),8,1), KIND = wp )
-          ibit7 = REAL( IBITS(advc_flag(k,j,i),7,1), KIND = wp )
-          ibit6 = REAL( IBITS(advc_flag(k,j,i),6,1), KIND = wp )
-
-          flux_t(k) = w(k,j,i) * rho_air_zw(k) * (                            &
-                     ( 37.0_wp * ibit8 * adv_sca_5                            &
-                  +     7.0_wp * ibit7 * adv_sca_3                            &
-                  +              ibit6 * adv_sca_1                            &
-                     ) *                                                      &
-                             ( sk(k+1,j,i)  + sk(k,j,i)    )                  &
-              -      (  8.0_wp * ibit8 * adv_sca_5                            &
-                  +              ibit7 * adv_sca_3                            &
-                     ) *                                                      &
-                             ( sk(k+2,j,i) + sk(k-1,j,i)  )                   &
-              +      (           ibit8 * adv_sca_5                            &
-                     ) *     ( sk(k+3,j,i)+ sk(k-2,j,i) )                     &
-                                                 )
-
-          diss_t(k) = -ABS( w(k,j,i) ) * rho_air_zw(k) * (                    &
-                     ( 10.0_wp * ibit8 * adv_sca_5                            &
-                  +     3.0_wp * ibit7 * adv_sca_3                            &
-                  +              ibit6 * adv_sca_1                            &
-                     ) *                                                      &
-                             ( sk(k+1,j,i)   - sk(k,j,i)    )                 &
-              -      (  5.0_wp * ibit8 * adv_sca_5                            &
-                  +              ibit7 * adv_sca_3                            &
-                     ) *                                                      &
-                             ( sk(k+2,j,i)  - sk(k-1,j,i)  )                  &
-              +      (           ibit8 * adv_sca_5                            &
-                     ) *                                                      &
-                             ( sk(k+3,j,i) - sk(k-2,j,i) )                    &
-                                                         )
-       ENDDO       
-       
-       DO  k = nzt-1, nzt-symmetry_flag
-          ibit8 = REAL( IBITS(advc_flag(k,j,i),8,1), KIND = wp )
-          ibit7 = REAL( IBITS(advc_flag(k,j,i),7,1), KIND = wp )
-          ibit6 = REAL( IBITS(advc_flag(k,j,i),6,1), KIND = wp )
-!
-!--       k index has to be modified near bottom and top, else array
-!--       subscripts will be exceeded.
-          k_ppp = k + 3 * ibit8
-          k_pp  = k + 2 * ( 1 - ibit6  )
-          k_mm  = k - 2 * ibit8
-
 
           flux_t(k) = w(k,j,i) * rho_air_zw(k) * (                            &
@@ -1671,9 +1594,86 @@
                                                          )
        ENDDO
-       
+
+       DO  k = nzb+2, nzt-2
+          ibit8 = REAL( IBITS(advc_flag(k,j,i),8,1), KIND = wp )
+          ibit7 = REAL( IBITS(advc_flag(k,j,i),7,1), KIND = wp )
+          ibit6 = REAL( IBITS(advc_flag(k,j,i),6,1), KIND = wp )
+
+          flux_t(k) = w(k,j,i) * rho_air_zw(k) * (                            &
+                     ( 37.0_wp * ibit8 * adv_sca_5                            &
+                  +     7.0_wp * ibit7 * adv_sca_3                            &
+                  +              ibit6 * adv_sca_1                            &
+                     ) *                                                      &
+                             ( sk(k+1,j,i)  + sk(k,j,i)    )                  &
+              -      (  8.0_wp * ibit8 * adv_sca_5                            &
+                  +              ibit7 * adv_sca_3                            &
+                     ) *                                                      &
+                             ( sk(k+2,j,i) + sk(k-1,j,i)  )                   &
+              +      (           ibit8 * adv_sca_5                            &
+                     ) *     ( sk(k+3,j,i)+ sk(k-2,j,i) )                     &
+                                                 )
+
+          diss_t(k) = -ABS( w(k,j,i) ) * rho_air_zw(k) * (                    &
+                     ( 10.0_wp * ibit8 * adv_sca_5                            &
+                  +     3.0_wp * ibit7 * adv_sca_3                            &
+                  +              ibit6 * adv_sca_1                            &
+                     ) *                                                      &
+                             ( sk(k+1,j,i)   - sk(k,j,i)    )                 &
+              -      (  5.0_wp * ibit8 * adv_sca_5                            &
+                  +              ibit7 * adv_sca_3                            &
+                     ) *                                                      &
+                             ( sk(k+2,j,i)  - sk(k-1,j,i)  )                  &
+              +      (           ibit8 * adv_sca_5                            &
+                     ) *                                                      &
+                             ( sk(k+3,j,i) - sk(k-2,j,i) )                    &
+                                                         )
+       ENDDO
+
+       DO  k = nzt-1, nzt-symmetry_flag
+          ibit8 = REAL( IBITS(advc_flag(k,j,i),8,1), KIND = wp )
+          ibit7 = REAL( IBITS(advc_flag(k,j,i),7,1), KIND = wp )
+          ibit6 = REAL( IBITS(advc_flag(k,j,i),6,1), KIND = wp )
+!
+!--       k index has to be modified near bottom and top, else array
+!--       subscripts will be exceeded.
+          k_ppp = k + 3 * ibit8
+          k_pp  = k + 2 * ( 1 - ibit6  )
+          k_mm  = k - 2 * ibit8
+
+
+          flux_t(k) = w(k,j,i) * rho_air_zw(k) * (                            &
+                     ( 37.0_wp * ibit8 * adv_sca_5                            &
+                  +     7.0_wp * ibit7 * adv_sca_3                            &
+                  +              ibit6 * adv_sca_1                            &
+                     ) *                                                      &
+                             ( sk(k+1,j,i)  + sk(k,j,i)    )                  &
+              -      (  8.0_wp * ibit8 * adv_sca_5                            &
+                  +              ibit7 * adv_sca_3                            &
+                     ) *                                                      &
+                             ( sk(k_pp,j,i) + sk(k-1,j,i)  )                  &
+              +      (           ibit8 * adv_sca_5                            &
+                     ) *     ( sk(k_ppp,j,i)+ sk(k_mm,j,i) )                  &
+                                                 )
+
+          diss_t(k) = -ABS( w(k,j,i) ) * rho_air_zw(k) * (                    &
+                     ( 10.0_wp * ibit8 * adv_sca_5                            &
+                  +     3.0_wp * ibit7 * adv_sca_3                            &
+                  +              ibit6 * adv_sca_1                            &
+                     ) *                                                      &
+                             ( sk(k+1,j,i)   - sk(k,j,i)    )                 &
+              -      (  5.0_wp * ibit8 * adv_sca_5                            &
+                  +              ibit7 * adv_sca_3                            &
+                     ) *                                                      &
+                             ( sk(k_pp,j,i)  - sk(k-1,j,i)  )                 &
+              +      (           ibit8 * adv_sca_5                            &
+                     ) *                                                      &
+                             ( sk(k_ppp,j,i) - sk(k_mm,j,i) )                 &
+                                                         )
+       ENDDO
+
 !
 !--    Set resolved/turbulent flux at model top to zero (w-level). In case that
 !--    a symmetric behavior between bottom and top shall be guaranteed (closed
-!--    channel flow), the flux at nzt is also set to zero. 
+!--    channel flow), the flux at nzt is also set to zero.
        IF ( symmetry_flag == 1 ) THEN
           flux_t(nzt) = 0.0_wp
@@ -1682,6 +1682,6 @@
        flux_t(nzt+1) = 0.0_wp
        diss_t(nzt+1) = 0.0_wp
-       
-       
+
+
        IF ( limiter )  THEN
 !
@@ -1695,58 +1695,58 @@
 !
 !--          In flux limitation the total flux will be corrected. For the sake
-!--          of cleariness the higher-order advective and disspative fluxes 
-!--          will be merged onto flux_t. 
+!--          of cleariness the higher-order advective and disspative fluxes
+!--          will be merged onto flux_t.
              flux_t(k) = flux_t(k) + diss_t(k)
              diss_t(k) = 0.0_wp
           ENDDO
 !
-!--       Flux limitation of vertical fluxes according to Skamarock (2006). 
+!--       Flux limitation of vertical fluxes according to Skamarock (2006).
 !--       Please note, as flux limitation implies linear dependencies of fluxes,
 !--       flux limitation is only made for the vertical advection term. Limitation
-!--       of the horizontal terms cannot be parallelized. 
+!--       of the horizontal terms cannot be parallelized.
 !--       Due to the linear dependency, the following loop will not be vectorized.
 !--       Further, note that the flux limiter is only applied within the urban
-!--       layer, i.e up to the topography top.  
+!--       layer, i.e up to the topography top.
           DO  k = nzb+1, nzb_max_l
 !
 !--          Compute one-dimensional divergence along the vertical direction,
-!--          which is used to correct the advection discretization. This is 
+!--          which is used to correct the advection discretization. This is
 !--          necessary as in one-dimensional space the advection velocity
-!--          should actually be constant. 
+!--          should actually be constant.
              div = ( w(k,j,i)   * rho_air_zw(k)                                &
-                   - w(k-1,j,i) * rho_air_zw(k-1)                              &      
+                   - w(k-1,j,i) * rho_air_zw(k-1)                              &
                    ) * drho_air(k) * ddzw(k)
 !
-!--          Compute monotone solution of the advection equation from 
+!--          Compute monotone solution of the advection equation from
 !--          1st-order fluxes. Please note, the advection equation is corrected
 !--          by the divergence term (in 1D the advective flow should be divergence
-!--          free). Moreover, please note, as time-increment the full timestep 
-!--          is used, even though a Runge-Kutta scheme will be used. However, 
-!--          the length of the actual time increment is not important at all 
-!--          since it cancels out later when the fluxes are limited.   
+!--          free). Moreover, please note, as time-increment the full timestep
+!--          is used, even though a Runge-Kutta scheme will be used. However,
+!--          the length of the actual time increment is not important at all
+!--          since it cancels out later when the fluxes are limited.
              mon = sk(k,j,i) + ( - ( flux_t_1st(k) - flux_t_1st(k-1) )         &
                              * drho_air(k) * ddzw(k)                           &
                              + div * sk(k,j,i)                                 &
-                               ) * dt_3d 
+                               ) * dt_3d
 !
 !--          Determine minimum and maximum values along the numerical stencil.
              k_mmm = MAX( k - 3, nzb + 1 )
-             k_ppp = MIN( k + 3, nzt + 1 ) 
+             k_ppp = MIN( k + 3, nzt + 1 )
 
              min_val = MINVAL( sk(k_mmm:k_ppp,j,i) )
              max_val = MAXVAL( sk(k_mmm:k_ppp,j,i) )
 !
-!--          Compute difference between high- and low-order fluxes, which may 
+!--          Compute difference between high- and low-order fluxes, which may
 !--          act as correction fluxes
              f_corr_t = flux_t(k)   - flux_t_1st(k)
              f_corr_d = flux_t(k-1) - flux_t_1st(k-1)
 !
-!--          Determine outgoing fluxes, i.e. the part of the fluxes which can 
+!--          Determine outgoing fluxes, i.e. the part of the fluxes which can
 !--          decrease the value within the grid box
              f_corr_t_out = MAX( 0.0_wp, f_corr_t )
              f_corr_d_out = MIN( 0.0_wp, f_corr_d )
 !
-!--          Determine ingoing fluxes, i.e. the part of the fluxes which can 
-!--          increase the value within the grid box 
+!--          Determine ingoing fluxes, i.e. the part of the fluxes which can
+!--          increase the value within the grid box
              f_corr_t_in = MIN( 0.0_wp, f_corr_t)
              f_corr_d_in = MAX( 0.0_wp, f_corr_d)
@@ -1762,5 +1762,5 @@
 !--          Check if outgoing fluxes can lead to undershoots, i.e. values smaller
 !--          than the minimum value within the numerical stencil. If so, limit
-!--          them. 
+!--          them.
              IF ( mon - min_val < - div_out  .AND.  ABS( div_out ) > 0.0_wp )  &
              THEN
@@ -1772,5 +1772,5 @@
 !--          Check if ingoing fluxes can lead to overshoots, i.e. values larger
 !--          than the maximum value within the numerical stencil. If so, limit
-!--          them. 
+!--          them.
              IF ( mon - max_val > - div_in  .AND.  ABS( div_in ) > 0.0_wp )    &
              THEN
@@ -1780,24 +1780,25 @@
              ENDIF
 !
-!--          Finally add the limited fluxes to the original ones. If no 
-!--          flux limitation was done, the fluxes equal the original ones. 
+!--          Finally add the limited fluxes to the original ones. If no
+!--          flux limitation was done, the fluxes equal the original ones.
              flux_t(k)   = flux_t_1st(k)   + f_corr_t_out + f_corr_t_in
              flux_t(k-1) = flux_t_1st(k-1) + f_corr_d_out + f_corr_d_in
           ENDDO
        ENDIF
-
+!
+!--    Now compute the tendency term including divergence correction.
        DO  k = nzb+1, nzb_max_l
 
           flux_d    = flux_t(k-1)
           diss_d    = diss_t(k-1)
-          
+
           ibit2 = REAL( IBITS(advc_flag(k,j,i),2,1), KIND = wp )
           ibit1 = REAL( IBITS(advc_flag(k,j,i),1,1), KIND = wp )
           ibit0 = REAL( IBITS(advc_flag(k,j,i),0,1), KIND = wp )
-          
+
           ibit5 = REAL( IBITS(advc_flag(k,j,i),5,1), KIND = wp )
           ibit4 = REAL( IBITS(advc_flag(k,j,i),4,1), KIND = wp )
           ibit3 = REAL( IBITS(advc_flag(k,j,i),3,1), KIND = wp )
-          
+
           ibit8 = REAL( IBITS(advc_flag(k,j,i),8,1), KIND = wp )
           ibit7 = REAL( IBITS(advc_flag(k,j,i),7,1), KIND = wp )
@@ -1807,36 +1808,36 @@
 !--       correction is needed to overcome numerical instabilities introduced
 !--       by a not sufficient reduction of divergences near topography.
-          div         =   ( u(k,j,i+1) * ( ibit0 + ibit1 + ibit2 )            &
-                          - u(k,j,i)   * (                                    &
-                        REAL( IBITS(advc_flag(k,j,i-1),0,1), KIND = wp )      &
-                      + REAL( IBITS(advc_flag(k,j,i-1),1,1), KIND = wp )      &
-                      + REAL( IBITS(advc_flag(k,j,i-1),2,1), KIND = wp )      &
-                                         )                                    &
-                          ) * ddx                                             &
-                        + ( v(k,j+1,i) * ( ibit3 + ibit4 + ibit5 )            &
-                          - v(k,j,i)   * (                                    &
-                        REAL( IBITS(advc_flag(k,j-1,i),3,1), KIND = wp )      &
-                      + REAL( IBITS(advc_flag(k,j-1,i),4,1), KIND = wp )      &
-                      + REAL( IBITS(advc_flag(k,j-1,i),5,1), KIND = wp )      &
-                                         )                                    &
-                          ) * ddy                                             &
-                        + ( w(k,j,i) * rho_air_zw(k) *                        &
-                                         ( ibit6 + ibit7 + ibit8 )            &
-                          - w(k-1,j,i) * rho_air_zw(k-1) *                    &
-                                         (                                    &
-                        REAL( IBITS(advc_flag(k-1,j,i),6,1), KIND = wp )      &
-                      + REAL( IBITS(advc_flag(k-1,j,i),7,1), KIND = wp )      &
-                      + REAL( IBITS(advc_flag(k-1,j,i),8,1), KIND = wp )      &
-                                         )                                    &      
+          div         =   ( u(k,j,i+1) * ( ibit0 + ibit1 + ibit2 )             &
+                          - u(k,j,i)   * (                                     &
+                        REAL( IBITS(advc_flag(k,j,i-1),0,1), KIND = wp )       &
+                      + REAL( IBITS(advc_flag(k,j,i-1),1,1), KIND = wp )       &
+                      + REAL( IBITS(advc_flag(k,j,i-1),2,1), KIND = wp )       &
+                                         )                                     &
+                          ) * ddx                                              &
+                        + ( v(k,j+1,i) * ( ibit3 + ibit4 + ibit5 )             &
+                          - v(k,j,i)   * (                                     &
+                        REAL( IBITS(advc_flag(k,j-1,i),3,1), KIND = wp )       &
+                      + REAL( IBITS(advc_flag(k,j-1,i),4,1), KIND = wp )       &
+                      + REAL( IBITS(advc_flag(k,j-1,i),5,1), KIND = wp )       &
+                                         )                                     &
+                          ) * ddy                                              &
+                        + ( w(k,j,i) * rho_air_zw(k) *                         &
+                                         ( ibit6 + ibit7 + ibit8 )             &
+                          - w(k-1,j,i) * rho_air_zw(k-1) *                     &
+                                         (                                     &
+                        REAL( IBITS(advc_flag(k-1,j,i),6,1), KIND = wp )       &
+                      + REAL( IBITS(advc_flag(k-1,j,i),7,1), KIND = wp )       &
+                      + REAL( IBITS(advc_flag(k-1,j,i),8,1), KIND = wp )       &
+                                         )                                     &
                           ) * drho_air(k) * ddzw(k)
 
-          tend(k,j,i) = tend(k,j,i) - (                                       &
-                        ( flux_r(k) + diss_r(k) - swap_flux_x_local(k,j,tn) - &
-                          swap_diss_x_local(k,j,tn)            ) * ddx        &
-                      + ( flux_n(k) + diss_n(k) - swap_flux_y_local(k,tn)   - &
-                          swap_diss_y_local(k,tn)              ) * ddy        &
-                      + ( ( flux_t(k) + diss_t(k) ) -                         &
-                          ( flux_d    + diss_d    )                           &
-                                                    ) * drho_air(k) * ddzw(k) &
+          tend(k,j,i) = tend(k,j,i) - (                                        &
+                        ( flux_r(k) + diss_r(k) - swap_flux_x_local(k,j,tn) -  &
+                          swap_diss_x_local(k,j,tn)            ) * ddx         &
+                      + ( flux_n(k) + diss_n(k) - swap_flux_y_local(k,tn)   -  &
+                          swap_diss_y_local(k,tn)              ) * ddy         &
+                      + ( ( flux_t(k) + diss_t(k) ) -                          &
+                          ( flux_d    + diss_d    )                            &
+                                                    ) * drho_air(k) * ddzw(k)  &
                                       ) + sk(k,j,i) * div
 
@@ -1848,5 +1849,5 @@
 
        ENDDO
-       
+
        DO  k = nzb_max_l+1, nzt
 
@@ -1857,18 +1858,18 @@
 !--       correction is needed to overcome numerical instabilities introduced
 !--       by a not sufficient reduction of divergences near topography.
-          div         =   ( u(k,j,i+1) - u(k,j,i) ) * ddx                     &
-                        + ( v(k,j+1,i) - v(k,j,i) ) * ddy                     &
-                        + ( w(k,j,i) * rho_air_zw(k)                          &
-                          - w(k-1,j,i) * rho_air_zw(k-1)                      &
+          div         =   ( u(k,j,i+1) - u(k,j,i) ) * ddx                      &
+                        + ( v(k,j+1,i) - v(k,j,i) ) * ddy                      &
+                        + ( w(k,j,i) * rho_air_zw(k)                           &
+                          - w(k-1,j,i) * rho_air_zw(k-1)                       &
                                                   ) * drho_air(k) * ddzw(k)
 
-          tend(k,j,i) = tend(k,j,i) - (                                       &
-                        ( flux_r(k) + diss_r(k) - swap_flux_x_local(k,j,tn) - &
-                          swap_diss_x_local(k,j,tn)            ) * ddx        &
-                      + ( flux_n(k) + diss_n(k) - swap_flux_y_local(k,tn)   - &
-                          swap_diss_y_local(k,tn)              ) * ddy        &
-                      + ( ( flux_t(k) + diss_t(k) ) -                         &
-                          ( flux_d    + diss_d    )                           &
-                                                    ) * drho_air(k) * ddzw(k) &
+          tend(k,j,i) = tend(k,j,i) - (                                        &
+                        ( flux_r(k) + diss_r(k) - swap_flux_x_local(k,j,tn) -  &
+                          swap_diss_x_local(k,j,tn)            ) * ddx         &
+                      + ( flux_n(k) + diss_n(k) - swap_flux_y_local(k,tn)   -  &
+                          swap_diss_y_local(k,tn)              ) * ddy         &
+                      + ( ( flux_t(k) + diss_t(k) ) -                          &
+                          ( flux_d    + diss_d    )                            &
+                                                    ) * drho_air(k) * ddzw(k)  &
                                       ) + sk(k,j,i) * div
 
@@ -1895,5 +1896,5 @@
                     ) * weight_substep(intermediate_timestep_count)
              ENDDO
-            
+
           CASE ( 'sa' )
 
@@ -1906,5 +1907,5 @@
                     ) * weight_substep(intermediate_timestep_count)
              ENDDO
-            
+
           CASE ( 'q' )
 
@@ -1988,5 +1989,4 @@
           !kk Has to be implemented for kpp chemistry
 
-
          END SELECT
 
@@ -2011,7 +2011,7 @@
        INTEGER(iwp) ::  k_pp      !< k+2 index in disretization, can be modified to avoid segmentation faults
        INTEGER(iwp) ::  k_ppp     !< k+3 index in disretization, can be modified to avoid segmentation faults
-       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms  
+       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms
        INTEGER(iwp) ::  tn        !< number of OpenMP thread
-       
+
        REAL(wp)    ::  ibit0   !< flag indicating 1st-order scheme along x-direction
        REAL(wp)    ::  ibit1   !< flag indicating 3rd-order scheme along x-direction
@@ -2029,5 +2029,5 @@
        REAL(wp)    ::  gv       !< Galilei-transformation velocity along y
        REAL(wp)    ::  u_comp_l !< advection velocity along x at leftmost grid point on subdomain
-       
+
        REAL(wp), DIMENSION(nzb:nzt+1) ::  diss_n !< discretized artificial dissipation at northward-side of the grid box
        REAL(wp), DIMENSION(nzb:nzt+1) ::  diss_r !< discretized artificial dissipation at rightward-side of the grid box
@@ -2040,7 +2040,7 @@
        REAL(wp), DIMENSION(nzb:nzt+1) ::  w_comp !< advection velocity along z
 !
-!--    Used local modified copy of nzb_max (used to degrade order of 
+!--    Used local modified copy of nzb_max (used to degrade order of
 !--    discretization) at non-cyclic boundaries. Modify only at relevant points
-!--    instead of the entire subdomain. This should lead to better 
+!--    instead of the entire subdomain. This should lead to better
 !--    load balance between boundary and non-boundary PEs.
        IF( ( bc_dirichlet_l  .OR.  bc_radiation_l )  .AND.  i <= nxl + 2  .OR. &
@@ -2052,5 +2052,5 @@
           nzb_max_l = nzb_max
        END IF
-       
+
        gu = 2.0_wp * u_gtrans
        gv = 2.0_wp * v_gtrans
@@ -2058,5 +2058,5 @@
 !--    Compute southside fluxes for the respective boundary of PE
        IF ( j == nys  )  THEN
-       
+
           DO  k = nzb+1, nzb_max_l
 
@@ -2104,5 +2104,5 @@
                            37.0_wp * ( u(k,j,i)   + u(k,j-1,i)   )             &
                          -  8.0_wp * ( u(k,j+1,i) + u(k,j-2,i) )               &
-                         +           ( u(k,j+2,i) + u(k,j-3,i) ) ) * adv_mom_5 
+                         +           ( u(k,j+2,i) + u(k,j-3,i) ) ) * adv_mom_5
              diss_s_u(k,tn) = - ABS(v_comp(k)) * (                             &
                            10.0_wp * ( u(k,j,i)   - u(k,j-1,i)   )             &
@@ -2111,10 +2111,10 @@
 
           ENDDO
-          
+
        ENDIF
 !
 !--    Compute leftside fluxes for the respective boundary of PE
        IF ( i == i_omp  .OR.  i == nxlu )  THEN
-       
+
           DO  k = nzb+1, nzb_max_l
 
@@ -2137,6 +2137,6 @@
                               ) *                                              &
                                           ( u(k,j,i+2) + u(k,j,i-3) )          &
-                                           )                                  
-                                                                              
+                                           )
+
              diss_l_u(k,j,tn) = - ABS( u_comp_l ) * (                          &
                               ( 10.0_wp * ibit2 * adv_mom_5                    &
@@ -2169,5 +2169,5 @@
 
           ENDDO
-          
+
        ENDIF
 !
@@ -2188,5 +2188,5 @@
                                     ( u(k,j,i+1) + u(k,j,i)   )                &
               -      (  8.0_wp * ibit2 * adv_mom_5                             &
-                  +              ibit1 * adv_mom_3                             & 
+                  +              ibit1 * adv_mom_3                             &
                      ) *                                                       &
                                     ( u(k,j,i+2) + u(k,j,i-1) )                &
@@ -2194,6 +2194,6 @@
                      ) *                                                       &
                                     ( u(k,j,i+3) + u(k,j,i-2) )                &
-                                           )                                  
-                                                                              
+                                           )
+
           diss_r(k) = - ABS( u_comp(k) - gu ) * (                              &
                      ( 10.0_wp * ibit2 * adv_mom_5                             &
@@ -2229,6 +2229,6 @@
                      ) *                                                       &
                                     ( u(k,j+3,i) + u(k,j-2,i) )                &
-                                  )                                           
-                                                                              
+                                  )
+
           diss_n(k) = - ABS ( v_comp(k) ) * (                                  &
                      ( 10.0_wp * ibit5 * adv_mom_5                             &
@@ -2253,15 +2253,15 @@
                          37.0_wp * ( u(k,j,i+1) + u(k,j,i)   )                 &
                        -  8.0_wp * ( u(k,j,i+2) + u(k,j,i-1) )                 &
-                       +           ( u(k,j,i+3) + u(k,j,i-2) ) ) * adv_mom_5   
+                       +           ( u(k,j,i+3) + u(k,j,i-2) ) ) * adv_mom_5
           diss_r(k) = - ABS( u_comp(k) - gu ) * (                              &
                          10.0_wp * ( u(k,j,i+1) - u(k,j,i)   )                 &
                        -  5.0_wp * ( u(k,j,i+2) - u(k,j,i-1) )                 &
-                       +           ( u(k,j,i+3) - u(k,j,i-2) ) ) * adv_mom_5   
-                                                                               
-          v_comp(k) = v(k,j+1,i) + v(k,j+1,i-1) - gv                           
+                       +           ( u(k,j,i+3) - u(k,j,i-2) ) ) * adv_mom_5
+
+          v_comp(k) = v(k,j+1,i) + v(k,j+1,i-1) - gv
           flux_n(k) = v_comp(k) * (                                            &
                          37.0_wp * ( u(k,j+1,i) + u(k,j,i)   )                 &
                        -  8.0_wp * ( u(k,j+2,i) + u(k,j-1,i) )                 &
-                       +           ( u(k,j+3,i) + u(k,j-2,i) ) ) * adv_mom_5   
+                       +           ( u(k,j+3,i) + u(k,j-2,i) ) ) * adv_mom_5
           diss_n(k) = - ABS( v_comp(k) ) * (                                   &
                          10.0_wp * ( u(k,j+1,i) - u(k,j,i)   )                 &
@@ -2271,9 +2271,9 @@
        ENDDO
 !
-!--    Now, compute vertical fluxes. Split loop into a part treating the 
+!--    Now, compute vertical fluxes. Split loop into a part treating the
 !--    lowest grid points with indirect indexing, a main loop without
 !--    indirect indexing, and a loop for the uppermost grip points with
 !--    indirect indexing. This allows better vectorization for the main loop.
-!--    First, compute the flux at model surface, which need has to be 
+!--    First, compute the flux at model surface, which need has to be
 !--    calculated explicitly for the tendency at
 !--    the first w-level. For topography wall this is done implicitely by
@@ -2282,5 +2282,5 @@
        diss_t(nzb) = 0.0_wp
        w_comp(nzb) = 0.0_wp
-       
+
        DO  k = nzb+1, nzb+1
 !
@@ -2309,6 +2309,6 @@
                      ) *                                                       &
                                 ( u(k_ppp,j,i) + u(k_mm,j,i) )                 &
-                                                  )                            
-                                                                               
+                                                  )
+
           diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (                   &
                      ( 10.0_wp * ibit8 * adv_mom_5                             &
@@ -2326,5 +2326,5 @@
                                                            )
        ENDDO
-       
+
        DO  k = nzb+2, nzt-2
 
@@ -2344,5 +2344,5 @@
                      ) *                                                       &
                                 ( u(k+2,j,i) + u(k-1,j,i)   )                  &
-              +      (           ibit8 * adv_mom_5                             & 
+              +      (           ibit8 * adv_mom_5                             &
                      ) *                                                       &
                                 ( u(k+3,j,i) + u(k-2,j,i) )                    &
@@ -2364,5 +2364,5 @@
                                                            )
        ENDDO
-       
+
        DO  k = nzt-1, nzt-symmetry_flag
 !
@@ -2408,9 +2408,9 @@
                                                            )
        ENDDO
-       
+
 !
 !--    Set resolved/turbulent flux at model top to zero (w-level). In case that
 !--    a symmetric behavior between bottom and top shall be guaranteed (closed
-!--    channel flow), the flux at nzt is also set to zero. 
+!--    channel flow), the flux at nzt is also set to zero.
        IF ( symmetry_flag == 1 ) THEN
           flux_t(nzt) = 0.0_wp
@@ -2421,18 +2421,18 @@
        diss_t(nzt+1) = 0.0_wp
        w_comp(nzt+1) = 0.0_wp
-       
+
        DO  k = nzb+1, nzb_max_l
 
           flux_d    = flux_t(k-1)
           diss_d    = diss_t(k-1)
-          
+
           ibit2 = REAL( IBITS(advc_flags_m(k,j,i),2,1), KIND = wp )
           ibit1 = REAL( IBITS(advc_flags_m(k,j,i),1,1), KIND = wp )
           ibit0 = REAL( IBITS(advc_flags_m(k,j,i),0,1), KIND = wp )
-          
+
           ibit5 = REAL( IBITS(advc_flags_m(k,j,i),5,1), KIND = wp )
           ibit4 = REAL( IBITS(advc_flags_m(k,j,i),4,1), KIND = wp )
           ibit3 = REAL( IBITS(advc_flags_m(k,j,i),3,1), KIND = wp )
-          
+
           ibit8 = REAL( IBITS(advc_flags_m(k,j,i),8,1), KIND = wp )
           ibit7 = REAL( IBITS(advc_flags_m(k,j,i),7,1), KIND = wp )
@@ -2464,8 +2464,8 @@
                    + REAL( IBITS(advc_flags_m(k-1,j,i),7,1), KIND = wp )       &
                    + REAL( IBITS(advc_flags_m(k-1,j,i),8,1), KIND = wp )       &
-                                      )                                        &  
+                                      )                                        &
                   ) * drho_air(k) * ddzw(k)                                    &
-                ) * 0.5_wp                                                     
-                                                                               
+                ) * 0.5_wp
+
           tend(k,j,i) = tend(k,j,i) - (                                        &
                             ( flux_r(k) + diss_r(k)                            &
@@ -2504,5 +2504,5 @@
                   ) *   weight_substep(intermediate_timestep_count)
        ENDDO
-       
+
        DO  k = nzb_max_l+1, nzt
 
@@ -2516,5 +2516,5 @@
                +  ( v_comp(k) + gv  - ( v(k,j,i)   + v(k,j,i-1) ) ) * ddy      &
                +  ( w_comp(k)   * rho_air_zw(k)                                &
-                 -  w_comp(k-1) * rho_air_zw(k-1)                              &  
+                 -  w_comp(k-1) * rho_air_zw(k-1)                              &
                   ) * drho_air(k) * ddzw(k)                                    &
                 ) * 0.5_wp
@@ -2528,5 +2528,5 @@
                           -   ( flux_d    + diss_d    )                        &
                                                     ) * drho_air(k) * ddzw(k)  &
-                                       ) + div * u(k,j,i)
+                                      ) + div * u(k,j,i)
 
           flux_l_u(k,j,tn) = flux_r(k)
@@ -2578,11 +2578,11 @@
        INTEGER(iwp)  ::  k_pp      !< k+2 index in disretization, can be modified to avoid segmentation faults
        INTEGER(iwp)  ::  k_ppp     !< k+3 index in disretization, can be modified to avoid segmentation faults
-       INTEGER(iwp)  ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms  
+       INTEGER(iwp)  ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms
        INTEGER(iwp)  ::  tn        !< number of OpenMP thread
-       
+
        REAL(wp)      ::  ibit9    !< flag indicating 1st-order scheme along x-direction
        REAL(wp)      ::  ibit10   !< flag indicating 3rd-order scheme along x-direction
        REAL(wp)      ::  ibit11   !< flag indicating 5th-order scheme along x-direction
-       REAL(wp)      ::  ibit12   !< flag indicating 1st-order scheme along y-direction 
+       REAL(wp)      ::  ibit12   !< flag indicating 1st-order scheme along y-direction
        REAL(wp)      ::  ibit13   !< flag indicating 3rd-order scheme along y-direction
        REAL(wp)      ::  ibit14   !< flag indicating 3rd-order scheme along y-direction
@@ -2596,5 +2596,5 @@
        REAL(wp)      ::  gv       !< Galilei-transformation velocity along y
        REAL(wp)      ::  v_comp_l !< advection velocity along y on leftmost grid point on subdomain
-       
+
        REAL(wp), DIMENSION(nzb:nzt+1)  ::  diss_n !< discretized artificial dissipation at northward-side of the grid box
        REAL(wp), DIMENSION(nzb:nzt+1)  ::  diss_r !< discretized artificial dissipation at rightward-side of the grid box
@@ -2607,7 +2607,7 @@
        REAL(wp), DIMENSION(nzb:nzt+1)  ::  w_comp !< advection velocity along z
 !
-!--    Used local modified copy of nzb_max (used to degrade order of 
+!--    Used local modified copy of nzb_max (used to degrade order of
 !--    discretization) at non-cyclic boundaries. Modify only at relevant points
-!--    instead of the entire subdomain. This should lead to better 
+!--    instead of the entire subdomain. This should lead to better
 !--    load balance between boundary and non-boundary PEs.
        IF( ( bc_dirichlet_l  .OR.  bc_radiation_l )  .AND.  i <= nxl + 2  .OR. &
@@ -2619,9 +2619,9 @@
           nzb_max_l = nzb_max
        END IF
-       
+
        gu = 2.0_wp * u_gtrans
        gv = 2.0_wp * v_gtrans
 
-!       
+!
 !--    Compute leftside fluxes for the respective boundary.
        IF ( i == i_omp )  THEN
@@ -2634,32 +2634,32 @@
 
              u_comp(k)        = u(k,j-1,i) + u(k,j,i) - gu
-             flux_l_v(k,j,tn) = u_comp(k) * (                                 &
-                              ( 37.0_wp * ibit11 * adv_mom_5                  &
-                           +     7.0_wp * ibit10 * adv_mom_3                  &
-                           +              ibit9  * adv_mom_1                  &
-                              ) *                                             &
-                                        ( v(k,j,i)   + v(k,j,i-1) )           &
-                       -      (  8.0_wp * ibit11 * adv_mom_5                  &
-                           +              ibit10 * adv_mom_3                  &
-                              ) *                                             &
-                                        ( v(k,j,i+1) + v(k,j,i-2) )           &
-                       +      (           ibit11 * adv_mom_5                  &
-                              ) *                                             &
-                                        ( v(k,j,i+2) + v(k,j,i-3) )           &
+             flux_l_v(k,j,tn) = u_comp(k) * (                                  &
+                              ( 37.0_wp * ibit11 * adv_mom_5                   &
+                           +     7.0_wp * ibit10 * adv_mom_3                   &
+                           +              ibit9  * adv_mom_1                   &
+                              ) *                                              &
+                                        ( v(k,j,i)   + v(k,j,i-1) )            &
+                       -      (  8.0_wp * ibit11 * adv_mom_5                   &
+                           +              ibit10 * adv_mom_3                   &
+                              ) *                                              &
+                                        ( v(k,j,i+1) + v(k,j,i-2) )            &
+                       +      (           ibit11 * adv_mom_5                   &
+                              ) *                                              &
+                                        ( v(k,j,i+2) + v(k,j,i-3) )            &
                                             )
 
-             diss_l_v(k,j,tn) = - ABS( u_comp(k) ) * (                        &
-                              ( 10.0_wp * ibit11 * adv_mom_5                  &
-                           +     3.0_wp * ibit10 * adv_mom_3                  &
-                           +              ibit9  * adv_mom_1                  &
-                              ) *                                             &
-                                        ( v(k,j,i)   - v(k,j,i-1) )           &
-                       -      (  5.0_wp * ibit11 * adv_mom_5                  &
-                           +              ibit10 * adv_mom_3                  &
-                              ) *                                             &
-                                        ( v(k,j,i+1) - v(k,j,i-2) )           &
-                       +      (           ibit11 * adv_mom_5                  &
-                              ) *                                             &
-                                        ( v(k,j,i+2) - v(k,j,i-3) )           &
+             diss_l_v(k,j,tn) = - ABS( u_comp(k) ) * (                         &
+                              ( 10.0_wp * ibit11 * adv_mom_5                   &
+                           +     3.0_wp * ibit10 * adv_mom_3                   &
+                           +              ibit9  * adv_mom_1                   &
+                              ) *                                              &
+                                        ( v(k,j,i)   - v(k,j,i-1) )            &
+                       -      (  5.0_wp * ibit11 * adv_mom_5                   &
+                           +              ibit10 * adv_mom_3                   &
+                              ) *                                              &
+                                        ( v(k,j,i+1) - v(k,j,i-2) )            &
+                       +      (           ibit11 * adv_mom_5                   &
+                              ) *                                              &
+                                        ( v(k,j,i+2) - v(k,j,i-3) )            &
                                                      )
 
@@ -2669,20 +2669,20 @@
 
              u_comp(k)        = u(k,j-1,i) + u(k,j,i) - gu
-             flux_l_v(k,j,tn) = u_comp(k) * (                                 &
-                             37.0_wp * ( v(k,j,i)   + v(k,j,i-1)   )          &
-                           -  8.0_wp * ( v(k,j,i+1) + v(k,j,i-2) )            &
+             flux_l_v(k,j,tn) = u_comp(k) * (                                  &
+                             37.0_wp * ( v(k,j,i)   + v(k,j,i-1)   )           &
+                           -  8.0_wp * ( v(k,j,i+1) + v(k,j,i-2) )             &
                            +           ( v(k,j,i+2) + v(k,j,i-3) ) ) * adv_mom_5
-             diss_l_v(k,j,tn) = - ABS( u_comp(k) ) * (                        &
-                             10.0_wp * ( v(k,j,i)   - v(k,j,i-1)   )          &
-                           -  5.0_wp * ( v(k,j,i+1) - v(k,j,i-2) )            &
+             diss_l_v(k,j,tn) = - ABS( u_comp(k) ) * (                         &
+                             10.0_wp * ( v(k,j,i)   - v(k,j,i-1)   )           &
+                           -  5.0_wp * ( v(k,j,i+1) - v(k,j,i-2) )             &
                            +           ( v(k,j,i+2) - v(k,j,i-3) ) ) * adv_mom_5
 
           ENDDO
-          
+
        ENDIF
 !
 !--    Compute southside fluxes for the respective boundary.
        IF ( j == nysv )  THEN
-       
+
           DO  k = nzb+1, nzb_max_l
 
@@ -2692,32 +2692,32 @@
 
              v_comp_l       = v(k,j,i) + v(k,j-1,i) - gv
-             flux_s_v(k,tn) = v_comp_l * (                                    &
-                            ( 37.0_wp * ibit14 * adv_mom_5                    &
-                         +     7.0_wp * ibit13 * adv_mom_3                    &
-                         +              ibit12 * adv_mom_1                    &
-                            ) *                                               &
-                                        ( v(k,j,i)   + v(k,j-1,i) )           &
-                     -      (  8.0_wp * ibit14 * adv_mom_5                    &
-                         +              ibit13 * adv_mom_3                    &
-                            ) *                                               &
-                                        ( v(k,j+1,i) + v(k,j-2,i) )           &
-                     +      (           ibit14 * adv_mom_5                    &
-                            ) *                                               &
-                                        ( v(k,j+2,i) + v(k,j-3,i) )           &
+             flux_s_v(k,tn) = v_comp_l * (                                     &
+                            ( 37.0_wp * ibit14 * adv_mom_5                     &
+                         +     7.0_wp * ibit13 * adv_mom_3                     &
+                         +              ibit12 * adv_mom_1                     &
+                            ) *                                                &
+                                        ( v(k,j,i)   + v(k,j-1,i) )            &
+                     -      (  8.0_wp * ibit14 * adv_mom_5                     &
+                         +              ibit13 * adv_mom_3                     &
+                            ) *                                                &
+                                        ( v(k,j+1,i) + v(k,j-2,i) )            &
+                     +      (           ibit14 * adv_mom_5                     &
+                            ) *                                                &
+                                        ( v(k,j+2,i) + v(k,j-3,i) )            &
                                          )
 
-             diss_s_v(k,tn) = - ABS( v_comp_l ) * (                           &
-                            ( 10.0_wp * ibit14 * adv_mom_5                    &
-                         +     3.0_wp * ibit13 * adv_mom_3                    &
-                         +              ibit12 * adv_mom_1                    &
-                            ) *                                               &
-                                        ( v(k,j,i)   - v(k,j-1,i) )           &
-                     -      (  5.0_wp * ibit14 * adv_mom_5                    &
-                         +              ibit13 * adv_mom_3                    &
-                            ) *                                               &
-                                        ( v(k,j+1,i) - v(k,j-2,i) )           &
-                     +      (           ibit14 * adv_mom_5                    &
-                            ) *                                               &
-                                        ( v(k,j+2,i) - v(k,j-3,i) )           &
+             diss_s_v(k,tn) = - ABS( v_comp_l ) * (                            &
+                            ( 10.0_wp * ibit14 * adv_mom_5                     &
+                         +     3.0_wp * ibit13 * adv_mom_3                     &
+                         +              ibit12 * adv_mom_1                     &
+                            ) *                                                &
+                                        ( v(k,j,i)   - v(k,j-1,i) )            &
+                     -      (  5.0_wp * ibit14 * adv_mom_5                     &
+                         +              ibit13 * adv_mom_3                     &
+                            ) *                                                &
+                                        ( v(k,j+1,i) - v(k,j-2,i) )            &
+                     +      (           ibit14 * adv_mom_5                     &
+                            ) *                                                &
+                                        ( v(k,j+2,i) - v(k,j-3,i) )            &
                                                   )
 
@@ -2727,15 +2727,15 @@
 
              v_comp_l       = v(k,j,i) + v(k,j-1,i) - gv
-             flux_s_v(k,tn) = v_comp_l * (                                    &
-                           37.0_wp * ( v(k,j,i)   + v(k,j-1,i)   )            &
-                         -  8.0_wp * ( v(k,j+1,i) + v(k,j-2,i) )              &
+             flux_s_v(k,tn) = v_comp_l * (                                     &
+                           37.0_wp * ( v(k,j,i)   + v(k,j-1,i)   )             &
+                         -  8.0_wp * ( v(k,j+1,i) + v(k,j-2,i) )               &
                          +           ( v(k,j+2,i) + v(k,j-3,i) ) ) * adv_mom_5
-             diss_s_v(k,tn) = - ABS( v_comp_l ) * (                           &
-                           10.0_wp * ( v(k,j,i)   - v(k,j-1,i)   )            &
-                         -  5.0_wp * ( v(k,j+1,i) - v(k,j-2,i) )              &
+             diss_s_v(k,tn) = - ABS( v_comp_l ) * (                            &
+                           10.0_wp * ( v(k,j,i)   - v(k,j-1,i)   )             &
+                         -  5.0_wp * ( v(k,j+1,i) - v(k,j-2,i) )               &
                          +           ( v(k,j+2,i) - v(k,j-3,i) ) ) * adv_mom_5
 
           ENDDO
-          
+
        ENDIF
 !
@@ -2747,34 +2747,34 @@
           ibit10 = REAL( IBITS(advc_flags_m(k,j,i),10,1), KIND = wp )
           ibit9  = REAL( IBITS(advc_flags_m(k,j,i),9,1),  KIND = wp )
- 
+
           u_comp(k) = u(k,j-1,i+1) + u(k,j,i+1) - gu
-          flux_r(k) = u_comp(k) * (                                           &
-                     ( 37.0_wp * ibit11 * adv_mom_5                           &
-                  +     7.0_wp * ibit10 * adv_mom_3                           &
-                  +              ibit9  * adv_mom_1                           &
-                     ) *                                                      &
-                                    ( v(k,j,i+1) + v(k,j,i)   )               &
-              -      (  8.0_wp * ibit11 * adv_mom_5                           &
-                  +              ibit10 * adv_mom_3                           &
-                     ) *                                                      &
-                                    ( v(k,j,i+2) + v(k,j,i-1) )               &
-              +      (           ibit11 * adv_mom_5                           &
-                     ) *                                                      &
-                                    ( v(k,j,i+3) + v(k,j,i-2) )               &
+          flux_r(k) = u_comp(k) * (                                            &
+                     ( 37.0_wp * ibit11 * adv_mom_5                            &
+                  +     7.0_wp * ibit10 * adv_mom_3                            &
+                  +              ibit9  * adv_mom_1                            &
+                     ) *                                                       &
+                                    ( v(k,j,i+1) + v(k,j,i)   )                &
+              -      (  8.0_wp * ibit11 * adv_mom_5                            &
+                  +              ibit10 * adv_mom_3                            &
+                     ) *                                                       &
+                                    ( v(k,j,i+2) + v(k,j,i-1) )                &
+              +      (           ibit11 * adv_mom_5                            &
+                     ) *                                                       &
+                                    ( v(k,j,i+3) + v(k,j,i-2) )                &
                                   )
 
-          diss_r(k) = - ABS( u_comp(k) ) * (                                  &
-                     ( 10.0_wp * ibit11 * adv_mom_5                           &
-                  +     3.0_wp * ibit10 * adv_mom_3                           &
-                  +              ibit9  * adv_mom_1                           &
-                     ) *                                                      &
-                                    ( v(k,j,i+1) - v(k,j,i)  )                &
-              -      (  5.0_wp * ibit11 * adv_mom_5                           &
-                  +              ibit10 * adv_mom_3                           &
-                     ) *                                                      &
-                                    ( v(k,j,i+2) - v(k,j,i-1) )               &
-              +      (           ibit11 * adv_mom_5                           &
-                     ) *                                                      &
-                                    ( v(k,j,i+3) - v(k,j,i-2) )               &
+          diss_r(k) = - ABS( u_comp(k) ) * (                                   &
+                     ( 10.0_wp * ibit11 * adv_mom_5                            &
+                  +     3.0_wp * ibit10 * adv_mom_3                            &
+                  +              ibit9  * adv_mom_1                            &
+                     ) *                                                       &
+                                    ( v(k,j,i+1) - v(k,j,i)  )                 &
+              -      (  5.0_wp * ibit11 * adv_mom_5                            &
+                  +              ibit10 * adv_mom_3                            &
+                     ) *                                                       &
+                                    ( v(k,j,i+2) - v(k,j,i-1) )                &
+              +      (           ibit11 * adv_mom_5                            &
+                     ) *                                                       &
+                                    ( v(k,j,i+3) - v(k,j,i-2) )                &
                                            )
 
@@ -2785,32 +2785,32 @@
 
           v_comp(k) = v(k,j+1,i) + v(k,j,i)
-          flux_n(k) = ( v_comp(k) - gv ) * (                                  &
-                     ( 37.0_wp * ibit14 * adv_mom_5                           &
-                  +     7.0_wp * ibit13 * adv_mom_3                           &
-                  +              ibit12 * adv_mom_1                           &
-                     ) *                                                      &
-                                    ( v(k,j+1,i) + v(k,j,i)   )               &
-              -      (  8.0_wp * ibit14 * adv_mom_5                           &
-                  +              ibit13 * adv_mom_3                           &
-                     ) *                                                      &
-                                    ( v(k,j+2,i) + v(k,j-1,i) )               &
-              +      (           ibit14 * adv_mom_5                           &
-                     ) *                                                      &
-                                    ( v(k,j+3,i) + v(k,j-2,i) )               &
+          flux_n(k) = ( v_comp(k) - gv ) * (                                   &
+                     ( 37.0_wp * ibit14 * adv_mom_5                            &
+                  +     7.0_wp * ibit13 * adv_mom_3                            &
+                  +              ibit12 * adv_mom_1                            &
+                     ) *                                                       &
+                                    ( v(k,j+1,i) + v(k,j,i)   )                &
+              -      (  8.0_wp * ibit14 * adv_mom_5                            &
+                  +              ibit13 * adv_mom_3                            &
+                     ) *                                                       &
+                                    ( v(k,j+2,i) + v(k,j-1,i) )                &
+              +      (           ibit14 * adv_mom_5                            &
+                     ) *                                                       &
+                                    ( v(k,j+3,i) + v(k,j-2,i) )                &
                                            )
 
-          diss_n(k) = - ABS( v_comp(k) - gv ) * (                             &
-                     ( 10.0_wp * ibit14 * adv_mom_5                           &
-                  +     3.0_wp * ibit13 * adv_mom_3                           &
-                  +              ibit12 * adv_mom_1                           &
-                     ) *                                                      &
-                                    ( v(k,j+1,i) - v(k,j,i)   )               &
-              -      (  5.0_wp * ibit14 * adv_mom_5                           &
-                  +              ibit13 * adv_mom_3                           &
-                     ) *                                                      &
-                                    ( v(k,j+2,i) - v(k,j-1,i) )               &
-              +      (           ibit14 * adv_mom_5                           &
-                     ) *                                                      &
-                                    ( v(k,j+3,i) - v(k,j-2,i) )               &
+          diss_n(k) = - ABS( v_comp(k) - gv ) * (                              &
+                     ( 10.0_wp * ibit14 * adv_mom_5                            &
+                  +     3.0_wp * ibit13 * adv_mom_3                            &
+                  +              ibit12 * adv_mom_1                            &
+                     ) *                                                       &
+                                    ( v(k,j+1,i) - v(k,j,i)   )                &
+              -      (  5.0_wp * ibit14 * adv_mom_5                            &
+                  +              ibit13 * adv_mom_3                            &
+                     ) *                                                       &
+                                    ( v(k,j+2,i) - v(k,j-1,i) )                &
+              +      (           ibit14 * adv_mom_5                            &
+                     ) *                                                       &
+                                    ( v(k,j+3,i) - v(k,j-2,i) )                &
                                                 )
        ENDDO
@@ -2819,32 +2819,32 @@
 
           u_comp(k) = u(k,j-1,i+1) + u(k,j,i+1) - gu
-          flux_r(k) = u_comp(k) * (                                           &
-                      37.0_wp * ( v(k,j,i+1) + v(k,j,i)   )                   &
-                    -  8.0_wp * ( v(k,j,i+2) + v(k,j,i-1) )                   &
+          flux_r(k) = u_comp(k) * (                                            &
+                      37.0_wp * ( v(k,j,i+1) + v(k,j,i)   )                    &
+                    -  8.0_wp * ( v(k,j,i+2) + v(k,j,i-1) )                    &
                     +           ( v(k,j,i+3) + v(k,j,i-2) ) ) * adv_mom_5
 
-          diss_r(k) = - ABS( u_comp(k) ) * (                                  &
-                      10.0_wp * ( v(k,j,i+1) - v(k,j,i) )                     &
-                    -  5.0_wp * ( v(k,j,i+2) - v(k,j,i-1) )                   &
+          diss_r(k) = - ABS( u_comp(k) ) * (                                   &
+                      10.0_wp * ( v(k,j,i+1) - v(k,j,i) )                      &
+                    -  5.0_wp * ( v(k,j,i+2) - v(k,j,i-1) )                    &
                     +           ( v(k,j,i+3) - v(k,j,i-2) ) ) * adv_mom_5
 
 
           v_comp(k) = v(k,j+1,i) + v(k,j,i)
-          flux_n(k) = ( v_comp(k) - gv ) * (                                  &
-                      37.0_wp * ( v(k,j+1,i) + v(k,j,i)   )                   &
-                    -  8.0_wp * ( v(k,j+2,i) + v(k,j-1,i) )                   &
+          flux_n(k) = ( v_comp(k) - gv ) * (                                   &
+                      37.0_wp * ( v(k,j+1,i) + v(k,j,i)   )                    &
+                    -  8.0_wp * ( v(k,j+2,i) + v(k,j-1,i) )                    &
                       +         ( v(k,j+3,i) + v(k,j-2,i) ) ) * adv_mom_5
 
-          diss_n(k) = - ABS( v_comp(k) - gv ) * (                             &
-                      10.0_wp * ( v(k,j+1,i) - v(k,j,i)   )                   &
-                    -  5.0_wp * ( v(k,j+2,i) - v(k,j-1,i) )                   &
+          diss_n(k) = - ABS( v_comp(k) - gv ) * (                              &
+                      10.0_wp * ( v(k,j+1,i) - v(k,j,i)   )                    &
+                    -  5.0_wp * ( v(k,j+2,i) - v(k,j-1,i) )                    &
                     +           ( v(k,j+3,i) - v(k,j-2,i) ) ) * adv_mom_5
        ENDDO
 !
-!--    Now, compute vertical fluxes. Split loop into a part treating the 
+!--    Now, compute vertical fluxes. Split loop into a part treating the
 !--    lowest grid points with indirect indexing, a main loop without
 !--    indirect indexing, and a loop for the uppermost grip points with
 !--    indirect indexing. This allows better vectorization for the main loop.
-!--    First, compute the flux at model surface, which need has to be 
+!--    First, compute the flux at model surface, which need has to be
 !--    calculated explicitly for the tendency at
 !--    the first w-level. For topography wall this is done implicitely by
@@ -2853,5 +2853,5 @@
        diss_t(nzb) = 0.0_wp
        w_comp(nzb) = 0.0_wp
-       
+
        DO  k = nzb+1, nzb+1
 !
@@ -2867,35 +2867,35 @@
 
           w_comp(k) = w(k,j-1,i) + w(k,j,i)
-          flux_t(k) = w_comp(k) * rho_air_zw(k) * (                           &
-                     ( 37.0_wp * ibit17 * adv_mom_5                           &
-                  +     7.0_wp * ibit16 * adv_mom_3                           &
-                  +              ibit15 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( v(k+1,j,i)   + v(k,j,i)    )                &
-              -      (  8.0_wp * ibit17 * adv_mom_5                           &
-                  +              ibit16 * adv_mom_3                           &
-                     ) *                                                      &
-                                ( v(k_pp,j,i)  + v(k-1,j,i)  )                &
-              +      (           ibit17 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( v(k_ppp,j,i) + v(k_mm,j,i) )                &
+          flux_t(k) = w_comp(k) * rho_air_zw(k) * (                            &
+                     ( 37.0_wp * ibit17 * adv_mom_5                            &
+                  +     7.0_wp * ibit16 * adv_mom_3                            &
+                  +              ibit15 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( v(k+1,j,i)   + v(k,j,i)    )                 &
+              -      (  8.0_wp * ibit17 * adv_mom_5                            &
+                  +              ibit16 * adv_mom_3                            &
+                     ) *                                                       &
+                                ( v(k_pp,j,i)  + v(k-1,j,i)  )                 &
+              +      (           ibit17 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( v(k_ppp,j,i) + v(k_mm,j,i) )                 &
                                                   )
 
-          diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (                  &
-                     ( 10.0_wp * ibit17 * adv_mom_5                           &
-                  +     3.0_wp * ibit16 * adv_mom_3                           &
-                  +              ibit15 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( v(k+1,j,i)   - v(k,j,i)    )                &
-              -      (  5.0_wp * ibit17 * adv_mom_5                           &
-                  +              ibit16 * adv_mom_3                           &
-                     ) *                                                      &
-                                ( v(k_pp,j,i)  - v(k-1,j,i)  )                &
-              +      (           ibit17 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( v(k_ppp,j,i) - v(k_mm,j,i) )                &
+          diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (                   &
+                     ( 10.0_wp * ibit17 * adv_mom_5                            &
+                  +     3.0_wp * ibit16 * adv_mom_3                            &
+                  +              ibit15 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( v(k+1,j,i)   - v(k,j,i)    )                 &
+              -      (  5.0_wp * ibit17 * adv_mom_5                            &
+                  +              ibit16 * adv_mom_3                            &
+                     ) *                                                       &
+                                ( v(k_pp,j,i)  - v(k-1,j,i)  )                 &
+              +      (           ibit17 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( v(k_ppp,j,i) - v(k_mm,j,i) )                 &
                                                            )
        ENDDO
-       
+
        DO  k = nzb+2, nzt-2
 
@@ -2905,35 +2905,35 @@
 
           w_comp(k) = w(k,j-1,i) + w(k,j,i)
-          flux_t(k) = w_comp(k) * rho_air_zw(k) * (                           &
-                     ( 37.0_wp * ibit17 * adv_mom_5                           &
-                  +     7.0_wp * ibit16 * adv_mom_3                           &
-                  +              ibit15 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( v(k+1,j,i) + v(k,j,i)   )                   &
-              -      (  8.0_wp * ibit17 * adv_mom_5                           &
-                  +              ibit16 * adv_mom_3                           &
-                     ) *                                                      &
-                                ( v(k+2,j,i) + v(k-1,j,i) )                   &
-              +      (           ibit17 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( v(k+3,j,i) + v(k-2,j,i) )                   &
+          flux_t(k) = w_comp(k) * rho_air_zw(k) * (                            &
+                     ( 37.0_wp * ibit17 * adv_mom_5                            &
+                  +     7.0_wp * ibit16 * adv_mom_3                            &
+                  +              ibit15 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( v(k+1,j,i) + v(k,j,i)   )                    &
+              -      (  8.0_wp * ibit17 * adv_mom_5                            &
+                  +              ibit16 * adv_mom_3                            &
+                     ) *                                                       &
+                                ( v(k+2,j,i) + v(k-1,j,i) )                    &
+              +      (           ibit17 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( v(k+3,j,i) + v(k-2,j,i) )                    &
                                                   )
 
-          diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (                  &
-                     ( 10.0_wp * ibit17 * adv_mom_5                           &
-                  +     3.0_wp * ibit16 * adv_mom_3                           &
-                  +              ibit15 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( v(k+1,j,i) - v(k,j,i)   )                   &
-              -      (  5.0_wp * ibit17 * adv_mom_5                           &
-                  +              ibit16 * adv_mom_3                           &
-                     ) *                                                      &
+          diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (                   &
+                     ( 10.0_wp * ibit17 * adv_mom_5                            &
+                  +     3.0_wp * ibit16 * adv_mom_3                            &
+                  +              ibit15 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( v(k+1,j,i) - v(k,j,i)   )                    &
+              -      (  5.0_wp * ibit17 * adv_mom_5                            &
+                  +              ibit16 * adv_mom_3                            &
+                     ) *                                                       &
                                 ( v(k+2,j,i) - v(k-1,j,i) )                    &
-              +      (           ibit17 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( v(k+3,j,i) - v(k-2,j,i) )                   &
+              +      (           ibit17 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( v(k+3,j,i) - v(k-2,j,i) )                    &
                                                            )
        ENDDO
-       
+
        DO  k = nzt-1, nzt-symmetry_flag
 !
@@ -2949,39 +2949,39 @@
 
           w_comp(k) = w(k,j-1,i) + w(k,j,i)
-          flux_t(k) = w_comp(k) * rho_air_zw(k) * (                           &
-                     ( 37.0_wp * ibit17 * adv_mom_5                           &
-                  +     7.0_wp * ibit16 * adv_mom_3                           &
-                  +              ibit15 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( v(k+1,j,i)   + v(k,j,i)    )                &
-              -      (  8.0_wp * ibit17 * adv_mom_5                           &
-                  +              ibit16 * adv_mom_3                           &
-                     ) *                                                      &
-                                ( v(k_pp,j,i)  + v(k-1,j,i)  )                &
-              +      (           ibit17 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( v(k_ppp,j,i) + v(k_mm,j,i) )                &
+          flux_t(k) = w_comp(k) * rho_air_zw(k) * (                            &
+                     ( 37.0_wp * ibit17 * adv_mom_5                            &
+                  +     7.0_wp * ibit16 * adv_mom_3                            &
+                  +              ibit15 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( v(k+1,j,i)   + v(k,j,i)    )                 &
+              -      (  8.0_wp * ibit17 * adv_mom_5                            &
+                  +              ibit16 * adv_mom_3                            &
+                     ) *                                                       &
+                                ( v(k_pp,j,i)  + v(k-1,j,i)  )                 &
+              +      (           ibit17 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( v(k_ppp,j,i) + v(k_mm,j,i) )                 &
                                                   )
 
-          diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (                  &
-                     ( 10.0_wp * ibit17 * adv_mom_5                           &
-                  +     3.0_wp * ibit16 * adv_mom_3                           &
-                  +              ibit15 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( v(k+1,j,i)   - v(k,j,i)    )                &
-              -      (  5.0_wp * ibit17 * adv_mom_5                           &
-                  +              ibit16 * adv_mom_3                           &
-                     ) *                                                      &
-                                ( v(k_pp,j,i)  - v(k-1,j,i)  )                &
-              +      (           ibit17 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( v(k_ppp,j,i) - v(k_mm,j,i) )                &
+          diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (                   &
+                     ( 10.0_wp * ibit17 * adv_mom_5                            &
+                  +     3.0_wp * ibit16 * adv_mom_3                            &
+                  +              ibit15 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( v(k+1,j,i)   - v(k,j,i)    )                 &
+              -      (  5.0_wp * ibit17 * adv_mom_5                            &
+                  +              ibit16 * adv_mom_3                            &
+                     ) *                                                       &
+                                ( v(k_pp,j,i)  - v(k-1,j,i)  )                 &
+              +      (           ibit17 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( v(k_ppp,j,i) - v(k_mm,j,i) )                 &
                                                            )
        ENDDO
-       
+
 !
 !--    Set resolved/turbulent flux at model top to zero (w-level). In case that
 !--    a symmetric behavior between bottom and top shall be guaranteed (closed
-!--    channel flow), the flux at nzt is also set to zero. 
+!--    channel flow), the flux at nzt is also set to zero.
        IF ( symmetry_flag == 1 ) THEN
           flux_t(nzt) = 0.0_wp
@@ -2992,18 +2992,18 @@
        diss_t(nzt+1) = 0.0_wp
        w_comp(nzt+1) = 0.0_wp
-       
+
        DO  k = nzb+1, nzb_max_l
 
           flux_d    = flux_t(k-1)
           diss_d    = diss_t(k-1)
-          
+
           ibit11 = REAL( IBITS(advc_flags_m(k,j,i),11,1), KIND = wp )
           ibit10 = REAL( IBITS(advc_flags_m(k,j,i),10,1), KIND = wp )
           ibit9  = REAL( IBITS(advc_flags_m(k,j,i),9,1),  KIND = wp )
-          
+
           ibit14 = REAL( IBITS(advc_flags_m(k,j,i),14,1), KIND = wp )
           ibit13 = REAL( IBITS(advc_flags_m(k,j,i),13,1), KIND = wp )
           ibit12 = REAL( IBITS(advc_flags_m(k,j,i),12,1), KIND = wp )
-          
+
           ibit17 = REAL( IBITS(advc_flags_m(k,j,i),17,1), KIND = wp )
           ibit16 = REAL( IBITS(advc_flags_m(k,j,i),16,1), KIND = wp )
@@ -3013,40 +3013,40 @@
 !--       correction is needed to overcome numerical instabilities introduced
 !--       by a not sufficient reduction of divergences near topography.
-          div = ( ( ( u_comp(k)     + gu )                                    &
-                                       * ( ibit9 + ibit10 + ibit11 )          &
-                  - ( u(k,j-1,i) + u(k,j,i) )                                 &
-                                       * (                                    &
-                        REAL( IBITS(advc_flags_m(k,j,i-1),9,1),  KIND = wp )  &
-                      + REAL( IBITS(advc_flags_m(k,j,i-1),10,1), KIND = wp )  &
-                      + REAL( IBITS(advc_flags_m(k,j,i-1),11,1), KIND = wp )  &
-                                         )                                    &
-                  ) * ddx                                                     &
-               +  ( v_comp(k)                                                 &
-                                       * ( ibit12 + ibit13 + ibit14 )         &
-                - ( v(k,j,i)     + v(k,j-1,i) )                               &
-                                       * (                                    &
-                        REAL( IBITS(advc_flags_m(k,j-1,i),12,1), KIND = wp )  &
-                      + REAL( IBITS(advc_flags_m(k,j-1,i),13,1), KIND = wp )  &
-                      + REAL( IBITS(advc_flags_m(k,j-1,i),14,1), KIND = wp )  &
-                                         )                                    &
-                  ) * ddy                                                     &
-               +  ( w_comp(k)   * rho_air_zw(k) * ( ibit15 + ibit16 + ibit17 )&
-                -   w_comp(k-1) * rho_air_zw(k-1)                             &
-                                       * (                                    &
-                        REAL( IBITS(advc_flags_m(k-1,j,i),15,1), KIND = wp )  &
-                      + REAL( IBITS(advc_flags_m(k-1,j,i),16,1), KIND = wp )  &
-                      + REAL( IBITS(advc_flags_m(k-1,j,i),17,1), KIND = wp )  &
-                                         )                                    &
-                   ) * drho_air(k) * ddzw(k)                                  &
+          div = ( ( ( u_comp(k)     + gu )                                     &
+                                       * ( ibit9 + ibit10 + ibit11 )           &
+                  - ( u(k,j-1,i) + u(k,j,i) )                                  &
+                                       * (                                     &
+                        REAL( IBITS(advc_flags_m(k,j,i-1),9,1),  KIND = wp )   &
+                      + REAL( IBITS(advc_flags_m(k,j,i-1),10,1), KIND = wp )   &
+                      + REAL( IBITS(advc_flags_m(k,j,i-1),11,1), KIND = wp )   &
+                                         )                                     &
+                  ) * ddx                                                      &
+               +  ( v_comp(k)                                                  &
+                                       * ( ibit12 + ibit13 + ibit14 )          &
+                - ( v(k,j,i)     + v(k,j-1,i) )                                &
+                                       * (                                     &
+                        REAL( IBITS(advc_flags_m(k,j-1,i),12,1), KIND = wp )   &
+                      + REAL( IBITS(advc_flags_m(k,j-1,i),13,1), KIND = wp )   &
+                      + REAL( IBITS(advc_flags_m(k,j-1,i),14,1), KIND = wp )   &
+                                         )                                     &
+                  ) * ddy                                                      &
+               +  ( w_comp(k)   * rho_air_zw(k) * ( ibit15 + ibit16 + ibit17 ) &
+                -   w_comp(k-1) * rho_air_zw(k-1)                              &
+                                       * (                                     &
+                        REAL( IBITS(advc_flags_m(k-1,j,i),15,1), KIND = wp )   &
+                      + REAL( IBITS(advc_flags_m(k-1,j,i),16,1), KIND = wp )   &
+                      + REAL( IBITS(advc_flags_m(k-1,j,i),17,1), KIND = wp )   &
+                                         )                                     &
+                   ) * drho_air(k) * ddzw(k)                                   &
                 ) * 0.5_wp
 
-          tend(k,j,i) = tend(k,j,i) - (                                       &
-                         ( flux_r(k) + diss_r(k)                              &
-                       -   flux_l_v(k,j,tn) - diss_l_v(k,j,tn)   ) * ddx      &
-                       + ( flux_n(k) + diss_n(k)                              &
-                       -   flux_s_v(k,tn) - diss_s_v(k,tn)       ) * ddy      &
-                       + ( ( flux_t(k) + diss_t(k) )                          &
-                       -   ( flux_d    + diss_d    )                          &
-                                                   ) * drho_air(k) * ddzw(k)  &
+          tend(k,j,i) = tend(k,j,i) - (                                        &
+                         ( flux_r(k) + diss_r(k)                               &
+                       -   flux_l_v(k,j,tn) - diss_l_v(k,j,tn)   ) * ddx       &
+                       + ( flux_n(k) + diss_n(k)                               &
+                       -   flux_s_v(k,tn) - diss_s_v(k,tn)       ) * ddy       &
+                       + ( ( flux_t(k) + diss_t(k) )                           &
+                       -   ( flux_d    + diss_d    )                           &
+                                                   ) * drho_air(k) * ddzw(k)   &
                                       ) + v(k,j,i) * div
 
@@ -3078,5 +3078,5 @@
 
        ENDDO
-       
+
        DO  k = nzb_max_l+1, nzt
 
@@ -3152,7 +3152,7 @@
        INTEGER(iwp) ::  k_pp      !< k+2 index in disretization, can be modified to avoid segmentation faults
        INTEGER(iwp) ::  k_ppp     !< k+3 index in disretization, can be modified to avoid segmentation faults
-       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms  
+       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms
        INTEGER(iwp) ::  tn        !< number of OpenMP thread
-       
+
        REAL(wp)    ::  ibit18  !< flag indicating 1st-order scheme along x-direction
        REAL(wp)    ::  ibit19  !< flag indicating 3rd-order scheme along x-direction
@@ -3169,5 +3169,5 @@
        REAL(wp)    ::  gu      !< Galilei-transformation velocity along x
        REAL(wp)    ::  gv      !< Galilei-transformation velocity along y
-       
+
        REAL(wp), DIMENSION(nzb:nzt+1)  ::  diss_n !< discretized artificial dissipation at northward-side of the grid box
        REAL(wp), DIMENSION(nzb:nzt+1)  ::  diss_r !< discretized artificial dissipation at rightward-side of the grid box
@@ -3180,7 +3180,7 @@
        REAL(wp), DIMENSION(nzb:nzt+1)  ::  w_comp !< advection velocity along z
 !
-!--    Used local modified copy of nzb_max (used to degrade order of 
+!--    Used local modified copy of nzb_max (used to degrade order of
 !--    discretization) at non-cyclic boundaries. Modify only at relevant points
-!--    instead of the entire subdomain. This should lead to better 
+!--    instead of the entire subdomain. This should lead to better
 !--    load balance between boundary and non-boundary PEs.
        IF( ( bc_dirichlet_l  .OR.  bc_radiation_l )  .AND.  i <= nxl + 2  .OR. &
@@ -3192,5 +3192,5 @@
           nzb_max_l = nzb_max
        END IF
-       
+
        gu = 2.0_wp * u_gtrans
        gv = 2.0_wp * v_gtrans
@@ -3205,32 +3205,32 @@
 
              v_comp(k)      = v(k+1,j,i) + v(k,j,i) - gv
-             flux_s_w(k,tn) = v_comp(k) * (                                   &
-                            ( 37.0_wp * ibit23 * adv_mom_5                    &
-                         +     7.0_wp * ibit22 * adv_mom_3                    &
-                         +              ibit21 * adv_mom_1                    &
-                            ) *                                               &
-                                        ( w(k,j,i)   + w(k,j-1,i) )           &
-                     -      (  8.0_wp * ibit23 * adv_mom_5                    &
-                         +              ibit22 * adv_mom_3                    &
-                            ) *                                               &
-                                        ( w(k,j+1,i) + w(k,j-2,i) )           &
-                     +      (           ibit23 * adv_mom_5                    &
-                            ) *                                               &
-                                        ( w(k,j+2,i) + w(k,j-3,i) )           &
+             flux_s_w(k,tn) = v_comp(k) * (                                    &
+                            ( 37.0_wp * ibit23 * adv_mom_5                     &
+                         +     7.0_wp * ibit22 * adv_mom_3                     &
+                         +              ibit21 * adv_mom_1                     &
+                            ) *                                                &
+                                        ( w(k,j,i)   + w(k,j-1,i) )            &
+                     -      (  8.0_wp * ibit23 * adv_mom_5                     &
+                         +              ibit22 * adv_mom_3                     &
+                            ) *                                                &
+                                        ( w(k,j+1,i) + w(k,j-2,i) )            &
+                     +      (           ibit23 * adv_mom_5                     &
+                            ) *                                                &
+                                        ( w(k,j+2,i) + w(k,j-3,i) )            &
                                           )
 
-             diss_s_w(k,tn) = - ABS( v_comp(k) ) * (                          &
-                            ( 10.0_wp * ibit23 * adv_mom_5                    &
-                         +     3.0_wp * ibit22 * adv_mom_3                    &
-                         +              ibit21 * adv_mom_1                    &
-                            ) *                                               &
-                                        ( w(k,j,i)   - w(k,j-1,i) )           &
-                     -      (  5.0_wp * ibit23 * adv_mom_5                    &
-                         +              ibit22 * adv_mom_3                    &
-                            ) *                                               &
-                                        ( w(k,j+1,i) - w(k,j-2,i) )           &
-                     +      (           ibit23 * adv_mom_5                    &
-                            ) *                                               &
-                                        ( w(k,j+2,i) - w(k,j-3,i) )           &
+             diss_s_w(k,tn) = - ABS( v_comp(k) ) * (                           &
+                            ( 10.0_wp * ibit23 * adv_mom_5                     &
+                         +     3.0_wp * ibit22 * adv_mom_3                     &
+                         +              ibit21 * adv_mom_1                     &
+                            ) *                                                &
+                                        ( w(k,j,i)   - w(k,j-1,i) )            &
+                     -      (  5.0_wp * ibit23 * adv_mom_5                     &
+                         +              ibit22 * adv_mom_3                     &
+                            ) *                                                &
+                                        ( w(k,j+1,i) - w(k,j-2,i) )            &
+                     +      (           ibit23 * adv_mom_5                     &
+                            ) *                                                &
+                                        ( w(k,j+2,i) - w(k,j-3,i) )            &
                                                    )
 
@@ -3240,11 +3240,11 @@
 
              v_comp(k)      = v(k+1,j,i) + v(k,j,i) - gv
-             flux_s_w(k,tn) = v_comp(k) * (                                   &
-                           37.0_wp * ( w(k,j,i)   + w(k,j-1,i) )              &
-                         -  8.0_wp * ( w(k,j+1,i) + w(k,j-2,i) )              &
+             flux_s_w(k,tn) = v_comp(k) * (                                    &
+                           37.0_wp * ( w(k,j,i)   + w(k,j-1,i) )               &
+                         -  8.0_wp * ( w(k,j+1,i) + w(k,j-2,i) )               &
                          +           ( w(k,j+2,i) + w(k,j-3,i) ) ) * adv_mom_5
-             diss_s_w(k,tn) = - ABS( v_comp(k) ) * (                          &
-                           10.0_wp * ( w(k,j,i)   - w(k,j-1,i) )              &
-                         -  5.0_wp * ( w(k,j+1,i) - w(k,j-2,i) )              &
+             diss_s_w(k,tn) = - ABS( v_comp(k) ) * (                           &
+                           10.0_wp * ( w(k,j,i)   - w(k,j-1,i) )               &
+                         -  5.0_wp * ( w(k,j+1,i) - w(k,j-2,i) )               &
                          +           ( w(k,j+2,i) - w(k,j-3,i) ) ) * adv_mom_5
 
@@ -3263,32 +3263,32 @@
 
              u_comp(k)        = u(k+1,j,i) + u(k,j,i) - gu
-             flux_l_w(k,j,tn) = u_comp(k) * (                                 &
-                             ( 37.0_wp * ibit20 * adv_mom_5                   &
-                          +     7.0_wp * ibit19 * adv_mom_3                   &
-                          +              ibit18 * adv_mom_1                   &
-                             ) *                                              &
-                                        ( w(k,j,i)   + w(k,j,i-1) )           &
-                      -      (  8.0_wp * ibit20 * adv_mom_5                   &
-                          +              ibit19 * adv_mom_3                   &
-                             ) *                                              &
-                                        ( w(k,j,i+1) + w(k,j,i-2) )           &
-                      +      (           ibit20 * adv_mom_5                   &
-                             ) *                                              &
-                                        ( w(k,j,i+2) + w(k,j,i-3) )           &
+             flux_l_w(k,j,tn) = u_comp(k) * (                                  &
+                             ( 37.0_wp * ibit20 * adv_mom_5                    &
+                          +     7.0_wp * ibit19 * adv_mom_3                    &
+                          +              ibit18 * adv_mom_1                    &
+                             ) *                                               &
+                                        ( w(k,j,i)   + w(k,j,i-1) )            &
+                      -      (  8.0_wp * ibit20 * adv_mom_5                    &
+                          +              ibit19 * adv_mom_3                    &
+                             ) *                                               &
+                                        ( w(k,j,i+1) + w(k,j,i-2) )            &
+                      +      (           ibit20 * adv_mom_5                    &
+                             ) *                                               &
+                                        ( w(k,j,i+2) + w(k,j,i-3) )            &
                                             )
 
-             diss_l_w(k,j,tn) = - ABS( u_comp(k) ) * (                        &
-                             ( 10.0_wp * ibit20 * adv_mom_5                   &
-                          +     3.0_wp * ibit19 * adv_mom_3                   &
-                          +              ibit18 * adv_mom_1                   &
-                             ) *                                              &
-                                        ( w(k,j,i)   - w(k,j,i-1) )           &
-                      -      (  5.0_wp * ibit20 * adv_mom_5                   &
-                          +              ibit19 * adv_mom_3                   &
-                             ) *                                              &
-                                        ( w(k,j,i+1) - w(k,j,i-2) )           &
-                      +      (           ibit20 * adv_mom_5                   &
-                             ) *                                              &
-                                        ( w(k,j,i+2) - w(k,j,i-3) )           &
+             diss_l_w(k,j,tn) = - ABS( u_comp(k) ) * (                         &
+                             ( 10.0_wp * ibit20 * adv_mom_5                    &
+                          +     3.0_wp * ibit19 * adv_mom_3                    &
+                          +              ibit18 * adv_mom_1                    &
+                             ) *                                               &
+                                        ( w(k,j,i)   - w(k,j,i-1) )            &
+                      -      (  5.0_wp * ibit20 * adv_mom_5                    &
+                          +              ibit19 * adv_mom_3                    &
+                             ) *                                               &
+                                        ( w(k,j,i+1) - w(k,j,i-2) )            &
+                      +      (           ibit20 * adv_mom_5                    &
+                             ) *                                               &
+                                        ( w(k,j,i+2) - w(k,j,i-3) )            &
                                                      )
 
@@ -3298,12 +3298,12 @@
 
              u_comp(k)        = u(k+1,j,i) + u(k,j,i) - gu
-             flux_l_w(k,j,tn) = u_comp(k) * (                                 &
-                            37.0_wp * ( w(k,j,i)   + w(k,j,i-1) )             &
-                          -  8.0_wp * ( w(k,j,i+1) + w(k,j,i-2) )             &
+             flux_l_w(k,j,tn) = u_comp(k) * (                                  &
+                            37.0_wp * ( w(k,j,i)   + w(k,j,i-1) )              &
+                          -  8.0_wp * ( w(k,j,i+1) + w(k,j,i-2) )              &
                           +           ( w(k,j,i+2) + w(k,j,i-3) ) ) * adv_mom_5
-             diss_l_w(k,j,tn) = - ABS( u_comp(k) ) * (                        &
-                            10.0_wp * ( w(k,j,i)   - w(k,j,i-1) )             &
-                          -  5.0_wp * ( w(k,j,i+1) - w(k,j,i-2) )             &
-                          +           ( w(k,j,i+2) - w(k,j,i-3) ) ) * adv_mom_5 
+             diss_l_w(k,j,tn) = - ABS( u_comp(k) ) * (                         &
+                            10.0_wp * ( w(k,j,i)   - w(k,j,i-1) )              &
+                          -  5.0_wp * ( w(k,j,i+1) - w(k,j,i-2) )              &
+                          +           ( w(k,j,i+2) - w(k,j,i-3) ) ) * adv_mom_5
 
           ENDDO
@@ -3320,32 +3320,32 @@
 
           u_comp(k) = u(k+1,j,i+1) + u(k,j,i+1) - gu
-          flux_r(k) = u_comp(k) * (                                           &
-                     ( 37.0_wp * ibit20 * adv_mom_5                           &
-                  +     7.0_wp * ibit19 * adv_mom_3                           &
-                  +              ibit18 * adv_mom_1                           &
-                     ) *                                                      &
-                                    ( w(k,j,i+1) + w(k,j,i)   )               &
-              -      (  8.0_wp * ibit20 * adv_mom_5                           &
-                  +              ibit19 * adv_mom_3                           &
-                     ) *                                                      &
-                                    ( w(k,j,i+2) + w(k,j,i-1) )               &
-              +      (           ibit20 * adv_mom_5                           &
-                     ) *                                                      &
-                                    ( w(k,j,i+3) + w(k,j,i-2) )               &
+          flux_r(k) = u_comp(k) * (                                            &
+                     ( 37.0_wp * ibit20 * adv_mom_5                            &
+                  +     7.0_wp * ibit19 * adv_mom_3                            &
+                  +              ibit18 * adv_mom_1                            &
+                     ) *                                                       &
+                                    ( w(k,j,i+1) + w(k,j,i)   )                &
+              -      (  8.0_wp * ibit20 * adv_mom_5                            &
+                  +              ibit19 * adv_mom_3                            &
+                     ) *                                                       &
+                                    ( w(k,j,i+2) + w(k,j,i-1) )                &
+              +      (           ibit20 * adv_mom_5                            &
+                     ) *                                                       &
+                                    ( w(k,j,i+3) + w(k,j,i-2) )                &
                                   )
 
-          diss_r(k) = - ABS( u_comp(k) ) * (                                  &
-                     ( 10.0_wp * ibit20 * adv_mom_5                           &
-                  +     3.0_wp * ibit19 * adv_mom_3                           &
-                  +              ibit18 * adv_mom_1                           &
-                     ) *                                                      &
-                                    ( w(k,j,i+1) - w(k,j,i)   )               &
-              -      (  5.0_wp * ibit20 * adv_mom_5                           &
-                  +              ibit19 * adv_mom_3                           &
-                     ) *                                                      &
-                                    ( w(k,j,i+2) - w(k,j,i-1) )               &
-              +      (           ibit20 * adv_mom_5                           &
-                     ) *                                                      &
-                                    ( w(k,j,i+3) - w(k,j,i-2) )               &
+          diss_r(k) = - ABS( u_comp(k) ) * (                                   &
+                     ( 10.0_wp * ibit20 * adv_mom_5                            &
+                  +     3.0_wp * ibit19 * adv_mom_3                            &
+                  +              ibit18 * adv_mom_1                            &
+                     ) *                                                       &
+                                    ( w(k,j,i+1) - w(k,j,i)   )                &
+              -      (  5.0_wp * ibit20 * adv_mom_5                            &
+                  +              ibit19 * adv_mom_3                            &
+                     ) *                                                       &
+                                    ( w(k,j,i+2) - w(k,j,i-1) )                &
+              +      (           ibit20 * adv_mom_5                            &
+                     ) *                                                       &
+                                    ( w(k,j,i+3) - w(k,j,i-2) )                &
                                            )
 
@@ -3355,32 +3355,32 @@
 
           v_comp(k) = v(k+1,j+1,i) + v(k,j+1,i) - gv
-          flux_n(k) = v_comp(k) * (                                           &
-                     ( 37.0_wp * ibit23 * adv_mom_5                           &
-                  +     7.0_wp * ibit22 * adv_mom_3                           &
-                  +              ibit21 * adv_mom_1                           &
-                     ) *                                                      &
-                                    ( w(k,j+1,i) + w(k,j,i)   )               &
-              -      (  8.0_wp * ibit23 * adv_mom_5                           &
-                  +              ibit22 * adv_mom_3                           &
-                     ) *                                                      &
-                                    ( w(k,j+2,i) + w(k,j-1,i) )               &
-              +      (           ibit23 * adv_mom_5                           &
-                     ) *                                                      &
-                                    ( w(k,j+3,i) + w(k,j-2,i) )               &
+          flux_n(k) = v_comp(k) * (                                            &
+                     ( 37.0_wp * ibit23 * adv_mom_5                            &
+                  +     7.0_wp * ibit22 * adv_mom_3                            &
+                  +              ibit21 * adv_mom_1                            &
+                     ) *                                                       &
+                                    ( w(k,j+1,i) + w(k,j,i)   )                &
+              -      (  8.0_wp * ibit23 * adv_mom_5                            &
+                  +              ibit22 * adv_mom_3                            &
+                     ) *                                                       &
+                                    ( w(k,j+2,i) + w(k,j-1,i) )                &
+              +      (           ibit23 * adv_mom_5                            &
+                     ) *                                                       &
+                                    ( w(k,j+3,i) + w(k,j-2,i) )                &
                                   )
 
-          diss_n(k) = - ABS( v_comp(k) ) * (                                  &
-                     ( 10.0_wp * ibit23 * adv_mom_5                           &
-                  +     3.0_wp * ibit22 * adv_mom_3                           &
-                  +              ibit21 * adv_mom_1                           &
-                     ) *                                                      &
-                                    ( w(k,j+1,i) - w(k,j,i)   )               &
-              -      (  5.0_wp * ibit23 * adv_mom_5                           &
-                  +              ibit22 * adv_mom_3                           &
-                     ) *                                                      &
-                                   ( w(k,j+2,i)  - w(k,j-1,i) )               &
-              +      (           ibit23 * adv_mom_5                           &
-                     ) *                                                      &
-                                   ( w(k,j+3,i)  - w(k,j-2,i) )               &
+          diss_n(k) = - ABS( v_comp(k) ) * (                                   &
+                     ( 10.0_wp * ibit23 * adv_mom_5                            &
+                  +     3.0_wp * ibit22 * adv_mom_3                            &
+                  +              ibit21 * adv_mom_1                            &
+                     ) *                                                       &
+                                    ( w(k,j+1,i) - w(k,j,i)   )                &
+              -      (  5.0_wp * ibit23 * adv_mom_5                            &
+                  +              ibit22 * adv_mom_3                            &
+                     ) *                                                       &
+                                   ( w(k,j+2,i)  - w(k,j-1,i) )                &
+              +      (           ibit23 * adv_mom_5                            &
+                     ) *                                                       &
+                                   ( w(k,j+3,i)  - w(k,j-2,i) )                &
                                            )
        ENDDO
@@ -3389,35 +3389,35 @@
 
           u_comp(k) = u(k+1,j,i+1) + u(k,j,i+1) - gu
-          flux_r(k) = u_comp(k) * (                                           &
-                      37.0_wp * ( w(k,j,i+1) + w(k,j,i)   )                   &
-                    -  8.0_wp * ( w(k,j,i+2) + w(k,j,i-1) )                   &
+          flux_r(k) = u_comp(k) * (                                            &
+                      37.0_wp * ( w(k,j,i+1) + w(k,j,i)   )                    &
+                    -  8.0_wp * ( w(k,j,i+2) + w(k,j,i-1) )                    &
                     +           ( w(k,j,i+3) + w(k,j,i-2) ) ) * adv_mom_5
 
-          diss_r(k) = - ABS( u_comp(k) ) * (                                  &
-                      10.0_wp * ( w(k,j,i+1) - w(k,j,i)   )                   &
-                    -  5.0_wp * ( w(k,j,i+2) - w(k,j,i-1) )                   &
+          diss_r(k) = - ABS( u_comp(k) ) * (                                   &
+                      10.0_wp * ( w(k,j,i+1) - w(k,j,i)   )                    &
+                    -  5.0_wp * ( w(k,j,i+2) - w(k,j,i-1) )                    &
                     +           ( w(k,j,i+3) - w(k,j,i-2) ) ) * adv_mom_5
 
           v_comp(k) = v(k+1,j+1,i) + v(k,j+1,i) - gv
-          flux_n(k) = v_comp(k) * (                                           &
-                      37.0_wp * ( w(k,j+1,i) + w(k,j,i)   )                   &
-                    -  8.0_wp * ( w(k,j+2,i) + w(k,j-1,i) )                   &
+          flux_n(k) = v_comp(k) * (                                            &
+                      37.0_wp * ( w(k,j+1,i) + w(k,j,i)   )                    &
+                    -  8.0_wp * ( w(k,j+2,i) + w(k,j-1,i) )                    &
                     +           ( w(k,j+3,i) + w(k,j-2,i) ) ) * adv_mom_5
 
-          diss_n(k) = - ABS( v_comp(k) ) * (                                  &
-                      10.0_wp * ( w(k,j+1,i) - w(k,j,i)   )                   &
-                    -  5.0_wp * ( w(k,j+2,i) - w(k,j-1,i) )                   &
+          diss_n(k) = - ABS( v_comp(k) ) * (                                   &
+                      10.0_wp * ( w(k,j+1,i) - w(k,j,i)   )                    &
+                    -  5.0_wp * ( w(k,j+2,i) - w(k,j-1,i) )                    &
                     +           ( w(k,j+3,i) - w(k,j-2,i) ) ) * adv_mom_5
        ENDDO
 
 !
-!--    Now, compute vertical fluxes. Split loop into a part treating the 
+!--    Now, compute vertical fluxes. Split loop into a part treating the
 !--    lowest grid points with indirect indexing, a main loop without
 !--    indirect indexing, and a loop for the uppermost grip points with
 !--    indirect indexing. This allows better vectorization for the main loop.
-!--    First, compute the flux at model surface, which need has to be 
+!--    First, compute the flux at model surface, which need has to be
 !--    calculated explicitly for the tendency at
 !--    the first w-level. For topography wall this is done implicitely by
-!--    advc_flags_m.
+!--    advc_flags_m. First, compute flux at lowest level, located at z=dz/2.
        k         = nzb + 1
        w_comp(k) = w(k,j,i) + w(k-1,j,i)
@@ -3426,5 +3426,5 @@
        diss_t(0) = -ABS(w_comp(k)) * rho_air(k)                                &
                  * ( w(k,j,i) - w(k-1,j,i) ) * adv_mom_1
-       
+
        DO  k = nzb+1, nzb+1
 !
@@ -3440,37 +3440,37 @@
 
           w_comp(k) = w(k+1,j,i) + w(k,j,i)
-          flux_t(k) = w_comp(k) * rho_air(k+1) * (                            &
-                     ( 37.0_wp * ibit26 * adv_mom_5                           &
-                  +     7.0_wp * ibit25 * adv_mom_3                           &
-                  +              ibit24 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( w(k+1,j,i)   + w(k,j,i)    )                &
-              -      (  8.0_wp * ibit26 * adv_mom_5                           &
-                  +              ibit25 * adv_mom_3                           &
-                     ) *                                                      &
-                                ( w(k_pp,j,i)  + w(k-1,j,i)  )                &
-              +      (           ibit26 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( w(k_ppp,j,i) + w(k_mm,j,i) )                &
+          flux_t(k) = w_comp(k) * rho_air(k+1) * (                             &
+                     ( 37.0_wp * ibit26 * adv_mom_5                            &
+                  +     7.0_wp * ibit25 * adv_mom_3                            &
+                  +              ibit24 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( w(k+1,j,i)   + w(k,j,i)    )                 &
+              -      (  8.0_wp * ibit26 * adv_mom_5                            &
+                  +              ibit25 * adv_mom_3                            &
+                     ) *                                                       &
+                                ( w(k_pp,j,i)  + w(k-1,j,i)  )                 &
+              +      (           ibit26 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( w(k_ppp,j,i) + w(k_mm,j,i) )                 &
                                                  )
 
-          diss_t(k) = - ABS( w_comp(k) ) * rho_air(k+1) * (                   &
-                     ( 10.0_wp * ibit26 * adv_mom_5                           &
-                  +     3.0_wp * ibit25 * adv_mom_3                           &
-                  +              ibit24 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( w(k+1,j,i)   - w(k,j,i)    )                &
-              -      (  5.0_wp * ibit26 * adv_mom_5                           &
-                  +              ibit25 * adv_mom_3                           &
-                     ) *                                                      &
-                                ( w(k_pp,j,i)  - w(k-1,j,i)  )                &
-              +      (           ibit26 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( w(k_ppp,j,i) - w(k_mm,j,i) )                &
+          diss_t(k) = - ABS( w_comp(k) ) * rho_air(k+1) * (                    &
+                     ( 10.0_wp * ibit26 * adv_mom_5                            &
+                  +     3.0_wp * ibit25 * adv_mom_3                            &
+                  +              ibit24 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( w(k+1,j,i)   - w(k,j,i)    )                 &
+              -      (  5.0_wp * ibit26 * adv_mom_5                            &
+                  +              ibit25 * adv_mom_3                            &
+                     ) *                                                       &
+                                ( w(k_pp,j,i)  - w(k-1,j,i)  )                 &
+              +      (           ibit26 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( w(k_ppp,j,i) - w(k_mm,j,i) )                 &
                                                           )
        ENDDO
-       
+
        DO  k = nzb+2, nzt-2
-       
+
           ibit26 = REAL( IBITS(advc_flags_m(k,j,i),26,1), KIND = wp )
           ibit25 = REAL( IBITS(advc_flags_m(k,j,i),25,1), KIND = wp )
@@ -3478,35 +3478,35 @@
 
           w_comp(k) = w(k+1,j,i) + w(k,j,i)
-          flux_t(k) = w_comp(k) * rho_air(k+1) * (                            &
-                     ( 37.0_wp * ibit26 * adv_mom_5                           &
-                  +     7.0_wp * ibit25 * adv_mom_3                           &
-                  +              ibit24 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( w(k+1,j,i)  + w(k,j,i)   )                  &
-              -      (  8.0_wp * ibit26 * adv_mom_5                           &
-                  +              ibit25 * adv_mom_3                           &
-                     ) *                                                      &
-                                ( w(k+2,j,i)  + w(k-1,j,i) )                  &
-              +      (           ibit26 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( w(k+3,j,i)  + w(k-2,j,i) )                  &
+          flux_t(k) = w_comp(k) * rho_air(k+1) * (                             &
+                     ( 37.0_wp * ibit26 * adv_mom_5                            &
+                  +     7.0_wp * ibit25 * adv_mom_3                            &
+                  +              ibit24 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( w(k+1,j,i)  + w(k,j,i)   )                   &
+              -      (  8.0_wp * ibit26 * adv_mom_5                            &
+                  +              ibit25 * adv_mom_3                            &
+                     ) *                                                       &
+                                ( w(k+2,j,i)  + w(k-1,j,i) )                   &
+              +      (           ibit26 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( w(k+3,j,i)  + w(k-2,j,i) )                   &
                                                  )
 
-          diss_t(k) = - ABS( w_comp(k) ) * rho_air(k+1) * (                   &
-                     ( 10.0_wp * ibit26 * adv_mom_5                           &
-                  +     3.0_wp * ibit25 * adv_mom_3                           &
-                  +              ibit24 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( w(k+1,j,i) - w(k,j,i)    )                  &
-              -      (  5.0_wp * ibit26 * adv_mom_5                           &
-                  +              ibit25 * adv_mom_3                           &
-                     ) *                                                      &
-                                ( w(k+2,j,i) - w(k-1,j,i)  )                  &
-              +      (           ibit26 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( w(k+3,j,i) - w(k-2,j,i)  )                  &
+          diss_t(k) = - ABS( w_comp(k) ) * rho_air(k+1) * (                    &
+                     ( 10.0_wp * ibit26 * adv_mom_5                            &
+                  +     3.0_wp * ibit25 * adv_mom_3                            &
+                  +              ibit24 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( w(k+1,j,i) - w(k,j,i)    )                   &
+              -      (  5.0_wp * ibit26 * adv_mom_5                            &
+                  +              ibit25 * adv_mom_3                            &
+                     ) *                                                       &
+                                ( w(k+2,j,i) - w(k-1,j,i)  )                   &
+              +      (           ibit26 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( w(k+3,j,i) - w(k-2,j,i)  )                   &
                                                           )
        ENDDO
-       
+
        DO  k = nzt-1, nzt-1
 !
@@ -3522,37 +3522,37 @@
 
           w_comp(k) = w(k+1,j,i) + w(k,j,i)
-          flux_t(k) = w_comp(k) * rho_air(k+1) * (                            &
-                     ( 37.0_wp * ibit26 * adv_mom_5                           &
-                  +     7.0_wp * ibit25 * adv_mom_3                           &
-                  +              ibit24 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( w(k+1,j,i)   + w(k,j,i)    )                &
-              -      (  8.0_wp * ibit26 * adv_mom_5                           &
-                  +              ibit25 * adv_mom_3                           &
-                     ) *                                                      &
-                                ( w(k_pp,j,i)  + w(k-1,j,i)  )                &
-              +      (           ibit26 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( w(k_ppp,j,i) + w(k_mm,j,i) )                &
+          flux_t(k) = w_comp(k) * rho_air(k+1) * (                             &
+                     ( 37.0_wp * ibit26 * adv_mom_5                            &
+                  +     7.0_wp * ibit25 * adv_mom_3                            &
+                  +              ibit24 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( w(k+1,j,i)   + w(k,j,i)    )                 &
+              -      (  8.0_wp * ibit26 * adv_mom_5                            &
+                  +              ibit25 * adv_mom_3                            &
+                     ) *                                                       &
+                                ( w(k_pp,j,i)  + w(k-1,j,i)  )                 &
+              +      (           ibit26 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( w(k_ppp,j,i) + w(k_mm,j,i) )                 &
                                                  )
 
-          diss_t(k) = - ABS( w_comp(k) ) * rho_air(k+1) * (                   &
-                     ( 10.0_wp * ibit26 * adv_mom_5                           &
-                  +     3.0_wp * ibit25 * adv_mom_3                           &
-                  +              ibit24 * adv_mom_1                           &
-                     ) *                                                      &
-                                ( w(k+1,j,i)   - w(k,j,i)    )                &
-              -      (  5.0_wp * ibit26 * adv_mom_5                           &
-                  +              ibit25 * adv_mom_3                           &
-                     ) *                                                      &
-                                ( w(k_pp,j,i)  - w(k-1,j,i)  )                &
-              +      (           ibit26 * adv_mom_5                           &
-                     ) *                                                      &
-                                ( w(k_ppp,j,i) - w(k_mm,j,i) )                &
+          diss_t(k) = - ABS( w_comp(k) ) * rho_air(k+1) * (                    &
+                     ( 10.0_wp * ibit26 * adv_mom_5                            &
+                  +     3.0_wp * ibit25 * adv_mom_3                            &
+                  +              ibit24 * adv_mom_1                            &
+                     ) *                                                       &
+                                ( w(k+1,j,i)   - w(k,j,i)    )                 &
+              -      (  5.0_wp * ibit26 * adv_mom_5                            &
+                  +              ibit25 * adv_mom_3                            &
+                     ) *                                                       &
+                                ( w(k_pp,j,i)  - w(k-1,j,i)  )                 &
+              +      (           ibit26 * adv_mom_5                            &
+                     ) *                                                       &
+                                ( w(k_ppp,j,i) - w(k_mm,j,i) )                 &
                                                           )
        ENDDO
-       
-!
-!--    Set resolved/turbulent flux at model top to zero (w-level). Hint: The 
+
+!
+!--    Set resolved/turbulent flux at model top to zero (w-level). Hint: The
 !--    flux at nzt is defined at the scalar grid point nzt+1. Therefore, the
 !--    flux at nzt+1 is already outside of the model domain
@@ -3560,22 +3560,22 @@
        diss_t(nzt) = 0.0_wp
        w_comp(nzt) = 0.0_wp
-       
+
        flux_t(nzt+1) = 0.0_wp
        diss_t(nzt+1) = 0.0_wp
        w_comp(nzt+1) = 0.0_wp
-       
+
        DO  k = nzb+1, nzb_max_l
 
           flux_d    = flux_t(k-1)
           diss_d    = diss_t(k-1)
-          
+
           ibit20 = REAL( IBITS(advc_flags_m(k,j,i),20,1), KIND = wp )
           ibit19 = REAL( IBITS(advc_flags_m(k,j,i),19,1), KIND = wp )
           ibit18 = REAL( IBITS(advc_flags_m(k,j,i),18,1), KIND = wp )
-          
+
           ibit23 = REAL( IBITS(advc_flags_m(k,j,i),23,1), KIND = wp )
           ibit22 = REAL( IBITS(advc_flags_m(k,j,i),22,1), KIND = wp )
           ibit21 = REAL( IBITS(advc_flags_m(k,j,i),21,1), KIND = wp )
-          
+
           ibit26 = REAL( IBITS(advc_flags_m(k,j,i),26,1), KIND = wp )
           ibit25 = REAL( IBITS(advc_flags_m(k,j,i),25,1), KIND = wp )
@@ -3585,70 +3585,28 @@
 !--       correction is needed to overcome numerical instabilities introduced
 !--       by a not sufficient reduction of divergences near topography.
-          div = ( ( ( u_comp(k) + gu ) * ( ibit18 + ibit19 + ibit20 )         &
-                  - ( u(k+1,j,i) + u(k,j,i)   )                               & 
-                                    * (                                       &
-                     REAL( IBITS(advc_flags_m(k,j,i-1),18,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k,j,i-1),19,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k,j,i-1),20,1), KIND = wp )     &
-                                      )                                       &
-                  ) * ddx                                                     &
-              +   ( ( v_comp(k) + gv ) * ( ibit21 + ibit22 + ibit23 )         & 
-                  - ( v(k+1,j,i) + v(k,j,i)   )                               &
-                                    * (                                       &
-                     REAL( IBITS(advc_flags_m(k,j-1,i),21,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k,j-1,i),22,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k,j-1,i),23,1), KIND = wp )     &
-                                      )                                       &
-                  ) * ddy                                                     &
-              +   ( w_comp(k)               * rho_air(k+1)                    &
-                                            * ( ibit24 + ibit25 + ibit26 )    &
-                - ( w(k,j,i) + w(k-1,j,i) ) * rho_air(k)                      &
-                                    * (                                       &
-                     REAL( IBITS(advc_flags_m(k-1,j,i),24,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k-1,j,i),25,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k-1,j,i),26,1), KIND = wp )     &
-                                      )                                       & 
-                  ) * drho_air_zw(k) * ddzu(k+1)                              &
-                ) * 0.5_wp
-
-          tend(k,j,i) = tend(k,j,i) - (                                       &
-                      ( flux_r(k) + diss_r(k)                                 &
-                    -   flux_l_w(k,j,tn) - diss_l_w(k,j,tn)   ) * ddx         &
-                    + ( flux_n(k) + diss_n(k)                                 &
-                    -   flux_s_w(k,tn) - diss_s_w(k,tn)       ) * ddy         &
-                    + ( ( flux_t(k) + diss_t(k) )                             &
-                    -   ( flux_d    + diss_d    )                             &
-                                              ) * drho_air_zw(k) * ddzu(k+1)  &
-                                      ) + div * w(k,j,i)
-
-          flux_l_w(k,j,tn) = flux_r(k)
-          diss_l_w(k,j,tn) = diss_r(k)
-          flux_s_w(k,tn)   = flux_n(k)
-          diss_s_w(k,tn)   = diss_n(k)
-!
-!--       Statistical Evaluation of w'w'.
-          sums_ws2_ws_l(k,tn)  = sums_ws2_ws_l(k,tn)                          &
-                      + ( flux_t(k)                                           &
-                       * ( w_comp(k) - 2.0_wp * hom(k,1,3,0)                ) &
-                       / ( w_comp(k) + SIGN( 1.0E-20_wp, w_comp(k) )        ) &
-                        + diss_t(k)                                           &
-                       *   ABS( w_comp(k) - 2.0_wp * hom(k,1,3,0)           ) &
-                       / ( ABS( w_comp(k) ) + 1.0E-20_wp                    ) &
-                        ) *   weight_substep(intermediate_timestep_count)
-
-       ENDDO
-       
-       DO  k = nzb_max_l+1, nzt-1
-
-          flux_d    = flux_t(k-1)
-          diss_d    = diss_t(k-1)
-!
-!--       Calculate the divergence of the velocity field. A respective
-!--       correction is needed to overcome numerical instabilities introduced
-!--       by a not sufficient reduction of divergences near topography.
-          div = ( ( u_comp(k) + gu - ( u(k+1,j,i) + u(k,j,i)   ) ) * ddx       &
-              +   ( v_comp(k) + gv - ( v(k+1,j,i) + v(k,j,i)   ) ) * ddy       &
+          div = ( ( ( u_comp(k) + gu ) * ( ibit18 + ibit19 + ibit20 )          &
+                  - ( u(k+1,j,i) + u(k,j,i)   )                                &
+                                    * (                                        &
+                     REAL( IBITS(advc_flags_m(k,j,i-1),18,1), KIND = wp )      &
+                   + REAL( IBITS(advc_flags_m(k,j,i-1),19,1), KIND = wp )      &
+                   + REAL( IBITS(advc_flags_m(k,j,i-1),20,1), KIND = wp )      &
+                                      )                                        &
+                  ) * ddx                                                      &
+              +   ( ( v_comp(k) + gv ) * ( ibit21 + ibit22 + ibit23 )          &
+                  - ( v(k+1,j,i) + v(k,j,i)   )                                &
+                                    * (                                        &
+                     REAL( IBITS(advc_flags_m(k,j-1,i),21,1), KIND = wp )      &
+                   + REAL( IBITS(advc_flags_m(k,j-1,i),22,1), KIND = wp )      &
+                   + REAL( IBITS(advc_flags_m(k,j-1,i),23,1), KIND = wp )      &
+                                      )                                        &
+                  ) * ddy                                                      &
               +   ( w_comp(k)               * rho_air(k+1)                     &
-                - ( w(k,j,i) + w(k-1,j,i) ) * rho_air(k)                       & 
+                                            * ( ibit24 + ibit25 + ibit26 )     &
+                - ( w(k,j,i) + w(k-1,j,i) ) * rho_air(k)                       &
+                                    * (                                        &
+                     REAL( IBITS(advc_flags_m(k-1,j,i),24,1), KIND = wp )      &
+                   + REAL( IBITS(advc_flags_m(k-1,j,i),25,1), KIND = wp )      &
+                   + REAL( IBITS(advc_flags_m(k-1,j,i),26,1), KIND = wp )      &
+                                      )                                        &
                   ) * drho_air_zw(k) * ddzu(k+1)                               &
                 ) * 0.5_wp
@@ -3681,6 +3639,48 @@
        ENDDO
 
+       DO  k = nzb_max_l+1, nzt-1
+
+          flux_d    = flux_t(k-1)
+          diss_d    = diss_t(k-1)
+!
+!--       Calculate the divergence of the velocity field. A respective
+!--       correction is needed to overcome numerical instabilities introduced
+!--       by a not sufficient reduction of divergences near topography.
+          div = ( ( u_comp(k) + gu - ( u(k+1,j,i) + u(k,j,i)   ) ) * ddx       &
+              +   ( v_comp(k) + gv - ( v(k+1,j,i) + v(k,j,i)   ) ) * ddy       &
+              +   ( w_comp(k)               * rho_air(k+1)                     &
+                - ( w(k,j,i) + w(k-1,j,i) ) * rho_air(k)                       &
+                  ) * drho_air_zw(k) * ddzu(k+1)                               &
+                ) * 0.5_wp
+
+          tend(k,j,i) = tend(k,j,i) - (                                        &
+                      ( flux_r(k) + diss_r(k)                                  &
+                    -   flux_l_w(k,j,tn) - diss_l_w(k,j,tn)   ) * ddx          &
+                    + ( flux_n(k) + diss_n(k)                                  &
+                    -   flux_s_w(k,tn) - diss_s_w(k,tn)       ) * ddy          &
+                    + ( ( flux_t(k) + diss_t(k) )                              &
+                    -   ( flux_d    + diss_d    )                              &
+                                              ) * drho_air_zw(k) * ddzu(k+1)   &
+                                      ) + div * w(k,j,i)
+
+          flux_l_w(k,j,tn) = flux_r(k)
+          diss_l_w(k,j,tn) = diss_r(k)
+          flux_s_w(k,tn)   = flux_n(k)
+          diss_s_w(k,tn)   = diss_n(k)
+!
+!--       Statistical Evaluation of w'w'.
+          sums_ws2_ws_l(k,tn)  = sums_ws2_ws_l(k,tn)                           &
+                      + ( flux_t(k)                                            &
+                       * ( w_comp(k) - 2.0_wp * hom(k,1,3,0)                )  &
+                       / ( w_comp(k) + SIGN( 1.0E-20_wp, w_comp(k) )        )  &
+                        + diss_t(k)                                            &
+                       *   ABS( w_comp(k) - 2.0_wp * hom(k,1,3,0)           )  &
+                       / ( ABS( w_comp(k) ) + 1.0E-20_wp                    )  &
+                        ) *   weight_substep(intermediate_timestep_count)
+
+       ENDDO
+
     END SUBROUTINE advec_w_ws_ij
-    
+
 
 !------------------------------------------------------------------------------!
@@ -3694,96 +3694,74 @@
 
 
-       CHARACTER (LEN = *), INTENT(IN)    ::  sk_char !< string identifier, used for assign fluxes to the correct dimension in the analysis array 
-       INTEGER(iwp) ::  sk_num !< integer identifier, used for assign fluxes to the correct dimension in the analysis array
-       
-       INTEGER(iwp) ::  i          !< grid index along x-direction
-       INTEGER(iwp) ::  j          !< grid index along y-direction
-       INTEGER(iwp) ::  k          !< grid index along z-direction
-       INTEGER(iwp) ::  k_mm       !< k-2 index in disretization, can be modified to avoid segmentation faults
-       INTEGER(iwp) ::  k_pp       !< k+2 index in disretization, can be modified to avoid segmentation faults
-       INTEGER(iwp) ::  k_ppp      !< k+3 index in disretization, can be modified to avoid segmentation faults
-       INTEGER(iwp) ::  nzb_max_l  !< index indicating upper bound for order degradation of horizontal advection terms 
-       INTEGER(iwp) ::  tn = 0     !< number of OpenMP thread
-       
+       CHARACTER (LEN = *), INTENT(IN) ::  sk_char !< string identifier, used for assign fluxes
+                                                   !< to the correct dimension in the analysis array
+
+       INTEGER(iwp) ::  i         !< grid index along x-direction
+       INTEGER(iwp) ::  j         !< grid index along y-direction
+       INTEGER(iwp) ::  k         !< grid index along z-direction
+       INTEGER(iwp) ::  k_mm      !< k-2 index in disretization, can be modified to avoid segmentation faults
+       INTEGER(iwp) ::  k_pp      !< k+2 index in disretization, can be modified to avoid segmentation faults
+       INTEGER(iwp) ::  k_ppp     !< k+3 index in disretization, can be modified to avoid segmentation faults
+       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms
+       INTEGER(iwp) ::  sk_num    !< integer identifier, used for assign fluxes to the correct dimension in the analysis array
+       INTEGER(iwp) ::  tn = 0    !< number of OpenMP thread
+
        INTEGER(iwp), INTENT(IN), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::   &
                                                   advc_flag !< flag array to control order of scalar advection
-                                                  
-       LOGICAL ::  non_cyclic_l    !< flag that indicates non-cyclic boundary on the left
-       LOGICAL ::  non_cyclic_n    !< flag that indicates non-cyclic boundary on the north
-       LOGICAL ::  non_cyclic_r    !< flag that indicates non-cyclic boundary on the right
-       LOGICAL ::  non_cyclic_s    !< flag that indicates non-cyclic boundary on the south  
-!       
-!--    sk is an array from parameter list. It should not be a pointer, because 
-!--    in that case the compiler can not assume a stride 1 and cannot perform 
-!--    a strided one vector load. Adding the CONTIGUOUS keyword makes things 
-!--    even worse, because the compiler cannot assume strided one in the 
-!--    caller side.
-       REAL(wp), INTENT(IN), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  sk !<  advected scalar
-
-       REAL(wp) ::  ibit0  !< flag indicating 1st-order scheme along x-direction
-       REAL(wp) ::  ibit1  !< flag indicating 3rd-order scheme along x-direction
-       REAL(wp) ::  ibit2  !< flag indicating 5th-order scheme along x-direction
+
+       LOGICAL  ::  non_cyclic_l    !< flag that indicates non-cyclic boundary on the left
+       LOGICAL  ::  non_cyclic_n    !< flag that indicates non-cyclic boundary on the north
+       LOGICAL  ::  non_cyclic_r    !< flag that indicates non-cyclic boundary on the right
+       LOGICAL  ::  non_cyclic_s    !< flag that indicates non-cyclic boundary on the south
+
+       REAL(wp) ::  diss_d        !< artificial dissipation term at grid box bottom
+       REAL(wp) ::  div           !< velocity diverence on scalar grid
+       REAL(wp) ::  flux_d        !< 6th-order flux at grid box bottom
+       REAL(wp) ::  ibit0         !< flag indicating 1st-order scheme along x-direction
+       REAL(wp) ::  ibit1         !< flag indicating 3rd-order scheme along x-direction
+       REAL(wp) ::  ibit2         !< flag indicating 5th-order scheme along x-direction
+       REAL(wp) ::  ibit3         !< flag indicating 1st-order scheme along y-direction
+       REAL(wp) ::  ibit4         !< flag indicating 3rd-order scheme along y-direction
+       REAL(wp) ::  ibit5         !< flag indicating 5th-order scheme along y-direction
+       REAL(wp) ::  ibit6         !< flag indicating 1st-order scheme along z-direction
+       REAL(wp) ::  ibit7         !< flag indicating 3rd-order scheme along z-direction
+       REAL(wp) ::  ibit8         !< flag indicating 5th-order scheme along z-direction
 #ifdef _OPENACC
        REAL(wp) ::  ibit0_l  !< flag indicating 1st-order scheme along x-direction
        REAL(wp) ::  ibit1_l  !< flag indicating 3rd-order scheme along x-direction
        REAL(wp) ::  ibit2_l  !< flag indicating 5th-order scheme along x-direction
-#endif
-       REAL(wp) ::  ibit3  !< flag indicating 1st-order scheme along y-direction
-       REAL(wp) ::  ibit4  !< flag indicating 3rd-order scheme along y-direction
-       REAL(wp) ::  ibit5  !< flag indicating 5th-order scheme along y-direction
-#ifdef _OPENACC
        REAL(wp) ::  ibit3_s  !< flag indicating 1st-order scheme along y-direction
        REAL(wp) ::  ibit4_s  !< flag indicating 3rd-order scheme along y-direction
        REAL(wp) ::  ibit5_s  !< flag indicating 5th-order scheme along y-direction
 #endif
-       REAL(wp) ::  ibit6  !< flag indicating 1st-order scheme along z-direction
-       REAL(wp) ::  ibit7  !< flag indicating 3rd-order scheme along z-direction
-       REAL(wp) ::  ibit8  !< flag indicating 5th-order scheme along z-direction
-       REAL(wp) ::  diss_d !< artificial dissipation term at grid box bottom 
-       REAL(wp) ::  div    !< diverence on scalar grid
-       REAL(wp) ::  flux_d !< 6th-order flux at grid box bottom
-       REAL(wp) ::  u_comp !< advection velocity along x-direction
+       REAL(wp) ::  u_comp        !< advection velocity along x-direction
+       REAL(wp) ::  v_comp        !< advection velocity along y-direction
 #ifdef _OPENACC
        REAL(wp) ::  u_comp_l !< advection velocity along x-direction
-#endif
-       REAL(wp) ::  v_comp !< advection velocity along y-direction
-#ifdef _OPENACC
        REAL(wp) ::  v_comp_s !< advection velocity along y-direction
 #endif
-       
-       REAL(wp) ::  diss_n !< discretized artificial dissipation at northward-side of the grid box
-       REAL(wp) ::  diss_r !< discretized artificial dissipation at rightward-side of the grid box
-       REAL(wp) ::  diss_t !< discretized artificial dissipation at rightward-side of the grid box
-       REAL(wp) ::  flux_n !< discretized 6th-order flux at northward-side of the grid box
-       REAL(wp) ::  flux_r !< discretized 6th-order flux at rightward-side of the grid box
-       REAL(wp) ::  flux_t !< discretized 6th-order flux at rightward-side of the grid box
-       
-       REAL(wp) ::  diss_s !< discretized artificial dissipation term at southward-side of the grid box
-       REAL(wp) ::  flux_s !< discretized 6th-order flux at northward-side of the grid box
-#ifndef _OPENACC
-       REAL(wp), DIMENSION(nzb+1:nzt) ::  swap_diss_y_local !< discretized artificial dissipation term at southward-side of the grid box
-       REAL(wp), DIMENSION(nzb+1:nzt) ::  swap_flux_y_local !< discretized 6th-order flux at northward-side of the grid box
-#endif
-       
-       REAL(wp) ::  diss_l !< discretized artificial dissipation term at leftward-side of the grid box
-       REAL(wp) ::  flux_l !< discretized 6th-order flux at leftward-side of the grid box
-#ifndef _OPENACC
-       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn) ::  swap_diss_x_local !< discretized artificial dissipation term at leftward-side of the grid box
-       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn) ::  swap_flux_x_local !< discretized 6th-order flux at leftward-side of the grid box
-#endif
-        
-!
-!--    Set local version of nzb_max. At non-cyclic boundaries the order of the 
-!--    advection need to be degraded near the boundary. Please note, in contrast
-!--    to the cache-optimized routines, nzb_max_l is set constantly for the 
-!--    entire subdomain, in order to avoid unsymmetric loops which might be 
-!--    an issue for GPUs.
-       IF( non_cyclic_l  .OR.  non_cyclic_r  .OR.                             &
-           non_cyclic_s  .OR.  non_cyclic_n )  THEN
-          nzb_max_l = nzt
-       ELSE
-          nzb_max_l = nzb_max
-       END IF 
-        
+!
+!--    sk is an array from parameter list. It should not be a pointer, because
+!--    in that case the compiler can not assume a stride 1 and cannot perform
+!--    a strided one vector load. Adding the CONTIGUOUS keyword makes things
+!--    even worse, because the compiler cannot assume strided one in the
+!--    caller side.
+       REAL(wp), INTENT(IN),DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  sk !<  advected scalar
+
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  diss_n     !< discretized artificial dissipation at northward-side
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  diss_r     !< discretized artificial dissipation at rightward-side
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  diss_t     !< discretized artificial dissipation at top of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  flux_n     !< discretized 6th-order flux at northward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  flux_r     !< discretized 6th-order flux at rightward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1)         ::  flux_t     !< discretized 6th-order flux at top of the grid box
+
+       REAL(wp), DIMENSION(nzb+1:nzt,0:threads_per_task-1) ::  swap_diss_y_local !< discretized artificial dissipation at southward-side
+       REAL(wp), DIMENSION(nzb+1:nzt,0:threads_per_task-1) ::  swap_flux_y_local !< discretized 6th-order flux at northward-side
+
+       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn,0:threads_per_task-1) ::  swap_diss_x_local !< discretized artificial dissipation at leftward-side
+       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn,0:threads_per_task-1) ::  swap_flux_x_local !< discretized 6th-order flux at leftward-side
+
+       CALL cpu_log( log_point_s(49), 'advec_s_ws', 'start' )
+
        SELECT CASE ( sk_char )
 
@@ -3811,69 +3789,4 @@
        END SELECT
 
-#ifndef _OPENACC
-!
-!--    Compute the fluxes for the whole left boundary of the processor domain.
-       i = nxl
-       DO  j = nys, nyn
-
-          DO  k = nzb+1, nzb_max_l
-
-             ibit2 = REAL( IBITS(advc_flag(k,j,i-1),2,1), KIND = wp )
-             ibit1 = REAL( IBITS(advc_flag(k,j,i-1),1,1), KIND = wp )
-             ibit0 = REAL( IBITS(advc_flag(k,j,i-1),0,1), KIND = wp )
-
-             u_comp                 = u(k,j,i) - u_gtrans + u_stokes_zu(k)
-             swap_flux_x_local(k,j) = u_comp * (                              &
-                                             ( 37.0_wp * ibit2 * adv_sca_5    &
-                                          +     7.0_wp * ibit1 * adv_sca_3    &
-                                          +              ibit0 * adv_sca_1    &
-                                             ) *                              &
-                                          ( sk(k,j,i)   + sk(k,j,i-1)    )    &
-                                      -      (  8.0_wp * ibit2 * adv_sca_5    &
-                                          +              ibit1 * adv_sca_3    &
-                                             ) *                              &
-                                          ( sk(k,j,i+1) + sk(k,j,i-2)    )    &
-                                      +      (           ibit2 * adv_sca_5    & 
-                                             ) *                              &
-                                          ( sk(k,j,i+2) + sk(k,j,i-3)    )    &
-                                               )
-
-              swap_diss_x_local(k,j) = -ABS( u_comp ) * (                     &
-                                             ( 10.0_wp * ibit2 * adv_sca_5    &
-                                          +     3.0_wp * ibit1 * adv_sca_3    &
-                                          +              ibit0 * adv_sca_1    &
-                                             ) *                              &
-                                          ( sk(k,j,i)   - sk(k,j,i-1) )       &
-                                      -      (  5.0_wp * ibit2 * adv_sca_5    &
-                                          +              ibit1 * adv_sca_3    &
-                                             ) *                              &
-                                         ( sk(k,j,i+1) - sk(k,j,i-2)  )       &
-                                      +      (           ibit2 * adv_sca_5    &
-                                             ) *                              &
-                                          ( sk(k,j,i+2) - sk(k,j,i-3) )       &
-                                                        )
-
-          ENDDO
-
-          DO  k = nzb_max_l+1, nzt
-
-             u_comp                 = u(k,j,i) - u_gtrans + u_stokes_zu(k)
-             swap_flux_x_local(k,j) = u_comp * (                              &
-                                      37.0_wp * ( sk(k,j,i)   + sk(k,j,i-1) ) &
-                                    -  8.0_wp * ( sk(k,j,i+1) + sk(k,j,i-2) ) &
-                                    +           ( sk(k,j,i+2) + sk(k,j,i-3) ) &
-                                               ) * adv_sca_5
-
-             swap_diss_x_local(k,j) = -ABS( u_comp ) * (                      &
-                                      10.0_wp * ( sk(k,j,i)   - sk(k,j,i-1) ) &
-                                    -  5.0_wp * ( sk(k,j,i+1) - sk(k,j,i-2) ) &
-                                    +           ( sk(k,j,i+2) - sk(k,j,i-3) ) &
-                                                       ) * adv_sca_5
-
-          ENDDO
-
-       ENDDO
-#endif
-
        !$ACC PARALLEL LOOP COLLAPSE(2) FIRSTPRIVATE(tn, sk_num) &
        !$ACC PRIVATE(i, j, k, k_mm, k_pp, k_ppp) &
@@ -3882,6 +3795,7 @@
        !$ACC PRIVATE(ibit3_s, ibit4_s, ibit5_s) &
        !$ACC PRIVATE(ibit6, ibit7, ibit8) &
-       !$ACC PRIVATE(flux_r, diss_r, flux_l, diss_l) &
-       !$ACC PRIVATE(flux_n, diss_n, flux_s, diss_s) &
+       !$ACC PRIVATE(flux_r, diss_r) &
+       !$ACC PRIVATE(flux_n, diss_n) &
+       !$ACC PRIVATE(swap_diss_y_local, swap_flux_y_local) &
        !$ACC PRIVATE(flux_t, diss_t, flux_d, diss_d) &
        !$ACC PRIVATE(div, u_comp, u_comp_l, v_comp, v_comp_s) &
@@ -3890,5 +3804,5 @@
        !$ACC PRESENT(drho_air, rho_air_zw, ddzw) &
        !$ACC PRESENT(tend) &
-       !$ACC PRESENT(hom(nzb+1:nzb_max_l,1,1:3,0)) &
+       !$ACC PRESENT(hom(:,1,1:3,0)) &
        !$ACC PRESENT(weight_substep(intermediate_timestep_count)) &
        !$ACC PRESENT(sums_wspts_ws_l, sums_wssas_ws_l) &
@@ -3898,106 +3812,185 @@
        !$ACC PRESENT(sums_salsa_ws_l)
        DO  i = nxl, nxr
-
+          DO  j = nys, nyn
+!
+!--          Used local modified copy of nzb_max (used to degrade order of
+!--          discretization) at non-cyclic boundaries. Modify only at relevant points
+!--          instead of the entire subdomain. This should lead to better
+!--          load balance between boundary and non-boundary PEs.
+             IF( non_cyclic_l  .AND.  i <= nxl + 2  .OR.                       &
+                 non_cyclic_r  .AND.  i >= nxr - 2  .OR.                       &
+                 non_cyclic_s  .AND.  j <= nys + 2  .OR.                       &
+                 non_cyclic_n  .AND.  j >= nyn - 2 )  THEN
+                nzb_max_l = nzt
+             ELSE
+                nzb_max_l = nzb_max
+             END IF
 #ifndef _OPENACC
-          j = nys
-          DO  k = nzb+1, nzb_max_l
-
-             ibit5 = REAL( IBITS(advc_flag(k,j-1,i),5,1), KIND = wp )
-             ibit4 = REAL( IBITS(advc_flag(k,j-1,i),4,1), KIND = wp )
-             ibit3 = REAL( IBITS(advc_flag(k,j-1,i),3,1), KIND = wp )
-
-             v_comp               = v(k,j,i) - v_gtrans + v_stokes_zu(k)
-             swap_flux_y_local(k) = v_comp * (                                &
-                                             ( 37.0_wp * ibit5 * adv_sca_5    &
-                                          +     7.0_wp * ibit4 * adv_sca_3    &
-                                          +              ibit3 * adv_sca_1    &
-                                             ) *                              &
-                                         ( sk(k,j,i)  + sk(k,j-1,i)     )     &
-                                       -     (  8.0_wp * ibit5 * adv_sca_5    &
-                                          +              ibit4 * adv_sca_3    &
-                                              ) *                             &
-                                         ( sk(k,j+1,i) + sk(k,j-2,i)    )     &
-                                      +      (           ibit5 * adv_sca_5    &
-                                             ) *                              &
-                                        ( sk(k,j+2,i) + sk(k,j-3,i)     )     &
-                                             )
-
-             swap_diss_y_local(k) = -ABS( v_comp ) * (                        &
-                                             ( 10.0_wp * ibit5 * adv_sca_5    &
-                                          +     3.0_wp * ibit4 * adv_sca_3    &
-                                          +              ibit3 * adv_sca_1    &
-                                             ) *                              &
-                                          ( sk(k,j,i)   - sk(k,j-1,i)    )    &
-                                      -      (  5.0_wp * ibit5 * adv_sca_5    &
-                                          +              ibit4 * adv_sca_3    &
-                                             ) *                              &
-                                          ( sk(k,j+1,i) - sk(k,j-2,i)    )    &
-                                      +      (           ibit5 * adv_sca_5    &
-                                             ) *                              &
-                                          ( sk(k,j+2,i) - sk(k,j-3,i)    )    &
-                                                     )
-
-          ENDDO
-!
-!--       Above to the top of the highest topography. No degradation necessary.
-          DO  k = nzb_max_l+1, nzt
-
-             v_comp               = v(k,j,i) - v_gtrans + v_stokes_zu(k)
-             swap_flux_y_local(k) = v_comp * (                               &
-                                    37.0_wp * ( sk(k,j,i)   + sk(k,j-1,i) )  &
-                                  -  8.0_wp * ( sk(k,j+1,i) + sk(k,j-2,i) )  &
-                                  +           ( sk(k,j+2,i) + sk(k,j-3,i) )  &
-                                             ) * adv_sca_5
-             swap_diss_y_local(k) = -ABS( v_comp ) * (                       &
-                                    10.0_wp * ( sk(k,j,i)   - sk(k,j-1,i) )  &
-                                  -  5.0_wp * ( sk(k,j+1,i) - sk(k,j-2,i) )  &
-                                  +             sk(k,j+2,i) - sk(k,j-3,i)    &
+!
+!--          Compute leftside fluxes of the respective PE bounds.
+             IF ( i == nxl )  THEN
+
+                DO  k = nzb+1, nzb_max_l
+
+                   ibit2 = REAL( IBITS(advc_flag(k,j,i-1),2,1), KIND = wp )
+                   ibit1 = REAL( IBITS(advc_flag(k,j,i-1),1,1), KIND = wp )
+                   ibit0 = REAL( IBITS(advc_flag(k,j,i-1),0,1), KIND = wp )
+
+                   u_comp                    = u(k,j,i) - u_gtrans + u_stokes_zu(k)
+                   swap_flux_x_local(k,j,tn) = u_comp * (                      &
+                                               ( 37.0_wp * ibit2 * adv_sca_5   &
+                                            +     7.0_wp * ibit1 * adv_sca_3   &
+                                            +              ibit0 * adv_sca_1   &
+                                               ) *                             &
+                                            ( sk(k,j,i)   + sk(k,j,i-1)    )   &
+                                        -      (  8.0_wp * ibit2 * adv_sca_5   &
+                                            +              ibit1 * adv_sca_3   &
+                                               ) *                             &
+                                            ( sk(k,j,i+1) + sk(k,j,i-2)    )   &
+                                        +      (           ibit2 * adv_sca_5   &
+                                               ) *                             &
+                                               ( sk(k,j,i+2) + sk(k,j,i-3)    )&
+                                                        )
+
+                   swap_diss_x_local(k,j,tn) = -ABS( u_comp ) * (              &
+                                                ( 10.0_wp * ibit2 * adv_sca_5  &
+                                             +     3.0_wp * ibit1 * adv_sca_3  &
+                                             +              ibit0 * adv_sca_1  &
+                                                ) *                            &
+                                             ( sk(k,j,i)   - sk(k,j,i-1)    )  &
+                                         -      (  5.0_wp * ibit2 * adv_sca_5  &
+                                             +              ibit1 * adv_sca_3  &
+                                                ) *                            &
+                                             ( sk(k,j,i+1) - sk(k,j,i-2)    )  &
+                                         +      (           ibit2 * adv_sca_5  &
+                                                ) *                            &
+                                             ( sk(k,j,i+2) - sk(k,j,i-3)    )  &
+                                                                )
+
+                ENDDO
+
+                DO  k = nzb_max_l+1, nzt
+
+                   u_comp                    = u(k,j,i) - u_gtrans + u_stokes_zu(k)
+                   swap_flux_x_local(k,j,tn) = u_comp * (                      &
+                                        37.0_wp * ( sk(k,j,i)   + sk(k,j,i-1) )&
+                                      -  8.0_wp * ( sk(k,j,i+1) + sk(k,j,i-2) )&
+                                      +           ( sk(k,j,i+2) + sk(k,j,i-3) )&
+                                                        ) * adv_sca_5
+
+                   swap_diss_x_local(k,j,tn) = -ABS( u_comp ) * (              &
+                                        10.0_wp * ( sk(k,j,i)   - sk(k,j,i-1) )&
+                                      -  5.0_wp * ( sk(k,j,i+1) - sk(k,j,i-2) )&
+                                      +           ( sk(k,j,i+2) - sk(k,j,i-3) )&
+                                                                ) * adv_sca_5
+
+                ENDDO
+
+             ENDIF
+!
+!--          Compute southside fluxes of the respective PE bounds.
+             IF ( j == nys )  THEN
+!
+!--             Up to the top of the highest topography.
+                DO  k = nzb+1, nzb_max_l
+
+                   ibit5 = REAL( IBITS(advc_flag(k,j-1,i),5,1), KIND = wp )
+                   ibit4 = REAL( IBITS(advc_flag(k,j-1,i),4,1), KIND = wp )
+                   ibit3 = REAL( IBITS(advc_flag(k,j-1,i),3,1), KIND = wp )
+
+                   v_comp                  = v(k,j,i) - v_gtrans + v_stokes_zu(k)
+                   swap_flux_y_local(k,tn) = v_comp *         (                &
+                                                ( 37.0_wp * ibit5 * adv_sca_5  &
+                                             +     7.0_wp * ibit4 * adv_sca_3  &
+                                             +              ibit3 * adv_sca_1  &
+                                                ) *                            &
+                                            ( sk(k,j,i)  + sk(k,j-1,i)     )   &
+                                          -     (  8.0_wp * ibit5 * adv_sca_5  &
+                                             +              ibit4 * adv_sca_3  &
+                                                 ) *                           &
+                                            ( sk(k,j+1,i) + sk(k,j-2,i)    )   &
+                                          +     (           ibit5 * adv_sca_5  &
+                                                ) *                            &
+                                            ( sk(k,j+2,i) + sk(k,j-3,i)    )   &
+                                                              )
+
+                   swap_diss_y_local(k,tn) = -ABS( v_comp ) * (                &
+                                                ( 10.0_wp * ibit5 * adv_sca_5  &
+                                             +     3.0_wp * ibit4 * adv_sca_3  &
+                                             +              ibit3 * adv_sca_1  &
+                                                ) *                            &
+                                             ( sk(k,j,i)   - sk(k,j-1,i)  )    &
+                                         -      (  5.0_wp * ibit5 * adv_sca_5  &
+                                             +              ibit4 * adv_sca_3  &
+                                             ) *                               &
+                                             ( sk(k,j+1,i) - sk(k,j-2,i)  )    &
+                                         +      (           ibit5 * adv_sca_5  &
+                                                ) *                            &
+                                             ( sk(k,j+2,i) - sk(k,j-3,i)  )    &
+                                                              )
+
+                ENDDO
+!
+!--             Above to the top of the highest topography. No degradation necessary.
+                DO  k = nzb_max_l+1, nzt
+
+                   v_comp                  = v(k,j,i) - v_gtrans + v_stokes_zu(k)
+                   swap_flux_y_local(k,tn) = v_comp * (                        &
+                                     37.0_wp * ( sk(k,j,i)   + sk(k,j-1,i) )   &
+                                   -  8.0_wp * ( sk(k,j+1,i) + sk(k,j-2,i) )   &
+                                   +           ( sk(k,j+2,i) + sk(k,j-3,i) )   &
                                                       ) * adv_sca_5
-
-          ENDDO
+                   swap_diss_y_local(k,tn) = -ABS( v_comp ) * (                &
+                                     10.0_wp * ( sk(k,j,i)   - sk(k,j-1,i) )   &
+                                   -  5.0_wp * ( sk(k,j+1,i) - sk(k,j-2,i) )   &
+                                   +             sk(k,j+2,i) - sk(k,j-3,i)     &
+                                                         ) * adv_sca_5
+
+                ENDDO
+
+             ENDIF
 #endif
-
-          DO  j = nys, nyn
-
-             flux_d    = 0.0_wp
-             diss_d    = 0.0_wp
-
+!
+!--          Now compute the fluxes and tendency terms for the horizontal and
+!--          vertical parts up to the top of the highest topography.
              DO  k = nzb+1, nzb_max_l
-
+!
+!--             Note: It is faster to conduct all multiplications explicitly, e.g.
+!--             * adv_sca_5 ... than to determine a factor and multiplicate the
+!--             flux at the end.
                 ibit2 = REAL( IBITS(advc_flag(k,j,i),2,1), KIND = wp )
                 ibit1 = REAL( IBITS(advc_flag(k,j,i),1,1), KIND = wp )
                 ibit0 = REAL( IBITS(advc_flag(k,j,i),0,1), KIND = wp )
 
-                u_comp = u(k,j,i+1) - u_gtrans + u_stokes_zu(k)
-                flux_r = u_comp * (                                           &
-                          ( 37.0_wp * ibit2 * adv_sca_5                       &
-                      +      7.0_wp * ibit1 * adv_sca_3                       &
-                      +               ibit0 * adv_sca_1                       &
-                          ) *                                                 &
-                             ( sk(k,j,i+1) + sk(k,j,i)   )                    &
-                   -      (  8.0_wp * ibit2 * adv_sca_5                       &
-                       +              ibit1 * adv_sca_3                       &
-                          ) *                                                 &
-                             ( sk(k,j,i+2) + sk(k,j,i-1) )                    &
-                   +      (           ibit2 * adv_sca_5                       &
-                          ) *                                                 &
-                             ( sk(k,j,i+3) + sk(k,j,i-2) )                    &
+                u_comp    = u(k,j,i+1) - u_gtrans + u_stokes_zu(k)
+                flux_r(k) = u_comp * (                                         &
+                           ( 37.0_wp * ibit2 * adv_sca_5                       &
+                        +     7.0_wp * ibit1 * adv_sca_3                       &
+                        +              ibit0 * adv_sca_1                       &
+                           ) *                                                 &
+                                   ( sk(k,j,i+1) + sk(k,j,i)   )               &
+                    -      (  8.0_wp * ibit2 * adv_sca_5                       &
+                        +              ibit1 * adv_sca_3                       &
+                           ) *                                                 &
+                                   ( sk(k,j,i+2) + sk(k,j,i-1) )               &
+                    +      (           ibit2 * adv_sca_5                       &
+                           ) *                                                 &
+                                   ( sk(k,j,i+3) + sk(k,j,i-2) )               &
                                      )
 
-                diss_r = -ABS( u_comp ) * (                                   &
-                          ( 10.0_wp * ibit2 * adv_sca_5                       &
-                       +     3.0_wp * ibit1 * adv_sca_3                       &
-                       +              ibit0 * adv_sca_1                       &
-                          ) *                                                 &
-                             ( sk(k,j,i+1) - sk(k,j,i)   )                    &
-                   -      (  5.0_wp * ibit2 * adv_sca_5                       &
-                       +              ibit1 * adv_sca_3                       &
-                          ) *                                                 &
-                             ( sk(k,j,i+2) - sk(k,j,i-1) )                    &
-                   +      (           ibit2 * adv_sca_5                       &
-                          ) *                                                 &
-                             ( sk(k,j,i+3) - sk(k,j,i-2) )                    &
+                diss_r(k) = -ABS( u_comp ) * (                                 &
+                           ( 10.0_wp * ibit2 * adv_sca_5                       &
+                        +     3.0_wp * ibit1 * adv_sca_3                       &
+                        +              ibit0 * adv_sca_1                       &
+                           ) *                                                 &
+                                   ( sk(k,j,i+1) - sk(k,j,i)  )                &
+                    -      (  5.0_wp * ibit2 * adv_sca_5                       &
+                        +              ibit1 * adv_sca_3                       &
+                           ) *                                                 &
+                                   ( sk(k,j,i+2) - sk(k,j,i-1) )               &
+                    +      (           ibit2 * adv_sca_5                       &
+                           ) *                                                 &
+                                   ( sk(k,j,i+3) - sk(k,j,i-2) )               &
                                              )
-
 #ifdef _OPENACC
 !
@@ -4008,73 +4001,68 @@
 
                 u_comp_l = u(k,j,i) - u_gtrans + u_stokes_zu(k)
-                flux_l = u_comp_l * (                                         &
-                                             ( 37.0_wp * ibit2_l * adv_sca_5  &
-                                          +     7.0_wp * ibit1_l * adv_sca_3  &
-                                          +              ibit0_l * adv_sca_1  &
-                                             ) *                              &
-                                          ( sk(k,j,i)   + sk(k,j,i-1)    )    &
-                                      -      (  8.0_wp * ibit2_l * adv_sca_5  &
-                                          +              ibit1_l * adv_sca_3  &
-                                             ) *                              &
-                                          ( sk(k,j,i+1) + sk(k,j,i-2)    )    &
-                                      +      (           ibit2_l * adv_sca_5  & 
-                                             ) *                              &
-                                          ( sk(k,j,i+2) + sk(k,j,i-3)    )    &
-                                               )
-
-                 diss_l = -ABS( u_comp_l ) * (                                &
-                                             ( 10.0_wp * ibit2_l * adv_sca_5  &
-                                          +     3.0_wp * ibit1_l * adv_sca_3  &
-                                          +              ibit0_l * adv_sca_1  &
-                                             ) *                              &
-                                          ( sk(k,j,i)   - sk(k,j,i-1) )       &
-                                      -      (  5.0_wp * ibit2_l * adv_sca_5  &
-                                          +              ibit1_l * adv_sca_3  &
-                                             ) *                              &
-                                         ( sk(k,j,i+1) - sk(k,j,i-2)  )       &
-                                      +      (           ibit2_l * adv_sca_5  &
-                                             ) *                              &
-                                          ( sk(k,j,i+2) - sk(k,j,i-3) )       &
-                                                        )
-#else
-                flux_l = swap_flux_x_local(k,j)
-                diss_l = swap_diss_x_local(k,j)
+                swap_flux_x_local(k,j,tn) = u_comp_l * (                       &
+                                             ( 37.0_wp * ibit2_l * adv_sca_5   &
+                                          +     7.0_wp * ibit1_l * adv_sca_3   &
+                                          +              ibit0_l * adv_sca_1   &
+                                             ) *                               &
+                                          ( sk(k,j,i)   + sk(k,j,i-1)    )     &
+                                      -      (  8.0_wp * ibit2_l * adv_sca_5   &
+                                          +              ibit1_l * adv_sca_3   &
+                                             ) *                               &
+                                          ( sk(k,j,i+1) + sk(k,j,i-2)    )     &
+                                      +      (           ibit2_l * adv_sca_5   &
+                                             ) *                               &
+                                          ( sk(k,j,i+2) + sk(k,j,i-3)    )     &
+                                                       )
+
+                swap_diss_x_local(k,j,tn) = -ABS( u_comp_l ) * (               &
+                                            ( 10.0_wp * ibit2_l * adv_sca_5    &
+                                         +     3.0_wp * ibit1_l * adv_sca_3    &
+                                         +              ibit0_l * adv_sca_1    &
+                                            ) *                                &
+                                         ( sk(k,j,i)   - sk(k,j,i-1) )         &
+                                     -      (  5.0_wp * ibit2_l * adv_sca_5    &
+                                         +              ibit1_l * adv_sca_3    &
+                                            ) *                                &
+                                        ( sk(k,j,i+1) - sk(k,j,i-2)  )         &
+                                     +      (           ibit2_l * adv_sca_5    &
+                                            ) *                                &
+                                         ( sk(k,j,i+2) - sk(k,j,i-3) )         &
+                                                               )
 #endif
-
                 ibit5 = REAL( IBITS(advc_flag(k,j,i),5,1), KIND = wp )
                 ibit4 = REAL( IBITS(advc_flag(k,j,i),4,1), KIND = wp )
                 ibit3 = REAL( IBITS(advc_flag(k,j,i),3,1), KIND = wp )
 
-                v_comp = v(k,j+1,i) - v_gtrans + v_stokes_zu(k)
-                flux_n = v_comp * (                                           &
-                          ( 37.0_wp * ibit5 * adv_sca_5                       &
-                       +     7.0_wp * ibit4 * adv_sca_3                       &
-                       +              ibit3 * adv_sca_1                       &
-                          ) *                                                 &
-                             ( sk(k,j+1,i) + sk(k,j,i)   )                    &
-                   -      (  8.0_wp * ibit5 * adv_sca_5                       &
-                       +              ibit4 * adv_sca_3                       &
-                          ) *                                                 &
-                             ( sk(k,j+2,i) + sk(k,j-1,i) )                    &
-                   +      (           ibit5 * adv_sca_5                       &
-                          ) *                                                 &
-                             ( sk(k,j+3,i) + sk(k,j-2,i) )                    &
+                v_comp    = v(k,j+1,i) - v_gtrans + v_stokes_zu(k)
+                flux_n(k) = v_comp * (                                         &
+                           ( 37.0_wp * ibit5 * adv_sca_5                       &
+                        +     7.0_wp * ibit4 * adv_sca_3                       &
+                        +              ibit3 * adv_sca_1                       &
+                           ) *                                                 &
+                                   ( sk(k,j+1,i) + sk(k,j,i)   )               &
+                    -      (  8.0_wp * ibit5 * adv_sca_5                       &
+                        +              ibit4 * adv_sca_3                       &
+                           ) *                                                 &
+                                   ( sk(k,j+2,i) + sk(k,j-1,i) )               &
+                    +      (           ibit5 * adv_sca_5                       &
+                           ) *                                                 &
+                                   ( sk(k,j+3,i) + sk(k,j-2,i) )               &
                                      )
 
-                diss_n = -ABS( v_comp ) * (                                   &
-                          ( 10.0_wp * ibit5 * adv_sca_5                       &
-                       +     3.0_wp * ibit4 * adv_sca_3                       &
-                       +              ibit3 * adv_sca_1                       &
-                          ) *                                                 &
-                             ( sk(k,j+1,i) - sk(k,j,i)    )                   &
-                   -      (  5.0_wp * ibit5 * adv_sca_5                       &
-                       +              ibit4 * adv_sca_3                       &
-                          ) *                                                 &
-                             ( sk(k,j+2,i) - sk(k,j-1,i)  )                   &
-                   +      (           ibit5 * adv_sca_5                       &
-                          ) *                                                 &
-                             ( sk(k,j+3,i) - sk(k,j-2,i) )                    &
+                diss_n(k) = -ABS( v_comp ) * (                                 &
+                           ( 10.0_wp * ibit5 * adv_sca_5                       &
+                        +     3.0_wp * ibit4 * adv_sca_3                       &
+                        +              ibit3 * adv_sca_1                       &
+                           ) *                                                 &
+                                   ( sk(k,j+1,i) - sk(k,j,i)   )               &
+                    -      (  5.0_wp * ibit5 * adv_sca_5                       &
+                        +              ibit4 * adv_sca_3                       &
+                           ) *                                                 &
+                                   ( sk(k,j+2,i) - sk(k,j-1,i) )               &
+                    +      (           ibit5 * adv_sca_5                       &
+                           ) *                                                 &
+                                   ( sk(k,j+3,i) - sk(k,j-2,i) )               &
                                              )
-
 #ifdef _OPENACC
 !
@@ -4084,46 +4072,112 @@
                 ibit3_s = REAL( IBITS(advc_flag(k,j-1,i),3,1), KIND = wp )
 
-                v_comp_s = v(k,j,i) - v_gtrans + v_stokes_zu(k)
-                flux_s = v_comp_s * (                                         &
-                                             ( 37.0_wp * ibit5_s * adv_sca_5  &
-                                          +     7.0_wp * ibit4_s * adv_sca_3  &
-                                          +              ibit3_s * adv_sca_1  &
-                                             ) *                              &
-                                         ( sk(k,j,i)  + sk(k,j-1,i)     )     &
-                                       -     (  8.0_wp * ibit5_s * adv_sca_5  &
-                                          +              ibit4_s * adv_sca_3  &
-                                              ) *                             &
-                                         ( sk(k,j+1,i) + sk(k,j-2,i)    )     &
-                                      +      (           ibit5_s * adv_sca_5  &
-                                             ) *                              &
-                                        ( sk(k,j+2,i) + sk(k,j-3,i)     )     &
-                                             )
-
-                diss_s = -ABS( v_comp_s ) * (                                 &
-                                             ( 10.0_wp * ibit5_s * adv_sca_5  &
-                                          +     3.0_wp * ibit4_s * adv_sca_3  &
-                                          +              ibit3_s * adv_sca_1  &
-                                             ) *                              &
-                                          ( sk(k,j,i)   - sk(k,j-1,i)    )    &
-                                      -      (  5.0_wp * ibit5_s * adv_sca_5  &
-                                          +              ibit4_s * adv_sca_3  &
-                                             ) *                              &
-                                          ( sk(k,j+1,i) - sk(k,j-2,i)    )    &
-                                      +      (           ibit5_s * adv_sca_5  &
-                                             ) *                              &
-                                          ( sk(k,j+2,i) - sk(k,j-3,i)    )    &
+                v_comp_s                = v(k,j,i) - v_gtrans + v_stokes_zu(k)
+                swap_flux_y_local(k,tn) = v_comp_s * (                         &
+                                             ( 37.0_wp * ibit5_s * adv_sca_5   &
+                                          +     7.0_wp * ibit4_s * adv_sca_3   &
+                                          +              ibit3_s * adv_sca_1   &
+                                             ) *                               &
+                                         ( sk(k,j,i)  + sk(k,j-1,i)     )      &
+                                       -     (  8.0_wp * ibit5_s * adv_sca_5   &
+                                          +              ibit4_s * adv_sca_3   &
+                                              ) *                              &
+                                         ( sk(k,j+1,i) + sk(k,j-2,i)    )      &
+                                      +      (           ibit5_s * adv_sca_5   &
+                                             ) *                               &
+                                        ( sk(k,j+2,i) + sk(k,j-3,i)     )      &
                                                      )
-#else
-                flux_s = swap_flux_y_local(k)
-                diss_s = swap_diss_y_local(k)
+
+                swap_flux_y_local(k,tn) = -ABS( v_comp_s ) * (                 &
+                                             ( 10.0_wp * ibit5_s * adv_sca_5   &
+                                          +     3.0_wp * ibit4_s * adv_sca_3   &
+                                          +              ibit3_s * adv_sca_1   &
+                                             ) *                               &
+                                          ( sk(k,j,i)   - sk(k,j-1,i)    )     &
+                                      -      (  5.0_wp * ibit5_s * adv_sca_5   &
+                                          +              ibit4_s * adv_sca_3   &
+                                             ) *                               &
+                                          ( sk(k,j+1,i) - sk(k,j-2,i)    )     &
+                                      +      (           ibit5_s * adv_sca_5   &
+                                             ) *                               &
+                                          ( sk(k,j+2,i) - sk(k,j-3,i)    )     &
+                                                             )
 #endif
-
-!
-!--             k index has to be modified near bottom and top, else array
-!--             subscripts will be exceeded.
+             ENDDO
+!
+!--          Now compute the fluxes and tendency terms for the horizontal and
+!--          vertical parts above the top of the highest topography. No degradation
+!--          for the horizontal parts, but for the vertical it is stell needed.
+             DO  k = nzb_max_l+1, nzt
+
+                u_comp    = u(k,j,i+1) - u_gtrans + u_stokes_zu(k)
+                flux_r(k) = u_comp * (                                         &
+                            37.0_wp * ( sk(k,j,i+1) + sk(k,j,i)   )            &
+                          -  8.0_wp * ( sk(k,j,i+2) + sk(k,j,i-1) )            &
+                          +           ( sk(k,j,i+3) + sk(k,j,i-2) ) ) * adv_sca_5
+                diss_r(k) = -ABS( u_comp ) * (                                 &
+                            10.0_wp * ( sk(k,j,i+1) - sk(k,j,i)   )            &
+                          -  5.0_wp * ( sk(k,j,i+2) - sk(k,j,i-1) )            &
+                          +           ( sk(k,j,i+3) - sk(k,j,i-2) ) ) * adv_sca_5
+#ifdef _OPENACC
+!
+!--             Recompute the left fluxes.
+                u_comp_l                  = u(k,j,i) - u_gtrans + u_stokes_zu(k)
+                swap_flux_x_local(k,j,tn) = u_comp_l * (                       &
+                                      37.0_wp * ( sk(k,j,i)   + sk(k,j,i-1) )  &
+                                    -  8.0_wp * ( sk(k,j,i+1) + sk(k,j,i-2) )  &
+                                    +           ( sk(k,j,i+2) + sk(k,j,i-3) )  &
+                                                       ) * adv_sca_5
+
+                swap_diss_x_local(k,j,tn) = -ABS( u_comp_l ) * (               &
+                                      10.0_wp * ( sk(k,j,i)   - sk(k,j,i-1) )  &
+                                    -  5.0_wp * ( sk(k,j,i+1) - sk(k,j,i-2) )  &
+                                    +           ( sk(k,j,i+2) - sk(k,j,i-3) )  &
+                                                               ) * adv_sca_5
+#endif
+
+                v_comp    = v(k,j+1,i) - v_gtrans + v_stokes_zu(k)
+                flux_n(k) = v_comp * (                                         &
+                            37.0_wp * ( sk(k,j+1,i) + sk(k,j,i)   )            &
+                          -  8.0_wp * ( sk(k,j+2,i) + sk(k,j-1,i) )            &
+                          +           ( sk(k,j+3,i) + sk(k,j-2,i) ) ) * adv_sca_5
+                diss_n(k) = -ABS( v_comp ) * (                                 &
+                            10.0_wp * ( sk(k,j+1,i) - sk(k,j,i)   )            &
+                          -  5.0_wp * ( sk(k,j+2,i) - sk(k,j-1,i) )            &
+                          +           ( sk(k,j+3,i) - sk(k,j-2,i) ) ) * adv_sca_5
+#ifdef _OPENACC
+!
+!--             Recompute the south fluxes.
+                v_comp_s                = v(k,j,i) - v_gtrans + v_stokes_zu(k)
+                swap_flux_y_local(k,tn) = v_comp_s * (                         &
+                                    37.0_wp * ( sk(k,j,i)   + sk(k,j-1,i) )    &
+                                  -  8.0_wp * ( sk(k,j+1,i) + sk(k,j-2,i) )    &
+                                  +           ( sk(k,j+2,i) + sk(k,j-3,i) )    &
+                                                     ) * adv_sca_5
+                swap_diss_y_local(k,tn) = -ABS( v_comp_s ) * (                 &
+                                    10.0_wp * ( sk(k,j,i)   - sk(k,j-1,i) )    &
+                                  -  5.0_wp * ( sk(k,j+1,i) - sk(k,j-2,i) )    &
+                                  +             sk(k,j+2,i) - sk(k,j-3,i)      &
+                                                             ) * adv_sca_5
+#endif
+             ENDDO
+!
+!--          Now, compute vertical fluxes. Split loop into a part treating the
+!--          lowest grid points with indirect indexing, a main loop without
+!--          indirect indexing, and a loop for the uppermost grip points with
+!--          indirect indexing. This allows better vectorization for the main loop.
+!--          First, compute the flux at model surface, which need has to be
+!--          calculated explicetely for the tendency at
+!--          the first w-level. For topography wall this is done implicitely by
+!--          advc_flag.
+             flux_t(nzb) = 0.0_wp
+             diss_t(nzb) = 0.0_wp
+
+             DO  k = nzb+1, nzb+1
                 ibit8 = REAL( IBITS(advc_flag(k,j,i),8,1), KIND = wp )
                 ibit7 = REAL( IBITS(advc_flag(k,j,i),7,1), KIND = wp )
                 ibit6 = REAL( IBITS(advc_flag(k,j,i),6,1), KIND = wp )
-
+!
+!--             k index has to be modified near bottom and top, else array
+!--             subscripts will be exceeded.
                 k_ppp = k + 3 * ibit8
                 k_pp  = k + 2 * ( 1 - ibit6  )
@@ -4131,408 +4185,320 @@
 
 
-                flux_t = w(k,j,i) * rho_air_zw(k) * (                         &
-                           ( 37.0_wp * ibit8 * adv_sca_5                      &
-                        +     7.0_wp * ibit7 * adv_sca_3                      &
-                        +           ibit6 * adv_sca_1                         &
-                           ) *                                                &
-                                   ( sk(k+1,j,i)  + sk(k,j,i)    )            &
-                    -      (  8.0_wp * ibit8 * adv_sca_5                      &
-                        +              ibit7 * adv_sca_3                      &
-                           ) *                                                &
-                                   ( sk(k_pp,j,i) + sk(k-1,j,i)  )            &
-                    +      (           ibit8 * adv_sca_5                      &
-                           ) *     ( sk(k_ppp,j,i)+ sk(k_mm,j,i) )            &
-                                       )
-
-                diss_t = -ABS( w(k,j,i) ) * rho_air_zw(k) * (                 &
-                           ( 10.0_wp * ibit8 * adv_sca_5                      &
-                        +     3.0_wp * ibit7 * adv_sca_3                      &
-                        +              ibit6 * adv_sca_1                      &
-                           ) *                                                &
-                                   ( sk(k+1,j,i)   - sk(k,j,i)    )           &
-                    -      (  5.0_wp * ibit8 * adv_sca_5                      &
-                        +              ibit7 * adv_sca_3                      &
-                           ) *                                                &
-                                   ( sk(k_pp,j,i)  - sk(k-1,j,i)  )           &
-                    +      (           ibit8 * adv_sca_5                      &
-                           ) *                                                &
-                                   ( sk(k_ppp,j,i) - sk(k_mm,j,i) )           &
-                                               )
-!
-!--             Calculate the divergence of the velocity field. A respective
-!--             correction is needed to overcome numerical instabilities caused
-!--             by a not sufficient reduction of divergences near topography.
-                div   =   ( u(k,j,i+1) * ( ibit0 + ibit1 + ibit2 )             &
-                          - u(k,j,i)   * (                                     &
-                        REAL( IBITS(advc_flag(k,j,i-1),0,1), KIND = wp )       &
-                      + REAL( IBITS(advc_flag(k,j,i-1),1,1), KIND = wp )       &
-                      + REAL( IBITS(advc_flag(k,j,i-1),2,1), KIND = wp )       &
-                                         )                                     &
-                          ) * ddx                                              &
-                        + ( v(k,j+1,i) * ( ibit3 + ibit4 + ibit5 )             &
-                          - v(k,j,i)   * (                                     &
-                        REAL( IBITS(advc_flag(k,j-1,i),3,1), KIND = wp )       &
-                      + REAL( IBITS(advc_flag(k,j-1,i),4,1), KIND = wp )       &
-                      + REAL( IBITS(advc_flag(k,j-1,i),5,1), KIND = wp )       &
-                                         )                                     &
-                          ) * ddy                                              &
-                        + ( w(k,j,i) * rho_air_zw(k) *                         &
-                                         ( ibit6 + ibit7 + ibit8 )             &
-                          - w(k-1,j,i) * rho_air_zw(k-1) *                     &
-                                         (                                     &
-                        REAL( IBITS(advc_flag(k-1,j,i),6,1), KIND = wp )       &
-                      + REAL( IBITS(advc_flag(k-1,j,i),7,1), KIND = wp )       &
-                      + REAL( IBITS(advc_flag(k-1,j,i),8,1), KIND = wp )       &
-                                         )                                     &      
-                          ) * drho_air(k) * ddzw(k)
-
-
-                tend(k,j,i) = tend(k,j,i) - (                                 &
-                        ( ( flux_r + diss_r )                                 &
-                      -   ( flux_l + diss_l ) ) * ddx                         &
-                      + ( ( flux_n + diss_n )                                 &
-                      -   ( flux_s + diss_s ) ) * ddy                         &
-                      + ( ( flux_t + diss_t )                                 &
-                      -   ( flux_d + diss_d ) ) * drho_air(k) * ddzw(k)       &
-                                            ) + sk(k,j,i) * div
-
-#ifndef _OPENACC
-                swap_flux_y_local(k)   = flux_n
-                swap_diss_y_local(k)   = diss_n
-                swap_flux_x_local(k,j) = flux_r
-                swap_diss_x_local(k,j) = diss_r
-#endif
-                flux_d                 = flux_t
-                diss_d                 = diss_t
-
-!
-!--             Evaluation of statistics. 
-                SELECT CASE ( sk_num )
-
-                    CASE ( 1 )
-                       !$ACC ATOMIC
-                       sums_wspts_ws_l(k,tn) = sums_wspts_ws_l(k,tn)           &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 2 )
-                       !$ACC ATOMIC
-                       sums_wssas_ws_l(k,tn) = sums_wssas_ws_l(k,tn)           &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 3 )
-                       !$ACC ATOMIC
-                       sums_wsqs_ws_l(k,tn)  = sums_wsqs_ws_l(k,tn)            &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 4 )
-                       !$ACC ATOMIC
-                       sums_wsqcs_ws_l(k,tn)  = sums_wsqcs_ws_l(k,tn)          &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 5 )
-                       !$ACC ATOMIC
-                       sums_wsqrs_ws_l(k,tn)  = sums_wsqrs_ws_l(k,tn)          &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 6 )
-                       !$ACC ATOMIC
-                       sums_wsncs_ws_l(k,tn)  = sums_wsncs_ws_l(k,tn)          &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 7 )
-                       !$ACC ATOMIC
-                       sums_wsnrs_ws_l(k,tn)  = sums_wsnrs_ws_l(k,tn)          &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 8 )
-                       !$ACC ATOMIC
-                       sums_wsss_ws_l(k,tn)  = sums_wsss_ws_l(k,tn)            &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 9 )
-                        !$ACC ATOMIC
-                        sums_salsa_ws_l(k,tn)  = sums_salsa_ws_l(k,tn)         &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-
-                END SELECT
-
+                flux_t(k) = w(k,j,i) * rho_air_zw(k) * (                       &
+                           ( 37.0_wp * ibit8 * adv_sca_5                       &
+                        +     7.0_wp * ibit7 * adv_sca_3                       &
+                        +              ibit6 * adv_sca_1                       &
+                           ) *                                                 &
+                                   ( sk(k+1,j,i)  + sk(k,j,i)    )             &
+                    -      (  8.0_wp * ibit8 * adv_sca_5                       &
+                        +              ibit7 * adv_sca_3                       &
+                           ) *                                                 &
+                                   ( sk(k_pp,j,i) + sk(k-1,j,i)  )             &
+                    +      (           ibit8 * adv_sca_5                       &
+                           ) *     ( sk(k_ppp,j,i)+ sk(k_mm,j,i) )             &
+                                                       )
+
+                diss_t(k) = -ABS( w(k,j,i) ) * rho_air_zw(k) * (               &
+                           ( 10.0_wp * ibit8 * adv_sca_5                       &
+                        +     3.0_wp * ibit7 * adv_sca_3                       &
+                        +              ibit6 * adv_sca_1                       &
+                           ) *                                                 &
+                                   ( sk(k+1,j,i)   - sk(k,j,i)    )            &
+                    -      (  5.0_wp * ibit8 * adv_sca_5                       &
+                        +              ibit7 * adv_sca_3                       &
+                           ) *                                                 &
+                                   ( sk(k_pp,j,i)  - sk(k-1,j,i)  )            &
+                    +      (           ibit8 * adv_sca_5                       &
+                           ) *                                                 &
+                                   ( sk(k_ppp,j,i) - sk(k_mm,j,i) )            &
+                                                               )
              ENDDO
 
-             DO  k = nzb_max_l+1, nzt
-
-                u_comp = u(k,j,i+1) - u_gtrans + u_stokes_zu(k)
-                flux_r = u_comp * (                                           &
-                      37.0_wp * ( sk(k,j,i+1) + sk(k,j,i)   )                 &
-                    -  8.0_wp * ( sk(k,j,i+2) + sk(k,j,i-1) )                 &
-                    +           ( sk(k,j,i+3) + sk(k,j,i-2) ) ) * adv_sca_5
-                diss_r = -ABS( u_comp ) * (                                   &
-                      10.0_wp * ( sk(k,j,i+1) - sk(k,j,i)   )                 &
-                    -  5.0_wp * ( sk(k,j,i+2) - sk(k,j,i-1) )                 &
-                    +           ( sk(k,j,i+3) - sk(k,j,i-2) ) ) * adv_sca_5
-
-#ifdef _OPENACC
-!
-!--             Recompute the left fluxes.
-                u_comp_l = u(k,j,i) - u_gtrans + u_stokes_zu(k)
-                flux_l = u_comp_l * (                                         &
-                                      37.0_wp * ( sk(k,j,i)   + sk(k,j,i-1) ) &
-                                    -  8.0_wp * ( sk(k,j,i+1) + sk(k,j,i-2) ) &
-                                    +           ( sk(k,j,i+2) + sk(k,j,i-3) ) &
-                                               ) * adv_sca_5
-
-                diss_l = -ABS( u_comp_l ) * (                                 &
-                                      10.0_wp * ( sk(k,j,i)   - sk(k,j,i-1) ) &
-                                    -  5.0_wp * ( sk(k,j,i+1) - sk(k,j,i-2) ) &
-                                    +           ( sk(k,j,i+2) - sk(k,j,i-3) ) &
-                                                       ) * adv_sca_5
-#else
-                flux_l = swap_flux_x_local(k,j)
-                diss_l = swap_diss_x_local(k,j)
-#endif
-
-                v_comp = v(k,j+1,i) - v_gtrans + v_stokes_zu(k)
-                flux_n = v_comp * (                                           &
-                      37.0_wp * ( sk(k,j+1,i) + sk(k,j,i)   )                 &
-                    -  8.0_wp * ( sk(k,j+2,i) + sk(k,j-1,i) )                 &
-                    +           ( sk(k,j+3,i) + sk(k,j-2,i) ) ) * adv_sca_5
-                diss_n = -ABS( v_comp ) * (                                   &
-                      10.0_wp * ( sk(k,j+1,i) - sk(k,j,i)   )                 &
-                    -  5.0_wp * ( sk(k,j+2,i) - sk(k,j-1,i) )                 &
-                    +           ( sk(k,j+3,i) - sk(k,j-2,i) ) ) * adv_sca_5
-
-#ifdef _OPENACC
-!
-!--             Recompute the south fluxes.
-                v_comp_s = v(k,j,i) - v_gtrans + v_stokes_zu(k)
-                flux_s = v_comp_s * (                                        &
-                                    37.0_wp * ( sk(k,j,i)   + sk(k,j-1,i) )  &
-                                  -  8.0_wp * ( sk(k,j+1,i) + sk(k,j-2,i) )  &
-                                  +           ( sk(k,j+2,i) + sk(k,j-3,i) )  &
-                                             ) * adv_sca_5
-                diss_s = -ABS( v_comp_s ) * (                                &
-                                    10.0_wp * ( sk(k,j,i)   - sk(k,j-1,i) )  &
-                                  -  5.0_wp * ( sk(k,j+1,i) - sk(k,j-2,i) )  &
-                                  +             sk(k,j+2,i) - sk(k,j-3,i)    &
-                                                      ) * adv_sca_5
-#else
-                flux_s = swap_flux_y_local(k)
-                diss_s = swap_diss_y_local(k)
-#endif
-
-!
-!--             k index has to be modified near bottom and top, else array
-!--             subscripts will be exceeded.
+             DO  k = nzb+2, nzt-2
                 ibit8 = REAL( IBITS(advc_flag(k,j,i),8,1), KIND = wp )
                 ibit7 = REAL( IBITS(advc_flag(k,j,i),7,1), KIND = wp )
                 ibit6 = REAL( IBITS(advc_flag(k,j,i),6,1), KIND = wp )
 
+                flux_t(k) = w(k,j,i) * rho_air_zw(k) * (                       &
+                           ( 37.0_wp * ibit8 * adv_sca_5                       &
+                        +     7.0_wp * ibit7 * adv_sca_3                       &
+                        +              ibit6 * adv_sca_1                       &
+                           ) *                                                 &
+                                   ( sk(k+1,j,i)  + sk(k,j,i)    )             &
+                    -      (  8.0_wp * ibit8 * adv_sca_5                       &
+                        +              ibit7 * adv_sca_3                       &
+                           ) *                                                 &
+                                   ( sk(k+2,j,i) + sk(k-1,j,i)  )              &
+                    +      (           ibit8 * adv_sca_5                       &
+                           ) *     ( sk(k+3,j,i)+ sk(k-2,j,i) )                &
+                                                       )
+
+                diss_t(k) = -ABS( w(k,j,i) ) * rho_air_zw(k) * (               &
+                           ( 10.0_wp * ibit8 * adv_sca_5                       &
+                        +     3.0_wp * ibit7 * adv_sca_3                       &
+                        +              ibit6 * adv_sca_1                       &
+                           ) *                                                 &
+                                   ( sk(k+1,j,i)   - sk(k,j,i)    )            &
+                    -      (  5.0_wp * ibit8 * adv_sca_5                       &
+                        +              ibit7 * adv_sca_3                       &
+                           ) *                                                 &
+                                   ( sk(k+2,j,i)  - sk(k-1,j,i)  )             &
+                    +      (           ibit8 * adv_sca_5                       &
+                           ) *                                                 &
+                                   ( sk(k+3,j,i) - sk(k-2,j,i) )               &
+                                                               )
+             ENDDO
+
+             DO  k = nzt-1, nzt-symmetry_flag
+                ibit8 = REAL( IBITS(advc_flag(k,j,i),8,1), KIND = wp )
+                ibit7 = REAL( IBITS(advc_flag(k,j,i),7,1), KIND = wp )
+                ibit6 = REAL( IBITS(advc_flag(k,j,i),6,1), KIND = wp )
+!
+!--             k index has to be modified near bottom and top, else array
+!--             subscripts will be exceeded.
                 k_ppp = k + 3 * ibit8
                 k_pp  = k + 2 * ( 1 - ibit6  )
                 k_mm  = k - 2 * ibit8
 
-
-                flux_t = w(k,j,i) * rho_air_zw(k) * (                         &
-                           ( 37.0_wp * ibit8 * adv_sca_5                      &
-                        +     7.0_wp * ibit7 * adv_sca_3                      &
-                        +              ibit6 * adv_sca_1                      &
-                           ) *                                                &
-                                   ( sk(k+1,j,i)  + sk(k,j,i)     )           &
-                    -      (  8.0_wp * ibit8 * adv_sca_5                      &
-                        +              ibit7 * adv_sca_3                      &
-                           ) *                                                &
-                                   ( sk(k_pp,j,i) + sk(k-1,j,i)   )           &
-                    +      (           ibit8 * adv_sca_5                      &
-                           ) *     ( sk(k_ppp,j,i)+ sk(k_mm,j,i)  )           &
-                                       )
-
-                diss_t = -ABS( w(k,j,i) ) * rho_air_zw(k) * (                 &
-                           ( 10.0_wp * ibit8 * adv_sca_5                      &
-                        +     3.0_wp * ibit7 * adv_sca_3                      &
-                        +              ibit6 * adv_sca_1                      &
-                           ) *                                                &
-                                   ( sk(k+1,j,i)   - sk(k,j,i)    )           &
-                    -      (  5.0_wp * ibit8 * adv_sca_5                      &
-                        +              ibit7 * adv_sca_3                      &
-                           ) *                                                &
-                                   ( sk(k_pp,j,i)  - sk(k-1,j,i)  )           &
-                    +      (           ibit8 * adv_sca_5                      &
-                           ) *                                                &
-                                   ( sk(k_ppp,j,i) - sk(k_mm,j,i) )           &
-                                               )
+                flux_t(k) = w(k,j,i) * rho_air_zw(k) * (                       &
+                           ( 37.0_wp * ibit8 * adv_sca_5                       &
+                        +     7.0_wp * ibit7 * adv_sca_3                       &
+                        +              ibit6 * adv_sca_1                       &
+                           ) *                                                 &
+                                   ( sk(k+1,j,i)  + sk(k,j,i)    )             &
+                    -      (  8.0_wp * ibit8 * adv_sca_5                       &
+                        +              ibit7 * adv_sca_3                       &
+                           ) *                                                 &
+                                   ( sk(k_pp,j,i) + sk(k-1,j,i)  )             &
+                    +      (           ibit8 * adv_sca_5                       &
+                           ) *     ( sk(k_ppp,j,i)+ sk(k_mm,j,i) )             &
+                                                       )
+
+                diss_t(k) = -ABS( w(k,j,i) ) * rho_air_zw(k) * (               &
+                           ( 10.0_wp * ibit8 * adv_sca_5                       &
+                        +     3.0_wp * ibit7 * adv_sca_3                       &
+                        +              ibit6 * adv_sca_1                       &
+                           ) *                                                 &
+                                   ( sk(k+1,j,i)   - sk(k,j,i)    )            &
+                    -      (  5.0_wp * ibit8 * adv_sca_5                       &
+                        +              ibit7 * adv_sca_3                       &
+                           ) *                                                 &
+                                   ( sk(k_pp,j,i)  - sk(k-1,j,i)  )            &
+                    +      (           ibit8 * adv_sca_5                       &
+                           ) *                                                 &
+                                   ( sk(k_ppp,j,i) - sk(k_mm,j,i) )            &
+                                                               )
+             ENDDO
+
+!
+!--          Set resolved/turbulent flux at model top to zero (w-level). In case that
+!--          a symmetric behavior between bottom and top shall be guaranteed (closed
+!--          channel flow), the flux at nzt is also set to zero.
+             IF ( symmetry_flag == 1 ) THEN
+                flux_t(nzt) = 0.0_wp
+                diss_t(nzt) = 0.0_wp
+             ENDIF
+             flux_t(nzt+1) = 0.0_wp
+             diss_t(nzt+1) = 0.0_wp
+
+             DO  k = nzb+1, nzb_max_l
+
+                flux_d    = flux_t(k-1)
+                diss_d    = diss_t(k-1)
+
+                ibit2 = REAL( IBITS(advc_flag(k,j,i),2,1), KIND = wp )
+                ibit1 = REAL( IBITS(advc_flag(k,j,i),1,1), KIND = wp )
+                ibit0 = REAL( IBITS(advc_flag(k,j,i),0,1), KIND = wp )
+
+                ibit5 = REAL( IBITS(advc_flag(k,j,i),5,1), KIND = wp )
+                ibit4 = REAL( IBITS(advc_flag(k,j,i),4,1), KIND = wp )
+                ibit3 = REAL( IBITS(advc_flag(k,j,i),3,1), KIND = wp )
+
+                ibit8 = REAL( IBITS(advc_flag(k,j,i),8,1), KIND = wp )
+                ibit7 = REAL( IBITS(advc_flag(k,j,i),7,1), KIND = wp )
+                ibit6 = REAL( IBITS(advc_flag(k,j,i),6,1), KIND = wp )
 !
 !--             Calculate the divergence of the velocity field. A respective
 !--             correction is needed to overcome numerical instabilities introduced
 !--             by a not sufficient reduction of divergences near topography.
-                div         =   ( u(k,j,i+1) - u(k,j,i)   ) * ddx              &
-                              + ( v(k,j+1,i) - v(k,j,i)   ) * ddy              &
-                              + ( w(k,j,i)   * rho_air_zw(k) -                 &
-                                  w(k-1,j,i) * rho_air_zw(k-1)                 &
+                div         =   ( u(k,j,i+1) * ( ibit0 + ibit1 + ibit2 )       &
+                                - u(k,j,i)   * (                               &
+                              REAL( IBITS(advc_flag(k,j,i-1),0,1), KIND = wp ) &
+                            + REAL( IBITS(advc_flag(k,j,i-1),1,1), KIND = wp ) &
+                            + REAL( IBITS(advc_flag(k,j,i-1),2,1), KIND = wp ) &
+                                               )                               &
+                                ) * ddx                                        &
+                              + ( v(k,j+1,i) * ( ibit3 + ibit4 + ibit5 )       &
+                                - v(k,j,i)   * (                               &
+                              REAL( IBITS(advc_flag(k,j-1,i),3,1), KIND = wp ) &
+                            + REAL( IBITS(advc_flag(k,j-1,i),4,1), KIND = wp ) &
+                            + REAL( IBITS(advc_flag(k,j-1,i),5,1), KIND = wp ) &
+                                               )                               &
+                                ) * ddy                                        &
+                              + ( w(k,j,i) * rho_air_zw(k) *                   &
+                                               ( ibit6 + ibit7 + ibit8 )       &
+                                - w(k-1,j,i) * rho_air_zw(k-1) *               &
+                                               (                               &
+                              REAL( IBITS(advc_flag(k-1,j,i),6,1), KIND = wp ) &
+                            + REAL( IBITS(advc_flag(k-1,j,i),7,1), KIND = wp ) &
+                            + REAL( IBITS(advc_flag(k-1,j,i),8,1), KIND = wp ) &
+                                               )                               &
                                 ) * drho_air(k) * ddzw(k)
 
-                tend(k,j,i) = tend(k,j,i) - (                                 &
-                        ( ( flux_r + diss_r )                                 &
-                      -   ( flux_l + diss_l ) ) * ddx                         &
-                      + ( ( flux_n + diss_n )                                 &
-                      -   ( flux_s + diss_s ) ) * ddy                         &
-                      + ( ( flux_t + diss_t )                                 &
-                      -   ( flux_d + diss_d ) ) * drho_air(k) * ddzw(k)       &
+                tend(k,j,i) = tend(k,j,i) - (                                  &
+                         ( flux_r(k) + diss_r(k) - swap_flux_x_local(k,j,tn) - &
+                           swap_diss_x_local(k,j,tn)            ) * ddx        &
+                       + ( flux_n(k) + diss_n(k) - swap_flux_y_local(k,tn)   - &
+                           swap_diss_y_local(k,tn)              ) * ddy        &
+                       + ( ( flux_t(k) + diss_t(k) ) -                         &
+                           ( flux_d    + diss_d    )                           &
+                                                                )              &
+                          * drho_air(k) * ddzw(k) &
                                             ) + sk(k,j,i) * div
 
 #ifndef _OPENACC
-                swap_flux_y_local(k)   = flux_n
-                swap_diss_y_local(k)   = diss_n
-                swap_flux_x_local(k,j) = flux_r
-                swap_diss_x_local(k,j) = diss_r
+                swap_flux_y_local(k,tn)   = flux_n(k)
+                swap_diss_y_local(k,tn)   = diss_n(k)
+                swap_flux_x_local(k,j,tn) = flux_r(k)
+                swap_diss_x_local(k,j,tn) = diss_r(k)
 #endif
-                flux_d                 = flux_t
-                diss_d                 = diss_t
-
-!
-!--             Evaluation of statistics. 
-                SELECT CASE ( sk_num )
-
-                    CASE ( 1 )
+
+             ENDDO
+
+             DO  k = nzb_max_l+1, nzt
+
+                flux_d    = flux_t(k-1)
+                diss_d    = diss_t(k-1)
+!
+!--             Calculate the divergence of the velocity field. A respective
+!--             correction is needed to overcome numerical instabilities introduced
+!--             by a not sufficient reduction of divergences near topography.
+                div         =   ( u(k,j,i+1) - u(k,j,i) ) * ddx                &
+                              + ( v(k,j+1,i) - v(k,j,i) ) * ddy                &
+                              + ( w(k,j,i) * rho_air_zw(k)                     &
+                                - w(k-1,j,i) * rho_air_zw(k-1)                 &
+                                                        ) * drho_air(k) * ddzw(k)
+
+                tend(k,j,i) = tend(k,j,i) - (                                  &
+                         ( flux_r(k) + diss_r(k) - swap_flux_x_local(k,j,tn) - &
+                           swap_diss_x_local(k,j,tn)            ) * ddx        &
+                       + ( flux_n(k) + diss_n(k) - swap_flux_y_local(k,tn)   - &
+                           swap_diss_y_local(k,tn)              ) * ddy        &
+                       + ( ( flux_t(k) + diss_t(k) ) -                         &
+                           ( flux_d    + diss_d    )            )              &
+                           * drho_air(k) * ddzw(k)                             &
+                                            ) + sk(k,j,i) * div
+
+#ifndef _OPENACC
+                swap_flux_y_local(k,tn)   = flux_n(k)
+                swap_diss_y_local(k,tn)   = diss_n(k)
+                swap_flux_x_local(k,j,tn) = flux_r(k)
+                swap_diss_x_local(k,j,tn) = diss_r(k)
+#endif
+            ENDDO
+
+!
+!--         Evaluation of statistics.
+            DO  k = nzb+1, nzt
+               SELECT CASE ( sk_num )
+
+                   CASE ( 1 )
+                      !$ACC ATOMIC
+                      sums_wspts_ws_l(k,tn) = sums_wspts_ws_l(k,tn)            &
+                         + ( flux_t(k)                                         &
+                               / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )   &
+                               * ( w(k,j,i) - hom(k,1,3,0)                 )   &
+                           + diss_t(k)                                         &
+                               / ( ABS(w(k,j,i)) + 1.0E-20_wp              )   &
+                               *   ABS(w(k,j,i) - hom(k,1,3,0)             )   &
+                           ) * weight_substep(intermediate_timestep_count)
+                   CASE ( 2 )
+                      !$ACC ATOMIC
+                      sums_wssas_ws_l(k,tn) = sums_wssas_ws_l(k,tn)            &
+                         + ( flux_t(k)                                         &
+                               / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )   &
+                               * ( w(k,j,i) - hom(k,1,3,0)                 )   &
+                           + diss_t(k)                                         &
+                               / ( ABS(w(k,j,i)) + 1.0E-20_wp              )   &
+                               *   ABS(w(k,j,i) - hom(k,1,3,0)             )   &
+                           ) * weight_substep(intermediate_timestep_count)
+                   CASE ( 3 )
+                      !$ACC ATOMIC
+                      sums_wsqs_ws_l(k,tn)  = sums_wsqs_ws_l(k,tn)             &
+                         + ( flux_t(k)                                         &
+                               / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )   &
+                               * ( w(k,j,i) - hom(k,1,3,0)                 )   &
+                           + diss_t(k)                                         &
+                               / ( ABS(w(k,j,i)) + 1.0E-20_wp              )   &
+                               *   ABS(w(k,j,i) - hom(k,1,3,0)             )   &
+                           ) * weight_substep(intermediate_timestep_count)
+                   CASE ( 4 )
+                      !$ACC ATOMIC
+                      sums_wsqcs_ws_l(k,tn)  = sums_wsqcs_ws_l(k,tn)           &
+                         + ( flux_t(k)                                         &
+                               / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )   &
+                               * ( w(k,j,i) - hom(k,1,3,0)                 )   &
+                           + diss_t(k)                                         &
+                               / ( ABS(w(k,j,i)) + 1.0E-20_wp              )   &
+                               *   ABS(w(k,j,i) - hom(k,1,3,0)             )   &
+                           ) * weight_substep(intermediate_timestep_count)
+                   CASE ( 5 )
+                      !$ACC ATOMIC
+                      sums_wsqrs_ws_l(k,tn)  = sums_wsqrs_ws_l(k,tn)           &
+                         + ( flux_t(k)                                         &
+                               / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )   &
+                               * ( w(k,j,i) - hom(k,1,3,0)                 )   &
+                           + diss_t(k)                                         &
+                               / ( ABS(w(k,j,i)) + 1.0E-20_wp              )   &
+                               *   ABS(w(k,j,i) - hom(k,1,3,0)             )   &
+                           ) * weight_substep(intermediate_timestep_count)
+                   CASE ( 6 )
+                      !$ACC ATOMIC
+                      sums_wsncs_ws_l(k,tn)  = sums_wsncs_ws_l(k,tn)           &
+                         + ( flux_t(k)                                         &
+                               / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )   &
+                               * ( w(k,j,i) - hom(k,1,3,0)                 )   &
+                           + diss_t(k)                                         &
+                               / ( ABS(w(k,j,i)) + 1.0E-20_wp              )   &
+                               *   ABS(w(k,j,i) - hom(k,1,3,0)             )   &
+                           ) * weight_substep(intermediate_timestep_count)
+                   CASE ( 7 )
+                      !$ACC ATOMIC
+                      sums_wsnrs_ws_l(k,tn)  = sums_wsnrs_ws_l(k,tn)           &
+                         + ( flux_t(k)                                         &
+                               / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )   &
+                               * ( w(k,j,i) - hom(k,1,3,0)                 )   &
+                           + diss_t(k)                                         &
+                               / ( ABS(w(k,j,i)) + 1.0E-20_wp              )   &
+                               *   ABS(w(k,j,i) - hom(k,1,3,0)             )   &
+                           ) * weight_substep(intermediate_timestep_count)
+                   CASE ( 8 )
+                      !$ACC ATOMIC
+                      sums_wsss_ws_l(k,tn)  = sums_wsss_ws_l(k,tn)             &
+                         + ( flux_t(k)                                         &
+                               / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )   &
+                               * ( w(k,j,i) - hom(k,1,3,0)                 )   &
+                           + diss_t(k)                                         &
+                               / ( ABS(w(k,j,i)) + 1.0E-20_wp              )   &
+                               *   ABS(w(k,j,i) - hom(k,1,3,0)             )   &
+                           ) * weight_substep(intermediate_timestep_count)
+                   CASE ( 9 )
                        !$ACC ATOMIC
-                       sums_wspts_ws_l(k,tn) = sums_wspts_ws_l(k,tn)           &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 2 )
-                       !$ACC ATOMIC
-                       sums_wssas_ws_l(k,tn) = sums_wssas_ws_l(k,tn)           &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 3 )
-                       !$ACC ATOMIC
-                       sums_wsqs_ws_l(k,tn)  = sums_wsqs_ws_l(k,tn)            &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 4 )
-                       !$ACC ATOMIC
-                       sums_wsqcs_ws_l(k,tn)  = sums_wsqcs_ws_l(k,tn)          &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 5 )
-                       !$ACC ATOMIC
-                       sums_wsqrs_ws_l(k,tn)  = sums_wsqrs_ws_l(k,tn)          &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 6 )
-                       !$ACC ATOMIC
-                       sums_wsncs_ws_l(k,tn)  = sums_wsncs_ws_l(k,tn)          &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 7 )
-                       !$ACC ATOMIC
-                       sums_wsnrs_ws_l(k,tn)  = sums_wsnrs_ws_l(k,tn)          &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 8 )
-                       !$ACC ATOMIC
-                       sums_wsss_ws_l(k,tn)  = sums_wsss_ws_l(k,tn)            &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
-                    CASE ( 9 )
-                        !$ACC ATOMIC
-                        sums_salsa_ws_l(k,tn)  = sums_salsa_ws_l(k,tn)         &
-                          + ( flux_t                                           &
-                                / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )  &
-                                * ( w(k,j,i) - hom(k,1,3,0)                 )  &
-                            + diss_t                                           &
-                                / ( ABS(w(k,j,i)) + 1.0E-20_wp              )  &
-                                *   ABS(w(k,j,i) - hom(k,1,3,0)             )  &
-                            ) * weight_substep(intermediate_timestep_count)
+                       sums_salsa_ws_l(k,tn)  = sums_salsa_ws_l(k,tn)          &
+                         + ( flux_t(k)                                         &
+                               / ( w(k,j,i) + SIGN( 1.0E-20_wp, w(k,j,i) ) )   &
+                               * ( w(k,j,i) - hom(k,1,3,0)                 )   &
+                           + diss_t(k)                                         &
+                               / ( ABS(w(k,j,i)) + 1.0E-20_wp              )   &
+                               *   ABS(w(k,j,i) - hom(k,1,3,0)             )   &
+                           ) * weight_substep(intermediate_timestep_count)
 
                 END SELECT
 
              ENDDO
-
-         ENDDO
-      ENDDO
+          ENDDO
+       ENDDO
+
+       CALL cpu_log( log_point_s(49), 'advec_s_ws', 'stop' )
 
     END SUBROUTINE advec_s_ws
@@ -4553,7 +4519,7 @@
        INTEGER(iwp) ::  k_pp      !< k+2 index in disretization, can be modified to avoid segmentation faults
        INTEGER(iwp) ::  k_ppp     !< k+3 index in disretization, can be modified to avoid segmentation faults
-       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms 
-       INTEGER(iwp) ::  tn = 0    !< number of OpenMP thread
-       
+       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms
+       INTEGER(iwp) ::  tn = 0    !< number of OpenMP thread (is always zero here)
+
        REAL(wp)    ::  ibit0 !< flag indicating 1st-order scheme along x-direction
        REAL(wp)    ::  ibit1 !< flag indicating 3rd-order scheme along x-direction
@@ -4579,112 +4545,22 @@
        REAL(wp)    ::  flux_d !< 6th-order flux at grid box bottom
        REAL(wp)    ::  gu     !< Galilei-transformation velocity along x
-       REAL(wp)    ::  gv     !< Galilei-transformation velocity along y 
-       REAL(wp)    ::  v_comp !< advection velocity along y
-#ifdef _OPENACC
+       REAL(wp)    ::  gv     !< Galilei-transformation velocity along y
+       REAL(wp)    ::  u_comp_l !<
        REAL(wp)    ::  v_comp_s !< advection velocity along y
-#endif
-       REAL(wp)    ::  w_comp !< advection velocity along z
-       
-       REAL(wp)    :: diss_s  !< discretized artificial dissipation at southward-side of the grid box
-       REAL(wp)    :: flux_s  !< discretized 6th-order flux at southward-side of the grid box
-#ifndef _OPENACC
-       REAL(wp), DIMENSION(nzb+1:nzt) ::  swap_diss_y_local_u !< discretized artificial dissipation at southward-side of the grid box
-       REAL(wp), DIMENSION(nzb+1:nzt) ::  swap_flux_y_local_u !< discretized 6th-order flux at southward-side of the grid box
-#endif
-       
-       REAL(wp)    :: diss_l  !< discretized artificial dissipation at leftward-side of the grid box
-       REAL(wp)    :: flux_l  !< discretized 6th-order flux at leftward-side of the grid box
-#ifndef _OPENACC
-       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn) ::  swap_diss_x_local_u !< discretized artificial dissipation at leftward-side of the grid box
-       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn) ::  swap_flux_x_local_u !< discretized 6th-order flux at leftward-side of the grid box
-#endif
-       
-       REAL(wp) ::  diss_n !< discretized artificial dissipation at northward-side of the grid box
-       REAL(wp) ::  diss_r !< discretized artificial dissipation at leftward-side of the grid box
-       REAL(wp) ::  diss_t !< discretized artificial dissipation at top of the grid box
-       REAL(wp) ::  flux_n !< discretized 6th-order flux at northward-side of the grid box
-       REAL(wp) ::  flux_r !< discretized 6th-order flux at rightward-side of the grid box
-       REAL(wp) ::  flux_t !< discretized 6th-order flux at top of the grid box
-       REAL(wp) ::  u_comp !< advection velocity along x
-#ifdef _OPENACC
-       REAL(wp)    ::  u_comp_l !<
-#endif
-!
-!--    Set local version of nzb_max. At non-cyclic boundaries the order of the 
-!--    advection need to be degraded near the boundary. Please note, in contrast
-!--    to the cache-optimized routines, nzb_max_l is set constantly for the 
-!--    entire subdomain, in order to avoid unsymmetric loops which might be 
-!--    an issue for GPUs.
-       IF( bc_dirichlet_l  .OR.  bc_radiation_l  .OR.                          &
-           bc_dirichlet_r  .OR.  bc_radiation_r  .OR.                          &
-           bc_dirichlet_s  .OR.  bc_radiation_s  .OR.                          &
-           bc_dirichlet_n  .OR.  bc_radiation_n )  THEN
-          nzb_max_l = nzt
-       ELSE
-          nzb_max_l = nzb_max
-       END IF 
- 
+
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  diss_n !< discretized artificial dissipation at northward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  diss_r !< discretized artificial dissipation at rightward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  diss_t !< discretized artificial dissipation at top of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  flux_n !< discretized 6th-order flux at northward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  flux_r !< discretized 6th-order flux at rightward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  flux_t !< discretized 6th-order flux at top of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  u_comp !< advection velocity along x
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  v_comp !< advection velocity along y
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  w_comp !< advection velocity along z
+
+       CALL cpu_log( log_point_s(68), 'advec_u_ws', 'start' )
+
        gu = 2.0_wp * u_gtrans
        gv = 2.0_wp * v_gtrans
-
-#ifndef _OPENACC
-!
-!--    Compute the fluxes for the whole left boundary of the processor domain.
-       i = nxlu
-       DO  j = nys, nyn
-          DO  k = nzb+1, nzb_max_l
-
-             ibit2 = REAL( IBITS(advc_flags_m(k,j,i-1),2,1), KIND = wp )
-             ibit1 = REAL( IBITS(advc_flags_m(k,j,i-1),1,1), KIND = wp )
-             ibit0 = REAL( IBITS(advc_flags_m(k,j,i-1),0,1), KIND = wp )
-
-             u_comp                   = u(k,j,i) + u(k,j,i-1) - gu
-             swap_flux_x_local_u(k,j) = u_comp * (                             &
-                                       ( 37.0_wp * ibit2 * adv_mom_5           &
-                                    +     7.0_wp * ibit1 * adv_mom_3           &
-                                    +              ibit0 * adv_mom_1           &
-                                       ) *                                     &
-                                     ( u(k,j,i)   + u(k,j,i-1) )               &
-                                -      (  8.0_wp * ibit2 * adv_mom_5           &
-                                    +              ibit1 * adv_mom_3           &
-                                       ) *                                     &
-                                     ( u(k,j,i+1) + u(k,j,i-2) )               &
-                                +      (           ibit2 * adv_mom_5           &
-                                       ) *                                     &
-                                     ( u(k,j,i+2) + u(k,j,i-3) )               &
-                                                   )
-
-              swap_diss_x_local_u(k,j) = - ABS( u_comp ) * (                   &
-                                       ( 10.0_wp * ibit2 * adv_mom_5           &
-                                    +     3.0_wp * ibit1 * adv_mom_3           &
-                                    +              ibit0 * adv_mom_1          &
-                                       ) *                                     &
-                                     ( u(k,j,i)   - u(k,j,i-1) )               &
-                                -      (  5.0_wp * ibit2 * adv_mom_5           &
-                                    +              ibit1 * adv_mom_3           &
-                                       ) *                                     &
-                                     ( u(k,j,i+1) - u(k,j,i-2) )               &
-                                +      (           ibit2 * adv_mom_5           &
-                                       ) *                                     &
-                                     ( u(k,j,i+2) - u(k,j,i-3) )               &
-                                                             )
-
-          ENDDO
-
-          DO  k = nzb_max_l+1, nzt
-
-             u_comp            = u(k,j,i) + u(k,j,i-1) - gu
-             swap_flux_x_local_u(k,j) = u_comp * (                             &
-                             37.0_wp * ( u(k,j,i) + u(k,j,i-1)   )             &
-                           -  8.0_wp * ( u(k,j,i+1) + u(k,j,i-2) )             &
-                           +           ( u(k,j,i+2) + u(k,j,i-3) ) ) * adv_mom_5
-             swap_diss_x_local_u(k,j) = - ABS(u_comp) * (                      &
-                             10.0_wp * ( u(k,j,i) - u(k,j,i-1)   )             &
-                           -  5.0_wp * ( u(k,j,i+1) - u(k,j,i-2) )             &
-                           +           ( u(k,j,i+2) - u(k,j,i-3) ) ) * adv_mom_5
-
-          ENDDO
-       ENDDO
-#endif
 
        !$ACC PARALLEL LOOP COLLAPSE(2) FIRSTPRIVATE(tn, gu, gv) &
@@ -4694,7 +4570,8 @@
        !$ACC PRIVATE(ibit3_s, ibit4_s, ibit5_s) &
        !$ACC PRIVATE(ibit6, ibit7, ibit8) &
-       !$ACC PRIVATE(flux_r, diss_r, flux_l, diss_l) &
-       !$ACC PRIVATE(flux_n, diss_n, flux_s, diss_s) &
+       !$ACC PRIVATE(flux_r, diss_r) &
+       !$ACC PRIVATE(flux_n, diss_n) &
        !$ACC PRIVATE(flux_t, diss_t, flux_d, diss_d) &
+       !$ACC PRIVATE(flux_l_u, diss_l_u, flux_s_u, diss_s_u) &
        !$ACC PRIVATE(div, u_comp, u_comp_l, v_comp, v_comp_s, w_comp) &
        !$ACC PRESENT(advc_flags_m) &
@@ -4702,73 +4579,144 @@
        !$ACC PRESENT(drho_air, rho_air_zw, ddzw) &
        !$ACC PRESENT(tend) &
-       !$ACC PRESENT(hom(nzb+1:nzb_max_l,1,1:3,0)) &
+       !$ACC PRESENT(hom(:,1,1:3,0)) &
        !$ACC PRESENT(weight_substep(intermediate_timestep_count)) &
        !$ACC PRESENT(sums_us2_ws_l, sums_wsus_ws_l)
-       DO i = nxlu, nxr
+       DO  i = nxlu, nxr
+
+          DO  j = nys, nyn
+!
+!--          Used local modified copy of nzb_max (used to degrade order of
+!--          discretization) at non-cyclic boundaries. Modify only at relevant points
+!--          instead of the entire subdomain. This should lead to better
+!--          load balance between boundary and non-boundary PEs.
+             IF( ( bc_dirichlet_l  .OR.  bc_radiation_l )  .AND.  i <= nxl + 2  .OR. &
+                 ( bc_dirichlet_r  .OR.  bc_radiation_r )  .AND.  i >= nxr - 2  .OR. &
+                 ( bc_dirichlet_s  .OR.  bc_radiation_s )  .AND.  j <= nys + 2  .OR. &
+                 ( bc_dirichlet_n  .OR.  bc_radiation_n )  .AND.  j >= nyn - 2 )  THEN
+                nzb_max_l = nzt
+             ELSE
+                nzb_max_l = nzb_max
+             END IF
 #ifndef _OPENACC
-!       
-!--       The following loop computes the fluxes for the south boundary points
-          j = nys
-          DO  k = nzb+1, nzb_max_l
-
-             ibit5 = REAL( IBITS(advc_flags_m(k,j-1,i),5,1), KIND = wp )
-             ibit4 = REAL( IBITS(advc_flags_m(k,j-1,i),4,1), KIND = wp )
-             ibit3 = REAL( IBITS(advc_flags_m(k,j-1,i),3,1), KIND = wp )
-
-             v_comp                 = v(k,j,i) + v(k,j,i-1) - gv
-             swap_flux_y_local_u(k) = v_comp * (                               &
-                                   ( 37.0_wp * ibit5 * adv_mom_5               &
-                                +     7.0_wp * ibit4 * adv_mom_3               &
-                                +              ibit3 * adv_mom_1               &
-                                   ) *                                         &
-                                     ( u(k,j,i)   + u(k,j-1,i) )               &
-                            -      (  8.0_wp * ibit5 * adv_mom_5               &
-                            +                  ibit4 * adv_mom_3               &
-                                   ) *                                         &
-                                     ( u(k,j+1,i) + u(k,j-2,i) )               &
-                        +      (               ibit5 * adv_mom_5               &
-                               ) *                                             &
-                                     ( u(k,j+2,i) + u(k,j-3,i) )               &
-                                               )                              
-                                                                              
-             swap_diss_y_local_u(k) = - ABS ( v_comp ) * (                     &
-                                   ( 10.0_wp * ibit5 * adv_mom_5               &
-                                +     3.0_wp * ibit4 * adv_mom_3               &
-                                +              ibit3 * adv_mom_1               &
-                                   ) *                                         &
-                                     ( u(k,j,i)   - u(k,j-1,i) )               &
-                            -      (  5.0_wp * ibit5 * adv_mom_5               &
-                                +              ibit4 * adv_mom_3               &
-                                   ) *                                         &
-                                     ( u(k,j+1,i) - u(k,j-2,i) )               &
-                            +      (           ibit5 * adv_mom_5               &
-                                   ) *                                         &
-                                     ( u(k,j+2,i) - u(k,j-3,i) )               &
-                                                         )
-
-          ENDDO
-
-          DO  k = nzb_max_l+1, nzt
-
-             v_comp                 = v(k,j,i) + v(k,j,i-1) - gv
-             swap_flux_y_local_u(k) = v_comp * (                               &
-                           37.0_wp * ( u(k,j,i)   + u(k,j-1,i) )               &
-                         -  8.0_wp * ( u(k,j+1,i) + u(k,j-2,i) )               &
-                         +           ( u(k,j+2,i) + u(k,j-3,i) ) ) * adv_mom_5
-             swap_diss_y_local_u(k) = - ABS(v_comp) * (                        &
-                           10.0_wp * ( u(k,j,i)   - u(k,j-1,i) )               &
-                         -  5.0_wp * ( u(k,j+1,i) - u(k,j-2,i) )               &
-                         +           ( u(k,j+2,i) - u(k,j-3,i) ) ) * adv_mom_5
-
-          ENDDO
+!
+!--          Compute southside fluxes for the respective boundary of PE
+             IF ( j == nys  )  THEN
+
+                DO  k = nzb+1, nzb_max_l
+
+                   ibit5 = REAL( IBITS(advc_flags_m(k,j-1,i),5,1), KIND = wp )
+                   ibit4 = REAL( IBITS(advc_flags_m(k,j-1,i),4,1), KIND = wp )
+                   ibit3 = REAL( IBITS(advc_flags_m(k,j-1,i),3,1), KIND = wp )
+
+                   v_comp_s       = v(k,j,i) + v(k,j,i-1) - gv
+                   flux_s_u(k,tn) = v_comp_s * (                               &
+                                  ( 37.0_wp * ibit5 * adv_mom_5                &
+                               +     7.0_wp * ibit4 * adv_mom_3                &
+                               +              ibit3 * adv_mom_1                &
+                                  ) *                                          &
+                                              ( u(k,j,i)   + u(k,j-1,i) )      &
+                           -      (  8.0_wp * ibit5 * adv_mom_5                &
+                               +              ibit4 * adv_mom_3                &
+                                  ) *                                          &
+                                              ( u(k,j+1,i) + u(k,j-2,i) )      &
+                           +      (           ibit5 * adv_mom_5                &
+                                  ) *                                          &
+                                              ( u(k,j+2,i) + u(k,j-3,i) )      &
+                                                )
+
+                   diss_s_u(k,tn) = - ABS ( v_comp_s ) * (                     &
+                                  ( 10.0_wp * ibit5 * adv_mom_5                &
+                               +     3.0_wp * ibit4 * adv_mom_3                &
+                               +              ibit3 * adv_mom_1                &
+                                  ) *                                          &
+                                              ( u(k,j,i)   - u(k,j-1,i) )      &
+                           -      (  5.0_wp * ibit5 * adv_mom_5                &
+                               +              ibit4 * adv_mom_3                &
+                                  ) *                                          &
+                                              ( u(k,j+1,i) - u(k,j-2,i) )      &
+                           +      (           ibit5 * adv_mom_5                &
+                                  ) *                                          &
+                                              ( u(k,j+2,i) - u(k,j-3,i) )      &
+                                                          )
+
+                ENDDO
+
+                DO  k = nzb_max_l+1, nzt
+
+                   v_comp_s       = v(k,j,i) + v(k,j,i-1) - gv
+                   flux_s_u(k,tn) = v_comp_s * (                               &
+                                 37.0_wp * ( u(k,j,i)   + u(k,j-1,i)   )       &
+                               -  8.0_wp * ( u(k,j+1,i) + u(k,j-2,i) )         &
+                               +           ( u(k,j+2,i) + u(k,j-3,i) ) ) * adv_mom_5
+                   diss_s_u(k,tn) = - ABS( v_comp_s ) * (                      &
+                                 10.0_wp * ( u(k,j,i)   - u(k,j-1,i)   )       &
+                               -  5.0_wp * ( u(k,j+1,i) - u(k,j-2,i) )         &
+                               +           ( u(k,j+2,i) - u(k,j-3,i) ) ) * adv_mom_5
+
+                ENDDO
+
+             ENDIF
+!
+!--          Compute leftside fluxes for the respective boundary of PE
+             IF ( i == nxlu )  THEN
+
+                DO  k = nzb+1, nzb_max_l
+
+                   ibit2 = REAL( IBITS(advc_flags_m(k,j,i-1),2,1), KIND = wp )
+                   ibit1 = REAL( IBITS(advc_flags_m(k,j,i-1),1,1), KIND = wp )
+                   ibit0 = REAL( IBITS(advc_flags_m(k,j,i-1),0,1), KIND = wp )
+
+                   u_comp_l         = u(k,j,i) + u(k,j,i-1) - gu
+                   flux_l_u(k,j,tn) = u_comp_l * (                             &
+                                    ( 37.0_wp * ibit2 * adv_mom_5              &
+                                 +     7.0_wp * ibit1 * adv_mom_3              &
+                                 +              ibit0 * adv_mom_1              &
+                                    ) *                                        &
+                                                ( u(k,j,i)   + u(k,j,i-1) )    &
+                             -      (  8.0_wp * ibit2 * adv_mom_5              &
+                                 +              ibit1 * adv_mom_3              &
+                                    ) *                                        &
+                                                ( u(k,j,i+1) + u(k,j,i-2) )    &
+                             +      (           ibit2 * adv_mom_5              &
+                                    ) *                                        &
+                                                ( u(k,j,i+2) + u(k,j,i-3) )    &
+                                                 )
+
+                    diss_l_u(k,j,tn) = - ABS( u_comp_l ) * (                   &
+                                    ( 10.0_wp * ibit2 * adv_mom_5              &
+                                 +     3.0_wp * ibit1 * adv_mom_3              &
+                                 +              ibit0  * adv_mom_1             &
+                                    ) *                                        &
+                                              ( u(k,j,i)   - u(k,j,i-1) )      &
+                             -      (  5.0_wp * ibit2 * adv_mom_5              &
+                                 +              ibit1 * adv_mom_3              &
+                                    ) *                                        &
+                                              ( u(k,j,i+1) - u(k,j,i-2) )      &
+                             +      (           ibit2 * adv_mom_5              &
+                                    ) *                                        &
+                                              ( u(k,j,i+2) - u(k,j,i-3) )      &
+                                                           )
+
+                ENDDO
+
+                DO  k = nzb_max_l+1, nzt
+
+                   u_comp_l         = u(k,j,i) + u(k,j,i-1) - gu
+                   flux_l_u(k,j,tn) = u_comp_l * (                             &
+                                   37.0_wp * ( u(k,j,i)   + u(k,j,i-1)   )     &
+                                 -  8.0_wp * ( u(k,j,i+1) + u(k,j,i-2) )       &
+                                 +           ( u(k,j,i+2) + u(k,j,i-3) ) ) * adv_mom_5
+                   diss_l_u(k,j,tn) = - ABS(u_comp_l) * (                      &
+                                   10.0_wp * ( u(k,j,i)   - u(k,j,i-1)   )     &
+                                 -  5.0_wp * ( u(k,j,i+1) - u(k,j,i-2) )       &
+                                 +           ( u(k,j,i+2) - u(k,j,i-3) ) ) * adv_mom_5
+
+                ENDDO
+
+             ENDIF
 #endif
 
 !
-!--       Computation of interior fluxes and tendency terms
-          DO  j = nys, nyn
-
-             flux_d    = 0.0_wp
-             diss_d    = 0.0_wp
-
+!--          Now compute the fluxes for the horizontal and parts.
              DO  k = nzb+1, nzb_max_l
 
@@ -4777,34 +4725,34 @@
                 ibit0 = REAL( IBITS(advc_flags_m(k,j,i),0,1), KIND = wp )
 
-                u_comp = u(k,j,i+1) + u(k,j,i)
-                flux_r = ( u_comp - gu ) * (                                   &
-                          ( 37.0_wp * ibit2 * adv_mom_5                        &
-                       +     7.0_wp * ibit1 * adv_mom_3                        &
-                       +              ibit0  * adv_mom_1                       &
-                          ) *                                                  &
-                                 ( u(k,j,i+1) + u(k,j,i)   )                   &
-                   -      (  8.0_wp * ibit2 * adv_mom_5                        &
-                       +              ibit1 * adv_mom_3                        &
-                          ) *                                                  &
-                                 ( u(k,j,i+2) + u(k,j,i-1) )                   &
-                   +      (           ibit2 * adv_mom_5                        &
-                          ) *                                                  &
-                                 ( u(k,j,i+3) + u(k,j,i-2) )                   &
-                                                 )                            
-                                                                              
-                diss_r = - ABS( u_comp - gu ) * (                              &
-                          ( 10.0_wp * ibit2 * adv_mom_5                        &
-                       +     3.0_wp * ibit1 * adv_mom_3                        & 
-                       +              ibit0  * adv_mom_1                       &
-                          ) *                                                  &
-                                 ( u(k,j,i+1) - u(k,j,i)  )                    &
-                   -      (  5.0_wp * ibit2 * adv_mom_5                        &
-                       +              ibit1 * adv_mom_3                        &
-                          ) *                                                  &
-                                 ( u(k,j,i+2) - u(k,j,i-1) )                   &
-                   +      (           ibit2 * adv_mom_5                        &
-                          ) *                                                  &
-                                 ( u(k,j,i+3) - u(k,j,i-2) )                   &
-                                                     )
+                u_comp(k) = u(k,j,i+1) + u(k,j,i)
+                flux_r(k) = ( u_comp(k) - gu ) * (                             &
+                           ( 37.0_wp * ibit2 * adv_mom_5                       &
+                        +     7.0_wp * ibit1 * adv_mom_3                       &
+                        +              ibit0 * adv_mom_1                       &
+                           ) *                                                 &
+                                          ( u(k,j,i+1) + u(k,j,i)   )          &
+                    -      (  8.0_wp * ibit2 * adv_mom_5                       &
+                        +              ibit1 * adv_mom_3                       &
+                           ) *                                                 &
+                                          ( u(k,j,i+2) + u(k,j,i-1) )          &
+                    +      (           ibit2 * adv_mom_5                       &
+                           ) *                                                 &
+                                          ( u(k,j,i+3) + u(k,j,i-2) )          &
+                                                 )
+
+                diss_r(k) = - ABS( u_comp(k) - gu ) * (                        &
+                           ( 10.0_wp * ibit2 * adv_mom_5                       &
+                        +     3.0_wp * ibit1 * adv_mom_3                       &
+                        +              ibit0 * adv_mom_1                       &
+                           ) *                                                 &
+                                          ( u(k,j,i+1) - u(k,j,i)   )          &
+                    -      (  5.0_wp * ibit2 * adv_mom_5                       &
+                        +              ibit1 * adv_mom_3                       &
+                           ) *                                                 &
+                                          ( u(k,j,i+2) - u(k,j,i-1) )          &
+                    +      (           ibit2 * adv_mom_5                       &
+                           ) *                                                 &
+                                          ( u(k,j,i+3) - u(k,j,i-2) )          &
+                                                      )
 
 #ifdef _OPENACC
@@ -4815,9 +4763,9 @@
                 ibit0_l = REAL( IBITS(advc_flags_m(k,j,i-1),0,1), KIND = wp )
 
-                u_comp_l = u(k,j,i) + u(k,j,i-1) - gu
-                flux_l   = u_comp_l * (                                        &
+                u_comp_l           = u(k,j,i) + u(k,j,i-1) - gu
+                flux_l_u(k,j,tn)   = u_comp_l * (                              &
                                        ( 37.0_wp * ibit2_l * adv_mom_5         &
                                     +     7.0_wp * ibit1_l * adv_mom_3         &
-                                    +              ibit0_l  * adv_mom_1        &
+                                    +              ibit0_l * adv_mom_1         &
                                        ) *                                     &
                                      ( u(k,j,i)   + u(k,j,i-1) )               &
@@ -4829,7 +4777,7 @@
                                        ) *                                     &
                                      ( u(k,j,i+2) + u(k,j,i-3) )               &
-                                                   )
-
-                diss_l   = - ABS( u_comp_l ) * (                               &
+                                                )
+
+                diss_l_u(k,j,tn)   = - ABS( u_comp_l ) * (                     &
                                        ( 10.0_wp * ibit2_l * adv_mom_5         &
                                     +     3.0_wp * ibit1_l * adv_mom_3         &
@@ -4844,9 +4792,7 @@
                                        ) *                                     &
                                      ( u(k,j,i+2) - u(k,j,i-3) )               &
-                                                             )
-#else
-                flux_l = swap_flux_x_local_u(k,j)
-                diss_l = swap_diss_x_local_u(k,j)
+                                                         )
 #endif
+
 
                 ibit5 = REAL( IBITS(advc_flags_m(k,j,i),5,1), KIND = wp )
@@ -4854,34 +4800,34 @@
                 ibit3 = REAL( IBITS(advc_flags_m(k,j,i),3,1), KIND = wp )
 
-                v_comp = v(k,j+1,i) + v(k,j+1,i-1) - gv
-                flux_n = v_comp * (                                            &
-                          ( 37.0_wp * ibit5 * adv_mom_5                        &
-                       +     7.0_wp * ibit4 * adv_mom_3                        &
-                       +              ibit3 * adv_mom_1                        &
-                          ) *                                                  &
-                                 ( u(k,j+1,i) + u(k,j,i)   )                   &
-                   -      (  8.0_wp * ibit5 * adv_mom_5                        &
-                       +              ibit4 * adv_mom_3                        &
-                          ) *                                                  &
-                                 ( u(k,j+2,i) + u(k,j-1,i) )                   &
-                   +      (           ibit5 * adv_mom_5                        & 
-                          ) *                                                  &
-                                 ( u(k,j+3,i) + u(k,j-2,i) )                   &
-                                                 )                            
-                                                                              
-                diss_n = - ABS ( v_comp ) * (                                  &
-                          ( 10.0_wp * ibit5 * adv_mom_5                        &
-                       +     3.0_wp * ibit4 * adv_mom_3                        &
-                       +              ibit3 * adv_mom_1                        &
-                          ) *                                                  &
-                                 ( u(k,j+1,i) - u(k,j,i)  )                    &
-                   -      (  5.0_wp * ibit5 * adv_mom_5                        &
-                       +              ibit4 * adv_mom_3                        &
-                          ) *                                                  &
-                                 ( u(k,j+2,i) - u(k,j-1,i) )                   &
-                   +      (           ibit5 * adv_mom_5                        &
-                          ) *                                                  &
-                                 ( u(k,j+3,i) - u(k,j-2,i) )                   &
-                                                      )
+                v_comp(k) = v(k,j+1,i) + v(k,j+1,i-1) - gv
+                flux_n(k) = v_comp(k) * (                                      &
+                           ( 37.0_wp * ibit5 * adv_mom_5                       &
+                        +     7.0_wp * ibit4 * adv_mom_3                       &
+                        +              ibit3 * adv_mom_1                       &
+                           ) *                                                 &
+                                          ( u(k,j+1,i) + u(k,j,i)   )          &
+                    -      (  8.0_wp * ibit5 * adv_mom_5                       &
+                        +              ibit4 * adv_mom_3                       &
+                           ) *                                                 &
+                                          ( u(k,j+2,i) + u(k,j-1,i) )          &
+                    +      (           ibit5 * adv_mom_5                       &
+                           ) *                                                 &
+                                          ( u(k,j+3,i) + u(k,j-2,i) )          &
+                                        )
+
+                diss_n(k) = - ABS ( v_comp(k) ) * (                            &
+                           ( 10.0_wp * ibit5 * adv_mom_5                       &
+                        +     3.0_wp * ibit4 * adv_mom_3                       &
+                        +              ibit3 * adv_mom_1                       &
+                           ) *                                                 &
+                                          ( u(k,j+1,i) - u(k,j,i)   )          &
+                    -      (  5.0_wp * ibit5 * adv_mom_5                       &
+                        +              ibit4 * adv_mom_3                       &
+                           ) *                                                 &
+                                          ( u(k,j+2,i) - u(k,j-1,i) )          &
+                    +      (           ibit5 * adv_mom_5                       &
+                           ) *                                                 &
+                                          ( u(k,j+3,i) - u(k,j-2,i) )          &
+                                                  )
 
 #ifdef _OPENACC
@@ -4892,6 +4838,6 @@
                 ibit3_s = REAL( IBITS(advc_flags_m(k,j-1,i),3,1), KIND = wp )
 
-                v_comp_s = v(k,j,i) + v(k,j,i-1) - gv
-                flux_s   = v_comp_s * (                                        &
+                v_comp_s         = v(k,j,i) + v(k,j,i-1) - gv
+                flux_s_u(k,tn)   = v_comp_s * (                                &
                                    ( 37.0_wp * ibit5_s * adv_mom_5             &
                                 +     7.0_wp * ibit4_s * adv_mom_3             &
@@ -4906,7 +4852,7 @@
                                ) *                                             &
                                      ( u(k,j+2,i) + u(k,j-3,i) )               &
-                                               )
-
-                diss_s   = - ABS ( v_comp_s ) * (                              &
+                                              )
+
+                diss_s_u(k,tn)   = - ABS ( v_comp_s ) * (                      &
                                    ( 10.0_wp * ibit5_s * adv_mom_5             &
                                 +     3.0_wp * ibit4_s * adv_mom_3             &
@@ -4921,10 +4867,69 @@
                                    ) *                                         &
                                      ( u(k,j+2,i) - u(k,j-3,i) )               &
-                                                         )
-#else
-                flux_s = swap_flux_y_local_u(k)
-                diss_s = swap_diss_y_local_u(k)
+                                                        )
 #endif
-
+             ENDDO
+
+             DO  k = nzb_max_l+1, nzt
+
+                u_comp(k) = u(k,j,i+1) + u(k,j,i)
+                flux_r(k) = ( u_comp(k) - gu ) * (                             &
+                               37.0_wp * ( u(k,j,i+1) + u(k,j,i)   )           &
+                             -  8.0_wp * ( u(k,j,i+2) + u(k,j,i-1) )           &
+                             +           ( u(k,j,i+3) + u(k,j,i-2) ) ) * adv_mom_5
+                diss_r(k) = - ABS( u_comp(k) - gu ) * (                        &
+                               10.0_wp * ( u(k,j,i+1) - u(k,j,i)   )           &
+                             -  5.0_wp * ( u(k,j,i+2) - u(k,j,i-1) )           &
+                             +           ( u(k,j,i+3) - u(k,j,i-2) ) ) * adv_mom_5
+#ifdef _OPENACC
+!
+!--             Recompute the left fluxes.
+                u_comp_l           = u(k,j,i) + u(k,j,i-1) - gu
+                flux_l_u(k,j,tn)   = u_comp_l * (                              &
+                             37.0_wp * ( u(k,j,i) + u(k,j,i-1)   )             &
+                           -  8.0_wp * ( u(k,j,i+1) + u(k,j,i-2) )             &
+                           +           ( u(k,j,i+2) + u(k,j,i-3) ) ) * adv_mom_5
+                diss_l_u(k,j,tn)   = - ABS(u_comp_l) * (                       &
+                             10.0_wp * ( u(k,j,i) - u(k,j,i-1)   )             &
+                           -  5.0_wp * ( u(k,j,i+1) - u(k,j,i-2) )             &
+                           +           ( u(k,j,i+2) - u(k,j,i-3) ) ) * adv_mom_5
+
+#endif
+                v_comp(k) = v(k,j+1,i) + v(k,j+1,i-1) - gv
+                flux_n(k) = v_comp(k) * (                                      &
+                               37.0_wp * ( u(k,j+1,i) + u(k,j,i)   )           &
+                             -  8.0_wp * ( u(k,j+2,i) + u(k,j-1,i) )           &
+                             +           ( u(k,j+3,i) + u(k,j-2,i) ) ) * adv_mom_5
+                diss_n(k) = - ABS( v_comp(k) ) * (                             &
+                               10.0_wp * ( u(k,j+1,i) - u(k,j,i)   )           &
+                             -  5.0_wp * ( u(k,j+2,i) - u(k,j-1,i) )           &
+                             +           ( u(k,j+3,i) - u(k,j-2,i) ) ) * adv_mom_5
+#ifdef _OPENACC
+!
+!--             Recompute the south fluxes.
+                v_comp_s         = v(k,j,i) + v(k,j,i-1) - gv
+                flux_s_u(k,tn)   = v_comp_s * (                                &
+                           37.0_wp * ( u(k,j,i) + u(k,j-1,i)   )               &
+                         -  8.0_wp * ( u(k,j+1,i) + u(k,j-2,i) )               &
+                         +           ( u(k,j+2,i) + u(k,j-3,i) ) ) * adv_mom_5
+                diss_s_u(k,tn)   = - ABS( v_comp_s ) * (                       &
+                           10.0_wp * ( u(k,j,i) - u(k,j-1,i)   )               &
+                         -  5.0_wp * ( u(k,j+1,i) - u(k,j-2,i) )               &
+                         +           ( u(k,j+2,i) - u(k,j-3,i) ) ) * adv_mom_5
+#endif
+             ENDDO
+!
+!--          Now, compute vertical fluxes. Split loop into a part treating the
+!--          lowest 2 grid points with indirect indexing, a main loop without
+!--          indirect indexing, and a loop for the uppermost 2 grip points with
+!--          indirect indexing. This allows better vectorization for the main loop.
+!--          First, compute the flux at model surface, which need has to be
+!--          calculated explicetely for the tendency at
+!--          the first w-level. For topography wall this is done implicitely by
+!--          advc_flags_m.
+             flux_t(nzb) = 0.0_wp
+             diss_t(nzb) = 0.0_wp
+             w_comp(nzb) = 0.0_wp
+             DO  k = nzb+1, nzb+2
 !
 !--             k index has to be modified near bottom and top, else array
@@ -4935,168 +4940,78 @@
 
                 k_ppp = k + 3 * ibit8
-                k_pp  = k + 2 * ( 1 - ibit6  )
+                k_pp  = k + 2 * ( 1 - ibit6 )
                 k_mm  = k - 2 * ibit8
 
-                w_comp = w(k,j,i) + w(k,j,i-1)
-                flux_t = w_comp * rho_air_zw(k) * (                            &
-                          ( 37.0_wp * ibit8 * adv_mom_5                        &
-                       +     7.0_wp * ibit7 * adv_mom_3                        &
-                       +              ibit6 * adv_mom_1                        & 
-                          ) *                                                  &
-                             ( u(k+1,j,i)  + u(k,j,i)     )                    &
-                   -      (  8.0_wp * ibit8 * adv_mom_5                        &
-                       +              ibit7 * adv_mom_3                        &
-                          ) *                                                  &
-                             ( u(k_pp,j,i) + u(k-1,j,i)   )                    &
-                   +      (           ibit8 * adv_mom_5                        &
-                          ) *                                                  &
-                             ( u(k_ppp,j,i) + u(k_mm,j,i) )                    &
-                                      )                                       
-                                                                              
-                diss_t = - ABS( w_comp ) * rho_air_zw(k) * (                   &
-                          ( 10.0_wp * ibit8 * adv_mom_5                        &
-                       +     3.0_wp * ibit7 * adv_mom_3                        &
-                       +              ibit6 * adv_mom_1                        &
-                          ) *                                                  &
-                             ( u(k+1,j,i)   - u(k,j,i)    )                    &
-                   -      (  5.0_wp * ibit8 * adv_mom_5                        &
-                       +              ibit7 * adv_mom_3                        &
-                          ) *                                                  &
-                             ( u(k_pp,j,i)  - u(k-1,j,i)  )                    &
-                   +      (           ibit8 * adv_mom_5                        &
-                           ) *                                                 &
-                             ( u(k_ppp,j,i) - u(k_mm,j,i) )                    &
-                                              )
-!
-!--             Calculate the divergence of the velocity field. A respective
-!--             correction is needed to overcome numerical instabilities caused
-!--             by a not sufficient reduction of divergences near topography.
-                div = ( ( u_comp * ( ibit0 + ibit1 + ibit2 )                   &
-                - ( u(k,j,i)   + u(k,j,i-1)   )                                &
-                                    * (                                        &
-                    REAL( IBITS(advc_flags_m(k,j,i-1),0,1),  KIND = wp )       &
-                  + REAL( IBITS(advc_flags_m(k,j,i-1),1,1), KIND = wp )        &
-                  + REAL( IBITS(advc_flags_m(k,j,i-1),2,1), KIND = wp )        &
-                                      )                                        &
-                  ) * ddx                                                      &
-               +  ( ( v_comp + gv ) * ( ibit3 + ibit4 + ibit5 )                &
-                  - ( v(k,j,i)   + v(k,j,i-1 )  )                              &
-                                    * (                                        &
-                     REAL( IBITS(advc_flags_m(k,j-1,i),3,1), KIND = wp )       &
-                   + REAL( IBITS(advc_flags_m(k,j-1,i),4,1), KIND = wp )       &
-                   + REAL( IBITS(advc_flags_m(k,j-1,i),5,1), KIND = wp )       &
-                                      )                                        &
-                  ) * ddy                                                      &
-               +  ( w_comp * rho_air_zw(k) * ( ibit6 + ibit7 + ibit8 )         &
-                - ( w(k-1,j,i) + w(k-1,j,i-1) ) * rho_air_zw(k-1)              &
-                                    * (                                        &
-                     REAL( IBITS(advc_flags_m(k-1,j,i),6,1), KIND = wp )       &
-                   + REAL( IBITS(advc_flags_m(k-1,j,i),7,1), KIND = wp )       &
-                   + REAL( IBITS(advc_flags_m(k-1,j,i),8,1), KIND = wp )       &
-                                      )                                        &  
-                  ) * drho_air(k) * ddzw(k)                                    &
-                ) * 0.5_wp
-
-
-
-                tend(k,j,i) = tend(k,j,i) - (                                  &
-                 ( ( flux_r + diss_r )                                         &
-               -   ( flux_l + diss_l ) ) * ddx                                 &
-               + ( ( flux_n + diss_n )                                         &
-               -   ( flux_s + diss_s ) ) * ddy                                 &
-               + ( ( flux_t + diss_t )                                         &
-               -   ( flux_d + diss_d ) ) * drho_air(k) * ddzw(k)               &
-                                           ) + div * u(k,j,i)
-
-#ifndef _OPENACC
-                swap_flux_x_local_u(k,j) = flux_r
-                swap_diss_x_local_u(k,j) = diss_r
-                swap_flux_y_local_u(k)   = flux_n
-                swap_diss_y_local_u(k)   = diss_n
-#endif
-                flux_d                   = flux_t
-                diss_d                   = diss_t
-!
-!--             Statistical Evaluation of u'u'. The factor has to be applied
-!--             for right evaluation when gallilei_trans = .T. .
-                !$ACC ATOMIC
-                sums_us2_ws_l(k,tn) = sums_us2_ws_l(k,tn)                      &
-                + ( flux_r                                                     &
-                    * ( u_comp - 2.0_wp * hom(k,1,1,0)                   )     &
-                    / ( u_comp - gu + SIGN( 1.0E-20_wp, u_comp - gu )    )     &
-                  + diss_r                                                     &
-                    *   ABS( u_comp - 2.0_wp * hom(k,1,1,0)              )     &
-                    / ( ABS( u_comp - gu ) + 1.0E-20_wp                  )     &
-                  ) *   weight_substep(intermediate_timestep_count)
-!
-!--             Statistical Evaluation of w'u'.
-                !$ACC ATOMIC
-                sums_wsus_ws_l(k,tn) = sums_wsus_ws_l(k,tn)                    &
-                + ( flux_t                                                     &
-                    * ( w_comp - 2.0_wp * hom(k,1,3,0)                   )     &
-                    / ( w_comp + SIGN( 1.0E-20_wp, w_comp )              )     &
-                  + diss_t                                                     &
-                    *   ABS( w_comp - 2.0_wp * hom(k,1,3,0)              )     &
-                    / ( ABS( w_comp ) + 1.0E-20_wp                       )     &
-                  ) *   weight_substep(intermediate_timestep_count)
-
+                w_comp(k) = w(k,j,i) + w(k,j,i-1)
+                flux_t(k) = w_comp(k) * rho_air_zw(k) * (                      &
+                           ( 37.0_wp * ibit8 * adv_mom_5                       &
+                        +     7.0_wp * ibit7 * adv_mom_3                       &
+                        +              ibit6 * adv_mom_1                       &
+                           ) *                                                 &
+                                      ( u(k+1,j,i)   + u(k,j,i)    )           &
+                    -      (  8.0_wp * ibit8 * adv_mom_5                       &
+                        +              ibit7 * adv_mom_3                       &
+                           ) *                                                 &
+                                      ( u(k_pp,j,i)  + u(k-1,j,i)  )           &
+                    +      (           ibit8 * adv_mom_5                       &
+                           ) *                                                 &
+                                      ( u(k_ppp,j,i) + u(k_mm,j,i) )           &
+                                                        )
+
+                diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (             &
+                           ( 10.0_wp * ibit8 * adv_mom_5                       &
+                        +     3.0_wp * ibit7 * adv_mom_3                       &
+                        +              ibit6 * adv_mom_1                       &
+                           ) *                                                 &
+                                      ( u(k+1,j,i)   - u(k,j,i)    )           &
+                    -      (  5.0_wp * ibit8 * adv_mom_5                       &
+                        +              ibit7 * adv_mom_3                       &
+                           ) *                                                 &
+                                      ( u(k_pp,j,i)  - u(k-1,j,i)  )           &
+                    +      (           ibit8 * adv_mom_5                       &
+                           ) *                                                 &
+                                      ( u(k_ppp,j,i) - u(k_mm,j,i) )           &
+                                                                 )
              ENDDO
 
-             DO  k = nzb_max_l+1, nzt
-
-                u_comp = u(k,j,i+1) + u(k,j,i)
-                flux_r = ( u_comp - gu ) * (                                   &
-                         37.0_wp * ( u(k,j,i+1) + u(k,j,i)   )                 &
-                       -  8.0_wp * ( u(k,j,i+2) + u(k,j,i-1) )                 &
-                       +           ( u(k,j,i+3) + u(k,j,i-2) ) ) * adv_mom_5
-                diss_r = - ABS( u_comp - gu ) * (                              &
-                         10.0_wp * ( u(k,j,i+1) - u(k,j,i)   )                 &
-                       -  5.0_wp * ( u(k,j,i+2) - u(k,j,i-1) )                 &
-                       +           ( u(k,j,i+3) - u(k,j,i-2) ) ) * adv_mom_5
-
-#ifdef _OPENACC
-!
-!--             Recompute the left fluxes.
-                u_comp_l = u(k,j,i) + u(k,j,i-1) - gu
-                flux_l   = u_comp_l * (                                        &
-                             37.0_wp * ( u(k,j,i) + u(k,j,i-1)   )             &
-                           -  8.0_wp * ( u(k,j,i+1) + u(k,j,i-2) )             &
-                           +           ( u(k,j,i+2) + u(k,j,i-3) ) ) * adv_mom_5
-                diss_l   = - ABS(u_comp_l) * (                                 &
-                             10.0_wp * ( u(k,j,i) - u(k,j,i-1)   )             &
-                           -  5.0_wp * ( u(k,j,i+1) - u(k,j,i-2) )             &
-                           +           ( u(k,j,i+2) - u(k,j,i-3) ) ) * adv_mom_5
-#else
-                flux_l = swap_flux_x_local_u(k,j)
-                diss_l = swap_diss_x_local_u(k,j)
-#endif
-
-                v_comp = v(k,j+1,i) + v(k,j+1,i-1) - gv
-                flux_n = v_comp * (                                            &
-                         37.0_wp * ( u(k,j+1,i) + u(k,j,i)   )                 &
-                       -  8.0_wp * ( u(k,j+2,i) + u(k,j-1,i) )                 &
-                       +           ( u(k,j+3,i) + u(k,j-2,i) ) ) * adv_mom_5
-                diss_n = - ABS( v_comp ) * (                                   &
-                         10.0_wp * ( u(k,j+1,i) - u(k,j,i)   )                 &
-                       -  5.0_wp * ( u(k,j+2,i) - u(k,j-1,i) )                 &
-                       +           ( u(k,j+3,i) - u(k,j-2,i) ) ) * adv_mom_5
-
-#ifdef _OPENACC
-!
-!--             Recompute the south fluxes.
-                v_comp_s = v(k,j,i) + v(k,j,i-1) - gv
-                flux_s   = v_comp_s * (                                        &
-                           37.0_wp * ( u(k,j,i) + u(k,j-1,i)   )               &
-                         -  8.0_wp * ( u(k,j+1,i) + u(k,j-2,i) )               &
-                         +           ( u(k,j+2,i) + u(k,j-3,i) ) ) * adv_mom_5
-                diss_s   = - ABS( v_comp_s ) * (                               &
-                           10.0_wp * ( u(k,j,i) - u(k,j-1,i)   )               &
-                         -  5.0_wp * ( u(k,j+1,i) - u(k,j-2,i) )               &
-                         +           ( u(k,j+2,i) - u(k,j-3,i) ) ) * adv_mom_5
-#else
-                flux_s = swap_flux_y_local_u(k)
-                diss_s = swap_diss_y_local_u(k)
-#endif
-
+             DO  k = nzb+3, nzt-2
+
+                ibit8 = REAL( IBITS(advc_flags_m(k,j,i),8,1), KIND = wp )
+                ibit7 = REAL( IBITS(advc_flags_m(k,j,i),7,1), KIND = wp )
+                ibit6 = REAL( IBITS(advc_flags_m(k,j,i),6,1), KIND = wp )
+
+                w_comp(k) = w(k,j,i) + w(k,j,i-1)
+                flux_t(k) = w_comp(k) * rho_air_zw(k) * (                      &
+                           ( 37.0_wp * ibit8 * adv_mom_5                       &
+                        +     7.0_wp * ibit7 * adv_mom_3                       &
+                        +              ibit6 * adv_mom_1                       &
+                           ) *                                                 &
+                                      ( u(k+1,j,i)  + u(k,j,i)     )           &
+                    -      (  8.0_wp * ibit8 * adv_mom_5                       &
+                        +              ibit7 * adv_mom_3                       &
+                           ) *                                                 &
+                                      ( u(k+2,j,i) + u(k-1,j,i)   )            &
+                    +      (           ibit8 * adv_mom_5                       &
+                           ) *                                                 &
+                                      ( u(k+3,j,i) + u(k-2,j,i) )              &
+                                                        )
+
+                diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (             &
+                           ( 10.0_wp * ibit8 * adv_mom_5                       &
+                        +     3.0_wp * ibit7 * adv_mom_3                       &
+                        +              ibit6 * adv_mom_1                       &
+                           ) *                                                 &
+                                      ( u(k+1,j,i)  - u(k,j,i)    )            &
+                    -      (  5.0_wp * ibit8 * adv_mom_5                       &
+                        +              ibit7 * adv_mom_3                       &
+                           ) *                                                 &
+                                      ( u(k+2,j,i)  - u(k-1,j,i)  )            &
+                    +      (           ibit8 * adv_mom_5                       &
+                           ) *                                                 &
+                                      ( u(k+3,j,i) - u(k-2,j,i)   )            &
+                                                                 )
+             ENDDO
+
+             DO  k = nzt-1, nzt-symmetry_flag
 !
 !--             k index has to be modified near bottom and top, else array
@@ -5107,94 +5022,196 @@
 
                 k_ppp = k + 3 * ibit8
-                k_pp  = k + 2 * ( 1 - ibit6  )
+                k_pp  = k + 2 * ( 1 - ibit6 )
                 k_mm  = k - 2 * ibit8
 
-                w_comp = w(k,j,i) + w(k,j,i-1)
-                flux_t = w_comp * rho_air_zw(k) * (                            &
-                          ( 37.0_wp * ibit8 * adv_mom_5                        &
-                       +     7.0_wp * ibit7 * adv_mom_3                        &
-                       +              ibit6 * adv_mom_1                        &
-                          ) *                                                  &
-                             ( u(k+1,j,i)  + u(k,j,i)     )                    &
-                   -      (  8.0_wp * ibit8 * adv_mom_5                        &
-                       +              ibit7 * adv_mom_3                        &
-                          ) *                                                  &
-                             ( u(k_pp,j,i) + u(k-1,j,i)   )                    &
-                   +      (           ibit8 * adv_mom_5                        &
-                          ) *                                                  &
-                             ( u(k_ppp,j,i) + u(k_mm,j,i) )                    &
-                                      )
-
-                diss_t = - ABS( w_comp ) * rho_air_zw(k) * (                   &
-                          ( 10.0_wp * ibit8 * adv_mom_5                        &
-                       +     3.0_wp * ibit7 * adv_mom_3                        &
-                       +              ibit6 * adv_mom_1                        &
-                          ) *                                                  &
-                             ( u(k+1,j,i)   - u(k,j,i)    )                    &
-                   -      (  5.0_wp * ibit8 * adv_mom_5                        &
-                       +              ibit7 * adv_mom_3                        &
-                          ) *                                                  &
-                             ( u(k_pp,j,i)  - u(k-1,j,i)  )                    &
-                   +      (           ibit8 * adv_mom_5                        &
-                           ) *                                                 &
-                             ( u(k_ppp,j,i) - u(k_mm,j,i) )                    &
-                                              )
+                w_comp(k) = w(k,j,i) + w(k,j,i-1)
+                flux_t(k) = w_comp(k) * rho_air_zw(k) * (                      &
+                           ( 37.0_wp * ibit8 * adv_mom_5                       &
+                        +     7.0_wp * ibit7 * adv_mom_3                       &
+                        +              ibit6 * adv_mom_1                       &
+                           ) *                                                 &
+                                      ( u(k+1,j,i)   + u(k,j,i)    )           &
+                    -      (  8.0_wp * ibit8 * adv_mom_5                       &
+                        +              ibit7 * adv_mom_3                       &
+                           ) *                                                 &
+                                      ( u(k_pp,j,i)  + u(k-1,j,i)  )           &
+                    +      (           ibit8 * adv_mom_5                       &
+                           ) *                                                 &
+                                      ( u(k_ppp,j,i) + u(k_mm,j,i) )           &
+                                                        )
+
+                diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (             &
+                           ( 10.0_wp * ibit8 * adv_mom_5                       &
+                        +     3.0_wp * ibit7 * adv_mom_3                       &
+                        +              ibit6 * adv_mom_1                       &
+                           ) *                                                 &
+                                      ( u(k+1,j,i)   - u(k,j,i)    )           &
+                    -      (  5.0_wp * ibit8 * adv_mom_5                       &
+                        +              ibit7 * adv_mom_3                       &
+                           ) *                                                 &
+                                      ( u(k_pp,j,i)  - u(k-1,j,i)  )           &
+                    +      (           ibit8 * adv_mom_5                       &
+                           ) *                                                 &
+                                      ( u(k_ppp,j,i) - u(k_mm,j,i) )           &
+                                                                 )
+             ENDDO
+!
+!--          Set resolved/turbulent flux at model top to zero (w-level). In case that
+!--          a symmetric behavior between bottom and top shall be guaranteed (closed
+!--          channel flow), the flux at nzt is also set to zero.
+             IF ( symmetry_flag == 1 ) THEN
+                flux_t(nzt) = 0.0_wp
+                diss_t(nzt) = 0.0_wp
+                w_comp(nzt) = 0.0_wp
+             ENDIF
+             flux_t(nzt+1) = 0.0_wp
+             diss_t(nzt+1) = 0.0_wp
+             w_comp(nzt+1) = 0.0_wp
+
+             DO  k = nzb+1, nzb_max_l
+
+                flux_d    = flux_t(k-1)
+                diss_d    = diss_t(k-1)
+
+                ibit2 = REAL( IBITS(advc_flags_m(k,j,i),2,1), KIND = wp )
+                ibit1 = REAL( IBITS(advc_flags_m(k,j,i),1,1), KIND = wp )
+                ibit0 = REAL( IBITS(advc_flags_m(k,j,i),0,1), KIND = wp )
+
+                ibit5 = REAL( IBITS(advc_flags_m(k,j,i),5,1), KIND = wp )
+                ibit4 = REAL( IBITS(advc_flags_m(k,j,i),4,1), KIND = wp )
+                ibit3 = REAL( IBITS(advc_flags_m(k,j,i),3,1), KIND = wp )
+
+                ibit8 = REAL( IBITS(advc_flags_m(k,j,i),8,1), KIND = wp )
+                ibit7 = REAL( IBITS(advc_flags_m(k,j,i),7,1), KIND = wp )
+                ibit6 = REAL( IBITS(advc_flags_m(k,j,i),6,1), KIND = wp )
 !
 !--             Calculate the divergence of the velocity field. A respective
-!--             correction is needed to overcome numerical instabilities caused
+!--             correction is needed to overcome numerical instabilities introduced
 !--             by a not sufficient reduction of divergences near topography.
-                div = ( ( u_comp      - ( u(k,j,i)   + u(k,j,i-1)   ) ) * ddx  &
-                     +  ( v_comp + gv - ( v(k,j,i)   + v(k,j,i-1 )  ) ) * ddy  &
-                     +  (   w_comp                      * rho_air_zw(k) -      &
-                          ( w(k-1,j,i) + w(k-1,j,i-1) ) * rho_air_zw(k-1)      &
-                        ) * drho_air(k) * ddzw(k)                              &
+                div = ( ( u_comp(k)       * ( ibit0 + ibit1 + ibit2 )            &
+                      - ( u(k,j,i)   + u(k,j,i-1)   )                            &
+                                          * (                                    &
+                           REAL( IBITS(advc_flags_m(k,j,i-1),0,1),  KIND = wp )  &
+                         + REAL( IBITS(advc_flags_m(k,j,i-1),1,1), KIND = wp )   &
+                         + REAL( IBITS(advc_flags_m(k,j,i-1),2,1), KIND = wp )   &
+                                            )                                    &
+                        ) * ddx                                                  &
+                     +  ( ( v_comp(k) + gv ) * ( ibit3 + ibit4 + ibit5 )         &
+                        - ( v(k,j,i)   + v(k,j,i-1 )  )                          &
+                                          * (                                    &
+                           REAL( IBITS(advc_flags_m(k,j-1,i),3,1), KIND = wp )   &
+                         + REAL( IBITS(advc_flags_m(k,j-1,i),4,1), KIND = wp )   &
+                         + REAL( IBITS(advc_flags_m(k,j-1,i),5,1), KIND = wp )   &
+                                            )                                    &
+                        ) * ddy                                                  &
+                     +  ( w_comp(k)   * rho_air_zw(k) * ( ibit6 + ibit7 + ibit8 )&
+                      -   w_comp(k-1) * rho_air_zw(k-1)                          &
+                                          * (                                    &
+                           REAL( IBITS(advc_flags_m(k-1,j,i),6,1), KIND = wp )   &
+                         + REAL( IBITS(advc_flags_m(k-1,j,i),7,1), KIND = wp )   &
+                         + REAL( IBITS(advc_flags_m(k-1,j,i),8,1), KIND = wp )   &
+                                            )                                    &
+                        ) * drho_air(k) * ddzw(k)                                &
                       ) * 0.5_wp
 
-                tend(k,j,i) = tend(k,j,i) - (                                  &
-                 ( ( flux_r + diss_r )                                         &
-               -   ( flux_l + diss_l ) ) * ddx                                 &
-               + ( ( flux_n + diss_n )                                         &
-               -   ( flux_s + diss_s ) ) * ddy                                 &
-               + ( ( flux_t + diss_t )                                         &
-               -   ( flux_d + diss_d ) ) * drho_air(k) * ddzw(k)               &
-                                           ) + div * u(k,j,i)
-
+                tend(k,j,i) = tend(k,j,i) - (                                    &
+                                  ( flux_r(k) + diss_r(k)                        &
+                                -   flux_l_u(k,j,tn) - diss_l_u(k,j,tn) ) * ddx  &
+                                + ( flux_n(k) + diss_n(k)                        &
+                                -   flux_s_u(k,tn) - diss_s_u(k,tn)     ) * ddy  &
+                                + ( ( flux_t(k) + diss_t(k) )                    &
+                                -   ( flux_d    + diss_d    )                    &
+                                                       ) * drho_air(k) * ddzw(k) &
+                                             ) + div * u(k,j,i)
 #ifndef _OPENACC
-                swap_flux_x_local_u(k,j) = flux_r
-                swap_diss_x_local_u(k,j) = diss_r
-                swap_flux_y_local_u(k)   = flux_n
-                swap_diss_y_local_u(k)   = diss_n
+!
+!--             Swap fluxes. Note, in the OPENACC case these are computed again.
+                flux_l_u(k,j,tn) = flux_r(k)
+                diss_l_u(k,j,tn) = diss_r(k)
+                flux_s_u(k,tn)   = flux_n(k)
+                diss_s_u(k,tn)   = diss_n(k)
 #endif
-                flux_d                   = flux_t
-                diss_d                   = diss_t
-!
-!--             Statistical Evaluation of u'u'. The factor has to be applied
-!--             for right evaluation when gallilei_trans = .T. .
-                !$ACC ATOMIC
-                sums_us2_ws_l(k,tn) = sums_us2_ws_l(k,tn)                      &
-                + ( flux_r                                                     &
-                    * ( u_comp - 2.0_wp * hom(k,1,1,0)                   )     &
-                    / ( u_comp - gu + SIGN( 1.0E-20_wp, u_comp - gu )    )     &
-                  + diss_r                                                     &
-                    *   ABS( u_comp - 2.0_wp * hom(k,1,1,0)              )     &
-                    / ( ABS( u_comp - gu ) + 1.0E-20_wp                  )     &
-                  ) *   weight_substep(intermediate_timestep_count)
+!
+!--             Statistical Evaluation of u'u'. The factor has to be applied for
+!--             right evaluation when gallilei_trans = .T. .
+                sums_us2_ws_l(k,tn) = sums_us2_ws_l(k,tn)                           &
+                      + ( flux_r(k)                                                 &
+                          * ( u_comp(k) - 2.0_wp * hom(k,1,1,0)                   ) &
+                          / ( u_comp(k) - gu + SIGN( 1.0E-20_wp, u_comp(k) - gu ) ) &
+                        + diss_r(k)                                                 &
+                          *   ABS( u_comp(k) - 2.0_wp * hom(k,1,1,0)              ) &
+                          / ( ABS( u_comp(k) - gu ) + 1.0E-20_wp                  ) &
+                        ) *   weight_substep(intermediate_timestep_count)
 !
 !--             Statistical Evaluation of w'u'.
-                !$ACC ATOMIC
-                sums_wsus_ws_l(k,tn) = sums_wsus_ws_l(k,tn)                    &
-                + ( flux_t                                                     &
-                    * ( w_comp - 2.0_wp * hom(k,1,3,0)                   )     &
-                    / ( w_comp + SIGN( 1.0E-20_wp, w_comp )              )     &
-                  + diss_t                                                     &
-                    *   ABS( w_comp - 2.0_wp * hom(k,1,3,0)              )     &
-                    / ( ABS( w_comp ) + 1.0E-20_wp                       )     &
-                  ) *   weight_substep(intermediate_timestep_count)
+                sums_wsus_ws_l(k,tn) = sums_wsus_ws_l(k,tn)                         &
+                      + ( flux_t(k)                                                 &
+                          * ( w_comp(k) - 2.0_wp * hom(k,1,3,0)                   ) &
+                          / ( w_comp(k) + SIGN( 1.0E-20_wp, w_comp(k) )           ) &
+                        + diss_t(k)                                                 &
+                          *   ABS( w_comp(k) - 2.0_wp * hom(k,1,3,0)              ) &
+                          / ( ABS( w_comp(k) ) + 1.0E-20_wp                       ) &
+                        ) *   weight_substep(intermediate_timestep_count)
+             ENDDO
+
+             DO  k = nzb_max_l+1, nzt
+
+                flux_d    = flux_t(k-1)
+                diss_d    = diss_t(k-1)
+!
+!--             Calculate the divergence of the velocity field. A respective
+!--             correction is needed to overcome numerical instabilities introduced
+!--             by a not sufficient reduction of divergences near topography.
+                div = ( ( u_comp(k)       - ( u(k,j,i)   + u(k,j,i-1) ) ) * ddx      &
+                     +  ( v_comp(k) + gv  - ( v(k,j,i)   + v(k,j,i-1) ) ) * ddy      &
+                     +  ( w_comp(k)   * rho_air_zw(k)                                &
+                       -  w_comp(k-1) * rho_air_zw(k-1)                              &
+                        ) * drho_air(k) * ddzw(k)                                    &
+                      ) * 0.5_wp
+
+                tend(k,j,i) = tend(k,j,i) - (                                        &
+                                  ( flux_r(k) + diss_r(k)                            &
+                                -   flux_l_u(k,j,tn) - diss_l_u(k,j,tn) ) * ddx      &
+                                + ( flux_n(k) + diss_n(k)                            &
+                                -   flux_s_u(k,tn) - diss_s_u(k,tn)     ) * ddy      &
+                                + ( ( flux_t(k) + diss_t(k) )                        &
+                                -   ( flux_d    + diss_d    )                        &
+                                                          ) * drho_air(k) * ddzw(k)  &
+                                             ) + div * u(k,j,i)
+#ifndef _OPENACC
+                flux_l_u(k,j,tn) = flux_r(k)
+                diss_l_u(k,j,tn) = diss_r(k)
+                flux_s_u(k,tn)   = flux_n(k)
+                diss_s_u(k,tn)   = diss_n(k)
+#endif
+!
+!--             Statistical Evaluation of u'u'. The factor has to be applied for
+!--             right evaluation when gallilei_trans = .T. .
+                sums_us2_ws_l(k,tn) = sums_us2_ws_l(k,tn)                            &
+                      + ( flux_r(k)                                                  &
+                          * ( u_comp(k) - 2.0_wp * hom(k,1,1,0)                   )  &
+                          / ( u_comp(k) - gu + SIGN( 1.0E-20_wp, u_comp(k) - gu ) )  &
+                        + diss_r(k)                                                  &
+                          *   ABS( u_comp(k) - 2.0_wp * hom(k,1,1,0)              )  &
+                          / ( ABS( u_comp(k) - gu ) + 1.0E-20_wp                  )  &
+                        ) *   weight_substep(intermediate_timestep_count)
+!
+!--             Statistical Evaluation of w'u'.
+                sums_wsus_ws_l(k,tn) = sums_wsus_ws_l(k,tn)                          &
+                      + ( flux_t(k)                                                  &
+                          * ( w_comp(k) - 2.0_wp * hom(k,1,3,0)                   )  &
+                          / ( w_comp(k) + SIGN( 1.0E-20_wp, w_comp(k) )           )  &
+                        + diss_t(k)                                                  &
+                          *   ABS( w_comp(k) - 2.0_wp * hom(k,1,3,0)              )  &
+                          / ( ABS( w_comp(k) ) + 1.0E-20_wp                       )  &
+                        ) *   weight_substep(intermediate_timestep_count)
              ENDDO
           ENDDO
        ENDDO
 
+       CALL cpu_log( log_point_s(68), 'advec_u_ws', 'stop' )
+
     END SUBROUTINE advec_u_ws
-    
+
 
 !------------------------------------------------------------------------------!
@@ -5212,7 +5229,7 @@
        INTEGER(iwp) ::  k_pp      !< k+2 index in disretization, can be modified to avoid segmentation faults
        INTEGER(iwp) ::  k_ppp     !< k+3 index in disretization, can be modified to avoid segmentation faults
-       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms 
+       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms
        INTEGER(iwp) ::  tn = 0    !< number of OpenMP thread
-       
+
        REAL(wp)    ::  ibit9 !< flag indicating 1st-order scheme along x-direction
        REAL(wp)    ::  ibit10 !< flag indicating 3rd-order scheme along x-direction
@@ -5231,73 +5248,76 @@
        REAL(wp)    ::  ibit14_s !< flag indicating 5th-order scheme along y-direction
 #endif
-       REAL(wp)    ::  ibit15 !< flag indicating 1st-order scheme along z-direction
-       REAL(wp)    ::  ibit16 !< flag indicating 3rd-order scheme along z-direction
-       REAL(wp)    ::  ibit17 !< flag indicating 5th-order scheme along z-direction
-       REAL(wp)    ::  diss_d !< artificial dissipation term at grid box bottom
-       REAL(wp)    ::  div    !< diverence on v-grid
-       REAL(wp)    ::  flux_d !< artificial 6th-order flux at grid box bottom
-       REAL(wp)    ::  gu     !< Galilei-transformation velocity along x
-       REAL(wp)    ::  gv     !< Galilei-transformation velocity along y
-       REAL(wp)    ::  u_comp !< advection velocity along x
+       REAL(wp)    ::  ibit15   !< flag indicating 1st-order scheme along z-direction
+       REAL(wp)    ::  ibit16   !< flag indicating 3rd-order scheme along z-direction
+       REAL(wp)    ::  ibit17   !< flag indicating 5th-order scheme along z-direction
+       REAL(wp)    ::  diss_d   !< artificial dissipation term at grid box bottom
+       REAL(wp)    ::  div      !< diverence on v-grid
+       REAL(wp)    ::  flux_d   !< artificial 6th-order flux at grid box bottom
+       REAL(wp)    ::  gu       !< Galilei-transformation velocity along x
+       REAL(wp)    ::  gv       !< Galilei-transformation velocity along y
 #ifdef _OPENACC
-       REAL(wp)    ::  u_comp_l !< advection velocity along x
+       REAL(wp)    ::  u_comp_l !< advection velocity along x at leftward side
+       REAL(wp)    ::  v_comp_s !< advection velocity along y at southward side
 #endif
-       REAL(wp)    ::  w_comp !< advection velocity along z
-       
-       REAL(wp)    ::  diss_s !< discretized artificial dissipation at southward-side of the grid box
-       REAL(wp)    ::  flux_s !< discretized 6th-order flux at southward-side of the grid box
-#ifndef _OPENACC
-       REAL(wp), DIMENSION(nzb+1:nzt) ::  swap_diss_y_local_v !< discretized artificial dissipation at southward-side of the grid box
-       REAL(wp), DIMENSION(nzb+1:nzt) ::  swap_flux_y_local_v !< discretized 6th-order flux at southward-side of the grid box
-#endif
-       
-       REAL(wp)    ::  diss_l !< discretized artificial dissipation at leftward-side of the grid box
-       REAL(wp)    ::  flux_l !< discretized 6th-order flux at leftward-side of the grid box
-#ifndef _OPENACC
-       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn) ::  swap_diss_x_local_v !< discretized artificial dissipation at leftward-side of the grid box
-       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn) ::  swap_flux_x_local_v !< discretized 6th-order flux at leftward-side of the grid box
-#endif
-       
-       REAL(wp)    ::  diss_n !< discretized artificial dissipation at northward-side of the grid box
-       REAL(wp)    ::  diss_r !< discretized artificial dissipation at rightward-side of the grid box
-       REAL(wp)    ::  diss_t !< discretized artificial dissipation at top of the grid box
-       REAL(wp)    ::  flux_n !< discretized 6th-order flux at northward-side of the grid box
-       REAL(wp)    ::  flux_r !< discretized 6th-order flux at rightward-side of the grid box
-       REAL(wp)    ::  flux_t !< discretized 6th-order flux at top of the grid box
-       REAL(wp)    ::  v_comp !< advection velocity along y
-#ifdef _OPENACC
-       REAL(wp)    ::  v_comp_s !<
-#endif
-!
-!--    Set local version of nzb_max. At non-cyclic boundaries the order of the 
-!--    advection need to be degraded near the boundary. Please note, in contrast
-!--    to the cache-optimized routines, nzb_max_l is set constantly for the 
-!--    entire subdomain, in order to avoid unsymmetric loops which might be 
-!--    an issue for GPUs.
-       IF( bc_dirichlet_l  .OR.  bc_radiation_l  .OR.                          &
-           bc_dirichlet_r  .OR.  bc_radiation_r  .OR.                          &
-           bc_dirichlet_s  .OR.  bc_radiation_s  .OR.                          &
-           bc_dirichlet_n  .OR.  bc_radiation_n )  THEN
-          nzb_max_l = nzt
-       ELSE
-          nzb_max_l = nzb_max
-       END IF
-       
+
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  diss_n !< discretized artificial dissipation at northward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  diss_r !< discretized artificial dissipation at rightward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  diss_t !< discretized artificial dissipation at top of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  flux_n !< discretized 6th-order flux at northward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  flux_r !< discretized 6th-order flux at rightward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  flux_t !< discretized 6th-order flux at top of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  u_comp !< advection velocity along x
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  v_comp !< advection velocity along y
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  w_comp !< advection velocity along z
+
+       CALL cpu_log( log_point_s(69), 'advec_v_ws', 'start' )
+
        gu = 2.0_wp * u_gtrans
        gv = 2.0_wp * v_gtrans
 
+       !$ACC PARALLEL LOOP COLLAPSE(2) FIRSTPRIVATE(tn, gu, gv) &
+       !$ACC PRIVATE(i, j, k, k_mm, k_pp, k_ppp) &
+       !$ACC PRIVATE(ibit9, ibit10, ibit11, ibit12, ibit13, ibit14) &
+       !$ACC PRIVATE(ibit15, ibit16, ibit17) &
+       !$ACC PRIVATE(ibit9_l, ibit10_l, ibit11_l) &
+       !$ACC PRIVATE(ibit12_s, ibit13_s, ibit14_s) &
+       !$ACC PRIVATE(flux_r, diss_r) &
+       !$ACC PRIVATE(flux_n, diss_n) &
+       !$ACC PRIVATE(flux_t, diss_t, flux_d, diss_d) &
+       !$ACC PRIVATE(flux_l_v, diss_l_v, flux_s_v, diss_s_v) &
+       !$ACC PRIVATE(div, u_comp, u_comp_l, v_comp, v_comp_s, w_comp) &
+       !$ACC PRESENT(advc_flags_m) &
+       !$ACC PRESENT(u, v, w) &
+       !$ACC PRESENT(drho_air, rho_air_zw, ddzw) &
+       !$ACC PRESENT(tend) &
+       !$ACC PRESENT(hom(:,1,1:3,0)) &
+       !$ACC PRESENT(weight_substep(intermediate_timestep_count)) &
+       !$ACC PRESENT(sums_vs2_ws_l, sums_wsvs_ws_l)
+       DO  i = nxl, nxr
+          DO  j = nysv, nyn
+!
+!--          Used local modified copy of nzb_max (used to degrade order of
+!--          discretization) at non-cyclic boundaries. Modify only at relevant points
+!--          instead of the entire subdomain. This should lead to better
+!--          load balance between boundary and non-boundary PEs.
+             IF( ( bc_dirichlet_l  .OR.  bc_radiation_l )  .AND.  i <= nxl + 2  .OR. &
+                 ( bc_dirichlet_r  .OR.  bc_radiation_r )  .AND.  i >= nxr - 2  .OR. &
+                 ( bc_dirichlet_s  .OR.  bc_radiation_s )  .AND.  j <= nys + 2  .OR. &
+                 ( bc_dirichlet_n  .OR.  bc_radiation_n )  .AND.  j >= nyn - 2 )  THEN
+                nzb_max_l = nzt
+             ELSE
+                nzb_max_l = nzb_max
+             END IF
+
 #ifndef _OPENACC
-!
-!--    First compute the whole left boundary of the processor domain
-       i = nxl
-       DO  j = nysv, nyn
-          DO  k = nzb+1, nzb_max_l
-
-             ibit11 = REAL( IBITS(advc_flags_m(k,j,i-1),11,1), KIND = wp )
-             ibit10 = REAL( IBITS(advc_flags_m(k,j,i-1),10,1), KIND = wp )
-             ibit9  = REAL( IBITS(advc_flags_m(k,j,i-1),9,1),  KIND = wp )
-
-             u_comp                   = u(k,j-1,i) + u(k,j,i) - gu
-             swap_flux_x_local_v(k,j) = u_comp * (                             &
+             IF ( i == nxl )  THEN
+                DO  k = nzb+1, nzb_max_l
+
+                   ibit11 = REAL( IBITS(advc_flags_m(k,j,i-1),11,1), KIND = wp )
+                   ibit10 = REAL( IBITS(advc_flags_m(k,j,i-1),10,1), KIND = wp )
+                   ibit9  = REAL( IBITS(advc_flags_m(k,j,i-1),9,1),  KIND = wp )
+
+                   u_comp(k)        = u(k,j-1,i) + u(k,j,i) - gu
+                   flux_l_v(k,j,tn) = u_comp(k) * (                            &
                                       ( 37.0_wp * ibit11 * adv_mom_5           &
                                    +     7.0_wp * ibit10 * adv_mom_3           &
@@ -5314,5 +5334,5 @@
                                                  )
 
-              swap_diss_x_local_v(k,j) = - ABS( u_comp ) * (                   &
+                   diss_l_v(k,j,tn) = - ABS( u_comp(k) ) * (                   &
                                       ( 10.0_wp * ibit11 * adv_mom_5           &
                                    +     3.0_wp * ibit10 * adv_mom_3           &
@@ -5329,102 +5349,76 @@
                                                            )
 
-          ENDDO
-
-          DO  k = nzb_max_l+1, nzt
-
-             u_comp                   = u(k,j-1,i) + u(k,j,i) - gu
-             swap_flux_x_local_v(k,j) = u_comp * (                             &
+                ENDDO
+
+                DO  k = nzb_max_l+1, nzt
+
+                   u_comp(k)        = u(k,j-1,i) + u(k,j,i) - gu
+                   flux_l_v(k,j,tn) = u_comp(k) * (                            &
                              37.0_wp * ( v(k,j,i) + v(k,j,i-1)   )             &
                            -  8.0_wp * ( v(k,j,i+1) + v(k,j,i-2) )             &
                            +           ( v(k,j,i+2) + v(k,j,i-3) ) ) * adv_mom_5
-             swap_diss_x_local_v(k,j) = - ABS( u_comp ) * (                    &
+                   diss_l_v(k,j,tn) = - ABS( u_comp(k) ) * (                   &
                              10.0_wp * ( v(k,j,i) - v(k,j,i-1)   )             &
                            -  5.0_wp * ( v(k,j,i+1) - v(k,j,i-2) )             &
                            +           ( v(k,j,i+2) - v(k,j,i-3) ) ) * adv_mom_5
 
-          ENDDO
-
-       ENDDO
+                ENDDO
+             ENDIF
+
+             IF ( j == nysv )  THEN
+                DO  k = nzb+1, nzb_max_l
+
+                   ibit14 = REAL( IBITS(advc_flags_m(k,j-1,i),14,1), KIND = wp )
+                   ibit13 = REAL( IBITS(advc_flags_m(k,j-1,i),13,1), KIND = wp )
+                   ibit12 = REAL( IBITS(advc_flags_m(k,j-1,i),12,1), KIND = wp )
+
+                   v_comp(k)      = v(k,j,i) + v(k,j-1,i) - gv
+                   flux_s_v(k,tn) = v_comp(k) * (                              &
+                                         ( 37.0_wp * ibit14 * adv_mom_5        &
+                                      +     7.0_wp * ibit13 * adv_mom_3        &
+                                      +              ibit12 * adv_mom_1        &
+                                         ) *                                   &
+                                           ( v(k,j,i)   + v(k,j-1,i) )         &
+                                  -      (  8.0_wp * ibit14 * adv_mom_5        &
+                                      +              ibit13 * adv_mom_3        &
+                                         ) *                                   &
+                                           ( v(k,j+1,i) + v(k,j-2,i) )         &
+                                  +      (           ibit14 * adv_mom_5        &
+                                         ) *                                   &
+                                           ( v(k,j+2,i) + v(k,j-3,i) )         &
+                                                )
+
+                   diss_s_v(k,tn) = - ABS( v_comp(k) ) * (                     &
+                                         ( 10.0_wp * ibit14 * adv_mom_5        &
+                                      +     3.0_wp * ibit13 * adv_mom_3        &
+                                      +              ibit12 * adv_mom_1        &
+                                         ) *                                   &
+                                           ( v(k,j,i)   - v(k,j-1,i) )         &
+                                  -      (  5.0_wp * ibit14 * adv_mom_5        &
+                                      +              ibit13 * adv_mom_3        &
+                                         ) *                                   &
+                                           ( v(k,j+1,i) - v(k,j-2,i) )         &
+                                  +      (           ibit14 * adv_mom_5        &
+                                         ) *                                   &
+                                           ( v(k,j+2,i) - v(k,j-3,i) )         &
+                                                         )
+
+                ENDDO
+
+                DO  k = nzb_max_l+1, nzt
+
+                   v_comp(k)      = v(k,j,i) + v(k,j-1,i) - gv
+                   flux_s_v(k,tn) = v_comp(k) * (                              &
+                                 37.0_wp * ( v(k,j,i) + v(k,j-1,i)   )         &
+                               -  8.0_wp * ( v(k,j+1,i) + v(k,j-2,i) )         &
+                               +           ( v(k,j+2,i) + v(k,j-3,i) ) ) * adv_mom_5
+                   diss_s_v(k,tn) = - ABS( v_comp(k) ) * (                     &
+                                 10.0_wp * ( v(k,j,i) - v(k,j-1,i)   )         &
+                               -  5.0_wp * ( v(k,j+1,i) - v(k,j-2,i) )         &
+                               +           ( v(k,j+2,i) - v(k,j-3,i) ) ) * adv_mom_5
+
+                ENDDO
+             ENDIF
 #endif
-
-       !$ACC PARALLEL LOOP COLLAPSE(2) FIRSTPRIVATE(tn, gu, gv) &
-       !$ACC PRIVATE(i, j, k, k_mm, k_pp, k_ppp) &
-       !$ACC PRIVATE(ibit9, ibit10, ibit11, ibit12, ibit13, ibit14) &
-       !$ACC PRIVATE(ibit9_l, ibit10_l, ibit11_l) &
-       !$ACC PRIVATE(ibit12_s, ibit13_s, ibit14_s) &
-       !$ACC PRIVATE(ibit15, ibit16, ibit17) &
-       !$ACC PRIVATE(flux_r, diss_r, flux_l, diss_l) &
-       !$ACC PRIVATE(flux_n, diss_n, flux_s, diss_s) &
-       !$ACC PRIVATE(flux_t, diss_t, flux_d, diss_d) &
-       !$ACC PRIVATE(div, u_comp, u_comp_l, v_comp, v_comp_s, w_comp) &
-       !$ACC PRESENT(advc_flags_m) &
-       !$ACC PRESENT(u, v, w) &
-       !$ACC PRESENT(drho_air, rho_air_zw, ddzw) &
-       !$ACC PRESENT(tend) &
-       !$ACC PRESENT(hom(nzb+1:nzb_max_l,1,2:3,0)) &
-       !$ACC PRESENT(weight_substep(intermediate_timestep_count)) &
-       !$ACC PRESENT(sums_vs2_ws_l, sums_wsvs_ws_l)
-       DO i = nxl, nxr
-
-#ifndef _OPENACC
-          j = nysv
-          DO  k = nzb+1, nzb_max_l
-
-             ibit14 = REAL( IBITS(advc_flags_m(k,j-1,i),14,1), KIND = wp )
-             ibit13 = REAL( IBITS(advc_flags_m(k,j-1,i),13,1), KIND = wp )
-             ibit12 = REAL( IBITS(advc_flags_m(k,j-1,i),12,1), KIND = wp )
-
-             v_comp                 = v(k,j,i) + v(k,j-1,i) - gv
-             swap_flux_y_local_v(k) = v_comp * (                               &
-                                   ( 37.0_wp * ibit14 * adv_mom_5              &
-                                +     7.0_wp * ibit13 * adv_mom_3              &
-                                +              ibit12 * adv_mom_1              &
-                                   ) *                                         &
-                                     ( v(k,j,i)   + v(k,j-1,i) )               &
-                            -      (  8.0_wp * ibit14 * adv_mom_5              &
-                                +              ibit13 * adv_mom_3              &
-                                   ) *                                         &
-                                     ( v(k,j+1,i) + v(k,j-2,i) )               &
-                            +      (           ibit14 * adv_mom_5              &
-                                   ) *                                         &
-                                     ( v(k,j+2,i) + v(k,j-3,i) )               &
-                                                 )
-
-             swap_diss_y_local_v(k) = - ABS( v_comp ) * (                      &
-                                   ( 10.0_wp * ibit14 * adv_mom_5              &
-                                +     3.0_wp * ibit13 * adv_mom_3              &
-                                +              ibit12 * adv_mom_1              &
-                                   ) *                                         &
-                                     ( v(k,j,i)   - v(k,j-1,i) )               &
-                            -      (  5.0_wp * ibit14 * adv_mom_5              &
-                                +              ibit13 * adv_mom_3              &
-                                   ) *                                         &
-                                     ( v(k,j+1,i) - v(k,j-2,i) )               &
-                            +      (           ibit14 * adv_mom_5              &
-                                   ) *                                         &
-                                     ( v(k,j+2,i) - v(k,j-3,i) )               &
-                                                          )
-
-          ENDDO
-
-          DO  k = nzb_max_l+1, nzt
-
-             v_comp                 = v(k,j,i) + v(k,j-1,i) - gv
-             swap_flux_y_local_v(k) = v_comp * (                               &
-                           37.0_wp * ( v(k,j,i) + v(k,j-1,i)   )               &
-                         -  8.0_wp * ( v(k,j+1,i) + v(k,j-2,i) )               &
-                         +           ( v(k,j+2,i) + v(k,j-3,i) ) ) * adv_mom_5
-             swap_diss_y_local_v(k) = - ABS( v_comp ) * (                      &
-                           10.0_wp * ( v(k,j,i) - v(k,j-1,i)   )               &
-                         -  5.0_wp * ( v(k,j+1,i) - v(k,j-2,i) )               &
-                         +           ( v(k,j+2,i) - v(k,j-3,i) ) ) * adv_mom_5
-
-          ENDDO
-#endif
-
-          DO  j = nysv, nyn
-
-             flux_d    = 0.0_wp
-             diss_d    = 0.0_wp
 
              DO  k = nzb+1, nzb_max_l
@@ -5434,6 +5428,6 @@
                 ibit9  = REAL( IBITS(advc_flags_m(k,j,i),9,1),  KIND = wp )
 
-                u_comp = u(k,j-1,i+1) + u(k,j,i+1) - gu
-                flux_r = u_comp * (                                            &
+                u_comp(k) = u(k,j-1,i+1) + u(k,j,i+1) - gu
+                flux_r(k) = u_comp(k) * (                                      &
                           ( 37.0_wp * ibit11 * adv_mom_5                       &
                        +     7.0_wp * ibit10 * adv_mom_3                       &
@@ -5448,7 +5442,7 @@
                           ) *                                                  &
                                  ( v(k,j,i+3) + v(k,j,i-2) )                   &
-                                     )
-
-                diss_r = - ABS( u_comp ) * (                                   &
+                                        )
+
+                diss_r(k) = - ABS( u_comp(k) ) * (                             &
                           ( 10.0_wp * ibit11 * adv_mom_5                       &
                        +     3.0_wp * ibit10 * adv_mom_3                       &
@@ -5463,5 +5457,5 @@
                           ) *                                                  &
                                  ( v(k,j,i+3) - v(k,j,i-2) )                   &
-                                              )
+                                                 )
 
 #ifdef _OPENACC
@@ -5472,6 +5466,6 @@
                 ibit9_l  = REAL( IBITS(advc_flags_m(k,j,i-1),9,1),  KIND = wp )
 
-                u_comp_l  = u(k,j-1,i) + u(k,j,i) - gu
-                flux_l    = u_comp_l * (                                       &
+                u_comp_l            = u(k,j-1,i) + u(k,j,i) - gu
+                flux_l_v(k,j,tn)    = u_comp_l * (                             &
                                       ( 37.0_wp * ibit11_l * adv_mom_5         &
                                    +     7.0_wp * ibit10_l * adv_mom_3         &
@@ -5488,5 +5482,5 @@
                                                  )
 
-                 diss_l   = - ABS( u_comp_l ) * (                              &
+                 diss_l_v(k,j,tn)   = - ABS( u_comp_l ) * (                    &
                                       ( 10.0_wp * ibit11_l * adv_mom_5         &
                                    +     3.0_wp * ibit10_l * adv_mom_3         &
@@ -5502,7 +5496,4 @@
                                      ( v(k,j,i+2) - v(k,j,i-3) )               &
                                                            )
-#else
-                flux_l = swap_flux_x_local_v(k,j)
-                diss_l = swap_diss_x_local_v(k,j)
 #endif
 
@@ -5511,6 +5502,6 @@
                 ibit12 = REAL( IBITS(advc_flags_m(k,j,i),12,1), KIND = wp )
 
-                v_comp = v(k,j+1,i) + v(k,j,i)
-                flux_n = ( v_comp - gv ) * (                                   &
+                v_comp(k) = v(k,j+1,i) + v(k,j,i)
+                flux_n(k) = ( v_comp(k) - gv ) * (                             &
                           ( 37.0_wp * ibit14 * adv_mom_5                       &
                        +     7.0_wp * ibit13 * adv_mom_3                       &
@@ -5527,5 +5518,5 @@
                                      )
 
-                diss_n = - ABS( v_comp - gv ) * (                              &
+                diss_n(k) = - ABS( v_comp(k) - gv ) * (                        &
                           ( 10.0_wp * ibit14 * adv_mom_5                       &
                        +     3.0_wp * ibit13 * adv_mom_3                       &
@@ -5549,6 +5540,6 @@
                 ibit12_s = REAL( IBITS(advc_flags_m(k,j-1,i),12,1), KIND = wp )
 
-                v_comp_s = v(k,j,i) + v(k,j-1,i) - gv
-                flux_s   = v_comp_s * (                                        &
+                v_comp_s         = v(k,j,i) + v(k,j-1,i) - gv
+                flux_s_v(k,tn)   = v_comp_s * (                                &
                                    ( 37.0_wp * ibit14_s * adv_mom_5            &
                                 +     7.0_wp * ibit13_s * adv_mom_3            &
@@ -5563,7 +5554,7 @@
                                    ) *                                         &
                                      ( v(k,j+2,i) + v(k,j-3,i) )               &
-                                                 )
-
-                diss_s   = - ABS( v_comp_s ) * (                               &
+                                               )
+
+               diss_s_v(k,tn)   = - ABS( v_comp_s ) * (                        &
                                    ( 10.0_wp * ibit14_s * adv_mom_5            &
                                 +     3.0_wp * ibit13_s * adv_mom_3            &
@@ -5578,10 +5569,73 @@
                                    ) *                                         &
                                      ( v(k,j+2,i) - v(k,j-3,i) )               &
-                                                          )
-#else
-               flux_s = swap_flux_y_local_v(k)
-               diss_s = swap_diss_y_local_v(k)
+                                                      )
 #endif
-
+             ENDDO
+
+             DO  k = nzb_max_l+1, nzt
+
+                u_comp(k) = u(k,j-1,i+1) + u(k,j,i+1) - gu
+                flux_r(k) = u_comp(k) * (                                      &
+                      37.0_wp * ( v(k,j,i+1) + v(k,j,i)   )                    &
+                    -  8.0_wp * ( v(k,j,i+2) + v(k,j,i-1) )                    &
+                    +           ( v(k,j,i+3) + v(k,j,i-2) ) ) * adv_mom_5
+
+                diss_r(k) = - ABS( u_comp(k) ) * (                             &
+                      10.0_wp * ( v(k,j,i+1) - v(k,j,i) )                      &
+                    -  5.0_wp * ( v(k,j,i+2) - v(k,j,i-1) )                    &
+                    +           ( v(k,j,i+3) - v(k,j,i-2) ) ) * adv_mom_5
+
+#ifdef _OPENACC
+!
+!--             Recompute the left fluxes.
+                u_comp_l           = u(k,j-1,i) + u(k,j,i) - gu
+                flux_l_v(k,j,tn)   = u_comp_l * (                              &
+                             37.0_wp * ( v(k,j,i) + v(k,j,i-1)   )             &
+                           -  8.0_wp * ( v(k,j,i+1) + v(k,j,i-2) )             &
+                           +           ( v(k,j,i+2) + v(k,j,i-3) ) ) * adv_mom_5
+                diss_l_v(k,j,tn)   = - ABS( u_comp_l ) * (                     &
+                             10.0_wp * ( v(k,j,i) - v(k,j,i-1)   )             &
+                           -  5.0_wp * ( v(k,j,i+1) - v(k,j,i-2) )             &
+                           +           ( v(k,j,i+2) - v(k,j,i-3) ) ) * adv_mom_5
+#endif
+
+                v_comp(k) = v(k,j+1,i) + v(k,j,i)
+                flux_n(k) = ( v_comp(k) - gv ) * (                             &
+                      37.0_wp * ( v(k,j+1,i) + v(k,j,i)   )                    &
+                    -  8.0_wp * ( v(k,j+2,i) + v(k,j-1,i) )                    &
+                      +         ( v(k,j+3,i) + v(k,j-2,i) ) ) * adv_mom_5
+
+                diss_n(k) = - ABS( v_comp(k) - gv ) * (                        &
+                      10.0_wp * ( v(k,j+1,i) - v(k,j,i)   )                    &
+                    -  5.0_wp * ( v(k,j+2,i) - v(k,j-1,i) )                    &
+                    +           ( v(k,j+3,i) - v(k,j-2,i) ) ) * adv_mom_5
+
+#ifdef _OPENACC
+!
+!--             Recompute the south fluxes.
+                v_comp_s = v(k,j,i) + v(k,j-1,i) - gv
+                flux_s_v(k,tn)   = v_comp_s * (                                &
+                           37.0_wp * ( v(k,j,i) + v(k,j-1,i)   )               &
+                         -  8.0_wp * ( v(k,j+1,i) + v(k,j-2,i) )               &
+                         +           ( v(k,j+2,i) + v(k,j-3,i) ) ) * adv_mom_5
+                diss_s_v(k,tn)   = - ABS( v_comp_s ) * (                       &
+                           10.0_wp * ( v(k,j,i) - v(k,j-1,i)   )               &
+                         -  5.0_wp * ( v(k,j+1,i) - v(k,j-2,i) )               &
+                         +           ( v(k,j+2,i) - v(k,j-3,i) ) ) * adv_mom_5
+#endif
+             ENDDO
+!
+!--          Now, compute vertical fluxes. Split loop into a part treating the
+!--          lowest 2 grid points with indirect indexing, a main loop without
+!--          indirect indexing, and a loop for the uppermost 2 grip points with
+!--          indirect indexing. This allows better vectorization for the main loop.
+!--          First, compute the flux at model surface, which need has to be
+!--          calculated explicetely for the tendency at
+!--          the first w-level. For topography wall this is done implicitely by
+!--          advc_flags_m.
+             flux_t(nzb) = 0.0_wp
+             diss_t(nzb) = 0.0_wp
+             w_comp(nzb) = 0.0_wp
+             DO  k = nzb+1, nzb+2
 !
 !--             k index has to be modified near bottom and top, else array
@@ -5595,6 +5649,6 @@
                 k_mm  = k - 2 * ibit17
 
-                w_comp = w(k,j-1,i) + w(k,j,i)
-                flux_t = w_comp * rho_air_zw(k) * (                            &
+                w_comp(k) = w(k,j-1,i) + w(k,j,i)
+                flux_t(k) = w_comp(k) * rho_air_zw(k) * (                      &
                           ( 37.0_wp * ibit17 * adv_mom_5                       &
                        +     7.0_wp * ibit16 * adv_mom_3                       &
@@ -5609,7 +5663,7 @@
                           ) *                                                  &
                              ( v(k_ppp,j,i) + v(k_mm,j,i) )                    &
-                                      )
-
-                diss_t = - ABS( w_comp ) * rho_air_zw(k) * (                   &
+                                                        )
+
+                diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (             &
                           ( 10.0_wp * ibit17 * adv_mom_5                       &
                        +     3.0_wp * ibit16 * adv_mom_3                       &
@@ -5624,141 +5678,45 @@
                           ) *                                                  &
                              ( v(k_ppp,j,i) - v(k_mm,j,i) )                    &
-                                               )
-!
-!--             Calculate the divergence of the velocity field. A respective
-!--             correction is needed to overcome numerical instabilities caused
-!--             by a not sufficient reduction of divergences near topography.
-                div = ( ( ( u_comp     + gu )                                  &
-                                       * ( ibit9 + ibit10 + ibit11 )           &
-                - ( u(k,j-1,i)   + u(k,j,i) )                                  &
-                                       * (                                     &
-                        REAL( IBITS(advc_flags_m(k,j,i-1),9,1), KIND = wp )    &
-                      + REAL( IBITS(advc_flags_m(k,j,i-1),10,1), KIND = wp )   &
-                      + REAL( IBITS(advc_flags_m(k,j,i-1),11,1), KIND = wp )   &
-                                         )                                     &
-                  ) * ddx                                                      &
-               +  ( v_comp                                                     &
-                                       * ( ibit12 + ibit13 + ibit14 )          &
-                - ( v(k,j,i)     + v(k,j-1,i) )                                &
-                                       * (                                     &
-                        REAL( IBITS(advc_flags_m(k,j-1,i),12,1), KIND = wp )   &
-                      + REAL( IBITS(advc_flags_m(k,j-1,i),13,1), KIND = wp )   & 
-                      + REAL( IBITS(advc_flags_m(k,j-1,i),14,1), KIND = wp )   &
-                                         )                                     &
-                  ) * ddy                                                      & 
-               +  ( w_comp * rho_air_zw(k)                                     &
-                                       * ( ibit15 + ibit16 + ibit17 )          &
-                - ( w(k-1,j-1,i) + w(k-1,j,i) ) * rho_air_zw(k-1)              &
-                                       * (                                     &
-                        REAL( IBITS(advc_flags_m(k-1,j,i),15,1), KIND = wp )   &
-                      + REAL( IBITS(advc_flags_m(k-1,j,i),16,1), KIND = wp )   &
-                      + REAL( IBITS(advc_flags_m(k-1,j,i),17,1), KIND = wp )   &
-                                         )                                     &
-                   ) * drho_air(k) * ddzw(k)                                   &
-                ) * 0.5_wp
-
-
-                tend(k,j,i) = tend(k,j,i) - (                                  &
-                       ( ( flux_r + diss_r )                                   &
-                     -   ( flux_l + diss_l ) ) * ddx                           &
-                     + ( ( flux_n + diss_n )                                   &
-                     -   ( flux_s + diss_s ) ) * ddy                           &
-                     + ( ( flux_t + diss_t )                                   &
-                     -   ( flux_d + diss_d ) ) * drho_air(k) * ddzw(k)         &
-                                            )  + v(k,j,i) * div
-
-#ifndef _OPENACC
-                swap_flux_x_local_v(k,j) = flux_r
-                swap_diss_x_local_v(k,j) = diss_r
-                swap_flux_y_local_v(k)   = flux_n
-                swap_diss_y_local_v(k)   = diss_n
-#endif
-                flux_d                   = flux_t
-                diss_d                   = diss_t
-
-!
-!--             Statistical Evaluation of v'v'. The factor has to be applied
-!--             for right evaluation when gallilei_trans = .T. .
-                !$ACC ATOMIC
-                sums_vs2_ws_l(k,tn) = sums_vs2_ws_l(k,tn)                      &
-                + ( flux_n                                                     &
-                    * ( v_comp - 2.0_wp * hom(k,1,2,0)                   )     &
-                    / ( v_comp - gv + SIGN( 1.0E-20_wp, v_comp - gv )    )     &
-               +   diss_n                                                      &
-                    *   ABS( v_comp - 2.0_wp * hom(k,1,2,0)              )     &
-                    / ( ABS( v_comp - gv ) + 1.0E-20_wp                  )     &
-                  ) *   weight_substep(intermediate_timestep_count)
-!
-!--             Statistical Evaluation of w'u'.
-                !$ACC ATOMIC
-                sums_wsvs_ws_l(k,tn) = sums_wsvs_ws_l(k,tn)                    &
-                + ( flux_t                                                     &
-                    * ( w_comp - 2.0_wp * hom(k,1,3,0)                   )     &
-                    / ( w_comp + SIGN( 1.0E-20_wp, w_comp )              )     &
-               +   diss_t                                                      &
-                    *   ABS( w_comp - 2.0_wp * hom(k,1,3,0)              )     &
-                    / ( ABS( w_comp ) + 1.0E-20_wp                       )     &
-                  ) *   weight_substep(intermediate_timestep_count)
-
+                                                                 )
              ENDDO
 
-             DO  k = nzb_max_l+1, nzt
-
-                u_comp = u(k,j-1,i+1) + u(k,j,i+1) - gu
-                flux_r = u_comp * (                                            &
-                      37.0_wp * ( v(k,j,i+1) + v(k,j,i)   )                    &
-                    -  8.0_wp * ( v(k,j,i+2) + v(k,j,i-1) )                    &
-                    +           ( v(k,j,i+3) + v(k,j,i-2) ) ) * adv_mom_5
-
-                diss_r = - ABS( u_comp ) * (                                   &
-                      10.0_wp * ( v(k,j,i+1) - v(k,j,i) )                      &
-                    -  5.0_wp * ( v(k,j,i+2) - v(k,j,i-1) )                    &
-                    +           ( v(k,j,i+3) - v(k,j,i-2) ) ) * adv_mom_5
-
-#ifdef _OPENACC
-!
-!--             Recompute the left fluxes.
-                u_comp_l = u(k,j-1,i) + u(k,j,i) - gu
-                flux_l   = u_comp_l * (                                        &
-                             37.0_wp * ( v(k,j,i) + v(k,j,i-1)   )             &
-                           -  8.0_wp * ( v(k,j,i+1) + v(k,j,i-2) )             &
-                           +           ( v(k,j,i+2) + v(k,j,i-3) ) ) * adv_mom_5
-                diss_l   = - ABS( u_comp_l ) * (                               &
-                             10.0_wp * ( v(k,j,i) - v(k,j,i-1)   )             &
-                           -  5.0_wp * ( v(k,j,i+1) - v(k,j,i-2) )             &
-                           +           ( v(k,j,i+2) - v(k,j,i-3) ) ) * adv_mom_5
-#else
-                flux_l = swap_flux_x_local_v(k,j)
-                diss_l = swap_diss_x_local_v(k,j)
-#endif
-
-                v_comp = v(k,j+1,i) + v(k,j,i)
-                flux_n = ( v_comp - gv ) * (                                   &
-                      37.0_wp * ( v(k,j+1,i) + v(k,j,i)   )                    &
-                    -  8.0_wp * ( v(k,j+2,i) + v(k,j-1,i) )                    &
-                      +         ( v(k,j+3,i) + v(k,j-2,i) ) ) * adv_mom_5
-
-                diss_n = - ABS( v_comp - gv ) * (                              &
-                      10.0_wp * ( v(k,j+1,i) - v(k,j,i)   )                    &
-                    -  5.0_wp * ( v(k,j+2,i) - v(k,j-1,i) )                    &
-                    +           ( v(k,j+3,i) - v(k,j-2,i) ) ) * adv_mom_5
-
-#ifdef _OPENACC
-!
-!--             Recompute the south fluxes.
-                v_comp_s = v(k,j,i) + v(k,j-1,i) - gv
-                flux_s   = v_comp_s * (                                        &
-                           37.0_wp * ( v(k,j,i) + v(k,j-1,i)   )               &
-                         -  8.0_wp * ( v(k,j+1,i) + v(k,j-2,i) )               &
-                         +           ( v(k,j+2,i) + v(k,j-3,i) ) ) * adv_mom_5
-                diss_s   = - ABS( v_comp_s ) * (                               &
-                           10.0_wp * ( v(k,j,i) - v(k,j-1,i)   )               &
-                         -  5.0_wp * ( v(k,j+1,i) - v(k,j-2,i) )               &
-                         +           ( v(k,j+2,i) - v(k,j-3,i) ) ) * adv_mom_5
-#else
-                flux_s = swap_flux_y_local_v(k)
-                diss_s = swap_diss_y_local_v(k)
-#endif
-
+             DO  k = nzb+3, nzt-2
+                ibit17 = REAL( IBITS(advc_flags_m(k,j,i),17,1), KIND = wp )
+                ibit16 = REAL( IBITS(advc_flags_m(k,j,i),16,1), KIND = wp )
+                ibit15 = REAL( IBITS(advc_flags_m(k,j,i),15,1), KIND = wp )
+
+                w_comp(k) = w(k,j-1,i) + w(k,j,i)
+                flux_t(k) = w_comp(k) * rho_air_zw(k) * (                      &
+                          ( 37.0_wp * ibit17 * adv_mom_5                       &
+                       +     7.0_wp * ibit16 * adv_mom_3                       &
+                       +              ibit15 * adv_mom_1                       &
+                          ) *                                                  &
+                             ( v(k+1,j,i)  + v(k,j,i)    )                     &
+                   -      (  8.0_wp * ibit17 * adv_mom_5                       &
+                       +              ibit16 * adv_mom_3                       &
+                          ) *                                                  &
+                             ( v(k+2,j,i) + v(k-1,j,i)   )                     &
+                   +      (           ibit17 * adv_mom_5                       &
+                          ) *                                                  &
+                             ( v(k+3,j,i) + v(k-2,j,i)   )                     &
+                                                        )
+
+                diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (             &
+                          ( 10.0_wp * ibit17 * adv_mom_5                       &
+                       +     3.0_wp * ibit16 * adv_mom_3                       &
+                       +              ibit15 * adv_mom_1                       &
+                          ) *                                                  &
+                             ( v(k+1,j,i) - v(k,j,i)     )                     &
+                   -      (  5.0_wp * ibit17 * adv_mom_5                       &
+                       +              ibit16 * adv_mom_3                       &
+                          ) *                                                  &
+                             ( v(k+2,j,i) - v(k-1,j,i)   )                     &
+                   +      (           ibit17 * adv_mom_5                       &
+                          ) *                                                  &
+                             ( v(k+3,j,i) - v(k-2,j,i)   )                     &
+                                                                 )
+             ENDDO
+
+             DO  k = nzt-1, nzt-symmetry_flag
 !
 !--             k index has to be modified near bottom and top, else array
@@ -5772,6 +5730,6 @@
                 k_mm  = k - 2 * ibit17
 
-                w_comp = w(k,j-1,i) + w(k,j,i)
-                flux_t = w_comp * rho_air_zw(k) * (                            &
+                w_comp(k) = w(k,j-1,i) + w(k,j,i)
+                flux_t(k) = w_comp(k) * rho_air_zw(k) * (                      &
                           ( 37.0_wp * ibit17 * adv_mom_5                       &
                        +     7.0_wp * ibit16 * adv_mom_3                       &
@@ -5786,7 +5744,7 @@
                           ) *                                                  &
                              ( v(k_ppp,j,i) + v(k_mm,j,i) )                    &
-                                      )
-
-                diss_t = - ABS( w_comp ) * rho_air_zw(k) * (                   &
+                                                        )
+
+                diss_t(k) = - ABS( w_comp(k) ) * rho_air_zw(k) * (             &
                           ( 10.0_wp * ibit17 * adv_mom_5                       &
                        +     3.0_wp * ibit16 * adv_mom_3                       &
@@ -5801,33 +5759,87 @@
                           ) *                                                  &
                              ( v(k_ppp,j,i) - v(k_mm,j,i) )                    &
-                                               )
+                                                                 )
+             ENDDO
+
+!
+!--          Set resolved/turbulent flux at model top to zero (w-level). In case that
+!--          a symmetric behavior between bottom and top shall be guaranteed (closed
+!--          channel flow), the flux at nzt is also set to zero.
+             IF ( symmetry_flag == 1 ) THEN
+                flux_t(nzt) = 0.0_wp
+                diss_t(nzt) = 0.0_wp
+                w_comp(nzt) = 0.0_wp
+             ENDIF
+             flux_t(nzt+1) = 0.0_wp
+             diss_t(nzt+1) = 0.0_wp
+             w_comp(nzt+1) = 0.0_wp
+
+             DO k = nzb+1, nzb_max_l
+
+                flux_d    = flux_t(k-1)
+                diss_d    = diss_t(k-1)
+
+                ibit11 = REAL( IBITS(advc_flags_m(k,j,i),11,1), KIND = wp )
+                ibit10 = REAL( IBITS(advc_flags_m(k,j,i),10,1), KIND = wp )
+                ibit9  = REAL( IBITS(advc_flags_m(k,j,i),9,1),  KIND = wp )
+
+                ibit14 = REAL( IBITS(advc_flags_m(k,j,i),14,1), KIND = wp )
+                ibit13 = REAL( IBITS(advc_flags_m(k,j,i),13,1), KIND = wp )
+                ibit12 = REAL( IBITS(advc_flags_m(k,j,i),12,1), KIND = wp )
+
+                ibit17 = REAL( IBITS(advc_flags_m(k,j,i),17,1), KIND = wp )
+                ibit16 = REAL( IBITS(advc_flags_m(k,j,i),16,1), KIND = wp )
+                ibit15 = REAL( IBITS(advc_flags_m(k,j,i),15,1), KIND = wp )
 !
 !--             Calculate the divergence of the velocity field. A respective
 !--             correction is needed to overcome numerical instabilities caused
 !--             by a not sufficient reduction of divergences near topography.
-                div = ( ( u_comp + gu - ( u(k,j-1,i)   + u(k,j,i)   ) ) * ddx  &
-                     +  ( v_comp      - ( v(k,j,i)     + v(k,j-1,i) ) ) * ddy  &
-                     +  (   w_comp                      * rho_air_zw(k) -      &
-                          ( w(k-1,j-1,i) + w(k-1,j,i) ) * rho_air_zw(k-1)      &
-                        ) * drho_air(k) * ddzw(k)                              &
-                      ) * 0.5_wp
- 
+                div = ( ( ( u_comp(k)     + gu )                               &
+                                       * ( ibit9 + ibit10 + ibit11 )           &
+                - ( u(k,j-1,i)   + u(k,j,i) )                                  &
+                                       * (                                     &
+                        REAL( IBITS(advc_flags_m(k,j,i-1),9,1), KIND = wp )    &
+                      + REAL( IBITS(advc_flags_m(k,j,i-1),10,1), KIND = wp )   &
+                      + REAL( IBITS(advc_flags_m(k,j,i-1),11,1), KIND = wp )   &
+                                         )                                     &
+                  ) * ddx                                                      &
+               +  ( v_comp(k)                                                  &
+                                       * ( ibit12 + ibit13 + ibit14 )          &
+                - ( v(k,j,i)     + v(k,j-1,i) )                                &
+                                       * (                                     &
+                        REAL( IBITS(advc_flags_m(k,j-1,i),12,1), KIND = wp )   &
+                      + REAL( IBITS(advc_flags_m(k,j-1,i),13,1), KIND = wp )   &
+                      + REAL( IBITS(advc_flags_m(k,j-1,i),14,1), KIND = wp )   &
+                                         )                                     &
+                  ) * ddy                                                      &
+               +  ( w_comp(k) * rho_air_zw(k)                                  &
+                                       * ( ibit15 + ibit16 + ibit17 )          &
+                - ( w(k-1,j-1,i) + w(k-1,j,i) ) * rho_air_zw(k-1)              &
+                                       * (                                     &
+                        REAL( IBITS(advc_flags_m(k-1,j,i),15,1), KIND = wp )   &
+                      + REAL( IBITS(advc_flags_m(k-1,j,i),16,1), KIND = wp )   &
+                      + REAL( IBITS(advc_flags_m(k-1,j,i),17,1), KIND = wp )   &
+                                         )                                     &
+                   ) * drho_air(k) * ddzw(k)                                   &
+                ) * 0.5_wp
+
+
                 tend(k,j,i) = tend(k,j,i) - (                                  &
-                       ( ( flux_r + diss_r )                                   &
-                     -   ( flux_l + diss_l ) ) * ddx                           &
-                     + ( ( flux_n + diss_n )                                   &
-                     -   ( flux_s + diss_s ) ) * ddy                           &
-                     + ( ( flux_t + diss_t )                                   &
+                       ( ( flux_r(k) + diss_r(k) )                             &
+                     -   ( flux_l_v(k,j,tn) + diss_l_v(k,j,tn) ) ) * ddx       &
+                     + ( ( flux_n(k) + diss_n(k) )                             &
+                     -   ( flux_s_v(k,tn) + diss_s_v(k,tn) ) ) * ddy           &
+                     + ( ( flux_t(k) + diss_t(k) )                             &
                      -   ( flux_d + diss_d ) ) * drho_air(k) * ddzw(k)         &
                                             )  + v(k,j,i) * div
 
 #ifndef _OPENACC
-                swap_flux_x_local_v(k,j) = flux_r
-                swap_diss_x_local_v(k,j) = diss_r
-                swap_flux_y_local_v(k)   = flux_n
-                swap_diss_y_local_v(k)   = diss_n
+!
+!--             Swap fluxes. Note, in the OPENACC case these are computed again.
+                flux_l_v(k,j,tn) = flux_r(k)
+                diss_l_v(k,j,tn) = diss_r(k)
+                flux_s_v(k,tn)   = flux_n(k)
+                diss_s_v(k,tn)   = diss_n(k)
 #endif
-                flux_d                   = flux_t
-                diss_d                   = diss_t
 
 !
@@ -5836,10 +5848,10 @@
                 !$ACC ATOMIC
                 sums_vs2_ws_l(k,tn) = sums_vs2_ws_l(k,tn)                      &
-                + ( flux_n                                                     &
-                    * ( v_comp - 2.0_wp * hom(k,1,2,0)                   )     &
-                    / ( v_comp - gv + SIGN( 1.0E-20_wp, v_comp - gv )    )     &
-               +   diss_n                                                      &
-                    *   ABS( v_comp - 2.0_wp * hom(k,1,2,0)              )     &
-                    / ( ABS( v_comp - gv ) + 1.0E-20_wp                  )     &
+                + ( flux_n(k)                                                  &
+                    * ( v_comp(k) - 2.0_wp * hom(k,1,2,0)                   )  &
+                    / ( v_comp(k) - gv + SIGN( 1.0E-20_wp, v_comp(k) - gv ) )  &
+               +   diss_n(k)                                                   &
+                    *   ABS( v_comp(k) - 2.0_wp * hom(k,1,2,0)              )  &
+                    / ( ABS( v_comp(k) - gv ) + 1.0E-20_wp                  )  &
                   ) *   weight_substep(intermediate_timestep_count)
 !
@@ -5847,19 +5859,81 @@
                 !$ACC ATOMIC
                 sums_wsvs_ws_l(k,tn) = sums_wsvs_ws_l(k,tn)                    &
-                + ( flux_t                                                     &
-                    * ( w_comp - 2.0_wp * hom(k,1,3,0)                   )     &
-                    / ( w_comp + SIGN( 1.0E-20_wp, w_comp )              )     &
-               +   diss_t                                                      &
-                    *   ABS( w_comp - 2.0_wp * hom(k,1,3,0)              )     &
-                    / ( ABS( w_comp ) + 1.0E-20_wp                       )     &
+                + ( flux_t(k)                                                  &
+                    * ( w_comp(k) - 2.0_wp * hom(k,1,3,0)                   )  &
+                    / ( w_comp(k) + SIGN( 1.0E-20_wp, w_comp(k) )           )  &
+               +   diss_t(k)                                                   &
+                    *   ABS( w_comp(k) - 2.0_wp * hom(k,1,3,0)              )  &
+                    / ( ABS( w_comp(k) ) + 1.0E-20_wp                       )  &
                   ) *   weight_substep(intermediate_timestep_count)
 
              ENDDO
+
+             DO  k = nzb_max_l+1, nzt
+
+                flux_d    = flux_t(k-1)
+                diss_d    = diss_t(k-1)
+!
+!--             Calculate the divergence of the velocity field. A respective
+!--             correction is needed to overcome numerical instabilities caused
+!--             by a not sufficient reduction of divergences near topography.
+                div = ( ( u_comp(k) + gu - ( u(k,j-1,i)  + u(k,j,i)   ) ) * ddx&
+                     +  ( v_comp(k)      - ( v(k,j,i)    + v(k,j-1,i) ) ) * ddy&
+                     +  ( w_comp(k)                     * rho_air_zw(k) -      &
+                          ( w(k-1,j-1,i) + w(k-1,j,i) ) * rho_air_zw(k-1)      &
+                        ) * drho_air(k) * ddzw(k)                              &
+                      ) * 0.5_wp
+
+                tend(k,j,i) = tend(k,j,i) - (                                  &
+                       ( ( flux_r(k) + diss_r(k) )                             &
+                     -   ( flux_l_v(k,j,tn) + diss_l_v(k,j,tn) ) ) * ddx       &
+                     + ( ( flux_n(k) + diss_n(k) )                             &
+                     -   ( flux_s_v(k,tn) + diss_s_v(k,tn) ) ) * ddy           &
+                     + ( ( flux_t(k) + diss_t(k) )                             &
+                     -   ( flux_d + diss_d ) ) * drho_air(k) * ddzw(k)         &
+                                            )  + v(k,j,i) * div
+
+#ifndef _OPENACC
+!
+!--             Swap fluxes. Note, in the OPENACC case these are computed again.
+                flux_l_v(k,j,tn) = flux_r(k)
+                diss_l_v(k,j,tn) = diss_r(k)
+                flux_s_v(k,tn)   = flux_n(k)
+                diss_s_v(k,tn)   = diss_n(k)
+#endif
+
+!
+!--             Statistical Evaluation of v'v'. The factor has to be applied
+!--             for right evaluation when gallilei_trans = .T. .
+                !$ACC ATOMIC
+                sums_vs2_ws_l(k,tn) = sums_vs2_ws_l(k,tn)                      &
+                + ( flux_n(k)                                                  &
+                    * ( v_comp(k) - 2.0_wp * hom(k,1,2,0)                   )  &
+                    / ( v_comp(k) - gv + SIGN( 1.0E-20_wp, v_comp(k) - gv ) )  &
+               +   diss_n(k)                                                   &
+                    *   ABS( v_comp(k) - 2.0_wp * hom(k,1,2,0)              )  &
+                    / ( ABS( v_comp(k) - gv ) + 1.0E-20_wp                  )  &
+                  ) *   weight_substep(intermediate_timestep_count)
+!
+!--             Statistical Evaluation of w'u'.
+                !$ACC ATOMIC
+                sums_wsvs_ws_l(k,tn) = sums_wsvs_ws_l(k,tn)                    &
+                + ( flux_t(k)                                                  &
+                    * ( w_comp(k) - 2.0_wp * hom(k,1,3,0)                   )  &
+                    / ( w_comp(k) + SIGN( 1.0E-20_wp, w_comp(k) )           )  &
+               +   diss_t(k)                                                   &
+                    *   ABS( w_comp(k) - 2.0_wp * hom(k,1,3,0)              )  &
+                    / ( ABS( w_comp(k) ) + 1.0E-20_wp                       )  &
+                  ) *   weight_substep(intermediate_timestep_count)
+
+             ENDDO
+
           ENDDO
        ENDDO
 
+       CALL cpu_log( log_point_s(69), 'advec_v_ws', 'stop' )
+
     END SUBROUTINE advec_v_ws
-    
-    
+
+
 !------------------------------------------------------------------------------!
 ! Description:
@@ -5876,7 +5950,7 @@
        INTEGER(iwp) ::  k_pp      !< k+2 index in disretization, can be modified to avoid segmentation faults
        INTEGER(iwp) ::  k_ppp     !< k+3 index in disretization, can be modified to avoid segmentation faults
-       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms  
+       INTEGER(iwp) ::  nzb_max_l !< index indicating upper bound for order degradation of horizontal advection terms
        INTEGER(iwp) ::  tn = 0    !< number of OpenMP thread
-       
+
        REAL(wp)    ::  ibit18 !< flag indicating 1st-order scheme along x-direction
        REAL(wp)    ::  ibit19 !< flag indicating 3rd-order scheme along x-direction
@@ -5895,74 +5969,76 @@
        REAL(wp)    ::  ibit23_s !< flag indicating 5th-order scheme along y-direction
 #endif
-       REAL(wp)    ::  ibit24 !< flag indicating 1st-order scheme along z-direction
-       REAL(wp)    ::  ibit25 !< flag indicating 3rd-order scheme along z-direction
-       REAL(wp)    ::  ibit26 !< flag indicating 5th-order scheme along z-direction
-       REAL(wp)    ::  diss_d !< artificial dissipation term at grid box bottom
-       REAL(wp)    ::  div    !< divergence on w-grid
-       REAL(wp)    ::  flux_d !< 6th-order flux at grid box bottom
-       REAL(wp)    ::  gu     !< Galilei-transformation velocity along x
-       REAL(wp)    ::  gv     !< Galilei-transformation velocity along y
-       REAL(wp)    ::  u_comp !< advection velocity along x
+       REAL(wp)    ::  ibit24   !< flag indicating 1st-order scheme along z-direction
+       REAL(wp)    ::  ibit25   !< flag indicating 3rd-order scheme along z-direction
+       REAL(wp)    ::  ibit26   !< flag indicating 5th-order scheme along z-direction
+       REAL(wp)    ::  diss_d   !< artificial dissipation term at grid box bottom
+       REAL(wp)    ::  div      !< divergence on w-grid
+       REAL(wp)    ::  flux_d   !< 6th-order flux at grid box bottom
+       REAL(wp)    ::  gu       !< Galilei-transformation velocity along x
+       REAL(wp)    ::  gv       !< Galilei-transformation velocity along y
 #ifdef _OPENACC
        REAL(wp)    ::  u_comp_l !< advection velocity along x
-#endif
-       REAL(wp)    ::  v_comp !< advection velocity along y
-#ifdef _OPENACC
        REAL(wp)    ::  v_comp_s !< advection velocity along y
 #endif
-       REAL(wp)    ::  w_comp !< advection velocity along z
-       
-       REAL(wp)    ::  diss_t !< discretized artificial dissipation at top of the grid box
-       REAL(wp)    ::  flux_t !< discretized 6th-order flux at top of the grid box
-       
-       REAL(wp)    ::  diss_n !< discretized artificial dissipation at northward-side of the grid box
-       REAL(wp)    ::  diss_r !< discretized artificial dissipation at rightward-side of the grid box
-       REAL(wp)    ::  flux_n !< discretized 6th-order flux at northward-side of the grid box
-       REAL(wp)    ::  flux_r !< discretized 6th-order flux at rightward-side of the grid box
-
-       REAL(wp)    ::  diss_s !< discretized artificial dissipation at southward-side of the grid box
-       REAL(wp)    ::  flux_s !< discretized 6th-order flux at southward-side of the grid box
-#ifndef _OPENACC
-       REAL(wp), DIMENSION(nzb+1:nzt)  ::  swap_diss_y_local_w !< discretized artificial dissipation at southward-side of the grid box
-       REAL(wp), DIMENSION(nzb+1:nzt)  ::  swap_flux_y_local_w !< discretized 6th-order flux at southward-side of the grid box
-#endif
-       
-       REAL(wp)    ::  diss_l !< discretized artificial dissipation at leftward-side of the grid box
-       REAL(wp)    ::  flux_l !< discretized 6th-order flux at leftward-side of the grid box
-#ifndef _OPENACC
-       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn) ::  swap_diss_x_local_w !< discretized artificial dissipation at leftward-side of the grid box
-       REAL(wp), DIMENSION(nzb+1:nzt,nys:nyn) ::  swap_flux_x_local_w !< discretized 6th-order flux at leftward-side of the grid box
-#endif
-!
-!--    Set local version of nzb_max. At non-cyclic boundaries the order of the 
-!--    advection need to be degraded near the boundary. Please note, in contrast
-!--    to the cache-optimized routines, nzb_max_l is set constantly for the 
-!--    entire subdomain, in order to avoid unsymmetric loops which might be 
-!--    an issue for GPUs.
-       IF( bc_dirichlet_l  .OR.  bc_radiation_l  .OR.                          &
-           bc_dirichlet_r  .OR.  bc_radiation_r  .OR.                          &
-           bc_dirichlet_s  .OR.  bc_radiation_s  .OR.                          &
-           bc_dirichlet_n  .OR.  bc_radiation_n )  THEN
-          nzb_max_l = nzt
-       ELSE
-          nzb_max_l = nzb_max
-       END IF
-       
+
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  diss_n !< discretized artificial dissipation at northward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  diss_r !< discretized artificial dissipation at rightward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  diss_t !< discretized artificial dissipation at top of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  flux_n !< discretized 6th-order flux at northward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  flux_r !< discretized 6th-order flux at rightward-side of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  flux_t !< discretized 6th-order flux at top of the grid box
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  u_comp !< advection velocity along x
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  v_comp !< advection velocity along y
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  w_comp !< advection velocity along z
+
+
+       CALL cpu_log( log_point_s(87), 'advec_w_ws', 'start' )
+
        gu = 2.0_wp * u_gtrans
        gv = 2.0_wp * v_gtrans
 
+       !$ACC PARALLEL LOOP COLLAPSE(2) FIRSTPRIVATE(tn, gu, gv) &
+       !$ACC PRIVATE(i, j, k, k_mm, k_pp, k_ppp) &
+       !$ACC PRIVATE(ibit18, ibit19, ibit20, ibit21, ibit22, ibit23) &
+       !$ACC PRIVATE(ibit24, ibit25, ibit26) &
+       !$ACC PRIVATE(ibit18_l, ibit19_l, ibit20_l) &
+       !$ACC PRIVATE(ibit21_s, ibit22_s, ibit23_s) &
+       !$ACC PRIVATE(flux_r, diss_r) &
+       !$ACC PRIVATE(flux_n, diss_n) &
+       !$ACC PRIVATE(flux_t, diss_t, flux_d, diss_d) &
+       !$ACC PRIVATE(flux_l_w, diss_l_w, flux_s_w, diss_s_w) &
+       !$ACC PRIVATE(div, u_comp, u_comp_l, v_comp, v_comp_s, w_comp) &
+       !$ACC PRESENT(advc_flags_m) &
+       !$ACC PRESENT(u, v, w) &
+       !$ACC PRESENT(drho_air, rho_air_zw, ddzw) &
+       !$ACC PRESENT(tend) &
+       !$ACC PRESENT(hom(:,1,1:3,0)) &
+       !$ACC PRESENT(weight_substep(intermediate_timestep_count)) &
+       !$ACC PRESENT(sums_ws2_ws_l)
+       DO  i = nxl, nxr
+          DO  j = nys, nyn
+!
+!--          Used local modified copy of nzb_max (used to degrade order of
+!--          discretization) at non-cyclic boundaries. Modify only at relevant points
+!--          instead of the entire subdomain. This should lead to better
+!--          load balance between boundary and non-boundary PEs.
+             IF( ( bc_dirichlet_l  .OR.  bc_radiation_l )  .AND.  i <= nxl + 2  .OR. &
+                 ( bc_dirichlet_r  .OR.  bc_radiation_r )  .AND.  i >= nxr - 2  .OR. &
+                 ( bc_dirichlet_s  .OR.  bc_radiation_s )  .AND.  j <= nys + 2  .OR. &
+                 ( bc_dirichlet_n  .OR.  bc_radiation_n )  .AND.  j >= nyn - 2 )  THEN
+                nzb_max_l = nzt
+             ELSE
+                nzb_max_l = nzb_max
+             END IF
+
 #ifndef _OPENACC
-!
-!--   compute the whole left boundary of the processor domain
-       i = nxl
-       DO  j = nys, nyn
-          DO  k = nzb+1, nzb_max_l
-
-             ibit20 = REAL( IBITS(advc_flags_m(k,j,i-1),20,1), KIND = wp )
-             ibit19 = REAL( IBITS(advc_flags_m(k,j,i-1),19,1), KIND = wp )
-             ibit18 = REAL( IBITS(advc_flags_m(k,j,i-1),18,1), KIND = wp )
-
-             u_comp                   = u(k+1,j,i) + u(k,j,i) - gu
-             swap_flux_x_local_w(k,j) = u_comp * (                             &
+             IF ( i == nxl )  THEN
+                DO  k = nzb+1, nzb_max_l
+                   ibit20 = REAL( IBITS(advc_flags_m(k,j,i-1),20,1), KIND = wp )
+                   ibit19 = REAL( IBITS(advc_flags_m(k,j,i-1),19,1), KIND = wp )
+                   ibit18 = REAL( IBITS(advc_flags_m(k,j,i-1),18,1), KIND = wp )
+
+                   u_comp(k)        = u(k+1,j,i) + u(k,j,i) - gu
+                   flux_l_w(k,j,tn) = u_comp(k) * (                            &
                                       ( 37.0_wp * ibit20 * adv_mom_5           &
                                    +     7.0_wp * ibit19 * adv_mom_3           &
@@ -5977,7 +6053,7 @@
                                       ) *                                      &
                                      ( w(k,j,i+2) + w(k,j,i-3) )               &
-                                                 )
-
-               swap_diss_x_local_w(k,j) = - ABS( u_comp ) * (                  &
+                                                  )
+
+                   diss_l_w(k,j,tn) = - ABS( u_comp(k) ) * (                   &
                                         ( 10.0_wp * ibit20 * adv_mom_5         &
                                      +     3.0_wp * ibit19 * adv_mom_3         &
@@ -5992,113 +6068,79 @@
                                         ) *                                    &
                                      ( w(k,j,i+2) - w(k,j,i-3) )               &
-                                                            )
-
-          ENDDO
-
-          DO  k = nzb_max_l+1, nzt-1
-
-             u_comp                   = u(k+1,j,i) + u(k,j,i) - gu
-             swap_flux_x_local_w(k,j) = u_comp * (                             &
-                            37.0_wp * ( w(k,j,i) + w(k,j,i-1)   )              &
-                          -  8.0_wp * ( w(k,j,i+1) + w(k,j,i-2) )              &
-                          +           ( w(k,j,i+2) + w(k,j,i-3) ) ) * adv_mom_5
-             swap_diss_x_local_w(k,j) = - ABS( u_comp ) * (                    &
-                            10.0_wp * ( w(k,j,i) - w(k,j,i-1)   )              &
-                          -  5.0_wp * ( w(k,j,i+1) - w(k,j,i-2) )              &
-                          +           ( w(k,j,i+2) - w(k,j,i-3) ) ) * adv_mom_5
-
-          ENDDO
-
-       ENDDO
+                                                           )
+
+                ENDDO
+
+                DO  k = nzb_max_l+1, nzt-1
+
+                   u_comp(k)        = u(k+1,j,i) + u(k,j,i) - gu
+                   flux_l_w(k,j,tn) = u_comp(k) * (                            &
+                               37.0_wp * ( w(k,j,i)   + w(k,j,i-1)   )         &
+                             -  8.0_wp * ( w(k,j,i+1) + w(k,j,i-2) )           &
+                             +           ( w(k,j,i+2) + w(k,j,i-3) ) ) * adv_mom_5
+                   diss_l_w(k,j,tn) = - ABS( u_comp(k) ) * (                   &
+                               10.0_wp * ( w(k,j,i)   - w(k,j,i-1)   )         &
+                             -  5.0_wp * ( w(k,j,i+1) - w(k,j,i-2) )           &
+                             +           ( w(k,j,i+2) - w(k,j,i-3) ) ) * adv_mom_5
+
+                ENDDO
+
+             ENDIF
+
+             IF ( j == nys )  THEN
+                DO  k = nzb+1, nzb_max_l
+
+                   ibit23 = REAL( IBITS(advc_flags_m(k,j-1,i),23,1), KIND = wp )
+                   ibit22 = REAL( IBITS(advc_flags_m(k,j-1,i),22,1), KIND = wp )
+                   ibit21 = REAL( IBITS(advc_flags_m(k,j-1,i),21,1), KIND = wp )
+
+                   v_comp(k)      = v(k+1,j,i) + v(k,j,i) - gv
+                   flux_s_w(k,tn) = v_comp(k) * (                               &
+                                       ( 37.0_wp * ibit23 * adv_mom_5           &
+                                    +     7.0_wp * ibit22 * adv_mom_3           &
+                                    +              ibit21 * adv_mom_1           &
+                                       ) *                                      &
+                                        ( w(k,j,i)   + w(k,j-1,i) )             &
+                                -      (  8.0_wp * ibit23 * adv_mom_5           &
+                                    +              ibit22 * adv_mom_3           &
+                                       ) *                                      &
+                                        ( w(k,j+1,i) + w(k,j-2,i) )             &
+                                +      (           ibit23 * adv_mom_5           &
+                                       ) *                                      &
+                                        ( w(k,j+2,i) + w(k,j-3,i) )             &
+                                                  )
+
+                   diss_s_w(k,tn) = - ABS( v_comp(k) ) * (                      &
+                                       ( 10.0_wp * ibit23 * adv_mom_5           &
+                                    +     3.0_wp * ibit22 * adv_mom_3           &
+                                    +              ibit21 * adv_mom_1           &
+                                       ) *                                      &
+                                        ( w(k,j,i)   - w(k,j-1,i) )             &
+                                -      (  5.0_wp * ibit23 * adv_mom_5           &
+                                    +              ibit22 * adv_mom_3           &
+                                       ) *                                      &
+                                        ( w(k,j+1,i) - w(k,j-2,i) )             &
+                                +      (           ibit23 * adv_mom_5           &
+                                       ) *                                      &
+                                        ( w(k,j+2,i) - w(k,j-3,i) )             &
+                                                           )
+
+                ENDDO
+
+                DO  k = nzb_max_l+1, nzt-1
+
+                   v_comp(k)      = v(k+1,j,i) + v(k,j,i) - gv
+                   flux_s_w(k,tn) = v_comp(k) * (                               &
+                              37.0_wp * ( w(k,j,i) + w(k,j-1,i)   )             &
+                            -  8.0_wp * ( w(k,j+1,i) +w(k,j-2,i)  )             &
+                            +           ( w(k,j+2,i) + w(k,j-3,i) ) ) * adv_mom_5
+                   diss_s_w(k,tn) = - ABS( v_comp(k) ) * (                      &
+                              10.0_wp * ( w(k,j,i) - w(k,j-1,i)   )             &
+                            -  5.0_wp * ( w(k,j+1,i) - w(k,j-2,i) )             &
+                            +           ( w(k,j+2,i) - w(k,j-3,i) ) ) * adv_mom_5
+
+                ENDDO
+             ENDIF
 #endif
-
-       !$ACC PARALLEL LOOP COLLAPSE(2) FIRSTPRIVATE(tn, gu, gv) &
-       !$ACC PRIVATE(i, j, k, k_mm, k_pp, k_ppp) &
-       !$ACC PRIVATE(ibit18, ibit19, ibit20, ibit21, ibit22, ibit23) &
-       !$ACC PRIVATE(ibit18_l, ibit19_l, ibit20_l) &
-       !$ACC PRIVATE(ibit21_s, ibit22_s, ibit23_s) &
-       !$ACC PRIVATE(ibit24, ibit25, ibit26) &
-       !$ACC PRIVATE(flux_r, diss_r, flux_l, diss_l) &
-       !$ACC PRIVATE(flux_n, diss_n, flux_s, diss_s) &
-       !$ACC PRIVATE(flux_t, diss_t, flux_d, diss_d) &
-       !$ACC PRIVATE(div, u_comp, u_comp_l, v_comp, v_comp_s, w_comp) &
-       !$ACC PRESENT(advc_flags_m) &
-       !$ACC PRESENT(u, v, w) &
-       !$ACC PRESENT(rho_air, drho_air_zw, ddzu) &
-       !$ACC PRESENT(tend) &
-       !$ACC PRESENT(hom(nzb+1:nzb_max_l,1,3,0)) &
-       !$ACC PRESENT(weight_substep(intermediate_timestep_count)) &
-       !$ACC PRESENT(sums_ws2_ws_l(nzb+1:nzb_max_l,0))
-       DO i = nxl, nxr
-
-#ifndef _OPENACC
-          j = nys
-          DO  k = nzb+1, nzb_max_l
-
-             ibit23 = REAL( IBITS(advc_flags_m(k,j-1,i),23,1),  KIND = wp )
-             ibit22 = REAL( IBITS(advc_flags_m(k,j-1,i),22,1), KIND = wp )
-             ibit21 = REAL( IBITS(advc_flags_m(k,j-1,i),21,1), KIND = wp )
-
-             v_comp                 = v(k+1,j,i) + v(k,j,i) - gv
-             swap_flux_y_local_w(k) = v_comp * (                               &
-                                    ( 37.0_wp * ibit23 * adv_mom_5             &
-                                 +     7.0_wp * ibit22 * adv_mom_3             &
-                                 +              ibit21 * adv_mom_1             &
-                                    ) *                                        &
-                                     ( w(k,j,i)   + w(k,j-1,i) )               &
-                             -      (  8.0_wp * ibit23 * adv_mom_5             &
-                                 +              ibit22 * adv_mom_3             &
-                                    ) *                                        &
-                                     ( w(k,j+1,i) + w(k,j-2,i) )               &
-                             +      (           ibit23 * adv_mom_5             &
-                                    ) *                                        &
-                                     ( w(k,j+2,i) + w(k,j-3,i) )               &
-                                               )
-
-             swap_diss_y_local_w(k) = - ABS( v_comp ) * (                      &
-                                    ( 10.0_wp * ibit23 * adv_mom_5             &
-                                 +     3.0_wp * ibit22 * adv_mom_3             &
-                                 +              ibit21 * adv_mom_1             &
-                                    ) *                                        &
-                                     ( w(k,j,i)   - w(k,j-1,i) )               &
-                             -      (  5.0_wp * ibit23 * adv_mom_5             &
-                                 +              ibit22 * adv_mom_3             &
-                                    ) *                                        &
-                                     ( w(k,j+1,i) - w(k,j-2,i) )               &
-                             +      (           ibit23 * adv_mom_5             &
-                                    ) *                                        &
-                                     ( w(k,j+2,i) - w(k,j-3,i) )               &
-                                                        )
-
-          ENDDO
-
-          DO  k = nzb_max_l+1, nzt-1
-
-             v_comp                 = v(k+1,j,i) + v(k,j,i) - gv
-             swap_flux_y_local_w(k) = v_comp * (                               &
-                           37.0_wp * ( w(k,j,i) + w(k,j-1,i)   )               &
-                         -  8.0_wp * ( w(k,j+1,i) +w(k,j-2,i)  )               &
-                         +           ( w(k,j+2,i) + w(k,j-3,i) ) ) * adv_mom_5
-             swap_diss_y_local_w(k) = - ABS( v_comp ) * (                      &
-                           10.0_wp * ( w(k,j,i) - w(k,j-1,i)   )               &
-                         -  5.0_wp * ( w(k,j+1,i) - w(k,j-2,i) )               &
-                         +           ( w(k,j+2,i) - w(k,j-3,i) ) ) * adv_mom_5
-
-          ENDDO
-#endif
-
-          DO  j = nys, nyn
-
-!
-!--          The lower flux has to be calculated explicitly for the tendency
-!--          at the first w-level. For topography wall this is done implicitely
-!--          by advc_flags_m.
-             k      = nzb + 1
-             w_comp = w(k,j,i) + w(k-1,j,i)
-             flux_d = w_comp       * rho_air(k)                                &
-                    * ( w(k,j,i) + w(k-1,j,i) ) * adv_mom_1
-             diss_d = -ABS(w_comp) * rho_air(k)                                &
-                    * ( w(k,j,i) - w(k-1,j,i) ) * adv_mom_1
-
              DO  k = nzb+1, nzb_max_l
 
@@ -6107,6 +6149,6 @@
                 ibit18 = REAL( IBITS(advc_flags_m(k,j,i),18,1), KIND = wp )
 
-                u_comp = u(k+1,j,i+1) + u(k,j,i+1) - gu
-                flux_r = u_comp * (                                            &
+                u_comp(k) = u(k+1,j,i+1) + u(k,j,i+1) - gu
+                flux_r(k) = u_comp(k) * (                                      &
                           ( 37.0_wp * ibit20 * adv_mom_5                       &
                        +     7.0_wp * ibit19 * adv_mom_3                       &
@@ -6121,7 +6163,7 @@
                           ) *                                                  &
                                  ( w(k,j,i+3) + w(k,j,i-2) )                   &
-                                     )
-
-                diss_r = - ABS( u_comp ) * (                                   &
+                                        )
+
+                diss_r(k) = - ABS( u_comp(k) ) * (                             &
                           ( 10.0_wp * ibit20 * adv_mom_5                       &
                        +     3.0_wp * ibit19 * adv_mom_3                       &
@@ -6136,5 +6178,5 @@
                           ) *                                                  &
                                  ( w(k,j,i+3) - w(k,j,i-2) )                   &
-                                              )
+                                                 )
 
 #ifdef _OPENACC
@@ -6145,6 +6187,6 @@
                 ibit18_l = REAL( IBITS(advc_flags_m(k,j,i-1),18,1), KIND = wp )
 
-                u_comp_l = u(k+1,j,i) + u(k,j,i) - gu
-                flux_l   = u_comp_l * (                                        &
+                u_comp_l           = u(k+1,j,i) + u(k,j,i) - gu
+                flux_l_w(k,j,tn)   = u_comp_l * (                              &
                                       ( 37.0_wp * ibit20_l * adv_mom_5         &
                                    +     7.0_wp * ibit19_l * adv_mom_3         &
@@ -6159,7 +6201,7 @@
                                       ) *                                      &
                                      ( w(k,j,i+2) + w(k,j,i-3) )               &
-                                                 )
-
-                diss_l   = - ABS( u_comp_l ) * (                               &
+                                                )
+
+                diss_l_w(k,j,tn)   = - ABS( u_comp_l ) * (                     &
                                         ( 10.0_wp * ibit20_l * adv_mom_5       &
                                      +     3.0_wp * ibit19_l * adv_mom_3       &
@@ -6174,8 +6216,5 @@
                                         ) *                                    &
                                      ( w(k,j,i+2) - w(k,j,i-3) )               &
-                                                            )
-#else
-                flux_l = swap_flux_x_local_w(k,j)
-                diss_l = swap_diss_x_local_w(k,j)
+                                                         )
 #endif
 
@@ -6185,6 +6224,6 @@
                 ibit21 = REAL( IBITS(advc_flags_m(k,j,i),21,1), KIND = wp )
 
-                v_comp = v(k+1,j+1,i) + v(k,j+1,i) - gv
-                flux_n = v_comp * (                                            &
+                v_comp(k) = v(k+1,j+1,i) + v(k,j+1,i) - gv
+                flux_n(k) = v_comp(k) * (                                      &
                           ( 37.0_wp * ibit23 * adv_mom_5                       &
                        +     7.0_wp * ibit22 * adv_mom_3                       &
@@ -6199,7 +6238,7 @@
                           ) *                                                  &
                                  ( w(k,j+3,i) + w(k,j-2,i) )                   &
-                                     )
-
-                diss_n = - ABS( v_comp ) * (                                   &
+                                        )
+
+                diss_n(k) = - ABS( v_comp(k) ) * (                             &
                           ( 10.0_wp * ibit23 * adv_mom_5                       &
                        +     3.0_wp * ibit22 * adv_mom_3                       &
@@ -6214,5 +6253,5 @@
                           ) *                                                  &
                                  ( w(k,j+3,i) - w(k,j-2,i) )                   &
-                                              )
+                                                 )
 
 #ifdef _OPENACC
@@ -6223,6 +6262,6 @@
                 ibit21_s = REAL( IBITS(advc_flags_m(k,j-1,i),21,1), KIND = wp )
 
-                v_comp_s = v(k+1,j,i) + v(k,j,i) - gv
-                flux_s   = v_comp_s * (                                        &
+                v_comp_s         = v(k+1,j,i) + v(k,j,i) - gv
+                flux_s_w(k,tn)   = v_comp_s * (                                &
                                     ( 37.0_wp * ibit23_s * adv_mom_5           &
                                  +     7.0_wp * ibit22_s * adv_mom_3           &
@@ -6237,7 +6276,7 @@
                                     ) *                                        &
                                      ( w(k,j+2,i) + w(k,j-3,i) )               &
-                                               )
-
-                diss_s   = - ABS( v_comp_s ) * (                               &
+                                              )
+
+                diss_s_w(k,tn)   = - ABS( v_comp_s ) * (                       &
                                     ( 10.0_wp * ibit23_s * adv_mom_5           &
                                  +     3.0_wp * ibit22_s * adv_mom_3           &
@@ -6253,9 +6292,76 @@
                                      ( w(k,j+2,i) - w(k,j-3,i) )               &
                                                         )
-#else
-                flux_s = swap_flux_y_local_w(k)
-                diss_s = swap_diss_y_local_w(k)
 #endif
-
+             ENDDO
+
+             DO  k = nzb_max_l+1, nzt-1
+
+                u_comp(k) = u(k+1,j,i+1) + u(k,j,i+1) - gu
+                flux_r(k) = u_comp(k) * (                                      &
+                      37.0_wp * ( w(k,j,i+1) + w(k,j,i)   )                    &
+                    -  8.0_wp * ( w(k,j,i+2) + w(k,j,i-1) )                    &
+                    +           ( w(k,j,i+3) + w(k,j,i-2) ) ) * adv_mom_5
+
+                diss_r(k) = - ABS( u_comp(k) ) * (                             &
+                      10.0_wp * ( w(k,j,i+1) - w(k,j,i)   )                    &
+                    -  5.0_wp * ( w(k,j,i+2) - w(k,j,i-1) )                    &
+                    +           ( w(k,j,i+3) - w(k,j,i-2) ) ) * adv_mom_5
+
+#ifdef _OPENACC
+!
+!--             Recompute the left fluxes.
+                u_comp_l           = u(k+1,j,i) + u(k,j,i) - gu
+                flux_l_w(k,j,tn)   = u_comp_l * (                              &
+                            37.0_wp * ( w(k,j,i)   + w(k,j,i-1)   )            &
+                          -  8.0_wp * ( w(k,j,i+1) + w(k,j,i-2) )              &
+                          +           ( w(k,j,i+2) + w(k,j,i-3) ) ) * adv_mom_5
+                diss_l_w(k,j,tn)   = - ABS( u_comp_l ) * (                     &
+                            10.0_wp * ( w(k,j,i)   - w(k,j,i-1)   )            &
+                          -  5.0_wp * ( w(k,j,i+1) - w(k,j,i-2) )              &
+                          +           ( w(k,j,i+2) - w(k,j,i-3) ) ) * adv_mom_5
+#endif
+
+                v_comp(k) = v(k+1,j+1,i) + v(k,j+1,i) - gv
+                flux_n(k) = v_comp(k) * (                                      &
+                      37.0_wp * ( w(k,j+1,i) + w(k,j,i)   )                    &
+                    -  8.0_wp * ( w(k,j+2,i) + w(k,j-1,i) )                    &
+                    +           ( w(k,j+3,i) + w(k,j-2,i) ) ) * adv_mom_5
+
+                diss_n(k) = - ABS( v_comp(k) ) * (                             &
+                      10.0_wp * ( w(k,j+1,i) - w(k,j,i)   )                    &
+                    -  5.0_wp * ( w(k,j+2,i) - w(k,j-1,i) )                    &
+                    +           ( w(k,j+3,i) - w(k,j-2,i) ) ) * adv_mom_5
+
+#ifdef _OPENACC
+!
+!--             Recompute the south fluxes.
+                v_comp_s         = v(k+1,j,i) + v(k,j,i) - gv
+                flux_s_w(k,tn)   = v_comp_s * (                                &
+                           37.0_wp * ( w(k,j,i)   + w(k,j-1,i) )               &
+                         -  8.0_wp * ( w(k,j+1,i) + w(k,j-2,i)  )              &
+                         +           ( w(k,j+2,i) + w(k,j-3,i) ) ) * adv_mom_5
+                diss_s_w(k,tn)   = - ABS( v_comp_s ) * (                       &
+                           10.0_wp * ( w(k,j,i)   - w(k,j-1,i) )               &
+                         -  5.0_wp * ( w(k,j+1,i) - w(k,j-2,i) )               &
+                         +           ( w(k,j+2,i) - w(k,j-3,i) ) ) * adv_mom_5
+#endif
+             ENDDO
+!
+!--          Now, compute vertical fluxes. Split loop into a part treating the
+!--          lowest grid points with indirect indexing, a main loop without
+!--          indirect indexing, and a loop for the uppermost grip points with
+!--          indirect indexing. This allows better vectorization for the main loop.
+!--          First, compute the flux at model surface, which need has to be
+!--          calculated explicitly for the tendency at
+!--          the first w-level. For topography wall this is done implicitely by
+!--          advc_flags_m.
+             k         = nzb + 1
+             w_comp(k) = w(k,j,i) + w(k-1,j,i)
+             flux_t(0) = w_comp(k)       * rho_air(k)                          &
+                       * ( w(k,j,i) + w(k-1,j,i) ) * adv_mom_1
+             diss_t(0) = -ABS(w_comp(k)) * rho_air(k)                          &
+                       * ( w(k,j,i) - w(k-1,j,i) ) * adv_mom_1
+
+             DO  k = nzb+1, nzb+1
 !
 !--             k index has to be modified near bottom and top, else array
@@ -6269,154 +6375,75 @@
                 k_mm  = k - 2 * ibit26
 
-                w_comp = w(k+1,j,i) + w(k,j,i)
-                flux_t = w_comp * rho_air(k+1) * (                             &
-                          ( 37.0_wp * ibit26 * adv_mom_5                       &
-                       +     7.0_wp * ibit25 * adv_mom_3                       &
-                       +              ibit24 * adv_mom_1                       &
-                          ) *                                                  &
-                             ( w(k+1,j,i)  + w(k,j,i)     )                    &
-                   -      (  8.0_wp * ibit26 * adv_mom_5                       &
-                       +              ibit25 * adv_mom_3                       &
-                          ) *                                                  &
-                             ( w(k_pp,j,i)  + w(k-1,j,i)  )                    &
-                   +      (           ibit26 * adv_mom_5                       &
-                          ) *                                                  &
-                             ( w(k_ppp,j,i) + w(k_mm,j,i) )                    &
-                                       )
-
-                diss_t = - ABS( w_comp ) * rho_air(k+1) * (                    &
-                          ( 10.0_wp * ibit26 * adv_mom_5                       &
-                       +     3.0_wp * ibit25 * adv_mom_3                       &
-                       +              ibit24 * adv_mom_1                       &
-                          ) *                                                  &
-                             ( w(k+1,j,i)   - w(k,j,i)    )                    &
-                   -      (  5.0_wp * ibit26 * adv_mom_5                       &
-                       +              ibit25 * adv_mom_3                       &
-                          ) *                                                  &
-                             ( w(k_pp,j,i)  - w(k-1,j,i)  )                    &
-                   +      (           ibit26 * adv_mom_5                       &
-                          ) *                                                  &
-                             ( w(k_ppp,j,i) - w(k_mm,j,i) )                    &
-                                               )
-!
-!--             Calculate the divergence of the velocity field. A respective
-!--             correction is needed to overcome numerical instabilities caused
-!--             by a not sufficient reduction of divergences near topography.
-                div = ( ( ( u_comp + gu ) * ( ibit18 + ibit19 + ibit20 )      &
-                  - ( u(k+1,j,i) + u(k,j,i)   )                               & 
-                                    * (                                       &
-                     REAL( IBITS(advc_flags_m(k,j,i-1),18,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k,j,i-1),19,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k,j,i-1),20,1), KIND = wp )     &
-                                      )                                       &
-                  ) * ddx                                                     &
-              +   ( ( v_comp + gv ) * ( ibit21 + ibit22 + ibit23 )            &
-                  - ( v(k+1,j,i) + v(k,j,i)   )                               &
-                                    * (                                       &
-                     REAL( IBITS(advc_flags_m(k,j-1,i),21,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k,j-1,i),22,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k,j-1,i),23,1),  KIND = wp )    &
-                                      )                                       &
-                  ) * ddy                                                     &
-              +   ( w_comp * rho_air(k+1) * ( ibit24 + ibit25 + ibit26 )      &
-                - ( w(k,j,i)   + w(k-1,j,i)   ) * rho_air(k)                  &
-                                    * (                                       &
-                     REAL( IBITS(advc_flags_m(k-1,j,i),24,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k-1,j,i),25,1), KIND = wp )     &
-                   + REAL( IBITS(advc_flags_m(k-1,j,i),26,1), KIND = wp )     &
-                                      )                                       & 
-                  ) * drho_air_zw(k) * ddzu(k+1)                              &
-                ) * 0.5_wp
-
-
-
-                tend(k,j,i) = tend(k,j,i) - (                                 &
-                      ( ( flux_r + diss_r )                                   &
-                    -   ( flux_l + diss_l ) ) * ddx                           &
-                    + ( ( flux_n + diss_n )                                   &
-                    -   ( flux_s + diss_s ) ) * ddy                           &
-                    + ( ( flux_t + diss_t )                                   &
-                    -   ( flux_d + diss_d ) ) * drho_air_zw(k) * ddzu(k+1)    &
-                                            )  + div * w(k,j,i)
-
-#ifndef _OPENACC
-                swap_flux_x_local_w(k,j) = flux_r
-                swap_diss_x_local_w(k,j) = diss_r
-                swap_flux_y_local_w(k)   = flux_n
-                swap_diss_y_local_w(k)   = diss_n
-#endif
-                flux_d                   = flux_t
-                diss_d                   = diss_t
-
-                !$ACC ATOMIC
-                sums_ws2_ws_l(k,tn)  = sums_ws2_ws_l(k,tn)                    &
-                      + ( flux_t                                              &
-                       * ( w_comp - 2.0_wp * hom(k,1,3,0)                   ) &
-                       / ( w_comp + SIGN( 1.0E-20_wp, w_comp )              ) &
-                        + diss_t                                              &
-                       *   ABS( w_comp - 2.0_wp * hom(k,1,3,0)              ) &
-                       / ( ABS( w_comp ) + 1.0E-20_wp                       ) &
-                        ) *   weight_substep(intermediate_timestep_count)
-
+                w_comp(k) = w(k+1,j,i) + w(k,j,i)
+                flux_t(k) = w_comp(k) * rho_air(k+1) * (                       &
+                           ( 37.0_wp * ibit26 * adv_mom_5                      &
+                        +     7.0_wp * ibit25 * adv_mom_3                      &
+                        +              ibit24 * adv_mom_1                      &
+                           ) *                                                 &
+                                      ( w(k+1,j,i)   + w(k,j,i)    )           &
+                    -      (  8.0_wp * ibit26 * adv_mom_5                      &
+                        +              ibit25 * adv_mom_3                      &
+                           ) *                                                 &
+                                      ( w(k_pp,j,i)  + w(k-1,j,i)  )           &
+                    +      (           ibit26 * adv_mom_5                      &
+                           ) *                                                 &
+                                      ( w(k_ppp,j,i) + w(k_mm,j,i) )           &
+                                                       )
+
+                diss_t(k) = - ABS( w_comp(k) ) * rho_air(k+1) * (              &
+                           ( 10.0_wp * ibit26 * adv_mom_5                      &
+                        +     3.0_wp * ibit25 * adv_mom_3                      &
+                        +              ibit24 * adv_mom_1                      &
+                           ) *                                                 &
+                                      ( w(k+1,j,i)   - w(k,j,i)    )           &
+                    -      (  5.0_wp * ibit26 * adv_mom_5                      &
+                        +              ibit25 * adv_mom_3                      &
+                           ) *                                                 &
+                                      ( w(k_pp,j,i)  - w(k-1,j,i)  )           &
+                    +      (           ibit26 * adv_mom_5                      &
+                           ) *                                                 &
+                                      ( w(k_ppp,j,i) - w(k_mm,j,i) )           &
+                                                                )
              ENDDO
 
-             DO  k = nzb_max_l+1, nzt-1
-
-                u_comp = u(k+1,j,i+1) + u(k,j,i+1) - gu
-                flux_r = u_comp * (                                         &
-                      37.0_wp * ( w(k,j,i+1) + w(k,j,i)   )                    &
-                    -  8.0_wp * ( w(k,j,i+2) + w(k,j,i-1) )                    &
-                    +           ( w(k,j,i+3) + w(k,j,i-2) ) ) * adv_mom_5
-
-                diss_r = - ABS( u_comp ) * (                                &
-                      10.0_wp * ( w(k,j,i+1) - w(k,j,i)   )                    &
-                    -  5.0_wp * ( w(k,j,i+2) - w(k,j,i-1) )                    &
-                    +           ( w(k,j,i+3) - w(k,j,i-2) ) ) * adv_mom_5
-
-#ifdef _OPENACC
-!
-!--             Recompute the left fluxes.
-                u_comp_l = u(k+1,j,i) + u(k,j,i) - gu
-                flux_l   = u_comp_l * (                                     &
-                            37.0_wp * ( w(k,j,i)   + w(k,j,i-1)   )              &
-                          -  8.0_wp * ( w(k,j,i+1) + w(k,j,i-2) )              &
-                          +           ( w(k,j,i+2) + w(k,j,i-3) ) ) * adv_mom_5
-                diss_l   = - ABS( u_comp_l ) * (                            &
-                            10.0_wp * ( w(k,j,i)   - w(k,j,i-1)   )              &
-                          -  5.0_wp * ( w(k,j,i+1) - w(k,j,i-2) )              &
-                          +           ( w(k,j,i+2) - w(k,j,i-3) ) ) * adv_mom_5
-#else
-                flux_l = swap_flux_x_local_w(k,j)
-                diss_l = swap_diss_x_local_w(k,j)
-#endif
-
-                v_comp = v(k+1,j+1,i) + v(k,j+1,i) - gv
-                flux_n = v_comp * (                                         &
-                      37.0_wp * ( w(k,j+1,i) + w(k,j,i)   )                    &
-                    -  8.0_wp * ( w(k,j+2,i) + w(k,j-1,i) )                    &
-                    +           ( w(k,j+3,i) + w(k,j-2,i) ) ) * adv_mom_5
-
-                diss_n = - ABS( v_comp ) * (                                &
-                      10.0_wp * ( w(k,j+1,i) - w(k,j,i)   )                    &
-                    -  5.0_wp * ( w(k,j+2,i) - w(k,j-1,i) )                    &
-                    +           ( w(k,j+3,i) - w(k,j-2,i) ) ) * adv_mom_5
-
-#ifdef _OPENACC
-!
-!--             Recompute the south fluxes.
-                v_comp_s = v(k+1,j,i) + v(k,j,i) - gv
-                flux_s   = v_comp_s * (                                     &
-                           37.0_wp * ( w(k,j,i)   + w(k,j-1,i) )               &
-                         -  8.0_wp * ( w(k,j+1,i) +w(k,j-2,i)  )               &
-                         +           ( w(k,j+2,i) + w(k,j-3,i) ) ) * adv_mom_5
-                diss_s   = - ABS( v_comp_s ) * (                            &
-                           10.0_wp * ( w(k,j,i)   - w(k,j-1,i) )               &
-                         -  5.0_wp * ( w(k,j+1,i) - w(k,j-2,i) )               &
-                         +           ( w(k,j+2,i) - w(k,j-3,i) ) ) * adv_mom_5
-#else
-                flux_s = swap_flux_y_local_w(k)
-                diss_s = swap_diss_y_local_w(k)
-#endif
-
+             DO  k = nzb+2, nzt-2
+
+                ibit26 = REAL( IBITS(advc_flags_m(k,j,i),26,1), KIND = wp )
+                ibit25 = REAL( IBITS(advc_flags_m(k,j,i),25,1), KIND = wp )
+                ibit24 = REAL( IBITS(advc_flags_m(k,j,i),24,1), KIND = wp )
+
+                w_comp(k) = w(k+1,j,i) + w(k,j,i)
+                flux_t(k) = w_comp(k) * rho_air(k+1) * (                       &
+                           ( 37.0_wp * ibit26 * adv_mom_5                      &
+                        +     7.0_wp * ibit25 * adv_mom_3                      &
+                        +              ibit24 * adv_mom_1                      &
+                           ) *                                                 &
+                                      ( w(k+1,j,i)  + w(k,j,i)   )             &
+                    -      (  8.0_wp * ibit26 * adv_mom_5                      &
+                        +              ibit25 * adv_mom_3                      &
+                           ) *                                                 &
+                                      ( w(k+2,j,i)  + w(k-1,j,i) )             &
+                    +      (           ibit26 * adv_mom_5                      &
+                           ) *                                                 &
+                                      ( w(k+3,j,i)  + w(k-2,j,i) )             &
+                                                       )
+
+                diss_t(k) = - ABS( w_comp(k) ) * rho_air(k+1) * (              &
+                           ( 10.0_wp * ibit26 * adv_mom_5                      &
+                        +     3.0_wp * ibit25 * adv_mom_3                      &
+                        +              ibit24 * adv_mom_1                      &
+                           ) *                                                 &
+                                      ( w(k+1,j,i) - w(k,j,i)    )             &
+                    -      (  5.0_wp * ibit26 * adv_mom_5                      &
+                        +              ibit25 * adv_mom_3                      &
+                           ) *                                                 &
+                                      ( w(k+2,j,i) - w(k-1,j,i)  )             &
+                    +      (           ibit26 * adv_mom_5                      &
+                           ) *                                                 &
+                                      ( w(k+3,j,i) - w(k-2,j,i)  )             &
+                                                                )
+             ENDDO
+
+             DO  k = nzt-1, nzt-1
 !
 !--             k index has to be modified near bottom and top, else array
@@ -6430,77 +6457,171 @@
                 k_mm  = k - 2 * ibit26
 
-                w_comp = w(k+1,j,i) + w(k,j,i)
-                flux_t = w_comp * rho_air(k+1) * (                           &
-                          ( 37.0_wp * ibit26 * adv_mom_5                        &
-                       +     7.0_wp * ibit25 * adv_mom_3                        &
-                       +              ibit24 * adv_mom_1                        &
-                          ) *                                                &
-                             ( w(k+1,j,i)  + w(k,j,i)     )                  &
-                   -      (  8.0_wp * ibit26 * adv_mom_5                        &
-                       +              ibit25 * adv_mom_3                        &
-                          ) *                                                &
-                             ( w(k_pp,j,i)  + w(k-1,j,i)  )                  &
-                   +      (           ibit26 * adv_mom_5                        &
-                          ) *                                                &
-                             ( w(k_ppp,j,i) + w(k_mm,j,i) )                  &
-                                       )
-
-                diss_t = - ABS( w_comp ) * rho_air(k+1) * (                  &
-                          ( 10.0_wp * ibit26 * adv_mom_5                        &
-                       +     3.0_wp * ibit25 * adv_mom_3                        &
-                       +              ibit24 * adv_mom_1                        &
-                          ) *                                                &
-                             ( w(k+1,j,i)   - w(k,j,i)    )                  &
-                   -      (  5.0_wp * ibit26 * adv_mom_5                        &
-                       +              ibit25 * adv_mom_3                        &
-                          ) *                                                &
-                             ( w(k_pp,j,i)  - w(k-1,j,i)  )                  &
-                   +      (           ibit26 * adv_mom_5                        &
-                          ) *                                                &
-                             ( w(k_ppp,j,i) - w(k_mm,j,i) )                  &
-                                               )
+                w_comp(k) = w(k+1,j,i) + w(k,j,i)
+                flux_t(k) = w_comp(k) * rho_air(k+1) * (                       &
+                           ( 37.0_wp * ibit26 * adv_mom_5                      &
+                        +     7.0_wp * ibit25 * adv_mom_3                      &
+                        +              ibit24 * adv_mom_1                      &
+                           ) *                                                 &
+                                      ( w(k+1,j,i)   + w(k,j,i)    )           &
+                    -      (  8.0_wp * ibit26 * adv_mom_5                      &
+                        +              ibit25 * adv_mom_3                      &
+                           ) *                                                 &
+                                      ( w(k_pp,j,i)  + w(k-1,j,i)  )           &
+                    +      (           ibit26 * adv_mom_5                      &
+                           ) *                                                 &
+                                      ( w(k_ppp,j,i) + w(k_mm,j,i) )           &
+                                                       )
+
+                diss_t(k) = - ABS( w_comp(k) ) * rho_air(k+1) * (              &
+                           ( 10.0_wp * ibit26 * adv_mom_5                      &
+                        +     3.0_wp * ibit25 * adv_mom_3                      &
+                        +              ibit24 * adv_mom_1                      &
+                           ) *                                                 &
+                                      ( w(k+1,j,i)   - w(k,j,i)    )           &
+                    -      (  5.0_wp * ibit26 * adv_mom_5                      &
+                        +              ibit25 * adv_mom_3                      &
+                           ) *                                                 &
+                                      ( w(k_pp,j,i)  - w(k-1,j,i)  )           &
+                    +      (           ibit26 * adv_mom_5                      &
+                           ) *                                                 &
+                                      ( w(k_ppp,j,i) - w(k_mm,j,i) )           &
+                                                                )
+             ENDDO
+
+!
+!--          Set resolved/turbulent flux at model top to zero (w-level). Hint: The
+!--          flux at nzt is defined at the scalar grid point nzt+1. Therefore, the
+!--          flux at nzt+1 is already outside of the model domain
+             flux_t(nzt) = 0.0_wp
+             diss_t(nzt) = 0.0_wp
+             w_comp(nzt) = 0.0_wp
+
+             flux_t(nzt+1) = 0.0_wp
+             diss_t(nzt+1) = 0.0_wp
+             w_comp(nzt+1) = 0.0_wp
+
+             DO  k = nzb+1, nzb_max_l
+
+                flux_d    = flux_t(k-1)
+                diss_d    = diss_t(k-1)
+
+                ibit20 = REAL( IBITS(advc_flags_m(k,j,i),20,1), KIND = wp )
+                ibit19 = REAL( IBITS(advc_flags_m(k,j,i),19,1), KIND = wp )
+                ibit18 = REAL( IBITS(advc_flags_m(k,j,i),18,1), KIND = wp )
+
+                ibit23 = REAL( IBITS(advc_flags_m(k,j,i),23,1), KIND = wp )
+                ibit22 = REAL( IBITS(advc_flags_m(k,j,i),22,1), KIND = wp )
+                ibit21 = REAL( IBITS(advc_flags_m(k,j,i),21,1), KIND = wp )
+
+                ibit26 = REAL( IBITS(advc_flags_m(k,j,i),26,1), KIND = wp )
+                ibit25 = REAL( IBITS(advc_flags_m(k,j,i),25,1), KIND = wp )
+                ibit24 = REAL( IBITS(advc_flags_m(k,j,i),24,1), KIND = wp )
 !
 !--             Calculate the divergence of the velocity field. A respective
-!--             correction is needed to overcome numerical instabilities caused
+!--             correction is needed to overcome numerical instabilities introduced
 !--             by a not sufficient reduction of divergences near topography.
-                div = ( ( u_comp + gu - ( u(k+1,j,i) + u(k,j,i)   ) ) * ddx  &
-                    +   ( v_comp + gv - ( v(k+1,j,i) + v(k,j,i)   ) ) * ddy  &
-                    +   (   w_comp                    * rho_air(k+1) -       &
-                          ( w(k,j,i)   + w(k-1,j,i) ) * rho_air(k)           &
-                        ) * drho_air_zw(k) * ddzu(k+1)                       &
+                div = ( ( ( u_comp(k) + gu ) * ( ibit18 + ibit19 + ibit20 )     &
+                        - ( u(k+1,j,i) + u(k,j,i)   )                           &
+                                          * (                                   &
+                           REAL( IBITS(advc_flags_m(k,j,i-1),18,1), KIND = wp ) &
+                         + REAL( IBITS(advc_flags_m(k,j,i-1),19,1), KIND = wp ) &
+                         + REAL( IBITS(advc_flags_m(k,j,i-1),20,1), KIND = wp ) &
+                                            )                                   &
+                        ) * ddx                                                 &
+                    +   ( ( v_comp(k) + gv ) * ( ibit21 + ibit22 + ibit23 )     &
+                        - ( v(k+1,j,i) + v(k,j,i)   )                           &
+                                          * (                                   &
+                           REAL( IBITS(advc_flags_m(k,j-1,i),21,1), KIND = wp ) &
+                         + REAL( IBITS(advc_flags_m(k,j-1,i),22,1), KIND = wp ) &
+                         + REAL( IBITS(advc_flags_m(k,j-1,i),23,1), KIND = wp ) &
+                                            )                                   &
+                        ) * ddy                                                 &
+                    +   ( w_comp(k)               * rho_air(k+1)                &
+                                                  * ( ibit24 + ibit25 + ibit26 )&
+                      - ( w(k,j,i) + w(k-1,j,i) ) * rho_air(k)                  &
+                                          * (                                   &
+                           REAL( IBITS(advc_flags_m(k-1,j,i),24,1), KIND = wp ) &
+                         + REAL( IBITS(advc_flags_m(k-1,j,i),25,1), KIND = wp ) &
+                         + REAL( IBITS(advc_flags_m(k-1,j,i),26,1), KIND = wp ) &
+                                            )                                   &
+                        ) * drho_air_zw(k) * ddzu(k+1)                          &
                       ) * 0.5_wp
 
-                tend(k,j,i) = tend(k,j,i) - (                                 &
-                      ( ( flux_r + diss_r )                                   &
-                    -   ( flux_l + diss_l ) ) * ddx                           &
-                    + ( ( flux_n + diss_n )                                   &
-                    -   ( flux_s + diss_s ) ) * ddy                           &
-                    + ( ( flux_t + diss_t )                                   &
-                    -   ( flux_d + diss_d ) ) * drho_air_zw(k) * ddzu(k+1)    &
-                                            )  + div * w(k,j,i)
-
+                tend(k,j,i) = tend(k,j,i) - (                                   &
+                            ( flux_r(k) + diss_r(k)                             &
+                          -   flux_l_w(k,j,tn) - diss_l_w(k,j,tn)   ) * ddx     &
+                          + ( flux_n(k) + diss_n(k)                             &
+                          -   flux_s_w(k,tn) - diss_s_w(k,tn)       ) * ddy     &
+                          + ( ( flux_t(k) + diss_t(k) )                         &
+                          -   ( flux_d    + diss_d    )                         &
+                                                ) * drho_air_zw(k) * ddzu(k+1)  &
+                                            ) + div * w(k,j,i)
 #ifndef _OPENACC
-                swap_flux_x_local_w(k,j) = flux_r
-                swap_diss_x_local_w(k,j) = diss_r
-                swap_flux_y_local_w(k)   = flux_n
-                swap_diss_y_local_w(k)   = diss_n
+                flux_l_w(k,j,tn) = flux_r(k)
+                diss_l_w(k,j,tn) = diss_r(k)
+                flux_s_w(k,tn)   = flux_n(k)
+                diss_s_w(k,tn)   = diss_n(k)
 #endif
-                flux_d                   = flux_t
-                diss_d                   = diss_t
-
-                !$ACC ATOMIC
-                sums_ws2_ws_l(k,tn)  = sums_ws2_ws_l(k,tn)                    &
-                      + ( flux_t                                              &
-                       * ( w_comp - 2.0_wp * hom(k,1,3,0)                   ) &
-                       / ( w_comp + SIGN( 1.0E-20_wp, w_comp )              ) &
-                        + diss_t                                              &
-                       *   ABS( w_comp - 2.0_wp * hom(k,1,3,0)              ) &
-                       / ( ABS( w_comp ) + 1.0E-20_wp                       ) &
-                        ) *   weight_substep(intermediate_timestep_count)
+!
+!--             Statistical Evaluation of w'w'.
+                sums_ws2_ws_l(k,tn)  = sums_ws2_ws_l(k,tn)                     &
+                            + ( flux_t(k)                                      &
+                             * ( w_comp(k) - 2.0_wp * hom(k,1,3,0)           ) &
+                             / ( w_comp(k) + SIGN( 1.0E-20_wp, w_comp(k) )   ) &
+                              + diss_t(k)                                      &
+                             *   ABS( w_comp(k) - 2.0_wp * hom(k,1,3,0)      ) &
+                             / ( ABS( w_comp(k) ) + 1.0E-20_wp               ) &
+                              ) *   weight_substep(intermediate_timestep_count)
 
              ENDDO
+
+             DO  k = nzb_max_l+1, nzt-1
+
+                flux_d    = flux_t(k-1)
+                diss_d    = diss_t(k-1)
+!
+!--             Calculate the divergence of the velocity field. A respective
+!--             correction is needed to overcome numerical instabilities introduced
+!--             by a not sufficient reduction of divergences near topography.
+                div = ( ( u_comp(k) + gu - ( u(k+1,j,i) + u(k,j,i)   ) ) * ddx &
+                    +   ( v_comp(k) + gv - ( v(k+1,j,i) + v(k,j,i)   ) ) * ddy &
+                    +   ( w_comp(k)               * rho_air(k+1)               &
+                      - ( w(k,j,i) + w(k-1,j,i) ) * rho_air(k)                 &
+                        ) * drho_air_zw(k) * ddzu(k+1)                         &
+                      ) * 0.5_wp
+
+                tend(k,j,i) = tend(k,j,i) - (                                  &
+                            ( flux_r(k) + diss_r(k)                            &
+                          -   flux_l_w(k,j,tn) - diss_l_w(k,j,tn)   ) * ddx    &
+                          + ( flux_n(k) + diss_n(k)                            &
+                          -   flux_s_w(k,tn) - diss_s_w(k,tn)       ) * ddy    &
+                          + ( ( flux_t(k) + diss_t(k) )                        &
+                          -   ( flux_d    + diss_d    )                        &
+                                               ) * drho_air_zw(k) * ddzu(k+1)  &
+                                            ) + div * w(k,j,i)
+#ifndef _OPENACC
+                flux_l_w(k,j,tn) = flux_r(k)
+                diss_l_w(k,j,tn) = diss_r(k)
+                flux_s_w(k,tn)   = flux_n(k)
+                diss_s_w(k,tn)   = diss_n(k)
+#endif
+!
+!--             Statistical Evaluation of w'w'.
+                sums_ws2_ws_l(k,tn)  = sums_ws2_ws_l(k,tn)                     &
+                            + ( flux_t(k)                                      &
+                             * ( w_comp(k) - 2.0_wp * hom(k,1,3,0)          )  &
+                             / ( w_comp(k) + SIGN( 1.0E-20_wp, w_comp(k) )  )  &
+                              + diss_t(k)                                      &
+                             *   ABS( w_comp(k) - 2.0_wp * hom(k,1,3,0)     )  &
+                             / ( ABS( w_comp(k) ) + 1.0E-20_wp              )  &
+                              ) *   weight_substep(intermediate_timestep_count)
+
+             ENDDO
+
           ENDDO
        ENDDO
 
+       CALL cpu_log( log_point_s(87), 'advec_w_ws', 'stop' )
+
     END SUBROUTINE advec_w_ws
 
Index: palm/trunk/SOURCE/time_integration.f90
===================================================================
--- palm/trunk/SOURCE/time_integration.f90	(revision 4465)
+++ palm/trunk/SOURCE/time_integration.f90	(revision 4466)
@@ -25,12 +25,15 @@
 ! -----------------
 ! $Id$
+! Add advection fluxes to ACC copyin
+!
+! 4457 2020-03-11 14:20:43Z raasch
 ! use statement for exchange horiz added
-! 
+!
 ! 4444 2020-03-05 15:59:50Z raasch
 ! bugfix: cpp-directives for serial mode added
-! 
+!
 ! 4420 2020-02-24 14:13:56Z maronga
 ! Added output control for wind turbine model
-! 
+!
 ! 4403 2020-02-12 13:08:46Z banzhafs
 ! Allowing both existing and on-demand emission read modes
@@ -38,18 +41,18 @@
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Bugfix, hour_call_emis uninitialized at first call of time_integration
-! 
+!
 ! 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
-! 
+!
 ! 4329 2019-12-10 15:46:36Z motisi
 ! Renamed wall_flags_0 to wall_flags_static_0
-! 
+!
 ! 4281 2019-10-29 15:15:39Z schwenkel
 ! Moved boundary conditions to module interface
-! 
+!
 ! 4276 2019-10-28 16:03:29Z schwenkel
 ! Further modularization of lpm code components
-! 
+!
 ! 4275 2019-10-28 15:34:55Z schwenkel
 ! Move call oft lpm to the end of intermediate timestep loop
@@ -60,36 +63,36 @@
 ! 4227 2019-09-10 18:04:34Z gronemeier
 ! implement new palm_date_time_mod
-! 
+!
 ! 4226 2019-09-10 17:03:24Z suehring
 ! Changes in interface for the offline nesting
-! 
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 4170 2019-08-19 17:12:31Z gronemeier
 ! copy diss, diss_p, tdiss_m to GPU
-! 
+!
 ! 4144 2019-08-06 09:11:47Z raasch
 ! relational operators .EQ., .NE., etc. replaced by ==, /=, etc.
-! 
+!
 ! 4126 2019-07-30 11:09:11Z gronemeier
 ! renamed routine to calculate uv exposure
-! 
+!
 ! 4111 2019-07-22 18:16:57Z suehring
 ! advc_flags_1 / advc_flags_2 renamed to advc_flags_m / advc_flags_s
-! 
+!
 ! 4069 2019-07-01 14:05:51Z Giersch
-! Masked output running index mid has been introduced as a local variable to 
+! Masked output running index mid has been introduced as a local variable to
 ! avoid runtime error (Loop variable has been modified) in time_integration
-! 
+!
 ! 4064 2019-07-01 05:33:33Z gronemeier
 ! Moved call to radiation module out of intermediate time loop
-! 
+!
 ! 4048 2019-06-21 21:00:21Z knoop
 ! Moved production_e_init call into turbulence_closure_mod
-! 
+!
 ! 4047 2019-06-21 18:58:09Z knoop
 ! Added remainings of swap_timelevel upon its dissolution
-! 
+!
 ! 4043 2019-06-18 16:59:00Z schwenkel
 ! Further LPM modularization
@@ -97,38 +100,38 @@
 ! 4039 2019-06-18 10:32:41Z suehring
 ! Rename subroutines in module for diagnostic quantities
-! 
+!
 ! 4029 2019-06-14 14:04:35Z raasch
 ! exchange of ghost points and boundary conditions separated for chemical species and SALSA module,
 ! bugfix: decycling of chemistry species after nesting data transfer
-! 
+!
 ! 4022 2019-06-12 11:52:39Z suehring
 ! Call synthetic turbulence generator at last RK3 substep right after boundary
-! conditions are updated in offline nesting in order to assure that 
-! perturbations are always imposed 
-! 
+! conditions are updated in offline nesting in order to assure that
+! perturbations are always imposed
+!
 ! 4017 2019-06-06 12:16:46Z schwenkel
 ! Mass (volume) flux correction included to ensure global mass conservation for child domains.
-! 
+!
 ! 3994 2019-05-22 18:08:09Z suehring
 ! output of turbulence intensity added
-! 
+!
 ! 3988 2019-05-22 11:32:37Z kanani
 ! Implement steerable output interval for virtual measurements
-! 
+!
 ! 3968 2019-05-13 11:04:01Z suehring
 ! replace nspec_out with n_matched_vars
-! 
+!
 ! 3929 2019-04-24 12:52:08Z banzhafs
 ! Reverse changes back from revision 3878: use chem_boundary_conds instead of
 ! chem_boundary_conds_decycle
-! 
-! 
+!
+!
 ! 3885 2019-04-11 11:29:34Z kanani
-! Changes related to global restructuring of location messages and introduction 
+! Changes related to global restructuring of location messages and introduction
 ! of additional debug messages
 !
 ! 3879 2019-04-08 20:25:23Z knoop
 ! Moved wtm_forces to module_interface_actions
-! 
+!
 ! 3872 2019-04-08 15:03:06Z knoop
 ! Modifications made for salsa:
@@ -136,16 +139,16 @@
 !   salsa_emission_update (i.e. skip_time_do_salsa >= time_since_reference_point
 !   and next_aero_emission_update <= time_since_reference_point ).
-! - Renamed nbins --> nbins_aerosol, ncc_tot --> ncomponents_mass and 
+! - Renamed nbins --> nbins_aerosol, ncc_tot --> ncomponents_mass and
 !   ngast --> ngases_salsa and loop indices b, c and sg to ib, ic and ig
 ! - Apply nesting for salsa variables
 ! - Removed cpu_log calls speciffic for salsa.
-! 
+!
 ! 3833 2019-03-28 15:04:04Z forkel
 ! added USE chem_gasphase_mod, replaced nspec by nspec since fixed compounds are not integrated
-! 
+!
 ! 3820 2019-03-27 11:53:41Z forkel
 ! renamed do_emiss to emissions_anthropogenic (ecc)
-! 
-! 
+!
+!
 ! 3774 2019-03-04 10:52:49Z moh.hefny
 ! rephrase if statement to avoid unallocated array in case of
@@ -155,18 +158,18 @@
 ! module section re-formatted and openacc required variables moved to separate section,
 ! re-formatting to 100 char line width
-! 
+!
 ! 3745 2019-02-15 18:57:56Z suehring
 ! Call indoor model after first timestep
-! 
+!
 ! 3744 2019-02-15 18:38:58Z suehring
 ! - Moved call of bio_calculate_thermal_index_maps from biometeorology module to
 ! time_integration to make sure averaged input is updated before calculating.
-! 
+!
 ! 3739 2019-02-13 08:05:17Z dom_dwd_user
 ! Removed everything related to "time_bio_results" as this is never used.
-! 
+!
 ! 3724 2019-02-06 16:28:23Z kanani
-! Correct double-used log_point_s unit 
-! 
+! Correct double-used log_point_s unit
+!
 ! 3719 2019-02-06 13:10:18Z kanani
 ! - removed wind_turbine cpu measurement, since same time is measured inside
@@ -176,11 +179,11 @@
 !   moved radiation_interactions cpulog to special measures
 ! - moved some cpu_log calls to this routine for better overview
-! 
+!
 ! 3705 2019-01-29 19:56:39Z suehring
 ! Data output for virtual measurements added
-! 
+!
 ! 3704 2019-01-29 19:51:41Z suehring
 ! Rename subroutines for surface-data output
-! 
+!
 ! 3647 2019-01-02 14:10:44Z kanani
 ! Bugfix: add time_since_reference_point to IF clause for data_output calls
@@ -198,5 +201,5 @@
 !------------------------------------------------------------------------------!
  SUBROUTINE time_integration
- 
+
 
     USE advec_ws,                                                                                  &
@@ -400,5 +403,5 @@
                vm_time_start
 
-               
+
     USE wind_turbine_model_mod,                                                                    &
         ONLY:  dt_data_output_wtm, time_wtm, wind_turbine, wtm_data_output
@@ -406,5 +409,19 @@
 #if defined( _OPENACC )
     USE arrays_3d,                                                                                 &
-        ONLY:  d, dd2zu, ddzu, ddzw, drho_air, drho_air_zw, dzw, e, heatflux_output_conversion,    &
+        ONLY:  d, dd2zu, ddzu, ddzw,                                                               &
+               diss_l_u,                                                                           &
+               diss_l_v,                                                                           &
+               diss_l_w,                                                                           &
+               diss_s_u,                                                                           &
+               diss_s_v,                                                                           &
+               diss_s_w,                                                                           &
+               drho_air, drho_air_zw, dzw, e,                                                      &
+               flux_l_u,                                                                           &
+               flux_l_v,                                                                           &
+               flux_l_w,                                                                           &
+               flux_s_u,                                                                           &
+               flux_s_v,                                                                           &
+               flux_s_w,                                                                           &
+               heatflux_output_conversion,                                                         &
                kh, km, momentumflux_output_conversion, nc, nr, p, ptdf_x, ptdf_y, qc, qr, rdf,     &
                rdf_sc, rho_air, rho_air_zw, s, tdiss_m, te_m, tpt_m, tu_m, tv_m, tw_m, ug, u_init, &
@@ -453,5 +470,5 @@
 !
 !-- Copy data from arrays_3d
-!$ACC DATA & 
+!$ACC DATA &
 !$ACC COPY(d(nzb+1:nzt,nys:nyn,nxl:nxr)) &
 !$ACC COPY(diss(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
@@ -466,4 +483,10 @@
 
 !$ACC DATA &
+!$ACC COPYIN(diss_l_u(0:nz+1,nys:nyn,0), flux_l_u(0:nz+1,nys:nyn,0)) &
+!$ACC COPYIN(diss_l_v(0:nz+1,nys:nyn,0), flux_l_v(0:nz+1,nys:nyn,0)) &
+!$ACC COPYIN(diss_l_w(0:nz+1,nys:nyn,0), flux_l_w(0:nz+1,nys:nyn,0)) &
+!$ACC COPYIN(diss_s_u(0:nz+1,0), flux_s_u(0:nz+1,0)) &
+!$ACC COPYIN(diss_s_v(0:nz+1,0), flux_s_v(0:nz+1,0)) &
+!$ACC COPYIN(diss_s_w(0:nz+1,0), flux_s_w(0:nz+1,0)) &
 !$ACC COPY(diss_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
 !$ACC COPY(e_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
@@ -569,10 +592,10 @@
     CALL run_control
 !
-!-- Data exchange between coupled models in case that a call has been omitted 
+!-- Data exchange between coupled models in case that a call has been omitted
 !-- at the end of the previous run of a job chain.
     IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled  .AND. .NOT. vnested )  THEN
 !
-!--    In case of model termination initiated by the local model the coupler 
-!--    must not be called because this would again cause an MPI hang. 
+!--    In case of model termination initiated by the local model the coupler
+!--    must not be called because this would again cause an MPI hang.
        DO WHILE ( time_coupling >= dt_coupling  .AND.  terminate_coupled == 0 )
           CALL surface_coupler
@@ -606,5 +629,5 @@
 
 !
-!--    Determine ug, vg and w_subs in dependence on data from external file 
+!--    Determine ug, vg and w_subs in dependence on data from external file
 !--    LSF_DATA
        IF ( large_scale_forcing .AND. lsf_vert )  THEN
@@ -614,6 +637,6 @@
 
 !
-!--    Set pt_init and q_init to the current profiles taken from 
-!--    NUDGING_DATA 
+!--    Set pt_init and q_init to the current profiles taken from
+!--    NUDGING_DATA
        IF ( nudging )  THEN
            CALL nudge_ref ( simulated_time )
@@ -649,10 +672,10 @@
        ENDIF
 !
-!--    Input of boundary data. 
+!--    Input of boundary data.
        IF ( nesting_offline )  CALL nesting_offl_input
 !
 !--    Execute all other module actions routines
        CALL module_interface_actions( 'before_timestep' )
-       
+
 !--    Start of intermediate step loop
        intermediate_timestep_count = 0
@@ -689,5 +712,5 @@
 !
 !--          Assure that ref_state does not become zero at any level
-!--          ( might be the case if a vertical level is completely occupied 
+!--          ( might be the case if a vertical level is completely occupied
 !--            with topography ).
              ref_state = MERGE( MAXVAL(ref_state), ref_state, ref_state == 0.0_wp )
@@ -856,5 +879,5 @@
                 ENDIF
 
-                IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )  
+                IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
 
                 IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
@@ -866,5 +889,5 @@
                 IF ( air_chemistry )  THEN
                    DO  n = 1, nvar
-                      CALL exchange_horiz( chem_species(n)%conc, nbgp ) 
+                      CALL exchange_horiz( chem_species(n)%conc, nbgp )
                    ENDDO
                 ENDIF
@@ -973,9 +996,9 @@
 
 !
-!--       Map forcing data derived from larger scale model onto domain 
+!--       Map forcing data derived from larger scale model onto domain
 !--       boundaries. Further, update geostrophic wind components.
           IF ( nesting_offline  .AND.  intermediate_timestep_count ==                              &
                                        intermediate_timestep_count_max  )  THEN
-!--          Determine interpolation factor before boundary conditions and geostrophic wind 
+!--          Determine interpolation factor before boundary conditions and geostrophic wind
 !--          is updated.
              CALL nesting_offl_interpolation_factor
@@ -994,5 +1017,5 @@
 !--       Ensure mass conservation. This need to be done after imposing
 !--       synthetic turbulence and top boundary condition for pressure is set to
-!--       Neumann conditions. 
+!--       Neumann conditions.
 !--       Is this also required in case of Dirichlet?
           IF ( nesting_offline )  CALL nesting_offl_mass_conservation
@@ -1013,5 +1036,5 @@
                 CALL vnest_boundary_conds
                 CALL cpu_log( log_point_s(30), 'vnest_bc', 'stop' )
- 
+
                 IF ( coupling_mode == 'vnested_fine' )  CALL pres
 
@@ -1058,8 +1081,8 @@
           ENDIF
 !
-!--       If required, compute virtual potential temperature 
-          IF ( humidity )  THEN 
-             CALL compute_vpt 
-          ENDIF 
+!--       If required, compute virtual potential temperature
+          IF ( humidity )  THEN
+             CALL compute_vpt
+          ENDIF
 
 !
@@ -1068,6 +1091,6 @@
 
 !
-!--          Determine surface fluxes shf and qsws and surface values 
-!--          pt_surface and q_surface in dependence on data from external 
+!--          Determine surface fluxes shf and qsws and surface values
+!--          pt_surface and q_surface in dependence on data from external
 !--          file LSF_DATA respectively
              IF ( ( large_scale_forcing .AND. lsf_surf ) .AND.                                     &
@@ -1078,5 +1101,5 @@
 
 !
-!--          First the vertical (and horizontal) fluxes in the surface 
+!--          First the vertical (and horizontal) fluxes in the surface
 !--          (constant flux) layer are computed
              IF ( constant_flux_layer )  THEN
@@ -1086,5 +1109,5 @@
              ENDIF
 !
-!--          If required, solve the energy balance for the surface and run soil 
+!--          If required, solve the energy balance for the surface and run soil
 !--          model. Call for horizontal as well as vertical surfaces
              IF ( land_surface .AND. time_since_reference_point >= skip_time_do_lsm)  THEN
@@ -1114,5 +1137,5 @@
 !
 !--             At the end, set boundary conditons for potential temperature
-!--             and humidity after running the land-surface model. This 
+!--             and humidity after running the land-surface model. This
 !--             might be important for the nesting, where arrays are transfered.
                 CALL lsm_boundary_condition
@@ -1122,5 +1145,5 @@
              ENDIF
 !
-!--          If required, solve the energy balance for urban surfaces and run 
+!--          If required, solve the energy balance for urban surfaces and run
 !--          the material heat model
              IF (urban_surface) THEN
@@ -1135,5 +1158,5 @@
 !
 !--             At the end, set boundary conditons for potential temperature
-!--             and humidity after running the urban-surface model. This 
+!--             and humidity after running the urban-surface model. This
 !--             might be important for the nesting, where arrays are transfered.
                 CALL usm_boundary_condition
@@ -1200,5 +1223,5 @@
 !
 !--          Adjust the current time to the time step of the radiation model.
-!--          Needed since radiation is pre-calculated and stored only on apparent 
+!--          Needed since radiation is pre-calculated and stored only on apparent
 !--          solar positions
              time_since_reference_point_save = time_since_reference_point
@@ -1213,5 +1236,5 @@
                 CALL cpu_log( log_point_s(46), 'radiation_interaction', 'stop' )
              ENDIF
- 
+
 !
 !--          Return the current time to its original value
@@ -1223,5 +1246,5 @@
        ENDIF
 
-       
+
 !
 !-- 20200203 (ECC)
@@ -1271,5 +1294,5 @@
 !--    dt_indoor steers the frequency of the indoor model calculations.
 !--    Note, at first timestep indoor model is called, in order to provide
-!--    a waste heat flux. 
+!--    a waste heat flux.
        IF ( indoor_model )  THEN
 
@@ -1342,5 +1365,5 @@
           time_virtual_measurement = time_virtual_measurement + dt_3d
        ENDIF
-       
+
 !
 !--    Increment time-counter for wind turbine data output
@@ -1348,8 +1371,8 @@
           time_wtm = time_wtm + dt_3d
        ENDIF
- 
+
 !
 !--    In case of synthetic turbulence generation and parametrized turbulence
-!--    information, update the time counter and if required, adjust the 
+!--    information, update the time counter and if required, adjust the
 !--    STG to new atmospheric conditions.
        IF ( use_syn_turb_gen  )  THEN
@@ -1371,8 +1394,8 @@
 
 !
-!--       In case of model termination initiated by the local model 
-!--       (terminate_coupled > 0), the coupler must be skipped because it would 
+!--       In case of model termination initiated by the local model
+!--       (terminate_coupled > 0), the coupler must be skipped because it would
 !--       cause an MPI intercomminucation hang.
-!--       If necessary, the coupler will be called at the beginning of the 
+!--       If necessary, the coupler will be called at the beginning of the
 !--       next restart run.
           DO WHILE ( time_coupling >= dt_coupling  .AND.  terminate_coupled == 0 )
@@ -1469,5 +1492,5 @@
                 .AND.  ( dt_dosurf_av - time_dosurf_av ) <= averaging_interval_surf                &
                 .AND.  time_since_reference_point >= skip_time_dosurf_av )  THEN
-             IF ( time_dosurf_av >= dt_averaging_input )  THEN        
+             IF ( time_dosurf_av >= dt_averaging_input )  THEN
                 CALL surface_data_output_averaging
                 average_count_surf = average_count_surf + 1
@@ -1502,5 +1525,5 @@
                                           MAX( dt_virtual_measurement, dt_3d ) )
        ENDIF
-       
+
 !
 !--    Output wind turbine data
@@ -1509,5 +1532,5 @@
           time_wtm = MOD( time_wtm, MAX( dt_data_output_wtm, dt_3d ) )
        ENDIF
-       
+
 !
 !--    Profile output (ASCII) on file
@@ -1707,5 +1730,5 @@
 #if defined( __parallel )
 !
-!-- Vertical nesting: Deallocate variables initialized for vertical nesting    
+!-- Vertical nesting: Deallocate variables initialized for vertical nesting
     IF ( vnest_init )  CALL vnest_deallocate
 #endif
