Index: /palm/trunk/SOURCE/init_3d_model.f90
===================================================================
--- /palm/trunk/SOURCE/init_3d_model.f90	(revision 4647)
+++ /palm/trunk/SOURCE/init_3d_model.f90	(revision 4648)
@@ -1,121 +1,117 @@
 !> @file init_3d_model.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! ------------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4548 2020-05-28 19:36:45Z suehring
 ! Bugfix, move call for lsf_forcing_surf after lsf_init is called
-! 
+!
 ! 4514 2020-04-30 16:29:59Z suehring
-! Add possibility to initialize surface sensible and latent heat fluxes via
-! a static driver.
-! 
+! Add possibility to initialize surface sensible and latent heat fluxes via a static driver.
+!
 ! 4493 2020-04-10 09:49:43Z pavelkrc
-! Overwrite u_init, v_init, pt_init, q_init and s_init with hom for all
-! cyclic_fill-cases, not only for turbulent_inflow = .TRUE.
-! 
+! Overwrite u_init, v_init, pt_init, q_init and s_init with hom for all cyclic_fill-cases, not only
+! for turbulent_inflow = .TRUE.
+!
 ! 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
-! 
+! 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
-! 
+!
 ! 4286 2019-10-30 16:01:14Z resler
 ! implement new palm_date_time_mod
-! 
+!
 ! 4223 2019-09-10 09:20:47Z gronemeier
-! Deallocate temporary string array since it may be re-used to read different 
-! input data in other modules
-! 
+! Deallocate temporary string array since it may be re-used to read different input data in other
+! modules
+!
 ! 4186 2019-08-23 16:06:14Z suehring
-! Design change, use variables defined in netcdf_data_input_mod to read netcd
-! variables rather than define local ones.
-! 
+! Design change, use variables defined in netcdf_data_input_mod to read netcd variables rather than
+! define local ones.
+!
 ! 4185 2019-08-23 13:49:38Z oliver.maas
 ! For initializing_actions = ' cyclic_fill':
-! Overwrite u_init, v_init, pt_init, q_init and s_init with the 
-! (temporally) and horizontally averaged vertical profiles from the end
-! of the prerun, because these profiles shall be used as the basic state
-! for the rayleigh damping and the pt_damping. 
-! 
+! Overwrite u_init, v_init, pt_init, q_init and s_init with the (temporally) and horizontally
+! averaged vertical profiles from the end of the prerun, because these profiles shall be used as the
+! basic state for the rayleigh damping and the pt_damping.
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 4168 2019-08-16 13:50:17Z suehring
 ! Replace function get_topography_top_index by topo_top_ind
-! 
+!
 ! 4151 2019-08-09 08:24:30Z suehring
 ! Add netcdf directive around input calls (fix for last commit)
-! 
+!
 ! 4150 2019-08-08 20:00:47Z suehring
-! Input of additional surface variables independent on land- or urban-surface
-! model
-! 
+! Input of additional surface variables independent on land- or urban-surface model
+!
 ! 4131 2019-08-02 11:06:18Z monakurppa
 ! Allocate sums and sums_l to allow profile output for salsa variables.
-! 
+!
 ! 4130 2019-08-01 13:04:13Z suehring
-! Effectively reduce 3D initialization to 1D initial profiles. This is because
-! 3D initialization produces structures in the w-component that are correlated
-! with the processor grid for some unknown reason  
-! 
+! Effectively reduce 3D initialization to 1D initial profiles. This is because 3D initialization
+! produces structures in the w-component that are correlated with the processor grid for some
+! unknown reason
+!
 ! 4090 2019-07-11 15:06:47Z Giersch
 ! Unused variables removed
-! 
+!
 ! 4088 2019-07-11 13:57:56Z Giersch
 ! Pressure and density profile calculations revised using basic functions
-! 
+!
 ! 4048 2019-06-21 21:00:21Z knoop
 ! Further modularization of particle code components
-! 
+!
 ! 4017 2019-06-06 12:16:46Z schwenkel
-! Convert most location messages to debug messages to reduce output in
-! job logfile to a minimum
-! 
-! 
+! Convert most location messages to debug messages to reduce output in job logfile to a minimum
+!
 ! unused variable removed
-! 
+!
 ! 3937 2019-04-29 15:09:07Z suehring
-! Move initialization of synthetic turbulence generator behind initialization
-! of offline nesting. Remove call for stg_adjust, as this is now already done
-! in stg_init. 
-! 
+! Move initialization of synthetic turbulence generator behind initialization of offline nesting.
+! Remove call for stg_adjust, as this is now already done in stg_init.
+!
 ! 3900 2019-04-16 15:17:43Z suehring
 ! Fix problem with LOD = 2 initialization
-! 
+!
 ! 3885 2019-04-11 11:29:34Z kanani
-! Changes related to global restructuring of location messages and introduction 
-! of additional debug messages
-! 
+! Changes related to global restructuring of location messages and introduction of additional debug
+! messages
+!
 ! 3849 2019-04-01 16:35:16Z knoop
 ! Move initialization of rmask before initializing user_init_arrays
-! 
+!
 ! 3711 2019-01-31 13:44:26Z knoop
 ! Introduced module_interface_init_checks for post-init checks in modules
-! 
+!
 ! 3700 2019-01-26 17:03:42Z knoop
 ! Some interface calls moved to module_interface + cleanup
-! 
+!
 ! 3648 2019-01-02 16:35:46Z suehring
 ! Rename subroutines for surface-data output
@@ -133,5 +129,5 @@
 !> or
 !> c) read values of a previous run
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE init_3d_model
 
@@ -141,17 +137,17 @@
     USE arrays_3d
 
-    USE basic_constants_and_equations_mod,                                     &
-        ONLY:  c_p, g, l_v, pi, exner_function, exner_function_invers,         &
-               ideal_gas_law_rho, ideal_gas_law_rho_pt, barometric_formula
-
-    USE bulk_cloud_model_mod,                                                  &
+    USE basic_constants_and_equations_mod,                                                         &
+        ONLY:  barometric_formula, c_p, exner_function, exner_function_invers, g,                  &
+               ideal_gas_law_rho, ideal_gas_law_rho_pt, l_v, pi
+
+    USE bulk_cloud_model_mod,                                                                      &
         ONLY:  bulk_cloud_model
 
-    USE chem_modules,                                                          &
+    USE chem_modules,                                                                              &
         ONLY:  max_pr_cs ! ToDo: this dependency needs to be removed cause it is ugly #new_dom
 
     USE control_parameters
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                                            &
         ONLY:  dx, dy, ddx2_mg, ddy2_mg
 
@@ -159,44 +155,44 @@
 
     USE kinds
-  
-    USE lsf_nudging_mod,                                                       &
+
+    USE lsf_nudging_mod,                                                                           &
         ONLY:  ls_forcing_surf
 
-    USE model_1d_mod,                                                          &
+    USE model_1d_mod,                                                                              &
         ONLY:  init_1d_model, l1d, u1d, v1d
 
-    USE module_interface,                                                      &
-        ONLY:  module_interface_init_arrays,                                   &
-               module_interface_init,                                          &
+    USE module_interface,                                                                          &
+        ONLY:  module_interface_init_arrays,                                                       &
+               module_interface_init,                                                              &
                module_interface_init_checks
 
-    USE multi_agent_system_mod,                                                &
+    USE multi_agent_system_mod,                                                                    &
         ONLY:  agents_active, mas_init
 
-    USE netcdf_interface,                                                      &
+    USE netcdf_interface,                                                                          &
         ONLY:  dots_max
 
-    USE netcdf_data_input_mod,                                                 &
-        ONLY:  char_fill,                                                      &
-               check_existence,                                                &
-               close_input_file,                                               &
-               get_attribute,                                                  &
-               get_variable,                                                   &
-               init_3d,                                                        &
-               input_pids_static,                                              &
-               inquire_num_variables,                                          &
-               inquire_variable_names,                                         &
-               input_file_static,                                              &
-               netcdf_data_input_init_3d,                                      &
-               num_var_pids,                                                   &
-               open_read_file,                                                 &
-               pids_id,                                                        &
-               real_2d,                                                        &
+    USE netcdf_data_input_mod,                                                                     &
+        ONLY:  char_fill,                                                                          &
+               check_existence,                                                                    &
+               close_input_file,                                                                   &
+               get_attribute,                                                                      &
+               get_variable,                                                                       &
+               init_3d,                                                                            &
+               input_pids_static,                                                                  &
+               inquire_num_variables,                                                              &
+               inquire_variable_names,                                                             &
+               input_file_static,                                                                  &
+               netcdf_data_input_init_3d,                                                          &
+               num_var_pids,                                                                       &
+               open_read_file,                                                                     &
+               pids_id,                                                                            &
+               real_2d,                                                                            &
                vars_pids
-               
-    USE nesting_offl_mod,                                                      &
+
+    USE nesting_offl_mod,                                                                          &
         ONLY:  nesting_offl_init
 
-    USE palm_date_time_mod,                                                    &
+    USE palm_date_time_mod,                                                                        &
         ONLY:  set_reference_date_time
 
@@ -204,49 +200,49 @@
 
 #if defined( __parallel )
-    USE pmc_interface,                                                         &
+    USE pmc_interface,                                                                             &
         ONLY:  nested_run
 #endif
 
-    USE random_function_mod 
-
-    USE random_generator_parallel,                                             &
+    USE random_function_mod
+
+    USE random_generator_parallel,                                                                 &
         ONLY:  init_parallel_random_generator
 
-    USE read_restart_data_mod,                                                 &
-        ONLY:  rrd_read_parts_of_global, rrd_local
-
-    USE statistics,                                                            &
-        ONLY:  hom, hom_sum, mean_surface_level_height, pr_palm, rmask,        &
-               statistic_regions, sums, sums_divnew_l, sums_divold_l, sums_l,  &
-               sums_l_l, sums_wsts_bc_l, ts_value,                             &
+    USE read_restart_data_mod,                                                                     &
+        ONLY:  rrd_local, rrd_read_parts_of_global
+
+    USE statistics,                                                                                &
+        ONLY:  hom, hom_sum, mean_surface_level_height, pr_palm, rmask, statistic_regions, sums,   &
+               sums_divnew_l, sums_divold_l, sums_l, sums_l_l, sums_wsts_bc_l, ts_value,           &
                weight_pres, weight_substep
 
-    USE synthetic_turbulence_generator_mod,                                    &
+    USE synthetic_turbulence_generator_mod,                                                        &
         ONLY:  stg_init, use_syn_turb_gen
 
-    USE surface_layer_fluxes_mod,                                              &
+    USE surface_layer_fluxes_mod,                                                                  &
         ONLY:  init_surface_layer_fluxes
 
-    USE surface_mod,                                                           &
-        ONLY :  init_single_surface_properties,                                &
-                init_surface_arrays,                                           &
-                init_surfaces,                                                 &
-                surf_def_h,                                                    &
-                surf_def_v,                                                    &
-                surf_lsm_h,                                                    &
+    USE surface_mod,                                                                               &
+        ONLY :  init_single_surface_properties,                                                    &
+                init_surface_arrays,                                                               &
+                init_surfaces,                                                                     &
+                surf_def_h,                                                                        &
+                surf_def_v,                                                                        &
+                surf_lsm_h,                                                                        &
                 surf_usm_h
 
 #if defined( _OPENACC )
-    USE surface_mod,                                                           &
+    USE surface_mod,                                                                               &
         ONLY :  bc_h
 #endif
 
-    USE surface_data_output_mod,                                               &
+    USE surface_data_output_mod,                                                                   &
         ONLY:  surface_data_output_init
 
     USE transpose_indices
 
+
     IMPLICIT NONE
-    
+
     INTEGER(iwp) ::  i                    !< grid index in x direction
     INTEGER(iwp) ::  ind_array(1)         !< dummy used to determine start index for external pressure forcing
@@ -254,6 +250,6 @@
     INTEGER(iwp) ::  k                    !< grid index in z direction
     INTEGER(iwp) ::  k_surf               !< surface level index
-    INTEGER(iwp) ::  l                    !< running index over surface orientation   
-    INTEGER(iwp) ::  m                    !< index of surface element in surface data type    
+    INTEGER(iwp) ::  l                    !< running index over surface orientation
+    INTEGER(iwp) ::  m                    !< index of surface element in surface data type
     INTEGER(iwp) ::  nz_u_shift           !< topography-top index on u-grid, used to vertically shift initial profiles
     INTEGER(iwp) ::  nz_v_shift           !< topography-top index on v-grid, used to vertically shift initial profiles
@@ -267,26 +263,27 @@
     INTEGER(iwp) ::  sr                   !< index of statistic region
 
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE   ::  ngp_2dh_l  !< toal number of horizontal grid points in statistical region on subdomain
-
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_outer_l    !< number of horizontal non-wall bounded grid points on subdomain
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_s_inner_l  !< number of horizontal non-topography grid points on subdomain
-
-
-    
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  init_l        !< dummy array used for averaging 3D data to obtain inital profiles 
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  p_hydrostatic !< hydrostatic pressure
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE   ::  ngp_2dh_l  !< toal number of horizontal grid points in statistical region on
+                                                             !< subdomain
+
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_outer_l    !< number of horizontal non-wall bounded grid points on
+                                                                     !< subdomain
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_s_inner_l  !< number of horizontal non-topography grid points on
+                                                                     !< subdomain
 
     REAL(wp) ::  dx_l !< grid spacing along x on different multigrid level
     REAL(wp) ::  dy_l !< grid spacing along y on different multigrid level
 
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  init_l                       !< dummy array used for averaging 3D data to obtain
+                                                                         !< inital profiles
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  mean_surface_level_height_l  !< mean surface level height on subdomain
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_l               !< total number of non-topography grid points on subdomain
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_tmp             !< total number of non-topography grid points
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  p_hydrostatic                !< hydrostatic pressure
+
     REAL(wp), DIMENSION(1:3) ::  volume_flow_area_l     !< area of lateral and top model domain surface on local subdomain
     REAL(wp), DIMENSION(1:3) ::  volume_flow_initial_l  !< initial volume flow into model domain
 
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  mean_surface_level_height_l !< mean surface level height on subdomain
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_l    !< total number of non-topography grid points on subdomain
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_tmp  !< total number of non-topography grid points
-
     TYPE(real_2d) ::  tmp_2d !< temporary variable to input additional surface-data from static file
-    
+
     CALL location_message( 'model initialization', 'start' )
 !
@@ -297,40 +294,40 @@
 !
 !-- Allocate arrays
-    ALLOCATE( mean_surface_level_height(0:statistic_regions),                  &
-              mean_surface_level_height_l(0:statistic_regions),                &
-              ngp_2dh(0:statistic_regions), ngp_2dh_l(0:statistic_regions),    &
-              ngp_3d(0:statistic_regions),                                     &
-              ngp_3d_inner(0:statistic_regions),                               &
-              ngp_3d_inner_l(0:statistic_regions),                             &
-              ngp_3d_inner_tmp(0:statistic_regions),                           &
-              sums_divnew_l(0:statistic_regions),                              &
+    ALLOCATE( mean_surface_level_height(0:statistic_regions),                                      &
+              mean_surface_level_height_l(0:statistic_regions),                                    &
+              ngp_2dh(0:statistic_regions), ngp_2dh_l(0:statistic_regions),                        &
+              ngp_3d(0:statistic_regions),                                                         &
+              ngp_3d_inner(0:statistic_regions),                                                   &
+              ngp_3d_inner_l(0:statistic_regions),                                                 &
+              ngp_3d_inner_tmp(0:statistic_regions),                                               &
+              sums_divnew_l(0:statistic_regions),                                                  &
               sums_divold_l(0:statistic_regions) )
     ALLOCATE( dp_smooth_factor(nzb:nzt), rdf(nzb+1:nzt), rdf_sc(nzb+1:nzt) )
-    ALLOCATE( ngp_2dh_outer(nzb:nzt+1,0:statistic_regions),                    &
-              ngp_2dh_outer_l(nzb:nzt+1,0:statistic_regions),                  &
-              ngp_2dh_s_inner(nzb:nzt+1,0:statistic_regions),                  &
-              ngp_2dh_s_inner_l(nzb:nzt+1,0:statistic_regions),                &
-              rmask(nysg:nyng,nxlg:nxrg,0:statistic_regions),                  &
-              sums(nzb:nzt+1,pr_palm+max_pr_user+max_pr_cs+max_pr_salsa),      &
+    ALLOCATE( ngp_2dh_outer(nzb:nzt+1,0:statistic_regions),                                        &
+              ngp_2dh_outer_l(nzb:nzt+1,0:statistic_regions),                                      &
+              ngp_2dh_s_inner(nzb:nzt+1,0:statistic_regions),                                      &
+              ngp_2dh_s_inner_l(nzb:nzt+1,0:statistic_regions),                                    &
+              rmask(nysg:nyng,nxlg:nxrg,0:statistic_regions),                                      &
+              sums(nzb:nzt+1,pr_palm+max_pr_user+max_pr_cs+max_pr_salsa),                          &
               sums_l(nzb:nzt+1,pr_palm+max_pr_user+max_pr_cs+max_pr_salsa,0:threads_per_task-1),   &
-              sums_l_l(nzb:nzt+1,0:statistic_regions,0:threads_per_task-1),    &
+              sums_l_l(nzb:nzt+1,0:statistic_regions,0:threads_per_task-1),                        &
               sums_wsts_bc_l(nzb:nzt+1,0:statistic_regions) )
     ALLOCATE( ts_value(dots_max,0:statistic_regions) )
     ALLOCATE( ptdf_x(nxlg:nxrg), ptdf_y(nysg:nyng) )
 
-    ALLOCATE( d(nzb+1:nzt,nys:nyn,nxl:nxr),                                    &
-              p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
+    ALLOCATE( d(nzb+1:nzt,nys:nyn,nxl:nxr),                                                        &
+              p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                    &
               tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 
-    ALLOCATE( pt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
-              pt_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
-              u_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
-              u_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
-              u_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
-              v_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
-              v_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
-              v_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
-              w_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
-              w_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
+    ALLOCATE( pt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                 &
+              pt_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                 &
+              u_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
+              u_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
+              u_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
+              v_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
+              v_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
+              v_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
+              w_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
+              w_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
               w_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
     IF (  .NOT.  neutral )  THEN
@@ -339,14 +336,13 @@
 !
 !-- Pre-set masks for regional statistics. Default is the total model domain.
-!-- Ghost points are excluded because counting values at the ghost boundaries
-!-- would bias the statistics
+!-- Ghost points are excluded because counting values at the ghost boundaries would bias the
+!-- statistics.
     rmask = 1.0_wp
     rmask(:,nxlg:nxl-1,:) = 0.0_wp;  rmask(:,nxr+1:nxrg,:) = 0.0_wp
     rmask(nysg:nys-1,:,:) = 0.0_wp;  rmask(nyn+1:nyng,:,:) = 0.0_wp
 !
-!-- Following array is required for perturbation pressure within the iterative
-!-- pressure solvers. For the multistep schemes (Runge-Kutta), array p holds
-!-- the weighted average of the substeps and cannot be used in the Poisson
-!-- solver.
+!-- Following array is required for perturbation pressure within the iterative pressure solvers. For
+!-- the multistep schemes (Runge-Kutta), array p holds the weighted average of the substeps and
+!-- cannot be used in the Poisson solver.
     IF ( psolver == 'sor' )  THEN
        ALLOCATE( p_loc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
@@ -367,16 +363,16 @@
 !
 !--    3D-humidity
-       ALLOCATE( q_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
-                 q_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
-                 q_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
-                 vpt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) 
-    ENDIF   
-    
+       ALLOCATE( q_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                               &
+                 q_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                               &
+                 q_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                               &
+                 vpt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+    ENDIF
+
     IF ( passive_scalar )  THEN
 
 !
 !--    3D scalar arrays
-       ALLOCATE( s_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
-                 s_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
+       ALLOCATE( s_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                               &
+                 s_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                               &
                  s_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 
@@ -384,7 +380,7 @@
 
 !
-!-- Allocate and set 1d-profiles for Stokes drift velocity. It may be set to
-!-- non-zero values later in ocean_init
-    ALLOCATE( u_stokes_zu(nzb:nzt+1), u_stokes_zw(nzb:nzt+1),                  &
+!-- Allocate and set 1d-profiles for Stokes drift velocity. It may be set to non-zero values later
+!-- in ocean_init.
+    ALLOCATE( u_stokes_zu(nzb:nzt+1), u_stokes_zw(nzb:nzt+1),                                      &
               v_stokes_zu(nzb:nzt+1), v_stokes_zw(nzb:nzt+1) )
     u_stokes_zu(:) = 0.0_wp
@@ -401,43 +397,40 @@
     ALLOCATE( drho_air_zw(nzb:nzt+1) )
 !
-!-- Density profile calculation for anelastic and Boussinesq approximation
-!-- In case of a Boussinesq approximation, a constant density is calculated
-!-- mainly for output purposes. This density do not need to be considered 
-!-- in the model's system of equations.
+!-- Density profile calculation for anelastic and Boussinesq approximation.
+!-- In case of a Boussinesq approximation, a constant density is calculated mainly for output
+!-- purposes. This density does not need to be considered in the model's system of equations.
     IF ( TRIM( approximation ) == 'anelastic' )  THEN
        DO  k = nzb, nzt+1
-          p_hydrostatic(k) = barometric_formula(zu(k), pt_surface *            & 
-                             exner_function(surface_pressure * 100.0_wp),      &
-                             surface_pressure * 100.0_wp)
-          
+          p_hydrostatic(k) = barometric_formula(zu(k), pt_surface *                                &
+                                                exner_function(surface_pressure * 100.0_wp),       &
+                                                surface_pressure * 100.0_wp)
+
           rho_air(k) = ideal_gas_law_rho_pt(p_hydrostatic(k), pt_init(k))
        ENDDO
-       
+
        DO  k = nzb, nzt
           rho_air_zw(k) = 0.5_wp * ( rho_air(k) + rho_air(k+1) )
        ENDDO
-       
-       rho_air_zw(nzt+1)  = rho_air_zw(nzt)                                    &
-                            + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt)  )
-                            
+
+       rho_air_zw(nzt+1)  = rho_air_zw(nzt) + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt)  )
+
     ELSE
        DO  k = nzb, nzt+1
-          p_hydrostatic(k) = barometric_formula(zu(nzb), pt_surface *          & 
-                             exner_function(surface_pressure * 100.0_wp),      &
-                             surface_pressure * 100.0_wp)
+          p_hydrostatic(k) = barometric_formula(zu(nzb), pt_surface *                              &
+                                                exner_function(surface_pressure * 100.0_wp),       &
+                                                surface_pressure * 100.0_wp)
 
           rho_air(k) = ideal_gas_law_rho_pt(p_hydrostatic(k), pt_init(nzb))
        ENDDO
-       
+
        DO  k = nzb, nzt
           rho_air_zw(k) = 0.5_wp * ( rho_air(k) + rho_air(k+1) )
        ENDDO
-       
-       rho_air_zw(nzt+1)  = rho_air_zw(nzt)                                    &
-                            + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt)  )
-                            
-    ENDIF
-!
-!-- compute the inverse density array in order to avoid expencive divisions
+
+       rho_air_zw(nzt+1)  = rho_air_zw(nzt) + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt)  )
+
+    ENDIF
+!
+!-- Compute the inverse density array in order to avoid expencive divisions
     drho_air    = 1.0_wp / rho_air
     drho_air_zw = 1.0_wp / rho_air_zw
@@ -453,5 +446,5 @@
 
 !
-!-- calculate flux conversion factors according to approximation and in-/output mode
+!-- Calculate flux conversion factors according to approximation and in-/output mode
     DO  k = nzb, nzt+1
 
@@ -484,6 +477,6 @@
 
 !
-!-- In case of multigrid method, compute grid lengths and grid factors for the
-!-- grid levels with respective density on each grid
+!-- In case of multigrid method, compute grid lengths and grid factors for the grid levels with
+!-- respective density on each grid.
     IF ( psolver(1:9) == 'multigrid' )  THEN
 
@@ -500,9 +493,8 @@
        dzu_mg(:,maximum_grid_level) = dzu
        rho_air_mg(:,maximum_grid_level) = rho_air
-!       
-!--    Next line to ensure an equally spaced grid. 
+!
+!--    Next line to ensure an equally spaced grid.
        dzu_mg(1,maximum_grid_level) = dzu(2)
-       rho_air_mg(nzb,maximum_grid_level) = rho_air(nzb) +                     &
-                                             (rho_air(nzb) - rho_air(nzb+1))
+       rho_air_mg(nzb,maximum_grid_level) = rho_air(nzb) + (rho_air(nzb) - rho_air(nzb+1))
 
        dzw_mg(:,maximum_grid_level) = dzw
@@ -512,6 +504,8 @@
            dzu_mg(nzb+1,l) = 2.0_wp * dzu_mg(nzb+1,l+1)
            dzw_mg(nzb+1,l) = 2.0_wp * dzw_mg(nzb+1,l+1)
-           rho_air_mg(nzb,l)    = rho_air_mg(nzb,l+1) + (rho_air_mg(nzb,l+1) - rho_air_mg(nzb+1,l+1))
-           rho_air_zw_mg(nzb,l) = rho_air_zw_mg(nzb,l+1) + (rho_air_zw_mg(nzb,l+1) - rho_air_zw_mg(nzb+1,l+1))
+           rho_air_mg(nzb,l)    = rho_air_mg(nzb,l+1)    + ( rho_air_mg(nzb,l+1)    -              &
+                                                             rho_air_mg(nzb+1,l+1)    )
+           rho_air_zw_mg(nzb,l) = rho_air_zw_mg(nzb,l+1) + ( rho_air_zw_mg(nzb,l+1) -              &
+                                                             rho_air_zw_mg(nzb+1,l+1) )
            rho_air_mg(nzb+1,l)    = rho_air_mg(nzb+1,l+1)
            rho_air_zw_mg(nzb+1,l) = rho_air_zw_mg(nzb+1,l+1)
@@ -534,5 +528,5 @@
              f2_mg(k,l) = rho_air_zw_mg(k,l) / ( dzu_mg(k+1,l) * dzw_mg(k,l) )
              f3_mg(k,l) = rho_air_zw_mg(k-1,l) / ( dzu_mg(k,l)   * dzw_mg(k,l) )
-             f1_mg(k,l) = 2.0_wp * ( ddx2_mg(l) + ddy2_mg(l) ) &
+             f1_mg(k,l) = 2.0_wp * ( ddx2_mg(l) + ddy2_mg(l) )                                     &
                           * rho_air_mg(k,l) + f2_mg(k,l) + f3_mg(k,l)
           ENDDO
@@ -552,37 +546,34 @@
 
 !
-!-- Arrays to store velocity data from t-dt and the phase speeds which
-!-- are needed for radiation boundary conditions
+!-- Arrays to store velocity data from t-dt and the phase speeds which are needed for radiation
+!-- boundary conditions.
     IF ( bc_radiation_l )  THEN
-       ALLOCATE( u_m_l(nzb:nzt+1,nysg:nyng,1:2),                               &
-                 v_m_l(nzb:nzt+1,nysg:nyng,0:1),                               &
+       ALLOCATE( u_m_l(nzb:nzt+1,nysg:nyng,1:2),                                                   &
+                 v_m_l(nzb:nzt+1,nysg:nyng,0:1),                                                   &
                  w_m_l(nzb:nzt+1,nysg:nyng,0:1) )
     ENDIF
     IF ( bc_radiation_r )  THEN
-       ALLOCATE( u_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx),                           &
-                 v_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx),                           &
+       ALLOCATE( u_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx),                                               &
+                 v_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx),                                               &
                  w_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx) )
     ENDIF
     IF ( bc_radiation_l  .OR.  bc_radiation_r )  THEN
-       ALLOCATE( c_u(nzb:nzt+1,nysg:nyng), c_v(nzb:nzt+1,nysg:nyng),           &
-                 c_w(nzb:nzt+1,nysg:nyng) )
+       ALLOCATE( c_u(nzb:nzt+1,nysg:nyng), c_v(nzb:nzt+1,nysg:nyng), c_w(nzb:nzt+1,nysg:nyng) )
     ENDIF
     IF ( bc_radiation_s )  THEN
-       ALLOCATE( u_m_s(nzb:nzt+1,0:1,nxlg:nxrg),                               &
-                 v_m_s(nzb:nzt+1,1:2,nxlg:nxrg),                               &
+       ALLOCATE( u_m_s(nzb:nzt+1,0:1,nxlg:nxrg),                                                   &
+                 v_m_s(nzb:nzt+1,1:2,nxlg:nxrg),                                                   &
                  w_m_s(nzb:nzt+1,0:1,nxlg:nxrg) )
     ENDIF
     IF ( bc_radiation_n )  THEN
-       ALLOCATE( u_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg),                           &
-                 v_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg),                           &
+       ALLOCATE( u_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg),                                               &
+                 v_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg),                                               &
                  w_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg) )
     ENDIF
     IF ( bc_radiation_s  .OR.  bc_radiation_n )  THEN
-       ALLOCATE( c_u(nzb:nzt+1,nxlg:nxrg), c_v(nzb:nzt+1,nxlg:nxrg),           &
-                 c_w(nzb:nzt+1,nxlg:nxrg) )
-    ENDIF
-    IF ( bc_radiation_l  .OR.  bc_radiation_r  .OR.  bc_radiation_s  .OR.      &
-         bc_radiation_n )  THEN
-       ALLOCATE( c_u_m_l(nzb:nzt+1), c_v_m_l(nzb:nzt+1), c_w_m_l(nzb:nzt+1) )                   
+       ALLOCATE( c_u(nzb:nzt+1,nxlg:nxrg), c_v(nzb:nzt+1,nxlg:nxrg), c_w(nzb:nzt+1,nxlg:nxrg) )
+    ENDIF
+    IF ( bc_radiation_l  .OR.  bc_radiation_r  .OR.  bc_radiation_s  .OR.  bc_radiation_n )  THEN
+       ALLOCATE( c_u_m_l(nzb:nzt+1), c_v_m_l(nzb:nzt+1), c_w_m_l(nzb:nzt+1) )
        ALLOCATE( c_u_m(nzb:nzt+1), c_v_m(nzb:nzt+1), c_w_m(nzb:nzt+1) )
     ENDIF
@@ -603,8 +594,8 @@
        vpt  => vpt_1
     ENDIF
-    
+
     IF ( passive_scalar )  THEN
        s => s_1;  s_p => s_2;  ts_m => s_3
-    ENDIF    
+    ENDIF
 
 !
@@ -617,15 +608,14 @@
 
 !
-!-- Allocate arrays containing the RK coefficient for calculation of 
-!-- perturbation pressure and turbulent fluxes. At this point values are
-!-- set for pressure calculation during initialization (where no timestep
-!-- is done). Further below the values needed within the timestep scheme
-!-- will be set.
-    ALLOCATE( weight_substep(1:intermediate_timestep_count_max),               &
+!-- Allocate arrays containing the RK coefficient for calculation of perturbation pressure and
+!-- turbulent fluxes. At this point values are set for pressure calculation during initialization
+!-- (where no timestep is done). Further below the values needed within the timestep scheme will be
+!-- set.
+    ALLOCATE( weight_substep(1:intermediate_timestep_count_max),                                   &
               weight_pres(1:intermediate_timestep_count_max) )
     weight_substep = 1.0_wp
     weight_pres    = 1.0_wp
     intermediate_timestep_count = 0  ! needed when simulated_time = 0.0
-       
+
     IF ( debug_output )  CALL debug_message( 'allocating arrays', 'end' )
 
@@ -636,15 +626,14 @@
 !
 !-- Initialize local summation arrays for routine flow_statistics.
-!-- This is necessary because they may not yet have been initialized when they
-!-- are called from flow_statistics (or - depending on the chosen model run -
-!-- are never initialized)
-    sums_divnew_l      = 0.0_wp
-    sums_divold_l      = 0.0_wp
-    sums_l_l           = 0.0_wp
-    sums_wsts_bc_l     = 0.0_wp
-    
+!-- This is necessary because they may not yet have been initialized when they are called from
+!-- flow_statistics (or - depending on the chosen model run - are never initialized)
+    sums_divnew_l  = 0.0_wp
+    sums_divold_l  = 0.0_wp
+    sums_l_l       = 0.0_wp
+    sums_wsts_bc_l = 0.0_wp
+
 !
 !-- Initialize model variables
-    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
+    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.                                &
          TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
 !
@@ -653,20 +642,20 @@
           IF ( debug_output )  CALL debug_message( 'initializing with INIFOR', 'start' )
 !
-!--       Read initial 1D profiles or 3D data from NetCDF file, depending 
-!--       on the provided level-of-detail. 
-!--       At the moment, only u, v, w, pt and q are provided. 
+!--       Read initial 1D profiles or 3D data from NetCDF file, depending on the provided
+!--       level-of-detail.
+!--       At the moment, only u, v, w, pt and q are provided.
           CALL netcdf_data_input_init_3d
 !
-!--       Please note, Inifor provides data from nzb+1 to nzt. 
-!--       Bottom and top boundary conditions for Inifor profiles are already 
-!--       set (just after reading), so that this is not necessary here.
-!--       Depending on the provided level-of-detail, initial Inifor data is
-!--       either stored on data type (lod=1), or directly on 3D arrays (lod=2). 
-!--       In order to obtain also initial profiles in case of lod=2 (which 
-!--       is required for e.g. damping), average over 3D data.
+!--       Please note, Inifor provides data from nzb+1 to nzt.
+!--       Bottom and top boundary conditions for Inifor profiles are already set (just after
+!--       reading), so that this is not necessary here.
+!--       Depending on the provided level-of-detail, initial Inifor data is either stored on data
+!--       type (lod=1), or directly on 3D arrays (lod=2).
+!--       In order to obtain also initial profiles in case of lod=2 (which is required for e.g.
+!--       damping), average over 3D data.
           IF( init_3d%lod_u == 1 )  THEN
              u_init = init_3d%u_init
-          ELSEIF( init_3d%lod_u == 2 )  THEN 
-             ALLOCATE( init_l(nzb:nzt+1) ) 
+          ELSEIF( init_3d%lod_u == 2 )  THEN
+             ALLOCATE( init_l(nzb:nzt+1) )
              DO  k = nzb, nzt+1
                 init_l(k) = SUM( u(k,nys:nyn,nxl:nxr) )
@@ -675,6 +664,5 @@
 
 #if defined( __parallel )
-             CALL MPI_ALLREDUCE( init_l, u_init, nzt+1-nzb+1,                  &
-                                 MPI_REAL, MPI_SUM, comm2d, ierr )
+             CALL MPI_ALLREDUCE( init_l, u_init, nzt+1-nzb+1, MPI_REAL, MPI_SUM, comm2d, ierr )
 #else
              u_init = init_l
@@ -683,9 +671,9 @@
 
           ENDIF
-           
-          IF( init_3d%lod_v == 1 )  THEN  
+
+          IF( init_3d%lod_v == 1 )  THEN
              v_init = init_3d%v_init
-          ELSEIF( init_3d%lod_v == 2 )  THEN 
-             ALLOCATE( init_l(nzb:nzt+1) ) 
+          ELSEIF( init_3d%lod_v == 2 )  THEN
+             ALLOCATE( init_l(nzb:nzt+1) )
              DO  k = nzb, nzt+1
                 init_l(k) = SUM( v(k,nys:nyn,nxl:nxr) )
@@ -694,6 +682,5 @@
 
 #if defined( __parallel )
-             CALL MPI_ALLREDUCE( init_l, v_init, nzt+1-nzb+1,                  &
-                                 MPI_REAL, MPI_SUM, comm2d, ierr )
+             CALL MPI_ALLREDUCE( init_l, v_init, nzt+1-nzb+1, MPI_REAL, MPI_SUM, comm2d, ierr )
 #else
              v_init = init_l
@@ -704,6 +691,6 @@
              IF( init_3d%lod_pt == 1 )  THEN
                 pt_init = init_3d%pt_init
-             ELSEIF( init_3d%lod_pt == 2 )  THEN 
-                ALLOCATE( init_l(nzb:nzt+1) ) 
+             ELSEIF( init_3d%lod_pt == 2 )  THEN
+                ALLOCATE( init_l(nzb:nzt+1) )
                 DO  k = nzb, nzt+1
                    init_l(k) = SUM( pt(k,nys:nyn,nxl:nxr) )
@@ -712,6 +699,5 @@
 
 #if defined( __parallel )
-                CALL MPI_ALLREDUCE( init_l, pt_init, nzt+1-nzb+1,               &
-                                    MPI_REAL, MPI_SUM, comm2d, ierr )
+                CALL MPI_ALLREDUCE( init_l, pt_init, nzt+1-nzb+1, MPI_REAL, MPI_SUM, comm2d, ierr )
 #else
                 pt_init = init_l
@@ -725,6 +711,6 @@
              IF( init_3d%lod_q == 1 )  THEN
                 q_init = init_3d%q_init
-             ELSEIF( init_3d%lod_q == 2 )  THEN 
-                ALLOCATE( init_l(nzb:nzt+1) ) 
+             ELSEIF( init_3d%lod_q == 2 )  THEN
+                ALLOCATE( init_l(nzb:nzt+1) )
                 DO  k = nzb, nzt+1
                    init_l(k) = SUM( q(k,nys:nyn,nxl:nxr) )
@@ -733,6 +719,5 @@
 
 #if defined( __parallel )
-                CALL MPI_ALLREDUCE( init_l, q_init, nzt+1-nzb+1,               &
-                                    MPI_REAL, MPI_SUM, comm2d, ierr )
+                CALL MPI_ALLREDUCE( init_l, q_init, nzt+1-nzb+1, MPI_REAL, MPI_SUM, comm2d, ierr )
 #else
                 q_init = init_l
@@ -743,26 +728,21 @@
 
 !
-!--       Write initial profiles onto 3D arrays. 
-!--       Work-around, 3D initialization of u,v,w creates artificial 
-!--       structures wich correlate with the processor grid. The reason
-!--       for this is still unknown. To work-around this, 3D initialization
-!--       will be effectively reduce to a 1D initialization where no such
-!--       artificial structures appear.
+!--       Write initial profiles onto 3D arrays.
+!--       Work-around, 3D initialization of u,v,w creates artificial structures which correlate with
+!--       the processor grid. The reason for this is still unknown. To work-around this, 3D
+!--       initialization will be effectively reduce to a 1D initialization where no such artificial
+!--       structures appear.
           DO  i = nxlg, nxrg
              DO  j = nysg, nyng
-                IF( init_3d%lod_u == 1  .OR.  init_3d%lod_u == 2 )             &
-                   u(:,j,i) = u_init(:)
-                IF( init_3d%lod_v == 1  .OR.  init_3d%lod_u == 2 )             &
-                   v(:,j,i) = v_init(:)
-                IF( .NOT. neutral  .AND.                                       &
-                    ( init_3d%lod_pt == 1  .OR.  init_3d%lod_pt == 2 ) )       &
+                IF( init_3d%lod_u == 1  .OR.  init_3d%lod_u == 2 )  u(:,j,i) = u_init(:)
+                IF( init_3d%lod_v == 1  .OR.  init_3d%lod_u == 2 )  v(:,j,i) = v_init(:)
+                IF( .NOT. neutral  .AND.  ( init_3d%lod_pt == 1  .OR.  init_3d%lod_pt == 2 ) )     &
                    pt(:,j,i) = pt_init(:)
-                IF( humidity  .AND.                                            &
-                    ( init_3d%lod_q == 1  .OR.  init_3d%lod_q == 2 ) )         &
+                IF( humidity  .AND.  ( init_3d%lod_q == 1  .OR.  init_3d%lod_q == 2 ) )            &
                    q(:,j,i) = q_init(:)
              ENDDO
           ENDDO
 !
-!--       Set geostrophic wind components.  
+!--       Set geostrophic wind components.
           IF ( init_3d%from_file_ug )  THEN
              ug(:) = init_3d%ug_init(:)
@@ -790,20 +770,18 @@
 
 !
-!--       Set velocity components at non-atmospheric / oceanic grid points to 
-!--       zero. 
+!--       Set velocity components at non-atmospheric / oceanic grid points to zero.
           u = MERGE( u, 0.0_wp, BTEST( wall_flags_total_0, 1 ) )
           v = MERGE( v, 0.0_wp, BTEST( wall_flags_total_0, 2 ) )
           w = MERGE( w, 0.0_wp, BTEST( wall_flags_total_0, 3 ) )
 !
-!--       Initialize surface variables, e.g. friction velocity, momentum 
-!--       fluxes, etc. 
-          CALL init_surfaces
-
-          IF ( debug_output )  CALL debug_message( 'initializing with INIFOR', 'end' )
+!--       Initialize surface variables, e.g. friction velocity, momentum fluxes, etc.
+          CALL  init_surfaces
+
+          IF ( debug_output )  CALL  debug_message( 'initializing with INIFOR', 'end' )
 !
 !--    Initialization via computed 1D-model profiles
        ELSEIF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
 
-          IF ( debug_output )  CALL debug_message( 'initializing with 1D model profiles', 'start' )
+          IF ( debug_output )  CALL  debug_message( 'initializing with 1D model profiles', 'start' )
 !
 !--       Use solutions of the 1D model as initial profiles,
@@ -833,5 +811,5 @@
                    s(:,j,i) = s_init
                 ENDDO
-             ENDDO   
+             ENDDO
           ENDIF
 !
@@ -843,12 +821,10 @@
 !--       Set velocities back to zero
           u = MERGE( u, 0.0_wp, BTEST( wall_flags_total_0, 1 ) )
-          v = MERGE( v, 0.0_wp, BTEST( wall_flags_total_0, 2 ) )         
-!
-!--       WARNING: The extra boundary conditions set after running the
-!--       -------  1D model impose an error on the divergence one layer
-!--                below the topography; need to correct later 
-!--       ATTENTION: Provisional correction for Piacsek & Williams
-!--       ---------  advection scheme: keep u and v zero one layer below
-!--                  the topography.
+          v = MERGE( v, 0.0_wp, BTEST( wall_flags_total_0, 2 ) )
+!
+!--       WARNING: The extra boundary conditions set after running the 1D model impose an error on
+!--       -------- the divergence one layer below the topography; need to correct later
+!--       ATTENTION: Provisional correction for Piacsek & Williams advection scheme: keep u and v
+!--       ---------- zero one layer below the topography.
           IF ( ibc_uv_b == 1 )  THEN
 !
@@ -863,18 +839,16 @@
           ENDIF
 !
-!--       Initialize surface variables, e.g. friction velocity, momentum 
-!--       fluxes, etc. 
+!--       Initialize surface variables, e.g. friction velocity, momentum fluxes, etc.
           CALL init_surfaces
 
-          IF ( debug_output )  CALL debug_message( 'initializing with 1D model profiles', 'end' )
-
-       ELSEIF ( INDEX(initializing_actions, 'set_constant_profiles') /= 0 )    &
-       THEN
-
-          IF ( debug_output )  CALL debug_message( 'initializing with constant profiles', 'start' )
-
-!
-!--       Use constructed initial profiles (velocity constant with height,
-!--       temperature profile with constant gradient)
+          IF ( debug_output )  CALL  debug_message( 'initializing with 1D model profiles', 'end' )
+
+       ELSEIF ( INDEX(initializing_actions, 'set_constant_profiles') /= 0 )  THEN
+
+          IF ( debug_output )  CALL  debug_message( 'initializing with constant profiles', 'start' )
+
+!
+!--       Use constructed initial profiles (velocity constant with height, temperature profile with
+!--       constant gradient)
           DO  i = nxlg, nxrg
              DO  j = nysg, nyng
@@ -889,20 +863,16 @@
           v = MERGE( v, 0.0_wp, BTEST( wall_flags_total_0, 2 ) )
 !
-!--       Set initial horizontal velocities at the lowest computational grid 
-!--       levels to zero in order to avoid too small time steps caused by the 
-!--       diffusion limit in the initial phase of a run (at k=1, dz/2 occurs
-!--       in the limiting formula!). 
-!--       Please note, in case land- or urban-surface model is used and a 
-!--       spinup is applied, masking the lowest computational level is not 
-!--       possible as MOST as well as energy-balance parametrizations will not 
-!--       work with zero wind velocity. 
-          IF ( ibc_uv_b /= 1  .AND.  .NOT.  spinup )  THEN
+!--       Set initial horizontal velocities at the lowest computational grid levels to zero in order
+!--       to avoid too small time steps caused by the diffusion limit in the initial phase of a run
+!--       (at k=1, dz/2 occurs in the limiting formula!).
+!--       Please note, in case land- or urban-surface model is used and a spinup is applied, masking
+!--       the lowest computational level is not possible as MOST as well as energy-balance
+!--       parametrizations will not work with zero wind velocity.
+          IF ( ibc_uv_b /= 1  .AND.  .NOT. spinup )  THEN
              DO  i = nxlg, nxrg
                 DO  j = nysg, nyng
                    DO  k = nzb, nzt
-                      u(k,j,i) = MERGE( u(k,j,i), 0.0_wp,                      &
-                                     BTEST( wall_flags_total_0(k,j,i), 20 ) )
-                      v(k,j,i) = MERGE( v(k,j,i), 0.0_wp,                      &
-                                     BTEST( wall_flags_total_0(k,j,i), 21 ) )
+                      u(k,j,i) = MERGE( u(k,j,i), 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 20 ) )
+                      v(k,j,i) = MERGE( v(k,j,i), 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 21 ) )
                    ENDDO
                 ENDDO
@@ -917,5 +887,5 @@
              ENDDO
           ENDIF
-          
+
           IF ( passive_scalar )  THEN
              DO  i = nxlg, nxrg
@@ -927,22 +897,19 @@
 
 !
-!--       Compute initial temperature field and other constants used in case
-!--       of a sloping surface
+!--       Compute initial temperature field and other constants used in case of a sloping surface.
           IF ( sloping_surface )  CALL init_slope
 !
-!--       Initialize surface variables, e.g. friction velocity, momentum 
-!--       fluxes, etc. 
+!--       Initialize surface variables, e.g. friction velocity, momentum fluxes, etc.
           CALL init_surfaces
-          
+
           IF ( debug_output )  CALL debug_message( 'initializing with constant profiles', 'end' )
 
-       ELSEIF ( INDEX(initializing_actions, 'by_user') /= 0 )                  &
-       THEN
+       ELSEIF ( INDEX(initializing_actions, 'by_user') /= 0 )  THEN
 
           IF ( debug_output )  CALL debug_message( 'initializing by user', 'start' )
 !
-!--       Pre-initialize surface variables, i.e. setting start- and end-indices
-!--       at each (j,i)-location. Please note, this does not supersede 
-!--       user-defined initialization of surface quantities. 
+!--       Pre-initialize surface variables, i.e. setting start- and end-indices at each
+!--       (j,i)-location. Please note, this does not supersede user-defined initialization of
+!--       surface quantities.
           CALL init_surfaces
 !
@@ -954,9 +921,11 @@
        ENDIF
 
-       IF ( debug_output )  CALL debug_message( 'initializing statistics, boundary conditions, etc.', 'start' )
+       IF ( debug_output )  THEN
+          CALL debug_message( 'initializing statistics, boundary conditions, etc.', 'start' )
+       ENDIF
 
 !
 !--    Bottom boundary
-       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2  )  THEN
+       IF ( ibc_uv_b == 0  .OR.  ibc_uv_b == 2  )  THEN
           u(nzb,:,:) = 0.0_wp
           v(nzb,:,:) = 0.0_wp
@@ -975,8 +944,7 @@
 
 !
-!--    Store initial profiles for output purposes etc.. Please note, in case of 
-!--    initialization of u, v, w, pt, and q via output data derived from larger 
-!--    scale models, data will not be horizontally homogeneous. Actually, a mean 
-!--    profile should be calculated before.   
+!--    Store initial profiles for output purposes etc.. Please note, in case of initialization of u,
+!--    v, w, pt, and q via output data derived from larger scale models, data will not be
+!--    horizontally homogeneous. Actually, a mean profile should be calculated before.
        hom(:,1,5,:) = SPREAD( u(:,nys,nxl), 2, statistic_regions+1 )
        hom(:,1,6,:) = SPREAD( v(:,nys,nxl), 2, statistic_regions+1 )
@@ -989,11 +957,9 @@
        IF ( humidity )  THEN
 !
-!--       Store initial profile of total water content, virtual potential
-!--       temperature 
+!--       Store initial profile of total water content, virtual potential temperature
           hom(:,1,26,:) = SPREAD(   q(:,nys,nxl), 2, statistic_regions+1 )
           hom(:,1,29,:) = SPREAD( vpt(:,nys,nxl), 2, statistic_regions+1 )
 !
-!--       Store initial profile of mixing ratio and potential
-!--       temperature
+!--       Store initial profile of mixing ratio and potential temperature
           IF ( bulk_cloud_model  .OR.  cloud_droplets ) THEN
              hom(:,1,27,:) = SPREAD(  q(:,nys,nxl), 2, statistic_regions+1 )
@@ -1011,13 +977,13 @@
 !--    Initialize the random number generators (from numerical recipes)
        CALL random_function_ini
-       
+
        IF ( random_generator == 'random-parallel' )  THEN
           CALL init_parallel_random_generator( nx, nys, nyn, nxl, nxr )
        ENDIF
 !
-!--    Set the reference state to be used in the buoyancy terms (for ocean runs
-!--    the reference state will be set (overwritten) in init_ocean)
+!--    Set the reference state to be used in the buoyancy terms (for ocean runs the reference state
+!--    will be set (overwritten) in init_ocean).
        IF ( use_single_reference_value )  THEN
-          IF (  .NOT.  humidity )  THEN
+          IF ( .NOT. humidity )  THEN
              ref_state(:) = pt_reference
           ELSE
@@ -1025,5 +991,5 @@
           ENDIF
        ELSE
-          IF (  .NOT.  humidity )  THEN
+          IF ( .NOT. humidity )  THEN
              ref_state(:) = pt_init(:)
           ELSE
@@ -1050,11 +1016,10 @@
 
 !
-!--    Impose temperature anomaly (advection test only) or warm air bubble 
-!--    close to surface
-       IF ( INDEX( initializing_actions, 'initialize_ptanom' ) /= 0  .OR.  &
+!--    Impose temperature anomaly (advection test only) or warm air bubble close to surface.
+       IF ( INDEX( initializing_actions, 'initialize_ptanom' ) /= 0  .OR.                          &
             INDEX( initializing_actions, 'initialize_bubble' ) /= 0  )  THEN
           CALL init_pt_anomaly
        ENDIF
-       
+
 !
 !--    If required, change the surface temperature at the start of the 3D run
@@ -1066,10 +1031,10 @@
 !--    If required, change the surface humidity/scalar at the start of the 3D
 !--    run
-       IF ( humidity  .AND.  q_surface_initial_change /= 0.0_wp )              &
+       IF ( humidity  .AND.  q_surface_initial_change /= 0.0_wp )                                  &
           q(nzb,:,:) = q(nzb,:,:) + q_surface_initial_change
-          
-       IF ( passive_scalar .AND.  s_surface_initial_change /= 0.0_wp )         &
+
+       IF ( passive_scalar  .AND.  s_surface_initial_change /= 0.0_wp )                            &
           s(nzb,:,:) = s(nzb,:,:) + s_surface_initial_change
-        
+
 
 !
@@ -1082,11 +1047,13 @@
           q_p = q
        ENDIF
-       
+
        IF ( passive_scalar )  THEN
           ts_m = 0.0_wp
           s_p  = s
-       ENDIF       
-
-       IF ( debug_output )  CALL debug_message( 'initializing statistics, boundary conditions, etc.', 'end' )
+       ENDIF
+
+       IF ( debug_output )  THEN
+          CALL debug_message( 'initializing statistics, boundary conditions, etc.', 'end' )
+       ENDIF
 
     ELSEIF ( TRIM( initializing_actions ) == 'read_restart_data'  .OR.         &
@@ -1094,20 +1061,19 @@
     THEN
 
-       IF ( debug_output )  CALL debug_message( 'initializing in case of restart / cyclic_fill', 'start' )
-!
-!--    Initialize surface elements and its attributes, e.g. heat- and 
-!--    momentumfluxes, roughness, scaling parameters. As number of surface 
-!--    elements might be different between runs, e.g. in case of cyclic fill, 
-!--    and not all surface elements are read, surface elements need to be 
-!--    initialized before. 
-!--    Please note, in case of cyclic fill, surfaces should be initialized 
-!--    after restart data is read, else, individual settings of surface 
-!--    parameters will be overwritten from data of precursor run, hence, 
-!--    init_surfaces is called a second time after reading the restart data. 
-       CALL init_surfaces                        
-!
-!--    When reading data for cyclic fill of 3D prerun data files, read
-!--    some of the global variables from the restart file which are required
-!--    for initializing the inflow
+       IF ( debug_output )  THEN
+          CALL debug_message( 'initializing in case of restart / cyclic_fill', 'start' )
+       ENDIF
+!
+!--    Initialize surface elements and its attributes, e.g. heat- and momentumfluxes, roughness,
+!--    scaling parameters. As number of surface elements might be different between runs, e.g. in
+!--    case of cyclic fill, and not all surface elements are read, surface elements need to be
+!--    initialized before.
+!--    Please note, in case of cyclic fill, surfaces should be initialized after restart data is
+!--    read, else, individual settings of surface parameters will be overwritten from data of
+!--    precursor run, hence, init_surfaces is called a second time after reading the restart data.
+       CALL init_surfaces
+!
+!--    When reading data for cyclic fill of 3D prerun data files, read some of the global variables
+!--    from the restart file which are required for initializing the inflow
        IF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
 
@@ -1133,34 +1099,29 @@
 #endif
        ENDDO
-       
-       
+
+
        IF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
 
 !
-!--       In case of cyclic fill, call init_surfaces a second time, so that 
-!--       surface properties such as heat fluxes are initialized as prescribed. 
+!--       In case of cyclic fill, call init_surfaces a second time, so that surface properties such
+!--       as heat fluxes are initialized as prescribed.
           CALL init_surfaces
 
 !
-!--       Overwrite u_init, v_init, pt_init, q_init and s_init with the
-!--       horizontally mean (hom) vertical profiles from the end
-!--       of the prerun, because these profiles shall be used as the reference
-!--       state for the rayleigh damping and the pt_damping. This is especially
-!--       important for the use of large_scale_subsidence, because the
-!--       reference temperature in the free atmosphere changes in time.
+!--       Overwrite u_init, v_init, pt_init, q_init and s_init with the horizontally mean (hom)
+!--       vertical profiles from the end of the prerun, because these profiles shall be used as the
+!--       reference state for the rayleigh damping and the pt_damping. This is especially important
+!--       for the use of large_scale_subsidence, because the reference temperature in the free
+!--       atmosphere changes in time.
           u_init(:) = hom_sum(:,1,0)
           v_init(:) = hom_sum(:,2,0)
           pt_init(:) = hom_sum(:,4,0)
-          IF ( humidity )                                                      &
-             q_init(:) = hom_sum(:,41,0)
-          IF ( passive_scalar )                                                &
-             s_init(:) = hom_sum(:,115,0)
-       ENDIF
-!
-!--    In case of complex terrain and cyclic fill method as initialization,
-!--    shift initial data in the vertical direction for each point in the 
-!--    x-y-plane depending on local surface height
-       IF ( complex_terrain  .AND.                                             &
-            TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
+          IF ( humidity )  q_init(:) = hom_sum(:,41,0)
+          IF ( passive_scalar )  s_init(:) = hom_sum(:,115,0)
+       ENDIF
+!
+!--    In case of complex terrain and cyclic fill method as initialization, shift initial data in
+!--    the vertical direction for each point in the x-y-plane depending on local surface height.
+       IF ( complex_terrain  .AND.  TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
           DO  i = nxlg, nxrg
              DO  j = nysg, nyng
@@ -1170,5 +1131,5 @@
                 nz_s_shift = topo_top_ind(j,i,0)
 
-                u(nz_u_shift:nzt+1,j,i)  = u(0:nzt+1-nz_u_shift,j,i)                
+                u(nz_u_shift:nzt+1,j,i)  = u(0:nzt+1-nz_u_shift,j,i)
 
                 v(nz_v_shift:nzt+1,j,i)  = v(0:nzt+1-nz_v_shift,j,i)
@@ -1183,11 +1144,9 @@
 !
 !--    Initialization of the turbulence recycling method
-       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.               &
-            turbulent_inflow )  THEN
+       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.  turbulent_inflow )  THEN
 !
 !--       First store the profiles to be used at the inflow.
-!--       These profiles are the (temporally) and horizontally averaged vertical
-!--       profiles from the prerun. Alternatively, prescribed profiles
-!--       for u,v-components can be used. 
+!--       These profiles are the (temporally) and horizontally averaged vertical profiles from the
+!--       prerun. Alternatively, prescribed profiles for u,v-components can be used.
           ALLOCATE( mean_inflow_profiles(nzb:nzt+1,1:num_mean_inflow_profiles) )
 
@@ -1200,14 +1159,12 @@
           ENDIF
           mean_inflow_profiles(:,4) = hom_sum(:,4,0)       ! pt
-          IF ( humidity )                                                      &
-             mean_inflow_profiles(:,6) = hom_sum(:,41,0)   ! q
-          IF ( passive_scalar )                                                &
-             mean_inflow_profiles(:,7) = hom_sum(:,115,0)   ! s
-
-!
-!--       In case of complex terrain, determine vertical displacement at inflow 
-!--       boundary and adjust mean inflow profiles
+          IF ( humidity )  mean_inflow_profiles(:,6) = hom_sum(:,41,0)          ! q
+          IF ( passive_scalar )  mean_inflow_profiles(:,7) = hom_sum(:,115,0)   ! s
+
+!
+!--       In case of complex terrain, determine vertical displacement at inflow boundary and adjust
+!--       mean inflow profiles
           IF ( complex_terrain )  THEN
-             IF ( nxlg <= 0 .AND. nxrg >= 0 .AND. nysg <= 0 .AND. nyng >= 0 )  THEN
+             IF ( nxlg <= 0  .AND.  nxrg >= 0  .AND.  nysg <= 0  .AND.  nyng >= 0 )  THEN
                 nz_u_shift_l = topo_top_ind(j,i,1)
                 nz_v_shift_l = topo_top_ind(j,i,2)
@@ -1222,12 +1179,8 @@
 
 #if defined( __parallel )
-             CALL MPI_ALLREDUCE(nz_u_shift_l, nz_u_shift, 1, MPI_INTEGER,      &
-                                MPI_MAX, comm2d, ierr)
-             CALL MPI_ALLREDUCE(nz_v_shift_l, nz_v_shift, 1, MPI_INTEGER,      &
-                                MPI_MAX, comm2d, ierr)
-             CALL MPI_ALLREDUCE(nz_w_shift_l, nz_w_shift, 1, MPI_INTEGER,      & 
-                                MPI_MAX, comm2d, ierr)
-             CALL MPI_ALLREDUCE(nz_s_shift_l, nz_s_shift, 1, MPI_INTEGER,      &
-                                MPI_MAX, comm2d, ierr)
+             CALL MPI_ALLREDUCE( nz_u_shift_l, nz_u_shift, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr )
+             CALL MPI_ALLREDUCE( nz_v_shift_l, nz_v_shift, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr )
+             CALL MPI_ALLREDUCE( nz_w_shift_l, nz_w_shift, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr )
+             CALL MPI_ALLREDUCE( nz_s_shift_l, nz_s_shift, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr )
 #else
              nz_u_shift = nz_u_shift_l
@@ -1248,6 +1201,5 @@
 
 !
-!--       If necessary, adjust the horizontal flow field to the prescribed
-!--       profiles
+!--       If necessary, adjust the horizontal flow field to the prescribed profiles
           IF ( use_prescribed_profile_data )  THEN
              DO  i = nxlg, nxrg
@@ -1262,6 +1214,5 @@
 
 !
-!--       Use these mean profiles at the inflow (provided that Dirichlet
-!--       conditions are used)
+!--       Use these mean profiles at the inflow (provided that Dirichlet conditions are used)
           IF ( bc_dirichlet_l )  THEN
              DO  j = nysg, nyng
@@ -1271,8 +1222,6 @@
                    w(k,j,nxlg:-1)  = 0.0_wp
                    pt(k,j,nxlg:-1) = mean_inflow_profiles(k,4)
-                   IF ( humidity )                                             &
-                      q(k,j,nxlg:-1)  = mean_inflow_profiles(k,6)
-                   IF ( passive_scalar )                                       &
-                      s(k,j,nxlg:-1)  = mean_inflow_profiles(k,7)                      
+                   IF ( humidity )  q(k,j,nxlg:-1)  = mean_inflow_profiles(k,6)
+                   IF ( passive_scalar )  s(k,j,nxlg:-1)  = mean_inflow_profiles(k,7)
                 ENDDO
              ENDDO
@@ -1280,19 +1229,17 @@
 
 !
-!--       Calculate the damping factors to be used at the inflow. For a
-!--       turbulent inflow the turbulent fluctuations have to be limited
-!--       vertically because otherwise the turbulent inflow layer will grow
-!--       in time.
+!--       Calculate the damping factors to be used at the inflow. For a turbulent inflow the
+!--       turbulent fluctuations have to be limited vertically because otherwise the turbulent
+!--       inflow layer will grow in time.
           IF ( inflow_damping_height == 9999999.9_wp )  THEN
 !
-!--          Default: use the inversion height calculated by the prerun; if
-!--          this is zero, inflow_damping_height must be explicitly
-!--          specified.
+!--          Default: use the inversion height calculated by the prerun; if this is zero,
+!--          inflow_damping_height must be explicitly specified.
              IF ( hom_sum(nzb+6,pr_palm,0) /= 0.0_wp )  THEN
                 inflow_damping_height = hom_sum(nzb+6,pr_palm,0)
              ELSE
-                WRITE( message_string, * ) 'inflow_damping_height must be ',   &
-                     'explicitly specified because&the inversion height ',     &
-                     'calculated by the prerun is zero.'
+                WRITE( message_string, * ) 'inflow_damping_height must be ',                       &
+                                           'explicitly specified because&the inversion height ',   &
+                                           'calculated by the prerun is zero.'
                 CALL message( 'init_3d_model', 'PA0318', 1, 2, 0, 6, 0 )
              ENDIF
@@ -1302,6 +1249,5 @@
           IF ( inflow_damping_width == 9999999.9_wp )  THEN
 !
-!--          Default for the transition range: one tenth of the undamped
-!--          layer
+!--          Default for the transition range: one tenth of the undamped layer
              inflow_damping_width = 0.1_wp * inflow_damping_height
 
@@ -1315,7 +1261,6 @@
                 inflow_damping_factor(k) = 1.0_wp
              ELSEIF ( zu(k) <= ( inflow_damping_height + inflow_damping_width ) )  THEN
-                inflow_damping_factor(k) = 1.0_wp -                            &
-                                           ( zu(k) - inflow_damping_height ) / &
-                                           inflow_damping_width
+                inflow_damping_factor(k) = 1.0_wp -                                                &
+                                           ( zu(k) - inflow_damping_height ) / inflow_damping_width
              ELSE
                 inflow_damping_factor(k) = 0.0_wp
@@ -1328,6 +1273,5 @@
 !
 !--    Inside buildings set velocities back to zero
-       IF ( TRIM( initializing_actions ) == 'cyclic_fill' .AND.                &
-            topography /= 'flat' )  THEN
+       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.  topography /= 'flat' )  THEN
 !
 !--       Inside buildings set velocities back to zero.
@@ -1337,10 +1281,7 @@
              DO  j = nysg, nyng
                 DO  k = nzb, nzt
-                   u(k,j,i)     = MERGE( u(k,j,i), 0.0_wp,                     &
-                                      BTEST( wall_flags_total_0(k,j,i), 1 ) )
-                   v(k,j,i)     = MERGE( v(k,j,i), 0.0_wp,                     &
-                                      BTEST( wall_flags_total_0(k,j,i), 2 ) )
-                   w(k,j,i)     = MERGE( w(k,j,i), 0.0_wp,                     &
-                                      BTEST( wall_flags_total_0(k,j,i), 3 ) )
+                   u(k,j,i) = MERGE( u(k,j,i), 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 1 ) )
+                   v(k,j,i) = MERGE( v(k,j,i), 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 2 ) )
+                   w(k,j,i) = MERGE( w(k,j,i), 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 3 ) )
                 ENDDO
              ENDDO
@@ -1350,11 +1291,9 @@
 
 !
-!--    Calculate initial temperature field and other constants used in case
-!--    of a sloping surface
+!--    Calculate initial temperature field and other constants used in case of a sloping surface
        IF ( sloping_surface )  CALL init_slope
 
 !
-!--    Initialize new time levels (only done in order to set boundary values
-!--    including ghost points)
+!--    Initialize new time levels (only done in order to set boundary values including ghost points)
        pt_p = pt; u_p = u; v_p = v; w_p = w
        IF ( humidity )  THEN
@@ -1363,7 +1302,6 @@
        IF ( passive_scalar )  s_p  = s
 !
-!--    Allthough tendency arrays are set in prognostic_equations, they have
-!--    have to be predefined here because they are used (but multiplied with 0)
-!--    there before they are set. 
+!--    Allthough tendency arrays are set in prognostic_equations, they have have to be predefined
+!--    here because they are used (but multiplied with 0) there before they are set.
        tpt_m = 0.0_wp; tu_m = 0.0_wp; tv_m = 0.0_wp; tw_m = 0.0_wp
        IF ( humidity )  THEN
@@ -1372,5 +1310,7 @@
        IF ( passive_scalar )  ts_m  = 0.0_wp
 
-       IF ( debug_output )  CALL debug_message( 'initializing in case of restart / cyclic_fill', 'end' )
+       IF ( debug_output )  THEN
+          CALL debug_message( 'initializing in case of restart / cyclic_fill', 'end' )
+       ENDIF
 
     ELSE
@@ -1405,5 +1345,5 @@
           w_m_n(:,:,:) = w(:,ny-1:ny,:)
        ENDIF
-       
+
     ENDIF
 
@@ -1420,30 +1360,30 @@
              DO  j = nys, nyn
                 DO  k = nzb+1, nzt
-                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +         &
-                                              u_init(k) * dzw(k)                 &
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,j,nxr), 1 )&
-                                            )
-
-                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)     &
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,j,nxr), 1 )&
-                                            )
+                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +                           &
+                                              u_init(k) * dzw(k)                                   &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                       BTEST( wall_flags_total_0(k,j,nxr), 1 )     &
+                                                     )
+
+                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)                       &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                       BTEST( wall_flags_total_0(k,j,nxr), 1 )     &
+                                                     )
                 ENDDO
              ENDDO
           ENDIF
-          
+
           IF ( nyn == ny )  THEN
              DO  i = nxl, nxr
                 DO  k = nzb+1, nzt
-                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +         &
-                                              v_init(k) * dzw(k)                 &        
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,nyn,i), 2 )&
-                                            )
-                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)     &        
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,nyn,i), 2 )&
-                                            )
+                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +                           &
+                                              v_init(k) * dzw(k)                                   &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                       BTEST( wall_flags_total_0(k,nyn,i), 2 )     &
+                                                     )
+                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)                       &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                       BTEST( wall_flags_total_0(k,nyn,i), 2 )     &
+                                                     )
                 ENDDO
              ENDDO
@@ -1451,13 +1391,13 @@
 
 #if defined( __parallel )
-          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
-                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
-          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
-                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1), 2, MPI_REAL,       &
+                              MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1), 2, MPI_REAL, MPI_SUM,    &
+                              comm2d, ierr )
 
 #else
           volume_flow_initial = volume_flow_initial_l
           volume_flow_area    = volume_flow_area_l
-#endif  
+#endif
 
        ELSEIF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
@@ -1469,29 +1409,29 @@
              DO  j = nys, nyn
                 DO  k = nzb+1, nzt
-                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +         &
-                                              hom_sum(k,1,0) * dzw(k)            &
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,j,nx), 1 ) &
-                                            )
-                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)     &
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,j,nx), 1 ) &
-                                            )
+                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +                           &
+                                              hom_sum(k,1,0) * dzw(k)                              &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                       BTEST( wall_flags_total_0(k,j,nx), 1 )      &
+                                                     )
+                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)                       &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                       BTEST( wall_flags_total_0(k,j,nx), 1 )      &
+                                                     )
                 ENDDO
              ENDDO
           ENDIF
-          
+
           IF ( nyn == ny )  THEN
              DO  i = nxl, nxr
                 DO  k = nzb+1, nzt
-                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +         &
-                                              hom_sum(k,2,0) * dzw(k)            &        
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,ny,i), 2 ) &
-                                            )
-                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)     &        
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,ny,i), 2 ) &
-                                            )
+                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +                           &
+                                              hom_sum(k,2,0) * dzw(k)                              &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                       BTEST( wall_flags_total_0(k,ny,i), 2 )      &
+                                                     )
+                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)                       &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                       BTEST( wall_flags_total_0(k,ny,i), 2 )      &
+                                                     )
                 ENDDO
              ENDDO
@@ -1499,13 +1439,13 @@
 
 #if defined( __parallel )
-          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
-                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
-          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
-                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1), 2, MPI_REAL,       &
+                              MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1), 2, MPI_REAL, MPI_SUM,    &
+                              comm2d, ierr )
 
 #else
           volume_flow_initial = volume_flow_initial_l
           volume_flow_area    = volume_flow_area_l
-#endif  
+#endif
 
        ELSEIF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
@@ -1517,29 +1457,29 @@
              DO  j = nys, nyn
                 DO  k = nzb+1, nzt
-                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +         &
-                                              u(k,j,nx) * dzw(k)                 &
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,j,nx), 1 ) &
-                                            )
-                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)     &
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,j,nx), 1 ) &
-                                            )
+                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +                           &
+                                              u(k,j,nx) * dzw(k)                                   &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                       BTEST( wall_flags_total_0(k,j,nx), 1 )      &
+                                                     )
+                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)                       &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                   BTEST( wall_flags_total_0(k,j,nx), 1 )          &
+                                                     )
                 ENDDO
              ENDDO
           ENDIF
-          
+
           IF ( nyn == ny )  THEN
              DO  i = nxl, nxr
                 DO  k = nzb+1, nzt
-                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +         &
-                                              v(k,ny,i) * dzw(k)                 &        
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,ny,i), 2 ) &
-                                            )
-                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)     &        
-                                     * MERGE( 1.0_wp, 0.0_wp,                    &
-                                          BTEST( wall_flags_total_0(k,ny,i), 2 ) &
-                                            )
+                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +                           &
+                                              v(k,ny,i) * dzw(k)                                   &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                       BTEST( wall_flags_total_0(k,ny,i), 2 )      &
+                                                     )
+                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)                       &
+                                              * MERGE( 1.0_wp, 0.0_wp,                             &
+                                                       BTEST( wall_flags_total_0(k,ny,i), 2 )      &
+                                                     )
                 ENDDO
              ENDDO
@@ -1547,19 +1487,18 @@
 
 #if defined( __parallel )
-          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
-                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
-          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
-                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1), 2, MPI_REAL,       &
+                              MPI_SUM, comm2d, ierr )
+          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1), 2, MPI_REAL, MPI_SUM,    &
+                              comm2d, ierr )
 
 #else
           volume_flow_initial = volume_flow_initial_l
           volume_flow_area    = volume_flow_area_l
-#endif  
-
-       ENDIF
-
-!
-!--    In case of 'bulk_velocity' mode, volume_flow_initial is calculated
-!--    from u|v_bulk instead
+#endif
+
+       ENDIF
+
+!
+!--    In case of 'bulk_velocity' mode, volume_flow_initial is calculated from u|v_bulk instead
        IF ( TRIM( conserve_volume_flow_mode ) == 'bulk_velocity' )  THEN
           volume_flow_initial(1) = u_bulk * volume_flow_area(1)
@@ -1569,10 +1508,9 @@
     ENDIF
 !
-!-- In the following, surface properties can be further initialized with
-!-- input from static driver file.
-!-- At the moment this affects only default surfaces. For example, 
-!-- roughness length or sensible / latent heat fluxes can be initialized
-!-- heterogeneously for default surfaces. Therefore, a generic routine
-!-- from netcdf_data_input_mod is called to read a 2D array.
+!-- In the following, surface properties can be further initialized with input from static driver
+!-- file.
+!-- At the moment this affects only default surfaces. For example, roughness length or sensible /
+!-- latent heat fluxes can be initialized heterogeneously for default surfaces. Therefore, a generic
+!-- routine from netcdf_data_input_mod is called to read a 2D array.
     IF ( input_pids_static )  THEN
 !
@@ -1583,8 +1521,7 @@
 !--    Open the static input file
 #if defined( __netcdf )
-       CALL open_read_file( TRIM( input_file_static ) //                    &
-                            TRIM( coupling_char ),                          &
-                            pids_id )
-                            
+       CALL open_read_file( TRIM( input_file_static ) //                                           &
+                            TRIM( coupling_char ), pids_id )
+
        CALL inquire_num_variables( pids_id, num_var_pids )
 !
@@ -1593,81 +1530,57 @@
        CALL inquire_variable_names( pids_id, vars_pids )
 !
-!--    Input roughness length. 
+!--    Input roughness length.
        IF ( check_existence( vars_pids, 'z0' ) )  THEN
 !
 !--       Read _FillValue attribute
-          CALL get_attribute( pids_id, char_fill, tmp_2d%fill,          &
-                              .FALSE., 'z0' )                                  
-!                                                                              
-!--       Read variable                                                        
-          CALL get_variable( pids_id, 'z0', tmp_2d%var,                 &
-                             nxl, nxr, nys, nyn )                              
-!                                                                              
-!--       Initialize roughness length. Note, z0 will be only initialized at    
-!--       default-type surfaces. At natural or urban z0 is implicitly          
-!--       initialized by the respective parameter lists.                        
-!--       Initialize horizontal surface elements.                              
-          CALL init_single_surface_properties( surf_def_h(0)%z0,               &
-                                               tmp_2d%var,                     &
-                                               surf_def_h(0)%ns,               &
-                                               tmp_2d%fill,                    &
-                                               surf_def_h(0)%i,                &
-                                               surf_def_h(0)%j )               
-!                                                                              
-!--       Initialize roughness also at vertical surface elements.              
-!--       Note, the actual 2D input arrays are only defined on the             
-!--       subdomain. Therefore, pass the index arrays with their respective    
-!--       offset values.                                                       
-          DO  l = 0, 3                                                         
-             CALL init_single_surface_properties(                              &
-                                         surf_def_v(l)%z0,                     &
-                                         tmp_2d%var,                           &
-                                         surf_def_v(l)%ns,                     &
-                                         tmp_2d%fill,                          &
-                                         surf_def_v(l)%i + surf_def_v(l)%ioff, &
-                                         surf_def_v(l)%j + surf_def_v(l)%joff )
+          CALL get_attribute( pids_id, char_fill, tmp_2d%fill, .FALSE., 'z0' )
+!
+!--       Read variable
+          CALL get_variable( pids_id, 'z0', tmp_2d%var, nxl, nxr, nys, nyn )
+!
+!--       Initialize roughness length. Note, z0 will be only initialized at default-type surfaces.
+!--       At natural or urban z0 is implicitly initialized by the respective parameter lists.
+!--       Initialize horizontal surface elements.
+          CALL init_single_surface_properties( surf_def_h(0)%z0, tmp_2d%var, surf_def_h(0)%ns,     &
+                                               tmp_2d%fill, surf_def_h(0)%i, surf_def_h(0)%j )
+!
+!--       Initialize roughness also at vertical surface elements.
+!--       Note, the actual 2D input arrays are only defined on the subdomain. Therefore, pass the
+!--       index arrays with their respective offset values.
+          DO  l = 0, 3
+             CALL init_single_surface_properties( surf_def_v(l)%z0, tmp_2d%var, surf_def_v(l)%ns,  &
+                                                  tmp_2d%fill, surf_def_v(l)%i+surf_def_v(l)%ioff, &
+                                                  surf_def_v(l)%j+surf_def_v(l)%joff )
           ENDDO
-          
-       ENDIF
-!
-!--    Input surface sensible heat flux. 
+
+       ENDIF
+!
+!--    Input surface sensible heat flux.
        IF ( check_existence( vars_pids, 'shf' ) )  THEN
 !
 !--       Read _FillValue attribute
-          CALL get_attribute( pids_id, char_fill, tmp_2d%fill,                 &
-                              .FALSE., 'shf' )
+          CALL get_attribute( pids_id, char_fill, tmp_2d%fill, .FALSE., 'shf' )
 !
 !--       Read variable
-          CALL get_variable( pids_id, 'shf', tmp_2d%var,                       &
-                             nxl, nxr, nys, nyn )
-!
-!--       Initialize heat flux. Note, shf will be only initialized at
-!--       default-type surfaces. At natural or urban shf is implicitly
-!--       initialized by the respective parameter lists.
+          CALL get_variable( pids_id, 'shf', tmp_2d%var, nxl, nxr, nys, nyn )
+!
+!--       Initialize heat flux. Note, shf will be only initialized at default-type surfaces. At
+!--       natural or urban shf is implicitly initialized by the respective parameter lists.
 !--       Initialize horizontal surface elements.
-          CALL init_single_surface_properties( surf_def_h(0)%shf,              &
-                                               tmp_2d%var,                     &
-                                               surf_def_h(0)%ns,               &
-                                               tmp_2d%fill,                    &
-                                               surf_def_h(0)%i,                &
-                                               surf_def_h(0)%j )
+          CALL init_single_surface_properties( surf_def_h(0)%shf, tmp_2d%var, surf_def_h(0)%ns,    &
+                                               tmp_2d%fill, surf_def_h(0)%i, surf_def_h(0)%j )
 !
 !--       Initialize heat flux also at vertical surface elements.
-!--       Note, the actual 2D input arrays are only defined on the
-!--       subdomain. Therefore, pass the index arrays with their respective
-!--       offset values.
+!--       Note, the actual 2D input arrays are only defined on the subdomain. Therefore, pass the
+!--       index arrays with their respective offset values.
           DO  l = 0, 3
-             CALL init_single_surface_properties(                              &
-                                         surf_def_v(l)%shf,                    &
-                                         tmp_2d%var,                           &
-                                         surf_def_v(l)%ns,                     &
-                                         tmp_2d%fill,                          &
-                                         surf_def_v(l)%i + surf_def_v(l)%ioff, &
-                                         surf_def_v(l)%j + surf_def_v(l)%joff )
+             CALL init_single_surface_properties( surf_def_v(l)%shf, tmp_2d%var, surf_def_v(l)%ns, &
+                                                  tmp_2d%fill, surf_def_v(l)%i+surf_def_v(l)%ioff, &
+                                                  surf_def_v(l)%j+surf_def_v(l)%joff )
           ENDDO
 
        ENDIF
 !
-!--    Input surface sensible heat flux. 
+!--    Input surface sensible heat flux.
        IF ( check_existence( vars_pids, 'qsws' ) )  THEN
 !
@@ -1680,32 +1593,22 @@
                              nxl, nxr, nys, nyn )
 !
-!--       Initialize latent heat flux. Note, qsws will be only initialized at
-!--       default-type surfaces. At natural or urban qsws is implicitly
-!--       initialized by the respective parameter lists.
+!--       Initialize latent heat flux. Note, qsws will be only initialized at default-type surfaces.
+!--       At natural or urban qsws is implicitly initialized by the respective parameter lists.
 !--       Initialize horizontal surface elements.
-          CALL init_single_surface_properties( surf_def_h(0)%qsws,             &
-                                               tmp_2d%var,                     &
-                                               surf_def_h(0)%ns,               &
-                                               tmp_2d%fill,                    &
-                                               surf_def_h(0)%i,                &
-                                               surf_def_h(0)%j )
+          CALL init_single_surface_properties( surf_def_h(0)%qsws, tmp_2d%var, surf_def_h(0)%ns,   &
+                                               tmp_2d%fill, surf_def_h(0)%i, surf_def_h(0)%j )
 !
 !--       Initialize latent heat flux also at vertical surface elements.
-!--       Note, the actual 2D input arrays are only defined on the
-!--       subdomain. Therefore, pass the index arrays with their respective
-!--       offset values.
+!--       Note, the actual 2D input arrays are only defined on the subdomain. Therefore, pass the
+!--       index arrays with their respective offset values.
           DO  l = 0, 3
-             CALL init_single_surface_properties(                              &
-                                         surf_def_v(l)%qsws,                   &
-                                         tmp_2d%var,                           &
-                                         surf_def_v(l)%ns,                     &
-                                         tmp_2d%fill,                          &
-                                         surf_def_v(l)%i + surf_def_v(l)%ioff, &
-                                         surf_def_v(l)%j + surf_def_v(l)%joff )
+             CALL init_single_surface_properties( surf_def_v(l)%qsws, tmp_2d%var, surf_def_v(l)%ns,&
+                                                  tmp_2d%fill, surf_def_v(l)%i+surf_def_v(l)%ioff, &
+                                                  surf_def_v(l)%j+surf_def_v(l)%joff )
           ENDDO
 
        ENDIF
 !
-!--    Additional variables, can be initialized the 
+!--    Additional variables, can be initialized the
 !--    same way.
 
@@ -1713,5 +1616,5 @@
 !--    Finally, close the input file and deallocate temporary arrays
        DEALLOCATE( vars_pids )
-       
+
        CALL close_input_file( pids_id )
 #endif
@@ -1719,15 +1622,12 @@
     ENDIF
 !
-!-- Finally, if random_heatflux is set, disturb shf at horizontal
-!-- surfaces. Actually, this should be done in surface_mod, where all other 
-!-- initializations of surface quantities are done. However, this
-!-- would create a ring dependency, hence, it is done here. Maybe delete
-!-- disturb_heatflux and tranfer the respective code directly into the 
-!-- initialization in surface_mod.         
-    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
+!-- Finally, if random_heatflux is set, disturb shf at horizontal surfaces. Actually, this should be
+!-- done in surface_mod, where all other initializations of surface quantities are done. However,
+!-- this would create a ring dependency, hence, it is done here. Maybe delete disturb_heatflux and
+!-- tranfer the respective code directly into the initialization in surface_mod.
+    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.                                &
          TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
- 
-       IF ( use_surface_fluxes  .AND.  constant_heatflux  .AND.                &
-            random_heatflux )  THEN
+
+       IF ( use_surface_fluxes  .AND.  constant_heatflux  .AND.  random_heatflux )  THEN
           IF ( surf_def_h(0)%ns >= 1 )  CALL disturb_heatflux( surf_def_h(0) )
           IF ( surf_lsm_h%ns    >= 1 )  CALL disturb_heatflux( surf_lsm_h    )
@@ -1737,9 +1637,8 @@
 
 !
-!-- Compute total sum of grid points and the mean surface level height for each
-!-- statistic region. These are mainly used for horizontal averaging of
-!-- turbulence statistics.
-!-- ngp_2dh: number of grid points of a horizontal cross section through the
-!--          respective statistic region
+!-- Compute total sum of grid points and the mean surface level height for each statistic region.
+!-- These are mainly used for horizontal averaging of turbulence statistics.
+!-- ngp_2dh: number of grid points of a horizontal cross section through the respective statistic
+!--          region
 !-- ngp_3d:  number of grid points of the respective statistic region
     ngp_2dh_outer_l   = 0
@@ -1766,27 +1665,21 @@
                 ngp_2dh_l(sr) = ngp_2dh_l(sr) + 1
 !
-!--             Determine mean surface-level height. In case of downward-
-!--             facing walls are present, more than one surface level exist.
-!--             In this case, use the lowest surface-level height. 
-                IF ( surf_def_h(0)%start_index(j,i) <=                         &
-                     surf_def_h(0)%end_index(j,i) )  THEN
+!--             Determine mean surface-level height. In case of downward-facing walls are present,
+!--             more than one surface level exist.
+!--             In this case, use the lowest surface-level height.
+                IF ( surf_def_h(0)%start_index(j,i) <= surf_def_h(0)%end_index(j,i) )  THEN
                    m = surf_def_h(0)%start_index(j,i)
                    k = surf_def_h(0)%k(m)
-                   mean_surface_level_height_l(sr) =                           &
-                                       mean_surface_level_height_l(sr) + zw(k-1)
+                   mean_surface_level_height_l(sr) = mean_surface_level_height_l(sr) + zw(k-1)
                 ENDIF
-                IF ( surf_lsm_h%start_index(j,i) <=                            &
-                     surf_lsm_h%end_index(j,i) )  THEN
+                IF ( surf_lsm_h%start_index(j,i) <= surf_lsm_h%end_index(j,i) )  THEN
                    m = surf_lsm_h%start_index(j,i)
                    k = surf_lsm_h%k(m)
-                   mean_surface_level_height_l(sr) =                           &
-                                       mean_surface_level_height_l(sr) + zw(k-1)
+                   mean_surface_level_height_l(sr) = mean_surface_level_height_l(sr) + zw(k-1)
                 ENDIF
-                IF ( surf_usm_h%start_index(j,i) <=                            &
-                     surf_usm_h%end_index(j,i) )  THEN
+                IF ( surf_usm_h%start_index(j,i) <= surf_usm_h%end_index(j,i) )  THEN
                    m = surf_usm_h%start_index(j,i)
                    k = surf_usm_h%k(m)
-                   mean_surface_level_height_l(sr) =                           &
-                                       mean_surface_level_height_l(sr) + zw(k-1)
+                   mean_surface_level_height_l(sr) = mean_surface_level_height_l(sr) + zw(k-1)
                 ENDIF
 
@@ -1796,9 +1689,9 @@
 !
 !--                xy-grid points above topography
-                   ngp_2dh_outer_l(k,sr) = ngp_2dh_outer_l(k,sr)     +         &
-                             MERGE( 1, 0, BTEST( wall_flags_total_0(k,j,i), 24 ) )
-
-                   ngp_2dh_s_inner_l(k,sr) = ngp_2dh_s_inner_l(k,sr) +         &
-                             MERGE( 1, 0, BTEST( wall_flags_total_0(k,j,i), 22 ) )
+                   ngp_2dh_outer_l(k,sr) = ngp_2dh_outer_l(k,sr)     +                             &
+                                           MERGE( 1, 0, BTEST( wall_flags_total_0(k,j,i), 24 ) )
+
+                   ngp_2dh_s_inner_l(k,sr) = ngp_2dh_s_inner_l(k,sr) +                             &
+                                             MERGE( 1, 0, BTEST( wall_flags_total_0(k,j,i), 22 ) )
 
                 ENDDO
@@ -1817,19 +1710,17 @@
 #if defined( __parallel )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( ngp_2dh_l(0), ngp_2dh(0), sr, MPI_INTEGER, MPI_SUM,    &
+    CALL MPI_ALLREDUCE( ngp_2dh_l(0), ngp_2dh(0), sr, MPI_INTEGER, MPI_SUM, comm2d, ierr )
+    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
+    CALL MPI_ALLREDUCE( ngp_2dh_outer_l(0,0), ngp_2dh_outer(0,0), (nz+2)*sr, MPI_INTEGER, MPI_SUM, &
                         comm2d, ierr )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( ngp_2dh_outer_l(0,0), ngp_2dh_outer(0,0), (nz+2)*sr,   &
-                        MPI_INTEGER, MPI_SUM, comm2d, ierr )
+    CALL MPI_ALLREDUCE( ngp_2dh_s_inner_l(0,0), ngp_2dh_s_inner(0,0), (nz+2)*sr, MPI_INTEGER,      &
+                        MPI_SUM, comm2d, ierr )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( ngp_2dh_s_inner_l(0,0), ngp_2dh_s_inner(0,0),          &
-                        (nz+2)*sr, MPI_INTEGER, MPI_SUM, comm2d, ierr )
-    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( ngp_3d_inner_l(0), ngp_3d_inner_tmp(0), sr, MPI_REAL,  &
-                        MPI_SUM, comm2d, ierr )
+    CALL MPI_ALLREDUCE( ngp_3d_inner_l(0), ngp_3d_inner_tmp(0), sr, MPI_REAL, MPI_SUM, comm2d,     &
+                        ierr )
     ngp_3d_inner = INT( ngp_3d_inner_tmp, KIND = SELECTED_INT_KIND( 18 ) )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( mean_surface_level_height_l(0),                        &
-                        mean_surface_level_height(0), sr, MPI_REAL,            &
+    CALL MPI_ALLREDUCE( mean_surface_level_height_l(0), mean_surface_level_height(0), sr, MPI_REAL,&
                         MPI_SUM, comm2d, ierr )
     mean_surface_level_height = mean_surface_level_height / REAL( ngp_2dh )
@@ -1842,21 +1733,20 @@
 #endif
 
-    ngp_3d = INT ( ngp_2dh, KIND = SELECTED_INT_KIND( 18 ) ) * &
+    ngp_3d = INT ( ngp_2dh, KIND = SELECTED_INT_KIND( 18 ) ) *                                     &
              INT ( (nz + 2 ), KIND = SELECTED_INT_KIND( 18 ) )
 
 !
-!-- Set a lower limit of 1 in order to avoid zero divisions in flow_statistics,
-!-- buoyancy, etc. A zero value will occur for cases where all grid points of
-!-- the respective subdomain lie below the surface topography
-    ngp_2dh_outer   = MAX( 1, ngp_2dh_outer(:,:)   ) 
-    ngp_3d_inner    = MAX( INT(1, KIND = SELECTED_INT_KIND( 18 )),             &
-                           ngp_3d_inner(:) )
-    ngp_2dh_s_inner = MAX( 1, ngp_2dh_s_inner(:,:) ) 
-
-    DEALLOCATE( mean_surface_level_height_l, ngp_2dh_l, ngp_2dh_outer_l,       &
-                ngp_3d_inner_l, ngp_3d_inner_tmp )
-
-!
-!-- Initializae 3D offline nesting in COSMO model and read data from 
+!-- Set a lower limit of 1 in order to avoid zero divisions in flow_statistics, buoyancy, etc. A
+!-- zero value will occur for cases where all grid points of the respective subdomain lie below the
+!-- surface topography
+    ngp_2dh_outer   = MAX( 1, ngp_2dh_outer(:,:)   )
+    ngp_3d_inner    = MAX( INT(1, KIND = SELECTED_INT_KIND( 18 )), ngp_3d_inner(:) )
+    ngp_2dh_s_inner = MAX( 1, ngp_2dh_s_inner(:,:) )
+
+    DEALLOCATE( mean_surface_level_height_l, ngp_2dh_l, ngp_2dh_outer_l, ngp_3d_inner_l,           &
+                ngp_3d_inner_tmp )
+
+!
+!-- Initializae 3D offline nesting in COSMO model and read data from
 !-- external NetCDF file.
     IF ( nesting_offline )  CALL nesting_offl_init
@@ -1868,9 +1758,11 @@
 !-- Impose random perturbation on the horizontal velocity field and then
 !-- remove the divergences from the velocity field at the initial stage
-    IF ( create_disturbances  .AND.  disturbance_energy_limit /= 0.0_wp  .AND. &
-         TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
+    IF ( create_disturbances  .AND.  disturbance_energy_limit /= 0.0_wp  .AND.                     &
+         TRIM( initializing_actions ) /= 'read_restart_data'  .AND.                                &
          TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
 
-       IF ( debug_output )  CALL debug_message( 'creating disturbances + applying pressure solver', 'start' )
+       IF ( debug_output )  THEN
+          CALL debug_message( 'creating disturbances + applying pressure solver', 'start' )
+       ENDIF
 !
 !--    Needed for both disturb_field and pres
@@ -1905,5 +1797,7 @@
 !$ACC END DATA
 
-       IF ( debug_output )  CALL debug_message( 'creating disturbances + applying pressure solver', 'end' )
+       IF ( debug_output )  THEN
+          CALL debug_message( 'creating disturbances + applying pressure solver', 'end' )
+       ENDIF
 
     ENDIF
@@ -1918,7 +1812,7 @@
 !--    Check temperature in case of too large domain height
        DO  k = nzb, nzt+1
-          IF ( ( pt_surface * exner_function(surface_pressure * 100.0_wp) - g/c_p * zu(k) ) < 0.0_wp )  THEN
-             WRITE( message_string, * )  'absolute temperature < 0.0 at zu(', k, &
-                                         ') = ', zu(k)
+          IF ( ( pt_surface * exner_function( surface_pressure * 100.0_wp ) - g/c_p * zu(k) )      &
+                 < 0.0_wp )  THEN
+             WRITE( message_string, * )  'absolute temperature < 0.0 at zu(', k, ') = ', zu(k)
              CALL message( 'init_3d_model', 'PA0142', 1, 2, 0, 6, 0 )
           ENDIF
@@ -1927,11 +1821,13 @@
 !
 !--    Calculate vertical profile of the hydrostatic pressure (hyp)
-       hyp    = barometric_formula(zu, pt_surface * exner_function(surface_pressure * 100.0_wp), surface_pressure * 100.0_wp)
-       d_exner = exner_function_invers(hyp)
-       exner = 1.0_wp / exner_function_invers(hyp)
-       hyrho  = ideal_gas_law_rho_pt(hyp, pt_init)
+       hyp    = barometric_formula( zu, pt_surface * exner_function( surface_pressure * 100.0_wp ),&
+                                    surface_pressure * 100.0_wp )
+       d_exner = exner_function_invers( hyp )
+       exner = 1.0_wp / exner_function_invers( hyp )
+       hyrho  = ideal_gas_law_rho_pt( hyp, pt_init )
 !
 !--    Compute reference density
-       rho_surface = ideal_gas_law_rho(surface_pressure * 100.0_wp, pt_surface * exner_function(surface_pressure * 100.0_wp))
+       rho_surface = ideal_gas_law_rho( surface_pressure * 100.0_wp,                               &
+                                        pt_surface * exner_function( surface_pressure * 100.0_wp ) )
 
     ENDIF
@@ -1947,6 +1843,5 @@
     CALL module_interface_init
 !
-!-- Initialize surface layer (done after LSM as roughness length are required
-!-- for initialization
+!-- Initialize surface layer (done after LSM as roughness length are required for initialization
     IF ( constant_flux_layer )  CALL init_surface_layer_fluxes
 !
@@ -1954,6 +1849,6 @@
     IF ( surface_output )  CALL surface_data_output_init
 !
-!-- Initialize the ws-scheme.    
-    IF ( ws_scheme_sca .OR. ws_scheme_mom )  CALL ws_init
+!-- Initialize the ws-scheme.
+    IF ( ws_scheme_sca  .OR.  ws_scheme_mom )  CALL ws_init
 !
 !-- Perform post-initializing checks for all other modules
@@ -1961,15 +1856,15 @@
 
 !
-!-- Initialize surface forcing corresponding to large-scale forcing. Therein, 
+!-- Initialize surface forcing corresponding to large-scale forcing. Therein,
 !-- initialize heat-fluxes, etc. via datatype. Revise it later!
-    IF ( large_scale_forcing .AND. lsf_surf )  THEN
+    IF ( large_scale_forcing  .AND.  lsf_surf )  THEN
        IF ( use_surface_fluxes  .AND.  constant_heatflux )  THEN
-          CALL ls_forcing_surf ( simulated_time )
-       ENDIF
-    ENDIF
-!
-!-- Setting weighting factors for calculation of perturbation pressure 
-!-- and turbulent quantities from the RK substeps
-    IF ( TRIM(timestep_scheme) == 'runge-kutta-3' )  THEN      ! for RK3-method
+          CALL ls_forcing_surf( simulated_time )
+       ENDIF
+    ENDIF
+!
+!-- Setting weighting factors for calculation of perturbation pressure and turbulent quantities from
+!-- the RK substeps.
+    IF ( TRIM( timestep_scheme ) == 'runge-kutta-3' )  THEN      ! for RK3-method
 
        weight_substep(1) = 1._wp/6._wp
@@ -1981,16 +1876,16 @@
        weight_pres(3)    = 1._wp/4._wp
 
-    ELSEIF ( TRIM(timestep_scheme) == 'runge-kutta-2' )  THEN  ! for RK2-method
+    ELSEIF ( TRIM( timestep_scheme ) == 'runge-kutta-2' )  THEN  ! for RK2-method
 
        weight_substep(1) = 1._wp/2._wp
        weight_substep(2) = 1._wp/2._wp
-          
+
        weight_pres(1)    = 1._wp/2._wp
-       weight_pres(2)    = 1._wp/2._wp        
+       weight_pres(2)    = 1._wp/2._wp
 
     ELSE                                     ! for Euler-method
 
-       weight_substep(1) = 1.0_wp      
-       weight_pres(1)    = 1.0_wp                   
+       weight_substep(1) = 1.0_wp
+       weight_pres(1)    = 1.0_wp
 
     ENDIF
@@ -2005,20 +1900,19 @@
           DO  k = nzb+1, nzt
              IF ( zu(k) >= rayleigh_damping_height )  THEN
-                rdf(k) = rayleigh_damping_factor *                             &
-                      ( SIN( pi * 0.5_wp * ( zu(k) - rayleigh_damping_height ) &
-                             / ( zu(nzt) - rayleigh_damping_height ) )         &
-                      )**2
+                rdf(k) = rayleigh_damping_factor *                                                 &
+                         ( SIN( pi * 0.5_wp * ( zu(k) - rayleigh_damping_height )                  &
+                                / ( zu(nzt) - rayleigh_damping_height ) )                          &
+                         )**2
              ENDIF
           ENDDO
        ELSE
 !
-!--       In ocean mode, rayleigh damping is applied in the lower part of the
-!--       model domain
+!--       In ocean mode, rayleigh damping is applied in the lower part of the model domain
           DO  k = nzt, nzb+1, -1
              IF ( zu(k) <= rayleigh_damping_height )  THEN
-                rdf(k) = rayleigh_damping_factor *                             &
-                      ( SIN( pi * 0.5_wp * ( rayleigh_damping_height - zu(k) ) &
-                             / ( rayleigh_damping_height - zu(nzb+1) ) )       &
-                      )**2
+                rdf(k) = rayleigh_damping_factor *                                                 &
+                         ( SIN( pi * 0.5_wp * ( rayleigh_damping_height - zu(k) )                  &
+                                / ( rayleigh_damping_height - zu(nzb+1) ) )                        &
+                         )**2
              ENDIF
           ENDDO
@@ -2029,14 +1923,13 @@
 
 !
-!-- Initialize the starting level and the vertical smoothing factor used for 
-!-- the external pressure gradient
+!-- Initialize the starting level and the vertical smoothing factor used for the external pressure
+!-- gradient
     dp_smooth_factor = 1.0_wp
     IF ( dp_external )  THEN
 !
-!--    Set the starting level dp_level_ind_b only if it has not been set before
-!--    (e.g. in init_grid).
+!--    Set the starting level dp_level_ind_b only if it has not been set before (e.g. in init_grid).
        IF ( dp_level_ind_b == 0 )  THEN
           ind_array = MINLOC( ABS( dp_level_b - zu ) )
-          dp_level_ind_b = ind_array(1) - 1 + nzb 
+          dp_level_ind_b = ind_array(1) - 1 + nzb
                                         ! MINLOC uses lower array bound 1
        ENDIF
@@ -2044,7 +1937,7 @@
           dp_smooth_factor(:dp_level_ind_b) = 0.0_wp
           DO  k = dp_level_ind_b+1, nzt
-             dp_smooth_factor(k) = 0.5_wp * ( 1.0_wp + SIN( pi *               &
-                        ( REAL( k - dp_level_ind_b, KIND=wp ) /                &
-                          REAL( nzt - dp_level_ind_b, KIND=wp ) - 0.5_wp ) ) )
+             dp_smooth_factor(k) = 0.5_wp * ( 1.0_wp + SIN( pi *                                   &
+                                             ( REAL( k - dp_level_ind_b, KIND=wp ) /               &
+                                               REAL( nzt - dp_level_ind_b, KIND=wp ) - 0.5_wp ) ) )
           ENDDO
        ENDIF
@@ -2052,7 +1945,7 @@
 
 !
-!-- Initialize damping zone for the potential temperature in case of
-!-- non-cyclic lateral boundaries. The damping zone has the maximum value 
-!-- at the inflow boundary and decreases to zero at pt_damping_width.
+!-- Initialize damping zone for the potential temperature in case of non-cyclic lateral boundaries.
+!-- The damping zone has the maximum value at the inflow boundary and decreases to zero at
+!-- pt_damping_width.
     ptdf_x = 0.0_wp
     ptdf_y = 0.0_wp
@@ -2060,34 +1953,31 @@
        DO  i = nxl, nxr
           IF ( ( i * dx ) < pt_damping_width )  THEN
-             ptdf_x(i) = pt_damping_factor * ( SIN( pi * 0.5_wp *              &
-                            REAL( pt_damping_width - i * dx, KIND=wp ) / (     &
-                            REAL( pt_damping_width, KIND=wp ) ) ) )**2 
-          ENDIF
+             ptdf_x(i) = pt_damping_factor * ( SIN( pi * 0.5_wp *                                  &
+                                                    REAL( pt_damping_width - i * dx, KIND=wp ) /   &
+                                                    REAL( pt_damping_width, KIND=wp ) ) )**2
+                                  ENDIF
        ENDDO
     ELSEIF ( bc_lr_raddir )  THEN
        DO  i = nxl, nxr
           IF ( ( i * dx ) > ( nx * dx - pt_damping_width ) )  THEN
-             ptdf_x(i) = pt_damping_factor *                                   &
-                         SIN( pi * 0.5_wp *                                    &
-                                 ( ( i - nx ) * dx + pt_damping_width ) /      &
-                                 REAL( pt_damping_width, KIND=wp ) )**2
-          ENDIF
-       ENDDO 
+             ptdf_x(i) = pt_damping_factor * SIN( pi * 0.5_wp *                                    &
+                                                  ( ( i - nx ) * dx + pt_damping_width ) /         &
+                                                  REAL( pt_damping_width, KIND=wp ) )**2
+          ENDIF
+       ENDDO
     ELSEIF ( bc_ns_dirrad )  THEN
        DO  j = nys, nyn
           IF ( ( j * dy ) > ( ny * dy - pt_damping_width ) )  THEN
-             ptdf_y(j) = pt_damping_factor *                                   &
-                         SIN( pi * 0.5_wp *                                    &
-                                 ( ( j - ny ) * dy + pt_damping_width ) /      &
-                                 REAL( pt_damping_width, KIND=wp ) )**2
-          ENDIF
-       ENDDO 
+             ptdf_y(j) = pt_damping_factor * SIN( pi * 0.5_wp *                                    &
+                                                  ( ( j - ny ) * dy + pt_damping_width ) /         &
+                                                  REAL( pt_damping_width, KIND=wp ) )**2
+          ENDIF
+       ENDDO
     ELSEIF ( bc_ns_raddir )  THEN
        DO  j = nys, nyn
           IF ( ( j * dy ) < pt_damping_width )  THEN
-             ptdf_y(j) = pt_damping_factor *                                   &
-                         SIN( pi * 0.5_wp *                                    &
-                                ( pt_damping_width - j * dy ) /                &
-                                REAL( pt_damping_width, KIND=wp ) )**2
+             ptdf_y(j) = pt_damping_factor * SIN( pi * 0.5_wp *                                    &
+                                                  ( pt_damping_width - j * dy ) /                  &
+                                                  REAL( pt_damping_width, KIND=wp ) )**2
           ENDIF
        ENDDO
@@ -2095,10 +1985,9 @@
 
 !
-!-- Input binary data file is not needed anymore. This line must be placed
-!-- after call of user_init!
+!-- Input binary data file is not needed anymore. This line must be placed after call of user_init!
     CALL close_file( 13 )
 !
-!-- In case of nesting, put an barrier to assure that all parent and child 
-!-- domains finished initialization. 
+!-- In case of nesting, put an barrier to assure that all parent and child domains finished
+!-- initialization.
 #if defined( __parallel )
     IF ( nested_run )  CALL MPI_BARRIER( MPI_COMM_WORLD, ierr )
Index: /palm/trunk/SOURCE/init_advec.f90
===================================================================
--- /palm/trunk/SOURCE/init_advec.f90	(revision 4647)
+++ /palm/trunk/SOURCE/init_advec.f90	(revision 4648)
@@ -1,30 +1,32 @@
 !> @file init_advec.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
 !
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
 !
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4360 2020-01-07 11:25:50Z suehring
 ! Corrected "Former revisions" section
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! Corrected "Former revisions" section
@@ -37,14 +39,14 @@
 ! ------------
 !> Initialize constant coefficients and parameters for certain advection schemes.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE init_advec
- 
 
-    USE advection,                                                             &
+
+    USE advection,                                                                                 &
         ONLY:  aex, bex, dex, eex
-        
+
     USE kinds
-    
-    USE control_parameters,                                                    &
+
+    USE control_parameters,                                                                        &
         ONLY:  scalar_advec
 
@@ -52,7 +54,7 @@
 
     INTEGER(iwp) ::  i          !<
-    INTEGER(iwp) ::  intervals  !< 
+    INTEGER(iwp) ::  intervals  !<
     INTEGER(iwp) ::  j          !<
-    
+
     REAL(wp) :: delt   !<
     REAL(wp) :: dn     !<
@@ -88,5 +90,5 @@
              ex1 = dn * EXP( -dn ) - EXP( 0.5_wp * dn ) + EXP( -0.5_wp * dn )
              ex2 = EXP( dn ) - EXP( -dn )
-             ex3 = EXP( -dn ) * ( 1.0_wp - dn ) - 0.5_wp * EXP(  0.5_wp * dn ) &
+             ex3 = EXP( -dn ) * ( 1.0_wp - dn ) - 0.5_wp * EXP(  0.5_wp * dn )                     &
                                                 - 0.5_wp * EXP( -0.5_wp * dn )
              ex4 = EXP( dn ) + EXP( -dn )
Index: /palm/trunk/SOURCE/init_coupling.f90
===================================================================
--- /palm/trunk/SOURCE/init_coupling.f90	(revision 4647)
+++ /palm/trunk/SOURCE/init_coupling.f90	(revision 4648)
@@ -1,36 +1,38 @@
 !> @file init_coupling.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
 !
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
 !
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! ------------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4564 2020-06-12 14:03:36Z raasch
 ! Vertical nesting method of Huq et al. (2019) removed
-! 
+!
 ! 4444 2020-03-05 15:59:50Z raasch
 ! bugfix: cpp-directives for serial mode added
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Corrected "Former revisions" section
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! references to mrun replaced by palmrun, and updated
@@ -41,15 +43,14 @@
 ! Description:
 ! ------------
-!> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is
-!> called.
-!------------------------------------------------------------------------------!
+!> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is called.
+!--------------------------------------------------------------------------------------------------!
   SUBROUTINE init_coupling
- 
 
-    USE control_parameters,                                                    &
+
+    USE control_parameters,                                                                        &
         ONLY:  coupling_char, coupling_mode
-        
+
     USE kinds
-    
+
     USE pegrid
 
@@ -62,12 +63,11 @@
     INTEGER(iwp) ::  inter_color  !<
 #endif
-    
+
     INTEGER(iwp), DIMENSION(:) ::  bc_data(0:3) = 0  !<
 
 !
-!-- Get information about the coupling mode from the environment variable
-!-- which has been set by the mpiexec command.
-!-- This method is currently not used because the mpiexec command is not
-!-- available on some machines
+!-- Get information about the coupling mode from the environment variable which has been set by the
+!-- mpiexec command.
+!-- This method is currently not used because the mpiexec command is not available on some machines.
 !    CALL GET_ENVIRONMENT_VARIABLE( 'coupling_mode', coupling_mode, i )
 !    IF ( i == 0 )  coupling_mode = 'uncoupled'
@@ -75,6 +75,6 @@
 
 !
-!-- Get information about the coupling mode from standard input (PE0 only) and
-!-- distribute it to the other PEs. Distribute PEs to 2 new communicators.
+!-- Get information about the coupling mode from standard input (PE0 only) and distribute it to the
+!-- other PEs. Distribute PEs to 2 new communicators.
 !-- ATTENTION: numprocs will be reset according to the new communicators
 #if defined ( __parallel )
@@ -91,6 +91,6 @@
 
 !
-!--    Check if '_O' has to be used as file extension in an uncoupled ocean
-!--    run. This is required, if this run shall be continued as a coupled run.
+!--    Check if '_O' has to be used as file extension in an uncoupled ocean run. This is required,
+!--    if this run shall be continued as a coupled run.
        IF ( TRIM( coupling_mode ) == 'precursor_ocean' )  bc_data(3) = 1
 
@@ -127,6 +127,5 @@
 
 !
-!--    Write a flag file for the ocean model and the other atmosphere
-!--    processes.
+!--    Write a flag file for the ocean model and the other atmosphere processes.
        OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' )
        WRITE ( 90, '(''TRUE'')' )
@@ -136,8 +135,7 @@
 
 !
-!-- In case of a precursor ocean run (followed by a coupled run), or a
-!-- coupled atmosphere-ocean run, set the file extension for the ocean files
-    IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) &
-    THEN
+!-- In case of a precursor ocean run (followed by a coupled run), or a coupled atmosphere-ocean run,
+!-- set the file extension for the ocean files.
+    IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 )  THEN
        coupling_char = '_O'
     ENDIF
Index: /palm/trunk/SOURCE/init_grid.f90
===================================================================
--- /palm/trunk/SOURCE/init_grid.f90	(revision 4647)
+++ /palm/trunk/SOURCE/init_grid.f90	(revision 4648)
@@ -1,20 +1,19 @@
 !> @file init_grid.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
@@ -25,113 +24,110 @@
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4630 2020-07-30 14:54:34Z suehring
 ! In case of ASCII topography input flag grid points as terrain and building.
 !
 ! 4601 2020-07-14 12:06:09Z suehring
 ! Minor formatting adjustments
-! 
+!
 ! 4564 2020-06-12 14:03:36Z raasch
 ! Vertical nesting method of Huq et al. (2019) removed
-! 
+!
 ! 4543 2020-05-20 14:12:22Z gronemeier
 ! Remove non-required check for canyon height
-! 
+!
 ! 4507 2020-04-22 18:21:45Z gronemeier
 ! update origin_z with shifting height of orography (oro_min)
-! 
+!
 ! 4457 2020-03-11 14:20:43Z raasch
 ! use statement for exchange horiz added,
 ! bugfix for call of exchange horiz 2d
-! 
+!
 ! 4444 2020-03-05 15:59:50Z raasch
 ! bugfix: cpp-directives for serial mode added
-! 
+!
 ! 4414 2020-02-19 20:16:04Z suehring
 ! - Remove deprecated topography arrays nzb_s_inner, nzb_u_inner, etc.
-! - Move initialization of boundary conditions and multigrid into an extra
-!   module interface.
-! 
+! - Move initialization of boundary conditions and multigrid into an extra module interface.
+!
 ! 4386 2020-01-27 15:07:30Z Giersch
-! Allocation statements, comments, naming of variables revised and _wp added to 
-! real type values
-! 
+! Allocation statements, comments, naming of variables revised and _wp added to real type values
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Revise error messages for generic tunnel setup.
-! 
+!
 ! 4346 2019-12-18 11:55:56Z motisi
-! Introduction of wall_flags_total_0, which currently sets bits based on static
-! topography information used in wall_flags_static_0
-! 
+! Introduction of wall_flags_total_0, which currently sets bits based on static topography
+! information used in wall_flags_static_0
+!
 ! 4340 2019-12-16 08:17:03Z Giersch
 ! Topography closed channel flow with symmetric boundaries implemented
-! 
+!
 ! 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 change in nzb_max computation. Commentation added.
-! 
+!
 ! 4314 2019-11-29 10:29:20Z suehring
-! Set additional topography flag 4 to mark topography grid points emerged
-! from the filtering process.
-! 
+! Set additional topography flag 4 to mark topography grid points emerged from the filtering process.
+!
 ! 4294 2019-11-13 18:34:16Z suehring
-! Bugfix, always set bit 5 and 6 of wall_flags, indicating terrain- and 
-! building surfaces in all  cases, in order to enable terrain-following output 
-! also when no land- or urban-surface model is applied. 
-! 
+! Bugfix, always set bit 5 and 6 of wall_flags, indicating terrain- and building surfaces in all
+! cases, in order to enable terrain-following output also when no land- or urban-surface model is
+! applied.
+!
 ! 4265 2019-10-15 16:16:24Z suehring
-! Bugfix for last commit, exchange oro_max variable only when it is allocated 
-! (not necessarily the case when topography is input from ASCII file).
-! 
+! Bugfix for last commit, exchange oro_max variable only when it is allocated (not necessarily the
+! case when topography is input from ASCII file).
+!
 ! 4245 2019-09-30 08:40:37Z pavelkrc
 ! Store oro_max (building z-offset) in 2D for building surfaces
-! 
+!
 ! 4189 2019-08-26 16:19:38Z suehring
 ! - Add check for proper setting of namelist parameter topography
 ! - Set flag to indicate land surfaces in case no topography is provided
-! 
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 4168 2019-08-16 13:50:17Z suehring
-! Pre-calculate topography top index and store it on an array (replaces former
-! functions get_topography_top_index)
-! 
+! Pre-calculate topography top index and store it on an array (replaces former functions
+! get_topography_top_index)
+!
 ! 4159 2019-08-15 13:31:35Z suehring
-! Revision of topography processing. This was not consistent between 2D and 3D
-! buildings. 
-! 
+! Revision of topography processing. This was not consistent between 2D and 3D buildings.
+!
 ! 4144 2019-08-06 09:11:47Z raasch
 ! relational operators .EQ., .NE., etc. replaced by ==, /=, etc.
-! 
+!
 ! 4115 2019-07-24 12:50:49Z suehring
-! Bugfix in setting near-surface flag 24, inidicating wall-bounded grid points 
-! 
+! Bugfix in setting near-surface flag 24, inidicating wall-bounded grid points
+!
 ! 4110 2019-07-22 17:05:21Z suehring
 ! - Separate initialization of advection flags for momentum and scalars.
 ! - Change subroutine interface for ws_init_flags_scalar to pass boundary flags
-! 
+!
 ! 4109 2019-07-22 17:00:34Z suehring
 ! Fix bad commit
-! 
+!
 ! 3926 2019-04-23 12:56:42Z suehring
-! Minor bugfix in building mapping when all building IDs in the model domain
-! are missing
-! 
+! Minor bugfix in building mapping when all building IDs in the model domain are missing
+!
 ! 3857 2019-04-03 13:00:16Z knoop
-! In projection of non-building 3D objects onto numerical grid remove 
-! dependency on building_type
-! 
+! In projection of non-building 3D objects onto numerical grid remove dependency on building_type
+!
 ! 3763 2019-02-25 17:33:49Z suehring
-! Replace work-around for ghost point exchange of 1-byte arrays with specific 
-! routine as already done in other routines
-! 
+! Replace work-around for ghost point exchange of 1-byte arrays with specific routine as already
+! done in other routines
+!
 ! 3761 2019-02-25 15:31:42Z raasch
 ! unused variables removed
-! 
+!
 ! 3661 2019-01-08 18:22:50Z suehring
-! Remove setting of nzb_max to nzt at non-cyclic boundary PEs, instead, 
-! order degradation of advection scheme is handeled directly in advec_ws
-! 
+! Remove setting of nzb_max to nzt at non-cyclic boundary PEs, instead, order degradation of
+! advection scheme is handeled directly in advec_ws
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! Comment added
@@ -142,50 +138,50 @@
 !
 ! Description:
-! -----------------------------------------------------------------------------!
+! -------------------------------------------------------------------------------------------------!
 !> Creating grid depending constants
 !> @todo: Rearrange topo flag list
-!> @todo: reference 3D buildings on top of orography is not tested and may need
-!>        further improvement for steep slopes
-!> @todo: Use more advanced setting of building type at filled holes 
-!------------------------------------------------------------------------------!
+!> @todo: reference 3D buildings on top of orography is not tested and may need further improvement
+!>        for steep slopes
+!> @todo: Use more advanced setting of building type at filled holes
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE init_grid
 
-    USE arrays_3d,                                                             &
+    USE arrays_3d,                                                                                 &
         ONLY:  dd2zu, ddzu, ddzu_pres, ddzw, dzu, dzw, x, xu, y, yv, zu, zw
 
-    USE control_parameters,                                                    &
-        ONLY:  constant_flux_layer, dz, dz_max, dz_stretch_factor,             &
-               dz_stretch_factor_array, dz_stretch_level, dz_stretch_level_end,&
-               dz_stretch_level_end_index, dz_stretch_level_start_index,       &
-               dz_stretch_level_start, ibc_uv_b, message_string,               &
-               number_stretch_level_end,                                       &
-               number_stretch_level_start,                                     &
-               ocean_mode,                                                     &
-               psolver,                                                        &
-               symmetry_flag,                                                  &
-               topography,                                                     &
+    USE control_parameters,                                                                        &
+        ONLY:  constant_flux_layer, dz, dz_max, dz_stretch_factor,                                 &
+               dz_stretch_factor_array, dz_stretch_level, dz_stretch_level_end,                    &
+               dz_stretch_level_end_index, dz_stretch_level_start_index,                           &
+               dz_stretch_level_start, ibc_uv_b, message_string,                                   &
+               number_stretch_level_end,                                                           &
+               number_stretch_level_start,                                                         &
+               ocean_mode,                                                                         &
+               psolver,                                                                            &
+               symmetry_flag,                                                                      &
+               topography,                                                                         &
                use_surface_fluxes
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                                            &
         ONLY:  ddx, ddx2, ddy, ddy2, dx, dx2, dy, dy2, zu_s_inner, zw_w_inner
 
-    USE indices,                                                               &
-        ONLY:  nbgp,                                                           &
-               nx,                                                             &
-               nxl,                                                            &
-               nxlg,                                                           &
-               nxr,                                                            &
-               nxrg,                                                           &
-               ny,                                                             &
-               nyn,                                                            &
-               nyng,                                                           &
-               nys,                                                            &
-               nysg,                                                           &
-               nz,                                                             &
-               nzb,                                                            &
-               nzb_diff,                                                       &
-               nzb_max,                                                        &
-               nzt,                                                            &
-               topo_top_ind,                                                   &
+    USE indices,                                                                                   &
+        ONLY:  nbgp,                                                                               &
+               nx,                                                                                 &
+               nxl,                                                                                &
+               nxlg,                                                                               &
+               nxr,                                                                                &
+               nxrg,                                                                               &
+               ny,                                                                                 &
+               nyn,                                                                                &
+               nyng,                                                                               &
+               nys,                                                                                &
+               nysg,                                                                               &
+               nz,                                                                                 &
+               nzb,                                                                                &
+               nzb_diff,                                                                           &
+               nzb_max,                                                                            &
+               nzt,                                                                                &
+               topo_top_ind,                                                                       &
                topo_min_level
 
@@ -196,10 +192,10 @@
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i             !< index variable along x 
+    INTEGER(iwp) ::  i             !< index variable along x
     INTEGER(iwp) ::  j             !< index variable along y
     INTEGER(iwp) ::  k             !< index variable along z
     INTEGER(iwp) ::  k_top         !< topography top index on local PE
     INTEGER(iwp) ::  n             !< loop variable for stretching
-    INTEGER(iwp) ::  number_dz     !< number of user-specified dz values       
+    INTEGER(iwp) ::  number_dz     !< number of user-specified dz values
     INTEGER(iwp) ::  nzb_local_max !< vertical grid index of maximum topography height
     INTEGER(iwp) ::  nzb_local_min !< vertical grid index of minimum topography height
@@ -209,6 +205,7 @@
     REAL(wp) ::  dz_level_end  !< distance between calculated height level for u/v-grid and user-specified end level for stretching
     REAL(wp) ::  dz_stretched  !< stretched vertical grid spacing
-    
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  min_dz_stretch_level_end !< Array that contains all minimum heights where the stretching can end
+
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  min_dz_stretch_level_end !< Array that contains all minimum heights where the stretching
+                                                                     !< can end
 
 
@@ -224,5 +221,5 @@
     ALLOCATE( x(0:nx) )
     ALLOCATE( xu(0:nx) )
-    
+
     DO i = 0, nx
        xu(i) = i * dx
@@ -232,5 +229,5 @@
     ALLOCATE( y(0:ny) )
     ALLOCATE( yv(0:ny) )
-    
+
     DO j = 0, ny
        yv(j) = j * dy
@@ -247,9 +244,9 @@
 
 !
-!-- For constructing an appropriate grid, the vertical grid spacing dz has to
-!-- be specified with a non-negative value in the parameter file
+!-- For constructing an appropriate grid, the vertical grid spacing dz has to be specified with a
+!-- non-negative value in the parameter file.
     IF ( dz(1) == -1.0_wp )  THEN
        message_string = 'missing dz'
-       CALL message( 'init_grid', 'PA0200', 1, 2, 0, 6, 0 ) 
+       CALL message( 'init_grid', 'PA0200', 1, 2, 0, 6, 0 )
     ELSEIF ( dz(1) <= 0.0_wp )  THEN
        WRITE( message_string, * ) 'dz=',dz(1),' <= 0.0'
@@ -258,59 +255,49 @@
 
 !
-!-- Initialize dz_stretch_level_start with the value of dz_stretch_level
-!-- if it was set by the user
+!-- Initialize dz_stretch_level_start with the value of dz_stretch_level if it was set by the user.
     IF ( dz_stretch_level /= -9999999.9_wp ) THEN
        dz_stretch_level_start(1) = dz_stretch_level
     ENDIF
-       
-!
-!-- Determine number of dz values and stretching levels specified by the
-!-- user to allow right controlling of the stretching mechanism and to
-!-- perform error checks. The additional requirement that dz /= dz_max
-!-- for counting number of user-specified dz values is necessary. Otherwise 
-!-- restarts would abort if the old stretching mechanism with dz_stretch_level
-!-- is used (Attention: The user is not allowed to specify a dz value equal
-!-- to the default of dz_max = 999.0). 
-    number_dz = COUNT( dz /= -1.0_wp .AND. dz /= dz_max)
-    number_stretch_level_start = COUNT( dz_stretch_level_start /=              &
-                                       -9999999.9_wp )
-    number_stretch_level_end = COUNT( dz_stretch_level_end /=                  &
-                                      9999999.9_wp )
-
-!
-!-- The number of specified end levels +1 has to be the same as the number 
+
+!
+!-- Determine number of dz values and stretching levels specified by the user to allow right
+!-- controlling of the stretching mechanism and to perform error checks. The additional requirement
+!-- that dz /= dz_max for counting number of user-specified dz values is necessary. Otherwise
+!-- restarts would abort if the old stretching mechanism with dz_stretch_level is used (Attention:
+!-- The user is not allowed to specify a dz value equal to the default of dz_max = 999.0).
+    number_dz = COUNT( dz /= -1.0_wp  .AND.  dz /= dz_max)
+    number_stretch_level_start = COUNT( dz_stretch_level_start /= -9999999.9_wp )
+    number_stretch_level_end = COUNT( dz_stretch_level_end /= 9999999.9_wp )
+
+!
+!-- The number of specified end levels +1 has to be the same as the number
 !-- of specified dz values
     IF ( number_dz /= number_stretch_level_end + 1 ) THEN
-       WRITE( message_string, * ) 'The number of values for dz = ',            &
-                                   number_dz, 'has to be the same as& ',       &
-                                   'the number of values for ',                &
-                                   'dz_stretch_level_end + 1 = ',              &
-                                   number_stretch_level_end+1
+       WRITE( message_string, * )  'The number of values for dz = ', number_dz,                    &
+                                   'has to be the same as& ', 'the number of values for ',         &
+                                   'dz_stretch_level_end + 1 = ', number_stretch_level_end+1
        CALL message( 'init_grid', 'PA0156', 1, 2, 0, 6, 0 )
     ENDIF
-    
-!
-!-- The number of specified start levels has to be the same or one less than 
-!-- the number of specified dz values
-    IF ( number_dz /= number_stretch_level_start + 1 .AND.                     &
-         number_dz /= number_stretch_level_start ) THEN
-       WRITE( message_string, * ) 'The number of values for dz = ',            &
-                                   number_dz, 'has to be the same as or one ', &
-                                   'more than& the number of values for ',     &
-                                   'dz_stretch_level_start = ',                &
-                                   number_stretch_level_start
+
+!
+!-- The number of specified start levels has to be the same or one less than the number of specified
+!-- dz values
+    IF ( number_dz /= number_stretch_level_start + 1  .AND.                                        &
+         number_dz /= number_stretch_level_start )  THEN
+       WRITE( message_string, * )  'The number of values for dz = ', number_dz,                    &
+                                   'has to be the same as or one ',                                &
+                                   'more than& the number of values for ',                         &
+                                   'dz_stretch_level_start = ', number_stretch_level_start
        CALL message( 'init_grid', 'PA0211', 1, 2, 0, 6, 0 )
     ENDIF
-    
-!-- The number of specified start levels has to be the same or one more than 
-!-- the number of specified end levels
-    IF ( number_stretch_level_start /= number_stretch_level_end + 1 .AND.      &
+
+!-- The number of specified start levels has to be the same or one more than the number of specified
+!-- end levels
+    IF ( number_stretch_level_start /= number_stretch_level_end + 1  .AND.                         &
          number_stretch_level_start /= number_stretch_level_end ) THEN
-       WRITE( message_string, * ) 'The number of values for ',                 &
-                                  'dz_stretch_level_start = ',                 &
-                                   dz_stretch_level_start, 'has to be the ',   &
-                                   'same or one more than& the number of ',    &
-                                   'values for dz_stretch_level_end = ',       &
-                                   number_stretch_level_end
+       WRITE( message_string, * )  'The number of values for ',                                    &
+                                   'dz_stretch_level_start = ', dz_stretch_level_start,            &
+                                   'has to be the ', 'same or one more than& the number of ',      &
+                                   'values for dz_stretch_level_end = ', number_stretch_level_end
        CALL message( 'init_grid', 'PA0216', 1, 2, 0, 6, 0 )
     ENDIF
@@ -318,18 +305,15 @@
 !
 !-- Initialize dz for the free atmosphere with the value of dz_max
-    IF ( dz(number_stretch_level_start+1) == -1.0_wp .AND.                     &
-         number_stretch_level_start /= 0 ) THEN 
+    IF ( dz(number_stretch_level_start+1) == -1.0_wp  .AND.  number_stretch_level_start /= 0 ) THEN
        dz(number_stretch_level_start+1) = dz_max
     ENDIF
-       
-!
-!-- Initialize the stretching factor if (infinitely) stretching in the free 
-!-- atmosphere is desired (dz_stretch_level_end was not specified for the 
-!-- free atmosphere)
-    IF ( number_stretch_level_start == number_stretch_level_end + 1 ) THEN 
-       dz_stretch_factor_array(number_stretch_level_start) =                   &
-       dz_stretch_factor
+
+!
+!-- Initialize the stretching factor if (infinitely) stretching in the free atmosphere is desired
+!-- (dz_stretch_level_end was not specified for the free atmosphere)
+    IF ( number_stretch_level_start == number_stretch_level_end + 1 )  THEN
+       dz_stretch_factor_array(number_stretch_level_start) = dz_stretch_factor
     ENDIF
-    
+
 !
 !-- Allocation of arrays for stretching
@@ -339,57 +323,50 @@
 !-- Define the vertical grid levels. Start with atmosphere branch
     IF ( .NOT. ocean_mode )  THEN
-    
-!
-!--    The stretching region has to be large enough to allow for a smooth
-!--    transition between two different grid spacings. The number 4 is an
-!--    empirical value
+
+!
+!--    The stretching region has to be large enough to allow for a smooth transition between two
+!--    different grid spacings. The number 4 is an empirical value.
        DO n = 1, number_stretch_level_start
-          min_dz_stretch_level_end(n) = dz_stretch_level_start(n) +            &
-                                        4 * MAX( dz(n),dz(n+1) )
+          min_dz_stretch_level_end(n) = dz_stretch_level_start(n) + 4 * MAX( dz(n),dz(n+1) )
        ENDDO
 
-       IF ( ANY( min_dz_stretch_level_end(1:number_stretch_level_start) >      &
-                 dz_stretch_level_end(1:number_stretch_level_start) ) ) THEN
-          message_string= 'Each dz_stretch_level_end has to be larger ' //     &
-                          'than its corresponding value for &' //              &
-                          'dz_stretch_level_start + 4*MAX(dz(n),dz(n+1)) '//   &
+       IF ( ANY( min_dz_stretch_level_end(1:number_stretch_level_start) >                          &
+                 dz_stretch_level_end(1:number_stretch_level_start) ) )  THEN
+          message_string= 'Each dz_stretch_level_end has to be larger ' //                         &
+                          'than its corresponding value for &' //                                  &
+                          'dz_stretch_level_start + 4*MAX(dz(n),dz(n+1)) '//                       &
                           'to allow for smooth grid stretching'
           CALL message( 'init_grid', 'PA0224', 1, 2, 0, 6, 0 )
        ENDIF
-       
-!
-!--    Stretching must not be applied within the surface layer 
-!--    (first two grid points). For the default case dz_stretch_level_start 
-!--    is negative. Therefore the absolut value is checked here.
+
+!
+!--    Stretching must not be applied within the surface layer (first two grid points). For the
+!--    default case dz_stretch_level_start is negative. Therefore the absolut value is checked here.
        IF ( ANY( ABS( dz_stretch_level_start ) <= dz(1) * 1.5_wp ) ) THEN
-          WRITE( message_string, * ) 'Each dz_stretch_level_start has to be ',&
-                                     'larger than ', dz(1) * 1.5
+          WRITE( message_string, * )  'Each dz_stretch_level_start has to be ',                    &
+                                      'larger than ', dz(1) * 1.5
           CALL message( 'init_grid', 'PA0226', 1, 2, 0, 6, 0 )
        ENDIF
 
 !
-!--    The stretching has to start and end on a grid level. Therefore 
-!--    user-specified values are mapped to the next lowest level. The  
-!--    calculation of the first level is realized differently just because of 
-!--    historical reasons (the advanced/new stretching mechanism was realized  
-!--    in a way that results don't change if the old parameters 
-!--    dz_stretch_level, dz_stretch_factor and dz_max are used)
-       IF ( number_stretch_level_start /= 0 ) THEN
-          dz_stretch_level_start(1) = INT( (dz_stretch_level_start(1) -        &
-                                            dz(1)/2.0) / dz(1) )               &
+!--    The stretching has to start and end on a grid level. Therefore user-specified values are
+!--    mapped to the next lowest level. The calculation of the first level is realized differently
+!--    just because of historical reasons (the advanced/new stretching mechanism was realized in a
+!--    way that results don't change if the old parameters dz_stretch_level, dz_stretch_factor and
+!--    dz_max are used).
+       IF ( number_stretch_level_start /= 0 )  THEN
+          dz_stretch_level_start(1) = INT( (dz_stretch_level_start(1) - dz(1)/2.0) / dz(1) )       &
                                       * dz(1) + dz(1)/2.0
        ENDIF
-       
+
        IF ( number_stretch_level_start > 1 ) THEN
           DO n = 2, number_stretch_level_start
-             dz_stretch_level_start(n) = INT( dz_stretch_level_start(n) /      &
-                                              dz(n) ) * dz(n)
-          ENDDO
-       ENDIF
-       
+             dz_stretch_level_start(n) = INT( dz_stretch_level_start(n) / dz(n) ) * dz(n)
+          ENDDO
+       ENDIF
+
        IF ( number_stretch_level_end /= 0 ) THEN
           DO n = 1, number_stretch_level_end
-             dz_stretch_level_end(n) = INT( dz_stretch_level_end(n) /          &
-                                            dz(n+1) ) * dz(n+1)
+             dz_stretch_level_end(n) = INT( dz_stretch_level_end(n) / dz(n+1) ) * dz(n+1)
           ENDDO
        ENDIF
@@ -397,5 +374,5 @@
 !
 !--    Determine stretching factor if necessary
-       IF ( number_stretch_level_end >= 1 ) THEN 
+       IF ( number_stretch_level_end >= 1 ) THEN
           CALL calculate_stretching_factor( number_stretch_level_end )
        ENDIF
@@ -403,21 +380,19 @@
 !
 !--    Grid for atmosphere with surface at z=0 (k=0, w-grid).
-!--    First compute the u- and v-levels. In case of dirichlet bc for u and v
-!--    the first u/v- and w-level (k=0) are defined at same height (z=0). 
-!--    The second u-level (k=1) corresponds to the top of the 
-!--    surface layer. In case of symmetric boundaries (closed channel flow), 
-!--    the first grid point is always at z=0.
-       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2 .OR.                              & 
-            topography == 'closed_channel' ) THEN
+!--    First compute the u- and v-levels. In case of dirichlet bc for u and v the first u/v- and
+!--    w-level (k=0) are defined at same height (z=0).
+!--    The second u-level (k=1) corresponds to the top of the surface layer. In case of symmetric
+!--    boundaries (closed channel flow), the first grid point is always at z=0.
+       IF ( ibc_uv_b == 0  .OR.  ibc_uv_b == 2  .OR.  topography == 'closed_channel' )  THEN
           zu(0) = 0.0_wp
        ELSE
           zu(0) = - dz(1) * 0.5_wp
        ENDIF
-          
+
        zu(1) =   dz(1) * 0.5_wp
-       
-!
-!--    Determine u and v height levels considering the possibility of grid
-!--    stretching in several heights.
+
+!
+!--    Determine u and v height levels considering the possibility of grid stretching in several
+!--    heights.
        n = 1
        dz_stretch_level_start_index = nzt+1
@@ -425,62 +400,58 @@
        dz_stretched = dz(1)
 
-!--    The default value of dz_stretch_level_start is negative, thus the first
-!--    condition is true even if no stretching shall be applied. Hence, the 
-!--    second condition is also necessary.
+!--    The default value of dz_stretch_level_start is negative, thus the first condition is true
+!--    even if no stretching shall be applied. Hence, the second condition is also necessary.
        DO  k = 2, nzt+1-symmetry_flag
-          IF ( dz_stretch_level_start(n) <= zu(k-1) .AND.                      &
-               dz_stretch_level_start(n) /= -9999999.9_wp ) THEN
+          IF ( dz_stretch_level_start(n) <= zu(k-1)  .AND.                                         &
+               dz_stretch_level_start(n) /= -9999999.9_wp )  THEN
              dz_stretched = dz_stretched * dz_stretch_factor_array(n)
-             
-             IF ( dz(n) > dz(n+1) ) THEN
+
+             IF ( dz(n) > dz(n+1) )  THEN
                 dz_stretched = MAX( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (higher) dz
              ELSE
                 dz_stretched = MIN( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (lower) dz
              ENDIF
-             
-             IF ( dz_stretch_level_start_index(n) == nzt+1 )                         &
-             dz_stretch_level_start_index(n) = k-1
-             
-          ENDIF
-          
+
+             IF ( dz_stretch_level_start_index(n) == nzt+1 )  dz_stretch_level_start_index(n) = k-1
+
+          ENDIF
+
           zu(k) = zu(k-1) + dz_stretched
-          
-!
-!--       Make sure that the stretching ends exactly at dz_stretch_level_end 
-          dz_level_end = ABS( zu(k) - dz_stretch_level_end(n) ) 
-          
-          IF ( dz_level_end  < dz(n+1)/3.0 ) THEN
+
+!
+!--       Make sure that the stretching ends exactly at dz_stretch_level_end
+          dz_level_end = ABS( zu(k) - dz_stretch_level_end(n) )
+
+          IF ( dz_level_end  < dz(n+1)/3.0 )  THEN
              zu(k) = dz_stretch_level_end(n)
              dz_stretched = dz(n+1)
              dz_stretch_level_end_index(n) = k
-             n = n + 1             
+             n = n + 1
           ENDIF
        ENDDO
-       
-!
-!--    If a closed channel flow is simulated, make sure that grid structure is  
-!--    the same for both bottom and top boundary. (Hint: Using a different dz 
-!--    at the bottom and at the top makes no sense due to symmetric boundaries
-!--    where dz should be equal. Therefore, different dz at the bottom and top  
-!--    causes an abort (see check_parameters).)
-       IF ( topography == 'closed_channel' ) THEN
+
+!
+!--    If a closed channel flow is simulated, make sure that grid structure is the same for both
+!--    bottom and top boundary. (Hint: Using a different dz at the bottom and at the top makes no
+!--    sense due to symmetric boundaries where dz should be equal. Therefore, different dz at the
+!--    bottom and top causes an abort (see check_parameters).)
+       IF ( topography == 'closed_channel' )  THEN
           zu(nzt+1) = zu(nzt) + dz(1) * 0.5_wp
        ENDIF
 
 !
-!--    Compute the w-levels. They are always staggered half-way between the 
-!--    corresponding u-levels. In case of dirichlet bc for u and v at the 
-!--    ground the first u- and w-level (k=0) are defined at same height (z=0). 
-!--    Per default, the top w-level is extrapolated linearly. In case of 
-!--    a closed channel flow, zu(nzt+1) and zw(nzt) must be set explicitely.
-!--    (Hint: Using a different dz at the bottom and at the top makes no sense
-!--    due to symmetric boundaries where dz should be equal. Therefore, 
-!--    different dz at the bottom and top causes an abort (see 
-!--    check_parameters).)
+!--    Compute the w-levels. They are always staggered half-way between the corresponding u-levels.
+!--    In case of dirichlet bc for u and v at the ground the first u- and w-level (k=0) are defined
+!--    at same height (z=0).
+!--    Per default, the top w-level is extrapolated linearly. In case of a closed channel flow,
+!--    zu(nzt+1) and zw(nzt) must be set explicitely.
+!--    (Hint: Using a different dz at the bottom and at the top makes no sense due to symmetric
+!--    boundaries where dz should be equal. Therefore, different dz at the bottom and top causes an
+!--    abort (see check_parameters).)
        zw(0) = 0.0_wp
        DO  k = 1, nzt-symmetry_flag
           zw(k) = ( zu(k) + zu(k+1) ) * 0.5_wp
        ENDDO
-       IF ( topography == 'closed_channel' ) THEN
+       IF ( topography == 'closed_channel' )  THEN
           zw(nzt)   = zw(nzt-1) + dz(1)
           zw(nzt+1) = zw(nzt) + dz(1)
@@ -492,60 +463,54 @@
 
 !
-!--    The stretching region has to be large enough to allow for a smooth
-!--    transition between two different grid spacings. The number 4 is an
-!--    empirical value
+!--    The stretching region has to be large enough to allow for a smooth transition between two
+!--    different grid spacings. The number 4 is an empirical value
        DO n = 1, number_stretch_level_start
-          min_dz_stretch_level_end(n) = dz_stretch_level_start(n) -            &
-                                        4 * MAX( dz(n),dz(n+1) )
+          min_dz_stretch_level_end(n) = dz_stretch_level_start(n) - 4 * MAX( dz(n),dz(n+1) )
        ENDDO
-       
-       IF ( ANY( min_dz_stretch_level_end (1:number_stretch_level_start) <     &
-                 dz_stretch_level_end(1:number_stretch_level_start) ) ) THEN
-             message_string= 'Each dz_stretch_level_end has to be less ' //   &
-                             'than its corresponding value for &' //           &
-                             'dz_stretch_level_start - 4*MAX(dz(n),dz(n+1)) '//&
+
+       IF ( ANY( min_dz_stretch_level_end (1:number_stretch_level_start) <                         &
+                 dz_stretch_level_end(1:number_stretch_level_start) ) )  THEN
+             message_string= 'Each dz_stretch_level_end has to be less ' //                        &
+                             'than its corresponding value for &' //                               &
+                             'dz_stretch_level_start - 4*MAX(dz(n),dz(n+1)) '//                    &
                              'to allow for smooth grid stretching'
              CALL message( 'init_grid', 'PA0224', 1, 2, 0, 6, 0 )
        ENDIF
-       
-!
-!--    Stretching must not be applied close to the surface (last two grid 
-!--    points). For the default case dz_stretch_level_start is negative. 
-       IF ( ANY( dz_stretch_level_start >= - dz(1) * 1.5_wp ) ) THEN
-          WRITE( message_string, * ) 'Each dz_stretch_level_start has to be ',&
-                                     'less than ', -dz(1) * 1.5
+
+!
+!--    Stretching must not be applied close to the surface (last two grid points). For the default
+!--    case dz_stretch_level_start is negative.
+       IF ( ANY( dz_stretch_level_start >= - dz(1) * 1.5_wp ) )  THEN
+          WRITE( message_string, * )  'Each dz_stretch_level_start has to be ',                    &
+                                      'less than ', -dz(1) * 1.5
              CALL message( 'init_grid', 'PA0226', 1, 2, 0, 6, 0 )
        ENDIF
 
 !
-!--    The stretching has to start and end on a grid level. Therefore 
-!--    user-specified values are mapped to the next highest level. The  
-!--    calculation of the first level is realized differently just because of 
-!--    historical reasons (the advanced/new stretching mechanism was realized  
-!--    in a way that results don't change if the old parameters 
-!--    dz_stretch_level, dz_stretch_factor and dz_max are used)
-       IF ( number_stretch_level_start /= 0 ) THEN
-          dz_stretch_level_start(1) = INT( (dz_stretch_level_start(1) +        &
-                                            dz(1)/2.0) / dz(1) )               &
+!--    The stretching has to start and end on a grid level. Therefore user-specified values are
+!--    mapped to the next highest level. The calculation of the first level is realized differently
+!--    just because of historical reasons (the advanced/new stretching mechanism was realized in a
+!--    way that results don't change if the old parameters dz_stretch_level, dz_stretch_factor and
+!--    dz_max are used)
+       IF ( number_stretch_level_start /= 0 )  THEN
+          dz_stretch_level_start(1) = INT( (dz_stretch_level_start(1) + dz(1)/2.0) / dz(1) )       &
                                       * dz(1) - dz(1)/2.0
        ENDIF
-       
-       IF ( number_stretch_level_start > 1 ) THEN
+
+       IF ( number_stretch_level_start > 1 )  THEN
           DO n = 2, number_stretch_level_start
-             dz_stretch_level_start(n) = INT( dz_stretch_level_start(n) /      &
-                                              dz(n) ) * dz(n)
-          ENDDO
-       ENDIF
-       
-       IF ( number_stretch_level_end /= 0 ) THEN
+             dz_stretch_level_start(n) = INT( dz_stretch_level_start(n) / dz(n) ) * dz(n)
+          ENDDO
+       ENDIF
+
+       IF ( number_stretch_level_end /= 0 )  THEN
           DO n = 1, number_stretch_level_end
-             dz_stretch_level_end(n) = INT( dz_stretch_level_end(n) /          &
-                                            dz(n+1) ) * dz(n+1)
-          ENDDO
-       ENDIF
-       
+             dz_stretch_level_end(n) = INT( dz_stretch_level_end(n) / dz(n+1) ) * dz(n+1)
+          ENDDO
+       ENDIF
+
 !
 !--    Determine stretching factor if necessary
-       IF ( number_stretch_level_end >= 1 ) THEN 
+       IF ( number_stretch_level_end >= 1 ) THEN
           CALL calculate_stretching_factor( number_stretch_level_end )
        ENDIF
@@ -553,7 +518,7 @@
 !
 !--    Grid for ocean with free water surface is at k=nzt (w-grid).
-!--    In case of neumann bc at the ground the first first u-level (k=0) lies
-!--    below the first w-level (k=0). In case of dirichlet bc the first u- and
-!--    w-level are defined at same height, but staggered from the second level.
+!--    In case of neumann bc at the ground the first first u-level (k=0) lies below the first
+!--    w-level (k=0). In case of dirichlet bc the first u- and w-level are defined at same height,
+!--    but staggered from the second level.
 !--    The second u-level (k=1) corresponds to the top of the surface layer.
 !--    z values are negative starting from z=0 (surface)
@@ -562,6 +527,6 @@
 
 !
-!--    Determine u and v height levels considering the possibility of grid
-!--    stretching in several heights.
+!--    Determine u and v height levels considering the possibility of grid stretching in several
+!--    heights.
        n = 1
        dz_stretch_level_start_index = 0
@@ -570,38 +535,36 @@
 
        DO  k = nzt-1, 0, -1
-          
-          IF ( dz_stretch_level_start(n) >= zu(k+1) ) THEN
+
+          IF ( dz_stretch_level_start(n) >= zu(k+1) )  THEN
              dz_stretched = dz_stretched * dz_stretch_factor_array(n)
 
-             IF ( dz(n) > dz(n+1) ) THEN
+             IF ( dz(n) > dz(n+1) )  THEN
                 dz_stretched = MAX( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (higher) dz
              ELSE
                 dz_stretched = MIN( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (lower) dz
              ENDIF
-             
-             IF ( dz_stretch_level_start_index(n) == 0 )                             &
-             dz_stretch_level_start_index(n) = k+1
-             
-          ENDIF
-          
+
+             IF ( dz_stretch_level_start_index(n) == 0 )  dz_stretch_level_start_index(n) = k+1
+
+          ENDIF
+
           zu(k) = zu(k+1) - dz_stretched
-          
-!
-!--       Make sure that the stretching ends exactly at dz_stretch_level_end 
-          dz_level_end = ABS( zu(k) - dz_stretch_level_end(n) ) 
-          
-          IF ( dz_level_end  < dz(n+1)/3.0 ) THEN
+
+!
+!--       Make sure that the stretching ends exactly at dz_stretch_level_end
+          dz_level_end = ABS( zu(k) - dz_stretch_level_end(n) )
+
+          IF ( dz_level_end  < dz(n+1)/3.0 )  THEN
              zu(k) = dz_stretch_level_end(n)
              dz_stretched = dz(n+1)
              dz_stretch_level_end_index(n) = k
-             n = n + 1             
+             n = n + 1
           ENDIF
        ENDDO
-       
-!
-!--    Compute the w-levels. They are always staggered half-way between the 
-!--    corresponding u-levels, except in case of dirichlet bc for u and v
-!--    at the ground. In this case the first u- and w-level are defined at 
-!--    same height. The top w-level (nzt+1) is not used but set for 
+
+!
+!--    Compute the w-levels. They are always staggered half-way between the corresponding u-levels,
+!--    except in case of dirichlet bc for u and v at the ground. In this case the first u- and
+!--    w-level are defined at same height. The top w-level (nzt+1) is not used but set for
 !--    consistency, since w and all scalar variables are defined up tp nzt+1.
        zw(nzt+1) = dz(1)
@@ -612,6 +575,5 @@
 
 !
-!--    In case of dirichlet bc for u and v the first u- and w-level are defined
-!--    at same height.
+!--    In case of dirichlet bc for u and v the first u- and w-level are defined at same height.
        IF ( ibc_uv_b == 0 ) THEN
           zu(0) = zw(0)
@@ -632,11 +594,9 @@
        dd2zu(k) = 1.0_wp / ( dzu(k) + dzu(k+1) )
     ENDDO
-    
-!    
-!-- The FFT- SOR-pressure solvers assume grid spacings of a staggered grid
-!-- everywhere. For the actual grid, the grid spacing at the lowest level
-!-- is only dz/2, but should be dz. Therefore, an additional array
-!-- containing with appropriate grid information is created for these
-!-- solvers.
+
+!
+!-- The FFT- SOR-pressure solvers assume grid spacings of a staggered grid everywhere. For the
+!-- actual grid, the grid spacing at the lowest level is only dz/2, but should be dz. Therefore, an
+!-- additional array containing with appropriate grid information is created for these solvers.
     IF ( psolver(1:9) /= 'multigrid' )  THEN
        ALLOCATE( ddzu_pres(1:nzt+1) )
@@ -659,14 +619,13 @@
     topo = 0
 !
-!-- Initialize topography by generic topography or read topography from file.  
+!-- Initialize topography by generic topography or read topography from file.
     CALL init_topo( topo )
 !
-!-- Set flags to mask topography on the grid. 
+!-- Set flags to mask topography on the grid.
     CALL set_topo_flags( topo )
 
 !
-!-- Determine the maximum level of topography. It is used for
-!-- steering the degradation of order of the applied advection scheme, 
-!-- as well in the lpm.
+!-- Determine the maximum level of topography. It is used for steering the degradation of order of
+!-- the applied advection scheme, as well in the lpm.
     k_top = 0
     DO  i = nxl, nxr
@@ -678,6 +637,5 @@
     ENDDO
 #if defined( __parallel )
-    CALL MPI_ALLREDUCE( k_top, nzb_max, 1, MPI_INTEGER,                        &
-                        MPI_MAX, comm2d, ierr )
+    CALL MPI_ALLREDUCE( k_top, nzb_max, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr )
 #else
     nzb_max = k_top
@@ -686,14 +644,14 @@
 !-- Increment nzb_max by 1 in order to allow for proper diverengence correction.
 !-- Further, in case topography extents up to the model top, limit to nzt.
-    nzb_max = MIN( nzb_max+1, nzt ) 
-!
-!-- Determine minimum index of topography. Usually, this will be nzb. In case
-!-- there is elevated topography, however, the lowest topography will be higher. 
-!-- This index is e.g. used to calculate mean first-grid point atmosphere 
-!-- temperature, surface pressure and density, etc. .
+    nzb_max = MIN( nzb_max+1, nzt )
+!
+!-- Determine minimum index of topography. Usually, this will be nzb. In case there is elevated
+!-- topography, however, the lowest topography will be higher.
+!-- This index is e.g. used to calculate mean first-grid point atmosphere temperature, surface
+!-- pressure and density, etc. .
     topo_min_level   = 0
 #if defined( __parallel )
-    CALL MPI_ALLREDUCE( MINVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ),             &
-                        topo_min_level, 1, MPI_INTEGER, MPI_MIN, comm2d, ierr )
+    CALL MPI_ALLREDUCE( MINVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ), topo_min_level, 1, MPI_INTEGER, &
+                        MPI_MIN, comm2d, ierr )
 #else
     topo_min_level = MINVAL( topo_top_ind(nys:nyn,nxl:nxr,0) )
@@ -701,11 +659,10 @@
 
 !
-!-- Check topography for consistency with model domain. Therefore, use
-!-- maximum and minium topography-top indices. Note, minimum topography top
-!-- index is already calculated.  
+!-- Check topography for consistency with model domain. Therefore, use maximum and minium
+!-- topography-top indices. Note, minimum topography top index is already calculated.
     IF ( TRIM( topography ) /= 'flat' )  THEN
 #if defined( __parallel )
-       CALL MPI_ALLREDUCE( MAXVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ),          &
-                           nzb_local_max, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr )               
+       CALL MPI_ALLREDUCE( MAXVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ), nzb_local_max, 1,            &
+                           MPI_INTEGER, MPI_MAX, comm2d, ierr )
 #else
        nzb_local_max = MAXVAL( topo_top_ind(nys:nyn,nxl:nxr,0) )
@@ -715,14 +672,13 @@
 !--    Consistency checks
        IF ( nzb_local_min < 0  .OR.  nzb_local_max  > nz + 1 )  THEN
-          WRITE( message_string, * ) 'nzb_local values are outside the',       &
-                                ' model domain',                               &
-                                '&MINVAL( nzb_local ) = ', nzb_local_min,      &
-                                '&MAXVAL( nzb_local ) = ', nzb_local_max
+          WRITE( message_string, * ) 'nzb_local values are outside the model domain',              &
+                                     '&MINVAL( nzb_local ) = ', nzb_local_min,                     &
+                                     '&MAXVAL( nzb_local ) = ', nzb_local_max
           CALL message( 'init_grid', 'PA0210', 1, 2, 0, 6, 0 )
        ENDIF
     ENDIF
 !
-!-- Define vertical gridpoint from (or to) which on the usual finite difference
-!-- form (which does not use surface fluxes) is applied 
+!-- Define vertical gridpoint from (or to) which on the usual finite difference form (which does not
+!-- use surface fluxes) is applied.
     IF ( constant_flux_layer  .OR.  use_surface_fluxes )  THEN
        nzb_diff = nzb + 2
@@ -733,18 +689,13 @@
     IF ( TRIM( topography ) /= 'flat' )  THEN
 !
-!--    Allocate and set the arrays containing the topography height (for output
-!--    reasons only).
+!--    Allocate and set the arrays containing the topography height (for output reasons only).
        IF ( nxr == nx  .AND.  nyn /= ny )  THEN
-          ALLOCATE( zu_s_inner(nxl:nxr+1,nys:nyn),                             &
-                    zw_w_inner(nxl:nxr+1,nys:nyn) )
+          ALLOCATE( zu_s_inner(nxl:nxr+1,nys:nyn), zw_w_inner(nxl:nxr+1,nys:nyn) )
        ELSEIF ( nxr /= nx  .AND.  nyn == ny )  THEN
-          ALLOCATE( zu_s_inner(nxl:nxr,nys:nyn+1),                             &
-                    zw_w_inner(nxl:nxr,nys:nyn+1) )
+          ALLOCATE( zu_s_inner(nxl:nxr,nys:nyn+1), zw_w_inner(nxl:nxr,nys:nyn+1) )
        ELSEIF ( nxr == nx  .AND.  nyn == ny )  THEN
-          ALLOCATE( zu_s_inner(nxl:nxr+1,nys:nyn+1),                           &
-                    zw_w_inner(nxl:nxr+1,nys:nyn+1) )
+          ALLOCATE( zu_s_inner(nxl:nxr+1,nys:nyn+1), zw_w_inner(nxl:nxr+1,nys:nyn+1) )
        ELSE
-          ALLOCATE( zu_s_inner(nxl:nxr,nys:nyn),                               &
-                    zw_w_inner(nxl:nxr,nys:nyn) )
+          ALLOCATE( zu_s_inner(nxl:nxr,nys:nyn), zw_w_inner(nxl:nxr,nys:nyn) )
        ENDIF
 
@@ -752,18 +703,17 @@
        zw_w_inner   = 0.0_wp
 !
-!--    Determine local topography height on scalar and w-grid. Note, setting
-!--    lateral boundary values is not necessary, realized via wall_flags_static_0
-!--    array. Further, please note that loop bounds are different from
-!--    nxl to nxr and nys to nyn on south and right model boundary, hence,
+!--    Determine local topography height on scalar and w-grid. Note, setting lateral boundary values
+!--    is not necessary, realized via wall_flags_static_0 array. Further, please note that loop
+!--    bounds are different from nxl to nxr and nys to nyn on south and right model boundary, hence,
 !--    use intrinsic lbound and ubound functions to infer array bounds.
        DO  i = LBOUND(zu_s_inner, 1), UBOUND(zu_s_inner, 1)
           DO  j = LBOUND(zu_s_inner, 2), UBOUND(zu_s_inner, 2)
 !
-!--          Topography height on scalar grid. Therefore, determine index of
-!--          upward-facing surface element on scalar grid.
+!--          Topography height on scalar grid. Therefore, determine index of upward-facing surface
+!--          element on scalar grid.
              zu_s_inner(i,j) = zu(topo_top_ind(j,i,0))
 !
-!--          Topography height on w grid. Therefore, determine index of
-!--          upward-facing surface element on w grid.
+!--          Topography height on w grid. Therefore, determine index of upward-facing surface
+!--          element on w grid.
              zw_w_inner(i,j) = zw(topo_top_ind(j,i,3))
           ENDDO
@@ -775,181 +725,171 @@
 
 ! Description:
-! -----------------------------------------------------------------------------!
-!> Calculation of the stretching factor through an iterative method. Ideas were 
-!> taken from the paper "Regional stretched grid generation and its application
-!> to the NCAR RegCM (1999)". Normally, no analytic solution exists because the
-!> system of equations has two variables (r,l) but four requirements 
-!> (l=integer, r=[0,88;1,2], Eq(6), Eq(5) starting from index j=1) which
-!> results into an overdetermined system. 
-!------------------------------------------------------------------------------!
+! -------------------------------------------------------------------------------------------------!
+!> Calculation of the stretching factor through an iterative method. Ideas were taken from the paper
+!> "Regional stretched grid generation and its application to the NCAR RegCM (1999)". Normally, no
+!> analytic solution exists because the system of equations has two variables (r,l) but four
+!> requirements  (l=integer, r=[0,88;1,2], Eq(6), Eq(5) starting from index j=1) which results into
+!> an overdetermined system.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE calculate_stretching_factor( number_end )
- 
-    USE control_parameters,                                                    &
-        ONLY:  dz, dz_stretch_factor_array,                 &
-               dz_stretch_level_end, dz_stretch_level_start, message_string
-  
+
+    USE control_parameters,                                                                        &
+        ONLY:  dz, dz_stretch_factor_array, dz_stretch_level_end, dz_stretch_level_start,          &
+               message_string
+
     USE kinds
-    
+
     IMPLICIT NONE
-    
-    INTEGER(iwp) ::  iterations  !< number of iterations until stretch_factor_lower/upper_limit is reached  
-    INTEGER(iwp) ::  l_rounded   !< after l_rounded grid levels dz(n) is strechted to dz(n+1) with stretch_factor_2 
+
+    REAL(wp), PARAMETER ::  stretch_factor_interval = 1.0E-06_wp  !< interval for sampling possible stretching factors
+    REAL(wp), PARAMETER ::  stretch_factor_lower_limit = 0.88_wp  !< lowest possible stretching factor
+    REAL(wp), PARAMETER ::  stretch_factor_upper_limit = 1.12_wp  !< highest possible stretching factor
+
+    INTEGER(iwp) ::  iterations  !< number of iterations until stretch_factor_lower/upper_limit is reached
+    INTEGER(iwp) ::  l_rounded   !< after l_rounded grid levels dz(n) is strechted to dz(n+1) with stretch_factor_2
     INTEGER(iwp) ::  n           !< loop variable for stretching
-    
+
     INTEGER(iwp), INTENT(IN) ::  number_end !< number of user-specified end levels for stretching
-        
+
     REAL(wp) ::  delta_l               !< absolute difference between l and l_rounded
     REAL(wp) ::  delta_stretch_factor  !< absolute difference between stretch_factor_1 and stretch_factor_2
-    REAL(wp) ::  delta_total_new       !< sum of delta_l and delta_stretch_factor for the next iteration (should be as small as possible) 
-    REAL(wp) ::  delta_total_old       !< sum of delta_l and delta_stretch_factor for the last iteration 
+    REAL(wp) ::  delta_total_new       !< sum of delta_l and delta_stretch_factor for the next iteration (should be as small as
+                                       !< possible)
+    REAL(wp) ::  delta_total_old       !< sum of delta_l and delta_stretch_factor for the last iteration
     REAL(wp) ::  distance              !< distance between dz_stretch_level_start and dz_stretch_level_end (stretching region)
-    REAL(wp) ::  l                     !< value that fulfil Eq. (5) in the paper mentioned above together with stretch_factor_1 exactly
+    REAL(wp) ::  l                     !< value that fulfil Eq. (5) in the paper mentioned above together with stretch_factor_1
+                                       !< exactly
     REAL(wp) ::  numerator             !< numerator of the quotient
     REAL(wp) ::  stretch_factor_1      !< stretching factor that fulfil Eq. (5) togehter with l exactly
     REAL(wp) ::  stretch_factor_2      !< stretching factor that fulfil Eq. (6) togehter with l_rounded exactly
-    
-    REAL(wp) ::  dz_stretch_factor_array_2(9) = 1.08_wp  !< Array that contains all stretch_factor_2 that belongs to stretch_factor_1 
-    
-    REAL(wp), PARAMETER ::  stretch_factor_interval = 1.0E-06_wp  !< interval for sampling possible stretching factors
-    REAL(wp), PARAMETER ::  stretch_factor_lower_limit = 0.88_wp  !< lowest possible stretching factor
-    REAL(wp), PARAMETER ::  stretch_factor_upper_limit = 1.12_wp  !< highest possible stretching factor
- 
- 
+
+    REAL(wp) ::  dz_stretch_factor_array_2(9) = 1.08_wp  !< Array that contains all stretch_factor_2 that belongs to
+                                                         !< stretch_factor_1
+
+
     l = 0
     DO  n = 1, number_end
-    
+
        iterations = 1
-       stretch_factor_1 = 1.0_wp 
+       stretch_factor_1 = 1.0_wp
        stretch_factor_2 = 1.0_wp
        delta_total_old = 1.0_wp
-       
+
 !
 !--    First branch for stretching from rough to fine
-       IF ( dz(n) > dz(n+1) ) THEN
-          DO WHILE ( stretch_factor_1 >= stretch_factor_lower_limit ) 
-             
+       IF ( dz(n) > dz(n+1) )  THEN
+          DO WHILE ( stretch_factor_1 >= stretch_factor_lower_limit )
+
              stretch_factor_1 = 1.0_wp - iterations * stretch_factor_interval
-             distance = ABS( dz_stretch_level_end(n) -                         &
-                        dz_stretch_level_start(n) )   
-             numerator = distance*stretch_factor_1/dz(n) +                     &
-                         stretch_factor_1 - distance/dz(n)
-             
-             IF ( numerator > 0.0_wp ) THEN
+             distance = ABS( dz_stretch_level_end(n) - dz_stretch_level_start(n) )
+             numerator = distance * stretch_factor_1 / dz(n) + stretch_factor_1 - distance / dz(n)
+
+             IF ( numerator > 0.0_wp )  THEN
                 l = LOG( numerator ) / LOG( stretch_factor_1 ) - 1.0_wp
                 l_rounded = NINT( l )
                 delta_l = ABS( l_rounded - l ) / l
              ENDIF
-             
+
              stretch_factor_2 = EXP( LOG( dz(n+1)/dz(n) ) / (l_rounded) )
-             
-             delta_stretch_factor = ABS( stretch_factor_1 -                    &
-                                         stretch_factor_2 ) /                  &
-                                    stretch_factor_2
-             
+
+             delta_stretch_factor = ABS( stretch_factor_1 - stretch_factor_2 ) / stretch_factor_2
+
              delta_total_new = delta_l + delta_stretch_factor
 
 !
-!--          stretch_factor_1 is taken to guarantee that the stretching
-!--          procedure ends as close as possible to dz_stretch_level_end.
-!--          stretch_factor_2 would guarantee that the stretched dz(n) is
-!--          equal to dz(n+1) after l_rounded grid levels.
-             IF (delta_total_new < delta_total_old) THEN
+!--          stretch_factor_1 is taken to guarantee that the stretching procedure ends as close as
+!--          possible to dz_stretch_level_end.
+!--          stretch_factor_2 would guarantee that the stretched dz(n) is equal to dz(n+1) after
+!--          l_rounded grid levels.
+             IF (delta_total_new < delta_total_old)  THEN
                 dz_stretch_factor_array(n) = stretch_factor_1
                 dz_stretch_factor_array_2(n) = stretch_factor_2
                 delta_total_old = delta_total_new
              ENDIF
-             
+
              iterations = iterations + 1
-            
+
           ENDDO
 
 !
 !--    Second branch for stretching from fine to rough
-       ELSEIF ( dz(n) < dz(n+1) ) THEN 
+       ELSEIF ( dz(n) < dz(n+1) )  THEN
           DO WHILE ( stretch_factor_1 <= stretch_factor_upper_limit )
-                     
+
              stretch_factor_1 = 1.0_wp + iterations * stretch_factor_interval
-             distance = ABS( dz_stretch_level_end(n) -                         &
-                        dz_stretch_level_start(n) ) 
-             numerator = distance*stretch_factor_1/dz(n) +                     &
-                         stretch_factor_1 - distance/dz(n)
-             
+             distance = ABS( dz_stretch_level_end(n) - dz_stretch_level_start(n) )
+             numerator = distance * stretch_factor_1 / dz(n) + stretch_factor_1 - distance / dz(n)
+
              l = LOG( numerator ) / LOG( stretch_factor_1 ) - 1.0_wp
              l_rounded = NINT( l )
              delta_l = ABS( l_rounded - l ) / l
-             
+
              stretch_factor_2 = EXP( LOG( dz(n+1)/dz(n) ) / (l_rounded) )
 
-             delta_stretch_factor = ABS( stretch_factor_1 -                    &
-                                        stretch_factor_2 ) /                   &
-                                        stretch_factor_2
-             
+             delta_stretch_factor = ABS( stretch_factor_1 - stretch_factor_2 ) / stretch_factor_2
+
              delta_total_new = delta_l + delta_stretch_factor
-             
-!
-!--          stretch_factor_1 is taken to guarantee that the stretching
-!--          procedure ends as close as possible to dz_stretch_level_end.
-!--          stretch_factor_2 would guarantee that the stretched dz(n) is
-!--          equal to dz(n+1) after l_rounded grid levels.
-             IF (delta_total_new < delta_total_old) THEN
+
+!
+!--          stretch_factor_1 is taken to guarantee that the stretching procedure ends as close as
+!--          possible to dz_stretch_level_end.
+!--          stretch_factor_2 would guarantee that the stretched dz(n) is equal to dz(n+1) after
+!--          l_rounded grid levels.
+             IF (delta_total_new < delta_total_old)  THEN
                 dz_stretch_factor_array(n) = stretch_factor_1
                 dz_stretch_factor_array_2(n) = stretch_factor_2
                 delta_total_old = delta_total_new
              ENDIF
-             
+
              iterations = iterations + 1
           ENDDO
-          
+
        ELSE
           message_string= 'Two adjacent values of dz must be different'
           CALL message( 'init_grid', 'PA0228', 1, 2, 0, 6, 0 )
-          
-       ENDIF
-
-!
-!--    Check if also the second stretching factor fits into the allowed
-!--    interval. If not, print a warning for the user.
-       IF ( dz_stretch_factor_array_2(n) < stretch_factor_lower_limit .OR.     & 
-            dz_stretch_factor_array_2(n) > stretch_factor_upper_limit ) THEN
-          WRITE( message_string, * ) 'stretch_factor_2 = ',                    &
-                                     dz_stretch_factor_array_2(n), ' which is',&
-                                     ' responsible for exactly reaching& dz =',&
-                                      dz(n+1), 'after a specific amount of',   & 
-                                     ' grid levels& exceeds the upper',        &
-                                     ' limit =', stretch_factor_upper_limit,   &
-                                     ' &or lower limit = ',                    &
-                                     stretch_factor_lower_limit
+
+       ENDIF
+
+!
+!--    Check if also the second stretching factor fits into the allowed interval. If not, print a
+!--    warning for the user.
+       IF ( dz_stretch_factor_array_2(n) < stretch_factor_lower_limit  .OR.                        &
+            dz_stretch_factor_array_2(n) > stretch_factor_upper_limit )  THEN
+          WRITE( message_string, * ) 'stretch_factor_2 = ', dz_stretch_factor_array_2(n),          &
+                                     ' which is', ' responsible for exactly reaching& dz =',       &
+                                      dz(n+1), 'after a specific amount of',                       &
+                                     ' grid levels& exceeds the upper',                            &
+                                     ' limit =', stretch_factor_upper_limit,                       &
+                                     ' &or lower limit = ', stretch_factor_lower_limit
           CALL message( 'init_grid', 'PA0499', 0, 1, 0, 6, 0 )
-            
+
        ENDIF
     ENDDO
-        
+
  END SUBROUTINE calculate_stretching_factor
- 
- 
+
+
 ! Description:
-! -----------------------------------------------------------------------------!
-!> Set temporary topography flags and reference buildings on top of underlying
-!> orography. 
-!------------------------------------------------------------------------------!
+! -------------------------------------------------------------------------------------------------!
+!> Set temporary topography flags and reference buildings on top of underlying orography.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE process_topography( topo_3d )
 
-    USE arrays_3d,                                                             &
+    USE arrays_3d,                                                                                 &
         ONLY:  zu, zw
 
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  bc_lr_cyc, bc_ns_cyc, ocean_mode
 
-    USE exchange_horiz_mod,                                                    &
-        ONLY:  exchange_horiz_int, exchange_horiz_2d
-
-    USE indices,                                                               &
-        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb,  &
-               nzt
-
-    USE netcdf_data_input_mod,                                                 &
-        ONLY:  buildings_f, building_id_f, building_type_f,                    &
-               init_model,                                                     &
-               input_pids_static,                                              &
+    USE exchange_horiz_mod,                                                                        &
+        ONLY:  exchange_horiz_2d, exchange_horiz_int
+
+    USE indices,                                                                                   &
+        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb, nzt
+
+    USE netcdf_data_input_mod,                                                                     &
+        ONLY:  buildings_f, building_id_f, building_type_f,                                        &
+               init_model,                                                                         &
+               input_pids_static,                                                                  &
                terrain_height_f
 
@@ -972,5 +912,6 @@
 #endif
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids           !< building IDs on entire model domain
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_final     !< building IDs on entire model domain, multiple occurences are sorted out 
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_final     !< building IDs on entire model domain, multiple occurences are
+                                                                    !< sorted out
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_final_tmp !< temporary array used for resizing
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_l         !< building IDs on local subdomain
@@ -980,23 +921,26 @@
     INTEGER(iwp), DIMENSION(0:numprocs-1) ::  num_buildings_l   !< number of buildings with different ID on local subdomain
 
-    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  topo_3d !< input array for 3D topography and dummy array for setting "outer"-flags
-
-    REAL(wp)                            ::  ocean_offset        !< offset to consider inverse vertical coordinate at topography definition
-    REAL(wp)                            ::  oro_min = 0.0_wp    !< minimum terrain height in entire model domain, used to reference terrain to zero
+    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  topo_3d !< input array for 3D topography and dummy array for setting
+                                                                       !< "outer"-flags
+
+    REAL(wp)                            ::  ocean_offset        !< offset to consider inverse vertical coordinate at topography
+                                                                !< definition
+    REAL(wp)                            ::  oro_min = 0.0_wp    !< minimum terrain height in entire model domain, used to reference
+                                                                !< terrain to zero
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  oro_max             !< maximum terrain height occupied by an building with certain id
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  oro_max_l           !< maximum terrain height occupied by an building with certain id, on local subdomain
-
-!
-!-- Reference lowest terrain height to zero. This ensures that first, 
-!-- non-required gird levels (those which lie entirely below the minimum 
-!-- orography) are avoided, and second, that also negative orography can be used
-!-- within the input file.
-!-- Please note, in case of a nested run, the global minimum from all parent and 
-!-- childs need to be remove to avoid steep edges at the child-domain boundaries.
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  oro_max_l           !< maximum terrain height occupied by an building with certain id,
+                                                                !< on local subdomain
+
+!
+!-- Reference lowest terrain height to zero. This ensures that first, non-required gird levels
+!-- (those which lie entirely below the minimum orography) are avoided, and second, that also
+!-- negative orography can be used within the input file.
+!-- Please note, in case of a nested run, the global minimum from all parent and childs needs to be
+!-- removed to avoid steep edges at the child-domain boundaries.
     IF ( input_pids_static )  THEN
-    
-#if defined( __parallel ) 
-       CALL MPI_ALLREDUCE( MINVAL( terrain_height_f%var ), oro_min, 1,         &
-                           MPI_REAL, MPI_MIN, MPI_COMM_WORLD, ierr )
+
+#if defined( __parallel )
+       CALL MPI_ALLREDUCE( MINVAL( terrain_height_f%var ), oro_min, 1, MPI_REAL, MPI_MIN,          &
+                           MPI_COMM_WORLD, ierr )
 #else
        oro_min = MINVAL( terrain_height_f%var )
@@ -1007,54 +951,49 @@
        init_model%origin_z = init_model%origin_z + oro_min
 
-    ENDIF    
-    
-!
-!-- In the following, buildings and orography are further preprocessed 
-!-- before they are mapped on the LES grid.
-!-- Buildings are mapped on top of the orography by maintaining the roof 
-!-- shape of the building. This can be achieved by referencing building on 
-!-- top of the maximum terrain height within the area occupied by the 
-!-- respective building. As buildings and terrain height are defined PE-wise,
-!-- parallelization of this referencing is required (a building can be 
-!-- distributed between different PEs).  
-!-- In a first step, determine the number of buildings with different 
-!-- building id on each PE. In a next step, all building ids are gathered
-!-- into one array which is present to all PEs. For each building ID, 
-!-- the maximum terrain height occupied by the respective building is 
-!-- computed and distributed to each PE.  
-!-- Finally, for each building id and its respective reference orography, 
-!-- builidings are mapped on top.   
-!-- 
-!-- First, pre-set topography flags, bit 1 indicates orography, bit 2 
-!-- buildings 
-!-- classify the respective surfaces.
+    ENDIF
+
+!
+!-- In the following, buildings and orography are further preprocessed before they are mapped on the
+!-- LES grid.
+!-- Buildings are mapped on top of the orography by maintaining the roof shape of the building. This
+!-- can be achieved by referencing building on top of the maximum terrain height within the area
+!-- occupied by the respective building. As buildings and terrain height are defined PE-wise,
+!-- parallelization of this referencing is required (a building can be distributed between different
+!-- PEs).
+!-- In a first step, determine the number of buildings with different building id on each PE. In a
+!-- next step, all building ids are gathered into one array which is present to all PEs. For each
+!-- building ID, the maximum terrain height occupied by the respective building is computed and
+!-- distributed to each PE.
+!-- Finally, for each building id and its respective reference orography, builidings are mapped on
+!-- top.
+!--
+!-- First, pre-set topography flags, bit 1 indicates orography, bit 2 buildings classify the
+!-- respective surfaces.
     topo_3d          = IBSET( topo_3d, 0 )
     topo_3d(nzb,:,:) = IBCLR( topo_3d(nzb,:,:), 0 )
 !
-!-- In order to map topography on PALM grid also in case of ocean simulations,
-!-- pre-calculate an offset value.
+!-- In order to map topography on PALM grid also in case of ocean simulations, pre-calculate an
+!-- offset value.
     ocean_offset = MERGE( zw(0), 0.0_wp, ocean_mode )
 !
-!-- Reference buildings on top of orography. This is not necessary
-!-- if topography is read from ASCII file as no distinction between buildings
-!-- and terrain height can be made. Moreover, this is also not necessary if
-!-- urban-surface and land-surface model are used at the same time. 
+!-- Reference buildings on top of orography. This is not necessary if topography is read from ASCII
+!-- file as no distinction between buildings and terrain height can be made. Moreover, this is also
+!-- not necessary if urban-surface and land-surface model are used at the same time.
     IF ( input_pids_static )  THEN
 
-       IF ( buildings_f%from_file )  THEN 
+       IF ( buildings_f%from_file )  THEN
           num_buildings_l = 0
           num_buildings   = 0
 !
-!--       Allocate at least one element for building ids and give it an inital
-!--       negative value that will be overwritten later. This, however, is 
-!--       necessary in case there all IDs in the model domain are fill values. 
+!--       Allocate at least one element for building ids and give it an inital negative value that
+!--       will be overwritten later. This, however, is necessary in case there all IDs in the model
+!--       domain are fill values.
           ALLOCATE( build_ids_l(1) )
-          build_ids_l = -1 
+          build_ids_l = -1
           DO  i = nxl, nxr
              DO  j = nys, nyn
                 IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
                    IF ( num_buildings_l(myid) > 0 )  THEN
-                      IF ( ANY( building_id_f%var(j,i) ==  build_ids_l ) )   &
-                      THEN
+                      IF ( ANY( building_id_f%var(j,i) ==  build_ids_l ) )  THEN
                          CYCLE
                       ELSE
@@ -1066,12 +1005,12 @@
                       DEALLOCATE( build_ids_l )
                       ALLOCATE( build_ids_l(1:num_buildings_l(myid)) )
-                      build_ids_l(1:num_buildings_l(myid)-1) =                 &
-                                  build_ids_l_tmp(1:num_buildings_l(myid)-1)
+                      build_ids_l(1:num_buildings_l(myid)-1) =                                     &
+                                                          build_ids_l_tmp(1:num_buildings_l(myid)-1)
                       build_ids_l(num_buildings_l(myid)) = building_id_f%var(j,i)
                       DEALLOCATE( build_ids_l_tmp )
                    ENDIF
 !
-!--                First occuring building id on PE 
-                   ELSE 
+!--                First occuring building id on PE
+                   ELSE
                       num_buildings_l(myid) = num_buildings_l(myid) + 1
                       build_ids_l(1) = building_id_f%var(j,i)
@@ -1081,23 +1020,21 @@
           ENDDO
 !
-!--       Determine number of different building ids for the entire domain 
-#if defined( __parallel ) 
-          CALL MPI_ALLREDUCE( num_buildings_l, num_buildings, numprocs,              &
-                              MPI_INTEGER, MPI_SUM, comm2d, ierr ) 
+!--       Determine number of different building ids for the entire domain
+#if defined( __parallel )
+          CALL MPI_ALLREDUCE( num_buildings_l, num_buildings, numprocs, MPI_INTEGER, MPI_SUM,      &
+                              comm2d, ierr )
 #else
           num_buildings = num_buildings_l
 #endif
 !
-!--       Gather all buildings ids on each PEs. 
-!--       First, allocate array encompassing all building ids in model domain.  
+!--       Gather all buildings ids on each PEs.
+!--       First, allocate array encompassing all building ids in model domain.
           ALLOCATE( build_ids(1:SUM(num_buildings)) )
-#if defined( __parallel ) 
-!
-!--       Allocate array for displacements. 
-!--       As each PE may has a different number of buildings, so that
-!--       the block sizes send by each PE may not be equal. Hence, 
-!--       information about the respective displacement is required, indicating 
-!--       the respective adress where each MPI-task writes into the receive 
-!--       buffer array  
+#if defined( __parallel )
+!
+!--       Allocate array for displacements.
+!--       As each PE may has a different number of buildings, so that the block sizes send by each
+!--       PE may not be equal. Hence,  information about the respective displacement is required,
+!--       indicating the respective adress where each MPI-task writes into the receive buffer array.
           ALLOCATE( displace_dum(0:numprocs-1) )
           displace_dum(0) = 0
@@ -1106,12 +1043,7 @@
           ENDDO
 
-          CALL MPI_ALLGATHERV( build_ids_l(1:num_buildings_l(myid)),                 &
-                               num_buildings(myid),                                  &
-                               MPI_INTEGER,                                          &
-                               build_ids,                                            &
-                               num_buildings,                                        &
-                               displace_dum,                                         & 
-                               MPI_INTEGER,                                          &
-                               comm2d, ierr )   
+          CALL MPI_ALLGATHERV( build_ids_l(1:num_buildings_l(myid)), num_buildings(myid),          &
+                               MPI_INTEGER, build_ids, num_buildings, displace_dum, MPI_INTEGER,   &
+                               comm2d, ierr )
 
           DEALLOCATE( displace_dum )
@@ -1122,7 +1054,6 @@
 
 !
-!--       Note, in parallel mode building ids can occure mutliple times, as 
-!--       each PE has send its own ids. Therefore, sort out building ids which 
-!--       appear more than one time. 
+!--       Note, in parallel mode building ids can occure mutliple times, as each PE has send its own
+!--       ids. Therefore, sort out building ids which appear more than one time.
           num_build = 0
           DO  nr = 1, SIZE(build_ids)
@@ -1142,5 +1073,5 @@
                    build_ids_final(num_build) = build_ids(nr)
                    DEALLOCATE( build_ids_final_tmp )
-                ENDIF             
+                ENDIF
              ELSE
                 num_build = num_build + 1
@@ -1151,6 +1082,6 @@
 
 !
-!--       Determine maximumum terrain height occupied by the respective 
-!--       building and temporalily store on oro_max 
+!--       Determine maximumum terrain height occupied by the respective building and temporalily
+!--       store on oro_max.
           ALLOCATE( oro_max_l(1:SIZE(build_ids_final)) )
           ALLOCATE( oro_max(1:SIZE(build_ids_final))   )
@@ -1158,15 +1089,14 @@
 
           DO  nr = 1, SIZE(build_ids_final)
-             oro_max_l(nr) = MAXVAL(                                           &
-                              MERGE( terrain_height_f%var(nys:nyn,nxl:nxr),    &
-                                     0.0_wp,                                   &
-                                     building_id_f%var(nys:nyn,nxl:nxr) ==     &
-                                     build_ids_final(nr) ) )
-          ENDDO
-   
-#if defined( __parallel )    
-          IF ( SIZE(build_ids_final) >= 1 ) THEN
-             CALL MPI_ALLREDUCE( oro_max_l, oro_max, SIZE( oro_max ), MPI_REAL,&
-                                 MPI_MAX, comm2d, ierr ) 
+             oro_max_l(nr) = MAXVAL( MERGE( terrain_height_f%var(nys:nyn,nxl:nxr),                 &
+                                              0.0_wp,                                              &
+                                              building_id_f%var(nys:nyn,nxl:nxr) ==                &
+                                              build_ids_final(nr) ) )
+          ENDDO
+
+#if defined( __parallel )
+          IF ( SIZE(build_ids_final) >= 1 )  THEN
+             CALL MPI_ALLREDUCE( oro_max_l, oro_max, SIZE( oro_max ), MPI_REAL, MPI_MAX, comm2d,   &
+                                 ierr )
           ENDIF
 #else
@@ -1174,14 +1104,12 @@
 #endif
 !
-!--       Finally, determine discrete grid height of maximum orography occupied
-!--       by a building. Use all-or-nothing approach, i.e. if terrain
-!--       exceeds the scalar level the grid box is fully terrain and the 
-!--       maximum terrain is set to the zw level. 
-!--       terrain or 
+!--       Finally, determine discrete grid height of maximum orography occupied by a building. Use
+!--       all-or-nothing approach, i.e. if terrain exceeds the scalar level the grid box is fully
+!--       terrain and the maximum terrain is set to the zw level.
+!--       terrain or
           oro_max_l = 0.0
           DO  nr = 1, SIZE(build_ids_final)
              DO  k = nzb, nzt
-                IF ( zu(k) - ocean_offset <= oro_max(nr) )                     &
-                   oro_max_l(nr) = zw(k) - ocean_offset
+                IF ( zu(k) - ocean_offset <= oro_max(nr) )  oro_max_l(nr) = zw(k) - ocean_offset
              ENDDO
              oro_max(nr) = oro_max_l(nr)
@@ -1195,5 +1123,5 @@
        END IF
 !
-!--    Map orography as well as buildings onto grid. 
+!--    Map orography as well as buildings onto grid.
        DO  i = nxl, nxr
           DO  j = nys, nyn
@@ -1204,8 +1132,7 @@
                 IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
 !
-!--                Determine index where maximum terrain height occupied by 
-!--                the respective building height is stored.
-                   nr = MINLOC( ABS( build_ids_final -                         &
-                                     building_id_f%var(j,i) ), DIM = 1 )
+!--                Determine index where maximum terrain height occupied by the respective building
+!--                height is stored.
+                   nr = MINLOC( ABS( build_ids_final - building_id_f%var(j,i) ), DIM=1 )
 !
 !--                Save grid-indexed oro_max
@@ -1215,10 +1142,9 @@
              DO  k = nzb, nzt
 !
-!--             In a first step, if grid point is below or equal the given 
-!--             terrain height, grid point is flagged to be of type natural. 
-!--             Please note, in case there is also a building which is lower
-!--             than the vertical grid spacing, initialization of surface
-!--             attributes will not be correct as given surface information
-!--             will not be in accordance to the classified grid points. 
+!--             In a first step, if grid point is below or equal the given terrain height, grid
+!--             point is flagged to be of type natural.
+!--             Please note, in case there is also a building which is lower than the vertical grid
+!--             spacing, initialization of surface attributes will not be correct as given surface
+!--             information will not be in accordance to the classified grid points.
 !--             Hence, in this case, also a building flag.
                 IF ( zu(k) - ocean_offset <= terrain_height_f%var(j,i) )  THEN
@@ -1228,18 +1154,17 @@
                 ENDIF
 !
-!--             Set building grid points. Here, only consider 2D buildings. 
-!--             3D buildings require separate treatment. 
+!--             Set building grid points. Here, only consider 2D buildings.
+!--             3D buildings require separate treatment.
                 IF ( buildings_f%from_file  .AND.  buildings_f%lod == 1 )  THEN
 !
-!--                Fill-up the terrain to the level of maximum orography
-!--                within the building-covered area.
+!--                Fill-up the terrain to the level of maximum orography within the building-covered
+!--                area.
                    IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
 !
-!--                   Note, oro_max is always on zw level                   
+!--                   Note, oro_max is always on zw level
                       IF ( zu(k) - ocean_offset < oro_max(nr) )  THEN
                          topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 )
                          topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 1 )
-                      ELSEIF ( zu(k) - ocean_offset <=                         &
-                               oro_max(nr) + buildings_f%var_2d(j,i) )  THEN
+                      ELSEIF ( zu(k) - ocean_offset <= oro_max(nr) + buildings_f%var_2d(j,i) )  THEN
                          topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 )
                          topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 )
@@ -1249,12 +1174,10 @@
              ENDDO
 !
-!--          Special treatment for non grid-resolved buildings. This case,
-!--          the uppermost terrain grid point is flagged as building as well
-!--          well, even though no building exists at all. However, the 
-!--          surface element will be identified as urban-surface and the 
-!--          input data provided by the drivers is consistent to the surface
-!--          classification. Else, all non grid-resolved buildings would vanish
-!--          and identified as terrain grid points, which, however, won't be
-!--          consistent with the input data. 
+!--          Special treatment for non grid-resolved buildings. This case, the uppermost terrain
+!--          grid point is flagged as building as well, even though no building exists at all.
+!--          However, the surface element will be identified as urban-surface and the input data
+!--          provided by the drivers is consistent to the surface classification. Else, all non
+!--          grid-resolved buildings would vanish and identified as terrain grid points, which,
+!--          however, won't be consistent with the input data.
              IF ( buildings_f%from_file  .AND.  buildings_f%lod == 1 )  THEN
                 IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
@@ -1269,35 +1192,32 @@
              ENDIF
 !
-!--          Map 3D buildings onto terrain height.  
-!--          In case of any slopes, map building on top of maximum terrain 
-!--          height covered by the building. In other words, extend 
-!--          building down to the respective local terrain-surface height. 
+!--          Map 3D buildings onto terrain height.
+!--          In case of any slopes, map building on top of maximum terrain height covered by the
+!--          building. In other words, extend building down to the respective local terrain-surface
+!--          height.
              IF ( buildings_f%from_file  .AND.  buildings_f%lod == 2 )  THEN
                 IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
 !
-!--                Extend building down to the terrain surface, i.e. fill-up
-!--                surface irregularities below a building. Note, oro_max
-!--                is already a discrete height according to the all-or-nothing
-!--                approach, i.e. grid box is either topography or atmosphere, 
+!--                Extend building down to the terrain surface, i.e. fill-up surface irregularities
+!--                below a building. Note, oro_max is already a discrete height according to the
+!--                all-or-nothing approach, i.e. grid box is either topography or atmosphere,
 !--                terrain top is defined at upper bound of the grid box.
-!--                Hence, check for zw in this case. 
-!--                Note, do this only for buildings which are surface mounted, 
-!--                i.e. building types 1-6. Below bridges, which are represented
-!--                exclusively by building type 7, terrain shape should be
-!--                maintained. 
+!--                Hence, check for zw in this case.
+!--                Note, do this only for buildings which are surface mounted, i.e. building types
+!--                1-6. Below bridges, which are represented exclusively by building type 7, terrain
+!--                shape should be maintained.
                    IF ( building_type_f%from_file )  THEN
                       IF ( building_type_f%var(j,i) /= 7 )  THEN
-                         DO k = topo_top_index + 1, nzt + 1      
+                         DO k = topo_top_index + 1, nzt + 1
                             IF ( zu(k) - ocean_offset <= oro_max(nr) )  THEN
                                topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 )
                                topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 1 )
                             ENDIF
-                         ENDDO        
-!                     
-!--                      After surface irregularities are smoothen, determine 
-!--                      lower start index where building starts. 
+                         ENDDO
+!
+!--                      After surface irregularities are smoothen, determine lower start index
+!--                      where building starts.
                          DO  k = nzb, nzt
-                            IF ( zu(k) - ocean_offset <= oro_max(nr) )         &
-                               topo_top_index = k
+                            IF ( zu(k) - ocean_offset <= oro_max(nr) )  topo_top_index = k
                          ENDDO
                       ENDIF
@@ -1320,6 +1240,6 @@
        ENDDO
 !
-!--    Horizontal exchange the oro_max array, which is required to for
-!--    initialization of building-surface properties.
+!--    Horizontal exchange the oro_max array, which is required to for initialization of
+!--    building-surface properties.
        IF ( ALLOCATED( buildings_f%oro_max ) )  THEN
           CALL exchange_horiz_2d( buildings_f%oro_max(:,:) )
@@ -1331,14 +1251,13 @@
        IF ( ALLOCATED( build_ids_final ) )  DEALLOCATE( build_ids_final )
 !
-!-- Topography input via ASCII format. 
+!-- Topography input via ASCII format.
     ELSE
        ocean_offset     = MERGE( zw(0), 0.0_wp, ocean_mode )
 !
-!--    Initialize topography bit 0 (indicates obstacle) everywhere to zero
-!--    and clear all grid points at nzb, where alway a surface is defined.
-!--    Further, set also bit 1 (indicates terrain) at nzb, which is further
-!--    used for masked data output and further processing. Note, in the 
-!--    ASCII case no distinction is made between buildings and terrain, 
-!--    so that setting of bit 1 and 2 at the same time has no effect. 
+!--    Initialize topography bit 0 (indicates obstacle) everywhere to zero and clear all grid points
+!--    at nzb, where alway a surface is defined.
+!--    Further, set also bit 1 (indicates terrain) at nzb, which is further used for masked data
+!--    output and further processing. Note, in the ASCII case no distinction is made between
+!--    buildings and terrain,  so that setting of bit 1 and 2 at the same time has no effect.
        topo_3d          = IBSET( topo_3d, 0 )
        topo_3d(nzb,:,:) = IBCLR( topo_3d(nzb,:,:), 0 )
@@ -1348,9 +1267,7 @@
              DO  k = nzb, nzt
 !
-!--             Flag topography for all grid points which are below
-!--             the local topography height. 
-!--             Note, each topography is flagged as building (bit 2) as well as 
-!--             terrain (bit 1) in order to employ urban-surface as well as 
-!--             land-surface model.
+!--             Flag topography for all grid points which are below the local topography height.
+!--             Note, each topography is flagged as building (bit 2) as well as terrain (bit 1) in
+!--             order to employ urban-surface as well as land-surface model.
                 IF ( zu(k) - ocean_offset <= buildings_f%var_2d(j,i) )  THEN
                    topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 )
@@ -1372,5 +1289,5 @@
     IF ( .NOT. bc_lr_cyc )  THEN
        IF ( nxl == 0  )  topo_3d(:,:,-1)   = topo_3d(:,:,0)
-       IF ( nxr == nx )  topo_3d(:,:,nx+1) = topo_3d(:,:,nx)          
+       IF ( nxr == nx )  topo_3d(:,:,nx+1) = topo_3d(:,:,nx)
     ENDIF
 
@@ -1379,42 +1296,44 @@
 
 ! Description:
-! -----------------------------------------------------------------------------!
-!> Filter topography, i.e. fill holes resolved by only one grid point.  
-!> Such holes are suspected to lead to velocity blow-ups as continuity 
-!> equation on discrete grid cannot be fulfilled in such case.
-!------------------------------------------------------------------------------!
+! -------------------------------------------------------------------------------------------------!
+!> Filter topography, i.e. fill holes resolved by only one grid point.
+!> Such holes are suspected to lead to velocity blow-ups as continuity equation on discrete grid
+!> cannot be fulfilled in such case.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE filter_topography( topo_3d )
 
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  bc_lr_cyc, bc_ns_cyc, message_string
 
-    USE exchange_horiz_mod,                                                    &
+    USE exchange_horiz_mod,                                                                        &
         ONLY:  exchange_horiz_int, exchange_horiz_2d_byte, exchange_horiz_2d_int
 
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb, nzt
 
-    USE netcdf_data_input_mod,                                                 &
-        ONLY:  building_id_f, building_type_f 
+    USE netcdf_data_input_mod,                                                                     &
+        ONLY:  building_id_f, building_type_f
 
     USE  pegrid
 
     IMPLICIT NONE
-
-    LOGICAL      ::  filled = .FALSE. !< flag indicating if holes were filled
 
     INTEGER(iwp) ::  i          !< running index along x-direction
     INTEGER(iwp) ::  j          !< running index along y-direction
     INTEGER(iwp) ::  k          !< running index along z-direction
-    INTEGER(iwp) ::  num_hole   !< number of holes (in topography) resolved by only one grid point 
-    INTEGER(iwp) ::  num_hole_l !< number of holes (in topography) resolved by only one grid point on local PE     
+    INTEGER(iwp) ::  num_hole   !< number of holes (in topography) resolved by only one grid point
+    INTEGER(iwp) ::  num_hole_l !< number of holes (in topography) resolved by only one grid point on local PE
     INTEGER(iwp) ::  num_wall   !< number of surrounding vertical walls for a single grid point
 
     INTEGER(iwp), DIMENSION(:,:,:), ALLOCATABLE            ::  topo_tmp          !< temporary 3D-topography used to fill holes
-    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  topo_3d           !< 3D-topography array merging buildings and orography
-!
-!-- Before checking for holes, set lateral boundary conditions for 
+    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  topo_3d           !< 3D-topography array merging buildings and
+                                                                                 !< orography
+
+    LOGICAL      ::  filled = .FALSE. !< flag indicating if holes were filled
+
+!
+!-- Before checking for holes, set lateral boundary conditions for
 !-- topography. After hole-filling, boundary conditions must be set again.
-!-- Several iterations are performed, in order to fill holes which might 
+!-- Several iterations are performed, in order to fill holes which might
 !-- emerge by the filling-algorithm itself.
     ALLOCATE( topo_tmp(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
@@ -1422,21 +1341,20 @@
 
     num_hole = 99999
-    DO WHILE ( num_hole > 0 )       
-
-       num_hole = 0    
+    DO WHILE ( num_hole > 0 )
+
+       num_hole = 0
        CALL exchange_horiz_int( topo_3d, nys, nyn, nxl, nxr, nzt, nbgp )
 !
-!--    Exchange also building ID and type. Note, building_type is an one-byte 
-!--    variable.
-       IF ( building_id_f%from_file )                                          &
+!--    Exchange also building ID and type. Note, building_type is an one-byte variable.
+       IF ( building_id_f%from_file )                                                              &
           CALL exchange_horiz_2d_int( building_id_f%var, nys, nyn, nxl, nxr, nbgp )
-       IF ( building_type_f%from_file )                                        &
+       IF ( building_type_f%from_file )                                                            &
           CALL exchange_horiz_2d_byte( building_type_f%var, nys, nyn, nxl, nxr, nbgp )
 
        topo_tmp = topo_3d
 !
-!--    In case of non-cyclic lateral boundaries, assume lateral boundary to be 
-!--    a solid wall. Thus, intermediate spaces of one grid point between 
-!--    boundary and some topographic structure will be filled.           
+!--    In case of non-cyclic lateral boundaries, assume lateral boundary to be a solid wall. Thus,
+!--    intermediate spaces of one grid point between boundary and some topographic structure will be
+!--    filled.
        IF ( .NOT. bc_ns_cyc )  THEN
           IF ( nys == 0  )  topo_tmp(:,-1,:)   = IBCLR( topo_tmp(:,0,:),  0 )
@@ -1446,5 +1364,5 @@
        IF ( .NOT. bc_lr_cyc )  THEN
           IF ( nxl == 0  )  topo_tmp(:,:,-1)   = IBCLR( topo_tmp(:,:,0),  0 )
-          IF ( nxr == nx )  topo_tmp(:,:,nx+1) = IBCLR( topo_tmp(:,:,nx), 0 )          
+          IF ( nxr == nx )  topo_tmp(:,:,nx+1) = IBCLR( topo_tmp(:,:,nx), 0 )
        ENDIF
 
@@ -1455,73 +1373,48 @@
                 IF ( BTEST( topo_tmp(k,j,i), 0 ) )  THEN
                    num_wall = 0
-                   IF ( .NOT. BTEST( topo_tmp(k,j-1,i), 0 ) )                  &
-                      num_wall = num_wall + 1
-                   IF ( .NOT. BTEST( topo_tmp(k,j+1,i), 0 ) )                  &
-                      num_wall = num_wall + 1
-                   IF ( .NOT. BTEST( topo_tmp(k,j,i-1), 0 ) )                  &
-                      num_wall = num_wall + 1
-                   IF ( .NOT. BTEST( topo_tmp(k,j,i+1), 0 ) )                  &
-                      num_wall = num_wall + 1
-                   IF ( .NOT. BTEST( topo_tmp(k-1,j,i), 0 ) )                  &
-                      num_wall = num_wall + 1   
-                   IF ( .NOT. BTEST( topo_tmp(k+1,j,i), 0 ) )                  &
-                      num_wall = num_wall + 1
+                   IF ( .NOT. BTEST( topo_tmp(k,j-1,i), 0 ) )  num_wall = num_wall + 1
+                   IF ( .NOT. BTEST( topo_tmp(k,j+1,i), 0 ) )  num_wall = num_wall + 1
+                   IF ( .NOT. BTEST( topo_tmp(k,j,i-1), 0 ) )  num_wall = num_wall + 1
+                   IF ( .NOT. BTEST( topo_tmp(k,j,i+1), 0 ) )  num_wall = num_wall + 1
+                   IF ( .NOT. BTEST( topo_tmp(k-1,j,i), 0 ) )  num_wall = num_wall + 1
+                   IF ( .NOT. BTEST( topo_tmp(k+1,j,i), 0 ) )  num_wall = num_wall + 1
 
                    IF ( num_wall >= 4 )  THEN
                       num_hole_l     = num_hole_l + 1
 !
-!--                   Clear flag 0 and set special flag ( bit 4) to indicate 
-!--                   that new topography point is a result of filtering process.
+!--                   Clear flag 0 and set special flag ( bit 4) to indicate that new topography
+!--                   point is a result of filtering process.
                       topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 )
                       topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 4 )
 !
-!--                   If filled grid point is occupied by a building, classify
-!--                   it as building grid point.
+!--                   If filled grid point is occupied by a building, classify it as building grid
+!--                   point.
                       IF ( building_type_f%from_file )  THEN
-                         IF ( building_type_f%var(j,i)   /=                    &  
-                              building_type_f%fill            .OR.             &       
-                              building_type_f%var(j+1,i) /=                    &  
-                              building_type_f%fill            .OR.             &                
-                              building_type_f%var(j-1,i) /=                    &                
-                              building_type_f%fill            .OR.             &                
-                              building_type_f%var(j,i+1) /=                    &                
-                              building_type_f%fill            .OR.             &                
-                              building_type_f%var(j,i-1) /=                    &                
-                              building_type_f%fill )  THEN
+                         IF ( building_type_f%var(j,i)   /=  building_type_f%fill  .OR.            &
+                              building_type_f%var(j+1,i) /=  building_type_f%fill  .OR.            &
+                              building_type_f%var(j-1,i) /=  building_type_f%fill  .OR.            &
+                              building_type_f%var(j,i+1) /=  building_type_f%fill  .OR.            &
+                              building_type_f%var(j,i-1) /=  building_type_f%fill )  THEN
 !
 !--                         Set flag indicating building surfaces
                             topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 )
 !
-!--                         Set building_type and ID at this position if not 
-!--                         already set. This is required for proper 
-!--                         initialization of urban-surface energy balance 
+!--                         Set building_type and ID at this position if not already set. This is
+!--                         required for proper initialization of urban-surface energy balance
 !--                         solver.
-                            IF ( building_type_f%var(j,i) ==                   &
-                                 building_type_f%fill )  THEN
-
-                               IF ( building_type_f%var(j+1,i) /=              &
-                                    building_type_f%fill )  THEN
-                                  building_type_f%var(j,i) =                   &
-                                                    building_type_f%var(j+1,i)
-                                  building_id_f%var(j,i) =                     &
-                                                    building_id_f%var(j+1,i)
-                               ELSEIF ( building_type_f%var(j-1,i) /=          &
-                                        building_type_f%fill )  THEN
-                                  building_type_f%var(j,i) =                   &
-                                                    building_type_f%var(j-1,i)
-                                  building_id_f%var(j,i) =                     &
-                                                    building_id_f%var(j-1,i)
-                               ELSEIF ( building_type_f%var(j,i+1) /=          &
-                                        building_type_f%fill )  THEN
-                                  building_type_f%var(j,i) =                   &
-                                                    building_type_f%var(j,i+1)
-                                  building_id_f%var(j,i) =                     &
-                                                    building_id_f%var(j,i+1)
-                               ELSEIF ( building_type_f%var(j,i-1) /=          &
-                                        building_type_f%fill )  THEN
-                                  building_type_f%var(j,i) =                   &
-                                                    building_type_f%var(j,i-1)
-                                  building_id_f%var(j,i) =                     &
-                                                    building_id_f%var(j,i-1)
+                            IF ( building_type_f%var(j,i) == building_type_f%fill )  THEN
+
+                               IF ( building_type_f%var(j+1,i) /= building_type_f%fill )  THEN
+                                  building_type_f%var(j,i) = building_type_f%var(j+1,i)
+                                  building_id_f%var(j,i)   = building_id_f%var(j+1,i)
+                               ELSEIF ( building_type_f%var(j-1,i) /= building_type_f%fill )  THEN
+                                  building_type_f%var(j,i) = building_type_f%var(j-1,i)
+                                  building_id_f%var(j,i)   = building_id_f%var(j-1,i)
+                               ELSEIF ( building_type_f%var(j,i+1) /= building_type_f%fill )  THEN
+                                  building_type_f%var(j,i) = building_type_f%var(j,i+1)
+                                  building_id_f%var(j,i)   = building_id_f%var(j,i+1)
+                               ELSEIF ( building_type_f%var(j,i-1) /= building_type_f%fill )  THEN
+                                  building_type_f%var(j,i) = building_type_f%var(j,i-1)
+                                  building_id_f%var(j,i)   = building_id_f%var(j,i-1)
                                ENDIF
                             ENDIF
@@ -1529,8 +1422,7 @@
                       ENDIF
 !
-!--                   If filled grid point is already classified as building
-!--                   everything is fine, else classify this grid point as
-!--                   natural type grid point. This case, values for the 
-!--                   surface type are already set.
+!--                   If filled grid point is already classified as building everything is fine,
+!--                   else classify this grid point as natural type grid point. This case, values
+!--                   for the surface type are already set.
                       IF ( .NOT. BTEST( topo_3d(k,j,i), 2 ) )  THEN
                          topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 1 )
@@ -1544,9 +1436,8 @@
 !--    Count the total number of holes, required for informative message.
 #if defined( __parallel )
-       CALL MPI_ALLREDUCE( num_hole_l, num_hole, 1, MPI_INTEGER, MPI_SUM,      &
-                           comm2d, ierr )
+       CALL MPI_ALLREDUCE( num_hole_l, num_hole, 1, MPI_INTEGER, MPI_SUM, comm2d, ierr )
 #else
        num_hole = num_hole_l
-#endif    
+#endif
        IF ( num_hole > 0  .AND.  .NOT. filled )  filled = .TRUE.
 
@@ -1555,6 +1446,6 @@
 !-- Create an informative message if any holes were filled.
     IF ( filled )  THEN
-       WRITE( message_string, * ) 'Topography was filtered, i.e. holes ' //    &
-                                  'resolved by only one grid point '     //    &
+       WRITE( message_string, * ) 'Topography was filtered, i.e. holes ' //                        &
+                                  'resolved by only one grid point '     //                        &
                                   'were filled during initialization.'
        CALL message( 'init_grid', 'PA0430', 0, 0, 0, 6, 0 )
@@ -1563,6 +1454,6 @@
     DEALLOCATE( topo_tmp )
 !
-!-- Finally, exchange topo_3d array again and if necessary set Neumann boundary
-!-- condition in case of non-cyclic lateral boundaries. 
+!-- Finally, exchange topo_3d array again and if necessary set Neumann boundary condition in case of
+!-- non-cyclic lateral boundaries.
     CALL exchange_horiz_int( topo_3d, nys, nyn, nxl, nxr, nzt, nbgp )
 
@@ -1574,11 +1465,11 @@
     IF ( .NOT. bc_lr_cyc )  THEN
        IF ( nxl == 0  )  topo_3d(:,:,-1)   = topo_3d(:,:,0)
-       IF ( nxr == nx )  topo_3d(:,:,nx+1) = topo_3d(:,:,nx)          
+       IF ( nxr == nx )  topo_3d(:,:,nx+1) = topo_3d(:,:,nx)
     ENDIF
 !
 !-- Exchange building ID and type. Note, building_type is an one-byte variable.
-    IF ( building_id_f%from_file )                                             &
+    IF ( building_id_f%from_file )                                                                 &
        CALL exchange_horiz_2d_int( building_id_f%var, nys, nyn, nxl, nxr, nbgp )
-    IF ( building_type_f%from_file )                                           &
+    IF ( building_type_f%from_file )                                                               &
        CALL exchange_horiz_2d_byte( building_type_f%var, nys, nyn, nxl, nxr, nbgp )
 
@@ -1587,37 +1478,33 @@
 
 ! Description:
-! -----------------------------------------------------------------------------!
-!> Reads topography information from file or sets generic topography. Moreover, 
-!> all topography-relevant topography arrays are initialized, and grid flags
-!> are set.  
-!------------------------------------------------------------------------------!
+! -------------------------------------------------------------------------------------------------!
+!> Reads topography information from file or sets generic topography. Moreover, all
+!> topography-relevant topography arrays are initialized, and grid flags are set.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE init_topo( topo )
 
-    USE arrays_3d,                                                             &
+    USE arrays_3d,                                                                                 &
         ONLY:  zw
-        
-    USE control_parameters,                                                    &
-        ONLY:  bc_lr_cyc, bc_ns_cyc, building_height, building_length_x,       &
-               building_length_y, building_wall_left, building_wall_south,     &
-               canyon_height, canyon_wall_left, canyon_wall_south,             &
-               canyon_width_x, canyon_width_y, dp_level_ind_b, dz,             &
-               message_string, topography, topography_grid_convention,         &
-               tunnel_height, tunnel_length, tunnel_width_x, tunnel_width_y,   &
-               tunnel_wall_depth
-         
-    USE exchange_horiz_mod,                                                    &
+
+    USE control_parameters,                                                                        &
+        ONLY:  bc_lr_cyc, bc_ns_cyc, building_height, building_length_x, building_length_y,        &
+               building_wall_left, building_wall_south, canyon_height, canyon_wall_left,           &
+               canyon_wall_south, canyon_width_x, canyon_width_y, dp_level_ind_b, dz,              &
+               message_string, topography, topography_grid_convention, tunnel_height,              &
+               tunnel_length, tunnel_width_x, tunnel_width_y, tunnel_wall_depth
+
+    USE exchange_horiz_mod,                                                                        &
         ONLY:  exchange_horiz_int
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                                            &
         ONLY:  dx, dy
-        
-    USE indices,                                                               &
-        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nz,   &
-               nzb, nzt
-    
+
+    USE indices,                                                                                   &
+        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nz, nzb, nzt
+
     USE kinds
-    
-    USE netcdf_data_input_mod,                                                 &
-        ONLY:  buildings_f, terrain_height_f 
+
+    USE netcdf_data_input_mod,                                                                     &
+        ONLY:  buildings_f, terrain_height_f
 
     USE pegrid
@@ -1626,64 +1513,62 @@
 
     INTEGER(iwp) ::  bh                !< temporary vertical index of building height
+    INTEGER(iwp) ::  ch                !< temporary vertical index for canyon height
+    INTEGER(iwp) ::  hv_in             !< heavyside function to model inner tunnel surface
+    INTEGER(iwp) ::  i                 !< index variable along x
+    INTEGER(iwp) ::  index_left_bwall  !< index for left building wall
+    INTEGER(iwp) ::  index_north_bwall !< index for north building wall
+    INTEGER(iwp) ::  index_right_bwall !< index for right building wall
+    INTEGER(iwp) ::  index_south_bwall !< index for south building wall
+    INTEGER(iwp) ::  index_left_cwall  !< index for left canyon wall
+    INTEGER(iwp) ::  index_north_cwall !< index for north canyon wall
+    INTEGER(iwp) ::  index_right_cwall !< index for right canyon wall
+    INTEGER(iwp) ::  index_south_cwall !< index for south canyon wall
+    INTEGER(iwp) ::  j                 !< index variable along y
+    INTEGER(iwp) ::  k                 !< index variable along z
     INTEGER(iwp) ::  ngp_bx            !< grid point number of building size along x
     INTEGER(iwp) ::  ngp_by            !< grid point number of building size along y
-    INTEGER(iwp) ::  index_left_bwall  !< index for left building wall
-    INTEGER(iwp) ::  index_right_bwall !< index for right building wall
-    INTEGER(iwp) ::  index_north_bwall !< index for north building wall
-    INTEGER(iwp) ::  index_south_bwall !< index for south building wall
-    INTEGER(iwp) ::  ch                !< temporary vertical index for canyon height
     INTEGER(iwp) ::  ngp_cx            !< grid point number of canyon size along x
     INTEGER(iwp) ::  ngp_cy            !< grid point number of canyon size along y
-    INTEGER(iwp) ::  index_left_cwall  !< index for left canyon wall
-    INTEGER(iwp) ::  index_right_cwall !< index for right canyon wall
-    INTEGER(iwp) ::  index_north_cwall !< index for north canyon wall
-    INTEGER(iwp) ::  index_south_cwall !< index for south canyon wall
-    INTEGER(iwp) ::  i                 !< index variable along x
-    INTEGER(iwp) ::  j                 !< index variable along y
-    INTEGER(iwp) ::  k                 !< index variable along z
-    INTEGER(iwp) ::  hv_in             !< heavyside function to model inner tunnel surface 
-    INTEGER(iwp) ::  hv_out            !< heavyside function to model outer tunnel surface 
-    INTEGER(iwp) ::  txe_out           !< end position of outer tunnel wall in x
-    INTEGER(iwp) ::  txs_out           !< start position of outer tunnel wall in x
-    INTEGER(iwp) ::  tye_out           !< end position of outer tunnel wall in y
-    INTEGER(iwp) ::  tys_out           !< start position of outer tunnel wall in y
-    INTEGER(iwp) ::  txe_in            !< end position of inner tunnel wall in x
-    INTEGER(iwp) ::  txs_in            !< start position of inner tunnel wall in x
-    INTEGER(iwp) ::  tye_in            !< end position of inner tunnel wall in y
-    INTEGER(iwp) ::  tys_in            !< start position of inner tunnel wall in y
+    INTEGER(iwp) ::  hv_out            !< heavyside function to model outer tunnel surface
     INTEGER(iwp) ::  td                !< tunnel wall depth
     INTEGER(iwp) ::  th                !< height of outer tunnel wall
+    INTEGER(iwp) ::  txe_in            !< end position of inner tunnel wall in x
+    INTEGER(iwp) ::  txe_out           !< end position of outer tunnel wall in x
+    INTEGER(iwp) ::  txs_in            !< start position of inner tunnel wall in x
+    INTEGER(iwp) ::  txs_out           !< start position of outer tunnel wall in x
+    INTEGER(iwp) ::  tye_in            !< end position of inner tunnel wall in y
+    INTEGER(iwp) ::  tye_out           !< end position of outer tunnel wall in y
+    INTEGER(iwp) ::  tys_in            !< start position of inner tunnel wall in y
+    INTEGER(iwp) ::  tys_out           !< start position of outer tunnel wall in y
 
     INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  nzb_local         !< index for topography top at cell-center
-    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  topo !< input array for 3D topography and dummy array for setting "outer"-flags
-!
-!-- Check for correct setting of the namelist parameter topography. If 
-!-- topography information is read from file but topography = 'flat', 
-!-- initialization does not work properly.
-    IF ( ( buildings_f%from_file  .OR.  terrain_height_f%from_file )  .AND.    &
+    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  topo !< input array for 3D topography and dummy array for setting
+                                                                    !< "outer"-flags
+!
+!-- Check for correct setting of the namelist parameter topography. If topography information is
+!-- read from file but topography = 'flat', initialization does not work properly.
+    IF ( ( buildings_f%from_file  .OR.  terrain_height_f%from_file )  .AND.                        &
            TRIM( topography ) /= 'read_from_file' )  THEN
-       message_string =  'If topography information is provided (via ' //      &
-                         'Netcdf or ASCII input) topography = '        //      &
+       message_string =  'If topography information is provided (via ' //                          &
+                         'Netcdf or ASCII input) topography = '        //                          &
                          '"read_from_file" is required.'
-       CALL message( 'init_grid', 'PA0437', 1, 2, 0, 6, 0 )      
+       CALL message( 'init_grid', 'PA0437', 1, 2, 0, 6, 0 )
     ENDIF
 !
 !-- Set outer and inner index arrays for non-flat topography.
-!-- Here consistency checks concerning domain size and periodicity are
-!-- necessary.
-!-- Within this SELECT CASE structure only nzb_local is initialized
-!-- individually depending on the chosen topography type, all other index 
-!-- arrays are initialized further below.
+!-- Here consistency checks concerning domain size and periodicity are necessary.
+!-- Within this SELECT CASE structure only nzb_local is initialized individually depending on the
+!-- chosen topography type, all other index arrays are initialized further below.
     SELECT CASE ( TRIM( topography ) )
 
        CASE ( 'flat' )
-!   
+!
 !--       Initialilize 3D topography array, used later for initializing flags
           topo(nzb+1:nzt+1,:,:) = IBSET( topo(nzb+1:nzt+1,:,:), 0 )
-          
+
        CASE ( 'closed_channel' )
-!   
+!
 !--       Initialilize 3D topography array, used later for initializing flags
-          topo(nzb+1:nzt,:,:) = IBSET( topo(nzb+1:nzt,:,:), 0 ) 
+          topo(nzb+1:nzt,:,:) = IBSET( topo(nzb+1:nzt,:,:), 0 )
 
        CASE ( 'single_building' )
@@ -1694,6 +1579,5 @@
           ngp_by = NINT( building_length_y / dy )
           bh  = MINLOC( ABS( zw - building_height ), 1 ) - 1
-          IF ( ABS( zw(bh)   - building_height ) == &
-               ABS( zw(bh+1) - building_height )    )  bh = bh + 1
+          IF ( ABS( zw(bh) - building_height ) ==  ABS( zw(bh+1) - building_height ) )  bh = bh + 1
           IF ( building_wall_left == 9999999.9_wp )  THEN
              building_wall_left = ( nx + 1 - ngp_bx ) / 2 * dx
@@ -1710,13 +1594,13 @@
 !
 !--       Building size has to meet some requirements
-          IF ( ( index_left_bwall < 1 ) .OR. ( index_right_bwall > nx-1 ) .OR. &
-               ( index_right_bwall < index_left_bwall+3 ) .OR.                 &
-               ( index_south_bwall < 1 ) .OR. ( index_north_bwall > ny-1 ) .OR.&
+          IF ( ( index_left_bwall  < 1 )  .OR.  ( index_right_bwall > nx-1 )  .OR.                 &
+               ( index_right_bwall < index_left_bwall+3 )  .OR.                                    &
+               ( index_south_bwall < 1 )  .OR.  ( index_north_bwall > ny-1 )  .OR.                 &
                ( index_north_bwall < index_south_bwall+3 ) )  THEN
-             WRITE( message_string, * ) 'inconsistent building parameters:',   &
-                                      '&index_left_bwall=', index_left_bwall,  &
-                                      'index_right_bwall=', index_right_bwall, &
-                                      'index_south_bwall=', index_south_bwall, &
-                                      'index_north_bwall=', index_north_bwall, &
+             WRITE( message_string, * ) 'inconsistent building parameters:',                       &
+                                      '&index_left_bwall=', index_left_bwall,                      &
+                                      'index_right_bwall=', index_right_bwall,                     &
+                                      'index_south_bwall=', index_south_bwall,                     &
+                                      'index_north_bwall=', index_north_bwall,                     &
                                       'nx=', nx, 'ny=', ny
              CALL message( 'init_grid', 'PA0203', 1, 2, 0, 6, 0 )
@@ -1726,8 +1610,8 @@
           nzb_local = 0
 !
-!--       Define the building. 
-          IF ( index_left_bwall <= nxr  .AND.  index_right_bwall >= nxl  .AND. &
-               index_south_bwall <= nyn  .AND.  index_north_bwall >= nys )     & 
-             nzb_local(MAX(nys,index_south_bwall):MIN(nyn,index_north_bwall),  &
+!--       Define the building.
+          IF ( index_left_bwall <= nxr  .AND.  index_right_bwall >= nxl  .AND.                     &
+               index_south_bwall <= nyn  .AND.  index_north_bwall >= nys )                         &
+             nzb_local(MAX(nys,index_south_bwall):MIN(nyn,index_north_bwall),                      &
                        MAX(nxl,index_left_bwall):MIN(nxr,index_right_bwall)) = bh
 !
@@ -1735,23 +1619,22 @@
           DO  i = nxl, nxr
              DO  j = nys, nyn
-                topo(nzb_local(j,i)+1:nzt+1,j,i) =                             &
-                                 IBSET( topo(nzb_local(j,i)+1:nzt+1,j,i), 0 ) 
+                topo(nzb_local(j,i)+1:nzt+1,j,i) = IBSET( topo(nzb_local(j,i)+1:nzt+1,j,i), 0 )
              ENDDO
           ENDDO
-        
+
           DEALLOCATE( nzb_local )
 
           CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp )
 !
-!--       Set boundary conditions also for flags. Can be interpreted as Neumann
-!--       boundary conditions for topography. 
+!--       Set boundary conditions also for flags. Can be interpreted as Neumannb oundary conditions
+!--       for topography.
           IF ( .NOT. bc_ns_cyc )  THEN
              IF ( nys == 0  )  THEN
-                DO  i = 1, nbgp     
+                DO  i = 1, nbgp
                    topo(:,nys-i,:)   = topo(:,nys,:)
                 ENDDO
              ENDIF
              IF ( nyn == ny )  THEN
-                DO  i = 1, nbgp  
+                DO  i = 1, nbgp
                    topo(:,nyn+i,:) = topo(:,nyn,:)
                 ENDDO
@@ -1760,13 +1643,13 @@
           IF ( .NOT. bc_lr_cyc )  THEN
              IF ( nxl == 0  )  THEN
-                DO  i = 1, nbgp   
+                DO  i = 1, nbgp
                    topo(:,:,nxl-i)   = topo(:,:,nxl)
                 ENDDO
              ENDIF
-             IF ( nxr == nx )  THEN 
-                DO  i = 1, nbgp   
-                   topo(:,:,nxr+i) = topo(:,:,nxr)     
+             IF ( nxr == nx )  THEN
+                DO  i = 1, nbgp
+                   topo(:,:,nxr+i) = topo(:,:,nxr)
                 ENDDO
-             ENDIF      
+             ENDIF
           ENDIF
 
@@ -1793,43 +1676,39 @@
              index_south_cwall = NINT( canyon_wall_south / dy )
              index_north_cwall = index_south_cwall + ngp_cy
-      
+
           ELSE
-             
+
              message_string = 'no street canyon width given'
              CALL message( 'init_grid', 'PA0204', 1, 2, 0, 6, 0 )
-  
+
           ENDIF
 
           ch  = MINLOC( ABS( zw - canyon_height ), 1 ) - 1
-          IF ( ABS( zw(ch)   - canyon_height ) == &
-               ABS( zw(ch+1) - canyon_height )    )  ch = ch + 1
+          IF ( ABS( zw(ch) - canyon_height ) == ABS( zw(ch+1) - canyon_height ) )  ch = ch + 1
           dp_level_ind_b = ch
 !
 !--       Street canyon size has to meet some requirements
           IF ( canyon_width_x /= 9999999.9_wp )  THEN
-             IF ( ( index_left_cwall< 1 ) .OR. ( index_right_cwall> nx-1 ) .OR.&
+             IF ( ( index_left_cwall< 1 )  .OR.  ( index_right_cwall> nx-1 )  .OR.                 &
                   ( ngp_cx < 3 ) )  THEN
-                WRITE( message_string, * ) 'inconsistent canyon parameters:',  &
-                                           '&index_left_cwall=', index_left_cwall, &
-                                           ' index_right_cwall=', index_right_cwall, &
-                                           ' ngp_cx=', ngp_cx,                 &
-                                           ' ch=', ch, ' nx=', nx, ' ny=', ny
-                CALL message( 'init_grid', 'PA0205', 1, 2, 0, 6, 0 ) 
+                WRITE( message_string, * ) 'inconsistent canyon parameters:',                      &
+                                           '&index_left_cwall=', index_left_cwall,                 &
+                                           ' index_right_cwall=', index_right_cwall,               &
+                                           ' ngp_cx=', ngp_cx, ' ch=', ch, ' nx=', nx, ' ny=', ny
+                CALL message( 'init_grid', 'PA0205', 1, 2, 0, 6, 0 )
              ENDIF
           ELSEIF ( canyon_width_y /= 9999999.9_wp )  THEN
-             IF ( ( index_south_cwall < 1 ) .OR.                               &
-                  ( index_north_cwall > ny-1 ) .OR. ( ngp_cy < 3 ) )  THEN
-                WRITE( message_string, * ) 'inconsistent canyon parameters:',  &
-                                           '&index_south_cwall=', index_south_cwall, & 
-                                           ' index_north_cwall=', index_north_cwall, &
-                                           ' ngp_cy=', ngp_cy,                 &
-                                           ' ch=', ch, ' nx=', nx, ' ny=', ny
-                CALL message( 'init_grid', 'PA0206', 1, 2, 0, 6, 0 ) 
-             ENDIF
-          ENDIF
-          IF ( canyon_width_x /= 9999999.9_wp .AND.                            &                 
-               canyon_width_y /= 9999999.9_wp )  THEN
-             message_string = 'inconsistent canyon parameters:' //             &   
-                              '&street canyon can only be oriented' //         &
+             IF ( ( index_south_cwall < 1 )  .OR.                                                  &
+                  ( index_north_cwall > ny-1 )  .OR.  ( ngp_cy < 3 ) )  THEN
+                WRITE( message_string, * ) 'inconsistent canyon parameters:',                      &
+                                           '&index_south_cwall=', index_south_cwall,               &
+                                           ' index_north_cwall=', index_north_cwall,               &
+                                           ' ngp_cy=', ngp_cy, ' ch=', ch, ' nx=', nx, ' ny=', ny
+                CALL message( 'init_grid', 'PA0206', 1, 2, 0, 6, 0 )
+             ENDIF
+          ENDIF
+          IF ( canyon_width_x /= 9999999.9_wp  .AND.  canyon_width_y /= 9999999.9_wp )  THEN
+             message_string = 'inconsistent canyon parameters:' //                                 &
+                              '&street canyon can only be oriented' //                             &
                               ' either in x- or in y-direction'
              CALL message( 'init_grid', 'PA0207', 1, 2, 0, 6, 0 )
@@ -1839,8 +1718,8 @@
           nzb_local = ch
           IF ( canyon_width_x /= 9999999.9_wp )  THEN
-             IF ( index_left_cwall<= nxr  .AND.  index_right_cwall>= nxl )     &
+             IF ( index_left_cwall<= nxr  .AND.  index_right_cwall>= nxl )                         &
                 nzb_local(:,MAX(nxl,index_left_cwall+1):MIN(nxr,index_right_cwall-1)) = 0
           ELSEIF ( canyon_width_y /= 9999999.9_wp )  THEN
-             IF ( index_south_cwall <= nyn  .AND.  index_north_cwall >= nys )  &          
+             IF ( index_south_cwall <= nyn  .AND.  index_north_cwall >= nys )                      &
                 nzb_local(MAX(nys,index_south_cwall+1):MIN(nyn,index_north_cwall-1),:) = 0
           ENDIF
@@ -1849,6 +1728,5 @@
           DO  i = nxl, nxr
              DO  j = nys, nyn
-                topo(nzb_local(j,i)+1:nzt+1,j,i) =                             &
-                                 IBSET( topo(nzb_local(j,i)+1:nzt+1,j,i), 0 ) 
+                topo(nzb_local(j,i)+1:nzt+1,j,i) = IBSET( topo(nzb_local(j,i)+1:nzt+1,j,i), 0 )
              ENDDO
           ENDDO
@@ -1857,14 +1735,14 @@
           CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp )
 !
-!--       Set boundary conditions also for flags. Can be interpreted as Neumann
-!--       boundary conditions for topography. 
+!--       Set boundary conditions also for flags. Can be interpreted as Neumann boundary conditions
+!--       for topography.
           IF ( .NOT. bc_ns_cyc )  THEN
              IF ( nys == 0  )  THEN
-                DO  i = 1, nbgp     
-                   topo(:,nys-i,:)   = topo(:,nys,:)
+                DO  i = 1, nbgp
+                   topo(:,nys-i,:) = topo(:,nys,:)
                 ENDDO
              ENDIF
              IF ( nyn == ny )  THEN
-                DO  i = 1, nbgp  
+                DO  i = 1, nbgp
                    topo(:,nyn+i,:) = topo(:,nyn,:)
                 ENDDO
@@ -1873,13 +1751,13 @@
           IF ( .NOT. bc_lr_cyc )  THEN
              IF ( nxl == 0  )  THEN
-                DO  i = 1, nbgp   
-                   topo(:,:,nxl-i)   = topo(:,:,nxl)
+                DO  i = 1, nbgp
+                   topo(:,:,nxl-i) = topo(:,:,nxl)
                 ENDDO
              ENDIF
-             IF ( nxr == nx )  THEN 
-                DO  i = 1, nbgp   
-                   topo(:,:,nxr+i) = topo(:,:,nxr)     
+             IF ( nxr == nx )  THEN
+                DO  i = 1, nbgp
+                   topo(:,:,nxr+i) = topo(:,:,nxr)
                 ENDDO
-             ENDIF      
+             ENDIF
           ENDIF
 
@@ -1895,5 +1773,5 @@
 !
 !--       Tunnel-wall depth
-          IF ( tunnel_wall_depth == 9999999.9_wp )  THEN  
+          IF ( tunnel_wall_depth == 9999999.9_wp )  THEN
              td = MAX ( dx, dy, dz(1) )
           ELSE
@@ -1902,13 +1780,11 @@
 !
 !--       Check for tunnel width
-          IF ( tunnel_width_x == 9999999.9_wp  .AND.                           &
-               tunnel_width_y == 9999999.9_wp  )  THEN
+          IF ( tunnel_width_x == 9999999.9_wp  .AND.  tunnel_width_y == 9999999.9_wp  )  THEN
              message_string = 'No tunnel width is given. '
              CALL message( 'init_grid', 'PA0280', 1, 2, 0, 6, 0 )
           ENDIF
-          IF ( tunnel_width_x /= 9999999.9_wp  .AND.                           &
-               tunnel_width_y /= 9999999.9_wp  )  THEN
-             message_string = 'Inconsistent tunnel parameters:' //             &   
-                              'tunnel can only be oriented' //                 &
+          IF ( tunnel_width_x /= 9999999.9_wp  .AND.  tunnel_width_y /= 9999999.9_wp  )  THEN
+             message_string = 'Inconsistent tunnel parameters:' //                                 &
+                              'tunnel can only be oriented' //                                     &
                               'either in x- or in y-direction.'
              CALL message( 'init_grid', 'PA0281', 1, 2, 0, 6, 0 )
@@ -1916,10 +1792,10 @@
 !
 !--       Check for too small tunnel width in x- and y-direction
-          IF ( tunnel_width_x /= 9999999.9_wp  .AND.                           &   
+          IF ( tunnel_width_x /= 9999999.9_wp  .AND.                                               &
                tunnel_width_x - 2.0_wp * td <= 2.0_wp * dx )  THEN
              message_string = 'tunnel_width_x too small'
              CALL message( 'init_grid', 'PA0175', 1, 2, 0, 6, 0 )
           ENDIF
-          IF ( tunnel_width_y /= 9999999.9_wp  .AND.                           &
+          IF ( tunnel_width_y /= 9999999.9_wp  .AND.                                               &
                tunnel_width_y - 2.0_wp * td <= 2.0_wp * dy )  THEN
              message_string = 'tunnel_width_y too small'
@@ -1927,5 +1803,5 @@
           ENDIF
 !
-!--       Check for too large tunnel width. 
+!--       Check for too large tunnel width.
 !--       Tunnel axis along y.
           IF ( tunnel_width_x /= 9999999.9_wp )  THEN
@@ -1937,8 +1813,6 @@
              txs_out = INT( ( nx + 1 ) * 0.5_wp * dx - tunnel_width_x * 0.5_wp )
              txe_out = INT( ( nx + 1 ) * 0.5_wp * dx + tunnel_width_x * 0.5_wp )
-             txs_in  = INT( ( nx + 1 ) * 0.5_wp * dx -                         &
-                                      ( tunnel_width_x * 0.5_wp - td ) )
-             txe_in  = INT( ( nx + 1 ) * 0.5_wp * dx +                         &
-                                   ( tunnel_width_x * 0.5_wp - td ) )
+             txs_in  = INT( ( nx + 1 ) * 0.5_wp * dx - ( tunnel_width_x * 0.5_wp - td ) )
+             txe_in  = INT( ( nx + 1 ) * 0.5_wp * dx + ( tunnel_width_x * 0.5_wp - td ) )
 
              tys_out = INT( ( ny + 1 ) * 0.5_wp * dy - tunnel_length * 0.5_wp )
@@ -1962,8 +1836,6 @@
              tys_out = INT( ( ny + 1 ) * 0.5_wp * dy - tunnel_width_y * 0.5_wp )
              tye_out = INT( ( ny + 1 ) * 0.5_wp * dy + tunnel_width_y * 0.5_wp )
-             tys_in  = INT( ( ny + 1 ) * 0.5_wp * dy -                         &
-                                        ( tunnel_width_y * 0.5_wp - td ) )
-             tye_in  = INT( ( ny + 1 ) * 0.5_wp * dy +                         &
-                                     ( tunnel_width_y * 0.5_wp - td ) )
+             tys_in  = INT( ( ny + 1 ) * 0.5_wp * dy - ( tunnel_width_y * 0.5_wp - td ) )
+             tye_in  = INT( ( ny + 1 ) * 0.5_wp * dy + ( tunnel_width_y * 0.5_wp - td ) )
           ENDIF
 
@@ -1973,20 +1845,16 @@
 !
 !--             Use heaviside function to model outer tunnel surface
-                hv_out = th * 0.5_wp *                                         &
-                              ( ( SIGN( 1.0_wp, i * dx - txs_out ) + 1.0_wp )  &
-                              - ( SIGN( 1.0_wp, i * dx - txe_out ) + 1.0_wp ) )
-
-                hv_out = hv_out * 0.5_wp *                                     &
-                            ( ( SIGN( 1.0_wp, j * dy - tys_out ) + 1.0_wp )    &
-                            - ( SIGN( 1.0_wp, j * dy - tye_out ) + 1.0_wp ) )
-!    
+                hv_out = th * 0.5_wp * ( ( SIGN( 1.0_wp, i * dx - txs_out ) + 1.0_wp )             &
+                                       - ( SIGN( 1.0_wp, i * dx - txe_out ) + 1.0_wp ) )
+
+                hv_out = hv_out * 0.5_wp * ( ( SIGN( 1.0_wp, j * dy - tys_out ) + 1.0_wp )         &
+                                           - ( SIGN( 1.0_wp, j * dy - tye_out ) + 1.0_wp ) )
+!
 !--             Use heaviside function to model inner tunnel surface
-                hv_in  = ( th - td ) * 0.5_wp *                                &
-                                ( ( SIGN( 1.0_wp, i * dx - txs_in ) + 1.0_wp ) &
-                                - ( SIGN( 1.0_wp, i * dx - txe_in ) + 1.0_wp ) )
-
-                hv_in = hv_in * 0.5_wp *                                       &
-                                ( ( SIGN( 1.0_wp, j * dy - tys_in ) + 1.0_wp ) &
-                                - ( SIGN( 1.0_wp, j * dy - tye_in ) + 1.0_wp ) )
+                hv_in  = ( th - td ) * 0.5_wp * ( ( SIGN( 1.0_wp, i * dx - txs_in ) + 1.0_wp )     &
+                                                - ( SIGN( 1.0_wp, i * dx - txe_in ) + 1.0_wp ) )
+
+                hv_in = hv_in * 0.5_wp * ( ( SIGN( 1.0_wp, j * dy - tys_in ) + 1.0_wp )            &
+                                         - ( SIGN( 1.0_wp, j * dy - tye_in ) + 1.0_wp ) )
 !
 !--             Set flags at x-y-positions without any tunnel surface
@@ -2009,9 +1877,9 @@
 !--                   Lateral tunnel walls
                       IF ( hv_out - hv_in == td )  THEN
-                         IF ( zw(k) <= hv_in )  THEN 
+                         IF ( zw(k) <= hv_in )  THEN
                             topo(k,j,i) = IBSET( topo(k,j,i), 0 )
-                         ELSEIF ( zw(k) > hv_in  .AND.  zw(k) <= hv_out )  THEN 
+                         ELSEIF ( zw(k) > hv_in  .AND.  zw(k) <= hv_out )  THEN
                             topo(k,j,i) = IBCLR( topo(k,j,i), 0 )
-                         ELSEIF ( zw(k) > hv_out )  THEN 
+                         ELSEIF ( zw(k) > hv_out )  THEN
                             topo(k,j,i) = IBSET( topo(k,j,i), 0 )
                          ENDIF
@@ -2024,14 +1892,14 @@
           CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp )
 !
-!--       Set boundary conditions also for flags. Can be interpreted as Neumann
-!--       boundary conditions for topography. 
+!--       Set boundary conditions also for flags. Can be interpreted as Neumann boundary conditions
+!--       for topography.
           IF ( .NOT. bc_ns_cyc )  THEN
              IF ( nys == 0  )  THEN
-                DO  i = 1, nbgp     
-                   topo(:,nys-i,:)   = topo(:,nys,:)
+                DO  i = 1, nbgp
+                   topo(:,nys-i,:) = topo(:,nys,:)
                 ENDDO
              ENDIF
              IF ( nyn == ny )  THEN
-                DO  i = 1, nbgp  
+                DO  i = 1, nbgp
                    topo(:,nyn+i,:) = topo(:,nyn,:)
                 ENDDO
@@ -2040,23 +1908,22 @@
           IF ( .NOT. bc_lr_cyc )  THEN
              IF ( nxl == 0  )  THEN
-                DO  i = 1, nbgp   
-                   topo(:,:,nxl-i)   = topo(:,:,nxl)
+                DO  i = 1, nbgp
+                   topo(:,:,nxl-i) = topo(:,:,nxl)
                 ENDDO
              ENDIF
-             IF ( nxr == nx )  THEN 
-                DO  i = 1, nbgp   
-                   topo(:,:,nxr+i) = topo(:,:,nxr)     
+             IF ( nxr == nx )  THEN
+                DO  i = 1, nbgp
+                   topo(:,:,nxr+i) = topo(:,:,nxr)
                 ENDDO
-             ENDIF      
+             ENDIF
           ENDIF
 
        CASE ( 'read_from_file' )
 !
-!--       Note, topography information have been already read.  
-!--       If required, further process topography, i.e. reference buildings on
-!--       top of orography and set temporary 3D topography array, which is 
-!--       used later to set grid flags. Calling of this rouinte is also 
-!--       required in case of ASCII input, even though no distinction between 
-!--       terrain- and building height is made in this case.  
+!--       Note, topography information have been already read.
+!--       If required, further process topography, i.e. reference buildings on top of orography and
+!--       set temporary 3D topography array, which is used later to set grid flags. Calling of this
+!--       rouinte is also required in case of ASCII input, even though no distinction between
+!--       terrain- and building height is made in this case.
           CALL process_topography( topo )
 !
@@ -2064,6 +1931,5 @@
           CALL filter_topography( topo )
 !
-!--       Exchange ghost-points, as well as add cyclic or Neumann boundary 
-!--       conditions.
+!--       Exchange ghost-points, as well as add cyclic or Neumann boundary conditions.
           CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp )
 !
@@ -2071,10 +1937,10 @@
           IF ( .NOT. bc_ns_cyc )  THEN
              IF ( nys == 0  )  THEN
-                DO  i = 1, nbgp         
+                DO  i = 1, nbgp
                    topo(:,nys-i,:) = topo(:,nys,:)
                 ENDDO
              ENDIF
              IF ( nyn == ny )  THEN
-                DO  i = 1, nbgp         
+                DO  i = 1, nbgp
                    topo(:,nyn+i,:) = topo(:,nyn,:)
                 ENDDO
@@ -2084,10 +1950,10 @@
           IF ( .NOT. bc_lr_cyc )  THEN
              IF ( nxl == 0  )  THEN
-                DO  i = 1, nbgp 
+                DO  i = 1, nbgp
                    topo(:,:,nxl-i) = topo(:,:,nxl)
                 ENDDO
              ENDIF
              IF ( nxr == nx )  THEN
-                DO  i = 1, nbgp 
+                DO  i = 1, nbgp
                    topo(:,:,nxr+i) = topo(:,:,nxr)
                 ENDDO
@@ -2097,9 +1963,8 @@
 
        CASE DEFAULT
-!   
-!--       The DEFAULT case is reached either if the parameter topography
-!--       contains a wrong character string or if the user has defined a special
-!--       case in the user interface. There, the subroutine user_init_grid 
-!--       checks which of these two conditions applies.
+!
+!--       The DEFAULT case is reached either if the parameter topography contains a wrong character
+!--       string or if the user has defined a special case in the user interface. There, the
+!--       subroutine user_init_grid checks which of these two conditions applies.
           CALL user_init_grid( topo )
           CALL filter_topography( topo )
@@ -2107,45 +1972,41 @@
     END SELECT
 !
-!-- Consistency checks and index array initialization are only required for
-!-- non-flat topography.
+!-- Consistency checks and index array initialization are only required for non-flat topography.
     IF ( TRIM( topography ) /= 'flat' )  THEN
 !
-!--    In case of non-flat topography, check whether the convention how to 
-!--    define the topography grid has been set correctly, or whether the default
-!--    is applicable. If this is not possible, abort.
+!--    In case of non-flat topography, check whether the convention how to define the topography
+!--    grid has been set correctly, or whether the default is applicable. If this is not possible,
+!--    abort.
        IF ( TRIM( topography_grid_convention ) == ' ' )  THEN
-          IF ( TRIM( topography ) /= 'closed_channel' .AND.                    &
-               TRIM( topography ) /= 'single_building' .AND.                   &
-               TRIM( topography ) /= 'single_street_canyon' .AND.              &
-               TRIM( topography ) /= 'tunnel'  .AND.                           &
+          IF ( TRIM( topography ) /= 'closed_channel'        .AND.                                 &
+               TRIM( topography ) /= 'single_building'       .AND.                                 &
+               TRIM( topography ) /= 'single_street_canyon'  .AND.                                 &
+               TRIM( topography ) /= 'tunnel'                .AND.                                 &
                TRIM( topography ) /= 'read_from_file')  THEN
-!--          The default value is not applicable here, because it is only valid
-!--          for the four standard cases 'single_building', 
-!--          'single_street_canyon', 'tunnel' and 'read_from_file'
+!--          The default value is not applicable here, because it is only valid for the four
+!--          standard cases 'single_building', 'single_street_canyon', 'tunnel' and 'read_from_file'
 !--          defined in init_grid.
-             WRITE( message_string, * )                                        &
-               'The value for "topography_grid_convention" ',                  &
-               'is not set. Its default value is & only valid for ',           &
-               '"topography" = ''single_building'', ''tunnel'' ',              &
-               '''single_street_canyon'', ''closed_channel'' & or ',           &
-               '''read_from_file''.',                                          &
-               '& Choose ''cell_edge'' or ''cell_center''.'
+             WRITE( message_string, * ) 'The value for "topography_grid_convention" ',             &
+                                        'is not set. Its default value is & only valid for ',      &
+                                        '"topography" = ''single_building'', ''tunnel'' ',         &
+                                        '''single_street_canyon'', ''closed_channel'' & or ',      &
+                                        '''read_from_file''.',                                     &
+                                        '& Choose ''cell_edge'' or ''cell_center''.'
              CALL message( 'init_grid', 'PA0239', 1, 2, 0, 6, 0 )
           ELSE
 !--          The default value is applicable here.
 !--          Set convention according to topography.
-             IF ( TRIM( topography ) == 'single_building' .OR.                 &
+             IF ( TRIM( topography ) == 'single_building'  .OR.                                    &
                   TRIM( topography ) == 'single_street_canyon' )  THEN
                 topography_grid_convention = 'cell_edge'
-             ELSEIF ( TRIM( topography ) == 'read_from_file'  .OR.             &
+             ELSEIF ( TRIM( topography ) == 'read_from_file'  .OR.                                 &
                       TRIM( topography ) == 'tunnel')  THEN
                 topography_grid_convention = 'cell_center'
              ENDIF
           ENDIF
-       ELSEIF ( TRIM( topography_grid_convention ) /= 'cell_edge' .AND.        &
+       ELSEIF ( TRIM( topography_grid_convention ) /= 'cell_edge'  .AND.                           &
                 TRIM( topography_grid_convention ) /= 'cell_center' )  THEN
-          WRITE( message_string, * )                                           &
-            'The value for "topography_grid_convention" is ',                  &
-            'not recognized.& Choose ''cell_edge'' or ''cell_center''.'
+          WRITE( message_string, * )  'The value for "topography_grid_convention" is ',            &
+                                      'not recognized.& Choose ''cell_edge'' or ''cell_center''.'
           CALL message( 'init_grid', 'PA0240', 1, 2, 0, 6, 0 )
        ENDIF
@@ -2153,13 +2014,13 @@
 
        IF ( topography_grid_convention == 'cell_edge' )  THEN
-! 
-!--       The array nzb_local as defined using the 'cell_edge' convention 
-!--       describes the actual total size of topography which is defined at the 
-!--       cell edges where u=0 on the topography walls in x-direction and v=0 
+!
+!--       The array nzb_local as defined using the 'cell_edge' convention
+!--       describes the actual total size of topography which is defined at the
+!--       cell edges where u=0 on the topography walls in x-direction and v=0
 !--       on the topography walls in y-direction. However, PALM uses individual
 !--       arrays nzb_u|v|w|s_inner|outer that are based on nzb_s_inner.
-!--       Therefore, the extent of topography in nzb_local is now reduced by 
-!--       1dx at the E topography walls and by 1dy at the N topography walls 
-!--       to form the basis for nzb_s_inner. 
+!--       Therefore, the extent of topography in nzb_local is now reduced by
+!--       1dx at the E topography walls and by 1dy at the N topography walls
+!--       to form the basis for nzb_s_inner.
 !--       Note, the reverse memory access (i-j instead of j-i) is absolutely
 !--       required at this point.
@@ -2167,10 +2028,9 @@
              DO  i = nxl-1, nxr
                 DO  k = nzb, nzt+1
-                   IF ( BTEST( topo(k,j,i), 0 )  .OR.                          &
-                        BTEST( topo(k,j,i+1), 0 ) )                            &
+                   IF ( BTEST( topo(k,j,i), 0 )  .OR.  BTEST( topo(k,j,i+1), 0 ) )                 &
                        topo(k,j,i) = IBSET( topo(k,j,i), 0 )
                 ENDDO
              ENDDO
-          ENDDO      
+          ENDDO
           CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp )
 
@@ -2178,12 +2038,11 @@
              DO  j = nys-1, nyn
                 DO  k = nzb, nzt+1
-                   IF ( BTEST( topo(k,j,i), 0 )  .OR.                          &
-                        BTEST( topo(k,j+1,i), 0 ) )                            &
+                   IF ( BTEST( topo(k,j,i), 0 )  .OR.  BTEST( topo(k,j+1,i), 0 ) )                 &
                       topo(k,j,i) = IBSET( topo(k,j,i), 0 )
                 ENDDO
              ENDDO
-          ENDDO  
+          ENDDO
           CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp )
-   
+
        ENDIF
     ENDIF
@@ -2194,14 +2053,14 @@
  SUBROUTINE set_topo_flags(topo)
 
-    USE control_parameters,                                                    &
-        ONLY:  bc_lr_cyc, bc_ns_cyc, constant_flux_layer,                      &
-               scalar_advec, topography, use_surface_fluxes, use_top_fluxes
-
-    USE exchange_horiz_mod,                                                    &
+    USE control_parameters,                                                                        &
+        ONLY:  bc_lr_cyc, bc_ns_cyc, constant_flux_layer, scalar_advec, topography,                &
+               use_surface_fluxes, use_top_fluxes
+
+    USE exchange_horiz_mod,                                                                        &
         ONLY:  exchange_horiz_int
 
-    USE indices,                                                               &
-        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb,  &
-               nzt, topo_top_ind, wall_flags_static_0, wall_flags_total_0
+    USE indices,                                                                                   &
+        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb, nzt, topo_top_ind,   &
+               wall_flags_static_0, wall_flags_total_0
 
     USE kinds
@@ -2214,5 +2073,6 @@
     INTEGER(iwp) ::  k             !< index variable along z
 
-    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  topo !< input array for 3D topography and dummy array for setting "outer"-flags
+    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  topo !< input array for 3D topography and dummy array for setting
+                                                                    !< "outer"-flags
 
     ALLOCATE( wall_flags_static_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
@@ -2220,5 +2080,5 @@
 !
 !-- Set-up topography flags. First, set flags only for s, u, v and w-grid.
-!-- Further special flags will be set in following loops. 
+!-- Further special flags will be set in following loops.
     DO  i = nxl, nxr
        DO  j = nys, nyn
@@ -2226,15 +2086,13 @@
 !
 !--          scalar grid
-             IF ( BTEST( topo(k,j,i), 0 ) )                                    &
+             IF ( BTEST( topo(k,j,i), 0 ) )                                                        &
                 wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 0 )
 !
 !--          u grid
-             IF ( BTEST( topo(k,j,i),   0 )  .AND.                             &
-                  BTEST( topo(k,j,i-1), 0 ) )                                  &
+             IF ( BTEST( topo(k,j,i), 0 )  .AND.  BTEST( topo(k,j,i-1), 0 ) )                      &
                 wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 1 )
 !
 !--          v grid
-             IF ( BTEST( topo(k,j,i),   0 )  .AND.                             &
-                  BTEST( topo(k,j-1,i), 0 ) )                                  &
+             IF ( BTEST( topo(k,j,i), 0 )  .AND.  BTEST( topo(k,j-1,i), 0 ) )                      &
                  wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 2 )
 
@@ -2244,10 +2102,9 @@
 !
 !--          w grid
-             IF ( BTEST( topo(k,j,i),   0 )  .AND.                             &
-                  BTEST( topo(k+1,j,i), 0 ) )                                  &
+             IF ( BTEST( topo(k,j,i), 0 )  .AND.  BTEST( topo(k+1,j,i), 0 ) )                      &
                 wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 3 )
           ENDDO
-          
-          IF ( topography /= 'closed_channel' ) THEN
+
+          IF ( topography /= 'closed_channel' )  THEN
              wall_flags_static_0(nzt+1,j,i) = IBSET( wall_flags_static_0(nzt+1,j,i), 3 )
           ENDIF
@@ -2259,11 +2116,10 @@
 
 !
-!-- Set outer array for scalars to mask near-surface grid points. Note, on 
-!-- basis of flag 24 futher flags will be derived which are used to control
-!-- production of subgrid TKE production near walls. 
-    
+!-- Set outer array for scalars to mask near-surface grid points. Note, on basis of flag 24 futher
+!-- flags will be derived which are used to control production of subgrid TKE production near walls.
+
     ALLOCATE( wall_flags_total_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
     wall_flags_total_0 = 0
-                                    
+
     DO i = nxl, nxr
        DO j = nys, nyn
@@ -2273,18 +2129,18 @@
        ENDDO
     ENDDO
-    
+
     CALL exchange_horiz_int( wall_flags_total_0, nys, nyn, nxl, nxr, nzt, nbgp )
-    
+
     DO i = nxl, nxr
        DO j = nys, nyn
           DO k = nzb, nzt+1
-             IF ( BTEST( wall_flags_total_0(k,j-1,i), 0 )    .AND.                   &
-                  BTEST( wall_flags_total_0(k,j+1,i), 0 )    .AND.                   &
-                  BTEST( wall_flags_total_0(k,j,i-1), 0 )    .AND.                   &
-                  BTEST( wall_flags_total_0(k,j,i+1), 0 )    .AND.                   &
-                  BTEST( wall_flags_total_0(k,j-1,i-1), 0 )  .AND.                   &
-                  BTEST( wall_flags_total_0(k,j+1,i-1), 0 )  .AND.                   &
-                  BTEST( wall_flags_total_0(k,j-1,i+1), 0 )  .AND.                   &
-                  BTEST( wall_flags_total_0(k,j+1,i+1), 0 ) )                        &
+             IF ( BTEST( wall_flags_total_0(k,j-1,i), 0 )    .AND.                                 &
+                  BTEST( wall_flags_total_0(k,j+1,i), 0 )    .AND.                                 &
+                  BTEST( wall_flags_total_0(k,j,i-1), 0 )    .AND.                                 &
+                  BTEST( wall_flags_total_0(k,j,i+1), 0 )    .AND.                                 &
+                  BTEST( wall_flags_total_0(k,j-1,i-1), 0 )  .AND.                                 &
+                  BTEST( wall_flags_total_0(k,j+1,i-1), 0 )  .AND.                                 &
+                  BTEST( wall_flags_total_0(k,j-1,i+1), 0 )  .AND.                                 &
+                  BTEST( wall_flags_total_0(k,j+1,i+1), 0 ) )                                      &
                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 24 )
           ENDDO
@@ -2298,18 +2154,15 @@
 !
 !--          scalar grid, former nzb_diff_s_inner.
-!--          Note, use this flag also to mask topography in diffusion_u and 
-!--          diffusion_v along the vertical direction. In case of 
-!--          use_surface_fluxes, fluxes are calculated via MOST, else, simple
-!--          gradient approach is applied. Please note, in case of u- and v-
-!--          diffuison, a small error is made at edges (on the east side for u,
-!--          at the north side for v), since topography on scalar grid point
-!--          is used instead of topography on u/v-grid. As number of topography grid
-!--          points on uv-grid is different than s-grid, different number of 
-!--          surface elements would be required. In order to avoid this, 
-!--          treat edges (u(k,j,i+1)) simply by a gradient approach, i.e. these
-!--          points are not masked within diffusion_u. Tests had shown that the
-!--          effect on the flow is negligible. 
+!--          Note, use this flag also to mask topography in diffusion_u and diffusion_v along the
+!--          vertical direction. In case of use_surface_fluxes, fluxes are calculated via MOST,
+!--          else, simple gradient approach is applied. Please note, in case of u- and v-diffuison,
+!--          a small error is made at edges (on the east side for u, at the north side for v), since
+!--          topography on scalar grid point is used instead of topography on u/v-grid. As number of
+!--          topography grid points on uv-grid is different than s-grid, different number of surface
+!--          elements would be required. In order to avoid this, treat edges (u(k,j,i+1)) simply by
+!--          a gradient approach, i.e. these points are not masked within diffusion_u. Tests had
+!--          shown that the effect on the flow is negligible.
              IF ( constant_flux_layer  .OR.  use_surface_fluxes )  THEN
-                IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )                         &
+                IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )                                       &
                    wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 8 )
              ELSE
@@ -2319,6 +2172,5 @@
           ENDDO
 !
-!--       Special flag to control vertical diffusion at model top - former 
-!--       nzt_diff
+!--       Special flag to control vertical diffusion at model top - former nzt_diff
           wall_flags_total_0(:,j,i) = IBSET( wall_flags_total_0(:,j,i), 9 )
           IF ( use_top_fluxes )                                                &
@@ -2328,50 +2180,46 @@
           DO k = nzb+1, nzt
 !
-!--          Special flag on u grid, former nzb_u_inner + 1, required   
-!--          for disturb_field and initialization. Do not disturb directly at
-!--          topography, as well as initialize u with zero one grid point outside
-!--          of topography.
-             IF ( 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 ) )                          &
+!--          Special flag on u grid, former nzb_u_inner + 1, required for disturb_field and
+!--          initialization. Do not disturb directly at topography, as well as initialize u with
+!--          zero one grid point outside of topography.
+             IF ( 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 ) )                                        &
                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 20 )
 !
-!--          Special flag on v grid, former nzb_v_inner + 1, required   
-!--          for disturb_field and initialization. Do not disturb directly at
-!--          topography, as well as initialize v with zero one grid point outside
-!--          of topography.
-             IF ( 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 ) )                          &
+!--          Special flag on v grid, former nzb_v_inner + 1, required for disturb_field and
+!--          initialization. Do not disturb directly at topography, as well as initialize v with
+!--          zero one grid point outside of topography.
+             IF ( 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 ) )                                        &
                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 21 )
 !
-!--          Special flag on scalar grid, former nzb_s_inner+1. Used for 
-!--          lpm_sgs_tke
-             IF ( 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+1,j,i), 0 ) )                          &
+!--          Special flag on scalar grid, former nzb_s_inner+1. Used for lpm_sgs_tke
+             IF ( 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+1,j,i), 0 ) )                                        &
                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 25 )
 !
-!--          Special flag on scalar grid, nzb_diff_s_outer - 1, required in 
+!--          Special flag on scalar grid, nzb_diff_s_outer - 1, required in in production_e
+             IF ( constant_flux_layer  .OR.  use_surface_fluxes )  THEN
+                IF ( BTEST( wall_flags_total_0(k,j,i),   24 )  .AND.                               &
+                     BTEST( wall_flags_total_0(k-1,j,i), 24 )  .AND.                               &
+                     BTEST( wall_flags_total_0(k+1,j,i), 0 ) )                                     &
+                   wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 29 )
+             ELSE
+                IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )                                       &
+                   wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 29 )
+             ENDIF
+!
+!--          Special flag on scalar grid, nzb_diff_s_outer - 1, required in
 !--          in production_e
              IF ( constant_flux_layer  .OR.  use_surface_fluxes )  THEN
-                IF ( BTEST( wall_flags_total_0(k,j,i),   24 )  .AND.                 &
-                     BTEST( wall_flags_total_0(k-1,j,i), 24 )  .AND.                 &
-                     BTEST( wall_flags_total_0(k+1,j,i), 0 ) )                       &
-                   wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 29 )
-             ELSE
-                IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )                         &
-                   wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 29 )
-             ENDIF
-!
-!--          Special flag on scalar grid, nzb_diff_s_outer - 1, required in 
-!--          in production_e
-             IF ( constant_flux_layer  .OR.  use_surface_fluxes )  THEN
-                IF ( 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+1,j,i), 0 ) )                       &
+                IF ( 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+1,j,i), 0 ) )                                     &
                    wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 30 )
              ELSE
-                IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )                         &
+                IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )                                       &
                    wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 30 )
              ENDIF
@@ -2382,21 +2230,21 @@
 !
 !--          Scalar grid
-             IF ( BTEST( wall_flags_total_0(k-1,j,i), 0 )  .AND.                     &
-            .NOT. BTEST( wall_flags_total_0(k,j,i), 0   ) )                          & 
-                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 13 ) 
+             IF (       BTEST( wall_flags_total_0(k-1,j,i), 0 )  .AND.                             &
+                  .NOT. BTEST( wall_flags_total_0(k,j,i), 0   ) )                                  &
+                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 13 )
 !
 !--          Downward facing wall on u grid
-             IF ( BTEST( wall_flags_total_0(k-1,j,i), 1 )  .AND.                     &
-            .NOT. BTEST( wall_flags_total_0(k,j,i), 1   ) )                          & 
+             IF (       BTEST( wall_flags_total_0(k-1,j,i), 1 )  .AND.                             &
+                  .NOT. BTEST( wall_flags_total_0(k,j,i), 1   ) )                                  &
                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 15 )
 !
 !--          Downward facing wall on v grid
-             IF ( BTEST( wall_flags_total_0(k-1,j,i), 2 )  .AND.                     &
-            .NOT. BTEST( wall_flags_total_0(k,j,i), 2   ) )                          & 
+             IF (       BTEST( wall_flags_total_0(k-1,j,i), 2 )  .AND.                             &
+                  .NOT. BTEST( wall_flags_total_0(k,j,i), 2   ) )                                  &
                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 17 )
 !
 !--          Downward facing wall on w grid
-             IF ( BTEST( wall_flags_total_0(k-1,j,i), 3 )  .AND.                     &
-            .NOT. BTEST( wall_flags_total_0(k,j,i), 3 ) )                            & 
+             IF (       BTEST( wall_flags_total_0(k-1,j,i), 3 )  .AND.                             &
+                  .NOT. BTEST( wall_flags_total_0(k,j,i), 3 ) )                                    &
                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 19 )
           ENDDO
@@ -2406,42 +2254,42 @@
 !
 !--          Upward facing wall on scalar grid
-             IF ( .NOT. BTEST( wall_flags_total_0(k,j,i),   0 )  .AND.               &
-                        BTEST( wall_flags_total_0(k+1,j,i), 0 ) )                    & 
+             IF ( .NOT. BTEST( wall_flags_total_0(k,j,i),   0 )  .AND.                             &
+                        BTEST( wall_flags_total_0(k+1,j,i), 0 ) )                                  &
                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 12 )
 !
 !--          Upward facing wall on u grid
-             IF ( .NOT. BTEST( wall_flags_total_0(k,j,i),   1 )  .AND.               &
-                        BTEST( wall_flags_total_0(k+1,j,i), 1 ) )                    & 
+             IF ( .NOT. BTEST( wall_flags_total_0(k,j,i),   1 )  .AND.                             &
+                        BTEST( wall_flags_total_0(k+1,j,i), 1 ) )                                  &
                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 14 )
 
-!   
+!
 !--          Upward facing wall on v grid
-             IF ( .NOT. BTEST( wall_flags_total_0(k,j,i),   2 )  .AND.               &
-                        BTEST( wall_flags_total_0(k+1,j,i), 2 ) )                    & 
+             IF ( .NOT. BTEST( wall_flags_total_0(k,j,i),   2 )  .AND.                             &
+                        BTEST( wall_flags_total_0(k+1,j,i), 2 ) )                                  &
                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 16 )
-   
+
 !
 !--          Upward facing wall on w grid
-             IF ( .NOT. BTEST( wall_flags_total_0(k,j,i),   3 )  .AND.               &
-                        BTEST( wall_flags_total_0(k+1,j,i), 3 ) )                    & 
+             IF ( .NOT. BTEST( wall_flags_total_0(k,j,i),   3 )  .AND.                             &
+                        BTEST( wall_flags_total_0(k+1,j,i), 3 ) )                                  &
                 wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 18 )
 !
 !--          Special flag on scalar grid, former nzb_s_inner
-             IF ( BTEST( wall_flags_total_0(k,j,i), 0 )  .OR.                        &
-                  BTEST( wall_flags_total_0(k,j,i), 12 ) .OR.                        &
-                  BTEST( wall_flags_total_0(k,j,i), 13 ) )                           &
+             IF ( BTEST( wall_flags_total_0(k,j,i), 0 )  .OR.                                      &
+                  BTEST( wall_flags_total_0(k,j,i), 12 ) .OR.                                      &
+                  BTEST( wall_flags_total_0(k,j,i), 13 ) )                                         &
                    wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 22 )
 !
-!--          Special flag on scalar grid, nzb_diff_s_inner - 1, required for 
+!--          Special flag on scalar grid, nzb_diff_s_inner - 1, required for
 !--          flow_statistics
              IF ( constant_flux_layer  .OR.  use_surface_fluxes )  THEN
-                IF ( BTEST( wall_flags_total_0(k,j,i),   0 )  .AND.                  &
-                     BTEST( wall_flags_total_0(k+1,j,i), 0 ) )                       &
+                IF ( BTEST( wall_flags_total_0(k,j,i),   0 )  .AND.                                &
+                     BTEST( wall_flags_total_0(k+1,j,i), 0 ) )                                     &
                   wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 23 )
              ELSE
-                IF ( BTEST( wall_flags_total_0(k,j,i), 22 ) )                        &
+                IF ( BTEST( wall_flags_total_0(k,j,i), 22 ) )                                      &
                    wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 23 )
              ENDIF
-   
+
 
           ENDDO
@@ -2449,29 +2297,28 @@
           wall_flags_total_0(nzt+1,j,i) = IBSET( wall_flags_total_0(nzt+1,j,i), 23 )
 !
-!--       Set flags indicating that topography is close by in horizontal 
-!--       direction, i.e. flags that infold the topography. These will be used
-!--       to set advection flags for passive scalars, where due to large 
-!--       gradients near buildings stationary numerical oscillations can produce 
-!--       unrealistically high concentrations. This is only necessary if 
-!--       WS-scheme is applied for scalar advection. Note, these flags will be 
-!--       only used for passive scalars such as chemical species or aerosols.
+!--       Set flags indicating that topography is close by in horizontal direction, i.e. flags that
+!--       infold the topography. These will be used to set advection flags for passive scalars,
+!--       where due to large gradients near buildings stationary numerical oscillations can produce
+!--       unrealistically high concentrations. This is only necessary if WS-scheme is applied for
+!--       scalar advection. Note, these flags will be only used for passive scalars such as chemical
+!--       species or aerosols.
           IF ( scalar_advec == 'ws-scheme' )  THEN
              DO k = nzb, nzt
-                IF ( BTEST( wall_flags_total_0(k,j,i), 0 )  .AND. (                  &
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i-1), 0 ) )  .OR.&
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i-2), 0 ) )  .OR.&
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i-3), 0 ) )  .OR.&
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i+1), 0 ) )  .OR.&
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i+2), 0 ) )  .OR.&
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i+3), 0 ) )  .OR.&
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-1,i-3:i+3), 0 ) )  .OR.&
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-2,i-3:i+3), 0 ) )  .OR.&
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3,i-3:i+3), 0 ) )  .OR.&
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j+1,i-3:i+3), 0 ) )  .OR.&
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j+2,i-3:i+3), 0 ) )  .OR.&
-                     ANY( .NOT. BTEST( wall_flags_total_0(k,j+3,i-3:i+3), 0 ) )      &
-                                                            ) )                      &
+                IF ( BTEST( wall_flags_total_0(k,j,i), 0 )  .AND. (                                &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i-1), 0 ) )  .OR.              &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i-2), 0 ) )  .OR.              &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i-3), 0 ) )  .OR.              &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i+1), 0 ) )  .OR.              &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i+2), 0 ) )  .OR.              &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i+3), 0 ) )  .OR.              &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-1,i-3:i+3), 0 ) )  .OR.              &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-2,i-3:i+3), 0 ) )  .OR.              &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j-3,i-3:i+3), 0 ) )  .OR.              &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j+1,i-3:i+3), 0 ) )  .OR.              &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j+2,i-3:i+3), 0 ) )  .OR.              &
+                     ANY( .NOT. BTEST( wall_flags_total_0(k,j+3,i-3:i+3), 0 ) )                    &
+                                                                  )                                &
+                   )                                                                               &
                    wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 31 )
-                     
              ENDDO
           ENDIF
@@ -2480,9 +2327,9 @@
 !
 !-- Finally, set identification flags indicating natural terrain or buildings.
-!-- Natural terrain grid points. Information on the type of the surface is 
-!-- stored in bit 1 of 3D Integer array topo. However, this bit is only set 
-!-- when topography is read from file. In order to run the land-surface model
-!-- also without topography information, set bit 1 explicitely in this case.
-!-- 
+!-- Natural terrain grid points. Information on the type of the surface is stored in bit 1 of
+!-- 3D Integer array topo. However, this bit is only set when topography is read from file. In order
+!-- to run the land-surface model also without topography information, set bit 1 explicitely in this
+!-- case.
+!--
 !-- Natural terrain grid points
 !-- If no topography is initialized, the land-surface is at k = nzb.
@@ -2493,7 +2340,7 @@
           DO j = nys, nyn
              DO k = nzb, nzt+1
-!         
+!
 !--             Natural terrain grid point
-                IF ( BTEST( topo(k,j,i), 1 ) )                                 &
+                IF ( BTEST( topo(k,j,i), 1 ) )                                                     &
                    wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 5 )
              ENDDO
@@ -2506,5 +2353,5 @@
        DO j = nys, nyn
           DO k = nzb, nzt+1
-             IF ( BTEST( topo(k,j,i), 2 ) )                                    &
+             IF ( BTEST( topo(k,j,i), 2 ) )                                                        &
                 wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 6 )
           ENDDO
@@ -2516,12 +2363,12 @@
        DO j = nys, nyn
           DO k = nzb, nzt+1
-             IF ( BTEST( topo(k,j,i), 4 ) )                                    &
+             IF ( BTEST( topo(k,j,i), 4 ) )                                                        &
                 wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 4 )
           ENDDO
        ENDDO
     ENDDO
-    
+
     CALL exchange_horiz_int( wall_flags_static_0, nys, nyn, nxl, nxr, nzt, nbgp )
-    
+
     DO i = nxl, nxr
        DO j = nys, nyn
@@ -2535,14 +2382,14 @@
     CALL exchange_horiz_int( wall_flags_total_0, nys, nyn, nxl, nxr, nzt, nbgp )
 !
-!-- Set boundary conditions also for flags. Can be interpreted as Neumann
-!-- boundary conditions for topography. 
+!-- Set boundary conditions also for flags. Can be interpreted as Neumann boundary conditions for
+!-- topography.
     IF ( .NOT. bc_ns_cyc )  THEN
        IF ( nys == 0  )  THEN
-          DO  i = 1, nbgp     
+          DO  i = 1, nbgp
              wall_flags_total_0(:,nys-i,:)   = wall_flags_total_0(:,nys,:)
           ENDDO
        ENDIF
        IF ( nyn == ny )  THEN
-          DO  i = 1, nbgp  
+          DO  i = 1, nbgp
              wall_flags_total_0(:,nyn+i,:) = wall_flags_total_0(:,nyn,:)
           ENDDO
@@ -2551,16 +2398,16 @@
     IF ( .NOT. bc_lr_cyc )  THEN
        IF ( nxl == 0  )  THEN
-          DO  i = 1, nbgp   
+          DO  i = 1, nbgp
              wall_flags_total_0(:,:,nxl-i)   = wall_flags_total_0(:,:,nxl)
           ENDDO
        ENDIF
-       IF ( nxr == nx )  THEN 
-          DO  i = 1, nbgp   
-             wall_flags_total_0(:,:,nxr+i) = wall_flags_total_0(:,:,nxr)     
-          ENDDO
-       ENDIF      
+       IF ( nxr == nx )  THEN
+          DO  i = 1, nbgp
+             wall_flags_total_0(:,:,nxr+i) = wall_flags_total_0(:,:,nxr)
+          ENDDO
+       ENDIF
     ENDIF
 !
-!-- Pre-calculate topography top indices (former get_topography_top_index 
+!-- Pre-calculate topography top indices (former get_topography_top_index
 !-- function)
     ALLOCATE( topo_top_ind(nysg:nyng,nxlg:nxrg,0:4) )
@@ -2568,41 +2415,26 @@
 !-- Uppermost topography index on scalar grid
     ibit = 12
-    topo_top_ind(:,:,0) = MAXLOC(                                              &
-                                  MERGE( 1, 0,                                 &
-                                    BTEST( wall_flags_total_0(:,:,:), ibit )   &
-                                       ), DIM = 1                              &
-                                ) - 1 
-!
-!-- Uppermost topography index on u grid 
+    topo_top_ind(:,:,0) = MAXLOC( MERGE( 1, 0, BTEST( wall_flags_total_0(:,:,:), ibit ) ), DIM=1 ) &
+                          - 1
+!
+!-- Uppermost topography index on u grid
     ibit = 14
-    topo_top_ind(:,:,1) = MAXLOC(                                              &
-                                  MERGE( 1, 0,                                 &
-                                    BTEST( wall_flags_total_0(:,:,:), ibit )   &
-                                       ), DIM = 1                              &
-                                ) - 1 
-!
-!-- Uppermost topography index on v grid 
+    topo_top_ind(:,:,1) = MAXLOC( MERGE( 1, 0, BTEST( wall_flags_total_0(:,:,:), ibit ) ), DIM=1 ) &
+                          - 1
+!
+!-- Uppermost topography index on v grid
     ibit = 16
-    topo_top_ind(:,:,2) = MAXLOC(                                              &
-                                  MERGE( 1, 0,                                 &
-                                    BTEST( wall_flags_total_0(:,:,:), ibit )   &
-                                       ), DIM = 1                              &
-                                ) - 1 
+    topo_top_ind(:,:,2) = MAXLOC( MERGE( 1, 0, BTEST( wall_flags_total_0(:,:,:), ibit ) ), DIM=1 ) &
+                          - 1
 !
 !-- Uppermost topography index on w grid
     ibit = 18
-    topo_top_ind(:,:,3) = MAXLOC(                                              &
-                                  MERGE( 1, 0,                                 &
-                                    BTEST( wall_flags_total_0(:,:,:), ibit )   &
-                                       ), DIM = 1                              &
-                                ) - 1 
+    topo_top_ind(:,:,3) = MAXLOC( MERGE( 1, 0, BTEST( wall_flags_total_0(:,:,:), ibit ) ), DIM=1 ) &
+                          - 1
 !
 !-- Uppermost topography index on scalar outer grid
     ibit = 24
-    topo_top_ind(:,:,4) = MAXLOC(                                              &
-                                  MERGE( 1, 0,                                 &
-                                    BTEST( wall_flags_total_0(:,:,:), ibit )   &
-                                       ), DIM = 1                              &
-                                ) - 1
+    topo_top_ind(:,:,4) = MAXLOC( MERGE( 1, 0, BTEST( wall_flags_total_0(:,:,:), ibit ) ), DIM=1 ) &
+                          - 1
 
  END SUBROUTINE set_topo_flags
Index: /palm/trunk/SOURCE/init_masks.f90
===================================================================
--- /palm/trunk/SOURCE/init_masks.f90	(revision 4647)
+++ /palm/trunk/SOURCE/init_masks.f90	(revision 4648)
@@ -1,52 +1,53 @@
 !> @file init_masks.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4521 2020-05-06 11:39:49Z schwenkel
 ! Rename variable
-! 
+!
 ! 4502 2020-04-17 16:14:16Z schwenkel
 ! Implementation of ice microphysics
-! 
+!
 ! 4444 2020-03-05 15:59:50Z raasch
 ! bugfix: cpp-directives for serial mode added
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Corrected "Former revisions" section
-! 
+!
 ! 4069 2019-07-01 14:05:51Z Giersch
-! Masked output running index mid has been introduced as a local variable to 
-! avoid runtime error (Loop variable has been modified) in time_integration 
-! 
+! Masked output running index mid has been introduced as a local variable to avoid runtime error
+! (Loop variable has been modified) in time_integration
+!
 ! 3766 2019-02-26 16:23:41Z raasch
 ! unused variables removed
-! 
+!
 ! 3687 2019-01-22 10:42:06Z knoop
 ! unused variables removed
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
-! Move the control parameter "salsa" from salsa_mod to control_parameters 
-! (M. Kurppa)
+! Move the control parameter "salsa" from salsa_mod to control_parameters (M. Kurppa)
 !
 ! 410 2009-12-04 17:05:40Z letzel
@@ -57,42 +58,38 @@
 ! ------------
 !> Initialize masked data output
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE init_masks
 
-    USE arrays_3d,                                                             &
+    USE arrays_3d,                                                                                 &
         ONLY:  zu, zw
 
-    USE bulk_cloud_model_mod,                                                  &
-        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert,   &
-              microphysics_ice_phase
-
-    USE control_parameters,                                                    &
-        ONLY:  constant_diffusion, cloud_droplets,                             &
-               data_output_masks, data_output_masks_user,                      &
-               doav, doav_n, domask, domask_no, dz, dz_stretch_level_start,    &
-               humidity, mask, masks, mask_scale, mask_i,                      &
-               mask_i_global, mask_j, mask_j_global, mask_k, mask_k_global,    &
-               mask_k_over_surface,                                            &
-               mask_loop, mask_size, mask_size_l, mask_start_l,                &
-               mask_surface, mask_x,                                           &
-               mask_x_loop, mask_xyz_dimension, mask_y, mask_y_loop, mask_z,   &
-               mask_z_loop, max_masks,  message_string,                        &
-               passive_scalar, ocean_mode, varnamelength
-
-    USE grid_variables,                                                        &
+    USE bulk_cloud_model_mod,                                                                      &
+        ONLY: bulk_cloud_model, microphysics_ice_phase, microphysics_morrison,                     &
+              microphysics_seifert
+
+
+    USE control_parameters,                                                                        &
+        ONLY:  constant_diffusion, cloud_droplets, data_output_masks, data_output_masks_user, doav,&
+               doav_n, domask, domask_no, dz, dz_stretch_level_start, humidity, mask, masks,       &
+               mask_scale, mask_i, mask_i_global, mask_j, mask_j_global, mask_k, mask_k_global,    &
+               mask_k_over_surface, mask_loop, mask_size, mask_size_l, mask_start_l, mask_surface, &
+               mask_x, mask_x_loop, mask_xyz_dimension, mask_y, mask_y_loop, mask_z, mask_z_loop,  &
+               max_masks,  message_string, passive_scalar, ocean_mode, varnamelength
+
+    USE grid_variables,                                                                            &
         ONLY:  dx, dy
 
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  nx, nxl, nxr, ny, nyn, nys, nz, nzb, nzt
 
     USE kinds
 
-    USE module_interface,                                                      &
+    USE module_interface,                                                                          &
         ONLY:  module_interface_init_masks
 
-    USE netcdf_interface,                                                      &
+    USE netcdf_interface,                                                                          &
         ONLY:  domask_unit, netcdf_data_format
 
-    USE particle_attributes,                                                   &
+    USE particle_attributes,                                                                       &
         ONLY:  particle_advection
 
@@ -103,5 +100,5 @@
     CHARACTER (LEN=varnamelength) ::  var  !< contains variable name
     CHARACTER (LEN=7)             ::  unit !< contains unit of variable
-    
+
     CHARACTER (LEN=varnamelength), DIMENSION(max_masks,100) ::  do_mask      !< list of output variables
     CHARACTER (LEN=varnamelength), DIMENSION(max_masks,100) ::  do_mask_user !< list of user-specified output variables
@@ -120,5 +117,5 @@
     INTEGER(iwp) ::  sender       !< PE id of sending PE
 #endif
-    
+
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  tmp_array !< temporary 1D array
 
@@ -126,7 +123,7 @@
 
 !
-!-- Initial values are explicitly set here due to a bug in the Cray compiler
-!-- in case of assignments of initial values in declaration statements for
-!-- arrays with more than 9999 elements (appears with -eD only)
+!-- Initial values are explicitly set here due to a bug in the Cray compiler in case of assignments
+!-- of initial values in declaration statements for arrays with more than 9999 elements
+!-- (appears with -eD only)
     domask = ' '
 
@@ -135,19 +132,17 @@
     ALLOCATE( tmp_array( MAX(nx,ny,nz)+2 ) )
 
-    ALLOCATE( mask_i(max_masks,nxr-nxl+2), &
-              mask_j(max_masks,nyn-nys+2), &
+    ALLOCATE( mask_i(max_masks,nxr-nxl+2),                                                         &
+              mask_j(max_masks,nyn-nys+2),                                                         &
               mask_k(max_masks,nzt-nzb+2) )
 !
 !-- internal mask arrays ("mask,dimension,selection")
-    ALLOCATE( mask(max_masks,3,mask_xyz_dimension), &
-              mask_loop(max_masks,3,3) )
-    
-!
-!-- Parallel mask output not yet supported. In check_parameters data format 
-!-- is restricted and is switched back to non-parallel output. Therefore the
-!-- following error can not occur at the moment.
+    ALLOCATE( mask(max_masks,3,mask_xyz_dimension), mask_loop(max_masks,3,3) )
+
+!
+!-- Parallel mask output not yet supported. In check_parameters data format is restricted and is
+!-- switched back to non-parallel output. Therefore the following error can not occur at the moment.
     IF ( netcdf_data_format > 4 )  THEN
-       message_string = 'netCDF file formats '//                               &
-                        '5 and 6 (with parallel I/O support)'//                &
+       message_string = 'netCDF file formats '//                                                   &
+                        '5 and 6 (with parallel I/O support)'//                                    &
                         ' are currently not supported.'
        CALL message( 'init_masks', 'PA0328', 1, 2, 0, 6, 0 )
@@ -157,10 +152,10 @@
 !-- Store data output parameters for masked data output in few shared arrays
     DO  mid = 1, masks
-    
+
        do_mask     (mid,:) = data_output_masks(mid,:)
        do_mask_user(mid,:) = data_output_masks_user(mid,:)
-       mask      (mid,1,:) = mask_x(mid,:) 
+       mask      (mid,1,:) = mask_x(mid,:)
        mask      (mid,2,:) = mask_y(mid,:)
-       mask      (mid,3,:) = mask_z(mid,:) 
+       mask      (mid,3,:) = mask_z(mid,:)
 !
 !--    Flag a mask as terrain following
@@ -169,6 +164,6 @@
        ENDIF
 
-       IF ( mask_x_loop(mid,1) == -1.0_wp  .AND.  mask_x_loop(mid,2) == -1.0_wp&
-            .AND.  mask_x_loop(mid,3) == -1.0_wp )  THEN
+       IF ( mask_x_loop(mid,1) == -1.0_wp  .AND.  mask_x_loop(mid,2) == -1.0_wp  .AND.             &
+            mask_x_loop(mid,3) == -1.0_wp )  THEN
           mask_loop(mid,1,1:2) = -1.0_wp
           mask_loop(mid,1,3)   =  0.0_wp
@@ -176,6 +171,6 @@
           mask_loop(mid,1,:) = mask_x_loop(mid,:)
        ENDIF
-       IF ( mask_y_loop(mid,1) == -1.0_wp  .AND.  mask_y_loop(mid,2) == -1.0_wp&
-            .AND.  mask_y_loop(mid,3) == -1.0_wp )  THEN
+       IF ( mask_y_loop(mid,1) == -1.0_wp  .AND.  mask_y_loop(mid,2) == -1.0_wp  .AND.             &
+            mask_y_loop(mid,3) == -1.0_wp )  THEN
           mask_loop(mid,2,1:2) = -1.0_wp
           mask_loop(mid,2,3)   =  0.0_wp
@@ -183,6 +178,6 @@
           mask_loop(mid,2,:) = mask_y_loop(mid,:)
        ENDIF
-       IF ( mask_z_loop(mid,1) == -1.0_wp  .AND.  mask_z_loop(mid,2) == -1.0_wp&
-            .AND.  mask_z_loop(mid,3) == -1.0_wp )  THEN
+       IF ( mask_z_loop(mid,1) == -1.0_wp  .AND.  mask_z_loop(mid,2) == -1.0_wp  .AND.             &
+            mask_z_loop(mid,3) == -1.0_wp )  THEN
           mask_loop(mid,3,1:2) = -1.0_wp
           mask_loop(mid,3,3)   =  0.0_wp
@@ -190,14 +185,14 @@
           mask_loop(mid,3,:) = mask_z_loop(mid,:)
        ENDIF
-       
+
     ENDDO
-    
+
     mask_i = -1; mask_j = -1; mask_k = -1
-    
+
 !
 !-- Global arrays are required by define_netcdf_header.
     IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
-       ALLOCATE( mask_i_global(max_masks,nx+2), &
-                 mask_j_global(max_masks,ny+2), &
+       ALLOCATE( mask_i_global(max_masks,nx+2),                                                    &
+                 mask_j_global(max_masks,ny+2),                                                    &
                  mask_k_global(max_masks,nz+2) )
        mask_i_global = -1; mask_j_global = -1; mask_k_global = -1
@@ -217,7 +212,7 @@
           DO  WHILE ( do_mask_user(mid,j) /= ' '  .AND.  j <= 100 )
              IF ( i > 100 )  THEN
-                WRITE ( message_string, * ) 'number of output quantitities ',  &
-                     'given by data_output_mask and data_output_mask_user ',   &
-                     'exceeds the limit of 100'
+                WRITE ( message_string, * ) 'number of output quantitities ',                      &
+                                            'given by data_output_mask and data_output_mask_user ',&
+                                            'exceeds the limit of 100'
                 CALL message( 'init_masks', 'PA0329', 1, 2, 0, 6, 0 )
              ENDIF
@@ -249,6 +244,6 @@
              CASE ( 'e' )
                 IF ( constant_diffusion )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires constant_diffusion = .FALSE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires constant_diffusion = .FALSE.'
                    CALL message( 'init_masks', 'PA0103', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -257,6 +252,6 @@
              CASE ( 'thetal' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -265,10 +260,9 @@
              CASE ( 'nc' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
-                 ELSEIF ( .NOT. microphysics_morrison ) THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                         'requires  = morrison'
+                ELSEIF ( .NOT. microphysics_morrison )  THEN
+                   message_string = 'output of "' // TRIM( var ) // '" ' // 'requires  = morrison'
                    CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -277,10 +271,10 @@
              CASE ( 'ni' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
-                 ELSEIF ( .NOT. microphysics_ice_phase ) THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                         'requires  microphysics_ice_phase = .TRUE.'
+                 ELSEIF ( .NOT. microphysics_ice_phase )  THEN
+                   message_string = 'output of "' // TRIM( var ) // '" ' //                        &
+                                    'requires  microphysics_ice_phase = .TRUE.'
                    CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -289,10 +283,10 @@
              CASE ( 'nr' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
-                 ELSEIF ( .NOT. microphysics_seifert ) THEN
-                   message_string = 'output of "' // TRIM( var ) // '"' //     &
-                         'requires cloud_scheme = seifert_beheng'
+                ELSEIF ( .NOT. microphysics_seifert )  THEN
+                   message_string = 'output of "' // TRIM( var ) // '"' //                         &
+                                    'requires cloud_scheme = seifert_beheng'
                    CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -301,7 +295,7 @@
              CASE ( 'pc', 'pr' )
                 IF ( .NOT. particle_advection )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires a "particles_par"-NAMELIST in the ',       &
-                        'parameter file (PARIN)'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires a "particles_par"-NAMELIST in the ',    &
+                                               'parameter file (PARIN)'
                    CALL message( 'init_masks', 'PA0104', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -311,6 +305,6 @@
              CASE ( 'q', 'thetav' )
                 IF ( .NOT. humidity )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires humidity = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires humidity = .TRUE.'
                    CALL message( 'init_masks', 'PA0105', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -320,6 +314,6 @@
              CASE ( 'qc' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   message_string = 'output of "' // TRIM( var ) // '"' //     &
-                            'requires bulk_cloud_model = .TRUE.'
+                   message_string = 'output of "' // TRIM( var ) // '"' //                         &
+                                    'requires bulk_cloud_model = .TRUE.'
                    CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -328,7 +322,7 @@
              CASE ( 'ql' )
                 IF ( .NOT. ( bulk_cloud_model  .OR.  cloud_droplets ) )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE. or ',            &
-                        'cloud_droplets = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires bulk_cloud_model = .TRUE. or ',         &
+                                               'cloud_droplets = .TRUE.'
                    CALL message( 'init_masks', 'PA0106', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -337,6 +331,6 @@
              CASE ( 'ql_c', 'ql_v', 'ql_vp' )
                 IF ( .NOT. cloud_droplets )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires cloud_droplets = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires cloud_droplets = .TRUE.'
                    CALL message( 'init_masks', 'PA0107', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -347,6 +341,6 @@
              CASE ( 'qv' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires bulk_cloud_model = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                        '                      " requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -355,10 +349,10 @@
              CASE ( 'qi' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                            'requires bulk_cloud_model = .TRUE.'
+                   message_string = 'output of "' // TRIM( var ) // '" ' //                        &
+                                    'requires bulk_cloud_model = .TRUE.'
                    CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
                 ELSEIF ( .NOT. microphysics_ice_phase ) THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                            'requires microphysics_ice_phase = .TRUE.'
+                   message_string = 'output of "' // TRIM( var ) // '" ' //                        &
+                                    'requires microphysics_ice_phase = .TRUE.'
                    CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -367,10 +361,10 @@
              CASE ( 'qr' )
                 IF ( .NOT. bulk_cloud_model )  THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                            'requires bulk_cloud_model = .TRUE.'
+                   message_string = 'output of "' // TRIM( var ) // '" ' //                        &
+                                    'requires bulk_cloud_model = .TRUE.'
                    CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
                 ELSEIF ( .NOT. microphysics_seifert ) THEN
-                   message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                            'requires cloud_scheme = seifert_beheng'
+                   message_string = 'output of "' // TRIM( var ) // '" ' //                        &
+                                    'requires cloud_scheme = seifert_beheng'
                    CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -379,6 +373,6 @@
              CASE ( 'rho_sea_water' )
                 IF ( .NOT. ocean_mode )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires ocean mode'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires ocean mode'
                    CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -387,6 +381,6 @@
              CASE ( 's' )
                 IF ( .NOT. passive_scalar )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires passive_scalar = .TRUE.'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),                         &
+                                               '" requires passive_scalar = .TRUE.'
                    CALL message( 'init_masks', 'PA0110', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -395,6 +389,5 @@
              CASE ( 'sa' )
                 IF ( .NOT. ocean_mode )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires ocean mode'
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ), '" requires ocean mode'
                    CALL message( 'init_masks', 'PA0109', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -402,7 +395,6 @@
 
              CASE ( 'us*', 't*', 'lwp*', 'pra*', 'prr*', 'z0*', 'z0h*' )
-                WRITE ( message_string, * ) 'illegal value for data_',         &
-                     'output: "', TRIM( var ), '" is only allowed',            &
-                     'for horizontal cross section'
+                WRITE ( message_string, * ) 'illegal value for data_', 'output: "', TRIM( var ),   &
+                                            '" is only allowed', 'for horizontal cross section'
                 CALL message( 'init_masks', 'PA0111', 1, 2, 0, 6, 0 )
 
@@ -422,11 +414,11 @@
                 IF ( unit == 'illegal' )  THEN
                    IF ( do_mask_user(mid,1) /= ' ' )  THEN
-                      WRITE ( message_string, * ) 'illegal value for data_',   &
-                           'output_masks or data_output_masks_user: "',        &
-                           TRIM( do_mask(mid,i) ), '"'
+                      WRITE ( message_string, * ) 'illegal value for data_',                       &
+                                                  'output_masks or data_output_masks_user: "',     &
+                                                  TRIM( do_mask(mid,i) ), '"'
                       CALL message( 'init_masks', 'PA0018', 1, 2, 0, 6, 0 )
                    ELSE
-                      WRITE ( message_string, * ) 'illegal value for data_',   &
-                           ' output_masks : "', TRIM( do_mask(mid,i) ), '"'
+                      WRITE ( message_string, * ) 'illegal value for data_',                       &
+                                                  ' output_masks : "', TRIM( do_mask(mid,i) ), '"'
                       CALL message( 'init_masks', 'PA0330', 1, 2, 0, 6, 0 )
                    ENDIF
@@ -471,13 +463,12 @@
        ELSE
 !
-!--       Set vertical mask locations and size in case of terrain-following
-!--       output
+!--       Set vertical mask locations and size in case of terrain-following output
           count = 0
           DO  WHILE ( mask_k_over_surface(mid, count+1) >= 0 )
              m = mask_k_over_surface(mid, count+1)
              IF ( m > nz+1 )  THEN
-                WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' )               &
-                     m,' in mask ',mid,' along dimension ', 3,                 &
-                     ' exceeds (nz+1) = ',nz+1
+                WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' )  m, ' in mask ', mid,             &
+                                                                  ' along dimension ', 3,          &
+                                                                  ' exceeds (nz+1) = ', nz+1
                 CALL message( 'init_masks', 'PA0331', 1, 2, 0, 6, 0 )
              ENDIF
@@ -491,11 +482,10 @@
        ENDIF
 !
-!--    Set global masks along all three dimensions (required by
-!--    define_netcdf_header).
+!--    Set global masks along all three dimensions (required by define_netcdf_header).
 #if defined( __parallel )
 !
-!--    PE0 receives partial arrays from all processors of the respective mask
-!--    and outputs them. Here a barrier has to be set, because otherwise 
-!--    "-MPI- FATAL: Remote protocol queue full" may occur.
+!--    PE0 receives partial arrays from all processors of the respective mask and outputs them. Here
+!--    a barrier has to be set, because otherwise "-MPI- FATAL: Remote protocol queue full" may
+!--    occur.
 
        CALL MPI_BARRIER( comm2d, ierr )
@@ -519,18 +509,17 @@
 !--          Receive index limits first, then arrays.
 !--          Index limits are received in arbitrary order from the PEs.
-             CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0,  &
-                  comm2d, status, ierr )
+             CALL MPI_RECV( ind(1), 6, MPI_INTEGER, MPI_ANY_SOURCE, 0, comm2d, status, ierr )
 !
 !--          Not all PEs have data for the mask.
              IF ( ind(1) /= -9999 )  THEN
                 sender = status(MPI_SOURCE)
-                CALL MPI_RECV( tmp_array(ind(1)), ind(2)-ind(1)+1,  &
-                               MPI_INTEGER, sender, 1, comm2d, status, ierr )
+                CALL MPI_RECV( tmp_array(ind(1)), ind(2)-ind(1)+1, MPI_INTEGER, sender, 1, comm2d, &
+                               status, ierr )
                 mask_i_global(mid,ind(1):ind(2)) = tmp_array(ind(1):ind(2))
-                CALL MPI_RECV( tmp_array(ind(3)), ind(4)-ind(3)+1,  &
-                               MPI_INTEGER, sender, 2, comm2d, status, ierr )
+                CALL MPI_RECV( tmp_array(ind(3)), ind(4)-ind(3)+1, MPI_INTEGER, sender, 2, comm2d, &
+                               status, ierr )
                 mask_j_global(mid,ind(3):ind(4)) = tmp_array(ind(3):ind(4))
-                CALL MPI_RECV( tmp_array(ind(5)), ind(6)-ind(5)+1,  &
-                               MPI_INTEGER, sender, 3, comm2d, status, ierr )
+                CALL MPI_RECV( tmp_array(ind(5)), ind(6)-ind(5)+1, MPI_INTEGER, sender, 3, comm2d, &
+                               status, ierr )
                 mask_k_global(mid,ind(5):ind(6)) = tmp_array(ind(5):ind(6))
              ENDIF
@@ -539,7 +528,7 @@
        ELSE
 !
-!--       If at least part of the mask resides on the PE, send the index limits
-!--       for the target array, otherwise send -9999 to PE0.
-          IF ( mask_size_l(mid,1) > 0  .AND.  mask_size_l(mid,2) > 0  .AND.  &
+!--       If at least part of the mask resides on the PE, send the index limits for the target
+!--       array, otherwise send -9999 to PE0.
+          IF ( mask_size_l(mid,1) > 0  .AND.  mask_size_l(mid,2) > 0  .AND.                        &
                mask_size_l(mid,3) > 0  )  THEN
              ind(1) = mask_start_l(mid,1)
@@ -559,28 +548,22 @@
           IF ( ind(1) /= -9999 )  THEN
              tmp_array(:mask_size_l(mid,1)) = mask_i(mid,:mask_size_l(mid,1))
-             CALL MPI_SEND( tmp_array(1), mask_size_l(mid,1),  &
-                            MPI_INTEGER, 0, 1, comm2d, ierr )
+             CALL MPI_SEND( tmp_array(1), mask_size_l(mid,1), MPI_INTEGER, 0, 1, comm2d, ierr )
              tmp_array(:mask_size_l(mid,2)) = mask_j(mid,:mask_size_l(mid,2))
-             CALL MPI_SEND( tmp_array(1), mask_size_l(mid,2),  &
-                            MPI_INTEGER, 0, 2, comm2d, ierr )
+             CALL MPI_SEND( tmp_array(1), mask_size_l(mid,2), MPI_INTEGER, 0, 2, comm2d, ierr )
              tmp_array(:mask_size_l(mid,3)) = mask_k(mid,:mask_size_l(mid,3))
-             CALL MPI_SEND( tmp_array(1), mask_size_l(mid,3),  &
-                            MPI_INTEGER, 0, 3, comm2d, ierr )
+             CALL MPI_SEND( tmp_array(1), mask_size_l(mid,3), MPI_INTEGER, 0, 3, comm2d, ierr )
           ENDIF
        ENDIF
 !
-!--    A barrier has to be set, because otherwise some PEs may proceed too fast
-!--    so that PE0 may receive wrong data on tag 0.
+!--    A barrier has to be set, because otherwise some PEs may proceed too fast so that PE0 may
+!--    receive wrong data on tag 0.
        CALL MPI_BARRIER( comm2d, ierr )
-       
+
        IF ( netcdf_data_format > 4 )  THEN
-         
-          CALL MPI_BCAST( mask_i_global(mid,:), nx+2, MPI_INTEGER, 0, comm2d, &
-                          ierr )
-          CALL MPI_BCAST( mask_j_global(mid,:), ny+2, MPI_INTEGER, 0, comm2d, &
-                          ierr )
-          CALL MPI_BCAST( mask_k_global(mid,:), nz+2, MPI_INTEGER, 0, comm2d, &
-                          ierr ) 
-     
+
+          CALL MPI_BCAST( mask_i_global(mid,:), nx+2, MPI_INTEGER, 0, comm2d, ierr )
+          CALL MPI_BCAST( mask_j_global(mid,:), ny+2, MPI_INTEGER, 0, comm2d, ierr )
+          CALL MPI_BCAST( mask_k_global(mid,:), nz+2, MPI_INTEGER, 0, comm2d, ierr )
+
        ENDIF
 
@@ -596,17 +579,16 @@
     DEALLOCATE( tmp_array )
 !
-!-- Internal mask arrays cannot be deallocated on PE 0 because they are
-!-- required for header output on PE 0.
+!-- Internal mask arrays cannot be deallocated on PE 0 because they are required for header output
+!-- on PE 0.
     IF ( myid /= 0 )  DEALLOCATE( mask, mask_loop )
 
  CONTAINS
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Set local mask for each subdomain along 'dim' direction.
-!------------------------------------------------------------------------------!
-    SUBROUTINE set_mask_locations( dim, dxyz, dxyz_string, nxyz, nxyz_string, &
-                                   lb, ub )
+!--------------------------------------------------------------------------------------------------!
+    SUBROUTINE set_mask_locations( dim, dxyz, dxyz_string, nxyz, nxyz_string, lb, ub )
 
        IMPLICIT NONE
@@ -614,5 +596,5 @@
        CHARACTER (LEN=2) ::  dxyz_string !<
        CHARACTER (LEN=2) ::  nxyz_string !<
-       
+
        INTEGER(iwp)  ::  count       !<
        INTEGER(iwp)  ::  count_l     !<
@@ -625,5 +607,5 @@
        INTEGER(iwp)  ::  nxyz        !<
        INTEGER(iwp)  ::  ub          !<
-       
+
        REAL(wp)      ::  dxyz  !<
        REAL(wp)      ::  ddxyz !<
@@ -631,6 +613,6 @@
        REAL(wp)      ::  tmp2  !<
 
-       count = 0;  count_l = 0  
-       ddxyz = 1.0_wp / dxyz  
+       count = 0;  count_l = 0
+       ddxyz = 1.0_wp / dxyz
        tmp1  = 0.0_wp
        tmp2  = 0.0_wp
@@ -638,8 +620,8 @@
        IF ( mask(mid,dim,1) >= 0.0_wp )  THEN
 !
-!--       use predefined mask_* array
+!--       Use predefined mask_* array
           DO  WHILE ( mask(mid,dim,count+1) >= 0.0_wp )
              count = count + 1
-             IF ( dim == 1 .OR. dim == 2 )  THEN
+             IF ( dim == 1  .OR.  dim == 2 )  THEN
                 m = NINT( mask(mid,dim,count) * mask_scale(dim) * ddxyz - 0.5_wp )
                 IF ( m < 0 )  m = 0  ! avoid negative values
@@ -650,11 +632,11 @@
              ENDIF
              IF ( m > (nxyz+1) )  THEN
-                WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' )               &
-                     m,' in mask ',mid,' along dimension ',dim,                &
-                     ' exceeds (',nxyz_string,'+1) = ',nxyz+1
+                WRITE ( message_string, '(I3,A,I3,A,I1,3A,I3)' )  m, ' in mask ', mid,             &
+                                                                  ' along dimension ' ,dim,        &
+                                                                  ' exceeds (' ,nxyz_string,       &
+                                                                  '+1) = ', nxyz+1
                 CALL message( 'init_masks', 'PA0331', 1, 2, 0, 6, 0 )
              ENDIF
-             IF ( ( m >= lb .AND. m <= ub ) .OR.     &
-                  ( m == (nxyz+1) .AND. ub == nxyz )  )  THEN
+             IF ( ( m >= lb  .AND.  m <= ub )  .OR.  ( m == (nxyz+1)  .AND.  ub == nxyz )  )  THEN
                 IF ( count_l == 0 )  mask_start_l(mid,dim) = count
                 count_l = count_l + 1
@@ -674,6 +656,6 @@
        ELSE
 !
-!--       use predefined mask_loop_* array, or use the default (all grid points
-!--       along this direction)
+!--       Use predefined mask_loop_* array, or use the default (all grid points along this
+!--       direction)
           IF ( mask_loop(mid,dim,1) < 0.0_wp )  THEN
              tmp1 = mask_loop(mid,dim,1)
@@ -687,18 +669,14 @@
              IF ( MAXVAL( mask_loop(mid,dim,1:2) )  &
                   > (nxyz+1) * dxyz / mask_scale(dim) )  THEN
-                WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),5A,I1,A,F9.3)' ) &
-                     'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1),     &
-                     ' and/or mask_loop(',mid,',',dim,',2)=', &
-                     mask_loop(mid,dim,2),' exceed (', &
-                     nxyz_string,'+1)*',dxyz_string,'/mask_scale(',dim,')=',   &
+                WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),5A,I1,A,F9.3)' )                     &
+                     'mask_loop(', mid, ',', dim, ',1)=', mask_loop(mid,dim,1),                    &
+                     ' and/or mask_loop(', mid, ',', dim, ',2)=', mask_loop(mid,dim,2),            &
+                     ' exceed (', nxyz_string,'+1)*',dxyz_string,'/mask_scale(',dim,')=',          &
                      (nxyz+1)*dxyz/mask_scale(dim)
                 CALL message( 'init_masks', 'PA0332', 1, 2, 0, 6, 0 )
              ENDIF
-             loop_begin  = NINT( mask_loop(mid,dim,1) * mask_scale(dim)        &
-                  * ddxyz - 0.5_wp )
-             loop_end    = NINT( mask_loop(mid,dim,2) * mask_scale(dim)        &
-                  * ddxyz - 0.5_wp )
-             loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim)        &
-                  * ddxyz )
+             loop_begin  = NINT( mask_loop(mid,dim,1) * mask_scale(dim) * ddxyz - 0.5_wp )
+             loop_end    = NINT( mask_loop(mid,dim,2) * mask_scale(dim) * ddxyz - 0.5_wp )
+             loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz )
              IF ( loop_begin == -1 )  loop_begin = 0  ! avoid negative values
           ELSEIF ( dim == 3 )  THEN
@@ -707,36 +685,29 @@
                 mask_loop(mid,dim,2) = zu(nz+1) / mask_scale(dim)   ! (default)
              ENDIF
-             IF ( MAXVAL( mask_loop(mid,dim,1:2) )  &
-                  > zu(nz+1) / mask_scale(dim) )  THEN
-                WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),A,I1,A,F9.3)' )  &
-                     'mask_loop(',mid,',',dim,',1)=',mask_loop(mid,dim,1),     &
-                     ' and/or mask_loop(',mid,',',dim,',2)=', &
-                     mask_loop(mid,dim,2),' exceed zu(nz+1)/mask_scale(',dim,  &
-                     ')=',zu(nz+1)/mask_scale(dim)
+             IF ( MAXVAL( mask_loop(mid,dim,1:2) ) > zu(nz+1) / mask_scale(dim) )  THEN
+                WRITE ( message_string, '(2(A,I3,A,I1,A,F9.3),A,I1,A,F9.3)' )                      &
+                      'mask_loop(', mid, ',', dim, ',1)=', mask_loop(mid,dim,1),                   &
+                      ' and/or mask_loop(', mid, ',', dim, ',2)=', mask_loop(mid,dim,2),           &
+                      ' exceed zu(nz+1)/mask_scale(', dim, ')=',zu(nz+1)/mask_scale(dim)
                 CALL message( 'init_masks', 'PA0333', 1, 2, 0, 6, 0 )
              ENDIF
-             ind_array =  &
-                  MINLOC( ABS( mask_loop(mid,dim,1) * mask_scale(dim) - zu ) )
-             loop_begin =  &
-                  ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1
-             ind_array =  &
-                  MINLOC( ABS( mask_loop(mid,dim,2) * mask_scale(dim) - zu ) )
-             loop_end = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1
-!
-!--          The following line assumes a constant vertical grid spacing within
-!--          the vertical mask range; it fails for vertical grid stretching.
-!--          Maybe revise later. Issue warning but continue execution. ABS(...)
-!--          within the IF statement is necessary because the default value of
-!--          dz_stretch_level_start is -9999999.9_wp.
+             ind_array  = MINLOC( ABS( mask_loop(mid,dim,1) * mask_scale(dim) - zu ) )
+             loop_begin = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1
+             ind_array  = MINLOC( ABS( mask_loop(mid,dim,2) * mask_scale(dim) - zu ) )
+             loop_end   = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1
+!
+!--          The following line assumes a constant vertical grid spacing within the vertical mask
+!--          range; it fails for vertical grid stretching.
+!--          Maybe revise later. Issue warning but continue execution. ABS(...) within the IF
+!--          statement is necessary because the default value of dz_stretch_level_start is
+!--          -9999999.9_wp.
              loop_stride = NINT( mask_loop(mid,dim,3) * mask_scale(dim) * ddxyz )
 
-             IF ( mask_loop(mid,dim,2) * mask_scale(dim) >                     &
-                  ABS( dz_stretch_level_start(1) ) )  THEN
-                WRITE ( message_string, '(A,I3,A,I1,A,F9.3,A,F8.2,3A)' )       &
-                     'mask_loop(',mid,',',dim,',2)=', mask_loop(mid,dim,2),    &
-                     ' exceeds dz_stretch_level=',dz_stretch_level_start(1),   &
-                     '.&Vertical mask locations will not ',                    &
-                     'match the desired heights within the stretching ',       &
-                     'region.'
+             IF ( mask_loop(mid,dim,2) * mask_scale(dim) > ABS( dz_stretch_level_start(1) ) )  THEN
+                WRITE ( message_string, '(A,I3,A,I1,A,F9.3,A,F8.2,3A)' )                           &
+                      'mask_loop(', mid, ',', dim, ',2)=', mask_loop(mid,dim,2),                   &
+                      ' exceeds dz_stretch_level=', dz_stretch_level_start(1),                     &
+                      '.&Vertical mask locations will not ',                                       &
+                      'match the desired heights within the stretching ', 'region.'
                 CALL message( 'init_masks', 'PA0334', 0, 1, 0, 6, 0 )
              ENDIF
@@ -748,6 +719,6 @@
           IF ( tmp2 < 0.0_wp )  mask_loop(mid,dim,2) = tmp2
 !
-!--       The default stride +/-1 (every grid point) applies if 
-!--       mask_loop(mid,dim,3) is not specified (its default is zero).
+!--       The default stride +/-1 (every grid point) applies if mask_loop(mid,dim,3) is not
+!--       specified (its default is zero).
           IF ( loop_stride == 0 )  THEN
              IF ( loop_end >= loop_begin )  THEN
@@ -759,6 +730,5 @@
           DO  m = loop_begin, loop_end, loop_stride
              count = count + 1
-             IF ( ( m >= lb  .AND.  m <= ub ) .OR.   &
-                  ( m == (nxyz+1) .AND. ub == nxyz )  )  THEN
+             IF ( ( m >= lb  .AND.  m <= ub ) .OR.  ( m == (nxyz+1) .AND. ub == nxyz )  )  THEN
                 IF ( count_l == 0 )  mask_start_l(mid,dim) = count
                 count_l = count_l + 1
Index: /palm/trunk/SOURCE/init_pegrid.f90
===================================================================
--- /palm/trunk/SOURCE/init_pegrid.f90	(revision 4647)
+++ /palm/trunk/SOURCE/init_pegrid.f90	(revision 4648)
@@ -1,73 +1,72 @@
 !> @file init_pegrid.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
-!
-! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Current revisions:
 ! ------------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4564 2020-06-12 14:03:36Z raasch
 ! Vertical nesting method of Huq et al. (2019) removed
-! 
+!
 ! 4461 2020-03-12 16:51:59Z raasch
 ! communicator configurations for four virtual pe grids defined
-! 
+!
 ! 4444 2020-03-05 15:59:50Z raasch
 ! bugfix: cpp-directives for serial mode added
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! changed message PA0467
-! 
+!
 ! 4264 2019-10-15 16:00:23Z scharf
 ! corrected error message string
-! 
+!
 ! 4241 2019-09-27 06:32:47Z raasch
-! Check added to ensure that subdomain grid has at least the size as given by the number
-! of ghost points
-! 
+! Check added to ensure that subdomain grid has at least the size as given by the number of ghost
+! points
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 4045 2019-06-21 10:58:47Z raasch
-! bugfix: kind attribute added to nint function to allow for large integers which may appear in
-! case of default recycling width and small grid spacings
-! 
+! bugfix: kind attribute added to nint function to allow for large integers which may appear in case
+!         of default recycling width and small grid spacings
+!
 ! 3999 2019-05-23 16:09:37Z suehring
 ! Spend 3 ghost points also in case of pw-scheme when nesting is applied
-! 
+!
 ! 3897 2019-04-15 11:51:14Z suehring
 ! Minor revision of multigrid check; give warning instead of an abort.
-! 
+!
 ! 3890 2019-04-12 15:59:20Z suehring
-! Check if grid coarsening is possible on subdomain, in order to avoid that 
-! multigrid approach effectively reduces to a Gauss-Seidel scheme.
-! 
+! Check if grid coarsening is possible on subdomain, in order to avoid that multigrid approach
+! effectively reduces to a Gauss-Seidel scheme.
+!
 ! 3885 2019-04-11 11:29:34Z kanani
-! Changes related to global restructuring of location messages and introduction 
-! of additional debug messages
-! 
+! Changes related to global restructuring of location messages and introduction of additional debug
+! messages
+!
 ! 3884 2019-04-10 13:31:55Z Giersch
 ! id_recycling is only calculated in case of tubulent inflow
-! 
+!
 ! 3761 2019-02-25 15:31:42Z raasch
 ! unused variable removed
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! variables documented
@@ -79,66 +78,57 @@
 ! Description:
 ! ------------
-!> Determination of the virtual processor topology (if not prescribed by the
-!> user)and computation of the grid point number and array bounds of the local
-!> domains.
-!> @todo: remove MPI-data types for 2D exchange on coarse multigrid level (not
-!>        used any more) 
-!------------------------------------------------------------------------------!
+!> Determination of the virtual processor topology (if not prescribed by the user) and computation
+!> of the grid point number and array bounds of the local domains.
+!> @todo: remove MPI-data types for 2D exchange on coarse multigrid level (not used any more)
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE init_pegrid
- 
-
-    USE control_parameters,                                                    &
-        ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s, &
-               bc_lr, bc_ns, bc_radiation_l, bc_radiation_n, bc_radiation_r,   &
-               bc_radiation_s, &
-               grid_level, grid_level_count, maximum_grid_level,               &
-               message_string, mg_switch_to_pe0_level,         &
-               psolver
+
+
+    USE control_parameters,                                                                        &
+        ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s, bc_lr, bc_ns,       &
+               bc_radiation_l, bc_radiation_n, bc_radiation_r, bc_radiation_s, grid_level,         &
+               grid_level_count, maximum_grid_level, message_string, mg_switch_to_pe0_level, psolver
 
 
 #if defined( __parallel )
-    USE control_parameters,                                                    &
-        ONLY:  coupling_mode, coupling_topology, gathered_size, momentum_advec, &
-               outflow_source_plane, recycling_width, scalar_advec, subdomain_size, &
+    USE control_parameters,                                                                        &
+        ONLY:  coupling_mode, coupling_topology, gathered_size, momentum_advec,                    &
+               outflow_source_plane, recycling_width, scalar_advec, subdomain_size,                &
                turbulent_inflow, turbulent_outflow, y_shift
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                                            &
         ONLY:  dx
 #endif
-        
-    USE indices,                                                               &
-        ONLY:  nnx, nny, nnz, nx, nxl, nxl_mg,   &
-               nxlu, nxr, nxr_mg, ny, nyn, nyn_mg, nys, nys_mg,    &
-               nysv, nz, nzb, nzt, nzt_mg, wall_flags_1, wall_flags_2,         &
-               wall_flags_3, wall_flags_4, wall_flags_5, wall_flags_6,         &
-               wall_flags_7, wall_flags_8, wall_flags_9, wall_flags_10
+
+    USE indices,                                                                                   &
+        ONLY:  nnx, nny, nnz, nx, nxl, nxl_mg, nxlu, nxr, nxr_mg, ny, nyn, nyn_mg, nys, nys_mg,    &
+               nysv, nz, nzb, nzt, nzt_mg, wall_flags_1, wall_flags_2, wall_flags_3, wall_flags_4, &
+               wall_flags_5, wall_flags_6, wall_flags_7, wall_flags_8, wall_flags_9, wall_flags_10
 
 #if defined( __parallel )
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  mg_loc_ind, nbgp, nx_a, nx_o, ny_a, ny_o
 #endif
 
     USE kinds
-      
+
     USE pegrid
-    
+
 #if defined( __parallel )
-    USE pmc_interface,                                                         &
+    USE pmc_interface,                                                                             &
         ONLY:  nested_run
 
-    USE spectra_mod,                                                           &
+    USE spectra_mod,                                                                               &
         ONLY:  calculate_spectra
 
-    USE synthetic_turbulence_generator_mod,                                    &
-        ONLY:  id_stg_left, id_stg_north, id_stg_right, id_stg_south,          &
-               use_syn_turb_gen
+    USE synthetic_turbulence_generator_mod,                                                        &
+        ONLY:  id_stg_left, id_stg_north, id_stg_right, id_stg_south, use_syn_turb_gen
 #endif
 
-    USE transpose_indices,                                                     &
-        ONLY:  nxl_y, nxl_z, nxr_y, nxr_z, nyn_x, nyn_z, nys_x,&
-               nys_z, nzb_x, nzb_y, nzt_x, nzt_y
+    USE transpose_indices,                                                                         &
+        ONLY:  nxl_y, nxl_z, nxr_y, nxr_z, nyn_x, nyn_z, nys_x, nys_z, nzb_x, nzb_y, nzt_x, nzt_y
 
 #if defined( __parallel )
-    USE transpose_indices,                                                     &
+    USE transpose_indices,                                                                         &
         ONLY:  nxl_yd, nxr_yd, nzb_yd, nzt_yd
 #endif
@@ -152,8 +142,8 @@
     INTEGER(iwp) ::  id_outflow_source_l      !< local value of id_outflow_source
     INTEGER(iwp) ::  id_recycling_l           !< ID indicating processors located at the recycling plane
-    INTEGER(iwp) ::  id_stg_left_l            !< left lateral boundary local core id in case of turbulence generator  
-    INTEGER(iwp) ::  id_stg_north_l           !< north lateral boundary local core id in case of turbulence generator  
-    INTEGER(iwp) ::  id_stg_right_l           !< right lateral boundary local core id in case of turbulence generator  
-    INTEGER(iwp) ::  id_stg_south_l           !< south lateral boundary local core id in case of turbulence generator  
+    INTEGER(iwp) ::  id_stg_left_l            !< left lateral boundary local core id in case of turbulence generator
+    INTEGER(iwp) ::  id_stg_north_l           !< north lateral boundary local core id in case of turbulence generator
+    INTEGER(iwp) ::  id_stg_right_l           !< right lateral boundary local core id in case of turbulence generator
+    INTEGER(iwp) ::  id_stg_south_l           !< south lateral boundary local core id in case of turbulence generator
     INTEGER(iwp) ::  ind(5)                   !< array containing the subdomain bounds
 #endif
@@ -222,10 +212,10 @@
 
 !
-!--    Prescribed by user. Number of processors on the prescribed topology
-!--    must be equal to the number of PEs available to the job
+!--    Prescribed by user. Number of processors on the prescribed topology must be equal to the
+!--    number of PEs available to the job
        IF ( ( npex * npey ) /= numprocs )  THEN
-          WRITE( message_string, * ) 'number of PEs of the prescribed ',       &
-              'topology (', npex*npey,') does not match & the number of ',     &
-              'PEs available to the job (', numprocs, ')'
+          WRITE( message_string, * ) 'number of PEs of the prescribed ', 'topology (', npex*npey,  &
+                                     ') does not match & the number of ',                          &
+                                     'PEs available to the job (', numprocs, ')'
           CALL message( 'init_pegrid', 'PA0221', 1, 2, 0, 6, 0 )
        ENDIF
@@ -237,7 +227,7 @@
 !--    If the processor topology is prescribed by the user, the number of
 !--    PEs must be given in both directions
-       message_string = 'if the processor topology is prescribed by th' //     &
-                'e user & both values of "npex" and "npey" must be given' //   &
-                ' in the &NAMELIST-parameter file'
+       message_string = 'if the processor topology is prescribed by th' //                         &
+                        'e user & both values of "npex" and "npey" must be given' //               &
+                        ' in the &NAMELIST-parameter file'
        CALL message( 'init_pegrid', 'PA0222', 1, 2, 0, 6, 0 )
 
@@ -245,6 +235,6 @@
 
 !
-!-- Create four default MPI communicators for the 2d virtual PE grid. One of them will be used
-!-- as the main communicator for this run, while others might be used for specific quantities like
+!-- Create four default MPI communicators for the 2d virtual PE grid. One of them will be used as
+!-- the main communicator for this run, while others might be used for specific quantities like
 !-- aerosol, chemical species, or passive scalars), if their horizontal boundary conditions shall
 !-- be different from those of the other quantities (e.g. non-cyclic conditions for aerosols, and
@@ -297,12 +287,10 @@
 
 !
-!-- In case of cyclic boundary conditions, a y-shift at the boundaries in
-!-- x-direction can be introduced via parameter y_shift. The shift is done
-!-- by modifying the processor grid in such a way that processors located
-!-- at the x-boundary communicate across it to processors with y-coordinate
-!-- shifted by y_shift relative to their own. This feature can not be used
-!-- in combination with an fft pressure solver. It has been implemented to
-!-- counter the effect of streak structures in case of cyclic boundary
-!-- conditions. For a description of these see Munters
+!-- In case of cyclic boundary conditions, a y-shift at the boundaries in x-direction can be
+!-- introduced via parameter y_shift. The shift is done by modifying the processor grid in such a
+!-- way that processors located at the x-boundary communicate across it to processors with
+!-- y-coordinate shifted by y_shift relative to their own. This feature can not be used in
+!-- combination with an fft pressure solver. It has been implemented to counter the effect of streak
+!-- structures in case of cyclic boundary conditions. For a description of these see Munters
 !-- (2016; dx.doi.org/10.1063/1.4941912)
 !--
@@ -310,7 +298,5 @@
     IF ( y_shift /= 0 ) THEN
        IF ( bc_lr == 'cyclic' ) THEN
-          IF ( TRIM( psolver ) /= 'multigrid' .AND.                            &
-                TRIM( psolver ) /= 'multigrid_noopt')                          &
-          THEN
+          IF ( TRIM( psolver ) /= 'multigrid' .AND.  TRIM( psolver ) /= 'multigrid_noopt')  THEN
              message_string = 'y_shift /= 0 requires a multigrid pressure solver '
              CALL message( 'check_parameters', 'PA0468', 1, 2, 0, 6, 0 )
@@ -320,34 +306,33 @@
           CALL MPI_CART_COORDS( comm2d, pleft, ndim, lcoord, ierr )
 
-!   
-!--       If the x(y)-coordinate of the right (left) neighbor is smaller (greater)
-!--       than that of the calling process, then the calling process is located on
-!--       the right (left) boundary of the processor grid. In that case,
-!--       the y-coordinate of that neighbor is increased (decreased) by y_shift.
-!--       The rank of the process with that coordinate is then inquired and the
-!--       neighbor rank for MPI_SENDRECV, pright (pleft) is set to it.
-!--       In this way, the calling process receives a new right (left) neighbor
-!--       for all future MPI_SENDRECV calls. That neighbor has a y-coordinate
-!--       of y+(-)y_shift, where y is the original right (left) neighbor's
-!--       y-coordinate. The modulo-operation ensures that if the neighbor's
-!--       y-coordinate exceeds the grid-boundary, it will be relocated to
-!--       the opposite part of the grid cyclicly.
-          IF ( rcoord(1) < pcoord(1) ) THEN
+!
+!--       If the x(y)-coordinate of the right (left) neighbor is smaller (greater) than that of the
+!--       calling process, then the calling process is located on the right (left) boundary of the
+!--       processor grid. In that case, the y-coordinate of that neighbor is increased (decreased)
+!--       by y_shift.
+!--       The rank of the process with that coordinate is then inquired and the neighbor rank for
+!--       MPI_SENDRECV, pright (pleft) is set to it.
+!--       In this way, the calling process receives a new right (left) neighbor for all future
+!--       MPI_SENDRECV calls. That neighbor has a y-coordinate of y+(-)y_shift, where y is the
+!--       original right (left) neighbor's y-coordinate. The modulo-operation ensures that if the
+!--       neighbor's y-coordinate exceeds the grid-boundary, it will be relocated to the opposite
+!--       part of the grid cyclicly.
+          IF ( rcoord(1) < pcoord(1) )  THEN
              rcoord(2) = MODULO( rcoord(2) + y_shift, pdims(2) )
              CALL MPI_CART_RANK( comm2d, rcoord, pright, ierr )
           ENDIF
 
-          IF ( lcoord(1) > pcoord(1) ) THEN
+          IF ( lcoord(1) > pcoord(1) )  THEN
              lcoord(2) = MODULO( lcoord(2) - y_shift, pdims(2) )
              CALL MPI_CART_RANK( comm2d, lcoord, pleft, ierr )
           ENDIF
-         
+
        ELSE
 !
-!--       y-shift for non-cyclic boundary conditions is only implemented 
+!--       y-shift for non-cyclic boundary conditions is only implemented
 !--       for the turbulence recycling method in inflow_turbulence.f90
           IF ( .NOT. turbulent_inflow )  THEN
-             message_string = 'y_shift /= 0 is only allowed for cyclic ' //    &
-                              'boundary conditions in both directions '  //    &
+             message_string = 'y_shift /= 0 is only allowed for cyclic ' //                        &
+                              'boundary conditions in both directions '  //                        &
                               'or with turbulent_inflow == .TRUE.'
              CALL message( 'check_parameters', 'PA0467', 1, 2, 0, 6, 0 )
@@ -373,11 +358,10 @@
 !
 !-- Calculate array bounds along x-direction for every PE.
-    ALLOCATE( nxlf(0:pdims(1)-1), nxrf(0:pdims(1)-1), nynf(0:pdims(2)-1),      &
-              nysf(0:pdims(2)-1) )
+    ALLOCATE( nxlf(0:pdims(1)-1), nxrf(0:pdims(1)-1), nynf(0:pdims(2)-1), nysf(0:pdims(2)-1) )
 
     IF ( MOD( nx+1 , pdims(1) ) /= 0 )  THEN
-       WRITE( message_string, * ) 'x-direction: gridpoint number (',nx+1,') ', &
-                                  'is not an& integral multiple of the number',&
-                                  ' of processors (',pdims(1),')'
+       WRITE( message_string, * ) 'x-direction: gridpoint number (' ,nx+1, ') ',                   &
+                                  'is not an& integral multiple of the number',                    &
+                                  ' of processors (', pdims(1), ')'
        CALL message( 'init_pegrid', 'PA0225', 1, 2, 0, 6, 0 )
     ELSE
@@ -395,7 +379,7 @@
 !-- Calculate array bounds in y-direction for every PE.
     IF ( MOD( ny+1 , pdims(2) ) /= 0 )  THEN
-       WRITE( message_string, * ) 'y-direction: gridpoint number (',ny+1,') ', &
-                                  'is not an& integral multiple of the number',&
-                                  ' of processors (',pdims(2),')'
+       WRITE( message_string, * ) 'y-direction: gridpoint number (', ny+1, ') ',                   &
+                                  'is not an& integral multiple of the number',                    &
+                                  ' of processors (', pdims(2), ')'
        CALL message( 'init_pegrid', 'PA0227', 1, 2, 0, 6, 0 )
     ELSE
@@ -421,6 +405,5 @@
 
 !
-!-- Set switches to define if the PE is situated at the border of the virtual
-!-- processor grid
+!-- Set switches to define if the PE is situated at the border of the virtual processor grid
     IF ( nxl == 0 )   left_border_pe  = .TRUE.
     IF ( nxr == nx )  right_border_pe = .TRUE.
@@ -429,8 +412,8 @@
 
 !
-!-- Calculate array bounds and gridpoint numbers for the transposed arrays
-!-- (needed in the pressure solver)
-!-- For the transposed arrays, cyclic boundaries as well as top and bottom
-!-- boundaries are omitted, because they are obstructive to the transposition
+!-- Calculate array bounds and gridpoint numbers for the transposed arrays (needed in the pressure
+!-- solver)
+!-- For the transposed arrays, cyclic boundaries as well as top and bottom boundaries are omitted,
+!-- because they are obstructive to the transposition
 
 !
@@ -441,7 +424,7 @@
        IF ( pdims(2) /= 1 )  THEN
           IF ( MOD( nz , pdims(1) ) /= 0 )  THEN
-             WRITE( message_string, * ) 'transposition z --> x:& ',              &
-                                        'nz=',nz,' is not an integral multiple ',&
-                                        'of pdims(1)=',pdims(1)
+             WRITE( message_string, * ) 'transposition z --> x:& ',                                &
+                                        'nz=', nz, ' is not an integral multiple ',                &
+                                        'of pdims(1)=', pdims(1)
              CALL message( 'init_pegrid', 'PA0230', 1, 2, 0, 6, 0 )
           ENDIF
@@ -463,7 +446,7 @@
 !--    2. transposition  x --> y
        IF ( MOD( nx+1 , pdims(2) ) /= 0 )  THEN
-          WRITE( message_string, * ) 'transposition x --> y:& ',              &
-                                     'nx+1=',nx+1,' is not an integral ',     &
-                                     'multiple of pdims(2)=',pdims(2)
+          WRITE( message_string, * ) 'transposition x --> y:& ',                                   &
+                                     'nx+1=', nx+1, ' is not an integral ',                        &
+                                     'multiple of pdims(2)=', pdims(2)
           CALL message( 'init_pegrid', 'PA0231', 1, 2, 0, 6, 0 )
        ENDIF
@@ -492,7 +475,7 @@
 !--       along x, except that the uptream-spline method is switched on
           IF ( MOD( ny+1 , pdims(1) ) /= 0 )  THEN
-             WRITE( message_string, * ) 'transposition y --> z:& ',            &
-                                        'ny+1=',ny+1,' is not an integral ',   &
-                                        'multiple of pdims(1)=',pdims(1)
+             WRITE( message_string, * ) 'transposition y --> z:& ',                                &
+                                        'ny+1=', ny+1, ' is not an integral ',                     &
+                                        'multiple of pdims(1)=', pdims(1)
              CALL message( 'init_pegrid', 'PA0232', 1, 2, 0, 6, 0 )
           ENDIF
@@ -503,7 +486,7 @@
 !--       This condition must be fulfilled for a 1D-decomposition along x
           IF ( MOD( ny+1 , pdims(1) ) /= 0 )  THEN
-             WRITE( message_string, * ) 'transposition x --> y:& ',            &
-                                        'ny+1=',ny+1,' is not an integral ',   &
-                                        'multiple of pdims(1)=',pdims(1)
+             WRITE( message_string, * ) 'transposition x --> y:& ',                                &
+                                        'ny+1=', ny+1, ' is not an integral ',                     &
+                                        'multiple of pdims(1)=', pdims(1)
              CALL message( 'init_pegrid', 'PA0233', 1, 2, 0, 6, 0 )
           ENDIF
@@ -517,7 +500,7 @@
     IF ( calculate_spectra )  THEN
        IF ( MOD( nz, pdims(2) ) /= 0 )  THEN
-          WRITE( message_string, * ) 'direct transposition z --> y (needed ',  &
-                                     'for spectra):& nz=',nz,' is not an ',    &
-                                     'integral multiple of pdims(2)=',pdims(2)
+          WRITE( message_string, * ) 'direct transposition z --> y (needed ',                      &
+                                     'for spectra):& nz=', nz, ' is not an ',                      &
+                                     'integral multiple of pdims(2)=', pdims(2)
           CALL message( 'init_pegrid', 'PA0234', 1, 2, 0, 6, 0 )
        ELSE
@@ -532,5 +515,5 @@
     IF ( psolver == 'poisfft'  .OR.  calculate_spectra )  THEN
 !
-!--    Indices for direct transpositions y --> x 
+!--    Indices for direct transpositions y --> x
 !--    (they are only possible in case of a 1d-decomposition along x)
        IF ( pdims(2) == 1 )  THEN
@@ -547,5 +530,5 @@
     IF ( psolver == 'poisfft' )  THEN
 !
-!--    Indices for direct transpositions x --> y 
+!--    Indices for direct transpositions x --> y
 !--    (they are only possible in case of a 1d-decomposition along y)
        IF ( pdims(1) == 1 )  THEN
@@ -579,6 +562,5 @@
 !--    Receive data from all other PEs
        DO  i = 1, numprocs-1
-          CALL MPI_RECV( ibuf, 4, MPI_INTEGER, i, MPI_ANY_TAG, comm2d, status, &
-                         ierr )
+          CALL MPI_RECV( ibuf, 4, MPI_INTEGER, i, MPI_ANY_TAG, comm2d, status, ierr )
           hor_index_bounds(:,i) = ibuf(1:4)
        ENDDO
@@ -602,18 +584,14 @@
        PRINT*, '*** processor topology ***'
        PRINT*, ' '
-       PRINT*, 'myid   pcoord    left right  south north  idx idy   nxl: nxr',&
-               &'   nys: nyn'
-       PRINT*, '------------------------------------------------------------',&
-               &'-----------'
-       WRITE (*,1000)  0, pcoord(1), pcoord(2), pleft, pright, psouth, pnorth, &
-                       myidx, myidy, nxl, nxr, nys, nyn
-1000   FORMAT (I4,2X,'(',I3,',',I3,')',3X,I4,2X,I4,3X,I4,2X,I4,2X,I3,1X,I3, &
-               2(2X,I4,':',I4))
+       PRINT*, 'myid   pcoord    left right  south north  idx idy   nxl: nxr','   nys: nyn'
+       PRINT*, '------------------------------------------------------------','-----------'
+       WRITE (*,1000)  0, pcoord(1), pcoord(2), pleft, pright, psouth, pnorth, myidx, myidy, nxl,  &
+                       nxr, nys, nyn
+1000   FORMAT (I4,2X,'(',I3,',',I3,')',3X,I4,2X,I4,3X,I4,2X,I4,2X,I3,1X,I3,2(2X,I4,':',I4))
 
 !
 !--    Receive data from the other PEs
        DO  i = 1,numprocs-1
-          CALL MPI_RECV( ibuf, 12, MPI_INTEGER, i, MPI_ANY_TAG, comm2d, status, &
-                         ierr )
+          CALL MPI_RECV( ibuf, 12, MPI_INTEGER, i, MPI_ANY_TAG, comm2d, status, ierr )
           WRITE (*,1000)  i, ( ibuf(j) , j = 1,12 )
        ENDDO
@@ -626,20 +604,20 @@
        ibuf(8) = myidy; ibuf(9) = nxl; ibuf(10) = nxr; ibuf(11) = nys
        ibuf(12) = nyn
-       CALL MPI_SEND( ibuf, 12, MPI_INTEGER, 0, myid, comm2d, ierr )       
+       CALL MPI_SEND( ibuf, 12, MPI_INTEGER, 0, myid, comm2d, ierr )
     ENDIF
 #endif
 
-! 
+!
 !-- Determine the number of ghost point layers
-    IF ( scalar_advec   == 'ws-scheme'  .OR.                                   &
+    IF ( scalar_advec   == 'ws-scheme'  .OR.                                                       &
          momentum_advec == 'ws-scheme'  .OR.  nested_run )  THEN
        nbgp = 3
     ELSE
        nbgp = 1
-    ENDIF 
-
-!
-!-- Check that the number of computational grid points is not smaller than the number of
-!-- ghost points.
+    ENDIF
+
+!
+!-- Check that the number of computational grid points is not smaller than the number of ghost
+!-- points.
     IF ( nnx < nbgp )  THEN
        WRITE( message_string, * ) 'number of subdomain grid points along x (', nnx, ') is smaller',&
@@ -654,6 +632,6 @@
 
 !
-!-- Create a new MPI derived datatype for the exchange of surface (xy) data,
-!-- which is needed for coupled atmosphere-ocean runs.
+!-- Create a new MPI derived datatype for the exchange of surface (xy) data, which is needed for
+!-- coupled atmosphere-ocean runs.
 !-- First, calculate number of grid points of an xy-plane.
     ngp_xy  = ( nxr - nxl + 1 + 2 * nbgp ) * ( nyn - nys + 1 + 2 * nbgp )
@@ -662,5 +640,5 @@
 
     IF ( TRIM( coupling_mode ) /= 'uncoupled' )  THEN
-   
+
 !
 !--    Pass the number of grid points of the atmosphere model to
@@ -673,35 +651,26 @@
           IF ( myid == 0 )  THEN
 
-             CALL MPI_SEND( nx_a, 1, MPI_INTEGER, numprocs, 1, comm_inter,  &
-                            ierr )
-             CALL MPI_SEND( ny_a, 1, MPI_INTEGER, numprocs, 2, comm_inter,  &
-                            ierr )
-             CALL MPI_SEND( pdims, 2, MPI_INTEGER, numprocs, 3, comm_inter, &
-                            ierr )
-             CALL MPI_RECV( nx_o, 1, MPI_INTEGER, numprocs, 4, comm_inter,  &
-                            status, ierr )
-             CALL MPI_RECV( ny_o, 1, MPI_INTEGER, numprocs, 5, comm_inter,  &
-                            status, ierr )
-             CALL MPI_RECV( pdims_remote, 2, MPI_INTEGER, numprocs, 6,      &
-                            comm_inter, status, ierr )
+             CALL MPI_SEND( nx_a, 1, MPI_INTEGER, numprocs, 1, comm_inter, ierr )
+             CALL MPI_SEND( ny_a, 1, MPI_INTEGER, numprocs, 2, comm_inter,  ierr )
+             CALL MPI_SEND( pdims, 2, MPI_INTEGER, numprocs, 3, comm_inter, ierr )
+             CALL MPI_RECV( nx_o, 1, MPI_INTEGER, numprocs, 4, comm_inter, status, ierr )
+             CALL MPI_RECV( ny_o, 1, MPI_INTEGER, numprocs, 5, comm_inter, status, ierr )
+             CALL MPI_RECV( pdims_remote, 2, MPI_INTEGER, numprocs, 6, comm_inter, status, ierr )
           ENDIF
 
           CALL MPI_BCAST( nx_o, 1, MPI_INTEGER, 0, comm2d, ierr )
-          CALL MPI_BCAST( ny_o, 1, MPI_INTEGER, 0, comm2d, ierr ) 
+          CALL MPI_BCAST( ny_o, 1, MPI_INTEGER, 0, comm2d, ierr )
           CALL MPI_BCAST( pdims_remote, 2, MPI_INTEGER, 0, comm2d, ierr )
-       
+
        ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
 
           nx_o = nx
-          ny_o = ny 
-
-          IF ( myid == 0 ) THEN
-
-             CALL MPI_RECV( nx_a, 1, MPI_INTEGER, 0, 1, comm_inter, status, &
-                            ierr )
-             CALL MPI_RECV( ny_a, 1, MPI_INTEGER, 0, 2, comm_inter, status, &
-                            ierr )
-             CALL MPI_RECV( pdims_remote, 2, MPI_INTEGER, 0, 3, comm_inter, &
-                            status, ierr )
+          ny_o = ny
+
+          IF ( myid == 0 )  THEN
+
+             CALL MPI_RECV( nx_a, 1, MPI_INTEGER, 0, 1, comm_inter, status, ierr )
+             CALL MPI_RECV( ny_a, 1, MPI_INTEGER, 0, 2, comm_inter, status, ierr )
+             CALL MPI_RECV( pdims_remote, 2, MPI_INTEGER, 0, 3, comm_inter, status, ierr )
              CALL MPI_SEND( nx_o, 1, MPI_INTEGER, 0, 4, comm_inter, ierr )
              CALL MPI_SEND( ny_o, 1, MPI_INTEGER, 0, 5, comm_inter, ierr )
@@ -710,46 +679,42 @@
 
           CALL MPI_BCAST( nx_a, 1, MPI_INTEGER, 0, comm2d, ierr)
-          CALL MPI_BCAST( ny_a, 1, MPI_INTEGER, 0, comm2d, ierr) 
-          CALL MPI_BCAST( pdims_remote, 2, MPI_INTEGER, 0, comm2d, ierr) 
-
-       ENDIF
-  
+          CALL MPI_BCAST( ny_a, 1, MPI_INTEGER, 0, comm2d, ierr)
+          CALL MPI_BCAST( pdims_remote, 2, MPI_INTEGER, 0, comm2d, ierr)
+
+       ENDIF
+
        ngp_a = ( nx_a+1 + 2 * nbgp ) * ( ny_a+1 + 2 * nbgp )
        ngp_o = ( nx_o+1 + 2 * nbgp ) * ( ny_o+1 + 2 * nbgp )
 
 !
-!--    Determine if the horizontal grid and the number of PEs in ocean and
-!--    atmosphere is same or not
-       IF ( nx_o == nx_a  .AND.  ny_o == ny_a  .AND.  &
-            pdims(1) == pdims_remote(1) .AND. pdims(2) == pdims_remote(2) ) &
-       THEN
+!--    Determine if the horizontal grid and the number of PEs in ocean and atmosphere is same or not.
+       IF ( nx_o == nx_a  .AND.  ny_o == ny_a  .AND.                                               &
+            pdims(1) == pdims_remote(1)  .AND.  pdims(2) == pdims_remote(2) )  THEN
           coupling_topology = 0
        ELSE
           coupling_topology = 1
-       ENDIF 
-
-!
-!--    Determine the target PEs for the exchange between ocean and
-!--    atmosphere (comm2d)
+       ENDIF
+
+!
+!--    Determine the target PEs for the exchange between ocean and atmosphere (comm2d)
        IF ( coupling_topology == 0 )  THEN
 !
-!--       In case of identical topologies, every atmosphere PE has exactly one
-!--       ocean PE counterpart and vice versa
-          IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' ) THEN
+!--       In case of identical topologies, every atmosphere PE has exactly one ocean PE counterpart
+!--       and vice versa
+          IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' )  THEN
              target_id = myid + numprocs
           ELSE
-             target_id = myid 
+             target_id = myid
           ENDIF
 
        ELSE
 !
-!--       In case of nonequivalent topology in ocean and atmosphere only for
-!--       PE0 in ocean and PE0 in atmosphere a target_id is needed, since
-!--       data echxchange between ocean and atmosphere will be done only
-!--       between these PEs.    
+!--       In case of nonequivalent topology in ocean and atmosphere only for PE0 in ocean and PE0 in
+!--       atmosphere a target_id is needed, since data echxchange between ocean and atmosphere will
+!--       be done only between these PEs.
           IF ( myid == 0 )  THEN
 
              IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' )  THEN
-                target_id = numprocs 
+                target_id = numprocs
              ELSE
                 target_id = 0
@@ -765,6 +730,5 @@
 
 !
-!-- Array bounds when running on a single PE (respectively a non-parallel
-!-- machine)
+!-- Array bounds when running on a single PE (respectively a non-parallel machine)
     nxl = 0
     nxr = nx
@@ -784,6 +748,6 @@
 
 !
-!-- Array bounds for the pressure solver (in the parallel code, these bounds
-!-- are the ones for the transposed arrays)
+!-- Array bounds for the pressure solver (in the parallel code, these bounds are the ones for the
+!-- transposed arrays)
     nys_x = nys
     nyn_x = nyn
@@ -804,6 +768,6 @@
 
 !
-!-- Calculate number of grid levels necessary for the multigrid poisson solver
-!-- as well as the gridpoint indices on each level
+!-- Calculate number of grid levels necessary for the multigrid poisson solver as well as the
+!-- gridpoint indices on each level
     IF ( psolver(1:9) == 'multigrid' )  THEN
 
@@ -833,11 +797,9 @@
        ENDDO
 !
-!--    The optimized MG-solver does not allow odd values for nz at the coarsest
-!--    grid level
+!--    The optimized MG-solver does not allow odd values for nz at the coarsest grid level
        IF ( TRIM( psolver ) /= 'multigrid_noopt' )  THEN
           IF ( MOD( k, 2 ) /= 0 )  mg_levels_z = mg_levels_z - 1
 !
-!--       An odd value of nz does not work. The finest level must have an even
-!--       value.
+!--       An odd value of nz does not work. The finest level must have an even value.
           IF (  mg_levels_z == 0 )  THEN
              message_string = 'optimized multigrid method requires nz to be even'
@@ -847,20 +809,20 @@
 
        maximum_grid_level = MIN( mg_levels_x, mg_levels_y, mg_levels_z )
-!       
-!--    Check if subdomain sizes prevents any coarsening. 
-!--    This case, the maximum number of grid levels is 1, i.e. effectively 
-!--    a Gauss-Seidel scheme is applied rather than a multigrid approach.
+!
+!--    Check if subdomain sizes prevents any coarsening.
+!--    This case, the maximum number of grid levels is 1, i.e. effectively a Gauss-Seidel scheme is
+!--    applied rather than a multigrid approach.
 !--    Give a warning in this case.
        IF ( maximum_grid_level == 1  .AND.  mg_switch_to_pe0_level == -1 )  THEN
-          message_string = 'No grid coarsening possible, multigrid ' //        &
-                           'approach effectively reduces to a Gauss-Seidel ' //&
+          message_string = 'No grid coarsening possible, multigrid ' //                            &
+                           'approach effectively reduces to a Gauss-Seidel ' //                    &
                            'scheme.'
-          
+
           CALL message( 'poismg', 'PA0648', 0, 1, 0, 6, 0 )
        ENDIF
 
 !
-!--    Find out, if the total domain allows more levels. These additional
-!--    levels are identically processed on all PEs.
+!--    Find out, if the total domain allows more levels. These additional levels are identically
+!--    processed on all PEs.
        IF ( numprocs > 1  .AND.  mg_switch_to_pe0_level /= -1 )  THEN
 
@@ -887,6 +849,5 @@
 
              IF ( maximum_grid_level_l > mg_switch_to_pe0_level_l )  THEN
-                mg_switch_to_pe0_level_l = maximum_grid_level_l - &
-                                           mg_switch_to_pe0_level_l + 1
+                mg_switch_to_pe0_level_l = maximum_grid_level_l - mg_switch_to_pe0_level_l + 1
              ELSE
                 mg_switch_to_pe0_level_l = 0
@@ -901,6 +862,5 @@
 
 !
-!--       Use switch level calculated above only if it is not pre-defined
-!--       by user
+!--       Use switch level calculated above only if it is not pre-defined by user
           IF ( mg_switch_to_pe0_level == 0 )  THEN
              IF ( mg_switch_to_pe0_level_l /= 0 )  THEN
@@ -912,7 +872,7 @@
 !
 !--          Check pre-defined value and reset to default, if neccessary
-             IF ( mg_switch_to_pe0_level < mg_switch_to_pe0_level_l  .OR.      &
+             IF ( mg_switch_to_pe0_level < mg_switch_to_pe0_level_l  .OR.                          &
                   mg_switch_to_pe0_level >= maximum_grid_level_l )  THEN
-                message_string = 'mg_switch_to_pe0_level ' //                  &
+                message_string = 'mg_switch_to_pe0_level ' //                                      &
                                  'out of range and reset to 0'
                 CALL message( 'init_pegrid', 'PA0235', 0, 1, 0, 6, 0 )
@@ -920,6 +880,6 @@
              ELSE
 !
-!--             Use the largest number of possible levels anyway and recalculate
-!--             the switch level to this largest number of possible values
+!--             Use the largest number of possible levels anyway and recalculate the switch level to
+!--             this largest number of possible values
                 maximum_grid_level = maximum_grid_level_l
 
@@ -930,13 +890,13 @@
        ENDIF
 
-       ALLOCATE( grid_level_count(maximum_grid_level),                       &
-                 nxl_mg(0:maximum_grid_level), nxr_mg(0:maximum_grid_level), &
-                 nyn_mg(0:maximum_grid_level), nys_mg(0:maximum_grid_level), &
+       ALLOCATE( grid_level_count(maximum_grid_level),                                             &
+                 nxl_mg(0:maximum_grid_level), nxr_mg(0:maximum_grid_level),                       &
+                 nyn_mg(0:maximum_grid_level), nys_mg(0:maximum_grid_level),                       &
                  nzt_mg(0:maximum_grid_level) )
 
        grid_level_count = 0
 !
-!--    Index zero required as dummy due to definition of arrays f2 and p2 in
-!--    recursive subroutine next_mg_level
+!--    Index zero required as dummy due to definition of arrays f2 and p2 in recursive subroutine
+!--    next_mg_level
        nxl_mg(0) = 0; nxr_mg(0) = 0; nyn_mg(0) = 0; nys_mg(0) = 0; nzt_mg(0) = 0
 
@@ -948,6 +908,5 @@
 #if defined( __parallel )
 !
-!--          Save the grid size of the subdomain at the switch level, because
-!--          it is needed in poismg.
+!--          Save the grid size of the subdomain at the switch level, because it is needed in poismg.
              ind(1) = nxl_l; ind(2) = nxr_l
              ind(3) = nys_l; ind(4) = nyn_l
@@ -969,16 +928,14 @@
              nys_l = 0
 !
-!--          The size of this gathered array must not be larger than the
-!--          array tend, which is used in the multigrid scheme as a temporary
-!--          array. Therefore the subdomain size of an PE is calculated and 
-!--          the size of the gathered grid. These values are used in  
-!--          routines pres and poismg
-             subdomain_size = ( nxr - nxl + 2 * nbgp + 1 ) * &
+!--          The size of this gathered array must not be larger than the array tend, which is used
+!--          in the multigrid scheme as a temporary array. Therefore the subdomain size of an PE is
+!--          calculated and the size of the gathered grid. These values are used in routines pres
+!--          and poismg.
+             subdomain_size = ( nxr - nxl + 2 * nbgp + 1 ) *                                       &
                               ( nyn - nys + 2 * nbgp + 1 ) * ( nzt - nzb + 2 )
-             gathered_size  = ( nxr_l - nxl_l + 3 ) * ( nyn_l - nys_l + 3 ) *  &
-                              ( nzt_l - nzb + 2 )
+             gathered_size  = ( nxr_l - nxl_l + 3 ) * ( nyn_l - nys_l + 3 ) * ( nzt_l - nzb + 2 )
 
 #else
-             message_string = 'multigrid gather/scatter impossible ' //        &
+             message_string = 'multigrid gather/scatter impossible ' //                            &
                           'in non parallel mode'
              CALL message( 'init_pegrid', 'PA0237', 1, 2, 0, 6, 0 )
@@ -992,174 +949,4 @@
           nzt_mg(i) = nzt_l
 
-          nxl_l = nxl_l / 2 
-          nxr_l = nxr_l / 2
-          nys_l = nys_l / 2 
-          nyn_l = nyn_l / 2 
-          nzt_l = nzt_l / 2 
-          
-       ENDDO
-
-!
-!--    Temporary problem: Currently calculation of maxerror in routine poismg crashes
-!--    if grid data are collected on PE0 already on the finest grid level.
-!--    To be solved later.
-       IF ( maximum_grid_level == mg_switch_to_pe0_level )  THEN
-          message_string = 'grid coarsening on subdomain level cannot be performed'
-          CALL message( 'poismg', 'PA0236', 1, 2, 0, 6, 0 )
-       ENDIF
-
-    ELSE
-
-       maximum_grid_level = 0
-
-    ENDIF
-
-!
-!-- Default level 0 tells exchange_horiz that all ghost planes have to be
-!-- exchanged. grid_level is adjusted in poismg, where only one ghost plane
-!-- is required.
-    grid_level = 0
-
-#if defined( __parallel )
-!
-!-- Gridpoint number for the exchange of ghost points (y-line for 2D-arrays)
-    ngp_y  = nyn - nys + 1 + 2 * nbgp
-
-!
-!-- Define new MPI derived datatypes for the exchange of ghost points in
-!-- x- and y-direction for 2D-arrays (line)
-    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp, ngp_y, MPI_REAL, type_x,     &
-                          ierr )
-    CALL MPI_TYPE_COMMIT( type_x, ierr )
-
-    CALL MPI_TYPE_VECTOR( nbgp, ngp_y, ngp_y, MPI_REAL, type_y, ierr )
-    CALL MPI_TYPE_COMMIT( type_y, ierr )
-!
-!-- Define new MPI derived datatypes for the exchange of ghost points in
-!-- x- and y-direction for 2D-INTEGER arrays (line) - on normal grid.
-!-- Define types for 32-bit and 8-bit Integer. The 8-bit Integer are only 
-!-- required on normal grid, while 32-bit Integer may be also required on 
-!-- coarser grid level in case of multigrid solver.
-!
-!-- 8-bit Integer
-    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp, ngp_y, MPI_BYTE,             &
-                          type_x_byte, ierr )
-    CALL MPI_TYPE_COMMIT( type_x_byte, ierr )
-
-    CALL MPI_TYPE_VECTOR( nbgp, ngp_y, ngp_y, MPI_BYTE,                        &
-                          type_y_byte, ierr )
-    CALL MPI_TYPE_COMMIT( type_y_byte, ierr )
-!
-!-- 32-bit Integer
-    ALLOCATE( type_x_int(0:maximum_grid_level),                                &
-              type_y_int(0:maximum_grid_level) )
-              
-    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp, ngp_y, MPI_INTEGER,          &
-                          type_x_int(0), ierr )
-    CALL MPI_TYPE_COMMIT( type_x_int(0), ierr )
-
-    CALL MPI_TYPE_VECTOR( nbgp, ngp_y, ngp_y, MPI_INTEGER, type_y_int(0), ierr )
-    CALL MPI_TYPE_COMMIT( type_y_int(0), ierr )
-!
-!-- Calculate gridpoint numbers for the exchange of ghost points along x
-!-- (yz-plane for 3D-arrays) and define MPI derived data type(s) for the
-!-- exchange of ghost points in y-direction (xz-plane).
-!-- Do these calculations for the model grid and (if necessary) also
-!-- for the coarser grid levels used in the multigrid method
-    ALLOCATE ( ngp_xz(0:maximum_grid_level),                                   &
-               ngp_xz_int(0:maximum_grid_level),                               &
-               ngp_yz(0:maximum_grid_level),                                   &
-               ngp_yz_int(0:maximum_grid_level),                               &
-               type_xz(0:maximum_grid_level),                                  &
-               type_xz_int(0:maximum_grid_level),                              &
-               type_yz(0:maximum_grid_level),                                  &
-               type_yz_int(0:maximum_grid_level) )
-
-    nxl_l = nxl; nxr_l = nxr; nys_l = nys; nyn_l = nyn; nzb_l = nzb; nzt_l = nzt
-
-!
-!-- Discern between the model grid, which needs nbgp ghost points and
-!-- grid levels for the multigrid scheme. In the latter case only one
-!-- ghost point is necessary.
-!-- First definition of MPI-datatypes for exchange of ghost layers on normal 
-!-- grid. The following loop is needed for data exchange in poismg.f90.
-!
-!-- Determine number of grid points of yz-layer for exchange
-    ngp_yz(0) = (nzt - nzb + 2) * (nyn - nys + 1 + 2 * nbgp)
-
-!
-!-- Define an MPI-datatype for the exchange of left/right boundaries.
-!-- Although data are contiguous in physical memory (which does not
-!-- necessarily require an MPI-derived datatype), the data exchange between
-!-- left and right PE's using the MPI-derived type is 10% faster than without.
-    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp*(nzt-nzb+2), ngp_yz(0), &
-                          MPI_REAL, type_xz(0), ierr )
-    CALL MPI_TYPE_COMMIT( type_xz(0), ierr )
-
-    CALL MPI_TYPE_VECTOR( nbgp, ngp_yz(0), ngp_yz(0), MPI_REAL, type_yz(0), &
-                          ierr ) 
-    CALL MPI_TYPE_COMMIT( type_yz(0), ierr )
-
-!
-!-- Define data types for exchange of 3D Integer arrays.
-    ngp_yz_int(0) = (nzt - nzb + 2) * (nyn - nys + 1 + 2 * nbgp)
-
-    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp*(nzt-nzb+2), ngp_yz_int(0),   &
-                          MPI_INTEGER, type_xz_int(0), ierr )
-    CALL MPI_TYPE_COMMIT( type_xz_int(0), ierr )
-
-    CALL MPI_TYPE_VECTOR( nbgp, ngp_yz_int(0), ngp_yz_int(0), MPI_INTEGER,     &
-                          type_yz_int(0), ierr )
-    CALL MPI_TYPE_COMMIT( type_yz_int(0), ierr )
-
-!
-!-- Definition of MPI-datatypes for multigrid method (coarser level grids)
-    IF ( psolver(1:9) == 'multigrid' )  THEN
-!    
-!--    Definition of MPI-datatyoe as above, but only 1 ghost level is used
-       DO  i = maximum_grid_level, 1 , -1
-!
-!--       For 3D-exchange on different multigrid level, one ghost point for 
-!--       REAL arrays, two ghost points for INTEGER arrays
-          ngp_xz(i) = (nzt_l - nzb_l + 2) * (nxr_l - nxl_l + 3)
-          ngp_yz(i) = (nzt_l - nzb_l + 2) * (nyn_l - nys_l + 3)
-
-          ngp_xz_int(i) = (nzt_l - nzb_l + 2) * (nxr_l - nxl_l + 3)
-          ngp_yz_int(i) = (nzt_l - nzb_l + 2) * (nyn_l - nys_l + 3)
-!
-!--       MPI data type for REAL arrays, for xz-layers
-          CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+3, nzt_l-nzb_l+2, ngp_yz(i),       &
-                                MPI_REAL, type_xz(i), ierr )
-          CALL MPI_TYPE_COMMIT( type_xz(i), ierr )
-
-!
-!--       MPI data type for INTEGER arrays, for xz-layers
-          CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+3, nzt_l-nzb_l+2, ngp_yz_int(i),   &
-                                MPI_INTEGER, type_xz_int(i), ierr )
-          CALL MPI_TYPE_COMMIT( type_xz_int(i), ierr )
-
-!
-!--       MPI data type for REAL arrays, for yz-layers
-          CALL MPI_TYPE_VECTOR( 1, ngp_yz(i), ngp_yz(i), MPI_REAL, type_yz(i), &
-                                ierr )
-          CALL MPI_TYPE_COMMIT( type_yz(i), ierr )
-!
-!--       MPI data type for INTEGER arrays, for yz-layers
-          CALL MPI_TYPE_VECTOR( 1, ngp_yz_int(i), ngp_yz_int(i), MPI_INTEGER,  &
-                                type_yz_int(i), ierr )
-          CALL MPI_TYPE_COMMIT( type_yz_int(i), ierr )
-
-
-!--       For 2D-exchange of INTEGER arrays on coarser grid level, where 2 ghost
-!--       points need to be exchanged. Only required for 32-bit Integer arrays.
-          CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+5, 2, nyn_l-nys_l+5, MPI_INTEGER,  &
-                                type_x_int(i), ierr )
-          CALL MPI_TYPE_COMMIT( type_x_int(i), ierr )
-
-
-          CALL MPI_TYPE_VECTOR( 2, nyn_l-nys_l+5, nyn_l-nys_l+5, MPI_INTEGER,  &
-                                type_y_int(i), ierr )
-          CALL MPI_TYPE_COMMIT( type_y_int(i), ierr )
-
           nxl_l = nxl_l / 2
           nxr_l = nxr_l / 2
@@ -1170,4 +957,159 @@
        ENDDO
 
+!
+!--    Temporary problem: Currently calculation of maxerror in routine poismg crashes if grid data
+!--    are collected on PE0 already on the finest grid level.
+!--    To be solved later.
+       IF ( maximum_grid_level == mg_switch_to_pe0_level )  THEN
+          message_string = 'grid coarsening on subdomain level cannot be performed'
+          CALL message( 'poismg', 'PA0236', 1, 2, 0, 6, 0 )
+       ENDIF
+
+    ELSE
+
+       maximum_grid_level = 0
+
+    ENDIF
+
+!
+!-- Default level 0 tells exchange_horiz that all ghost planes have to be exchanged. grid_level is
+!-- adjusted in poismg, where only one ghost plane is required.
+    grid_level = 0
+
+#if defined( __parallel )
+!
+!-- Gridpoint number for the exchange of ghost points (y-line for 2D-arrays)
+    ngp_y  = nyn - nys + 1 + 2 * nbgp
+
+!
+!-- Define new MPI derived datatypes for the exchange of ghost points in x- and y-direction for
+!-- 2D-arrays (line)
+    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp, ngp_y, MPI_REAL, type_x, ierr )
+    CALL MPI_TYPE_COMMIT( type_x, ierr )
+
+    CALL MPI_TYPE_VECTOR( nbgp, ngp_y, ngp_y, MPI_REAL, type_y, ierr )
+    CALL MPI_TYPE_COMMIT( type_y, ierr )
+!
+!-- Define new MPI derived datatypes for the exchange of ghost points in x- and y-direction for
+!-- 2D-INTEGER arrays (line) - on normal grid.
+!-- Define types for 32-bit and 8-bit Integer. The 8-bit Integer are only required on normal grid,
+!-- while 32-bit Integer may be also required on coarser grid level in case of multigrid solver.
+!
+!-- 8-bit Integer
+    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp, ngp_y, MPI_BYTE, type_x_byte, ierr )
+    CALL MPI_TYPE_COMMIT( type_x_byte, ierr )
+
+    CALL MPI_TYPE_VECTOR( nbgp, ngp_y, ngp_y, MPI_BYTE, type_y_byte, ierr )
+    CALL MPI_TYPE_COMMIT( type_y_byte, ierr )
+!
+!-- 32-bit Integer
+    ALLOCATE( type_x_int(0:maximum_grid_level), type_y_int(0:maximum_grid_level) )
+
+    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp, ngp_y, MPI_INTEGER, type_x_int(0), ierr )
+    CALL MPI_TYPE_COMMIT( type_x_int(0), ierr )
+
+    CALL MPI_TYPE_VECTOR( nbgp, ngp_y, ngp_y, MPI_INTEGER, type_y_int(0), ierr )
+    CALL MPI_TYPE_COMMIT( type_y_int(0), ierr )
+!
+!-- Calculate gridpoint numbers for the exchange of ghost points along x (yz-plane for 3D-arrays)
+!-- and define MPI derived data type(s) for the exchange of ghost points in y-direction (xz-plane).
+!-- Do these calculations for the model grid and (if necessary) also for the coarser grid levels
+!-- used in the multigrid method
+    ALLOCATE ( ngp_xz(0:maximum_grid_level),                                                       &
+               ngp_xz_int(0:maximum_grid_level),                                                   &
+               ngp_yz(0:maximum_grid_level),                                                       &
+               ngp_yz_int(0:maximum_grid_level),                                                   &
+               type_xz(0:maximum_grid_level),                                                      &
+               type_xz_int(0:maximum_grid_level),                                                  &
+               type_yz(0:maximum_grid_level),                                                      &
+               type_yz_int(0:maximum_grid_level) )
+
+    nxl_l = nxl; nxr_l = nxr; nys_l = nys; nyn_l = nyn; nzb_l = nzb; nzt_l = nzt
+
+!
+!-- Discern between the model grid, which needs nbgp ghost points and grid levels for the multigrid
+!-- scheme. In the latter case only one ghost point is necessary.
+!-- First definition of MPI-datatypes for exchange of ghost layers on normal grid. The following
+!-- loop is needed for data exchange in poismg.f90.
+!
+!-- Determine number of grid points of yz-layer for exchange
+    ngp_yz(0) = (nzt - nzb + 2) * (nyn - nys + 1 + 2 * nbgp)
+
+!
+!-- Define an MPI-datatype for the exchange of left/right boundaries.
+!-- Although data are contiguous in physical memory (which does not necessarily require an
+!-- MPI-derived datatype), the data exchange between left and right PE's using the MPI-derived type
+!-- is 10% faster than without.
+    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp*(nzt-nzb+2), ngp_yz(0), MPI_REAL, type_xz(0),     &
+                          ierr )
+    CALL MPI_TYPE_COMMIT( type_xz(0), ierr )
+
+    CALL MPI_TYPE_VECTOR( nbgp, ngp_yz(0), ngp_yz(0), MPI_REAL, type_yz(0), ierr )
+    CALL MPI_TYPE_COMMIT( type_yz(0), ierr )
+
+!
+!-- Define data types for exchange of 3D Integer arrays.
+    ngp_yz_int(0) = (nzt - nzb + 2) * (nyn - nys + 1 + 2 * nbgp)
+
+    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp*(nzt-nzb+2), ngp_yz_int(0), MPI_INTEGER,          &
+                          type_xz_int(0), ierr )
+    CALL MPI_TYPE_COMMIT( type_xz_int(0), ierr )
+
+    CALL MPI_TYPE_VECTOR( nbgp, ngp_yz_int(0), ngp_yz_int(0), MPI_INTEGER, type_yz_int(0), ierr )
+    CALL MPI_TYPE_COMMIT( type_yz_int(0), ierr )
+
+!
+!-- Definition of MPI-datatypes for multigrid method (coarser level grids)
+    IF ( psolver(1:9) == 'multigrid' )  THEN
+!
+!--    Definition of MPI-datatyoe as above, but only 1 ghost level is used
+       DO  i = maximum_grid_level, 1 , -1
+!
+!--       For 3D-exchange on different multigrid level, one ghost point for REAL arrays, two ghost
+!--       points for INTEGER arrays
+          ngp_xz(i) = (nzt_l - nzb_l + 2) * (nxr_l - nxl_l + 3)
+          ngp_yz(i) = (nzt_l - nzb_l + 2) * (nyn_l - nys_l + 3)
+
+          ngp_xz_int(i) = (nzt_l - nzb_l + 2) * (nxr_l - nxl_l + 3)
+          ngp_yz_int(i) = (nzt_l - nzb_l + 2) * (nyn_l - nys_l + 3)
+!
+!--       MPI data type for REAL arrays, for xz-layers
+          CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+3, nzt_l-nzb_l+2, ngp_yz(i), MPI_REAL, type_xz(i),     &
+                                ierr )
+          CALL MPI_TYPE_COMMIT( type_xz(i), ierr )
+
+!
+!--       MPI data type for INTEGER arrays, for xz-layers
+          CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+3, nzt_l-nzb_l+2, ngp_yz_int(i), MPI_INTEGER,          &
+                                type_xz_int(i), ierr )
+          CALL MPI_TYPE_COMMIT( type_xz_int(i), ierr )
+
+!
+!--       MPI data type for REAL arrays, for yz-layers
+          CALL MPI_TYPE_VECTOR( 1, ngp_yz(i), ngp_yz(i), MPI_REAL, type_yz(i), ierr )
+          CALL MPI_TYPE_COMMIT( type_yz(i), ierr )
+!
+!--       MPI data type for INTEGER arrays, for yz-layers
+          CALL MPI_TYPE_VECTOR( 1, ngp_yz_int(i), ngp_yz_int(i), MPI_INTEGER, type_yz_int(i), ierr )
+          CALL MPI_TYPE_COMMIT( type_yz_int(i), ierr )
+
+
+!--       For 2D-exchange of INTEGER arrays on coarser grid level, where 2 ghost points need to be
+!--       exchanged. Only required for 32-bit Integer arrays.
+          CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+5, 2, nyn_l-nys_l+5, MPI_INTEGER, type_x_int(i), ierr )
+          CALL MPI_TYPE_COMMIT( type_x_int(i), ierr )
+
+
+          CALL MPI_TYPE_VECTOR( 2, nyn_l-nys_l+5, nyn_l-nys_l+5, MPI_INTEGER, type_y_int(i), ierr )
+          CALL MPI_TYPE_COMMIT( type_y_int(i), ierr )
+
+          nxl_l = nxl_l / 2
+          nxr_l = nxr_l / 2
+          nys_l = nys_l / 2
+          nyn_l = nyn_l / 2
+          nzt_l = nzt_l / 2
+
+       ENDDO
+
     ENDIF
 
@@ -1178,5 +1120,5 @@
 !-- Setting of flags for inflow/outflow/nesting conditions.
     IF ( pleft == MPI_PROC_NULL )  THEN
-       IF ( bc_lr == 'dirichlet/radiation'  .OR.  bc_lr == 'nested'  .OR.      &
+       IF ( bc_lr == 'dirichlet/radiation'  .OR.  bc_lr == 'nested'  .OR.                          &
             bc_lr == 'nesting_offline' )  THEN
           bc_dirichlet_l  = .TRUE.
@@ -1185,9 +1127,9 @@
        ENDIF
     ENDIF
- 
+
     IF ( pright == MPI_PROC_NULL )  THEN
        IF ( bc_lr == 'dirichlet/radiation' )  THEN
           bc_radiation_r = .TRUE.
-       ELSEIF ( bc_lr == 'radiation/dirichlet'  .OR.  bc_lr == 'nested'  .OR.  &
+       ELSEIF ( bc_lr == 'radiation/dirichlet'  .OR.  bc_lr == 'nested'  .OR.                      &
                 bc_lr == 'nesting_offline' )  THEN
           bc_dirichlet_r  = .TRUE.
@@ -1198,5 +1140,5 @@
        IF ( bc_ns == 'dirichlet/radiation' )  THEN
           bc_radiation_s = .TRUE.
-       ELSEIF ( bc_ns == 'radiation/dirichlet'  .OR.  bc_ns == 'nested'  .OR.  &
+       ELSEIF ( bc_ns == 'radiation/dirichlet'  .OR.  bc_ns == 'nested'  .OR.                      &
                 bc_ns == 'nesting_offline' )  THEN
           bc_dirichlet_s  = .TRUE.
@@ -1205,5 +1147,5 @@
 
     IF ( pnorth == MPI_PROC_NULL )  THEN
-       IF ( bc_ns == 'dirichlet/radiation'  .OR.  bc_ns == 'nested'  .OR.      &
+       IF ( bc_ns == 'dirichlet/radiation'  .OR.  bc_ns == 'nested'  .OR.                          &
             bc_ns == 'nesting_offline' )  THEN
           bc_dirichlet_n  = .TRUE.
@@ -1213,7 +1155,7 @@
     ENDIF
 !
-!-- In case of synthetic turbulence geneartor determine ids. 
-!-- Please note, if no forcing or nesting is applied, the generator is applied
-!-- only at the left lateral boundary.
+!-- In case of synthetic turbulence geneartor determine ids.
+!-- Please note, if no forcing or nesting is applied, the generator is applied only at the left
+!-- lateral boundary.
     IF ( use_syn_turb_gen )  THEN
        IF ( bc_dirichlet_l )  THEN
@@ -1239,21 +1181,17 @@
 
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( id_stg_left_l, id_stg_left,   1, MPI_INTEGER,       &
-                           MPI_SUM, comm1dx, ierr )
+       CALL MPI_ALLREDUCE( id_stg_left_l, id_stg_left,   1, MPI_INTEGER, MPI_SUM, comm1dx, ierr )
 
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( id_stg_right_l, id_stg_right, 1, MPI_INTEGER,       &
-                           MPI_SUM, comm1dx, ierr )
+       CALL MPI_ALLREDUCE( id_stg_right_l, id_stg_right, 1, MPI_INTEGER, MPI_SUM, comm1dx, ierr )
 
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( id_stg_south_l, id_stg_south, 1, MPI_INTEGER,       &
-                           MPI_SUM, comm1dy, ierr )
+       CALL MPI_ALLREDUCE( id_stg_south_l, id_stg_south, 1, MPI_INTEGER, MPI_SUM, comm1dy, ierr )
 
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( id_stg_north_l, id_stg_north, 1, MPI_INTEGER,       &
-                           MPI_SUM, comm1dy, ierr )
-
-    ENDIF 
- 
+       CALL MPI_ALLREDUCE( id_stg_north_l, id_stg_north, 1, MPI_INTEGER, MPI_SUM, comm1dy, ierr )
+
+    ENDIF
+
 !
 !-- Broadcast the id of the inflow PE
@@ -1264,6 +1202,5 @@
     ENDIF
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( id_inflow_l, id_inflow, 1, MPI_INTEGER, MPI_SUM, &
-                        comm1dx, ierr )
+    CALL MPI_ALLREDUCE( id_inflow_l, id_inflow, 1, MPI_INTEGER, MPI_SUM, comm1dx, ierr )
 
 !
@@ -1271,5 +1208,5 @@
 !-- WARNING: needs to be adjusted in case of inflows other than from left side!
     IF ( turbulent_inflow ) THEN
-    
+
        IF ( NINT( recycling_width / dx, KIND=idp ) >= nxl  .AND.                                   &
             NINT( recycling_width / dx, KIND=idp ) <= nxr )  THEN
@@ -1279,7 +1216,6 @@
        ENDIF
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( id_recycling_l, id_recycling, 1, MPI_INTEGER, MPI_SUM, &
-                           comm1dx, ierr )
-                           
+       CALL MPI_ALLREDUCE( id_recycling_l, id_recycling, 1, MPI_INTEGER, MPI_SUM, comm1dx, ierr )
+
     ENDIF
 
@@ -1297,5 +1233,5 @@
                            comm1dx, ierr )
 
-       IF ( NINT( outflow_source_plane / dx ) >= nxl  .AND. &
+       IF ( NINT( outflow_source_plane / dx ) >= nxl  .AND.                                        &
             NINT( outflow_source_plane / dx ) <= nxr )  THEN
           id_outflow_source_l = myidx
@@ -1304,6 +1240,6 @@
        ENDIF
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( id_outflow_source_l, id_outflow_source, 1, &
-                           MPI_INTEGER, MPI_SUM, comm1dx, ierr )
+       CALL MPI_ALLREDUCE( id_outflow_source_l, id_outflow_source, 1, MPI_INTEGER, MPI_SUM,        &
+                           comm1dx, ierr )
 
     ENDIF
@@ -1330,6 +1266,5 @@
 
 !
-!-- At the inflow or outflow, u or v, respectively, have to be calculated for
-!-- one more grid point.
+!-- At the inflow or outflow, u or v, respectively, have to be calculated for one more grid point.
     IF ( bc_dirichlet_l  .OR.  bc_radiation_l )  THEN
        nxlu = nxl + 1
@@ -1352,51 +1287,51 @@
 
               CASE ( 1 )
-                 ALLOCATE( wall_flags_1(nzb:nzt_mg(i)+1,         &
-                                        nys_mg(i)-1:nyn_mg(i)+1, &
+                 ALLOCATE( wall_flags_1(nzb:nzt_mg(i)+1,                                           &
+                                        nys_mg(i)-1:nyn_mg(i)+1,                                   &
                                         nxl_mg(i)-1:nxr_mg(i)+1) )
 
               CASE ( 2 )
-                 ALLOCATE( wall_flags_2(nzb:nzt_mg(i)+1,         &
-                                        nys_mg(i)-1:nyn_mg(i)+1, &
+                 ALLOCATE( wall_flags_2(nzb:nzt_mg(i)+1,                                           &
+                                        nys_mg(i)-1:nyn_mg(i)+1,                                   &
                                         nxl_mg(i)-1:nxr_mg(i)+1) )
 
               CASE ( 3 )
-                 ALLOCATE( wall_flags_3(nzb:nzt_mg(i)+1,         &
-                                        nys_mg(i)-1:nyn_mg(i)+1, &
+                 ALLOCATE( wall_flags_3(nzb:nzt_mg(i)+1,                                           &
+                                        nys_mg(i)-1:nyn_mg(i)+1,                                   &
                                         nxl_mg(i)-1:nxr_mg(i)+1) )
 
               CASE ( 4 )
-                 ALLOCATE( wall_flags_4(nzb:nzt_mg(i)+1,         &
-                                        nys_mg(i)-1:nyn_mg(i)+1, &
+                 ALLOCATE( wall_flags_4(nzb:nzt_mg(i)+1,                                           &
+                                        nys_mg(i)-1:nyn_mg(i)+1,                                   &
                                         nxl_mg(i)-1:nxr_mg(i)+1) )
 
               CASE ( 5 )
-                 ALLOCATE( wall_flags_5(nzb:nzt_mg(i)+1,         &
-                                        nys_mg(i)-1:nyn_mg(i)+1, &
+                 ALLOCATE( wall_flags_5(nzb:nzt_mg(i)+1,                                           &
+                                        nys_mg(i)-1:nyn_mg(i)+1,                                   &
                                         nxl_mg(i)-1:nxr_mg(i)+1) )
 
               CASE ( 6 )
-                 ALLOCATE( wall_flags_6(nzb:nzt_mg(i)+1,         &
-                                        nys_mg(i)-1:nyn_mg(i)+1, &
+                 ALLOCATE( wall_flags_6(nzb:nzt_mg(i)+1,                                           &
+                                        nys_mg(i)-1:nyn_mg(i)+1,                                   &
                                         nxl_mg(i)-1:nxr_mg(i)+1) )
 
               CASE ( 7 )
-                 ALLOCATE( wall_flags_7(nzb:nzt_mg(i)+1,         &
-                                        nys_mg(i)-1:nyn_mg(i)+1, &
+                 ALLOCATE( wall_flags_7(nzb:nzt_mg(i)+1,                                           &
+                                        nys_mg(i)-1:nyn_mg(i)+1,                                   &
                                         nxl_mg(i)-1:nxr_mg(i)+1) )
 
               CASE ( 8 )
-                 ALLOCATE( wall_flags_8(nzb:nzt_mg(i)+1,         &
-                                        nys_mg(i)-1:nyn_mg(i)+1, &
+                 ALLOCATE( wall_flags_8(nzb:nzt_mg(i)+1,                                           &
+                                        nys_mg(i)-1:nyn_mg(i)+1,                                   &
                                         nxl_mg(i)-1:nxr_mg(i)+1) )
 
               CASE ( 9 )
-                 ALLOCATE( wall_flags_9(nzb:nzt_mg(i)+1,         &
-                                        nys_mg(i)-1:nyn_mg(i)+1, &
+                 ALLOCATE( wall_flags_9(nzb:nzt_mg(i)+1,                                           &
+                                        nys_mg(i)-1:nyn_mg(i)+1,                                   &
                                         nxl_mg(i)-1:nxr_mg(i)+1) )
 
               CASE ( 10 )
-                 ALLOCATE( wall_flags_10(nzb:nzt_mg(i)+1,        &
-                                        nys_mg(i)-1:nyn_mg(i)+1, &
+                 ALLOCATE( wall_flags_10(nzb:nzt_mg(i)+1,                                          &
+                                        nys_mg(i)-1:nyn_mg(i)+1,                                   &
                                         nxl_mg(i)-1:nxr_mg(i)+1) )
 
Index: /palm/trunk/SOURCE/init_pt_anomaly.f90
===================================================================
--- /palm/trunk/SOURCE/init_pt_anomaly.f90	(revision 4647)
+++ /palm/trunk/SOURCE/init_pt_anomaly.f90	(revision 4648)
@@ -1,40 +1,42 @@
 !> @file init_pt_anomaly.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
 !
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
 !
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4457 2020-03-11 14:20:43Z raasch
 ! use statement for exchange horiz added
-! 
+!
 ! 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
-! 
+! 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
-! 
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! Added topography flags
@@ -47,20 +49,20 @@
 ! ------------
 !> Impose a temperature perturbation for an advection test.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE init_pt_anomaly
 
 
-    USE arrays_3d,                                                             &
+    USE arrays_3d,                                                                                 &
         ONLY:  pt, zu
 
     USE control_parameters
 
-    USE exchange_horiz_mod,                                                    &
+    USE exchange_horiz_mod,                                                                        &
         ONLY:  exchange_horiz
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                                            &
         ONLY:  dx, dy
 
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  nbgp, nx, nxl, nxr, ny, nyn, nys, nzb, nzt, wall_flags_total_0
 
@@ -70,5 +72,5 @@
 
     INTEGER(iwp) ::  i  !< grid index along x
-    INTEGER(iwp) ::  ic !< center index along x 
+    INTEGER(iwp) ::  ic !< center index along x
     INTEGER(iwp) ::  j  !< grid index along y
     INTEGER(iwp) ::  jc !< center index along y
@@ -125,6 +127,5 @@
 
 !
-!-- Initialize warm air bubble close to surface and homogenous elegonated 
-!-- along x-Axis
+!-- Initialize warm air bubble close to surface and homogenous elegonated along x-Axis
     ELSEIF ( INDEX( initializing_actions, 'initialize_bubble' ) /= 0 )  THEN
 !
@@ -141,9 +142,7 @@
                 flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0 ) )
 
-                pt(k,j,i) = pt(k,j,i) +                                        &
-                               EXP( -0.5 * ( (j* dy  - bubble_center_y) /      &
-                                                       bubble_sigma_y )**2) *  &
-                               EXP( -0.5 * ( (zu(k)  - bubble_center_z) /      &
-                                                       bubble_sigma_z)**2) *   &
+                pt(k,j,i) = pt(k,j,i) +                                                            &
+                               EXP( -0.5 * ( (j* dy - bubble_center_y) / bubble_sigma_y )**2) *    &
+                               EXP( -0.5 * ( (zu(k) - bubble_center_z) / bubble_sigma_z)**2)  *    &
                                initial_temperature_difference * flag
              ENDDO
Index: /palm/trunk/SOURCE/init_rankine.f90
===================================================================
--- /palm/trunk/SOURCE/init_rankine.f90	(revision 4647)
+++ /palm/trunk/SOURCE/init_rankine.f90	(revision 4648)
@@ -1,33 +1,35 @@
 !> @file init_rankine.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4457 2020-03-11 14:20:43Z raasch
 ! use statement for exchange horiz added
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Corrected "Former revisions" section
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! Modularization of all bulk cloud physics code components
@@ -39,28 +41,28 @@
 ! Description:
 ! ------------
-!> Initialize a (nondivergent) Rankine eddy with a vertical axis in order to test 
-!> the advection terms and the pressure solver.
-!------------------------------------------------------------------------------!
+!> Initialize a (nondivergent) Rankine eddy with a vertical axis in order to test the advection
+!> terms and the pressure solver.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE init_rankine
- 
-
-    USE arrays_3d,                                                             &
+
+
+    USE arrays_3d,                                                                                 &
         ONLY:  pt, pt_init, u, u_init, v, v_init
 
-    USE control_parameters,                                                    &
-        ONLY:  initializing_actions, n_sor, nsor, nsor_ini   
-
-    USE basic_constants_and_equations_mod,                                     &
+    USE control_parameters,                                                                        &
+        ONLY:  initializing_actions, n_sor, nsor, nsor_ini
+
+    USE basic_constants_and_equations_mod,                                                         &
         ONLY:  pi
 
-    USE exchange_horiz_mod,                                                    &
+    USE exchange_horiz_mod,                                                                        &
         ONLY:  exchange_horiz
 
-    USE grid_variables,                                                        &
-        ONLY:  dx, dy 
-
-    USE indices,                                                               &
-        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt     
-                
+    USE grid_variables,                                                                            &
+        ONLY:  dx, dy
+
+    USE indices,                                                                                   &
+        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt
+
     USE kinds
 
@@ -74,5 +76,5 @@
     INTEGER(iwp) ::  kc1 !<
     INTEGER(iwp) ::  kc2 !<
-    
+
     REAL(wp)     ::  alpha  !<
     REAL(wp)     ::  betrag !<
Index: /palm/trunk/SOURCE/init_slope.f90
===================================================================
--- /palm/trunk/SOURCE/init_slope.f90	(revision 4647)
+++ /palm/trunk/SOURCE/init_slope.f90	(revision 4648)
@@ -1,30 +1,32 @@
 !> @file init_slope.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
 !
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
 !
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4360 2020-01-07 11:25:50Z suehring
 ! Corrected "Former revisions" section
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! Modularization of all bulk cloud physics code components
@@ -36,28 +38,27 @@
 ! Description:
 ! ------------
-!> Initialization of the temperature field and other variables used in case
-!> of a sloping surface.
+!> Initialization of the temperature field and other variables used in case of a sloping surface.
 !> @note when a sloping surface is used, only one constant temperature
 !>       gradient is allowed!
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE init_slope
- 
 
-    USE arrays_3d,                                                             &
+
+    USE arrays_3d,                                                                                 &
         ONLY:  pt, pt_init, pt_slope_ref, zu
-        
-    USE basic_constants_and_equations_mod,                                     &
+
+    USE basic_constants_and_equations_mod,                                                         &
         ONLY:  pi
-                    
-    USE control_parameters,                                                    &
-        ONLY:  alpha_surface, initializing_actions, pt_slope_offset,           &
-               pt_surface, pt_vertical_gradient, sin_alpha_surface
-        
-    USE grid_variables,                                                        &
+
+    USE control_parameters,                                                                        &
+        ONLY:  alpha_surface, initializing_actions, pt_slope_offset, pt_surface,                   &
+               pt_vertical_gradient, sin_alpha_surface
+
+    USE grid_variables,                                                                            &
         ONLY:  dx
-        
-    USE indices,                                                               &
+
+    USE indices,                                                                                   &
         ONLY:  ngp_2dh, nx, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt
-        
+
     USE kinds
 
@@ -70,10 +71,10 @@
     INTEGER(iwp) ::  j        !<
     INTEGER(iwp) ::  k        !<
-    
+
     REAL(wp)     ::  alpha    !<
     REAL(wp)     ::  height   !<
     REAL(wp)     ::  pt_value !<
     REAL(wp)     ::  radius   !<
-    
+
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  pt_init_local !<
 
@@ -86,9 +87,7 @@
 
 !
-!--       Compute height of grid-point relative to lower left corner of
-!--       the total domain.
-!--       First compute the distance between the actual grid point and the
-!--       lower left corner as well as the angle between the line connecting
-!--       these points and the bottom of the model.
+!--       Compute height of grid-point relative to lower left corner of the total domain.
+!--       First compute the distance between the actual grid point and the lower left corner as well
+!--       as the angle between the line connecting these points and the bottom of the model.
           IF ( k /= nzb )  THEN
              radius = SQRT( ( i * dx )**2 + zu(k)**2 )
@@ -106,15 +105,13 @@
 !--       Compute temperatures in the rotated coordinate system
           alpha    = alpha + alpha_surface / 180.0_wp * pi
-          pt_value = pt_surface + radius * SIN( alpha ) * &
-                                  pt_vertical_gradient(1) / 100.0_wp
+          pt_value = pt_surface + radius * SIN( alpha ) * pt_vertical_gradient(1) / 100.0_wp
           pt_slope_ref(k,i) = pt_value
-       ENDDO                
+       ENDDO
     ENDDO
 
 !
-!-- Temperature difference between left and right boundary of the total domain,
-!-- used for the cyclic boundary in x-direction
-    pt_slope_offset = (nx+1) * dx * sin_alpha_surface * &
-                      pt_vertical_gradient(1) / 100.0_wp
+!-- Temperature difference between left and right boundary of the total domain, used for the cyclic
+!-- boundary in x-direction
+    pt_slope_offset = (nx+1) * dx * sin_alpha_surface * pt_vertical_gradient(1) / 100.0_wp
 
 
@@ -129,6 +126,6 @@
 
 !
-!--    Recompute the mean initial temperature profile (mean along x-direction of
-!--    the rotated coordinate system)
+!--    Recompute the mean initial temperature profile (mean along x-direction of the rotated
+!--    coordinate system)
        ALLOCATE( pt_init_local(nzb:nzt+1) )
        pt_init_local = 0.0_wp
@@ -143,6 +140,5 @@
 #if defined( __parallel )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( pt_init_local, pt_init, nzt+2-nzb, MPI_REAL, &
-                            MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( pt_init_local, pt_init, nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d, ierr )
 #else
        pt_init = pt_init_local
Index: /palm/trunk/SOURCE/init_vertical_profiles.f90
===================================================================
--- /palm/trunk/SOURCE/init_vertical_profiles.f90	(revision 4647)
+++ /palm/trunk/SOURCE/init_vertical_profiles.f90	(revision 4648)
@@ -1,32 +1,33 @@
 !> @file ocean_mod.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
 !
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
 !
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 2017-2020 Leibniz Universitaet Hannover
-!--------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
-! split from check_parameters as separate file to avoid circular dependency
-! with ocean_mod
+! file re-formatted to follow the PALM coding standard
 !
-! 
+! 4481 2020-03-31 18:55:54Z maronga
+! split from check_parameters as separate file to avoid circular dependency with ocean_mod
+!
+!
 !
 !
@@ -38,17 +39,17 @@
 ! ------------
 !> Inititalizes the vertical profiles of scalar quantities.
-!------------------------------------------------------------------------------!
- SUBROUTINE init_vertical_profiles( vertical_gradient_level_ind,               &
-                                    vertical_gradient_level,                   &
-                                    vertical_gradient, initial_profile,        &
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE init_vertical_profiles( vertical_gradient_level_ind,                                   &
+                                    vertical_gradient_level,                                       &
+                                    vertical_gradient, initial_profile,                            &
                                     surface_value, bc_top_gradient )
 
-    USE arrays_3d,                                                             &
+    USE arrays_3d,                                                                                 &
         ONLY:  dzu, zu
 
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  ocean_mode
 
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  nz, nzt
 
@@ -59,4 +60,5 @@
     INTEGER(iwp) ::  i  !< loop counter
     INTEGER(iwp) ::  k  !< loop counter
+
     INTEGER(iwp), DIMENSION(1:10) ::  vertical_gradient_level_ind  !< vertical grid indices for gradient levels
 
@@ -77,5 +79,5 @@
        DO  k = 1, nzt+1
           IF ( i < 11 )  THEN
-             IF ( vertical_gradient_level(i) < zu(k)  .AND.            &
+             IF ( vertical_gradient_level(i) < zu(k)  .AND.                                        &
                   vertical_gradient_level(i) >= 0.0_wp )  THEN
                 gradient = vertical_gradient(i) / 100.0_wp
@@ -103,10 +105,10 @@
 
 !
-!--    In ocean mode, profiles are constructed starting from the ocean surface,
-!--    which is at the top of the model domain
+!--    In ocean mode, profiles are constructed starting from the ocean surface, which is at the top
+!--    of the model domain
        vertical_gradient_level_ind(1) = nzt+1
        DO  k = nzt, 0, -1
           IF ( i < 11 )  THEN
-             IF ( vertical_gradient_level(i) > zu(k)  .AND.            &
+             IF ( vertical_gradient_level(i) > zu(k)  .AND.                                        &
                   vertical_gradient_level(i) <= 0.0_wp )  THEN
                 gradient = vertical_gradient(i) / 100.0_wp
@@ -119,8 +121,6 @@
                 initial_profile(k) = initial_profile(k+1) - dzu(k+1) * gradient
              ELSE
-                initial_profile(k)   = surface_value - 0.5_wp * dzu(k+1) *     &
-                                                       gradient
-                initial_profile(k+1) = surface_value + 0.5_wp * dzu(k+1) *     &
-                                                       gradient
+                initial_profile(k)   = surface_value - 0.5_wp * dzu(k+1) * gradient
+                initial_profile(k+1) = surface_value + 0.5_wp * dzu(k+1) * gradient
              ENDIF
           ELSE
@@ -143,6 +143,5 @@
 !
 !-- Store gradient at the top boundary for possible Neumann boundary condition
-    bc_top_gradient  = ( initial_profile(nzt+1) - initial_profile(nzt) ) /     &
-                       dzu(nzt+1)
+    bc_top_gradient  = ( initial_profile(nzt+1) - initial_profile(nzt) ) / dzu(nzt+1)
 
  END SUBROUTINE init_vertical_profiles
Index: /palm/trunk/SOURCE/lagrangian_particle_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/lagrangian_particle_model_mod.f90	(revision 4647)
+++ /palm/trunk/SOURCE/lagrangian_particle_model_mod.f90	(revision 4648)
@@ -1,20 +1,19 @@
 !> @file lagrangian_particle_model_mod.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
@@ -25,4 +24,7 @@
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4629 2020-07-29 09:37:56Z raasch
 ! support for MPI Fortran77 interface (mpif.h) removed
 !
@@ -32,108 +34,106 @@
 ! 4616 2020-07-21 10:09:46Z schwenkel
 ! Bugfix in case of strechting: k-calculation limited lower bound of 1
-! 
+!
 ! 4589 2020-07-06 12:34:09Z suehring
 ! remove unused variables
-! 
+!
 ! 4588 2020-07-06 11:06:02Z suehring
 ! Simplify particle-speed interpolation in logarithmic layer
-! 
+!
 ! 4585 2020-06-30 15:05:20Z suehring
-! Limit logarithmically interpolated particle speed to the velocity component
-! at the first prognostic grid point (since no stability corrected interpolation
-! is employed the particle speed could be overestimated in unstable conditions).
-! 
+! Limit logarithmically interpolated particle speed to the velocity component at the first
+! prognostic grid point (since no stability corrected interpolation is employed the particle speed
+! could be overestimated in unstable conditions).
+!
 ! 4546 2020-05-24 12:16:41Z raasch
 ! Variables iran and iran_part completely removed, added I/O of parallel random numbers to restart
 ! file
-! 
+!
 ! 4545 2020-05-22 13:17:57Z schwenkel
 ! Using parallel random generator, thus preventing dependency of PE number
-! 
+!
 ! 4535 2020-05-15 12:07:23Z raasch
 ! bugfix for restart data format query
-! 
+!
 ! 4520 2020-05-06 08:57:19Z schwenkel
 ! Add error number
-! 
+!
 ! 4517 2020-05-03 14:29:30Z raasch
 ! restart data handling with MPI-IO added
-! 
+!
 ! 4471 2020-03-24 12:08:06Z schwenkel
 ! Bugfix in lpm_droplet_interactions_ptq
-! 
+!
 ! 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
-! 
+!
 ! 4430 2020-02-27 18:02:20Z suehring
-! - Bugfix in logarithmic interpolation of near-ground particle speed (density
-!   was not considered).
+! - Bugfix in logarithmic interpolation of near-ground particle speed (density was not considered).
 ! - Revise CFL-check when SGS particle speeds are considered.
-! - In nested case with SGS particle speeds in the child domain, do not give 
-!   warning that particles are on domain boundaries. At the end of the particle
-!   time integration these will be transferred to the parent domain anyhow.
-! 
+! - In nested case with SGS particle speeds in the child domain, do not give warning that particles
+!   are on domain boundaries. At the end of the particle time integration these will be transferred
+!   to the parent domain anyhow.
+!
 ! 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
-! 
+! Introduction of wall_flags_total_0, which currently sets bits based on static topography
+! information used in wall_flags_static_0
+!
 ! 4336 2019-12-13 10:12:05Z raasch
-! bugfix: wrong header output of particle group features (density ratio) in case
-! of restarts corrected
-! 
+! bugfix: wrong header output of particle group features (density ratio) in case of restarts
+!         corrected
+!
 ! 4329 2019-12-10 15:46:36Z motisi
 ! Renamed wall_flags_0 to wall_flags_static_0
-! 
+!
 ! 4282 2019-10-29 16:18:46Z schwenkel
 ! Bugfix of particle timeseries in case of more than one particle group
-! 
+!
 ! 4277 2019-10-28 16:53:23Z schwenkel
 ! Bugfix: Added first_call_lpm in use statement
-! 
+!
 ! 4276 2019-10-28 16:03:29Z schwenkel
 ! Modularize lpm: Move conditions in time intergration to module
-! 
+!
 ! 4275 2019-10-28 15:34:55Z schwenkel
-! Change call of simple predictor corrector method, i.e. two divergence free
-! velocitiy fields are now used.
+! Change call of simple predictor corrector method, i.e. two divergence free velocitiy fields are
+! now used.
 !
 ! 4232 2019-09-20 09:34:22Z knoop
 ! Removed INCLUDE "mpif.h", as it is not needed because of USE pegrid
-! 
+!
 ! 4195 2019-08-28 13:44:27Z schwenkel
-! Bugfix for simple_corrector interpolation method in case of ocean runs and
-! output particle advection interpolation method into header
-! 
+! Bugfix for simple_corrector interpolation method in case of ocean runs and output particle
+! advection interpolation method into header
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 4168 2019-08-16 13:50:17Z suehring
 ! Replace function get_topography_top_index by topo_top_ind
-! 
+!
 ! 4145 2019-08-06 09:55:22Z schwenkel
 ! Some reformatting
-! 
+!
 ! 4144 2019-08-06 09:11:47Z raasch
 ! relational operators .EQ., .NE., etc. replaced by ==, /=, etc.
-! 
+!
 ! 4143 2019-08-05 15:14:53Z schwenkel
 ! Rename variable and change select case to if statement
-! 
+!
 ! 4122 2019-07-26 13:11:56Z schwenkel
 ! Implement reset method as bottom boundary condition
-! 
+!
 ! 4121 2019-07-26 10:01:22Z schwenkel
-! Implementation of an simple method for interpolating the velocities to
-! particle position
-! 
+! Implementation of an simple method for interpolating the velocities to particle position
+!
 ! 4114 2019-07-23 14:09:27Z schwenkel
 ! Bugfix: Added working precision for if statement
-! 
+!
 ! 4054 2019-06-27 07:42:18Z raasch
 ! bugfix for calculating the minimum particle time step
-! 
+!
 ! 4044 2019-06-19 12:28:27Z schwenkel
 ! Bugfix in case of grid strecting: corrected calculation of k-Index
@@ -141,20 +141,20 @@
 ! 4043 2019-06-18 16:59:00Z schwenkel
 ! Remove min_nr_particle, Add lpm_droplet_interactions_ptq into module
-! 
+!
 ! 4028 2019-06-13 12:21:37Z schwenkel
 ! Further modularization of particle code components
-! 
+!
 ! 4020 2019-06-06 14:57:48Z schwenkel
-! Removing submodules 
-! 
+! Removing submodules
+!
 ! 4018 2019-06-06 13:41:50Z eckhard
 ! Bugfix for former revision
-! 
+!
 ! 4017 2019-06-06 12:16:46Z schwenkel
 ! Modularization of all lagrangian particle model code components
-! 
-! 3655 2019-01-07 16:51:22Z knoop 
-! bugfix to guarantee correct particle releases in case that the release
-! interval is smaller than the model timestep
+!
+! 3655 2019-01-07 16:51:22Z knoop
+! bugfix to guarantee correct particle releases in case that the release interval is smaller than
+! the model timestep
 !
 ! Revision 1.1  1999/11/25 16:16:06  raasch
@@ -164,8 +164,7 @@
 ! Description:
 ! ------------
-!> The embedded LPM allows for studying transport and dispersion processes within
-!> turbulent flows. This model including passive particles that do not show any
-!> feedback on the turbulent flow. Further also particles with inertia and
-!> cloud droplets ca be simulated explicitly.
+!> The embedded LPM allows for studying transport and dispersion processes within turbulent flows.
+!> This model is including passive particles that do not show any feedback on the turbulent flow.
+!> Further also particles with inertia and cloud droplets can be simulated explicitly.
 !>
 !> @todo test lcm
@@ -173,44 +172,36 @@
 !> @note <Enter notes on the module>
 !> @bug  <Enter bug on the module>
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  MODULE lagrangian_particle_model_mod
 
     USE, INTRINSIC ::  ISO_C_BINDING
 
-    USE arrays_3d,                                                             &
-        ONLY:  de_dx, de_dy, de_dz,                                            &
-               d_exner,                                                        &
-               dzw, zu, zw,  ql_c, ql_v, ql_vp, hyp,                           &
-               pt, q, exner, ql, diss, e, u, v, w, km, ql_1, ql_2
- 
-    USE averaging,                                                             &
-        ONLY:  ql_c_av, pr_av, pc_av, ql_vp_av, ql_v_av
-
-    USE basic_constants_and_equations_mod,                                     &
-        ONLY: molecular_weight_of_solute, molecular_weight_of_water, magnus,   &
-              pi, rd_d_rv, rho_l, r_v, rho_s, vanthoff, l_v, kappa, g, lv_d_cp
-
-    USE control_parameters,                                                    &
-        ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s, &
-               child_domain,                                                   &
-               cloud_droplets, constant_flux_layer, current_timestep_number,   &
-               dt_3d, dt_3d_reached, debug_output, first_call_lpm, humidity,   &
-               dt_3d_reached_l, dt_dopts, dz, initializing_actions,            &
-               intermediate_timestep_count, intermediate_timestep_count_max,   &
-               message_string, molecular_viscosity, ocean_mode,                &
-               particle_maximum_age, restart_data_format_input,                &
-               restart_data_format_output,                                     &
-               simulated_time, topography, dopts_time_count,                   &
-               time_since_reference_point, rho_surface, u_gtrans, v_gtrans,    &
-               dz_stretch_level, dz_stretch_level_start
-
-    USE cpulog,                                                                &
+    USE arrays_3d,                                                                                 &
+        ONLY:  d_exner, de_dx, de_dy, de_dz, diss, dzw, e, exner, hyp, km, pt, q, ql, ql_1, ql_2,  &
+               ql_c, ql_v, ql_vp, u, v, w, zu, zw
+
+    USE averaging,                                                                                 &
+        ONLY:  pc_av, pr_av, ql_c_av, ql_v_av, ql_vp_av
+
+    USE basic_constants_and_equations_mod,                                                         &
+        ONLY:  g, kappa, l_v, lv_d_cp, magnus, molecular_weight_of_solute,                         &
+               molecular_weight_of_water, pi, r_v, rd_d_rv, rho_l, rho_s, vanthoff
+
+    USE control_parameters,                                                                        &
+        ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s,                     &
+               child_domain, cloud_droplets, constant_flux_layer, current_timestep_number,         &
+               debug_output, dopts_time_count, dt_3d, dt_3d_reached, dt_3d_reached_l, dt_dopts, dz,&
+               dz_stretch_level, dz_stretch_level_start, first_call_lpm, humidity,                 &
+               initializing_actions, intermediate_timestep_count, intermediate_timestep_count_max, &
+               message_string, molecular_viscosity, ocean_mode, particle_maximum_age,              &
+               restart_data_format_input, restart_data_format_output, rho_surface, simulated_time, &
+               time_since_reference_point, topography, u_gtrans, v_gtrans
+
+    USE cpulog,                                                                                    &
         ONLY:  cpu_log, log_point, log_point_s
 
-    USE indices,                                                               &
-        ONLY:  nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb,    &
-               nzb_max, nzt,nbgp, ngp_2dh_outer,                               &
-               topo_top_ind,                                                   &
-               wall_flags_total_0
+    USE indices,                                                                                   &
+        ONLY:  nbgp, ngp_2dh_outer, nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb,   &
+               nzb_max, nzt, topo_top_ind, wall_flags_total_0
 
     USE kinds
@@ -221,50 +212,48 @@
 
 #if defined( __parallel )
-    USE pmc_particle_interface,                                                &
-        ONLY: pmcp_c_get_particle_from_parent, pmcp_p_fill_particle_win,       &
-              pmcp_c_send_particle_to_parent, pmcp_p_empty_particle_win,       &
-              pmcp_p_delete_particles_in_fine_grid_area, pmcp_g_init,          &
-              pmcp_g_print_number_of_particles
+    USE pmc_particle_interface,                                                                    &
+        ONLY: pmcp_c_get_particle_from_parent, pmcp_c_send_particle_to_parent, pmcp_g_init,        &
+              pmcp_g_print_number_of_particles, pmcp_p_delete_particles_in_fine_grid_area,         &
+              pmcp_p_empty_particle_win, pmcp_p_fill_particle_win
 #endif
 
-    USE pmc_interface,                                                         &
+    USE pmc_interface,                                                                             &
         ONLY: nested_run
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                                            &
         ONLY:  ddx, dx, ddy, dy
 
-    USE netcdf_interface,                                                      &
-        ONLY:  netcdf_data_format, netcdf_deflate, dopts_num, id_set_pts,      &
-               id_var_dopts, id_var_time_pts, nc_stat,                         &
-               netcdf_handle_error
-
-    USE random_generator_parallel,                                             &
-        ONLY:  init_parallel_random_generator,                                 &
-               random_dummy,                                                   &
-               random_number_parallel,                                         &
-               random_number_parallel_gauss,                                   &
-               random_seed_parallel,                                           &
-               id_random_array
-
-    USE restart_data_mpi_io_mod,                                               &
-        ONLY:  rd_mpi_io_check_array,                                          &
-               rd_mpi_io_check_open,                                           &
-               rd_mpi_io_close,                                                &
-               rd_mpi_io_open,                                                 &
-               rd_mpi_io_particle_filetypes,                                   &
-               rrd_mpi_io,                                                     &
-               rrd_mpi_io_global_array,                                        &
-               rrd_mpi_io_particles,                                           &
-               wrd_mpi_io,                                                     &
-               wrd_mpi_io_global_array,                                        &
+    USE netcdf_interface,                                                                          &
+        ONLY:  dopts_num, id_set_pts, id_var_dopts, id_var_time_pts, nc_stat, netcdf_data_format,  &
+               netcdf_deflate, netcdf_handle_error
+
+    USE random_generator_parallel,                                                                 &
+        ONLY:  init_parallel_random_generator,                                                     &
+               id_random_array,                                                                    &
+               random_dummy,                                                                       &
+               random_number_parallel,                                                             &
+               random_number_parallel_gauss,                                                       &
+               random_seed_parallel
+
+    USE restart_data_mpi_io_mod,                                                                   &
+        ONLY:  rd_mpi_io_check_array,                                                              &
+               rd_mpi_io_check_open,                                                               &
+               rd_mpi_io_close,                                                                    &
+               rd_mpi_io_open,                                                                     &
+               rd_mpi_io_particle_filetypes,                                                       &
+               rrd_mpi_io,                                                                         &
+               rrd_mpi_io_global_array,                                                            &
+               rrd_mpi_io_particles,                                                               &
+               wrd_mpi_io,                                                                         &
+               wrd_mpi_io_global_array,                                                            &
                wrd_mpi_io_particles
 
-    USE statistics,                                                            &
+    USE statistics,                                                                                &
         ONLY:  hom
 
-    USE surface_mod,                                                           &
-        ONLY:  bc_h,                                                           &
-               surf_def_h,                                                     &
-               surf_lsm_h,                                                     &
+    USE surface_mod,                                                                               &
+        ONLY:  bc_h,                                                                               &
+               surf_def_h,                                                                         &
+               surf_lsm_h,                                                                         &
                surf_usm_h
 
@@ -283,9 +272,15 @@
     IMPLICIT NONE
 
+    INTEGER(iwp), PARAMETER         ::  nr_2_direction_move = 10000 !<
+    INTEGER(iwp), PARAMETER         ::  phase_init    = 1           !<
+    INTEGER(iwp), PARAMETER, PUBLIC ::  phase_release = 2           !<
+
+    REAL(wp), PARAMETER ::  c_0 = 3.0_wp         !< parameter for lagrangian timescale
+
     CHARACTER(LEN=15) ::  aero_species = 'nacl'                   !< aerosol species
     CHARACTER(LEN=15) ::  aero_type    = 'maritime'               !< aerosol type
+    CHARACTER(LEN=15) ::  bc_par_b     = 'reflect'                !< bottom boundary condition
     CHARACTER(LEN=15) ::  bc_par_lr    = 'cyclic'                 !< left/right boundary condition
     CHARACTER(LEN=15) ::  bc_par_ns    = 'cyclic'                 !< north/south boundary condition
-    CHARACTER(LEN=15) ::  bc_par_b     = 'reflect'                !< bottom boundary condition
     CHARACTER(LEN=15) ::  bc_par_t     = 'absorb'                 !< top boundary condition
     CHARACTER(LEN=15) ::  collision_kernel   = 'none'             !< collision kernel
@@ -296,12 +291,15 @@
     CHARACTER(LEN=25) ::  particle_advection_interpolation = 'trilinear' !< interpolation method for calculatin the particle
 
-    INTEGER(iwp) ::  deleted_particles = 0                        !< number of deleted particles per time step    
+    INTEGER(iwp) ::  deleted_particles = 0                        !< number of deleted particles per time step
     INTEGER(iwp) ::  i_splitting_mode                             !< dummy for splitting mode
+    INTEGER(iwp) ::  isf                                          !< dummy for splitting function
     INTEGER(iwp) ::  max_number_particles_per_gridbox = 100       !< namelist parameter (see documentation)
-    INTEGER(iwp) ::  isf                                          !< dummy for splitting function
     INTEGER(iwp) ::  number_particles_per_gridbox = -1            !< namelist parameter (see documentation)
-    INTEGER(iwp) ::  number_of_sublayers = 20                     !< number of sublayers for particle velocities betwenn surface and first grid level
-    INTEGER(iwp) ::  offset_ocean_nzt = 0                         !< in case of oceans runs, the vertical index calculations need an offset
-    INTEGER(iwp) ::  offset_ocean_nzt_m1 = 0                      !< in case of oceans runs, the vertical index calculations need an offset
+    INTEGER(iwp) ::  number_of_sublayers = 20                     !< number of sublayers for particle velocities betwenn surface
+                                                                  !< and first grid level
+    INTEGER(iwp) ::  offset_ocean_nzt = 0                         !< in case of oceans runs, the vertical index calculations need
+                                                                  !< an offset
+    INTEGER(iwp) ::  offset_ocean_nzt_m1 = 0                      !< in case of oceans runs, the vertical index calculations need
+                                                                  !< an offset
     INTEGER(iwp) ::  particles_per_point = 1                      !< namelist parameter (see documentation)
     INTEGER(iwp) ::  radius_classes = 20                          !< namelist parameter (see documentation)
@@ -310,19 +308,22 @@
     INTEGER(iwp) ::  step_dealloc = 100                           !< namelist parameter (see documentation)
     INTEGER(iwp) ::  total_number_of_particles                    !< total number of particles in the whole model domain
+    INTEGER(iwp) ::  trlp_count_recv_sum                          !< parameter for particle exchange of PEs
     INTEGER(iwp) ::  trlp_count_sum                               !< parameter for particle exchange of PEs
-    INTEGER(iwp) ::  trlp_count_recv_sum                          !< parameter for particle exchange of PEs
+    INTEGER(iwp) ::  trrp_count_recv_sum                          !< parameter for particle exchange of PEs
     INTEGER(iwp) ::  trrp_count_sum                               !< parameter for particle exchange of PEs
-    INTEGER(iwp) ::  trrp_count_recv_sum                          !< parameter for particle exchange of PEs
+    INTEGER(iwp) ::  trsp_count_recv_sum                          !< parameter for particle exchange of PEs
     INTEGER(iwp) ::  trsp_count_sum                               !< parameter for particle exchange of PEs
-    INTEGER(iwp) ::  trsp_count_recv_sum                          !< parameter for particle exchange of PEs
+    INTEGER(iwp) ::  trnp_count_recv_sum                          !< parameter for particle exchange of PEs
     INTEGER(iwp) ::  trnp_count_sum                               !< parameter for particle exchange of PEs
-    INTEGER(iwp) ::  trnp_count_recv_sum                          !< parameter for particle exchange of PEs
 
     INTEGER(isp), DIMENSION(:,:,:), ALLOCATABLE ::  seq_random_array_particles   !< sequence of random array for particle
 
-    LOGICAL ::  lagrangian_particle_model = .FALSE.       !< namelist parameter (see documentation) 
     LOGICAL ::  curvature_solution_effects = .FALSE.      !< namelist parameter (see documentation)
     LOGICAL ::  deallocate_memory = .TRUE.                !< namelist parameter (see documentation)
     LOGICAL ::  hall_kernel = .FALSE.                     !< flag for collision kernel
+    LOGICAL ::  interpolation_simple_corrector = .FALSE.  !< flag for simple particle advection interpolation with corrector step
+    LOGICAL ::  interpolation_simple_predictor = .FALSE.  !< flag for simple particle advection interpolation with predictor step
+    LOGICAL ::  interpolation_trilinear = .FALSE.         !< flag for trilinear particle advection interpolation
+    LOGICAL ::  lagrangian_particle_model = .FALSE.       !< namelist parameter (see documentation)
     LOGICAL ::  merging = .FALSE.                         !< namelist parameter (see documentation)
     LOGICAL ::  random_start_position = .FALSE.           !< namelist parameter (see documentation)
@@ -332,9 +333,7 @@
     LOGICAL ::  use_kernel_tables = .FALSE.               !< parameter, which turns on the use of precalculated collision kernels
     LOGICAL ::  write_particle_statistics = .FALSE.       !< namelist parameter (see documentation)
-    LOGICAL ::  interpolation_simple_predictor = .FALSE.  !< flag for simple particle advection interpolation with predictor step
-    LOGICAL ::  interpolation_simple_corrector = .FALSE.  !< flag for simple particle advection interpolation with corrector step
-    LOGICAL ::  interpolation_trilinear = .FALSE.         !< flag for trilinear particle advection interpolation
-
-    LOGICAL, DIMENSION(max_number_of_particle_groups) ::   vertical_particle_advection = .TRUE. !< Switch for vertical particle transport
+
+    LOGICAL, DIMENSION(max_number_of_particle_groups) ::   vertical_particle_advection = .TRUE.  !< Switch for vertical particle
+                                                                                                 !< transport
 
     REAL(wp) ::  aero_weight = 1.0_wp                      !< namelist parameter (see documentation)
@@ -342,4 +341,5 @@
     REAL(wp) ::  dt_prel = 9999999.9_wp                    !< namelist parameter (see documentation)
     REAL(wp) ::  dt_write_particle_data = 9999999.9_wp     !< namelist parameter (see documentation)
+    REAL(wp) ::  epsilon_collision                         !<
     REAL(wp) ::  end_time_prel = 9999999.9_wp              !< namelist parameter (see documentation)
     REAL(wp) ::  initial_weighting_factor = 1.0_wp         !< namelist parameter (see documentation)
@@ -350,15 +350,13 @@
     REAL(wp) ::  radius_merge = 1.0E-7_wp                  !< namelist parameter (see documentation)
     REAL(wp) ::  radius_split = 40.0E-6_wp                 !< namelist parameter (see documentation)
+    REAL(wp) ::  rclass_lbound                             !<
+    REAL(wp) ::  rclass_ubound                             !<
     REAL(wp) ::  rm(3) = 1.0E-6_wp                         !< namelist parameter (see documentation)
     REAL(wp) ::  sgs_wf_part                               !< parameter for sgs
     REAL(wp) ::  time_write_particle_data = 0.0_wp         !< write particle data at current time on file
+    REAL(wp) ::  urms                                      !<
     REAL(wp) ::  weight_factor_merge = -1.0_wp             !< namelist parameter (see documentation)
     REAL(wp) ::  weight_factor_split = -1.0_wp             !< namelist parameter (see documentation)
     REAL(wp) ::  z0_av_global                              !< horizontal mean value of z0
-
-    REAL(wp) ::  rclass_lbound !<
-    REAL(wp) ::  rclass_ubound !<
-
-    REAL(wp), PARAMETER ::  c_0 = 3.0_wp         !< parameter for lagrangian timescale
 
     REAL(wp), DIMENSION(max_number_of_particle_groups) ::  density_ratio = 9999999.9_wp  !< namelist parameter (see documentation)
@@ -376,6 +374,4 @@
     REAL(wp), DIMENSION(:), ALLOCATABLE     ::  log_z_z0   !< Precalculate LOG(z/z0)
 
-    INTEGER(iwp), PARAMETER ::  NR_2_direction_move = 10000 !<
-
 #if defined( __parallel )
     INTEGER(iwp)            ::  nr_move_north               !<
@@ -385,7 +381,4 @@
     TYPE(particle_type), DIMENSION(:), ALLOCATABLE ::  move_also_south
 #endif
-
-    REAL(wp) ::  epsilon_collision !<
-    REAL(wp) ::  urms              !<
 
     REAL(wp), DIMENSION(:),   ALLOCATABLE ::  epsclass  !< dissipation rate class
@@ -404,24 +397,20 @@
     REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_t   !< w value of old timelevel t
 
-
-    INTEGER(iwp), PARAMETER         ::  PHASE_INIT    = 1  !<
-    INTEGER(iwp), PARAMETER, PUBLIC ::  PHASE_RELEASE = 2  !<
-
     SAVE
 
     PRIVATE
 
-    PUBLIC lpm_parin,     &
-           lpm_header,    &
-           lpm_init_arrays,&
-           lpm_init,      &
-           lpm_actions,   &
-           lpm_data_output_ptseries, &
-           lpm_interaction_droplets_ptq, &
-           lpm_rrd_local_particles, &
-           lpm_wrd_local, &
-           lpm_rrd_global, &
-           lpm_wrd_global, &
-           lpm_rrd_local, &
+    PUBLIC lpm_parin,                                                                              &
+           lpm_header,                                                                             &
+           lpm_init_arrays,                                                                        &
+           lpm_init,                                                                               &
+           lpm_actions,                                                                            &
+           lpm_data_output_ptseries,                                                               &
+           lpm_interaction_droplets_ptq,                                                           &
+           lpm_rrd_local_particles,                                                                &
+           lpm_wrd_local,                                                                          &
+           lpm_rrd_global,                                                                         &
+           lpm_wrd_global,                                                                         &
+           lpm_rrd_local,                                                                          &
            lpm_check_parameters
 
@@ -443,5 +432,5 @@
        MODULE PROCEDURE lpm_init_arrays
     END INTERFACE lpm_init_arrays
- 
+
     INTERFACE lpm_init
        MODULE PROCEDURE lpm_init
@@ -544,147 +533,147 @@
 
  CONTAINS
- 
-
-!------------------------------------------------------------------------------!
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Parin for &particle_parameters for the Lagrangian particle model
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_parin
- 
+
     CHARACTER (LEN=80) ::  line  !<
 
-    NAMELIST /particles_par/ &
-       aero_species, &
-       aero_type, &
-       aero_weight, &
-       alloc_factor, &
-       bc_par_b, &
-       bc_par_lr, &
-       bc_par_ns, &
-       bc_par_t, &
-       collision_kernel, &
-       curvature_solution_effects, &
-       deallocate_memory, &
-       density_ratio, &
-       dissipation_classes, &
-       dt_dopts, &
-       dt_min_part, &
-       dt_prel, &
-       dt_write_particle_data, &
-       end_time_prel, &
-       initial_weighting_factor, &
-       log_sigma, &
-       max_number_particles_per_gridbox, &
-       merging, &
-       na, &
-       number_concentration, &
-       number_of_particle_groups, &
-       number_particles_per_gridbox, &
-       particles_per_point, &
-       particle_advection_start, &
-       particle_advection_interpolation, &
-       particle_maximum_age, &
-       pdx, &
-       pdy, &
-       pdz, &
-       psb, &
-       psl, &
-       psn, &
-       psr, &
-       pss, &
-       pst, &
-       radius, &
-       radius_classes, &
-       radius_merge, &
-       radius_split, &
-       random_start_position, &
-       read_particles_from_restartfile, &
-       rm, &
-       seed_follows_topography, &
-       splitting, &
-       splitting_factor, &
-       splitting_factor_max, &
-       splitting_function, &
-       splitting_mode, &
-       step_dealloc, &
-       use_sgs_for_particles, &
-       vertical_particle_advection, &
-       weight_factor_merge, &
-       weight_factor_split, &
+    NAMELIST /particles_par/                                                                       &
+       aero_species,                                                                               &
+       aero_type,                                                                                  &
+       aero_weight,                                                                                &
+       alloc_factor,                                                                               &
+       bc_par_b,                                                                                   &
+       bc_par_lr,                                                                                  &
+       bc_par_ns,                                                                                  &
+       bc_par_t,                                                                                   &
+       collision_kernel,                                                                           &
+       curvature_solution_effects,                                                                 &
+       deallocate_memory,                                                                          &
+       density_ratio,                                                                              &
+       dissipation_classes,                                                                        &
+       dt_dopts,                                                                                   &
+       dt_min_part,                                                                                &
+       dt_prel,                                                                                    &
+       dt_write_particle_data,                                                                     &
+       end_time_prel,                                                                              &
+       initial_weighting_factor,                                                                   &
+       log_sigma,                                                                                  &
+       max_number_particles_per_gridbox,                                                           &
+       merging,                                                                                    &
+       na,                                                                                         &
+       number_concentration,                                                                       &
+       number_of_particle_groups,                                                                  &
+       number_particles_per_gridbox,                                                               &
+       particles_per_point,                                                                        &
+       particle_advection_start,                                                                   &
+       particle_advection_interpolation,                                                           &
+       particle_maximum_age,                                                                       &
+       pdx,                                                                                        &
+       pdy,                                                                                        &
+       pdz,                                                                                        &
+       psb,                                                                                        &
+       psl,                                                                                        &
+       psn,                                                                                        &
+       psr,                                                                                        &
+       pss,                                                                                        &
+       pst,                                                                                        &
+       radius,                                                                                     &
+       radius_classes,                                                                             &
+       radius_merge,                                                                               &
+       radius_split,                                                                               &
+       random_start_position,                                                                      &
+       read_particles_from_restartfile,                                                            &
+       rm,                                                                                         &
+       seed_follows_topography,                                                                    &
+       splitting,                                                                                  &
+       splitting_factor,                                                                           &
+       splitting_factor_max,                                                                       &
+       splitting_function,                                                                         &
+       splitting_mode,                                                                             &
+       step_dealloc,                                                                               &
+       use_sgs_for_particles,                                                                      &
+       vertical_particle_advection,                                                                &
+       weight_factor_merge,                                                                        &
+       weight_factor_split,                                                                        &
        write_particle_statistics
 
-    NAMELIST /particle_parameters/ &
-       aero_species, &
-       aero_type, &
-       aero_weight, &
-       alloc_factor, &
-       bc_par_b, &
-       bc_par_lr, &
-       bc_par_ns, &
-       bc_par_t, &
-       collision_kernel, &
-       curvature_solution_effects, &
-       deallocate_memory, &
-       density_ratio, &
-       dissipation_classes, &
-       dt_dopts, &
-       dt_min_part, &
-       dt_prel, &
-       dt_write_particle_data, &
-       end_time_prel, &
-       initial_weighting_factor, &
-       log_sigma, &
-       max_number_particles_per_gridbox, &
-       merging, &
-       na, &
-       number_concentration, &
-       number_of_output_particles, &
-       number_of_particle_groups, &
-       number_particles_per_gridbox, &
-       oversize, &
-       particles_per_point, &
-       particle_advection_start, &
-       particle_advection_interpolation, &
-       particle_maximum_age, &
-       part_output, &
-       part_inc, &
-       part_percent, &
-       pdx, &
-       pdy, &
-       pdz, &
-       psb, &
-       psl, &
-       psn, &
-       psr, &
-       pss, &
-       pst, &
-       radius, &
-       radius_classes, &
-       radius_merge, &
-       radius_split, &
-       random_start_position, &
-       read_particles_from_restartfile, &
-       rm, &
-       seed_follows_topography, &
-       splitting, &
-       splitting_factor, &
-       splitting_factor_max, &
-       splitting_function, &
-       splitting_mode, &
-       step_dealloc, &
-       unlimited_dimension, &
-       use_sgs_for_particles, &
-       vertical_particle_advection, &
-       weight_factor_merge, &
-       weight_factor_split, &
+    NAMELIST /particle_parameters/                                                                 &
+       aero_species,                                                                               &
+       aero_type,                                                                                  &
+       aero_weight,                                                                                &
+       alloc_factor,                                                                               &
+       bc_par_b,                                                                                   &
+       bc_par_lr,                                                                                  &
+       bc_par_ns,                                                                                  &
+       bc_par_t,                                                                                   &
+       collision_kernel,                                                                           &
+       curvature_solution_effects,                                                                 &
+       deallocate_memory,                                                                          &
+       density_ratio,                                                                              &
+       dissipation_classes,                                                                        &
+       dt_dopts,                                                                                   &
+       dt_min_part,                                                                                &
+       dt_prel,                                                                                    &
+       dt_write_particle_data,                                                                     &
+       end_time_prel,                                                                              &
+       initial_weighting_factor,                                                                   &
+       log_sigma,                                                                                  &
+       max_number_particles_per_gridbox,                                                           &
+       merging,                                                                                    &
+       na,                                                                                         &
+       number_concentration,                                                                       &
+       number_of_output_particles,                                                                 &
+       number_of_particle_groups,                                                                  &
+       number_particles_per_gridbox,                                                               &
+       oversize,                                                                                   &
+       particles_per_point,                                                                        &
+       particle_advection_start,                                                                   &
+       particle_advection_interpolation,                                                           &
+       particle_maximum_age,                                                                       &
+       part_output,                                                                                &
+       part_inc,                                                                                   &
+       part_percent,                                                                               &
+       pdx,                                                                                        &
+       pdy,                                                                                        &
+       pdz,                                                                                        &
+       psb,                                                                                        &
+       psl,                                                                                        &
+       psn,                                                                                        &
+       psr,                                                                                        &
+       pss,                                                                                        &
+       pst,                                                                                        &
+       radius,                                                                                     &
+       radius_classes,                                                                             &
+       radius_merge,                                                                               &
+       radius_split,                                                                               &
+       random_start_position,                                                                      &
+       read_particles_from_restartfile,                                                            &
+       rm,                                                                                         &
+       seed_follows_topography,                                                                    &
+       splitting,                                                                                  &
+       splitting_factor,                                                                           &
+       splitting_factor_max,                                                                       &
+       splitting_function,                                                                         &
+       splitting_mode,                                                                             &
+       step_dealloc,                                                                               &
+       unlimited_dimension,                                                                        &
+       use_sgs_for_particles,                                                                      &
+       vertical_particle_advection,                                                                &
+       weight_factor_merge,                                                                        &
+       weight_factor_split,                                                                        &
        write_particle_statistics
 
 !
-!-- Position the namelist-file at the beginning (it was already opened in
-!-- parin), search for the namelist-group of the package and position the
-!-- file at this line. Do the same for each optionally used package.
+!-- Position the namelist-file at the beginning (it was already opened in parin), search for the
+!-- namelist-group of the package and position the file at this line. Do the same for each
+!-- optionally used package.
     line = ' '
-    
+
 !
 !-- Try to find particles package
@@ -701,5 +690,5 @@
 !-- Set flag that indicates that particles are switched on
     particle_advection = .TRUE.
-    
+
     GOTO 14
 
@@ -719,6 +708,6 @@
     READ ( 11, particles_par, ERR = 13, END = 14 )
 
-    message_string = 'namelist particles_par is deprecated and will be ' //    &
-                     'removed in near future. Please use namelist ' //         &
+    message_string = 'namelist particles_par is deprecated and will be ' //                        &
+                     'removed in near future. Please use namelist ' //                             &
                      'particle_parameters instead'
     CALL message( 'package_parin', 'PA0487', 0, 1, 0, 6, 0 )
@@ -737,10 +726,10 @@
 
  END SUBROUTINE lpm_parin
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Writes used particle attributes in header file.
-!------------------------------------------------------------------------------! 
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_header ( io )
 
@@ -763,11 +752,10 @@
        ENDIF
     ENDIF
- 
+
     IF ( particle_advection )  THEN
 !
 !--    Particle attributes
-       WRITE ( io, 480 )  particle_advection_start, TRIM(particle_advection_interpolation), &
-                          dt_prel, bc_par_lr, &
-                          bc_par_ns, bc_par_b, bc_par_t, particle_maximum_age, &
+       WRITE ( io, 480 )  particle_advection_start, TRIM(particle_advection_interpolation),        &
+                          dt_prel, bc_par_lr, bc_par_ns, bc_par_b, bc_par_t, particle_maximum_age, &
                           end_time_prel
        IF ( use_sgs_for_particles )  WRITE ( io, 488 )  dt_min_part
@@ -801,37 +789,30 @@
              WRITE ( io, 492 )
           ENDIF
-          WRITE ( io, 493 )  psl(i), psr(i), pss(i), psn(i), psb(i), pst(i), &
-                             pdx(i), pdy(i), pdz(i)
+          WRITE ( io, 493 )  psl(i), psr(i), pss(i), psn(i), psb(i), pst(i), pdx(i), pdy(i), pdz(i)
           IF ( .NOT. vertical_particle_advection(i) )  WRITE ( io, 482 )
        ENDDO
 
     ENDIF
-    
+
 344 FORMAT ('       Output format: ',A/)
 354 FORMAT ('       Output format: ',A, '   compressed with level: ',I1/)
 
-433 FORMAT ('    Cloud droplets treated explicitly using the Lagrangian part', &
-                 'icle model')
-434 FORMAT ('    Curvature and solution effecs are considered for growth of', &
+433 FORMAT ('    Cloud droplets treated explicitly using the Lagrangian part','icle model')
+434 FORMAT ('    Curvature and solution effecs are considered for growth of',                      &
                  ' droplets < 1.0E-6 m')
 435 FORMAT ('    Droplet collision is handled by ',A,'-kernel')
-436 FORMAT ('       Fast kernel with fixed radius- and dissipation classes ', &
-                    'are used'/ &
-            '          number of radius classes:       ',I3,'    interval ', &
-                       '[1.0E-6,2.0E-4] m'/ &
-            '          number of dissipation classes:   ',I2,'    interval ', &
-                       '[0,1000] cm**2/s**3')
+436 FORMAT ('       Fast kernel with fixed radius- and dissipation classes ','are used'/           &
+            '          number of radius classes:       ',I3,'    interval ','[1.0E-6,2.0E-4] m'/   &
+            '          number of dissipation classes:   ',I2,'    interval ','[0,1000] cm**2/s**3')
 437 FORMAT ('    Droplet collision is switched off')
 
-480 FORMAT ('    Particles:'/ &
-            '    ---------'// &
-            '       Particle advection is active (switched on at t = ', F7.1, &
-                    ' s)'/ &
-            '       Interpolation of particle velocities is done by using ', A, &
-                    ' method'/ &
-            '       Start of new particle generations every  ',F6.1,' s'/ &
-            '       Boundary conditions: left/right: ', A, ' north/south: ', A/&
-            '                            bottom:     ', A, ' top:         ', A/&
-            '       Maximum particle age:                 ',F9.1,' s'/ &
+480 FORMAT ('    Particles:'/                                                                      &
+            '    ---------'//                                                                      &
+            '       Particle advection is active (switched on at t = ', F7.1,' s)'/                &
+            '       Interpolation of particle velocities is done by using ', A,' method'/          &
+            '       Start of new particle generations every  ',F6.1,' s'/                          &
+            '       Boundary conditions: left/right: ', A, ' north/south: ', A/                    &
+            '                            bottom:     ', A, ' top:         ', A/                    &
+            '       Maximum particle age:                 ',F9.1,' s'/                             &
             '       Advection stopped at t = ',F9.1,' s'/)
 481 FORMAT ('       Particles have random start positions'/)
@@ -840,33 +821,30 @@
 486 FORMAT ('       Particle statistics are written on file'/)
 487 FORMAT ('       Number of particle groups: ',I2/)
-488 FORMAT ('       SGS velocity components are used for particle advection'/ &
+488 FORMAT ('       SGS velocity components are used for particle advection'/                      &
             '          minimum timestep for advection:', F8.5/)
-489 FORMAT ('       Number of particles simultaneously released at each ', &
-                    'point: ', I5/)
-490 FORMAT ('       Particle group ',I2,':'/ &
+489 FORMAT ('       Number of particles simultaneously released at each ','point: ', I5/)
+490 FORMAT ('       Particle group ',I2,':'/                                                       &
             '          Particle radius: ',E10.3, 'm')
-491 FORMAT ('          Particle inertia is activated'/ &
+491 FORMAT ('          Particle inertia is activated'/                                             &
             '             density_ratio (rho_fluid/rho_particle) =',F6.3/)
 492 FORMAT ('          Particles are advected only passively (no inertia)'/)
-493 FORMAT ('          Boundaries of particle source: x:',F8.1,' - ',F8.1,' m'/&
-            '                                         y:',F8.1,' - ',F8.1,' m'/&
-            '                                         z:',F8.1,' - ',F8.1,' m'/&
-            '          Particle distances:  dx = ',F8.1,' m  dy = ',F8.1, &
-                       ' m  dz = ',F8.1,' m'/)
-494 FORMAT ('       Output of particle time series in NetCDF format every ', &
-                    F8.2,' s'/)
+493 FORMAT ('          Boundaries of particle source: x:',F8.1,' - ',F8.1,' m'/                    &
+            '                                         y:',F8.1,' - ',F8.1,' m'/                    &
+            '                                         z:',F8.1,' - ',F8.1,' m'/                    &
+            '          Particle distances:  dx = ',F8.1,' m  dy = ',F8.1,' m  dz = ',F8.1,' m'/)
+494 FORMAT ('       Output of particle time series in NetCDF format every ',F8.2,' s'/)
 495 FORMAT ('       Number of particles in total domain: ',I10/)
-496 FORMAT ('       Initial vertical particle positions are interpreted ', &
+496 FORMAT ('       Initial vertical particle positions are interpreted ',                         &
                     'as relative to the given topography')
-    
+
  END SUBROUTINE lpm_header
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Writes used particle attributes in header file.
-!------------------------------------------------------------------------------!  
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_check_parameters
- 
+
 !
 !-- Collision kernels:
@@ -883,5 +861,5 @@
 
        CASE DEFAULT
-          message_string = 'unknown collision kernel: collision_kernel = "' // &
+          message_string = 'unknown collision kernel: collision_kernel = "' //                     &
                            TRIM( collision_kernel ) // '"'
           CALL message( 'lpm_check_parameters', 'PA0350', 1, 2, 0, 6, 0 )
@@ -891,12 +869,11 @@
 
 !
-!-- Subgrid scale velocites with the simple interpolation method for resolved
-!-- velocites is not implemented for passive particles. However, for cloud
-!-- it can be combined as the sgs-velocites for active particles are
-!-- calculated differently, i.e. no subboxes are needed.
-    IF ( .NOT. TRIM( particle_advection_interpolation ) == 'trilinear'  .AND.  &
-       use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
-          message_string = 'subrgrid scale velocities in combination with ' // &
-                           'simple interpolation method is not '            // &
+!-- Subgrid scale velocites with the simple interpolation method for resolved velocites is not
+!-- implemented for passive particles. However, for cloud it can be combined as the sgs-velocites
+!-- for active particles are calculated differently, i.e. no subboxes are needed.
+    IF ( .NOT. TRIM( particle_advection_interpolation ) == 'trilinear'  .AND.                      &
+         use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
+          message_string = 'subrgrid scale velocities in combination with ' //                     &
+                           'simple interpolation method is not '            //                     &
                            'implemented'
           CALL message( 'lpm_check_parameters', 'PA0659', 1, 2, 0, 6, 0 )
@@ -904,5 +881,5 @@
 
     IF ( nested_run  .AND.  cloud_droplets )  THEN
-       message_string = 'nested runs in combination with cloud droplets ' // &
+       message_string = 'nested runs in combination with cloud droplets ' //                       &
                         'is not implemented'
           CALL message( 'lpm_check_parameters', 'PA0687', 1, 2, 0, 6, 0 )
@@ -911,25 +888,25 @@
 
  END SUBROUTINE lpm_check_parameters
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Initialize arrays for lpm
-!------------------------------------------------------------------------------!   
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_init_arrays
- 
+
     IF ( cloud_droplets )  THEN
 !
 !--    Liquid water content, change in liquid water content
-       ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                         &
+       ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                             &
                   ql_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 !--    Real volume of particles (with weighting), volume of particles
-       ALLOCATE ( ql_v(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                         &
+       ALLOCATE ( ql_v(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                             &
                   ql_vp(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
     ENDIF
 
 
-    ALLOCATE( u_t(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
-              v_t(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
+    ALLOCATE( u_t(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
+              v_t(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
               w_t(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 !
@@ -946,10 +923,10 @@
 
  END SUBROUTINE lpm_init_arrays
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Initialize Lagrangian particle model
-!------------------------------------------------------------------------------! 
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_init
 
@@ -965,6 +942,6 @@
 
 !
-!-- In case of oceans runs, the vertical index calculations need an offset,
-!-- because otherwise the k indices will become negative
+!-- In case of oceans runs, the vertical index calculations need an offset, because otherwise the k
+!-- indices will become negative
     IF ( ocean_mode )  THEN
        offset_ocean_nzt    = nzt
@@ -973,7 +950,7 @@
 
 !
-!-- Define block offsets for dividing a gridcell in 8 sub cells
-!-- See documentation for List of subgrid boxes
-!-- See pack_and_sort in lpm_pack_arrays.f90 for assignment of the subgrid boxes
+!-- Define block offsets for dividing a gridcell in 8 sub cells.
+!-- See documentation for List of subgrid boxes.
+!-- See pack_and_sort in lpm_pack_arrays.f90 for assignment of the subgrid boxes.
     block_offset(0) = block_offset_def ( 0, 0, 0)
     block_offset(1) = block_offset_def ( 0, 0,-1)
@@ -987,7 +964,7 @@
 !-- Check the number of particle groups.
     IF ( number_of_particle_groups > max_number_of_particle_groups )  THEN
-       WRITE( message_string, * ) 'max_number_of_particle_groups =',           &
-                                  max_number_of_particle_groups ,              &
-                                  '&number_of_particle_groups reset to ',      &
+       WRITE( message_string, * ) 'max_number_of_particle_groups =',                               &
+                                  max_number_of_particle_groups ,                                  &
+                                  '&number_of_particle_groups reset to ',                          &
                                   max_number_of_particle_groups
        CALL message( 'lpm_init', 'PA0213', 0, 1, 0, 6, 0 )
@@ -995,9 +972,8 @@
     ENDIF
 !
-!-- Check if downward-facing walls exist. This case, reflection boundary
-!-- conditions (as well as subgrid-scale velocities) may do not work
-!-- propably (not realized so far).
+!-- Check if downward-facing walls exist. This case, reflection boundary conditions (as well as
+!-- subgrid-scale velocities) may do not work properly (not realized so far).
     IF ( surf_def_h(1)%ns >= 1 )  THEN
-       WRITE( message_string, * ) 'Overhanging topography do not work '//      &
+       WRITE( message_string, * ) 'Overhanging topography do not work '//                          &
                                   'with particles'
        CALL message( 'lpm_init', 'PA0212', 0, 1, 0, 6, 0 )
@@ -1019,6 +995,6 @@
 
 !
-!-- If number_particles_per_gridbox is set, the parametres pdx, pdy and pdz are
-!-- calculated diagnostically. Therfore an isotropic distribution is prescribed.
+!-- If number_particles_per_gridbox is set, the parametres pdx, pdy and pdz are calculated
+!-- diagnostically. Therfore an isotropic distribution is prescribed.
     IF ( number_particles_per_gridbox /= -1 .AND.   &
          number_particles_per_gridbox >= 1 )    THEN
@@ -1026,6 +1002,5 @@
              REAL(number_particles_per_gridbox))**0.3333333_wp
 !
-!--    Ensure a smooth value (two significant digits) of distance between
-!--    particles (pdx, pdy, pdz).
+!--    Ensure a smooth value (two significant digits) of distance between particles (pdx, pdy, pdz).
        div = 1000.0_wp
        DO  WHILE ( pdx(1) < div )
@@ -1066,11 +1041,9 @@
 
 !
-!-- Allocate array required for logarithmic vertical interpolation of
-!-- horizontal particle velocities between the surface and the first vertical
-!-- grid level. In order to avoid repeated CPU cost-intensive CALLS of
-!-- intrinsic FORTRAN procedure LOG(z/z0), LOG(z/z0) is precalculated for
+!-- Allocate array required for logarithmic vertical interpolation of horizontal particle velocities
+!-- between the surface and the first vertical grid level. In order to avoid repeated CPU
+!-- cost-intensive CALLS of intrinsic FORTRAN procedure LOG(z/z0), LOG(z/z0) is precalculated for
 !-- several heights. Splitting into 20 sublayers turned out to be sufficient.
-!-- To obtain exact height levels of particles, linear interpolation is applied
-!-- (see lpm_advec.f90).
+!-- To obtain exact height levels of particles, linear interpolation is applied (see lpm_advec.f90).
     IF ( constant_flux_layer )  THEN
 
@@ -1079,15 +1052,12 @@
 
 !
-!--    Calculate horizontal mean value of z0 used for logartihmic
-!--    interpolation. Note: this is not exact for heterogeneous z0.
-!--    However, sensitivity studies showed that the effect is
-!--    negligible.
-       z0_av_local  = SUM( surf_def_h(0)%z0 ) + SUM( surf_lsm_h%z0 ) +         &
-                      SUM( surf_usm_h%z0 )
+!--    Calculate horizontal mean value of z0 used for logartihmic interpolation. Note: this is not
+!--    exact for heterogeneous z0.
+!--    However, sensitivity studies showed that the effect is negligible.
+       z0_av_local  = SUM( surf_def_h(0)%z0 ) + SUM( surf_lsm_h%z0 ) + SUM( surf_usm_h%z0 )
        z0_av_global = 0.0_wp
 
 #if defined( __parallel )
-       CALL MPI_ALLREDUCE(z0_av_local, z0_av_global, 1, MPI_REAL, MPI_SUM, &
-                          comm2d, ierr )
+       CALL MPI_ALLREDUCE( z0_av_local, z0_av_global, 1, MPI_REAL, MPI_SUM, comm2d, ierr )
 #else
        z0_av_global = z0_av_local
@@ -1143,5 +1113,5 @@
 
        CASE DEFAULT
-          WRITE( message_string, * )  'unknown boundary condition ',           &
+          WRITE( message_string, * )  'unknown boundary condition ',                               &
                                        'bc_par_b = "', TRIM( bc_par_b ), '"'
           CALL message( 'lpm_init', 'PA0217', 1, 2, 0, 6, 0 )
@@ -1160,5 +1130,5 @@
 
        CASE DEFAULT
-          WRITE( message_string, * ) 'unknown boundary condition ',            &
+          WRITE( message_string, * ) 'unknown boundary condition ',                                &
                                      'bc_par_t = "', TRIM( bc_par_t ), '"'
           CALL message( 'lpm_init', 'PA0218', 1, 2, 0, 6, 0 )
@@ -1180,5 +1150,5 @@
 
        CASE DEFAULT
-          WRITE( message_string, * ) 'unknown boundary condition ',   &
+          WRITE( message_string, * ) 'unknown boundary condition ',                                &
                                      'bc_par_lr = "', TRIM( bc_par_lr ), '"'
           CALL message( 'lpm_init', 'PA0219', 1, 2, 0, 6, 0 )
@@ -1200,5 +1170,5 @@
 
        CASE DEFAULT
-          WRITE( message_string, * ) 'unknown boundary condition ',   &
+          WRITE( message_string, * ) 'unknown boundary condition ',                                &
                                      'bc_par_ns = "', TRIM( bc_par_ns ), '"'
           CALL message( 'lpm_init', 'PA0220', 1, 2, 0, 6, 0 )
@@ -1217,6 +1187,5 @@
 
        CASE DEFAULT
-          WRITE( message_string, * )  'unknown splitting_mode = "',            &
-                                      TRIM( splitting_mode ), '"'
+          WRITE( message_string, * )  'unknown splitting_mode = "', TRIM( splitting_mode ), '"'
           CALL message( 'lpm_init', 'PA0146', 1, 2, 0, 6, 0 )
 
@@ -1234,5 +1203,5 @@
 
        CASE DEFAULT
-          WRITE( message_string, * )  'unknown splitting function = "',        &
+          WRITE( message_string, * )  'unknown splitting function = "',                            &
                                        TRIM( splitting_function ), '"'
           CALL message( 'lpm_init', 'PA0147', 1, 2, 0, 6, 0 )
@@ -1244,14 +1213,14 @@
 
 !
-!-- For the first model run of a possible job chain initialize the
-!-- particles, otherwise read the particle data from restart file.
-    IF ( TRIM( initializing_actions ) == 'read_restart_data'  &
+!-- For the first model run of a possible job chain initialize the particles, otherwise read the
+!-- particle data from restart file.
+    IF ( TRIM( initializing_actions ) == 'read_restart_data'                                       &
          .AND.  read_particles_from_restartfile )  THEN
        CALL lpm_rrd_local_particles
     ELSE
 !
-!--    Allocate particle arrays and set attributes of the initial set of
-!--    particles, which can be also periodically released at later times.
-       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
+!--    Allocate particle arrays and set attributes of the initial set of particles, which can be
+!--    also periodically released at later times.
+       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                         &
                  grid_particles(nzb+1:nzt,nys:nyn,nxl:nxr) )
 
@@ -1259,20 +1228,19 @@
        prt_count           = 0
 !
-!--    initialize counter for particle IDs
+!--    Initialize counter for particle IDs
        grid_particles%id_counter = 1
 !
-!--    Initialize all particles with dummy values (otherwise errors may
-!--    occur within restart runs). The reason for this is still not clear
-!--    and may be presumably caused by errors in the respective user-interface.
-       zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
-                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
-                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
-                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
+!--    Initialize all particles with dummy values (otherwise errors may occur within restart runs).
+!--    The reason for this is still not clear and may be presumably caused by errors in the
+!--    respective user-interface.
+       zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,                      &
+                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,                      &
+                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,                      &
+                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,                      &
                                       0, 0, 0_idp, .FALSE., -1, -1 )
 
        particle_groups = particle_groups_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp )
 !
-!--    Set values for the density ratio and radius for all particle
-!--    groups, if necessary
+!--    Set values for the density ratio and radius for all particle groups, if necessary.
        IF ( density_ratio(1) == 9999999.9_wp )  density_ratio(1) = 0.0_wp
        IF ( radius(1)        == 9999999.9_wp )  radius(1) = 0.0_wp
@@ -1286,5 +1254,5 @@
        DO  i = 1, number_of_particle_groups
           IF ( density_ratio(i) /= 0.0_wp  .AND.  radius(i) == 0 )  THEN
-             WRITE( message_string, * ) 'particle group #', i, ' has a',       &
+             WRITE( message_string, * ) 'particle group #', i, ' has a',                           &
                                         'density ratio /= 0 but radius = 0'
              CALL message( 'lpm_init', 'PA0215', 1, 2, 0, 6, 0 )
@@ -1295,5 +1263,5 @@
 
 !
-!--    Initialize parallel random number sequence seed for particles
+!--    Initialize parallel random number sequence seed for particles.
 !--    This is done separately here, as thus particle random numbers do not affect the random
 !--    numbers used for the flow field (e.g. for generating flow disturbances).
@@ -1301,6 +1269,5 @@
        seq_random_array_particles = 0
 
-!--    Initializing with random_seed_parallel for every vertical
-!--    gridpoint column.
+!--    Initializing with random_seed_parallel for every vertical gridpoint column.
        random_dummy = 0
        DO  i = nxl, nxr
@@ -1322,6 +1289,5 @@
        IF ( write_particle_statistics )  THEN
           CALL check_open( 80 )
-          WRITE ( 80, 8000 )  current_timestep_number, simulated_time,         &
-                              number_of_particles
+          WRITE ( 80, 8000 )  current_timestep_number, simulated_time, number_of_particles
           CALL close_file( 80 )
        ENDIF
@@ -1333,4 +1299,5 @@
 #endif
 
+!
 !-- next line is in preparation for particle data output
 !    CALL dop_init
@@ -1346,10 +1313,10 @@
 
  END SUBROUTINE lpm_init
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Create Lagrangian particles
-!------------------------------------------------------------------------------!  
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_create_particle (phase)
 
@@ -1378,10 +1345,9 @@
     REAL(wp)                   ::  rand_contr !< dummy argument for random position
 
-    TYPE(particle_type),TARGET ::  tmp_particle !< temporary particle used for initialization
-
-
-!
-!-- Calculate particle positions and store particle attributes, if
-!-- particle is situated on this PE
+    TYPE(particle_type), TARGET ::  tmp_particle !< temporary particle used for initialization
+
+
+!
+!-- Calculate particle positions and store particle attributes, if particle is situated on this PE.
     DO  loop_stride = 1, 2
        first_stride = (loop_stride == 1)
@@ -1395,6 +1361,5 @@
 !--    Calculate initial_weighting_factor diagnostically
        IF ( number_concentration /= -1.0_wp  .AND.  number_concentration > 0.0_wp )  THEN
-          initial_weighting_factor =  number_concentration  *                           &
-                                      pdx(1) * pdy(1) * pdz(1)
+          initial_weighting_factor =  number_concentration * pdx(1) * pdy(1) * pdz(1)
        END IF
 
@@ -1406,10 +1371,8 @@
                 pos_y = pss(i)
                 DO WHILE ( pos_y <= psn(i) )
-                   IF ( pos_y >= nys * dy  .AND.                  &
-                        pos_y <  ( nyn + 1 ) * dy  )  THEN
+                   IF ( pos_y >= nys * dy  .AND.  pos_y <  ( nyn + 1 ) * dy  )  THEN
                       pos_x = psl(i)
                xloop: DO WHILE ( pos_x <= psr(i) )
-                         IF ( pos_x >= nxl * dx  .AND.            &
-                              pos_x <  ( nxr + 1) * dx )  THEN
+                         IF ( pos_x >= nxl * dx  .AND.  pos_x <  ( nxr + 1) * dx )  THEN
                             DO  j = 1, particles_per_point
                                n = n + 1
@@ -1450,5 +1413,5 @@
 !
 !--                            In case of stretching the actual k index is found iteratively
-                               IF ( dz_stretch_level /= -9999999.9_wp  .OR.           &
+                               IF ( dz_stretch_level /= -9999999.9_wp  .OR.                        &
                                     dz_stretch_level_start(1) /= -9999999.9_wp )  THEN
                                   kp = MAX( MINLOC( ABS( tmp_particle%z - zu ), DIM = 1 ) - 1, 1 )
@@ -1457,6 +1420,6 @@
                                ENDIF
 !
-!--                            Determine surface level. Therefore, check for
-!--                            upward-facing wall on w-grid. 
+!--                            Determine surface level. Therefore, check for upward-facing wall on
+!--                            w-grid.
                                k_surf = topo_top_ind(jp,ip,3)
                                IF ( seed_follows_topography )  THEN
@@ -1465,20 +1428,18 @@
                                   kp = kp + k_surf
                                   tmp_particle%z = tmp_particle%z + zw(k_surf)
-!--                               Skip particle release if particle position is
-!--                               above model top, or within topography in case
-!--                               of overhanging structures.
-                                  IF ( kp > nzt  .OR.                          &
-                                 .NOT. BTEST( wall_flags_total_0(kp,jp,ip), 0 ) )  THEN
+!
+!--                               Skip particle release if particle position is above model top, or
+!--                               within topography in case of overhanging structures.
+                                  IF ( kp > nzt  .OR.                                              &
+                                       .NOT. BTEST( wall_flags_total_0(kp,jp,ip), 0 ) )  THEN
                                      pos_x = pos_x + pdx(i)
                                      CYCLE xloop
                                   ENDIF
 !
-!--                            Skip particle release if particle position is
-!--                            below surface, or within topography in case
-!--                            of overhanging structures.
-                               ELSEIF ( .NOT. seed_follows_topography .AND.    &
-                                         tmp_particle%z <= zw(k_surf)  .OR.    &
-                                        .NOT. BTEST( wall_flags_total_0(kp,jp,ip), 0 ) )&
-                               THEN
+!--                            Skip particle release if particle position is below surface, or
+!--                            within topography in case of overhanging structures.
+                               ELSEIF ( .NOT. seed_follows_topography .AND.                        &
+                                         tmp_particle%z <= zw(k_surf)  .OR.                        &
+                                        .NOT. BTEST( wall_flags_total_0(kp,jp,ip), 0 ) )  THEN
                                   pos_x = pos_x + pdx(i)
                                   CYCLE xloop
@@ -1494,5 +1455,6 @@
                                      write(6,*) 'xu ',ip,jp,kp,nxr,nyn,nzt
                                   ENDIF
-                                  grid_particles(kp,jp,ip)%particles(local_count(kp,jp,ip)) = tmp_particle
+                                  grid_particles(kp,jp,ip)%particles(local_count(kp,jp,ip)) =      &
+                                                                                        tmp_particle
                                ENDIF
                             ENDDO
@@ -1513,9 +1475,8 @@
              DO  jp = nys, nyn
                 DO  kp = nzb+1, nzt
-                   IF ( phase == PHASE_INIT )  THEN
+                   IF ( phase == phase_init )  THEN
                       IF ( local_count(kp,jp,ip) > 0 )  THEN
-                         alloc_size = MAX( INT( local_count(kp,jp,ip) *        &
-                            ( 1.0_wp + alloc_factor / 100.0_wp ) ),            &
-                            1 )
+                         alloc_size = MAX( INT( local_count(kp,jp,ip) *                            &
+                                                ( 1.0_wp + alloc_factor / 100.0_wp ) ), 1 )
                       ELSE
                          alloc_size = 1
@@ -1525,9 +1486,9 @@
                          grid_particles(kp,jp,ip)%particles(n) = zero_particle
                       ENDDO
-                   ELSEIF ( phase == PHASE_RELEASE )  THEN
+                   ELSEIF ( phase == phase_release )  THEN
                       IF ( local_count(kp,jp,ip) > 0 )  THEN
                          new_size   = local_count(kp,jp,ip) + prt_count(kp,jp,ip)
-                         alloc_size = MAX( INT( new_size * ( 1.0_wp +          &
-                            alloc_factor / 100.0_wp ) ), 1 )
+                         alloc_size = MAX( INT( new_size * ( 1.0_wp +                              &
+                                                alloc_factor / 100.0_wp ) ), 1 )
                          IF( alloc_size > SIZE( grid_particles(kp,jp,ip)%particles) )  THEN
                             CALL realloc_particles_array( ip, jp, kp, alloc_size )
@@ -1555,10 +1516,9 @@
              DO  n = local_start(kp,jp,ip), number_of_particles  !only new particles
 
-                particles(n)%id = 10000_idp**3 * grid_particles(kp,jp,ip)%id_counter + &
+                particles(n)%id = 10000_idp**3 * grid_particles(kp,jp,ip)%id_counter +             &
                                   10000_idp**2 * kp + 10000_idp * jp + ip
 !
 !--             Count the number of particles that have been released before
-                grid_particles(kp,jp,ip)%id_counter =                          &
-                                         grid_particles(kp,jp,ip)%id_counter + 1
+                grid_particles(kp,jp,ip)%id_counter = grid_particles(kp,jp,ip)%id_counter + 1
 
              ENDDO
@@ -1585,41 +1545,37 @@
                 particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
 !
-!--             Move only new particles. Moreover, limit random fluctuation
-!--             in order to prevent that particles move more than one grid box,
-!--             which would lead to problems concerning particle exchange
-!--             between processors in case pdx/pdy are larger than dx/dy,
+!--             Move only new particles. Moreover, limit random fluctuation in order to prevent that
+!--             particles move more than one grid box, which would lead to problems concerning
+!--             particle exchange between processors in case pdx/pdy are larger than dx/dy,
 !--             respectively.
                 DO  n = local_start(kp,jp,ip), number_of_particles
                    IF ( psl(particles(n)%group) /= psr(particles(n)%group) )  THEN
                       CALL random_number_parallel( random_dummy )
-                      rand_contr = ( random_dummy - 0.5_wp ) *                 &
-                                     pdx(particles(n)%group)
-                      particles(n)%x = particles(n)%x +                        &
-                              MERGE( rand_contr, SIGN( dx, rand_contr ),       &
-                                     ABS( rand_contr ) < dx                    &
-                                   )
+                      rand_contr = ( random_dummy - 0.5_wp ) * pdx(particles(n)%group)
+                      particles(n)%x = particles(n)%x +                                            &
+                                       MERGE( rand_contr, SIGN( dx, rand_contr ),                  &
+                                              ABS( rand_contr ) < dx                               &
+                                            )
                    ENDIF
                    IF ( pss(particles(n)%group) /= psn(particles(n)%group) )  THEN
                       CALL random_number_parallel( random_dummy )
-                      rand_contr = ( random_dummy - 0.5_wp ) *                 &
-                                     pdy(particles(n)%group)
-                      particles(n)%y = particles(n)%y +                        &
-                              MERGE( rand_contr, SIGN( dy, rand_contr ),       &
-                                     ABS( rand_contr ) < dy                    &
-                                   )
+                      rand_contr = ( random_dummy - 0.5_wp ) * pdy(particles(n)%group)
+                      particles(n)%y = particles(n)%y +                                            &
+                                       MERGE( rand_contr, SIGN( dy, rand_contr ),                  &
+                                              ABS( rand_contr ) < dy                               &
+                                            )
                    ENDIF
                    IF ( psb(particles(n)%group) /= pst(particles(n)%group) )  THEN
                       CALL random_number_parallel( random_dummy )
-                      rand_contr = ( random_dummy - 0.5_wp ) *                 &
-                                     pdz(particles(n)%group)
-                      particles(n)%z = particles(n)%z +                        &
-                              MERGE( rand_contr, SIGN( dzw(kp), rand_contr ),  &
-                                     ABS( rand_contr ) < dzw(kp)               &
-                                   )
+                      rand_contr = ( random_dummy - 0.5_wp ) * pdz(particles(n)%group)
+                      particles(n)%z = particles(n)%z +                                            &
+                                       MERGE( rand_contr, SIGN( dzw(kp), rand_contr ),             &
+                                              ABS( rand_contr ) < dzw(kp)                          &
+                                            )
                    ENDIF
                 ENDDO
 !
-!--             Identify particles located outside the model domain and reflect
-!--             or absorb them if necessary.
+!--             Identify particles located outside the model domain and reflect or absorb them if
+!--             necessary.
                 CALL lpm_boundary_conds( 'bottom/top', i, j, k )
 !
@@ -1627,6 +1583,5 @@
 !--             the particle speed is still zero at this point, wall
 !--             reflection boundary conditions will not work in this case.
-                particles =>                                                   &
-                       grid_particles(kp,jp,ip)%particles(1:number_of_particles)
+                particles =>  grid_particles(kp,jp,ip)%particles(1:number_of_particles)
                 DO  n = local_start(kp,jp,ip), number_of_particles
                    i = particles(n)%x * ddx
@@ -1660,8 +1615,7 @@
     ENDIF
 !
-!-- In case of random_start_position, delete particles identified by
-!-- lpm_exchange_horiz and lpm_boundary_conds. Then sort particles into blocks,
-!-- which is needed for a fast interpolation of the LES fields on the particle
-!-- position.
+!-- In case of random_start_position, delete particles identified by lpm_exchange_horiz and
+!-- lpm_boundary_conds. Then sort particles into blocks, which is needed for a fast interpolation of
+!-- the LES fields on the particle position.
     CALL lpm_sort_and_delete
 !
@@ -1670,6 +1624,5 @@
        DO  jp = nys, nyn
           DO  kp = nzb+1, nzt
-             number_of_particles         = number_of_particles                 &
-                                           + prt_count(kp,jp,ip)
+             number_of_particles         = number_of_particles + prt_count(kp,jp,ip)
           ENDDO
        ENDDO
@@ -1679,6 +1632,6 @@
 #if defined( __parallel )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, &
-    MPI_INTEGER, MPI_SUM, comm2d, ierr )
+    CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, MPI_INTEGER, MPI_SUM,   &
+                        comm2d, ierr )
 #else
     total_number_of_particles = number_of_particles
@@ -1688,13 +1641,19 @@
 
  END SUBROUTINE lpm_create_particle
- 
- 
-!------------------------------------------------------------------------------!
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> This routine initialize the particles as aerosols with physio-chemical 
-!> properties. 
-!------------------------------------------------------------------------------!   
+!> This routine initializes the particles as aerosols with physio-chemical properties.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_init_aerosols(local_start)
+
+    INTEGER(iwp) ::  ip             !<
+    INTEGER(iwp) ::  jp             !<
+    INTEGER(iwp) ::  kp             !<
+    INTEGER(iwp) ::  n              !<
+
+    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg), INTENT(IN) ::  local_start !<
 
     REAL(wp) ::  afactor            !< curvature effects
@@ -1703,36 +1662,30 @@
     REAL(wp) ::  e_a                !< vapor pressure
     REAL(wp) ::  e_s                !< saturation vapor pressure
+    REAL(wp) ::  rmax = 10.0e-6_wp  !< maximum aerosol radius
     REAL(wp) ::  rmin = 0.005e-6_wp !< minimum aerosol radius
-    REAL(wp) ::  rmax = 10.0e-6_wp  !< maximum aerosol radius
+    REAL(wp) ::  r_l                !< left radius of bin
     REAL(wp) ::  r_mid              !< mean radius of bin
-    REAL(wp) ::  r_l                !< left radius of bin
     REAL(wp) ::  r_r                !< right radius of bin
     REAL(wp) ::  sigma              !< surface tension
     REAL(wp) ::  t_int              !< temperature
 
-    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg), INTENT(IN) ::  local_start !<
-
-    INTEGER(iwp) ::  n              !<
-    INTEGER(iwp) ::  ip             !<
-    INTEGER(iwp) ::  jp             !<
-    INTEGER(iwp) ::  kp             !<
 
 !
 !-- Set constants for different aerosol species
     IF ( TRIM( aero_species ) == 'nacl' )  THEN
-       molecular_weight_of_solute = 0.05844_wp 
+       molecular_weight_of_solute = 0.05844_wp
        rho_s                      = 2165.0_wp
        vanthoff                   = 2.0_wp
     ELSEIF ( TRIM( aero_species ) == 'c3h4o4' )  THEN
-       molecular_weight_of_solute = 0.10406_wp 
+       molecular_weight_of_solute = 0.10406_wp
        rho_s                      = 1600.0_wp
        vanthoff                   = 1.37_wp
     ELSEIF ( TRIM( aero_species ) == 'nh4o3' )  THEN
-       molecular_weight_of_solute = 0.08004_wp 
+       molecular_weight_of_solute = 0.08004_wp
        rho_s                      = 1720.0_wp
        vanthoff                   = 2.31_wp
     ELSE
-       WRITE( message_string, * ) 'unknown aerosol species ',   &
-                                'aero_species = "', TRIM( aero_species ), '"'
+       WRITE( message_string, * ) 'unknown aerosol species ',                                      &
+                                  'aero_species = "', TRIM( aero_species ), '"'
        CALL message( 'lpm_init', 'PA0470', 1, 2, 0, 6, 0 )
     ENDIF
@@ -1771,6 +1724,6 @@
        CONTINUE
     ELSE
-       WRITE( message_string, * ) 'unknown aerosol type ',   &
-                                'aero_type = "', TRIM( aero_type ), '"'
+       WRITE( message_string, * ) 'unknown aerosol type ',                                         &
+                                  'aero_type = "', TRIM( aero_type ), '"'
        CALL message( 'lpm_init', 'PA0459', 1, 2, 0, 6, 0 )
     ENDIF
@@ -1787,9 +1740,9 @@
              particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
 
-             dlogr   = ( LOG10(rmax) - LOG10(rmin) ) / ( number_of_particles - local_start(kp,jp,ip) + 1 )
-!
-!--          Initialize the aerosols with a predefined spectral distribution
-!--          of the dry radius (logarithmically increasing bins) and a varying
-!--          weighting factor
+             dlogr   = ( LOG10( rmax ) - LOG10( rmin ) ) /                                         &
+                       ( number_of_particles - local_start(kp,jp,ip) + 1 )
+!
+!--          Initialize the aerosols with a predefined spectral distribution of the dry radius
+!--          (logarithmically increasing bins) and a varying weighting factor.
              DO  n = local_start(kp,jp,ip), number_of_particles  !only new particles
 
@@ -1799,25 +1752,26 @@
 
                 particles(n)%aux1          = r_mid
-                particles(n)%weight_factor =                                           &
-                   ( na(1) / ( SQRT( 2.0_wp * pi ) * log_sigma(1) ) *                     &
-                     EXP( - LOG10( r_mid / rm(1) )**2 / ( 2.0_wp * log_sigma(1)**2 ) ) +  &
-                     na(2) / ( SQRT( 2.0_wp * pi ) * log_sigma(2) ) *                     &
-                     EXP( - LOG10( r_mid / rm(2) )**2 / ( 2.0_wp * log_sigma(2)**2 ) ) +  &
-                     na(3) / ( SQRT( 2.0_wp * pi ) * log_sigma(3) ) *                     &
-                     EXP( - LOG10( r_mid / rm(3) )**2 / ( 2.0_wp * log_sigma(3)**2 ) )    &
-                   ) * ( LOG10(r_r) - LOG10(r_l) ) * ( dx * dy * dzw(kp) )
-
-!
-!--             Multiply weight_factor with the namelist parameter aero_weight
-!--             to increase or decrease the number of simulated aerosols
+                particles(n)%weight_factor =                                                       &
+                   ( na(1) / ( SQRT( 2.0_wp * pi ) * log_sigma(1) ) *                              &
+                     EXP( - LOG10( r_mid / rm(1) )**2 / ( 2.0_wp * log_sigma(1)**2 ) ) +           &
+                     na(2) / ( SQRT( 2.0_wp * pi ) * log_sigma(2) ) *                              &
+                     EXP( - LOG10( r_mid / rm(2) )**2 / ( 2.0_wp * log_sigma(2)**2 ) ) +           &
+                     na(3) / ( SQRT( 2.0_wp * pi ) * log_sigma(3) ) *                              &
+                     EXP( - LOG10( r_mid / rm(3) )**2 / ( 2.0_wp * log_sigma(3)**2 ) )             &
+                   ) * ( LOG10( r_r ) - LOG10( r_l ) ) * ( dx * dy * dzw(kp) )
+
+!
+!--             Multiply weight_factor with the namelist parameter aero_weight to increase or
+!--             decrease the number of simulated aerosols
                 particles(n)%weight_factor = particles(n)%weight_factor * aero_weight
 !
 !--             Create random numver with parallel number generator
                 CALL random_number_parallel( random_dummy )
-                IF ( particles(n)%weight_factor - FLOOR(particles(n)%weight_factor,KIND=wp) &
+                IF ( particles(n)%weight_factor - FLOOR( particles(n)%weight_factor, KIND=wp )     &
                      > random_dummy )  THEN
-                   particles(n)%weight_factor = FLOOR(particles(n)%weight_factor,KIND=wp) + 1.0_wp
+                   particles(n)%weight_factor = FLOOR( particles(n)%weight_factor, KIND=wp )       &
+                                                + 1.0_wp
                 ELSE
-                   particles(n)%weight_factor = FLOOR(particles(n)%weight_factor,KIND=wp)
+                   particles(n)%weight_factor = FLOOR( particles(n)%weight_factor, KIND=wp )
                 ENDIF
 !
@@ -1827,8 +1781,7 @@
              ENDDO
 !
-!--          Set particle radius to equilibrium radius based on the environmental
-!--          supersaturation (Khvorostyanov and Curry, 2007, JGR). This avoids
-!--          the sometimes lengthy growth toward their equilibrium radius within
-!--          the simulation.
+!--          Set particle radius to equilibrium radius based on the environmental supersaturation
+!--          (Khvorostyanov and Curry, 2007, JGR). This avoids the sometimes lengthy growth toward
+!--          their equilibrium radius within the simulation.
              t_int  = pt(kp,jp,ip) * exner(kp)
 
@@ -1839,9 +1792,9 @@
              afactor = 2.0_wp * sigma / ( rho_l * r_v * t_int )
 
-             bfactor = vanthoff * molecular_weight_of_water *    &
+             bfactor = vanthoff * molecular_weight_of_water *                                      &
                        rho_s / ( molecular_weight_of_solute * rho_l )
 !
-!--          The formula is only valid for subsaturated environments. For
-!--          supersaturations higher than -5 %, the supersaturation is set to -5%.
+!--          The formula is only valid for subsaturated environments. For supersaturations higher
+!--          than -5 %, the supersaturation is set to -5%.
              IF ( e_a / e_s >= 0.95_wp )  e_a = 0.95_wp * e_s
 
@@ -1850,10 +1803,10 @@
 !--             For details on this equation, see Eq. (14) of Khvorostyanov and
 !--             Curry (2007, JGR)
-                particles(n)%radius = bfactor**0.3333333_wp *                  &
-                   particles(n)%aux1 / ( 1.0_wp - e_a / e_s )**0.3333333_wp / &
-                   ( 1.0_wp + ( afactor / ( 3.0_wp * bfactor**0.3333333_wp *   &
-                     particles(n)%aux1 ) ) /                                  &
-                     ( 1.0_wp - e_a / e_s )**0.6666666_wp                      &
-                   )
+                particles(n)%radius = bfactor**0.3333333_wp *                                      &
+                                      particles(n)%aux1 / ( 1.0_wp - e_a / e_s )**0.3333333_wp /   &
+                                      ( 1.0_wp + ( afactor / ( 3.0_wp * bfactor**0.3333333_wp *    &
+                                        particles(n)%aux1 ) ) /                                    &
+                                       ( 1.0_wp - e_a / e_s )**0.6666666_wp                        &
+                                      )
 
              ENDDO
@@ -1869,18 +1822,17 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Calculates quantities required for considering the SGS velocity fluctuations
-!> in the particle transport by a stochastic approach. The respective
-!> quantities are: SGS-TKE gradients and horizontally averaged profiles of the
-!> SGS TKE and the resolved-scale velocity variances. 
-!------------------------------------------------------------------------------!
+!> Calculates quantities required for considering the SGS velocity fluctuations in the particle
+!> transport by a stochastic approach. The respective quantities are: SGS-TKE gradients and
+!> horizontally averaged profiles of the SGS TKE and the resolved-scale velocity variances.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_init_sgs_tke
 
-    USE exchange_horiz_mod,                                                    &
+    USE exchange_horiz_mod,                                                                        &
         ONLY:  exchange_horiz
 
-    USE statistics,                                                            &
+    USE statistics,                                                                                &
         ONLY:  flow_statistics_called, hom, sums, sums_l
 
@@ -1888,5 +1840,5 @@
     INTEGER(iwp) ::  j      !< index variable along y
     INTEGER(iwp) ::  k      !< index variable along z
-    INTEGER(iwp) ::  m      !< running index for the surface elements 
+    INTEGER(iwp) ::  m      !< running index for the surface elements
 
     REAL(wp) ::  flag1      !< flag to mask topography
@@ -1898,22 +1850,20 @@
           DO  k = nzb, nzt+1
 
-             IF ( .NOT. BTEST( wall_flags_total_0(k,j,i-1), 0 )  .AND.         &
-                        BTEST( wall_flags_total_0(k,j,i), 0   )  .AND.         &
-                        BTEST( wall_flags_total_0(k,j,i+1), 0 ) )              &
+             IF ( .NOT. BTEST( wall_flags_total_0(k,j,i-1), 0 )  .AND.                             &
+                        BTEST( wall_flags_total_0(k,j,i), 0   )  .AND.                             &
+                        BTEST( wall_flags_total_0(k,j,i+1), 0 ) )                                  &
              THEN
-                de_dx(k,j,i) = 2.0_wp * sgs_wf_part *                          &
-                               ( e(k,j,i+1) - e(k,j,i) ) * ddx
-             ELSEIF ( BTEST( wall_flags_total_0(k,j,i-1), 0 )  .AND.           &
-                      BTEST( wall_flags_total_0(k,j,i), 0   )  .AND.           &
-                .NOT. BTEST( wall_flags_total_0(k,j,i+1), 0 ) )                &
+                de_dx(k,j,i) = 2.0_wp * sgs_wf_part * ( e(k,j,i+1) - e(k,j,i) ) * ddx
+             ELSEIF ( BTEST( wall_flags_total_0(k,j,i-1), 0 )  .AND.                               &
+                      BTEST( wall_flags_total_0(k,j,i), 0   )  .AND.                               &
+                .NOT. BTEST( wall_flags_total_0(k,j,i+1), 0 ) )                                    &
              THEN
-                de_dx(k,j,i) = 2.0_wp * sgs_wf_part *                          &
-                               ( e(k,j,i) - e(k,j,i-1) ) * ddx
-             ELSEIF ( .NOT. BTEST( wall_flags_total_0(k,j,i), 22   )  .AND.    &
-                      .NOT. BTEST( wall_flags_total_0(k,j,i+1), 22 ) )         &   
+                de_dx(k,j,i) = 2.0_wp * sgs_wf_part * ( e(k,j,i) - e(k,j,i-1) ) * ddx
+             ELSEIF ( .NOT. BTEST( wall_flags_total_0(k,j,i), 22   )  .AND.                        &
+                      .NOT. BTEST( wall_flags_total_0(k,j,i+1), 22 ) )                             &
              THEN
                 de_dx(k,j,i) = 0.0_wp
-             ELSEIF ( .NOT. BTEST( wall_flags_total_0(k,j,i-1), 22 )  .AND.    &
-                      .NOT. BTEST( wall_flags_total_0(k,j,i), 22   ) )         &
+             ELSEIF ( .NOT. BTEST( wall_flags_total_0(k,j,i-1), 22 )  .AND.                        &
+                      .NOT. BTEST( wall_flags_total_0(k,j,i), 22   ) )                             &
              THEN
                 de_dx(k,j,i) = 0.0_wp
@@ -1922,22 +1872,20 @@
              ENDIF
 
-             IF ( .NOT. BTEST( wall_flags_total_0(k,j-1,i), 0 )  .AND.         &
-                        BTEST( wall_flags_total_0(k,j,i), 0   )  .AND.         &
-                        BTEST( wall_flags_total_0(k,j+1,i), 0 ) )              &
+             IF ( .NOT. BTEST( wall_flags_total_0(k,j-1,i), 0 )  .AND.                             &
+                        BTEST( wall_flags_total_0(k,j,i), 0   )  .AND.                             &
+                        BTEST( wall_flags_total_0(k,j+1,i), 0 ) )                                  &
              THEN
-                de_dy(k,j,i) = 2.0_wp * sgs_wf_part *                          &
-                               ( e(k,j+1,i) - e(k,j,i) ) * ddy
-             ELSEIF ( BTEST( wall_flags_total_0(k,j-1,i), 0 )  .AND.           &
-                      BTEST( wall_flags_total_0(k,j,i), 0   )  .AND.           &
-                .NOT. BTEST( wall_flags_total_0(k,j+1,i), 0 ) )                &
+                de_dy(k,j,i) = 2.0_wp * sgs_wf_part * ( e(k,j+1,i) - e(k,j,i) ) * ddy
+             ELSEIF ( BTEST( wall_flags_total_0(k,j-1,i), 0 )  .AND.                               &
+                      BTEST( wall_flags_total_0(k,j,i), 0   )  .AND.                               &
+                .NOT. BTEST( wall_flags_total_0(k,j+1,i), 0 ) )                                    &
              THEN
-                de_dy(k,j,i) = 2.0_wp * sgs_wf_part *                          &
-                               ( e(k,j,i) - e(k,j-1,i) ) * ddy
-             ELSEIF ( .NOT. BTEST( wall_flags_total_0(k,j,i), 22   )  .AND.    &
-                      .NOT. BTEST( wall_flags_total_0(k,j+1,i), 22 ) )         &   
+                de_dy(k,j,i) = 2.0_wp * sgs_wf_part * ( e(k,j,i) - e(k,j-1,i) ) * ddy
+             ELSEIF ( .NOT. BTEST( wall_flags_total_0(k,j,i), 22   )  .AND.                        &
+                      .NOT. BTEST( wall_flags_total_0(k,j+1,i), 22 ) )                             &
              THEN
                 de_dy(k,j,i) = 0.0_wp
-             ELSEIF ( .NOT. BTEST( wall_flags_total_0(k,j-1,i), 22 )  .AND.    &
-                      .NOT. BTEST( wall_flags_total_0(k,j,i), 22   ) )         &
+             ELSEIF ( .NOT. BTEST( wall_flags_total_0(k,j-1,i), 22 )  .AND.                        &
+                      .NOT. BTEST( wall_flags_total_0(k,j,i), 22   ) )                             &
              THEN
                 de_dy(k,j,i) = 0.0_wp
@@ -1959,7 +1907,6 @@
              flag1 = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 0  ) )
 
-             de_dz(k,j,i) = 2.0_wp * sgs_wf_part *                             &
-                           ( e(k+1,j,i) - e(k-1,j,i) ) / ( zu(k+1) - zu(k-1) ) &
-                                                 * flag1 
+             de_dz(k,j,i) = 2.0_wp * sgs_wf_part *                                                 &
+                           ( e(k+1,j,i) - e(k-1,j,i) ) / ( zu(k+1) - zu(k-1) ) * flag1
           ENDDO
 !
@@ -1967,6 +1914,5 @@
           DO  m = bc_h(0)%start_index(j,i), bc_h(0)%end_index(j,i)
              k            = bc_h(0)%k(m)
-             de_dz(k,j,i) = 2.0_wp * sgs_wf_part *                             &
-                           ( e(k+1,j,i) - e(k,j,i)   ) / ( zu(k+1) - zu(k) )
+             de_dz(k,j,i) = 2.0_wp * sgs_wf_part * ( e(k+1,j,i) - e(k,j,i) ) / ( zu(k+1) - zu(k) )
           ENDDO
 !
@@ -1974,6 +1920,5 @@
           DO  m = bc_h(1)%start_index(j,i), bc_h(1)%end_index(j,i)
              k            = bc_h(1)%k(m)
-             de_dz(k,j,i) = 2.0_wp * sgs_wf_part *                             &
-                           ( e(k,j,i) - e(k-1,j,i)   ) / ( zu(k) - zu(k-1) )
+             de_dz(k,j,i) = 2.0_wp * sgs_wf_part * ( e(k,j,i) - e(k-1,j,i) ) / ( zu(k) - zu(k-1) )
           ENDDO
 
@@ -1990,38 +1935,35 @@
     CALL exchange_horiz( diss, nbgp  )
 !
-!-- Set boundary conditions at non-periodic boundaries. Note, at non-period
-!-- boundaries zero-gradient boundary conditions are set for the subgrid TKE.
-!-- Thus, TKE gradients normal to the respective lateral boundaries are zero, 
-!-- while tangetial TKE gradients then must be the same as within the prognostic
-!-- domain.  
+!-- Set boundary conditions at non-periodic boundaries. Note, at non-period boundaries zero-gradient
+!-- boundary conditions are set for the subgrid TKE.
+!-- Thus, TKE gradients normal to the respective lateral boundaries are zero,
+!-- while tangetial TKE gradients then must be the same as within the prognostic domain.
     IF ( bc_dirichlet_l )  THEN
        de_dx(:,:,-1) = 0.0_wp
-       de_dy(:,:,-1) = de_dy(:,:,0) 
+       de_dy(:,:,-1) = de_dy(:,:,0)
        de_dz(:,:,-1) = de_dz(:,:,0)
     ENDIF
     IF ( bc_dirichlet_r )  THEN
        de_dx(:,:,nxr+1) = 0.0_wp
-       de_dy(:,:,nxr+1) = de_dy(:,:,nxr) 
+       de_dy(:,:,nxr+1) = de_dy(:,:,nxr)
        de_dz(:,:,nxr+1) = de_dz(:,:,nxr)
     ENDIF
     IF ( bc_dirichlet_n )  THEN
        de_dx(:,nyn+1,:) = de_dx(:,nyn,:)
-       de_dy(:,nyn+1,:) = 0.0_wp 
+       de_dy(:,nyn+1,:) = 0.0_wp
        de_dz(:,nyn+1,:) = de_dz(:,nyn,:)
     ENDIF
     IF ( bc_dirichlet_s )  THEN
        de_dx(:,nys-1,:) = de_dx(:,nys,:)
-       de_dy(:,nys-1,:) = 0.0_wp 
+       de_dy(:,nys-1,:) = 0.0_wp
        de_dz(:,nys-1,:) = de_dz(:,nys,:)
-    ENDIF  
-!
-!-- Calculate the horizontally averaged profiles of SGS TKE and resolved
-!-- velocity variances (they may have been already calculated in routine
-!-- flow_statistics).
+    ENDIF
+!
+!-- Calculate the horizontally averaged profiles of SGS TKE and resolved velocity variances (they
+!-- may have been already calculated in routine flow_statistics).
     IF ( .NOT. flow_statistics_called )  THEN
 
 !
-!--    First calculate horizontally averaged profiles of the horizontal
-!--    velocities.
+!--    First calculate horizontally averaged profiles of the horizontal velocities.
        sums_l(:,1,0) = 0.0_wp
        sums_l(:,2,0) = 0.0_wp
@@ -2044,9 +1986,9 @@
 !--    Compute total sum from local sums
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( sums_l(nzb,1,0), sums(nzb,1), nzt+2-nzb, &
-                           MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( sums_l(nzb,1,0), sums(nzb,1), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,     &
+                           ierr )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( sums_l(nzb,2,0), sums(nzb,2), nzt+2-nzb, &
-                              MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( sums_l(nzb,2,0), sums(nzb,2), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,     &
+                           ierr )
 #else
        sums(:,1) = sums_l(:,1,0)
@@ -2055,12 +1997,11 @@
 
 !
-!--    Final values are obtained by division by the total number of grid
-!--    points used for the summation.
+!--    Final values are obtained by division by the total number of grid points used for the
+!--    summation.
        hom(:,1,1,0) = sums(:,1) / ngp_2dh_outer(:,0)   ! u
        hom(:,1,2,0) = sums(:,2) / ngp_2dh_outer(:,0)   ! v
 
 !
-!--    Now calculate the profiles of SGS TKE and the resolved-scale
-!--    velocity variances
+!--    Now calculate the profiles of SGS TKE and the resolved-scale velocity variances
        sums_l(:,8,0)  = 0.0_wp
        sums_l(:,30,0) = 0.0_wp
@@ -2086,15 +2027,15 @@
 !--    Compute total sum from local sums
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( sums_l(nzb,8,0), sums(nzb,8), nzt+2-nzb, &
-                           MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( sums_l(nzb,8,0), sums(nzb,8), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,     &
+                           ierr )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( sums_l(nzb,30,0), sums(nzb,30), nzt+2-nzb, &
-                           MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( sums_l(nzb,30,0), sums(nzb,30), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,   &
+                           ierr )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( sums_l(nzb,31,0), sums(nzb,31), nzt+2-nzb, &
-                           MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( sums_l(nzb,31,0), sums(nzb,31), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,   &
+                           ierr )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( sums_l(nzb,32,0), sums(nzb,32), nzt+2-nzb, &
-                           MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( sums_l(nzb,32,0), sums(nzb,32), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,   &
+                           ierr )
 
 #else
@@ -2106,9 +2047,9 @@
 
 !
-!--    Final values are obtained by division by the total number of grid
-!--    points used for the summation.
+!--    Final values are obtained by division by the total number of grid points used for the
+!--    summation.
        hom(:,1,8,0)  = sums(:,8)  / ngp_2dh_outer(:,0)   ! e
        hom(:,1,30,0) = sums(:,30) / ngp_2dh_outer(:,0)   ! u*2
-       hom(:,1,31,0) = sums(:,31) / ngp_2dh_outer(:,0)   ! v*2 
+       hom(:,1,31,0) = sums(:,31) / ngp_2dh_outer(:,0)   ! v*2
        hom(:,1,32,0) = sums(:,32) / ngp_2dh_outer(:,0)   ! w*2
 
@@ -2116,14 +2057,14 @@
 
  END SUBROUTINE lpm_init_sgs_tke
- 
- 
-!------------------------------------------------------------------------------!
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Sobroutine control lpm actions, i.e. all actions during one time step. 
-!------------------------------------------------------------------------------!  
+!> Sobroutine control lpm actions, i.e. all actions during one time step.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_actions( location )
 
-    USE exchange_horiz_mod,                                                    &
+    USE exchange_horiz_mod,                                                                        &
         ONLY:  exchange_horiz
 
@@ -2152,5 +2093,5 @@
 !--       The particle model is executed if particle advection start is reached and only at the end
 !--       of the intermediate time step loop.
-          IF ( time_since_reference_point >= particle_advection_start   &
+          IF ( time_since_reference_point >= particle_advection_start                              &
                .AND.  intermediate_timestep_count == intermediate_timestep_count_max )             &
           THEN
@@ -2158,7 +2099,7 @@
 !
 !--          Write particle data at current time on file.
-!--          This has to be done here, before particles are further processed,
-!--          because they may be deleted within this timestep (in case that
-!--          dt_write_particle_data = dt_prel = particle_maximum_age).
+!--          This has to be done here, before particles are further processed, because they may be
+!--          deleted within this timestep (in case that dt_write_particle_data = dt_prel =
+!--          particle_maximum_age).
              time_write_particle_data = time_write_particle_data + dt_3d
              IF ( time_write_particle_data >= dt_write_particle_data )  THEN
@@ -2166,20 +2107,17 @@
                 CALL lpm_data_output_particles
 !
-!--          The MOD function allows for changes in the output interval with restart
-!--          runs.
-                time_write_particle_data = MOD( time_write_particle_data, &
+!--          The MOD function allows for changes in the output interval with restart runs.
+                time_write_particle_data = MOD( time_write_particle_data,                          &
                                            MAX( dt_write_particle_data, dt_3d ) )
              ENDIF
 
 !
-!--          Initialize arrays for marking those particles to be deleted after the
-!--          (sub-) timestep
+!--          Initialize arrays for marking those particles to be deleted after the (sub-) timestep.
              deleted_particles = 0
 
 !
-!--          Initialize variables used for accumulating the number of particles
-!--          xchanged between the subdomains during all sub-timesteps (if sgs
-!--          velocities are included). These data are output further below on the
-!--          particle statistics file.
+!--          Initialize variables used for accumulating the number of particles exchanged between
+!--          the subdomains during all sub-timesteps (if sgs velocities are included). These data
+!--          are output further below on the particle statistics file.
              trlp_count_sum      = 0
              trlp_count_recv_sum = 0
@@ -2195,18 +2133,17 @@
              DO  m = 1, number_of_particle_groups
                 IF ( particle_groups(m)%density_ratio /= 0.0_wp )  THEN
-                   particle_groups(m)%exp_arg  =                                        &
-                             4.5_wp * particle_groups(m)%density_ratio *                &
-                             molecular_viscosity / ( particle_groups(m)%radius )**2
-
-                   particle_groups(m)%exp_term = EXP( -particle_groups(m)%exp_arg *     &
-                             dt_3d )
+                   particle_groups(m)%exp_arg  = 4.5_wp * particle_groups(m)%density_ratio *       &
+                                                 molecular_viscosity /                             &
+                                                 ( particle_groups(m)%radius )**2
+
+                   particle_groups(m)%exp_term = EXP( -particle_groups(m)%exp_arg * dt_3d )
                 ENDIF
              ENDDO
 !
 !--          If necessary, release new set of particles
-             IF ( ( simulated_time - last_particle_release_time ) >= dt_prel  .AND.     &
+             IF ( ( simulated_time - last_particle_release_time ) >= dt_prel  .AND.                &
                     end_time_prel > simulated_time )  THEN
                 DO WHILE ( ( simulated_time - last_particle_release_time ) >= dt_prel )
-                   CALL lpm_create_particle( PHASE_RELEASE )
+                   CALL lpm_create_particle( phase_release )
                    last_particle_release_time = last_particle_release_time + dt_prel
                 ENDDO
@@ -2224,12 +2161,11 @@
 !
 !--          Timestep loop for particle advection.
-!--          This loop has to be repeated until the advection time of every particle
-!--          (within the total domain!) has reached the LES timestep (dt_3d).
-!--          In case of including the SGS velocities, the particle timestep may be
-!--          smaller than the LES timestep (because of the Lagrangian timescale
-!--          restriction) and particles may require to undergo several particle
-!--          timesteps, before the LES timestep is reached. Because the number of these
-!--          particle timesteps to be carried out is unknown at first, these steps are
-!--          carried out in the following infinite loop with exit condition.
+!--          This loop has to be repeated until the advection time of every particle (within the
+!--          total domain!) has reached the LES timestep (dt_3d).
+!--          In case of including the SGS velocities, the particle timestep may be smaller than the
+!--          LES timestep (because of the Lagrangian timescale restriction) and particles may
+!--          require to undergo several particle timesteps, before the LES timestep is reached.
+!--          Because the number of these particle timesteps to be carried out is unknown at first,
+!--          these steps are carried out in the following infinite loop with exit condition.
              DO
                 CALL cpu_log( log_point_s(44), 'lpm_advec', 'start' )
@@ -2237,19 +2173,17 @@
 
 !
-!--             If particle advection includes SGS velocity components, calculate the
-!--             required SGS quantities (i.e. gradients of the TKE, as well as
-!--             horizontally averaged profiles of the SGS TKE and the resolved-scale
-!--             velocity variances)
+!--             If particle advection includes SGS velocity components, calculate the required SGS
+!--             quantities (i.e. gradients of the TKE, as well as horizontally averaged profiles of
+!--             the SGS TKE and the resolved-scale velocity variances)
                 IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
                    CALL lpm_init_sgs_tke
                 ENDIF
 !
-!--             In case SGS-particle speed is considered, particles may carry out
-!--             several particle timesteps. In order to prevent unnecessary
-!--             treatment of particles that already reached the final time level,
-!--             particles are sorted into contiguous blocks of finished and
-!--             not-finished particles, in addition to their already sorting
+!--             In case SGS-particle speed is considered, particles may carry out several particle
+!--             timesteps. In order to prevent unnecessary treatment of particles that already
+!--             reached the final time level, particles are sorted into contiguous blocks of
+!--             finished and not-finished particles, in addition to their already sorting
 !--             according to their sub-boxes.
-                IF ( .NOT. first_loop_stride  .AND.  use_sgs_for_particles )            &
+                IF ( .NOT. first_loop_stride  .AND.  use_sgs_for_particles )                       &
                    CALL lpm_sort_timeloop_done
                 DO  i = nxl, nxr
@@ -2276,12 +2210,11 @@
                          particles(1:number_of_particles)%particle_mask = .TRUE.
 !
-!--                      Initialize the variable storing the total time that a particle
-!--                      has advanced within the timestep procedure
+!--                      Initialize the variable storing the total time that a particle has advanced
+!--                      within the timestep procedure.
                          IF ( first_loop_stride )  THEN
                             particles(1:number_of_particles)%dt_sum = 0.0_wp
                          ENDIF
 !
-!--                      Particle (droplet) growth by condensation/evaporation and
-!--                      collision
+!--                      Particle (droplet) growth by condensation/evaporation and collision
                          IF ( cloud_droplets  .AND.  first_loop_stride)  THEN
 !
@@ -2296,8 +2229,7 @@
                          ENDIF
 !
-!--                      Initialize the switch used for the loop exit condition checked
-!--                      at the end of this loop. If at least one particle has failed to
-!--                      reach the LES timestep, this switch will be set false in
-!--                      lpm_advec.
+!--                      Initialize the switch used for the loop exit condition checked at the end
+!--                      of this loop. If at least one particle has failed to reach the LES
+!--                      timestep, this switch will be set false in lpm_advec.
                          dt_3d_reached_l = .TRUE.
 
@@ -2306,26 +2238,24 @@
                          CALL lpm_advec( i, j, k )
 !
-!--                      Particle reflection from walls. Only applied if the particles
-!--                      are in the vertical range of the topography. (Here, some
-!--                      optimization is still possible.)
+!--                      Particle reflection from walls. Only applied if the particles are in the
+!--                      vertical range of the topography. (Here, some optimization is still
+!--                      possible.)
                          IF ( topography /= 'flat'  .AND.  k < nzb_max + 2 )  THEN
                             CALL  lpm_boundary_conds( 'walls', i, j, k )
                          ENDIF
 !
-!--                      User-defined actions after the calculation of the new particle
-!--                      position
+!--                      User-defined actions after the calculation of the new particle position
                          CALL user_lpm_advec( i, j, k )
 !
-!--                      Apply boundary conditions to those particles that have crossed
-!--                      the top or bottom boundary and delete those particles, which are
-!--                      older than allowed
+!--                      Apply boundary conditions to those particles that have crossed the top or
+!--                      bottom boundary and delete those particles, which are older than allowed
                          CALL lpm_boundary_conds( 'bottom/top', i, j, k )
 !
-!---                     If not all particles of the actual grid cell have reached the
-!--                      LES timestep, this cell has to do another loop iteration. Due to
-!--                      the fact that particles can move into neighboring grid cells,
-!--                      these neighbor cells also have to perform another loop iteration.
-!--                      Please note, this realization does not work properly if
-!--                      particles move into another subdomain.
+!---                     If not all particles of the actual grid cell have reached the LES timestep,
+!--                      this cell has to do another loop iteration. Due to the fact that particles
+!--                      can move into neighboring grid cells, these neighbor cells also have to
+!--                      perform another loop iteration.
+!--                      Please note, this realization does not work properly if particles move into
+!--                      another subdomain.
                          IF ( .NOT. dt_3d_reached_l )  THEN
                             ks = MAX(nzb+1,k-1)
@@ -2350,10 +2280,10 @@
                 dt_3d_reached_l = ALL(grid_particles(:,:,:)%time_loop_done)
 !
-!--             Find out, if all particles on every PE have completed the LES timestep
-!--             and set the switch corespondingly
+!--             Find out, if all particles on every PE have completed the LES timestep and set the
+!--             switch corespondingly
 #if defined( __parallel )
                 IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-                CALL MPI_ALLREDUCE( dt_3d_reached_l, dt_3d_reached, 1, MPI_LOGICAL, &
-                                    MPI_LAND, comm2d, ierr )
+                CALL MPI_ALLREDUCE( dt_3d_reached_l, dt_3d_reached, 1, MPI_LOGICAL, MPI_LAND,      &
+                                    comm2d, ierr )
 #else
                 dt_3d_reached = dt_3d_reached_l
@@ -2382,10 +2312,10 @@
                 IF ( .NOT. dt_3d_reached  .OR.  .NOT. nested_run )   THEN
 !
-!--                Pack particles (eliminate those marked for deletion),
-!--                determine new number of particles
+!--                Pack particles (eliminate those marked for deletion), determine new number of
+!--                particles
                    CALL lpm_sort_and_delete
 
-!--                Initialize variables for the next (sub-) timestep, i.e., for marking
-!--                those particles to be deleted after the timestep
+!--                Initialize variables for the next (sub-) timestep, i.e., for marking those
+!--                particles to be deleted after the timestep
                    deleted_particles = 0
                 ENDIF
@@ -2398,5 +2328,5 @@
 #if defined( __parallel )
 !
-!--          in case of nested runs do the transfer of particles after every full model time step
+!--          In case of nested runs do the transfer of particles after every full model time step
              IF ( nested_run )   THEN
                 CALL particles_from_parent_to_child
@@ -2433,10 +2363,9 @@
 
 !
-!--          Write particle statistics (in particular the number of particles
-!--          exchanged between the subdomains) on file
+!--          Write particle statistics (in particular the number of particles exchanged between the
+!--          subdomains) on file
              IF ( write_particle_statistics )  CALL lpm_write_exchange_statistics
 !
-!--          Execute Interactions of condnesation and evaporation to humidity and
-!--          temperature field
+!--          Execute Interactions of condnesation and evaporation to humidity and temperature field
              IF ( cloud_droplets )  THEN
                 CALL lpm_interaction_droplets_ptq
@@ -2465,6 +2394,6 @@
        CASE ( 'after_integration' )
 !
-!--       Call at the end of timestep routine to save particle velocities fields
-!--       for the next timestep
+!--       Call at the end of timestep routine to save particle velocities fields for the next
+!--       timestep
           CALL lpm_swap_timelevel_for_particle_advection
 
@@ -2475,12 +2404,12 @@
 
  END SUBROUTINE lpm_actions
- 
+
 
 #if defined( __parallel )
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE particles_from_parent_to_child
 
@@ -2492,10 +2421,10 @@
  END SUBROUTINE particles_from_parent_to_child
 
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE particles_from_child_to_parent
 
@@ -2507,10 +2436,10 @@
  END SUBROUTINE particles_from_child_to_parent
 #endif
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> This routine write exchange statistics of the lpm in a ascii file. 
-!------------------------------------------------------------------------------!
+!> This routine write exchange statistics of the lpm in a ascii file.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_write_exchange_statistics
 
@@ -2526,6 +2455,5 @@
        DO  jp = nys, nyn
           DO  kp = nzb+1, nzt
-             number_of_particles = number_of_particles                         &
-                                     + prt_count(kp,jp,ip)
+             number_of_particles = number_of_particles + prt_count(kp,jp,ip)
           ENDDO
        ENDDO
@@ -2534,24 +2462,21 @@
     CALL check_open( 80 )
 #if defined( __parallel )
-    WRITE ( 80, 8000 )  current_timestep_number+1, simulated_time+dt_3d, &
-                        number_of_particles, pleft, trlp_count_sum,      &
-                        trlp_count_recv_sum, pright, trrp_count_sum,     &
-                        trrp_count_recv_sum, psouth, trsp_count_sum,     &
-                        trsp_count_recv_sum, pnorth, trnp_count_sum,     &
-                        trnp_count_recv_sum
+    WRITE ( 80, 8000 )  current_timestep_number+1, simulated_time+dt_3d, number_of_particles,      &
+                        pleft, trlp_count_sum, trlp_count_recv_sum, pright, trrp_count_sum,        &
+                        trrp_count_recv_sum, psouth, trsp_count_sum, trsp_count_recv_sum, pnorth,  &
+                        trnp_count_sum, trnp_count_recv_sum
 #else
-    WRITE ( 80, 8000 )  current_timestep_number+1, simulated_time+dt_3d, &
-                        number_of_particles
+    WRITE ( 80, 8000 )  current_timestep_number+1, simulated_time+dt_3d, number_of_particles
 #endif
     CALL close_file( 80 )
 
     IF ( number_of_particles > 0 )  THEN
-        WRITE(9,*) 'number_of_particles ', number_of_particles,                &
-                    current_timestep_number + 1, simulated_time + dt_3d
+        WRITE(9,*) 'number_of_particles ', number_of_particles, current_timestep_number + 1,       &
+                   simulated_time + dt_3d
     ENDIF
 
 #if defined( __parallel )
-    CALL MPI_ALLREDUCE( number_of_particles, tot_number_of_particles, 1,       &
-                        MPI_INTEGER, MPI_SUM, comm2d, ierr )
+    CALL MPI_ALLREDUCE( number_of_particles, tot_number_of_particles, 1, MPI_INTEGER, MPI_SUM,     &
+                        comm2d, ierr )
 #else
     tot_number_of_particles = number_of_particles
@@ -2560,6 +2485,5 @@
 #if defined( __parallel )
     IF ( nested_run )  THEN
-       CALL pmcp_g_print_number_of_particles( simulated_time+dt_3d,            &
-                                              tot_number_of_particles)
+       CALL pmcp_g_print_number_of_particles( simulated_time + dt_3d, tot_number_of_particles)
     ENDIF
 #endif
@@ -2571,13 +2495,13 @@
 
  END SUBROUTINE lpm_write_exchange_statistics
- 
-
-!------------------------------------------------------------------------------! 
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Write particle data in FORTRAN binary and/or netCDF format 
-!------------------------------------------------------------------------------!
+!> Write particle data in FORTRAN binary and/or netCDF format
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_data_output_particles
- 
+
     INTEGER(iwp) ::  ip !<
     INTEGER(iwp) ::  jp !<
@@ -2587,6 +2511,6 @@
 
 !
-!-- Attention: change version number for unit 85 (in routine check_open)
-!--            whenever the output format for this unit is changed!
+!-- Attention: change version number for unit 85 (in routine check_open) whenever the output format
+!--            for this unit is changed!
     CALL check_open( 85 )
 
@@ -2612,14 +2536,14 @@
 ! !-- Output in netCDF format
 !     CALL check_open( 108 )
-! 
+!
 ! !
 ! !-- Update the NetCDF time axis
 !     prt_time_count = prt_time_count + 1
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_time_prt, &
 !                             (/ simulated_time /),        &
 !                             start = (/ prt_time_count /), count = (/ 1 /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 1 )
-! 
+!
 ! !
 ! !-- Output the real number of particles used
@@ -2628,5 +2552,5 @@
 !                             start = (/ prt_time_count /), count = (/ 1 /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 2 )
-! 
+!
 ! !
 ! !-- Output all particle attributes
@@ -2635,45 +2559,45 @@
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 3 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(2), particles%user,     &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 4 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(3), particles%origin_x, &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 5 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(4), particles%origin_y, &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 6 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(5), particles%origin_z, &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 7 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(6), particles%radius,   &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 8 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(7), particles%speed_x,  &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 9 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(8), particles%speed_y,  &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 10 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(9), particles%speed_z,  &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 11 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt,id_var_prt(10),                     &
 !                             particles%weight_factor,                       &
@@ -2681,30 +2605,30 @@
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 12 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(11), particles%x,       &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 13 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(12), particles%y,       &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 14 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(13), particles%z,       &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 15 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(14), particles%class,   &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 16 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(15), particles%group,   &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 17 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(16),                    &
 !                             particles%id2,                                 &
@@ -2712,10 +2636,10 @@
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 18 )
-! 
+!
 !     nc_stat = NF90_PUT_VAR( id_set_prt, id_var_prt(17), particles%id1,     &
 !                             start = (/ 1, prt_time_count /),               &
 !                             count = (/ maximum_number_of_particles /) )
 !     CALL netcdf_handle_error( 'lpm_data_output_particles', 19 )
-! 
+!
 #endif
 
@@ -2723,12 +2647,12 @@
 
  END SUBROUTINE lpm_data_output_particles
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> This routine calculates and provide particle timeseries output.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_data_output_ptseries
- 
+
     INTEGER(iwp) ::  i    !<
     INTEGER(iwp) ::  inum !<
@@ -2752,6 +2676,5 @@
 !
 !--    Update the particle time series time axis
-       nc_stat = NF90_PUT_VAR( id_set_pts, id_var_time_pts,      &
-                               (/ time_since_reference_point /), &
+       nc_stat = NF90_PUT_VAR( id_set_pts, id_var_time_pts, (/ time_since_reference_point /),      &
                                start = (/ dopts_time_count /), count = (/ 1 /) )
        CALL netcdf_handle_error( 'data_output_ptseries', 391 )
@@ -2760,5 +2683,5 @@
     ENDIF
 
-    ALLOCATE( pts_value(0:number_of_particle_groups,dopts_num), &
+    ALLOCATE( pts_value(0:number_of_particle_groups,dopts_num),                                    &
               pts_value_l(0:number_of_particle_groups,dopts_num) )
 
@@ -2767,6 +2690,6 @@
 
 !
-!-- Calculate or collect the particle time series quantities for all particles
-!-- and seperately for each particle group (if there is more than one group)
+!-- Calculate or collect the particle time series quantities for all particles and seperately for
+!-- each particle group (if there is more than one group)
     DO  i = nxl, nxr
        DO  j = nys, nyn
@@ -2779,27 +2702,25 @@
                 IF ( particles(n)%particle_mask )  THEN  ! Restrict analysis to active particles
 
-                   pts_value_l(0,1)  = pts_value_l(0,1) + 1.0_wp  ! total # of particles
-                   pts_value_l(0,2)  = pts_value_l(0,2) +                      &
-                          ( particles(n)%x - particles(n)%origin_x )  ! mean x
-                   pts_value_l(0,3)  = pts_value_l(0,3) +                      &
-                          ( particles(n)%y - particles(n)%origin_y )  ! mean y
-                   pts_value_l(0,4)  = pts_value_l(0,4) +                      &
-                          ( particles(n)%z - particles(n)%origin_z )  ! mean z
-                   pts_value_l(0,5)  = pts_value_l(0,5) + particles(n)%z        ! mean z (absolute)
-                   pts_value_l(0,6)  = pts_value_l(0,6) + particles(n)%speed_x  ! mean u
-                   pts_value_l(0,7)  = pts_value_l(0,7) + particles(n)%speed_y  ! mean v
-                   pts_value_l(0,8)  = pts_value_l(0,8) + particles(n)%speed_z  ! mean w
-                   pts_value_l(0,9)  = pts_value_l(0,9)  + particles(n)%rvar1 ! mean sgsu
-                   pts_value_l(0,10) = pts_value_l(0,10) + particles(n)%rvar2 ! mean sgsv
-                   pts_value_l(0,11) = pts_value_l(0,11) + particles(n)%rvar3 ! mean sgsw
+                   pts_value_l(0,1)  = pts_value_l(0,1) + 1.0_wp                   ! total # of particles
+                   pts_value_l(0,2)  = pts_value_l(0,2) +                                          &
+                                       ( particles(n)%x - particles(n)%origin_x )  ! mean x
+                   pts_value_l(0,3)  = pts_value_l(0,3) +                                          &
+                                       ( particles(n)%y - particles(n)%origin_y )  ! mean y
+                   pts_value_l(0,4)  = pts_value_l(0,4) +                                          &
+                                       ( particles(n)%z - particles(n)%origin_z )  ! mean z
+                   pts_value_l(0,5)  = pts_value_l(0,5) + particles(n)%z           ! mean z (absolute)
+                   pts_value_l(0,6)  = pts_value_l(0,6) + particles(n)%speed_x     ! mean u
+                   pts_value_l(0,7)  = pts_value_l(0,7) + particles(n)%speed_y     ! mean v
+                   pts_value_l(0,8)  = pts_value_l(0,8) + particles(n)%speed_z     ! mean w
+                   pts_value_l(0,9)  = pts_value_l(0,9)  + particles(n)%rvar1      ! mean sgsu
+                   pts_value_l(0,10) = pts_value_l(0,10) + particles(n)%rvar2      ! mean sgsv
+                   pts_value_l(0,11) = pts_value_l(0,11) + particles(n)%rvar3      ! mean sgsw
                    IF ( particles(n)%speed_z > 0.0_wp )  THEN
-                      pts_value_l(0,12) = pts_value_l(0,12) + 1.0_wp  ! # of upward moving prts
-                      pts_value_l(0,13) = pts_value_l(0,13) +                  &
-                                              particles(n)%speed_z ! mean w upw.
+                      pts_value_l(0,12) = pts_value_l(0,12) + 1.0_wp                ! # of upward moving prts
+                      pts_value_l(0,13) = pts_value_l(0,13) +  particles(n)%speed_z ! mean w upw.
                    ELSE
-                      pts_value_l(0,14) = pts_value_l(0,14) +                  &
-                                              particles(n)%speed_z ! mean w down
+                      pts_value_l(0,14) = pts_value_l(0,14) + particles(n)%speed_z  ! mean w down
                    ENDIF
-                   pts_value_l(0,15) = pts_value_l(0,15) + particles(n)%radius ! mean rad
+                   pts_value_l(0,15) = pts_value_l(0,15) + particles(n)%radius       ! mean rad
                    pts_value_l(0,16) = MIN( pts_value_l(0,16), particles(n)%radius ) ! minrad
                    pts_value_l(0,17) = MAX( pts_value_l(0,17), particles(n)%radius ) ! maxrad
@@ -2812,10 +2733,10 @@
 
                       pts_value_l(jg,1)  = pts_value_l(jg,1) + 1.0_wp
-                      pts_value_l(jg,2)  = pts_value_l(jg,2) +                   &
-                           ( particles(n)%x - particles(n)%origin_x )
-                      pts_value_l(jg,3)  = pts_value_l(jg,3) +                   &
-                           ( particles(n)%y - particles(n)%origin_y )
-                      pts_value_l(jg,4)  = pts_value_l(jg,4) +                   &
-                           ( particles(n)%z - particles(n)%origin_z )
+                      pts_value_l(jg,2)  = pts_value_l(jg,2) +                                     &
+                                           ( particles(n)%x  - particles(n)%origin_x )
+                      pts_value_l(jg,3)  = pts_value_l(jg,3) +                                     &
+                                           ( particles(n)%y  - particles(n)%origin_y )
+                      pts_value_l(jg,4)  = pts_value_l(jg,4) +                                     &
+                                           ( particles(n)%z  - particles(n)%origin_z )
                       pts_value_l(jg,5)  = pts_value_l(jg,5) + particles(n)%z
                       pts_value_l(jg,6)  = pts_value_l(jg,6) + particles(n)%speed_x
@@ -2853,18 +2774,13 @@
 
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( pts_value_l(0,1), pts_value(0,1), 15*inum, MPI_REAL, &
-                        MPI_SUM, comm2d, ierr )
+    CALL MPI_ALLREDUCE( pts_value_l(0,1), pts_value(0,1), 15*inum, MPI_REAL, MPI_SUM, comm2d, ierr )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( pts_value_l(0,16), pts_value(0,16), inum, MPI_REAL, &
-                        MPI_MIN, comm2d, ierr )
+    CALL MPI_ALLREDUCE( pts_value_l(0,16), pts_value(0,16), inum, MPI_REAL, MPI_MIN, comm2d, ierr )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( pts_value_l(0,17), pts_value(0,17), inum, MPI_REAL, &
-                        MPI_MAX, comm2d, ierr )
+    CALL MPI_ALLREDUCE( pts_value_l(0,17), pts_value(0,17), inum, MPI_REAL, MPI_MAX, comm2d, ierr )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( pts_value_l(0,18), pts_value(0,18), inum, MPI_REAL, &
-                        MPI_MAX, comm2d, ierr )
+    CALL MPI_ALLREDUCE( pts_value_l(0,18), pts_value(0,18), inum, MPI_REAL, MPI_MAX, comm2d, ierr )
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( pts_value_l(0,19), pts_value(0,19), inum, MPI_REAL, &
-                        MPI_MIN, comm2d, ierr )
+    CALL MPI_ALLREDUCE( pts_value_l(0,19), pts_value(0,19), inum, MPI_REAL, MPI_MIN, comm2d, ierr )
 #else
     pts_value(:,1:19) = pts_value_l(:,1:19)
@@ -2872,6 +2788,6 @@
 
 !
-!-- Normalize the above calculated quantities (except min/max values) with the
-!-- total number of particles
+!-- Normalize the above calculated quantities (except min/max values) with the total number of
+!-- particles
     IF ( number_of_particle_groups > 1 )  THEN
        inum = number_of_particle_groups
@@ -2899,6 +2815,6 @@
 
 !
-!-- Calculate higher order moments of particle time series quantities,
-!-- seperately for each particle group (if there is more than one group)
+!-- Calculate higher order moments of particle time series quantities, seperately for each particle
+!-- group (if there is more than one group)
     DO  i = nxl, nxr
        DO  j = nys, nyn
@@ -2909,21 +2825,21 @@
              DO  n = 1, number_of_particles
 
-                pts_value_l(0,20) = pts_value_l(0,20) + ( particles(n)%x - &
-                                    particles(n)%origin_x - pts_value(0,2) )**2 ! x*2
-                pts_value_l(0,21) = pts_value_l(0,21) + ( particles(n)%y - &
-                                    particles(n)%origin_y - pts_value(0,3) )**2 ! y*2
-                pts_value_l(0,22) = pts_value_l(0,22) + ( particles(n)%z - &
-                                    particles(n)%origin_z - pts_value(0,4) )**2 ! z*2
-                pts_value_l(0,23) = pts_value_l(0,23) + ( particles(n)%speed_x - &
-                                                         pts_value(0,6) )**2   ! u*2
-                pts_value_l(0,24) = pts_value_l(0,24) + ( particles(n)%speed_y - &
-                                                          pts_value(0,7) )**2   ! v*2
-                pts_value_l(0,25) = pts_value_l(0,25) + ( particles(n)%speed_z - &
-                                                          pts_value(0,8) )**2   ! w*2
-                pts_value_l(0,26) = pts_value_l(0,26) + ( particles(n)%rvar1 - &
-                                                          pts_value(0,9) )**2   ! u"2
-                pts_value_l(0,27) = pts_value_l(0,27) + ( particles(n)%rvar2 - &
-                                                          pts_value(0,10) )**2  ! v"2
-                pts_value_l(0,28) = pts_value_l(0,28) + ( particles(n)%rvar3 - &
+                pts_value_l(0,20) = pts_value_l(0,20) + ( particles(n)%x -                         &
+                                       particles(n)%origin_x - pts_value(0,2) )**2 ! x*2
+                pts_value_l(0,21) = pts_value_l(0,21) + ( particles(n)%y -                         &
+                                       particles(n)%origin_y - pts_value(0,3) )**2 ! y*2
+                pts_value_l(0,22) = pts_value_l(0,22) + ( particles(n)%z -                         &
+                                       particles(n)%origin_z - pts_value(0,4) )**2 ! z*2
+                pts_value_l(0,23) = pts_value_l(0,23) + ( particles(n)%speed_x -                   &
+                                                          pts_value(0,6) )**2      ! u*2
+                pts_value_l(0,24) = pts_value_l(0,24) + ( particles(n)%speed_y -                   &
+                                                          pts_value(0,7) )**2      ! v*2
+                pts_value_l(0,25) = pts_value_l(0,25) + ( particles(n)%speed_z -                   &
+                                                          pts_value(0,8) )**2      ! w*2
+                pts_value_l(0,26) = pts_value_l(0,26) + ( particles(n)%rvar1 -                     &
+                                                          pts_value(0,9) )**2      ! u"2
+                pts_value_l(0,27) = pts_value_l(0,27) + ( particles(n)%rvar2 -                     &
+                                                          pts_value(0,10) )**2     ! v"2
+                pts_value_l(0,28) = pts_value_l(0,28) + ( particles(n)%rvar3 -                     &
                                                           pts_value(0,11) )**2  ! w"2
 !
@@ -2932,22 +2848,22 @@
                    jg = particles(n)%group
 
-                   pts_value_l(jg,20) = pts_value_l(jg,20) + ( particles(n)%x - &
-                                       particles(n)%origin_x - pts_value(jg,2) )**2
-                   pts_value_l(jg,21) = pts_value_l(jg,21) + ( particles(n)%y - &
-                                       particles(n)%origin_y - pts_value(jg,3) )**2
-                   pts_value_l(jg,22) = pts_value_l(jg,22) + ( particles(n)%z - &
-                                       particles(n)%origin_z - pts_value(jg,4) )**2
-                   pts_value_l(jg,23) = pts_value_l(jg,23) + ( particles(n)%speed_x - &
-                                                             pts_value(jg,6) )**2
-                   pts_value_l(jg,24) = pts_value_l(jg,24) + ( particles(n)%speed_y - &
-                                                             pts_value(jg,7) )**2
-                   pts_value_l(jg,25) = pts_value_l(jg,25) + ( particles(n)%speed_z - &
-                                                             pts_value(jg,8) )**2
-                   pts_value_l(jg,26) = pts_value_l(jg,26) + ( particles(n)%rvar1 - &
-                                                             pts_value(jg,9) )**2
-                   pts_value_l(jg,27) = pts_value_l(jg,27) + ( particles(n)%rvar2 - &
-                                                             pts_value(jg,10) )**2
-                   pts_value_l(jg,28) = pts_value_l(jg,28) + ( particles(n)%rvar3 - &
-                                                             pts_value(jg,11) )**2
+                   pts_value_l(jg,20) = pts_value_l(jg,20) + ( particles(n)%x -                    &
+                                           particles(n)%origin_x - pts_value(jg,2) )**2
+                   pts_value_l(jg,21) = pts_value_l(jg,21) + ( particles(n)%y -                    &
+                                           particles(n)%origin_y - pts_value(jg,3) )**2
+                   pts_value_l(jg,22) = pts_value_l(jg,22) + ( particles(n)%z -                    &
+                                           particles(n)%origin_z - pts_value(jg,4) )**2
+                   pts_value_l(jg,23) = pts_value_l(jg,23) + ( particles(n)%speed_x -              &
+                                                               pts_value(jg,6) )**2
+                   pts_value_l(jg,24) = pts_value_l(jg,24) + ( particles(n)%speed_y -              &
+                                                               pts_value(jg,7) )**2
+                   pts_value_l(jg,25) = pts_value_l(jg,25) + ( particles(n)%speed_z -              &
+                                                               pts_value(jg,8) )**2
+                   pts_value_l(jg,26) = pts_value_l(jg,26) + ( particles(n)%rvar1 -                &
+                                                               pts_value(jg,9) )**2
+                   pts_value_l(jg,27) = pts_value_l(jg,27) + ( particles(n)%rvar2 -                &
+                                                               pts_value(jg,10) )**2
+                   pts_value_l(jg,28) = pts_value_l(jg,28) + ( particles(n)%rvar3 -                &
+                                                               pts_value(jg,11) )**2
                 ENDIF
 
@@ -2961,6 +2877,5 @@
     IF ( number_of_particle_groups > 1 )  THEN
        DO  j = 1, number_of_particle_groups
-          pts_value_l(j,29) = ( pts_value_l(j,1) - &
-                                pts_value(j,1) / numprocs )**2
+          pts_value_l(j,29) = ( pts_value_l(j,1) - pts_value(j,1) / numprocs )**2
        ENDDO
     ENDIF
@@ -2972,6 +2887,6 @@
 
     IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-    CALL MPI_ALLREDUCE( pts_value_l(0,20), pts_value(0,20), inum*10, MPI_REAL, &
-                        MPI_SUM, comm2d, ierr )
+    CALL MPI_ALLREDUCE( pts_value_l(0,20), pts_value(0,20), inum*10, MPI_REAL, MPI_SUM, comm2d,    &
+                        ierr )
 #else
     pts_value(:,20:29) = pts_value_l(:,20:29)
@@ -2979,6 +2894,5 @@
 
 !
-!-- Normalize the above calculated quantities with the total number of
-!-- particles
+!-- Normalize the above calculated quantities with the total number of particles
     IF ( number_of_particle_groups > 1 )  THEN
        inum = number_of_particle_groups
@@ -3002,7 +2916,7 @@
        DO  j = 0, inum
           DO  i = 1, dopts_num
-             nc_stat = NF90_PUT_VAR( id_set_pts, id_var_dopts(i,j),  &
-                                     (/ pts_value(j,i) /),           &
-                                     start = (/ dopts_time_count /), &
+             nc_stat = NF90_PUT_VAR( id_set_pts, id_var_dopts(i,j),                                &
+                                     (/ pts_value(j,i) /),                                         &
+                                     start = (/ dopts_time_count /),                               &
                                      count = (/ 1 /) )
              CALL netcdf_handle_error( 'data_output_ptseries', 392 )
@@ -3018,10 +2932,10 @@
 END SUBROUTINE lpm_data_output_ptseries
 
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> This routine reads the respective restart data for the lpm.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_rrd_local_particles
 
@@ -3048,9 +2962,7 @@
 !--    First open the input unit.
        IF ( myid_char == '' )  THEN
-          OPEN ( 90, FILE='PARTICLE_RESTART_DATA_IN'//myid_char,                  &
-                     FORM='UNFORMATTED' )
+          OPEN ( 90, FILE='PARTICLE_RESTART_DATA_IN'//myid_char, FORM='UNFORMATTED' )
        ELSE
-          OPEN ( 90, FILE='PARTICLE_RESTART_DATA_IN/'//myid_char,                 &
-                     FORM='UNFORMATTED' )
+          OPEN ( 90, FILE='PARTICLE_RESTART_DATA_IN/'//myid_char, FORM='UNFORMATTED' )
        ENDIF
 
@@ -3060,8 +2972,8 @@
        particle_binary_version = '4.0'
        IF ( TRIM( version_on_file ) /= TRIM( particle_binary_version ) )  THEN
-          message_string = 'version mismatch concerning data from prior ' //      &
-                           'run &version on file = "' //                          &
-                                         TRIM( version_on_file ) //               &
-                           '&version in program = "' //                           &
+          message_string = 'version mismatch concerning data from prior ' //                       &
+                           'run &version on file = "' //                                           &
+                                         TRIM( version_on_file ) //                                &
+                           '&version in program = "' //                                            &
                                          TRIM( particle_binary_version ) // '"'
           CALL message( 'lpm_read_restart_file', 'PA0214', 1, 2, 0, 6, 0 )
@@ -3069,20 +2981,18 @@
 
 !
-!--    If less particles are stored on the restart file than prescribed by
-!--    1, the remainder is initialized by zero_particle to avoid
-!--    errors.
-       zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,     &
-                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,     &
-                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,     &
-                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,     &
+!--    If less particles are stored on the restart file than prescribed by 1, the remainder is
+!--    initialized by zero_particle to avoid errors.
+       zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,                      &
+                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,                      &
+                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,                      &
+                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,                      &
                                       0, 0, 0_idp, .FALSE., -1, -1 )
 !
-!--    Read some particle parameters and the size of the particle arrays,
-!--    allocate them and read their contents.
-       READ ( 90 )  bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,                     &
-                    last_particle_release_time, number_of_particle_groups,        &
-                    particle_groups, time_write_particle_data
-
-       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                        &
+!--    Read some particle parameters and the size of the particle arrays, allocate them and read
+!--    their contents.
+       READ ( 90 )  bc_par_b, bc_par_lr, bc_par_ns, bc_par_t, last_particle_release_time,          &
+                    number_of_particle_groups, particle_groups, time_write_particle_data
+
+       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                         &
                  grid_particles(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 
@@ -3095,7 +3005,7 @@
                 number_of_particles = prt_count(kp,jp,ip)
                 IF ( number_of_particles > 0 )  THEN
-                   alloc_size = MAX( INT( number_of_particles *                   &
-                                ( 1.0_wp + alloc_factor / 100.0_wp ) ),           &
-                                1 )
+                   alloc_size = MAX( INT( number_of_particles *                                    &
+                                          ( 1.0_wp + alloc_factor / 100.0_wp ) ),                  &
+                                     1 )
                 ELSE
                    alloc_size = 1
@@ -3110,5 +3020,5 @@
                    DEALLOCATE( tmp_particles )
                    IF ( number_of_particles < alloc_size )  THEN
-                      grid_particles(kp,jp,ip)%particles(number_of_particles+1:alloc_size) &
+                      grid_particles(kp,jp,ip)%particles(number_of_particles+1:alloc_size)         &
                          = zero_particle
                    ENDIF
@@ -3128,11 +3038,10 @@
        FLUSH(9)
 
-       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                        &
+       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                         &
                  grid_particles(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 
        ALLOCATE( prt_global_index(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 !
-!--    Open restart file for read, if not already open, and do not allow usage of
-!--    shared-memory I/O
+!--    Open restart file for read, if not already open, and do not allow usage of shared-memory I/O
        IF ( .NOT. rd_mpi_io_check_open() )  THEN
           save_restart_data_format_input = restart_data_format_input
@@ -3156,7 +3065,7 @@
                 number_of_particles = prt_count(kp,jp,ip)
                 IF ( number_of_particles > 0 )  THEN
-                   alloc_size = MAX( INT( number_of_particles *                   &
-                      ( 1.0_wp + alloc_factor / 100.0_wp ) ),           &
-                      1 )
+                   alloc_size = MAX( INT( number_of_particles *                                    &
+                                          ( 1.0_wp + alloc_factor / 100.0_wp ) ),                  &
+                                     1 )
                 ELSE
                    alloc_size = 1
@@ -3186,22 +3095,21 @@
     ENDIF
 !
-!-- Must be called to sort particles into blocks, which is needed for a fast
-!-- interpolation of the LES fields on the particle position.
+!-- Must be called to sort particles into blocks, which is needed for a fast interpolation of the
+!-- LES fields on the particle position.
     CALL lpm_sort_and_delete
 
  END SUBROUTINE lpm_rrd_local_particles
- 
- 
-!------------------------------------------------------------------------------!
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific local restart data arrays (Fortran binary format).
-!------------------------------------------------------------------------------!
- SUBROUTINE lpm_rrd_local_ftn( k, nxlf, nxlc, nxl_on_file, nxrf, nxrc,          &
-                               nxr_on_file, nynf, nync, nyn_on_file, nysf,  &
-                               nysc, nys_on_file, tmp_3d, found )
-
-
-   USE control_parameters,                                                 &
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE lpm_rrd_local_ftn( k, nxlf, nxlc, nxl_on_file, nxrf, nxrc, nxr_on_file, nynf, nync,    &
+                               nyn_on_file, nysf, nysc, nys_on_file, tmp_3d, found )
+
+
+   USE control_parameters,                                                                         &
        ONLY: length, restart_string
 
@@ -3220,7 +3128,8 @@
     INTEGER(iwp) ::  nys_on_file     !<
 
+    INTEGER(isp), DIMENSION(:,:,:), ALLOCATABLE ::  tmp_2d_seq_random_particles  !< temporary array for storing random generator
+                                                                                 !< data for the lpm
+
     LOGICAL, INTENT(OUT)  ::  found
-
-    INTEGER(isp), DIMENSION(:,:,:), ALLOCATABLE ::  tmp_2d_seq_random_particles  !< temporary array for storing random generator data for the lpm
 
     REAL(wp), DIMENSION(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp,nxl_on_file-nbgp:nxr_on_file+nbgp) ::  tmp_3d   !<
@@ -3236,5 +3145,5 @@
            ENDIF
            IF ( k == 1 )  READ ( 13 )  tmp_3d
-           pc_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
+           pc_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =                                      &
               tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
@@ -3244,7 +3153,7 @@
            ENDIF
            IF ( k == 1 )  READ ( 13 )  tmp_3d
-           pr_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
+           pr_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =                                      &
               tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
- 
+
          CASE ( 'ql_c_av' )
             IF ( .NOT. ALLOCATED( ql_c_av ) )  THEN
@@ -3252,5 +3161,5 @@
             ENDIF
             IF ( k == 1 )  READ ( 13 )  tmp_3d
-            ql_c_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =        &
+            ql_c_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =                                   &
                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
@@ -3260,5 +3169,5 @@
             ENDIF
             IF ( k == 1 )  READ ( 13 )  tmp_3d
-            ql_v_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =        &
+            ql_v_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =                                   &
                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
@@ -3268,16 +3177,16 @@
             ENDIF
             IF ( k == 1 )  READ ( 13 )  tmp_3d
-            ql_vp_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =       &
+            ql_vp_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =                                  &
                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
          CASE ( 'seq_random_array_particles' )
-             ALLOCATE( tmp_2d_seq_random_particles(5,nys_on_file:nyn_on_file,nxl_on_file:nxr_on_file) )
-             IF ( .NOT. ALLOCATED( seq_random_array_particles ) )  THEN
-                ALLOCATE( seq_random_array_particles(5,nys:nyn,nxl:nxr) )
-             ENDIF
-             IF ( k == 1 )  READ ( 13 )  tmp_2d_seq_random_particles
-             seq_random_array_particles(:,nysc:nync,nxlc:nxrc) =                                   &
-                                                  tmp_2d_seq_random_particles(:,nysf:nynf,nxlf:nxrf)
-             DEALLOCATE( tmp_2d_seq_random_particles )
+            ALLOCATE( tmp_2d_seq_random_particles(5,nys_on_file:nyn_on_file,nxl_on_file:nxr_on_file) )
+            IF ( .NOT. ALLOCATED( seq_random_array_particles ) )  THEN
+               ALLOCATE( seq_random_array_particles(5,nys:nyn,nxl:nxr) )
+            ENDIF
+            IF ( k == 1 )  READ ( 13 )  tmp_2d_seq_random_particles
+            seq_random_array_particles(:,nysc:nync,nxlc:nxrc) =                                    &
+                                                 tmp_2d_seq_random_particles(:,nysf:nynf,nxlf:nxrf)
+            DEALLOCATE( tmp_2d_seq_random_particles )
 
           CASE DEFAULT
@@ -3289,10 +3198,10 @@
  END SUBROUTINE lpm_rrd_local_ftn
 
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific local restart data arrays (MPI-IO).
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_rrd_local_mpi
 
@@ -3349,11 +3258,11 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> This routine writes the respective restart data for the lpm.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_wrd_local
- 
+
     CHARACTER (LEN=10) ::  particle_binary_version   !<
     CHARACTER (LEN=32) ::  tmp_name                  !< temporary variable
@@ -3364,5 +3273,5 @@
     INTEGER(iwp) ::  jp                              !<
     INTEGER(iwp) ::  k                               !< loop index
-    INTEGER(iwp) ::  kp                              !< 
+    INTEGER(iwp) ::  kp                              !<
 
 #if defined( __parallel )
@@ -3382,25 +3291,21 @@
 !--    First open the output unit.
        IF ( myid_char == '' )  THEN
-          OPEN ( 90, FILE='PARTICLE_RESTART_DATA_OUT'//myid_char, &
-                     FORM='UNFORMATTED')
+          OPEN ( 90, FILE='PARTICLE_RESTART_DATA_OUT'//myid_char, FORM='UNFORMATTED')
        ELSE
           IF ( myid == 0 )  CALL local_system( 'mkdir PARTICLE_RESTART_DATA_OUT' )
 #if defined( __parallel )
 !
-!--       Set a barrier in order to allow that thereafter all other processors
-!--       in the directory created by PE0 can open their file
+!--       Set a barrier in order to allow that thereafter all other processors in the directory
+!--       created by PE0 can open their file
           CALL MPI_BARRIER( comm2d, ierr )
 #endif
-          OPEN ( 90, FILE='PARTICLE_RESTART_DATA_OUT/'//myid_char, &
-                     FORM='UNFORMATTED' )
+          OPEN ( 90, FILE='PARTICLE_RESTART_DATA_OUT/'//myid_char, FORM='UNFORMATTED' )
        ENDIF
 
 !
 !--    Write the version number of the binary format.
-!--    Attention: After changes to the following output commands the version
-!--    ---------  number of the variable particle_binary_version must be
-!--               changed! Also, the version number and the list of arrays
-!--               to be read in lpm_read_restart_file must be adjusted
-!--               accordingly.
+!--    Attention: After changes to the following output commands the version number of the variable
+!--    ---------  particle_binary_version must be changed! Also, the version number and the list of
+!--               arrays to be read in lpm_read_restart_file must be adjusted accordingly.
        particle_binary_version = '4.0'
        WRITE ( 90 )  particle_binary_version
@@ -3408,10 +3313,9 @@
 !
 !--    Write some particle parameters, the size of the particle arrays
-       WRITE ( 90 )  bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,                    &
-                     last_particle_release_time, number_of_particle_groups,       &
-                     particle_groups, time_write_particle_data
+       WRITE ( 90 )  bc_par_b, bc_par_lr, bc_par_ns, bc_par_t, last_particle_release_time,         &
+                     number_of_particle_groups, particle_groups, time_write_particle_data
 
        WRITE ( 90 )  prt_count
-          
+
        DO  ip = nxl, nxr
           DO  jp = nys, nyn
@@ -3465,6 +3369,6 @@
 
 #if defined( __parallel )
-       CALL MPI_ALLREDUCE( nr_particles_local, nr_particles_global, numprocs, MPI_INTEGER,         &
-                           MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( nr_particles_local, nr_particles_global, numprocs, MPI_INTEGER, MPI_SUM,&
+                           comm2d, ierr )
 #else
        nr_particles_global = nr_particles_local
@@ -3500,9 +3404,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> This routine writes the respective restart data for the lpm.
-!------------------------------------------------------------------------------! 
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_wrd_global
 
@@ -3513,5 +3417,5 @@
     REAL(wp), DIMENSION(4,max_number_of_particle_groups) ::  particle_groups_array  !<
 
- 
+
     IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
 
@@ -3569,14 +3473,14 @@
 
  END SUBROUTINE lpm_wrd_global
- 
-
-!------------------------------------------------------------------------------!
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific global restart data (Fortran binary format).
-!------------------------------------------------------------------------------! 
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_rrd_global_ftn( found )
- 
-    USE control_parameters,                            &
+
+    USE control_parameters,                                                                        &
         ONLY: length, restart_string
 
@@ -3603,14 +3507,14 @@
           found = .FALSE.
 
-    END SELECT 
-    
+    END SELECT
+
  END SUBROUTINE lpm_rrd_global_ftn
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific global restart data (MPI-IO).
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_rrd_global_mpi
 
@@ -3661,15 +3565,19 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> This is a submodule of the lagrangian particle model. It contains all 
-!> dynamic processes of the lpm. This includes the advection (resolved and sub-
-!> grid scale) as well as the boundary conditions of particles. As a next step
-!> this submodule should be excluded as an own file. 
-!------------------------------------------------------------------------------!
+!> This is a submodule of the lagrangian particle model. It contains all dynamic processes of the
+!> lpm. This includes the advection (resolved and sub-grid scale) as well as the boundary conditions
+!> of particles. As a next step this submodule should be excluded as an own file.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_advec (ip,jp,kp)
 
-    LOGICAL ::  subbox_at_wall !< flag to see if the current subgridbox is adjacent to a wall
+    REAL(wp), PARAMETER ::  a_rog = 9.65_wp      !< parameter for fall velocity
+    REAL(wp), PARAMETER ::  b_rog = 10.43_wp     !< parameter for fall velocity
+    REAL(wp), PARAMETER ::  c_rog = 0.6_wp       !< parameter for fall velocity
+    REAL(wp), PARAMETER ::  k_cap_rog = 4.0_wp   !< parameter for fall velocity
+    REAL(wp), PARAMETER ::  k_low_rog = 12.0_wp  !< parameter for fall velocity
+    REAL(wp), PARAMETER ::  d0_rog = 0.745_wp    !< separation diameter
 
     INTEGER(iwp) ::  i                           !< index variable along x
@@ -3681,5 +3589,5 @@
     INTEGER(iwp) ::  jp                          !< index variable along y
     INTEGER(iwp) ::  k                           !< index variable along z
-    INTEGER(iwp) ::  k_wall                      !< vertical index of topography top 
+    INTEGER(iwp) ::  k_wall                      !< vertical index of topography top
     INTEGER(iwp) ::  kp                          !< index variable along z
     INTEGER(iwp) ::  k_next                      !< index variable along z
@@ -3687,4 +3595,5 @@
     INTEGER(iwp) ::  kkw                         !< index variable along z
     INTEGER(iwp) ::  n                           !< loop variable over all particles in a grid box
+    INTEGER(iwp) ::  nn                          !< loop variable over iterations steps
     INTEGER(iwp) ::  nb                          !< block number particles are sorted in
     INTEGER(iwp) ::  particle_end                !< end index for partilce loop
@@ -3692,17 +3601,17 @@
     INTEGER(iwp) ::  subbox_end                  !< end index for loop over subboxes in particle advection
     INTEGER(iwp) ::  subbox_start                !< start index for loop over subboxes in particle advection
-    INTEGER(iwp) ::  nn                          !< loop variable over iterations steps
-
+
+    INTEGER(iwp), DIMENSION(0:7) ::  end_index   !< start particle index for current block
     INTEGER(iwp), DIMENSION(0:7) ::  start_index !< start particle index for current block
-    INTEGER(iwp), DIMENSION(0:7) ::  end_index   !< start particle index for current block
+
+    LOGICAL ::  subbox_at_wall !< flag to see if the current subgridbox is adjacent to a wall
 
     REAL(wp) ::  aa                 !< dummy argument for horizontal particle interpolation
     REAL(wp) ::  alpha              !< interpolation facor for x-direction
-
     REAL(wp) ::  bb                 !< dummy argument for horizontal particle interpolation
     REAL(wp) ::  beta               !< interpolation facor for y-direction
     REAL(wp) ::  cc                 !< dummy argument for horizontal particle interpolation
-    REAL(wp) ::  d_z_p_z0           !< inverse of interpolation length for logarithmic interpolation 
-    REAL(wp) ::  dd                 !< dummy argument for horizontal particle interpolation 
+    REAL(wp) ::  d_z_p_z0           !< inverse of interpolation length for logarithmic interpolation
+    REAL(wp) ::  dd                 !< dummy argument for horizontal particle interpolation
     REAL(wp) ::  de_dx_int_l        !< x/y-interpolated TKE gradient (x) at particle position at lower vertical level
     REAL(wp) ::  de_dx_int_u        !< x/y-interpolated TKE gradient (x) at particle position at upper vertical level
@@ -3724,8 +3633,8 @@
     REAL(wp) ::  exp_term           !< exponent term
     REAL(wp) ::  gamma              !< interpolation facor for z-direction
-    REAL(wp) ::  gg                 !< dummy argument for horizontal particle interpolation 
+    REAL(wp) ::  gg                 !< dummy argument for horizontal particle interpolation
     REAL(wp) ::  height_p           !< dummy argument for logarithmic interpolation
     REAL(wp) ::  log_z_z0_int       !< logarithmus used for surface_layer interpolation
-    REAL(wp) ::  RL                 !< Lagrangian autocorrelation coefficient
+    REAL(wp) ::  rl                 !< Lagrangian autocorrelation coefficient
     REAL(wp) ::  rg1                !< Gaussian distributed random number
     REAL(wp) ::  rg2                !< Gaussian distributed random number
@@ -3739,10 +3648,10 @@
     REAL(wp) ::  v_int_u            !< x/y-interpolated v-component at particle position at upper vertical level
     REAL(wp) ::  vnext              !< calculated particle v-velocity of corrector step
-    REAL(wp) ::  vv_int             !< dummy to compute interpolated mean SGS TKE, used to scale SGS advection 
+    REAL(wp) ::  vv_int             !< dummy to compute interpolated mean SGS TKE, used to scale SGS advection
     REAL(wp) ::  w_int_l            !< x/y-interpolated w-component at particle position at lower vertical level
     REAL(wp) ::  w_int_u            !< x/y-interpolated w-component at particle position at upper vertical level
     REAL(wp) ::  wnext              !< calculated particle w-velocity of corrector step
     REAL(wp) ::  w_s                !< terminal velocity of droplets
-    REAL(wp) ::  x                  !< dummy argument for horizontal particle interpolation 
+    REAL(wp) ::  x                  !< dummy argument for horizontal particle interpolation
     REAL(wp) ::  xp                 !< calculated particle position in x of predictor step
     REAL(wp) ::  y                  !< dummy argument for horizontal particle interpolation
@@ -3751,16 +3660,9 @@
     REAL(wp) ::  zp                 !< calculated particle position in z of predictor step
 
-    REAL(wp), PARAMETER ::  a_rog = 9.65_wp      !< parameter for fall velocity
-    REAL(wp), PARAMETER ::  b_rog = 10.43_wp     !< parameter for fall velocity
-    REAL(wp), PARAMETER ::  c_rog = 0.6_wp       !< parameter for fall velocity
-    REAL(wp), PARAMETER ::  k_cap_rog = 4.0_wp   !< parameter for fall velocity
-    REAL(wp), PARAMETER ::  k_low_rog = 12.0_wp  !< parameter for fall velocity
-    REAL(wp), PARAMETER ::  d0_rog = 0.745_wp    !< separation diameter
-
-    REAL(wp), DIMENSION(number_of_particles) ::  term_1_2       !< flag to communicate whether a particle is near topography or not
-    REAL(wp), DIMENSION(number_of_particles) ::  dens_ratio     !< ratio between the density of the fluid and the density of the particles 
     REAL(wp), DIMENSION(number_of_particles) ::  de_dx_int      !< horizontal TKE gradient along x at particle position
     REAL(wp), DIMENSION(number_of_particles) ::  de_dy_int      !< horizontal TKE gradient along y at particle position
     REAL(wp), DIMENSION(number_of_particles) ::  de_dz_int      !< horizontal TKE gradient along z at particle position
+    REAL(wp), DIMENSION(number_of_particles) ::  dens_ratio     !< ratio between the density of the fluid and the density of the
+                                                                !< particles
     REAL(wp), DIMENSION(number_of_particles) ::  diss_int       !< dissipation at particle position
     REAL(wp), DIMENSION(number_of_particles) ::  dt_gap         !< remaining time until particle time integration reaches LES time
@@ -3772,6 +3674,7 @@
     REAL(wp), DIMENSION(number_of_particles) ::  rvar2_temp     !< SGS particle velocity - v-component
     REAL(wp), DIMENSION(number_of_particles) ::  rvar3_temp     !< SGS particle velocity - w-component
+    REAL(wp), DIMENSION(number_of_particles) ::  term_1_2       !< flag to communicate whether a particle is near topography or not
     REAL(wp), DIMENSION(number_of_particles) ::  u_int          !< u-component of particle speed
-    REAL(wp), DIMENSION(number_of_particles) ::  v_int          !< v-component of particle speed 
+    REAL(wp), DIMENSION(number_of_particles) ::  v_int          !< v-component of particle speed
     REAL(wp), DIMENSION(number_of_particles) ::  w_int          !< w-component of particle speed
     REAL(wp), DIMENSION(number_of_particles) ::  xv             !< x-position
@@ -3783,8 +3686,7 @@
     CALL cpu_log( log_point_s(44), 'lpm_advec', 'continue' )
 !
-!-- Determine height of Prandtl layer and distance between Prandtl-layer
-!-- height and horizontal mean roughness height, which are required for
-!-- vertical logarithmic interpolation of horizontal particle speeds
-!-- (for particles below first vertical grid level).
+!-- Determine height of Prandtl layer and distance between Prandtl-layer height and horizontal mean
+!-- roughness height, which are required for vertical logarithmic interpolation of horizontal
+!-- particle speeds (for particles below first vertical grid level).
     z_p      = zu(nzb+1) - zw(nzb)
     d_z_p_z0 = 1.0_wp / ( z_p - z0_av_global )
@@ -3796,12 +3698,11 @@
 
 !
-!-- This case uses a simple interpolation method for the particle velocites,
-!-- and applying a predictor-corrector method. @note the current time divergence
-!-- free time step is denoted with u_t etc.; the velocities of the time level of
-!-- t+1 wit u,v, and w, as the model is called after swap timelevel
+!-- This case uses a simple interpolation method for the particle velocites, and applying a
+!-- predictor-corrector method. @note the current time divergence free time step is denoted with
+!-- u_t etc.; the velocities of the time level of t+1 wit u,v, and w, as the model is called after
+!-- swap timelevel
 !-- @attention: for the corrector step the velocities of t(n+1) are required.
-!-- Therefore the particle code is executed at the end of the time intermediate
-!-- timestep routine. This interpolation method is described in more detail
-!-- in Grabowski et al., 2018 (GMD).
+!-- Therefore the particle code is executed at the end of the time intermediate timestep routine.
+!-- This interpolation method is described in more detail in Grabowski et al., 2018 (GMD).
     IF ( interpolation_simple_corrector )  THEN
 !
@@ -3816,6 +3717,6 @@
           v_int(n) = v_t(kp,jp,ip) * ( 1.0_wp - beta ) + v_t(kp,jp+1,ip) * beta
 
-          gamma = MAX( MIN( ( particles(n)%z - zw(kkw) ) /                   &
-                            ( zw(kkw+1) - zw(kkw) ), 1.0_wp ), 0.0_wp )
+          gamma = MAX( MIN( ( particles(n)%z - zw(kkw) ) / ( zw(kkw+1) - zw(kkw) ), 1.0_wp ),      &
+                       0.0_wp )
           w_int(n) = w_t(kkw,jp,ip) * ( 1.0_wp - gamma ) + w_t(kkw+1,jp,ip) * gamma
 
@@ -3845,23 +3746,22 @@
 !--          z_direction
              k_next = MAX( MIN( FLOOR( zp / (zw(kkw+1)-zw(kkw)) + offset_ocean_nzt ), nzt ), 0)
-             gamma = MAX( MIN( ( zp - zw(k_next) ) /                      &
+             gamma = MAX( MIN( ( zp - zw(k_next) ) /                                               &
                                ( zw(k_next+1) - zw(k_next) ), 1.0_wp ), 0.0_wp )
 !
 !--          Calculate part of the corrector step
-             unext = u(k_next+1, j_next, i_next) * ( 1.0_wp - alpha ) +    &
+             unext = u(k_next+1, j_next, i_next) * ( 1.0_wp - alpha ) +                            &
                      u(k_next+1, j_next,   i_next+1) * alpha
 
-             vnext = v(k_next+1, j_next, i_next) * ( 1.0_wp - beta  ) +    &
+             vnext = v(k_next+1, j_next, i_next) * ( 1.0_wp - beta  ) +                            &
                      v(k_next+1, j_next+1, i_next  ) * beta
 
-             wnext = w(k_next,   j_next, i_next) * ( 1.0_wp - gamma ) +    &
+             wnext = w(k_next,   j_next, i_next) * ( 1.0_wp - gamma ) +                            &
                      w(k_next+1, j_next, i_next  ) * gamma
 
 !
-!--          Calculate interpolated particle velocity with predictor
-!--          corrector step. u_int, v_int and w_int describes the part of
-!--          the predictor step. unext, vnext and wnext is the part of the
-!--          corrector step. The resulting new position is set below. The
-!--          implementation is based on Grabowski et al., 2018 (GMD).
+!--          Calculate interpolated particle velocity with predictor corrector step. u_int, v_int
+!--          and w_int describes the part of the predictor step. unext, vnext and wnext is the part
+!--          of the corrector step. The resulting new position is set below. The implementation is
+!--          based on Grabowski et al., 2018 (GMD).
              u_int(n) = 0.5_wp * ( u_int(n) + unext )
              v_int(n) = 0.5_wp * ( v_int(n) + vnext )
@@ -3871,6 +3771,6 @@
        ENDDO
 !
-!-- This case uses a simple interpolation method for the particle velocites,
-!-- and applying a predictor.
+!-- This case uses a simple interpolation method for the particle velocites, and applying a
+!-- predictor.
     ELSEIF ( interpolation_simple_predictor )  THEN
 !
@@ -3886,6 +3786,6 @@
           v_int(n) = v(kp,jp,ip) * ( 1.0_wp - beta ) + v(kp,jp+1,ip) * beta
 
-          gamma    = MAX( MIN( ( particles(n)%z - zw(kkw) ) /                   &
-                               ( zw(kkw+1) - zw(kkw) ), 1.0_wp ), 0.0_wp )
+          gamma    = MAX( MIN( ( particles(n)%z - zw(kkw) ) / ( zw(kkw+1) - zw(kkw) ), 1.0_wp ),   &
+                          0.0_wp )
           w_int(n) = w(kkw,jp,ip) * ( 1.0_wp - gamma ) + w(kkw+1,jp,ip) * gamma
        ENDDO
@@ -3907,11 +3807,10 @@
 !
 !--          Interpolation of the u velocity component onto particle position.
-!--          Particles are interpolation bi-linearly in the horizontal and a
-!--          linearly in the vertical. An exception is made for particles below
-!--          the first vertical grid level in case of a prandtl layer. In this
-!--          case the horizontal particle velocity components are determined using
-!--          Monin-Obukhov relations (if branch).
-!--          First, check if particle is located below first vertical grid level
-!--          above topography (Prandtl-layer height)
+!--          Particles are interpolation bi-linearly in the horizontal and a linearly in the
+!--          vertical. An exception is made for particles below the first vertical grid level in
+!--          case of a prandtl layer. In this case the horizontal particle velocity components are
+!--          determined using Monin-Obukhov relations (if branch).
+!--          First, check if particle is located below first vertical grid level above topography
+!--          (Prandtl-layer height).
 !--          Determine vertical index of topography top
              k_wall = topo_top_ind(jp,ip,0)
@@ -3925,25 +3824,21 @@
 !
 !--                Determine the sublayer. Further used as index.
-                   height_p = ( zv(n) - zw(k_wall) - z0_av_global )            &
-                                        * REAL( number_of_sublayers, KIND=wp ) &
+                   height_p = ( zv(n) - zw(k_wall) - z0_av_global )                                &
+                                        * REAL( number_of_sublayers, KIND=wp )                     &
                                         * d_z_p_z0
 !
 !--                Calculate LOG(z/z0) for exact particle height. Therefore,
 !--                interpolate linearly between precalculated logarithm.
-                   log_z_z0_int = log_z_z0(INT(height_p))                      &
-                                    + ( height_p - INT(height_p) )             &
-                                    * ( log_z_z0(INT(height_p)+1)              &
-                                         - log_z_z0(INT(height_p))             &
-                                      )
+                   log_z_z0_int = log_z_z0( INT( height_p ) ) + ( height_p - INT( height_p ) ) *   &
+                                  ( log_z_z0( INT( height_p ) + 1 ) - log_z_z0( INT( height_p ) ) )
 !
 !--                Compute u*-portion for u-component based on mean roughness.
-!--                Note, neutral solution is applied for all situations, e.g. also for
-!--                unstable and stable situations. Even though this is not exact
-!--                this saves a lot of CPU time since several calls of intrinsic
-!--                FORTRAN procedures (LOG, ATAN) are avoided, This is justified
-!--                as sensitivity studies revealed no significant effect of
-!--                using the neutral solution also for un/stable situations. Based on the u*
-!--                recalculate the velocity at height z_particle. Since the analytical solution
-!--                only yields absolute values, include the sign using the intrinsic SIGN function.
+!--                Note, neutral solution is applied for all situations, e.g. also for unstable and
+!--                stable situations. Even though this is not exact this saves a lot of CPU time
+!--                since several calls of intrinsic FORTRAN procedures (LOG, ATAN) are avoided. This
+!--                is justified as sensitivity studies revealed no significant effect of using the
+!--                neutral solution also for un/stable situations. Based on the u* recalculate the
+!--                velocity at height z_particle. Since the analytical solution only yields absolute
+!--                values, include the sign using the intrinsic SIGN function.
                    us_int   = kappa * 0.5_wp * ABS( u(k_wall+1,jp,ip) + u(k_wall+1,jp,ip+1) ) /    &
                               log_z_z0(number_of_sublayers)
@@ -3953,6 +3848,6 @@
                 ENDIF
 !
-!--          Particle above the first grid level. Bi-linear interpolation in the
-!--          horizontal and linear interpolation in the vertical direction.
+!--          Particle above the first grid level. Bi-linear interpolation in the horizontal and
+!--          linear interpolation in the vertical direction.
              ELSE
                 x  = xv(n) - i * dx
@@ -3964,16 +3859,15 @@
                 gg = aa + bb + cc + dd
 
-                u_int_l = ( ( gg - aa ) * u(k,j,i)   + ( gg - bb ) * u(k,j,i+1)   &
-                            + ( gg - cc ) * u(k,j+1,i) + ( gg - dd ) *            &
-                            u(k,j+1,i+1) ) / ( 3.0_wp * gg ) - u_gtrans
+                u_int_l = ( ( gg - aa ) * u(k,j,i)   + ( gg - bb ) * u(k,j,i+1)                    &
+                            + ( gg - cc ) * u(k,j+1,i) + ( gg - dd ) * u(k,j+1,i+1) )              &
+                          / ( 3.0_wp * gg ) - u_gtrans
 
                 IF ( k == nzt )  THEN
                    u_int(n) = u_int_l
                 ELSE
-                   u_int_u = ( ( gg-aa ) * u(k+1,j,i) + ( gg-bb ) * u(k+1,j,i+1)  &
-                               + ( gg-cc ) * u(k+1,j+1,i) + ( gg-dd ) *           &
-                               u(k+1,j+1,i+1) ) / ( 3.0_wp * gg ) - u_gtrans
-                   u_int(n) = u_int_l + ( zv(n) - zu(k) ) / dzw(k+1) *            &
-                              ( u_int_u - u_int_l )
+                   u_int_u = ( ( gg-aa ) * u(k+1,j,i) + ( gg-bb ) * u(k+1,j,i+1)                   &
+                               + ( gg-cc ) * u(k+1,j+1,i) + ( gg-dd ) * u(k+1,j+1,i+1) )           &
+                             / ( 3.0_wp * gg ) - u_gtrans
+                   u_int(n) = u_int_l + ( zv(n) - zu(k) ) / dzw(k+1) * ( u_int_u - u_int_l )
                 ENDIF
              ENDIF
@@ -3998,25 +3892,23 @@
 !
 !--                Determine the sublayer. Further used as index.
-                   height_p = ( zv(n) - zw(k_wall) - z0_av_global )            &
-                                        * REAL( number_of_sublayers, KIND=wp ) &
+                   height_p = ( zv(n) - zw(k_wall) - z0_av_global )                                &
+                                        * REAL( number_of_sublayers, KIND=wp )                     &
                                         * d_z_p_z0
 !
-!--                Calculate LOG(z/z0) for exact particle height. Therefore,
-!--                interpolate linearly between precalculated logarithm.
-                   log_z_z0_int = log_z_z0(INT(height_p))                      &
-                                    + ( height_p - INT(height_p) )             &
-                                    * ( log_z_z0(INT(height_p)+1)              &
-                                         - log_z_z0(INT(height_p))             &
+!--                Calculate LOG(z/z0) for exact particle height. Therefore, interpolate linearly
+!--                between precalculated logarithm.
+                   log_z_z0_int = log_z_z0(INT(height_p))                                          &
+                                    + ( height_p - INT(height_p) )                                 &
+                                    * ( log_z_z0(INT(height_p)+1) - log_z_z0(INT(height_p))        &
                                       )
 !
 !--                Compute u*-portion for v-component based on mean roughness.
-!--                Note, neutral solution is applied for all situations, e.g. also for
-!--                unstable and stable situations. Even though this is not exact
-!--                this saves a lot of CPU time since several calls of intrinsic
-!--                FORTRAN procedures (LOG, ATAN) are avoided, This is justified
-!--                as sensitivity studies revealed no significant effect of
-!--                using the neutral solution also for un/stable situations. Based on the u*
-!--                recalculate the velocity at height z_particle. Since the analytical solution
-!--                only yields absolute values, include the sign using the intrinsic SIGN function.
+!--                Note, neutral solution is applied for all situations, e.g. also for unstable and
+!--                stable situations. Even though this is not exact this saves a lot of CPU time
+!--                since several calls of intrinsic FORTRAN procedures (LOG, ATAN) are avoided, This
+!--                is justified as sensitivity studies revealed no significant effect of using the
+!--                neutral solution also for un/stable situations. Based on the u* recalculate the
+!--                velocity at height z_particle. Since the analytical solution only yields absolute
+!--                values, include the sign using the intrinsic SIGN function.
                    us_int   = kappa * 0.5_wp * ABS( v(k_wall+1,jp,ip) + v(k_wall+1,jp+1,ip) ) /    &
                               log_z_z0(number_of_sublayers)
@@ -4034,6 +3926,6 @@
                 gg = aa + bb + cc + dd
 
-                v_int_l = ( ( gg - aa ) * v(k,j,i)   + ( gg - bb ) * v(k,j,i+1)   &
-                          + ( gg - cc ) * v(k,j+1,i) + ( gg - dd ) * v(k,j+1,i+1) &
+                v_int_l = ( ( gg - aa ) * v(k,j,i)   + ( gg - bb ) * v(k,j,i+1)                    &
+                          + ( gg - cc ) * v(k,j+1,i) + ( gg - dd ) * v(k,j+1,i+1)                  &
                           ) / ( 3.0_wp * gg ) - v_gtrans
 
@@ -4041,9 +3933,8 @@
                    v_int(n) = v_int_l
                 ELSE
-                   v_int_u = ( ( gg-aa ) * v(k+1,j,i)   + ( gg-bb ) * v(k+1,j,i+1)   &
-                             + ( gg-cc ) * v(k+1,j+1,i) + ( gg-dd ) * v(k+1,j+1,i+1) &
+                   v_int_u = ( ( gg-aa ) * v(k+1,j,i)   + ( gg-bb ) * v(k+1,j,i+1)                 &
+                             + ( gg-cc ) * v(k+1,j+1,i) + ( gg-dd ) * v(k+1,j+1,i+1)               &
                              ) / ( 3.0_wp * gg ) - v_gtrans
-                   v_int(n) = v_int_l + ( zv(n) - zu(k) ) / dzw(k+1) *               &
-                                     ( v_int_u - v_int_l )
+                   v_int(n) = v_int_l + ( zv(n) - zu(k) ) / dzw(k+1) * ( v_int_u - v_int_l )
                 ENDIF
              ENDIF
@@ -4065,6 +3956,6 @@
                 gg = aa + bb + cc + dd
 
-                w_int_l = ( ( gg - aa ) * w(k,j,i)   + ( gg - bb ) * w(k,j,i+1)   &
-                          + ( gg - cc ) * w(k,j+1,i) + ( gg - dd ) * w(k,j+1,i+1) &
+                w_int_l = ( ( gg - aa ) * w(k,j,i)   + ( gg - bb ) * w(k,j,i+1)                    &
+                          + ( gg - cc ) * w(k,j+1,i) + ( gg - dd ) * w(k,j+1,i+1)                  &
                           ) / ( 3.0_wp * gg )
 
@@ -4072,11 +3963,10 @@
                    w_int(n) = w_int_l
                 ELSE
-                   w_int_u = ( ( gg-aa ) * w(k+1,j,i)   + &
-                               ( gg-bb ) * w(k+1,j,i+1) + &
-                               ( gg-cc ) * w(k+1,j+1,i) + &
-                               ( gg-dd ) * w(k+1,j+1,i+1) &
+                   w_int_u = ( ( gg-aa ) * w(k+1,j,i)   +                                          &
+                               ( gg-bb ) * w(k+1,j,i+1) +                                          &
+                               ( gg-cc ) * w(k+1,j+1,i) +                                          &
+                               ( gg-dd ) * w(k+1,j+1,i+1)                                          &
                              ) / ( 3.0_wp * gg )
-                   w_int(n) = w_int_l + ( zv(n) - zw(k) ) / dzw(k+1) *            &
-                              ( w_int_u - w_int_l )
+                   w_int(n) = w_int_l + ( zv(n) - zw(k) ) / dzw(k+1) * ( w_int_u - w_int_l )
                 ENDIF
              ELSE
@@ -4087,6 +3977,5 @@
     ENDIF
 
-!-- Interpolate and calculate quantities needed for calculating the SGS
-!-- velocities
+!-- Interpolate and calculate quantities needed for calculating the SGS velocities
     IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
 
@@ -4100,7 +3989,7 @@
              j = jp + MERGE( -1_iwp , 1_iwp, BTEST( nb, 1 ) )
              k = kp + MERGE( -1_iwp , 1_iwp, BTEST( nb, 0 ) )
-             IF ( .NOT. BTEST(wall_flags_total_0(k,  jp, ip), 0) .OR.             &
-                  .NOT. BTEST(wall_flags_total_0(kp, j,  ip), 0) .OR.             &
-                  .NOT. BTEST(wall_flags_total_0(kp, jp, i ), 0) )                &
+             IF ( .NOT. BTEST(wall_flags_total_0(k,  jp, ip), 0) .OR.                              &
+                  .NOT. BTEST(wall_flags_total_0(kp, j,  ip), 0) .OR.                              &
+                  .NOT. BTEST(wall_flags_total_0(kp, jp, i ), 0) )                                 &
              THEN
                 subbox_at_wall = .TRUE.
@@ -4108,5 +3997,5 @@
           ENDIF
           IF ( subbox_at_wall )  THEN
-             e_int(start_index(nb):end_index(nb))     = e(kp,jp,ip) 
+             e_int(start_index(nb):end_index(nb))     = e(kp,jp,ip)
              diss_int(start_index(nb):end_index(nb))  = diss(kp,jp,ip)
              de_dx_int(start_index(nb):end_index(nb)) = de_dx(kp,jp,ip)
@@ -4132,6 +4021,6 @@
                 gg = aa + bb + cc + dd
 
-                e_int_l = ( ( gg-aa ) * e(k,j,i)   + ( gg-bb ) * e(k,j,i+1)   &
-                          + ( gg-cc ) * e(k,j+1,i) + ( gg-dd ) * e(k,j+1,i+1) &
+                e_int_l = ( ( gg-aa ) * e(k,j,i)   + ( gg-bb ) * e(k,j,i+1)                        &
+                          + ( gg-cc ) * e(k,j+1,i) + ( gg-dd ) * e(k,j+1,i+1)                      &
                           ) / ( 3.0_wp * gg )
 
@@ -4144,20 +4033,18 @@
                                ( gg - dd ) * e(k+1,j+1,i+1) &
                             ) / ( 3.0_wp * gg )
-                   e_int(n) = e_int_l + ( zv(n) - zu(k) ) / dzw(k+1) *            &
-                                     ( e_int_u - e_int_l )
+                   e_int(n) = e_int_l + ( zv(n) - zu(k) ) / dzw(k+1) * ( e_int_u - e_int_l )
                 ENDIF
 !
-!--             Needed to avoid NaN particle velocities (this might not be
-!--             required any more)
+!--             Needed to avoid NaN particle velocities (this might not be required any more)
                 IF ( e_int(n) <= 0.0_wp )  THEN
                    e_int(n) = 1.0E-20_wp
                 ENDIF
 !
-!--             Interpolate the TKE gradient along x (adopt incides i,j,k and
-!--             all position variables from above (TKE))
-                de_dx_int_l = ( ( gg - aa ) * de_dx(k,j,i)   + &
-                                ( gg - bb ) * de_dx(k,j,i+1) + &
-                                ( gg - cc ) * de_dx(k,j+1,i) + &
-                                ( gg - dd ) * de_dx(k,j+1,i+1) &
+!--             Interpolate the TKE gradient along x (adopt incides i,j,k and all position variables
+!--             from above (TKE))
+                de_dx_int_l = ( ( gg - aa ) * de_dx(k,j,i)   +                                     &
+                                ( gg - bb ) * de_dx(k,j,i+1) +                                     &
+                                ( gg - cc ) * de_dx(k,j+1,i) +                                     &
+                                ( gg - dd ) * de_dx(k,j+1,i+1)                                     &
                                ) / ( 3.0_wp * gg )
 
@@ -4165,28 +4052,28 @@
                    de_dx_int(n) = de_dx_int_l
                 ELSE
-                   de_dx_int_u = ( ( gg - aa ) * de_dx(k+1,j,i)   + &
-                                   ( gg - bb ) * de_dx(k+1,j,i+1) + &
-                                   ( gg - cc ) * de_dx(k+1,j+1,i) + &
-                                   ( gg - dd ) * de_dx(k+1,j+1,i+1) &
+                   de_dx_int_u = ( ( gg - aa ) * de_dx(k+1,j,i)   +                                &
+                                   ( gg - bb ) * de_dx(k+1,j,i+1) +                                &
+                                   ( gg - cc ) * de_dx(k+1,j+1,i) +                                &
+                                   ( gg - dd ) * de_dx(k+1,j+1,i+1)                                &
                                   ) / ( 3.0_wp * gg )
-                   de_dx_int(n) = de_dx_int_l + ( zv(n) - zu(k) ) / dzw(k+1) *    &
+                   de_dx_int(n) = de_dx_int_l + ( zv(n) - zu(k) ) / dzw(k+1) *                     &
                                               ( de_dx_int_u - de_dx_int_l )
                 ENDIF
 !
 !--             Interpolate the TKE gradient along y
-                de_dy_int_l = ( ( gg - aa ) * de_dy(k,j,i)   + &
-                                ( gg - bb ) * de_dy(k,j,i+1) + &
-                                ( gg - cc ) * de_dy(k,j+1,i) + &
-                                ( gg - dd ) * de_dy(k,j+1,i+1) &
+                de_dy_int_l = ( ( gg - aa ) * de_dy(k,j,i)   +                                     &
+                                ( gg - bb ) * de_dy(k,j,i+1) +                                     &
+                                ( gg - cc ) * de_dy(k,j+1,i) +                                     &
+                                ( gg - dd ) * de_dy(k,j+1,i+1)                                     &
                                ) / ( 3.0_wp * gg )
                 IF ( ( k+1 == nzt+1 )  .OR.  ( k == nzb ) )  THEN
                    de_dy_int(n) = de_dy_int_l
                 ELSE
-                   de_dy_int_u = ( ( gg - aa ) * de_dy(k+1,j,i)   + &
-                                   ( gg - bb ) * de_dy(k+1,j,i+1) + &
-                                   ( gg - cc ) * de_dy(k+1,j+1,i) + &
-                                   ( gg - dd ) * de_dy(k+1,j+1,i+1) &
+                   de_dy_int_u = ( ( gg - aa ) * de_dy(k+1,j,i)   +                                &
+                                   ( gg - bb ) * de_dy(k+1,j,i+1) +                                &
+                                   ( gg - cc ) * de_dy(k+1,j+1,i) +                                &
+                                   ( gg - dd ) * de_dy(k+1,j+1,i+1)                                &
                                   ) / ( 3.0_wp * gg )
-                      de_dy_int(n) = de_dy_int_l + ( zv(n) - zu(k) ) / dzw(k+1) * &
+                      de_dy_int(n) = de_dy_int_l + ( zv(n) - zu(k) ) / dzw(k+1) *                  &
                                                  ( de_dy_int_u - de_dy_int_l )
                 ENDIF
@@ -4197,8 +4084,8 @@
                    de_dz_int(n) = 0.0_wp
                 ELSE
-                   de_dz_int_l = ( ( gg - aa ) * de_dz(k,j,i)   + &
-                                   ( gg - bb ) * de_dz(k,j,i+1) + &
-                                   ( gg - cc ) * de_dz(k,j+1,i) + &
-                                   ( gg - dd ) * de_dz(k,j+1,i+1) &
+                   de_dz_int_l = ( ( gg - aa ) * de_dz(k,j,i)   +                                  &
+                                   ( gg - bb ) * de_dz(k,j,i+1) +                                  &
+                                   ( gg - cc ) * de_dz(k,j+1,i) +                                  &
+                                   ( gg - dd ) * de_dz(k,j+1,i+1)                                  &
                                   ) / ( 3.0_wp * gg )
 
@@ -4206,10 +4093,10 @@
                       de_dz_int(n) = de_dz_int_l
                    ELSE
-                      de_dz_int_u = ( ( gg - aa ) * de_dz(k+1,j,i)   + &
-                                      ( gg - bb ) * de_dz(k+1,j,i+1) + &
-                                      ( gg - cc ) * de_dz(k+1,j+1,i) + &
-                                      ( gg - dd ) * de_dz(k+1,j+1,i+1) &
+                      de_dz_int_u = ( ( gg - aa ) * de_dz(k+1,j,i)   +                             &
+                                      ( gg - bb ) * de_dz(k+1,j,i+1) +                             &
+                                      ( gg - cc ) * de_dz(k+1,j+1,i) +                             &
+                                      ( gg - dd ) * de_dz(k+1,j+1,i+1)                             &
                                      ) / ( 3.0_wp * gg )
-                      de_dz_int(n) = de_dz_int_l + ( zv(n) - zu(k) ) / dzw(k+1) * &
+                      de_dz_int(n) = de_dz_int_l + ( zv(n) - zu(k) ) / dzw(k+1) *                  &
                                                  ( de_dz_int_u - de_dz_int_l )
                    ENDIF
@@ -4218,8 +4105,8 @@
 !
 !--             Interpolate the dissipation of TKE
-                diss_int_l = ( ( gg - aa ) * diss(k,j,i)   + &
-                               ( gg - bb ) * diss(k,j,i+1) + &
-                               ( gg - cc ) * diss(k,j+1,i) + &
-                               ( gg - dd ) * diss(k,j+1,i+1) &
+                diss_int_l = ( ( gg - aa ) * diss(k,j,i)   +                                       &
+                               ( gg - bb ) * diss(k,j,i+1) +                                       &
+                               ( gg - cc ) * diss(k,j+1,i) +                                       &
+                               ( gg - dd ) * diss(k,j+1,i+1)                                       &
                                ) / ( 3.0_wp * gg )
 
@@ -4227,10 +4114,10 @@
                    diss_int(n) = diss_int_l
                 ELSE
-                   diss_int_u = ( ( gg - aa ) * diss(k+1,j,i)   + &
-                                  ( gg - bb ) * diss(k+1,j,i+1) + &
-                                  ( gg - cc ) * diss(k+1,j+1,i) + &
-                                  ( gg - dd ) * diss(k+1,j+1,i+1) &
+                   diss_int_u = ( ( gg - aa ) * diss(k+1,j,i)   +                                  &
+                                  ( gg - bb ) * diss(k+1,j,i+1) +                                  &
+                                  ( gg - cc ) * diss(k+1,j+1,i) +                                  &
+                                  ( gg - dd ) * diss(k+1,j+1,i+1)                                  &
                                  ) / ( 3.0_wp * gg )
-                   diss_int(n) = diss_int_l + ( zv(n) - zu(k) ) / dzw(k+1) *      &
+                   diss_int(n) = diss_int_l + ( zv(n) - zu(k) ) / dzw(k+1) *                       &
                                             ( diss_int_u - diss_int_l )
                 ENDIF
@@ -4250,16 +4137,14 @@
           DO  n = start_index(nb), end_index(nb)
 !
-!--          Vertical interpolation of the horizontally averaged SGS TKE and
-!--          resolved-scale velocity variances and use the interpolated values
-!--          to calculate the coefficient fs, which is a measure of the ratio
-!--          of the subgrid-scale turbulent kinetic energy to the total amount
+!--          Vertical interpolation of the horizontally averaged SGS TKE and resolved-scale velocity
+!--          variances and use the interpolated values to calculate the coefficient fs, which is a
+!--          measure of the ratio of the subgrid-scale turbulent kinetic energy to the total amount
 !--          of turbulent kinetic energy.
              IF ( k == 0 )  THEN
                 e_mean_int = hom(0,1,8,0)
              ELSE
-                e_mean_int = hom(k,1,8,0) +                                    &
-                                           ( hom(k+1,1,8,0) - hom(k,1,8,0) ) / &
-                                           ( zu(k+1) - zu(k) ) *               &
-                                           ( zv(n) - zu(k) )
+                e_mean_int = hom(k,1,8,0) + ( hom(k+1,1,8,0) - hom(k,1,8,0) ) /                    &
+                                            ( zu(k+1) - zu(k) ) *                                  &
+                                            ( zv(n) - zu(k) )
              ENDIF
 
@@ -4274,9 +4159,9 @@
                                          ( 1.0_wp * ( zw(kw+1) - zw(kw) ) ) )
              ELSE
-                aa  = hom(k,1,30,0) + ( hom(k+1,1,30,0) - hom(k,1,30,0) ) *    &
+                aa  = hom(k,1,30,0) + ( hom(k+1,1,30,0) - hom(k,1,30,0) ) *                        &
                            ( ( zv(n) - zu(k) ) / ( zu(k+1) - zu(k) ) )
-                bb  = hom(k,1,31,0) + ( hom(k+1,1,31,0) - hom(k,1,31,0) ) *    &
+                bb  = hom(k,1,31,0) + ( hom(k+1,1,31,0) - hom(k,1,31,0) ) *                        &
                            ( ( zv(n) - zu(k) ) / ( zu(k+1) - zu(k) ) )
-                cc  = hom(kw,1,32,0) + ( hom(kw+1,1,32,0)-hom(kw,1,32,0) ) *   &
+                cc  = hom(kw,1,32,0) + ( hom(kw+1,1,32,0)-hom(kw,1,32,0) ) *                       &
                            ( ( zv(n) - zw(kw) ) / ( zw(kw+1)-zw(kw) ) )
              ENDIF
@@ -4284,10 +4169,10 @@
              vv_int = ( 1.0_wp / 3.0_wp ) * ( aa + bb + cc )
 !
-!--          Needed to avoid NaN particle velocities. The value of 1.0 is just
-!--          an educated guess for the given case.
+!--          Needed to avoid NaN particle velocities. The value of 1.0 is just an educated guess for
+!--          the given case.
              IF ( vv_int + ( 2.0_wp / 3.0_wp ) * e_mean_int == 0.0_wp )  THEN
                 fs_int(n) = 1.0_wp
              ELSE
-                fs_int(n) = ( 2.0_wp / 3.0_wp ) * e_mean_int /                 &
+                fs_int(n) = ( 2.0_wp / 3.0_wp ) * e_mean_int /                                     &
                             ( vv_int + ( 2.0_wp / 3.0_wp ) * e_mean_int )
              ENDIF
@@ -4312,10 +4197,10 @@
 !
 !--          Calculate the Lagrangian timescale according to Weil et al. (2004).
-             lagr_timescale(n) = ( 4.0_wp * e_int(n) + 1E-20_wp ) / &
-                              ( 3.0_wp * fs_int(n) * c_0 * diss_int(n) + 1E-20_wp )
-
-!
-!--          Calculate the next particle timestep. dt_gap is the time needed to
-!--          complete the current LES timestep.
+             lagr_timescale(n) = ( 4.0_wp * e_int(n) + 1E-20_wp ) /                                &
+                                 ( 3.0_wp * fs_int(n) * c_0 * diss_int(n) + 1E-20_wp )
+
+!
+!--          Calculate the next particle timestep. dt_gap is the time needed to complete the current
+!--          LES timestep.
              dt_gap(n) = dt_3d - particles(n)%dt_sum
              dt_particle(n) = MIN( dt_3d, 0.025_wp * lagr_timescale(n), dt_gap(n) )
@@ -4323,6 +4208,6 @@
              particles(n)%aux2 = dt_gap(n)
 !
-!--          The particle timestep should not be too small in order to prevent
-!--          the number of particle timesteps of getting too large
+!--          The particle timestep should not be too small in order to prevent the number of
+!--          particle timesteps of getting too large
              IF ( dt_particle(n) < dt_min_part )  THEN
                 IF ( dt_min_part < dt_gap(n) )  THEN
@@ -4340,35 +4225,28 @@
              IF ( particles(n)%age == 0.0_wp )  THEN
 !
-!--             For new particles the SGS components are derived from the SGS
-!--             TKE. Limit the Gaussian random number to the interval
-!--             [-5.0*sigma, 5.0*sigma] in order to prevent the SGS velocities
-!--             from becoming unrealistically large.
-                rvar1_temp(n) = SQRT( 2.0_wp * sgs_wf_part * e_int(n)          &
-                                          + 1E-20_wp ) * rg(n,1)
-                rvar2_temp(n) = SQRT( 2.0_wp * sgs_wf_part * e_int(n)          &
-                                          + 1E-20_wp ) * rg(n,2)
-                rvar3_temp(n) = SQRT( 2.0_wp * sgs_wf_part * e_int(n)          &
-                                          + 1E-20_wp ) * rg(n,3)
+!--             For new particles the SGS components are derived from the SGS TKE. Limit the
+!--             Gaussian random number to the interval [-5.0*sigma, 5.0*sigma] in order to prevent
+!--             the SGS velocities from becoming unrealistically large.
+                rvar1_temp(n) = SQRT( 2.0_wp * sgs_wf_part * e_int(n) + 1E-20_wp ) * rg(n,1)
+                rvar2_temp(n) = SQRT( 2.0_wp * sgs_wf_part * e_int(n) + 1E-20_wp ) * rg(n,2)
+                rvar3_temp(n) = SQRT( 2.0_wp * sgs_wf_part * e_int(n) + 1E-20_wp ) * rg(n,3)
              ELSE
 !
-!--             Restriction of the size of the new timestep: compared to the 
+!--             Restriction of the size of the new timestep: compared to the
 !--             previous timestep the increase must not exceed 200%. First,
 !--             check if age > age_m, in order to prevent that particles get zero
 !--             timestep.
-                dt_particle_m = MERGE( dt_particle(n),                         &
-                                       particles(n)%age - particles(n)%age_m,  &
-                                       particles(n)%age - particles(n)%age_m < &
-                                       1E-8_wp )
+                dt_particle_m = MERGE( dt_particle(n),                                             &
+                                       particles(n)%age - particles(n)%age_m,                      &
+                                       particles(n)%age - particles(n)%age_m < 1E-8_wp )
                 IF ( dt_particle(n) > 2.0_wp * dt_particle_m )  THEN
                    dt_particle(n) = 2.0_wp * dt_particle_m
                 ENDIF
 
-!--             For old particles the SGS components are correlated with the
-!--             values from the previous timestep. Random numbers have also to
-!--             be limited (see above).
-!--             As negative values for the subgrid TKE are not allowed, the
-!--             change of the subgrid TKE with time cannot be smaller than
-!--             -e_int(n)/dt_particle. This value is used as a lower boundary
-!--             value for the change of TKE 
+!--             For old particles the SGS components are correlated with the values from the
+!--             previous timestep. Random numbers have also to be limited (see above).
+!--             As negative values for the subgrid TKE are not allowed, the change of the subgrid
+!--             TKE with time cannot be smaller than -e_int(n)/dt_particle. This value is used as a
+!--             lower boundary value for the change of TKE
                 de_dt_min = - e_int(n) / dt_particle(n)
 
@@ -4379,15 +4257,12 @@
                 ENDIF
 
-                CALL weil_stochastic_eq( rvar1_temp(n), fs_int(n), e_int(n),    &
-                                        de_dx_int(n), de_dt, diss_int(n),       &
-                                        dt_particle(n), rg(n,1), term_1_2(n) )
-
-                CALL weil_stochastic_eq( rvar2_temp(n), fs_int(n), e_int(n),    &
-                                        de_dy_int(n), de_dt, diss_int(n),       &
-                                        dt_particle(n), rg(n,2), term_1_2(n) )
-
-                CALL weil_stochastic_eq( rvar3_temp(n), fs_int(n), e_int(n),    &
-                                        de_dz_int(n), de_dt, diss_int(n),       &
-                                        dt_particle(n), rg(n,3), term_1_2(n) )
+                CALL weil_stochastic_eq( rvar1_temp(n), fs_int(n), e_int(n), de_dx_int(n), de_dt,  &
+                                         diss_int(n), dt_particle(n), rg(n,1), term_1_2(n) )
+
+                CALL weil_stochastic_eq( rvar2_temp(n), fs_int(n), e_int(n), de_dy_int(n), de_dt,  &
+                                         diss_int(n), dt_particle(n), rg(n,2), term_1_2(n) )
+
+                CALL weil_stochastic_eq( rvar3_temp(n), fs_int(n), e_int(n), de_dz_int(n), de_dt,  &
+                                         diss_int(n), dt_particle(n), rg(n,3), term_1_2(n) )
 
              ENDIF
@@ -4396,12 +4271,11 @@
        ENDDO
 !
-!--    Check if the added SGS velocities result in a violation of the CFL-
-!--    criterion. If yes, limt the SGS particle speed to match the
-!--    CFL criterion. Note, a re-calculation of the SGS particle speed with
-!--    smaller timestep does not necessarily fulfill the CFL criterion as the 
-!--    new SGS speed can be even larger (due to the random term with scales with
-!--    the square-root of dt_particle, for small dt the random contribution increases).
-!--    Thus, we would need to re-calculate the SGS speeds as long as they would
-!--    fulfill the requirements, which could become computationally expensive, 
+!--    Check if the added SGS velocities result in a violation of the CFL-criterion. If yes, limt
+!--    the SGS particle speed to match the CFL criterion. Note, a re-calculation of the SGS particle
+!--    speed with smaller timestep does not necessarily fulfill the CFL criterion as the new SGS
+!--    speed can be even larger (due to the random term with scales with the square-root of
+!--    dt_particle, for small dt the random contribution increases).
+!--    Thus, we would need to re-calculate the SGS speeds as long as they would fulfill the
+!--    requirements, which could become computationally expensive,
 !--    Hence, we just limit them.
        dz_temp = zw(kp)-zw(kp-1)
@@ -4409,32 +4283,32 @@
        DO  nb = 0, 7
           DO  n = start_index(nb), end_index(nb)
-             IF ( ABS( u_int(n) + rvar1_temp(n) ) > ( dx      / dt_particle(n) )  .OR.   &
-                  ABS( v_int(n) + rvar2_temp(n) ) > ( dy      / dt_particle(n) )  .OR.   &
+             IF ( ABS( u_int(n) + rvar1_temp(n) ) > ( dx      / dt_particle(n) )  .OR.             &
+                  ABS( v_int(n) + rvar2_temp(n) ) > ( dy      / dt_particle(n) )  .OR.             &
                   ABS( w_int(n) + rvar3_temp(n) ) > ( dz_temp / dt_particle(n) ) )  THEN
 !
-!--             If total speed exceeds the allowed speed according to CFL 
+!--             If total speed exceeds the allowed speed according to CFL
 !--             criterion, limit the SGS speed to
 !--             dx_i / dt_particle - u_resolved_i, considering a safty factor.
-                rvar1_temp(n) = MERGE( rvar1_temp(n),                          &
-                                       0.9_wp *                                &
-                                       SIGN( dx / dt_particle(n)               &
-                                           - ABS( u_int(n) ), rvar1_temp(n) ), &
-                                       ABS( u_int(n) + rvar1_temp(n) ) <       &
+                rvar1_temp(n) = MERGE( rvar1_temp(n),                                              &
+                                       0.9_wp *                                                    &
+                                       SIGN( dx / dt_particle(n)                                   &
+                                             - ABS( u_int(n) ), rvar1_temp(n) ),                   &
+                                       ABS( u_int(n) + rvar1_temp(n) ) <                           &
                                        ( dx / dt_particle(n) ) )
-                rvar2_temp(n) = MERGE( rvar2_temp(n),                          &
-                                       0.9_wp *                                &
-                                       SIGN( dy / dt_particle(n)               &
-                                           - ABS( v_int(n) ), rvar2_temp(n) ), &
-                                       ABS( v_int(n) + rvar2_temp(n) ) <       &
+                rvar2_temp(n) = MERGE( rvar2_temp(n),                                              &
+                                       0.9_wp *                                                    &
+                                       SIGN( dy / dt_particle(n)                                   &
+                                             - ABS( v_int(n) ), rvar2_temp(n) ),                   &
+                                       ABS( v_int(n) + rvar2_temp(n) ) <                           &
                                        ( dy / dt_particle(n) ) )
-                rvar3_temp(n) = MERGE( rvar3_temp(n),                          &
-                                       0.9_wp *                                &
-                                       SIGN( zw(kp)-zw(kp-1) / dt_particle(n)  &
-                                           - ABS( w_int(n) ), rvar3_temp(n) ), &
-                                       ABS( w_int(n) + rvar3_temp(n) ) <       &
+                rvar3_temp(n) = MERGE( rvar3_temp(n),                                              &
+                                       0.9_wp *                                                    &
+                                       SIGN( zw(kp)-zw(kp-1) / dt_particle(n)                      &
+                                             - ABS( w_int(n) ), rvar3_temp(n) ),                   &
+                                       ABS( w_int(n) + rvar3_temp(n) ) <                           &
                                        ( zw(kp)-zw(kp-1) / dt_particle(n) ) )
              ENDIF
 !
-!--          Update particle velocites 
+!--          Update particle velocites
              particles(n)%rvar1 = rvar1_temp(n)
              particles(n)%rvar2 = rvar2_temp(n)
@@ -4444,6 +4318,6 @@
              w_int(n) = w_int(n) + particles(n)%rvar3
 !
-!--          Store the SGS TKE of the current timelevel which is needed for
-!--          for calculating the SGS particle velocities at the next timestep
+!--          Store the SGS TKE of the current timelevel which is needed for for calculating the SGS
+!--          particle velocities at the next timestep
              particles(n)%e_m = e_int(n)
           ENDDO
@@ -4452,6 +4326,5 @@
     ELSE
 !
-!--    If no SGS velocities are used, only the particle timestep has to
-!--    be set
+!--    If no SGS velocities are used, only the particle timestep has to be set
        dt_particle = dt_3d
 
@@ -4461,11 +4334,10 @@
     IF ( ANY( dens_ratio == 0.0_wp ) )  THEN
 !
-!--    Decide whether the particle loop runs over the subboxes or only over 1,
-!--    number_of_particles. This depends on the selected interpolation method.
-!--    If particle interpolation method is not trilinear, then the sorting within
-!--    subboxes is not required. However, therefore the index start_index(nb) and
-!--    end_index(nb) are not defined and the loops are still over
-!--    number_of_particles. @todo find a more generic way to write this loop or
-!--    delete trilinear interpolation
+!--    Decide whether the particle loop runs over the subboxes or only over 1, number_of_particles.
+!--    This depends on the selected interpolation method.
+!--    If particle interpolation method is not trilinear, then the sorting within subboxes is not
+!--    required. However, therefore the index start_index(nb) and end_index(nb) are not defined and
+!--    the loops are still over number_of_particles. @todo find a more generic way to write this
+!--    loop or delete trilinear interpolation
        IF ( interpolation_trilinear )  THEN
           subbox_start = 0
@@ -4476,7 +4348,6 @@
        ENDIF
 !
-!--    loop over subboxes. In case of simple interpolation scheme no subboxes
-!--    are introduced, as they are not required. Accordingly, this loops goes
-!--    from 1 to 1.
+!--    loop over subboxes. In case of simple interpolation scheme no subboxes are introduced, as
+!--    they are not required. Accordingly, this loop goes from 1 to 1.
        DO  nb = subbox_start, subbox_end
           IF ( interpolation_trilinear )  THEN
@@ -4507,10 +4378,7 @@
 !
 !--             Transport of particles with inertia
-                particles(n)%x = particles(n)%x + particles(n)%speed_x * &
-                                                  dt_particle(n)
-                particles(n)%y = particles(n)%y + particles(n)%speed_y * &
-                                                  dt_particle(n)
-                particles(n)%z = particles(n)%z + particles(n)%speed_z * &
-                                                  dt_particle(n)
+                particles(n)%x = particles(n)%x + particles(n)%speed_x * dt_particle(n)
+                particles(n)%y = particles(n)%y + particles(n)%speed_y * dt_particle(n)
+                particles(n)%z = particles(n)%z + particles(n)%speed_z * dt_particle(n)
 
 !
@@ -4532,7 +4400,6 @@
                    IF ( use_sgs_for_particles )  THEN
                       lagr_timescale(n) = km(kp,jp,ip) / MAX( e(kp,jp,ip), 1.0E-20_wp )
-                      RL             = EXP( -1.0_wp * dt_3d / MAX( lagr_timescale(n), &
-                                             1.0E-20_wp ) )
-                      sigma          = SQRT( e(kp,jp,ip) )
+                      rl    = EXP( -1.0_wp * dt_3d / MAX( lagr_timescale(n), 1.0E-20_wp ) )
+                      sigma = SQRT( e(kp,jp,ip) )
 !
 !--                   Calculate random component of particle sgs velocity using parallel
@@ -4545,10 +4412,10 @@
                       rg3 = random_dummy
 
-                      particles(n)%rvar1 = RL * particles(n)%rvar1 +              &
-                                           SQRT( 1.0_wp - RL**2 ) * sigma * rg1
-                      particles(n)%rvar2 = RL * particles(n)%rvar2 +              &
-                                           SQRT( 1.0_wp - RL**2 ) * sigma * rg2
-                      particles(n)%rvar3 = RL * particles(n)%rvar3 +              &
-                                           SQRT( 1.0_wp - RL**2 ) * sigma * rg3
+                      particles(n)%rvar1 = rl * particles(n)%rvar1 +                               &
+                                           SQRT( 1.0_wp - rl**2 ) * sigma * rg1
+                      particles(n)%rvar2 = rl * particles(n)%rvar2 +                               &
+                                           SQRT( 1.0_wp - rl**2 ) * sigma * rg2
+                      particles(n)%rvar3 = rl * particles(n)%rvar3 +                               &
+                                           SQRT( 1.0_wp - rl**2 ) * sigma * rg3
 
                       particles(n)%speed_x = u_int(n) + particles(n)%rvar1
@@ -4570,10 +4437,10 @@
                       exp_term = particle_groups(particles(n)%group)%exp_term
                    ENDIF
-                   particles(n)%speed_x = particles(n)%speed_x * exp_term +         &
+                   particles(n)%speed_x = particles(n)%speed_x * exp_term +                        &
                                           u_int(n) * ( 1.0_wp - exp_term )
-                   particles(n)%speed_y = particles(n)%speed_y * exp_term +         &
+                   particles(n)%speed_y = particles(n)%speed_y * exp_term +                        &
                                           v_int(n) * ( 1.0_wp - exp_term )
-                   particles(n)%speed_z = particles(n)%speed_z * exp_term +         &
-                                          ( w_int(n) - ( 1.0_wp - dens_ratio(n) ) * &
+                   particles(n)%speed_z = particles(n)%speed_z * exp_term +                        &
+                                          ( w_int(n) - ( 1.0_wp - dens_ratio(n) ) *                &
                                           g / exp_arg ) * ( 1.0_wp - exp_term )
                 ENDIF
@@ -4585,6 +4452,6 @@
     ELSE
 !
-!--    Decide whether the particle loop runs over the subboxes or only over 1,
-!--    number_of_particles. This depends on the selected interpolation method.
+!--    Decide whether the particle loop runs over the subboxes or only over 1, number_of_particles.
+!--    This depends on the selected interpolation method.
        IF ( interpolation_trilinear )  THEN
           subbox_start = 0
@@ -4594,7 +4461,6 @@
           subbox_end   = 1
        ENDIF
-!--    loop over subboxes. In case of simple interpolation scheme no subboxes
-!--    are introduced, as they are not required. Accordingly, this loops goes
-!--    from 1 to 1.
+!--    loop over subboxes. In case of simple interpolation scheme no subboxes are introduced, as
+!--    they are not required. Accordingly, this loop goes from 1 to 1.
        DO  nb = subbox_start, subbox_end
           IF ( interpolation_trilinear )  THEN
@@ -4618,6 +4484,6 @@
              IF ( cloud_droplets )  THEN
 !
-!--             Terminal velocity is computed for vertical direction (Rogers et al.,
-!--             1993, J. Appl. Meteorol.)
+!--             Terminal velocity is computed for vertical direction (Rogers et al., 1993,
+!--             J. Appl. Meteorol.)
                 diameter = particles(n)%radius * 2000.0_wp !diameter in mm
                 IF ( diameter <= d0_rog )  THEN
@@ -4632,11 +4498,10 @@
                 IF ( use_sgs_for_particles )  THEN
                     lagr_timescale(n) = km(kp,jp,ip) / MAX( e(kp,jp,ip), 1.0E-20_wp )
-                     RL             = EXP( -1.0_wp * dt_3d / MAX( lagr_timescale(n), &
-                                             1.0E-20_wp ) )
-                    sigma          = SQRT( e(kp,jp,ip) )
-
-!
-!--                 Calculate random component of particle sgs velocity using parallel
-!--                 random generator
+                    rl    = EXP( -1.0_wp * dt_3d / MAX( lagr_timescale(n), 1.0E-20_wp ) )
+                    sigma = SQRT( e(kp,jp,ip) )
+
+!
+!--                 Calculate random component of particle sgs velocity using parallel random
+!--                 generator
                     CALL random_number_parallel_gauss( random_dummy )
                     rg1 = random_dummy
@@ -4646,10 +4511,10 @@
                     rg3 = random_dummy
 
-                    particles(n)%rvar1 = RL * particles(n)%rvar1 +                &
-                                         SQRT( 1.0_wp - RL**2 ) * sigma * rg1
-                    particles(n)%rvar2 = RL * particles(n)%rvar2 +                &
-                                         SQRT( 1.0_wp - RL**2 ) * sigma * rg2
-                    particles(n)%rvar3 = RL * particles(n)%rvar3 +                &
-                                         SQRT( 1.0_wp - RL**2 ) * sigma * rg3
+                    particles(n)%rvar1 = rl * particles(n)%rvar1 +                                 &
+                                         SQRT( 1.0_wp - rl**2 ) * sigma * rg1
+                    particles(n)%rvar2 = rl * particles(n)%rvar2 +                                 &
+                                         SQRT( 1.0_wp - rl**2 ) * sigma * rg2
+                    particles(n)%rvar3 = rl * particles(n)%rvar3 +                                 &
+                                         SQRT( 1.0_wp - rl**2 ) * sigma * rg3
 
                     particles(n)%speed_x = u_int(n) + particles(n)%rvar1
@@ -4671,10 +4536,10 @@
                    exp_term = particle_groups(particles(n)%group)%exp_term
                 ENDIF
-                particles(n)%speed_x = particles(n)%speed_x * exp_term +             &
+                particles(n)%speed_x = particles(n)%speed_x * exp_term +                           &
                                        u_int(n) * ( 1.0_wp - exp_term )
-                particles(n)%speed_y = particles(n)%speed_y * exp_term +             &
+                particles(n)%speed_y = particles(n)%speed_y * exp_term +                           &
                                        v_int(n) * ( 1.0_wp - exp_term )
-                particles(n)%speed_z = particles(n)%speed_z * exp_term +             &
-                                       ( w_int(n) - ( 1.0_wp - dens_ratio(n) ) * g / &
+                particles(n)%speed_z = particles(n)%speed_z * exp_term +                           &
+                                       ( w_int(n) - ( 1.0_wp - dens_ratio(n) ) * g /               &
                                        exp_arg ) * ( 1.0_wp - exp_term )
              ENDIF
@@ -4685,16 +4550,14 @@
 
 !
-!-- Store the old age of the particle ( needed to prevent that a
-!-- particle crosses several PEs during one timestep, and for the
-!-- evaluation of the subgrid particle velocity fluctuations )
+!-- Store the old age of the particle ( needed to prevent that a particle crosses several PEs during
+!-- one timestep, and for the evaluation of the subgrid particle velocity fluctuations )
     particles(1:number_of_particles)%age_m = particles(1:number_of_particles)%age
 
 !
-!--    loop over subboxes. In case of simple interpolation scheme no subboxes
-!--    are introduced, as they are not required. Accordingly, this loops goes
-!--    from 1 to 1.
-!
-!-- Decide whether the particle loop runs over the subboxes or only over 1,
-!-- number_of_particles. This depends on the selected interpolation method.
+!--    loop over subboxes. In case of simple interpolation scheme no subboxes are introduced, as
+!--    they are not required. Accordingly, this loop goes from 1 to 1.
+!
+!-- Decide whether the particle loop runs over the subboxes or only over 1, number_of_particles.
+!-- This depends on the selected interpolation method.
     IF ( interpolation_trilinear )  THEN
        subbox_start = 0
@@ -4713,7 +4576,6 @@
        ENDIF
 !
-!--    Loop from particle start to particle end and increment the particle 
-!--    age and the total time that the particle has advanced within the 
-!--    particle timestep procedure.
+!--    Loop from particle start to particle end and increment the particle age and the total time
+!--    that the particle has advanced within the particle timestep procedure.
        DO  n = particle_start, particle_end
           particles(n)%age    = particles(n)%age    + dt_particle(n)
@@ -4722,11 +4584,11 @@
 !
 !--    Particles that leave the child domain during the SGS-timestep loop
-!--    must not continue timestepping until they are transferred to the 
+!--    must not continue timestepping until they are transferred to the
 !--    parent. Hence, set their dt_sum to dt.
        IF ( child_domain  .AND.  use_sgs_for_particles )  THEN
           DO  n = particle_start, particle_end
-             IF ( particles(n)%x < 0.0_wp         .OR.                         &
-                  particles(n)%y < 0.0_wp         .OR.                         &
-                  particles(n)%x > ( nx+1 ) * dx  .OR.                         &
+             IF ( particles(n)%x < 0.0_wp         .OR.                                             &
+                  particles(n)%y < 0.0_wp         .OR.                                             &
+                  particles(n)%x > ( nx+1 ) * dx  .OR.                                             &
                   particles(n)%y < ( ny+1 ) * dy )  THEN
                 particles(n)%dt_sum = dt_3d
@@ -4735,9 +4597,7 @@
        ENDIF
 !
-!--    Check whether there is still a particle that has not yet completed
-!--    the total LES timestep
+!--    Check whether there is still a particle that has not yet completed the total LES timestep
        DO  n = particle_start, particle_end
-          IF ( ( dt_3d - particles(n)%dt_sum ) > 1E-8_wp )                     &
-             dt_3d_reached_l = .FALSE.
+          IF ( ( dt_3d - particles(n)%dt_sum ) > 1E-8_wp )  dt_3d_reached_l = .FALSE.
        ENDDO
     ENDDO
@@ -4748,18 +4608,17 @@
  END SUBROUTINE lpm_advec
 
- 
-!------------------------------------------------------------------------------!  
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Calculation of subgrid-scale particle speed using the stochastic model 
+!> Calculation of subgrid-scale particle speed using the stochastic model
 !> of Weil et al. (2004, JAS, 61, 2877-2887).
-!------------------------------------------------------------------------------! 
- SUBROUTINE weil_stochastic_eq( v_sgs, fs_n, e_n, dedxi_n, dedt_n, diss_n,     &
-                                dt_n, rg_n, fac )
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE weil_stochastic_eq( v_sgs, fs_n, e_n, dedxi_n, dedt_n, diss_n, dt_n, rg_n, fac )
 
     REAL(wp) ::  a1      !< dummy argument
-    REAL(wp) ::  dedt_n  !< time derivative of TKE at particle position 
+    REAL(wp) ::  dedt_n  !< time derivative of TKE at particle position
     REAL(wp) ::  dedxi_n !< horizontal derivative of TKE at particle position
-    REAL(wp) ::  diss_n  !< dissipation at particle position 
+    REAL(wp) ::  diss_n  !< dissipation at particle position
     REAL(wp) ::  dt_n    !< particle timestep
     REAL(wp) ::  e_n     !< TKE at particle position
@@ -4770,37 +4629,32 @@
     REAL(wp) ::  term2   !< drift correction term
     REAL(wp) ::  term3   !< random term
-    REAL(wp) ::  v_sgs   !< subgrid-scale velocity component 
-
-!-- At first, limit TKE to a small non-zero number, in order to prevent 
-!-- the occurrence of extremely large SGS-velocities in case TKE is zero, 
-!-- (could occur at the simulation begin).
+    REAL(wp) ::  v_sgs   !< subgrid-scale velocity component
+
+!-- At first, limit TKE to a small non-zero number, in order to prevent the occurrence of extremely
+!-- large SGS-velocities in case TKE is zero, (could occur at the simulation begin).
     e_n = MAX( e_n, 1E-20_wp )
 !
-!-- Please note, terms 1 and 2 (drift and memory term, respectively) are 
-!-- multiplied by a flag to switch of both terms near topography. 
-!-- This is necessary, as both terms may cause a subgrid-scale velocity build up 
-!-- if particles are trapped in regions with very small TKE, e.g. in narrow street 
-!-- canyons resolved by only a few grid points. Hence, term 1 and term 2 are 
-!-- disabled if one of the adjacent grid points belongs to topography. 
-!-- Moreover, in this case, the  previous subgrid-scale component is also set
-!-- to zero.
+!-- Please note, terms 1 and 2 (drift and memory term, respectively) are multiplied by a flag to
+!-- switch of both terms near topography.
+!-- This is necessary, as both terms may cause a subgrid-scale velocity build up if particles are
+!-- trapped in regions with very small TKE, e.g. in narrow street canyons resolved by only a few
+!-- grid points. Hence, term 1 and term 2 are disabled if one of the adjacent grid points belongs to
+!-- topography.
+!-- Moreover, in this case, the  previous subgrid-scale component is also set to zero.
 
     a1 = fs_n * c_0 * diss_n
 !
 !-- Memory term
-    term1 = - a1 * v_sgs * dt_n / ( 4.0_wp * sgs_wf_part * e_n + 1E-20_wp )    &
-                 * fac
+    term1 = - a1 * v_sgs * dt_n / ( 4.0_wp * sgs_wf_part * e_n + 1E-20_wp ) * fac
 !
 !-- Drift correction term
-    term2 = ( ( dedt_n * v_sgs / e_n ) + dedxi_n ) * 0.5_wp * dt_n              &
-                 * fac
+    term2 = ( ( dedt_n * v_sgs / e_n ) + dedxi_n ) * 0.5_wp * dt_n * fac
 !
 !-- Random term
     term3 = SQRT( MAX( a1, 1E-20_wp ) ) * ( rg_n - 1.0_wp ) * SQRT( dt_n )
 !
-!-- In cese one of the adjacent grid-boxes belongs to topograhy, the previous
-!-- subgrid-scale velocity component is set to zero, in order to prevent a 
-!-- velocity build-up. 
-!-- This case, set also previous subgrid-scale component to zero. 
+!-- In case one of the adjacent grid-boxes belongs to topograhy, the previous subgrid-scale velocity
+!-- component is set to zero, in order to prevent a velocity build-up.
+!-- This case, set also previous subgrid-scale component to zero.
     v_sgs = v_sgs * fac + term1 + term2 + term3
 
@@ -4808,16 +4662,15 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> swap timelevel in case of particle advection interpolation 'simple-corrector'
-!> This routine is called at the end of one timestep, the velocities are then
-!> used for the next timestep
-!------------------------------------------------------------------------------!
+!> This routine is called at the end of one timestep, the velocities are then used for the next
+!> timestep
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_swap_timelevel_for_particle_advection
 
 !
-!-- save the divergence free velocites of t+1 to use them at the end of the
-!-- next time step
+!-- Save the divergence free velocites of t+1 to use them at the end of the next time step
     u_t = u
     v_t = v
@@ -4827,25 +4680,24 @@
 
 
-!------------------------------------------------------------------------------!  
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Boundary conditions for the Lagrangian particles.
-!> The routine consists of two different parts. One handles the bottom (flat)
-!> and top boundary. In this part, also particles which exceeded their lifetime
-!> are deleted.
+!> The routine consists of two different parts. One handles the bottom (flat) and top boundary. In
+!> this part, also particles which exceeded their lifetime are deleted.
 !> The other part handles the reflection of particles from vertical walls.
 !> This part was developed by Jin Zhang during 2006-2007.
 !>
-!> To do: Code structure for finding the t_index values and for checking the
-!> -----  reflection conditions is basically the same for all four cases, so it
-!>        should be possible to further simplify/shorten it.
+!> To do: Code structure for finding the t_index values and for checking the reflection conditions
+!> ------ is basically the same for all four cases, so it should be possible to further
+!>        simplify/shorten it.
 !>
 !> THE WALLS PART OF THIS ROUTINE HAS NOT BEEN TESTED FOR OCEAN RUNS SO FAR!!!!
 !> (see offset_ocean_*)
-!------------------------------------------------------------------------------! 
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_boundary_conds( location_bc , i, j, k )
 
     CHARACTER (LEN=*), INTENT(IN) ::  location_bc !< general mode: boundary conditions at bottom/top of the model domain
-                                   !< or at vertical surfaces (buildings, terrain steps)    
+                                   !< or at vertical surfaces (buildings, terrain steps)
     INTEGER(iwp), INTENT(IN) ::  i !< grid index of particle box along x
     INTEGER(iwp), INTENT(IN) ::  j !< grid index of particle box along y
@@ -4919,25 +4771,23 @@
 
 !
-!--    Apply boundary conditions to those particles that have crossed the top or
-!--    bottom boundary and delete those particles, which are older than allowed
+!--    Apply boundary conditions to those particles that have crossed the top or bottom boundary and
+!--    delete those particles, which are older than allowed
        DO  n = 1, number_of_particles
 
 !
-!--       Stop if particles have moved further than the length of one 
-!--       PE subdomain (newly released particles have age = age_m!)
+!--       Stop if particles have moved further than the length of one PE subdomain (newly released
+!--       particles have age = age_m!)
           IF ( particles(n)%age /= particles(n)%age_m )  THEN
-             IF ( ABS(particles(n)%speed_x) >                                  &
-                  ((nxr-nxl+2)*dx)/(particles(n)%age-particles(n)%age_m)  .OR. &
-                  ABS(particles(n)%speed_y) >                                  &
+             IF ( ABS(particles(n)%speed_x) >                                                      &
+                  ((nxr-nxl+2)*dx)/(particles(n)%age-particles(n)%age_m)  .OR.                     &
+                  ABS(particles(n)%speed_y) >                                                      &
                   ((nyn-nys+2)*dy)/(particles(n)%age-particles(n)%age_m) )  THEN
 
-                  WRITE( message_string, * )  'particle too fast.  n = ',  n 
+                  WRITE( message_string, * )  'particle too fast.  n = ',  n
                   CALL message( 'lpm_boundary_conds', 'PA0148', 2, 2, -1, 6, 1 )
              ENDIF
           ENDIF
 
-          IF ( particles(n)%age > particle_maximum_age  .AND.  &
-               particles(n)%particle_mask )                              &
-          THEN
+          IF ( particles(n)%age > particle_maximum_age  .AND.  particles(n)%particle_mask )  THEN
              particles(n)%particle_mask  = .FALSE.
              deleted_particles = deleted_particles + 1
@@ -5026,8 +4876,8 @@
           k1 = k
 !
-!--       Determine horizontal as well as vertical walls at which particle can 
-!--       be potentially reflected. 
+!--       Determine horizontal as well as vertical walls at which particle can be potentially
+!--       reflected.
 !--       Start with walls aligned in yz layer.
-!--       Wall to the right 
+!--       Wall to the right
           IF ( prt_x > pos_x_old )  THEN
              xwall = ( i1 + 1 ) * dx
@@ -5074,17 +4924,16 @@
           z_wall_reached = .FALSE.
 !
-!--       Initialize time array 
+!--       Initialize time array
           t     = 0.0_wp
 !
-!--       Check if particle can reach any wall. This case, calculate the 
-!--       fractional time needed to reach this wall. Store this fractional
-!--       timestep in array t. Moreover, store indices for these grid
-!--       boxes where the respective wall belongs to.  
+!--       Check if particle can reach any wall. This case, calculate the fractional time needed to
+!--       reach this wall. Store this fractional timestep in array t. Moreover, store indices for
+!--       these grid boxes where the respective wall belongs to.
 !--       Start with x-direction.
           t_index    = 1
-          t(t_index) = ( xwall - pos_x_old )                                   &
-                     / MERGE( MAX( prt_x - pos_x_old,  1E-30_wp ),             &
-                              MIN( prt_x - pos_x_old, -1E-30_wp ),             &
-                              prt_x > pos_x_old )
+          t(t_index) = ( xwall - pos_x_old )                                                       &
+                       / MERGE( MAX( prt_x - pos_x_old,  1E-30_wp ),                               &
+                                MIN( prt_x - pos_x_old, -1E-30_wp ),                               &
+                                prt_x > pos_x_old )
           x_ind(t_index)   = i2
           y_ind(t_index)   = j1
@@ -5094,6 +4943,6 @@
           reach_z(t_index) = .FALSE.
 !
-!--       Store these values only if particle really reaches any wall. t must 
-!--       be in a interval between [0:1].
+!--       Store these values only if particle really reaches any wall. t must be in an interval
+!--       between [0:1].
           IF ( t(t_index) <= 1.0_wp  .AND.  t(t_index) >= 0.0_wp )  THEN
              t_index      = t_index + 1
@@ -5102,8 +4951,8 @@
 !
 !--       y-direction
-          t(t_index) = ( ywall - pos_y_old )                                   &
-                     / MERGE( MAX( prt_y - pos_y_old,  1E-30_wp ),             &
-                              MIN( prt_y - pos_y_old, -1E-30_wp ),             &
-                              prt_y > pos_y_old )
+          t(t_index) = ( ywall - pos_y_old )                                                       &
+                       / MERGE( MAX( prt_y - pos_y_old,  1E-30_wp ),                               &
+                                MIN( prt_y - pos_y_old, -1E-30_wp ),                               &
+                                prt_y > pos_y_old )
           x_ind(t_index)   = i1
           y_ind(t_index)   = j2
@@ -5118,8 +4967,8 @@
 !
 !--       z-direction
-          t(t_index) = (zwall - pos_z_old )                                    &
-                     / MERGE( MAX( prt_z - pos_z_old,  1E-30_wp ),             &
-                              MIN( prt_z - pos_z_old, -1E-30_wp ),             &
-                              prt_z > pos_z_old )
+          t(t_index) = (zwall - pos_z_old )                                                        &
+                       / MERGE( MAX( prt_z - pos_z_old,  1E-30_wp ),                               &
+                                MIN( prt_z - pos_z_old, -1E-30_wp ),                               &
+                                prt_z > pos_z_old )
 
           x_ind(t_index)   = i1
@@ -5139,7 +4988,6 @@
           IF ( cross_wall_x  .OR.  cross_wall_y  .OR.  cross_wall_z )  THEN
 !
-!--          Sort fractional timesteps in ascending order. Also sort the 
-!--          corresponding indices and flag according to the time interval a  
-!--          particle reaches the respective wall.
+!--          Sort fractional timesteps in ascending order. Also sort the corresponding indices and
+!--          flag according to the time interval a particle reaches the respective wall.
              inc = 1
              jr  = 1
@@ -5187,17 +5035,13 @@
 !--          Loop over all times a particle possibly moves into a new grid box
              t_old = 0.0_wp
-             DO t_index = 1, t_index_number 
-!
-!--             Calculate intermediate particle position according to the 
-!--             timesteps a particle reaches any wall.
-                pos_x = pos_x + ( t(t_index) - t_old ) * dt_particle           &
-                                                       * particles(n)%speed_x
-                pos_y = pos_y + ( t(t_index) - t_old ) * dt_particle           &
-                                                       * particles(n)%speed_y
-                pos_z = pos_z + ( t(t_index) - t_old ) * dt_particle           &
-                                                       * particles(n)%speed_z
-!
-!--             Obtain x/y grid indices for intermediate particle position from
-!--             sorted index array
+             DO t_index = 1, t_index_number
+!
+!--             Calculate intermediate particle position according to the timesteps a particle
+!--             reaches any wall.
+                pos_x = pos_x + ( t(t_index) - t_old ) * dt_particle * particles(n)%speed_x
+                pos_y = pos_y + ( t(t_index) - t_old ) * dt_particle * particles(n)%speed_y
+                pos_z = pos_z + ( t(t_index) - t_old ) * dt_particle * particles(n)%speed_z
+!
+!--             Obtain x/y grid indices for intermediate particle position from sorted index array
                 i3 = x_ind(t_index)
                 j3 = y_ind(t_index)
@@ -5205,29 +5049,27 @@
 !
 !--             Check which wall is already reached
-                IF ( .NOT. x_wall_reached )  x_wall_reached = reach_x(t_index) 
+                IF ( .NOT. x_wall_reached )  x_wall_reached = reach_x(t_index)
                 IF ( .NOT. y_wall_reached )  y_wall_reached = reach_y(t_index)
                 IF ( .NOT. z_wall_reached )  z_wall_reached = reach_z(t_index)
 !
-!--             Check if a particle needs to be reflected at any yz-wall. If 
-!--             necessary, carry out reflection. Please note, a security 
-!--             constant is required, as the particle position does not 
-!--             necessarily exactly match the wall location due to rounding 
-!--             errors.
-                IF ( reach_x(t_index)                      .AND.               & 
-                     ABS( pos_x - xwall ) < eps            .AND.               &
-                     .NOT. BTEST(wall_flags_total_0(k3,j3,i3),0) .AND.         &
+!--             Check if a particle needs to be reflected at any yz-wall. If necessary, carry out
+!--             reflection. Please note, a security constant is required, as the particle position
+!--             does not necessarily exactly match the wall location due to rounding  errors.
+                IF ( reach_x(t_index)                            .AND.                             &
+                     ABS( pos_x - xwall ) < eps                  .AND.                             &
+                     .NOT. BTEST(wall_flags_total_0(k3,j3,i3),0) .AND.                             &
                      .NOT. reflect_x )  THEN
-! 
-! 
-!--                Reflection in x-direction. 
-!--                Ensure correct reflection by MIN/MAX functions, depending on
-!--                direction of particle transport. 
-!--                Due to rounding errors pos_x does not exactly match the wall
-!--                location, leading to erroneous reflection.             
-                   pos_x = MERGE( MIN( 2.0_wp * xwall - pos_x, xwall ),        &
-                                  MAX( 2.0_wp * xwall - pos_x, xwall ),        &
+!
+!
+!--                Reflection in x-direction.
+!--                Ensure correct reflection by MIN/MAX functions, depending on direction of
+!--                particle transport.
+!--                Due to rounding errors pos_x does not exactly match the wall location, leading to
+!--                erroneous reflection.
+                   pos_x = MERGE( MIN( 2.0_wp * xwall - pos_x, xwall ),                            &
+                                  MAX( 2.0_wp * xwall - pos_x, xwall ),                            &
                                   particles(n)%x > xwall )
 !
-!--                Change sign of particle speed                     
+!--                Change sign of particle speed
                    particles(n)%speed_x = - particles(n)%speed_x
 !
@@ -5238,36 +5080,34 @@
                    reflect_x          = .TRUE.
 !
-!--                As the particle does not cross any further yz-wall during 
-!--                this timestep, set further x-indices to the current one.
+!--                As the particle does not cross any further yz-wall during this timestep, set
+!--                further x-indices to the current one.
                    x_ind(t_index:t_index_number) = i1
 !
-!--             If particle already reached the wall but was not reflected, 
-!--             set further x-indices to the new one.
-                ELSEIF ( x_wall_reached .AND. .NOT. reflect_x )  THEN
+!--             If particle already reached the wall but was not reflected, set further x-indices to
+!--             the new one.
+                ELSEIF ( x_wall_reached  .AND.  .NOT. reflect_x )  THEN
                     x_ind(t_index:t_index_number) = i2
-                ENDIF !particle reflection in x direction done
-
-!
-!--             Check if a particle needs to be reflected at any xz-wall. If 
-!--             necessary, carry out reflection. Please note, a security 
-!--             constant is required, as the particle position does not 
-!--             necessarily exactly match the wall location due to rounding 
-!--             errors. 
-                IF ( reach_y(t_index)                      .AND.               & 
-                     ABS( pos_y - ywall ) < eps            .AND.               &
-                     .NOT. BTEST(wall_flags_total_0(k3,j3,i3),0) .AND.         &
+                ENDIF  !particle reflection in x direction done
+
+!
+!--             Check if a particle needs to be reflected at any xz-wall. If necessary, carry out
+!--             reflection. Please note, a security constant is required, as the particle position
+!--             does not necessarily exactly match the wall location due to rounding errors.
+                IF ( reach_y(t_index)                            .AND.                             &
+                     ABS( pos_y - ywall ) < eps                  .AND.                             &
+                     .NOT. BTEST(wall_flags_total_0(k3,j3,i3),0) .AND.                             &
                      .NOT. reflect_y )  THEN
-! 
-! 
-!--                Reflection in y-direction. 
-!--                Ensure correct reflection by MIN/MAX functions, depending on
-!--                direction of particle transport. 
-!--                Due to rounding errors pos_y does not exactly match the wall
-!--                location, leading to erroneous reflection.             
-                   pos_y = MERGE( MIN( 2.0_wp * ywall - pos_y, ywall ),        &
-                                  MAX( 2.0_wp * ywall - pos_y, ywall ),        &
+!
+!
+!--                Reflection in y-direction.
+!--                Ensure correct reflection by MIN/MAX functions, depending on direction of
+!--                particle transport.
+!--                Due to rounding errors pos_y does not exactly match the wall location, leading to
+!--                erroneous reflection.
+                   pos_y = MERGE( MIN( 2.0_wp * ywall - pos_y, ywall ),                            &
+                                  MAX( 2.0_wp * ywall - pos_y, ywall ),                            &
                                   particles(n)%y > ywall )
 !
-!--                Change sign of particle speed                     
+!--                Change sign of particle speed
                    particles(n)%speed_y = - particles(n)%speed_y
 !
@@ -5278,36 +5118,34 @@
                    reflect_y          = .TRUE.
 !
-!--                As the particle does not cross any further xz-wall during 
-!--                this timestep, set further y-indices to the current one.
+!--                As the particle does not cross any further xz-wall during this timestep, set
+!--                further y-indices to the current one.
                    y_ind(t_index:t_index_number) = j1
 !
-!--             If particle already reached the wall but was not reflected, 
-!--             set further y-indices to the new one.
-                ELSEIF ( y_wall_reached .AND. .NOT. reflect_y )  THEN
+!--             If particle already reached the wall but was not reflected, set further y-indices to
+!--             the new one.
+                ELSEIF ( y_wall_reached  .AND.  .NOT. reflect_y )  THEN
                     y_ind(t_index:t_index_number) = j2
-                ENDIF !particle reflection in y direction done
-
-!
-!--             Check if a particle needs to be reflected at any xy-wall. If 
-!--             necessary, carry out reflection. Please note, a security 
-!--             constant is required, as the particle position does not 
-!--             necessarily exactly match the wall location due to rounding 
-!--             errors. 
-                IF ( reach_z(t_index)                      .AND.               & 
-                     ABS( pos_z - zwall ) < eps            .AND.               &
-                     .NOT. BTEST(wall_flags_total_0(k3,j3,i3),0) .AND.         &
+                ENDIF  !particle reflection in y direction done
+
+!
+!--             Check if a particle needs to be reflected at any xy-wall. If necessary, carry out
+!--             reflection. Please note, a security constant is required, as the particle position
+!--             does not necessarily exactly match the wall location due to rounding errors.
+                IF ( reach_z(t_index)                            .AND.                             &
+                     ABS( pos_z - zwall ) < eps                  .AND.                             &
+                     .NOT. BTEST(wall_flags_total_0(k3,j3,i3),0) .AND.                             &
                      .NOT. reflect_z )  THEN
-! 
-! 
-!--                Reflection in z-direction. 
-!--                Ensure correct reflection by MIN/MAX functions, depending on
-!--                direction of particle transport. 
-!--                Due to rounding errors pos_z does not exactly match the wall
-!--                location, leading to erroneous reflection.             
-                   pos_z = MERGE( MIN( 2.0_wp * zwall - pos_z, zwall ),        &
-                                  MAX( 2.0_wp * zwall - pos_z, zwall ),        &
+!
+!
+!--                Reflection in z-direction.
+!--                Ensure correct reflection by MIN/MAX functions, depending on direction of
+!--                particle transport.
+!--                Due to rounding errors pos_z does not exactly match the wall location, leading to
+!--                erroneous reflection.
+                   pos_z = MERGE( MIN( 2.0_wp * zwall - pos_z, zwall ),                            &
+                                  MAX( 2.0_wp * zwall - pos_z, zwall ),                            &
                                   particles(n)%z > zwall )
 !
-!--                Change sign of particle speed                     
+!--                Change sign of particle speed
                    particles(n)%speed_z = - particles(n)%speed_z
 !
@@ -5318,13 +5156,13 @@
                    reflect_z          = .TRUE.
 !
-!--                As the particle does not cross any further xy-wall during 
-!--                this timestep, set further z-indices to the current one.
+!--                As the particle does not cross any further xy-wall during this timestep, set
+!--                further z-indices to the current one.
                    z_ind(t_index:t_index_number) = k1
 !
-!--             If particle already reached the wall but was not reflected, 
-!--             set further z-indices to the new one.
-                ELSEIF ( z_wall_reached .AND. .NOT. reflect_z )  THEN
+!--             If particle already reached the wall but was not reflected, set further z-indices to
+!--             the new one.
+                ELSEIF ( z_wall_reached  .AND.  .NOT. reflect_z )  THEN
                     z_ind(t_index:t_index_number) = k2
-                ENDIF !particle reflection in z direction done                
+                ENDIF  !particle reflection in z direction done
 
 !
@@ -5334,14 +5172,10 @@
              ENDDO
 !
-!--          If a particle was reflected, calculate final position from last
-!--          intermediate position.
+!--          If a particle was reflected, calculate final position from last intermediate position.
              IF ( reflect_x  .OR.  reflect_y  .OR.  reflect_z )  THEN
 
-                particles(n)%x = pos_x + ( 1.0_wp - t_old ) * dt_particle      &
-                                                         * particles(n)%speed_x
-                particles(n)%y = pos_y + ( 1.0_wp - t_old ) * dt_particle      &
-                                                         * particles(n)%speed_y
-                particles(n)%z = pos_z + ( 1.0_wp - t_old ) * dt_particle      &
-                                                         * particles(n)%speed_z
+                particles(n)%x = pos_x + ( 1.0_wp - t_old ) * dt_particle * particles(n)%speed_x
+                particles(n)%y = pos_y + ( 1.0_wp - t_old ) * dt_particle * particles(n)%speed_y
+                particles(n)%z = pos_z + ( 1.0_wp - t_old ) * dt_particle * particles(n)%speed_z
 
              ENDIF
@@ -5358,23 +5192,37 @@
     END SELECT
 
- END SUBROUTINE lpm_boundary_conds 
-
-
-!------------------------------------------------------------------------------!
+ END SUBROUTINE lpm_boundary_conds
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Calculates change in droplet radius by condensation/evaporation, using
-!> either an analytic formula or by numerically integrating the radius growth
-!> equation including curvature and solution effects using Rosenbrocks method
-!> (see Numerical recipes in FORTRAN, 2nd edition, p. 731).
+!> Calculates change in droplet radius by condensation/evaporation, using either an analytic formula
+!> or by numerically integrating the radius growth equation including curvature and solution effects
+!> using Rosenbrocks method (see Numerical recipes in FORTRAN, 2nd edition, p. 731).
 !> The analytical formula and growth equation follow those given in
 !> Rogers and Yau (A short course in cloud physics, 3rd edition, p. 102/103).
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_droplet_condensation (i,j,k)
+
+!
+!-- Parameters for Rosenbrock method (see Verwer et al., 1999)
+    REAL(wp), PARAMETER ::  prec = 1.0E-3_wp     !< precision of Rosenbrock solution
+    REAL(wp), PARAMETER ::  q_increase = 1.5_wp  !< increase factor in timestep
+    REAL(wp), PARAMETER ::  q_decrease = 0.9_wp  !< decrease factor in timestep
+    REAL(wp), PARAMETER ::  gamma = 0.292893218814_wp !< = 1.0 - 1.0 / SQRT(2.0)
+!
+!-- Parameters for terminal velocity
+    REAL(wp), PARAMETER ::  a_rog = 9.65_wp      !< parameter for fall velocity
+    REAL(wp), PARAMETER ::  b_rog = 10.43_wp     !< parameter for fall velocity
+    REAL(wp), PARAMETER ::  c_rog = 0.6_wp       !< parameter for fall velocity
+    REAL(wp), PARAMETER ::  k_cap_rog = 4.0_wp   !< parameter for fall velocity
+    REAL(wp), PARAMETER ::  k_low_rog = 12.0_wp  !< parameter for fall velocity
+    REAL(wp), PARAMETER ::  d0_rog = 0.745_wp    !< separation diameter
 
     INTEGER(iwp), INTENT(IN) ::  i              !<
     INTEGER(iwp), INTENT(IN) ::  j              !<
     INTEGER(iwp), INTENT(IN) ::  k              !<
-    INTEGER(iwp) ::  n                          !<
+    INTEGER(iwp)             ::  n              !<
 
     REAL(wp) ::  afactor                       !< curvature effects
@@ -5398,26 +5246,12 @@
     REAL(wp) ::  r_ros_ini                     !< initial Rosenbrock radius
     REAL(wp) ::  r0                            !< gas-kinetic lengthscale
+    REAL(wp) ::  re_p                          !< particle Reynolds number
     REAL(wp) ::  sigma                         !< surface tension of water
     REAL(wp) ::  thermal_conductivity          !< thermal conductivity for water
     REAL(wp) ::  t_int                         !< temperature
     REAL(wp) ::  w_s                           !< terminal velocity of droplets
-    REAL(wp) ::  re_p                          !< particle Reynolds number
-!
-!-- Parameters for Rosenbrock method (see Verwer et al., 1999)
-    REAL(wp), PARAMETER ::  prec = 1.0E-3_wp     !< precision of Rosenbrock solution
-    REAL(wp), PARAMETER ::  q_increase = 1.5_wp  !< increase factor in timestep
-    REAL(wp), PARAMETER ::  q_decrease = 0.9_wp  !< decrease factor in timestep
-    REAL(wp), PARAMETER ::  gamma = 0.292893218814_wp !< = 1.0 - 1.0 / SQRT(2.0)
-!
-!-- Parameters for terminal velocity
-    REAL(wp), PARAMETER ::  a_rog = 9.65_wp      !< parameter for fall velocity
-    REAL(wp), PARAMETER ::  b_rog = 10.43_wp     !< parameter for fall velocity
-    REAL(wp), PARAMETER ::  c_rog = 0.6_wp       !< parameter for fall velocity
-    REAL(wp), PARAMETER ::  k_cap_rog = 4.0_wp   !< parameter for fall velocity
-    REAL(wp), PARAMETER ::  k_low_rog = 12.0_wp  !< parameter for fall velocity
-    REAL(wp), PARAMETER ::  d0_rog = 0.745_wp    !< separation diameter
-
+
+    REAL(wp), DIMENSION(number_of_particles) ::  new_r                  !<
     REAL(wp), DIMENSION(number_of_particles) ::  ventilation_effect     !<
-    REAL(wp), DIMENSION(number_of_particles) ::  new_r                  !<
 
     CALL cpu_log( log_point_s(42), 'lpm_droplet_condens', 'start' )
@@ -5437,6 +5271,5 @@
 !
 !-- Moldecular diffusivity of water vapor in air (Hall und Pruppacher, 1976)
-    diff_coeff           = 0.211E-4_wp * ( t_int / 273.15_wp )**1.94_wp * &
-                           ( 101325.0_wp / hyp(k) )
+    diff_coeff           = 0.211E-4_wp * ( t_int / 273.15_wp )**1.94_wp * ( 101325.0_wp / hyp(k) )
 !
 !-- Lengthscale for gas-kinetic effects (from Mordy, 1959, p. 23):
@@ -5445,7 +5278,7 @@
 !-- Calculate effects of heat conductivity and diffusion of water vapor on the
 !-- diffusional growth process (usually known as 1.0 / (F_k + F_d) )
-    ddenom  = 1.0_wp / ( rho_l * r_v * t_int / ( e_s * diff_coeff ) +          &
-                         ( l_v / ( r_v * t_int ) - 1.0_wp ) * rho_l *          &
-                         l_v / ( thermal_conductivity * t_int )                &
+    ddenom  = 1.0_wp / ( rho_l * r_v * t_int / ( e_s * diff_coeff ) +                              &
+                         ( l_v / ( r_v * t_int ) - 1.0_wp ) * rho_l *                              &
+                         l_v / ( thermal_conductivity * t_int )                                    &
                        )
     new_r = 0.0_wp
@@ -5458,5 +5291,5 @@
 !--       Terminal velocity is computed for vertical direction (Rogers et al.,
 !--       1993, J. Appl. Meteorol.)
-          diameter = particles(n)%radius * 2000.0_wp !diameter in mm
+          diameter = particles(n)%radius * 2000.0_wp  !diameter in mm
           IF ( diameter <= d0_rog )  THEN
              w_s = k_cap_rog * diameter * ( 1.0_wp - EXP( -k_low_rog * diameter ) )
@@ -5476,6 +5309,6 @@
        ELSE
 !
-!--       For small droplets or in supersaturated environments, the ventilation
-!--       effect does not play a role
+!--       For small droplets or in supersaturated environments, the ventilation effect does not play
+!--       a role.
           ventilation_effect(n) = 1.0_wp
        ENDIF
@@ -5484,9 +5317,9 @@
     IF( .NOT. curvature_solution_effects )  THEN
 !
-!--    Use analytic model for diffusional growth including gas-kinetic
-!--    effects (Mordy, 1959) but without the impact of aerosols.
+!--    Use analytic model for diffusional growth including gas-kinetic effects (Mordy, 1959) but
+!--    without the impact of aerosols.
        DO  n = 1, number_of_particles
-          arg      = ( particles(n)%radius + r0 )**2 + 2.0_wp * dt_3d * ddenom * &
-                                                       ventilation_effect(n) *   &
+          arg      = ( particles(n)%radius + r0 )**2 + 2.0_wp * dt_3d * ddenom *                   &
+                                                       ventilation_effect(n)   *                   &
                                                        ( e_a / e_s - 1.0_wp )
           arg      = MAX( arg, ( 0.01E-6 + r0 )**2 )
@@ -5508,5 +5341,5 @@
 !
 !--       Solute effect (bfactor)
-          bfactor = vanthoff * rho_s * particles(n)%aux1**3 *                    &
+          bfactor = vanthoff * rho_s * particles(n)%aux1**3 *                                      &
                     molecular_weight_of_water / ( rho_l * molecular_weight_of_solute )
 
@@ -5518,6 +5351,6 @@
 !
 !--       Integrate growth equation using a 2nd-order Rosenbrock method
-!--       (see Verwer et al., 1999, Eq. (3.2)). The Rosenbrock method adjusts
-!--       its with internal timestep to minimize the local truncation error.
+!--       (see Verwer et al., 1999, Eq. (3.2)). The Rosenbrock method adjusts its with internal
+!--       timestep to minimize the local truncation error.
           DO WHILE ( dt_ros_sum < dt_3d )
 
@@ -5526,16 +5359,16 @@
              DO
 
-                drdt = ddenom * ventilation_effect(n) * ( e_a / e_s - 1.0_wp - &
-                                                          afactor / r_ros +    &
-                                                          bfactor / r_ros**3   &
+                drdt = ddenom * ventilation_effect(n) * ( e_a / e_s - 1.0_wp -                     &
+                                                          afactor / r_ros +                        &
+                                                          bfactor / r_ros**3                       &
                                                         ) / ( r_ros + r0 )
 
-                d2rdtdr = -ddenom * ventilation_effect(n) * (                  &
-                                            (e_a / e_s - 1.0_wp ) * r_ros**4 - &
-                                            afactor * r0 * r_ros**2 -          &
-                                            2.0_wp * afactor * r_ros**3 +      &
-                                            3.0_wp * bfactor * r0 +            &
-                                            4.0_wp * bfactor * r_ros           &
-                                                            )                  &
+                d2rdtdr = -ddenom * ventilation_effect(n) *  (                                     &
+                                            ( e_a / e_s - 1.0_wp ) * r_ros**4 -                    &
+                                            afactor * r0 * r_ros**2 -                              &
+                                            2.0_wp * afactor * r_ros**3 +                          &
+                                            3.0_wp * bfactor * r0 +                                &
+                                            4.0_wp * bfactor * r_ros                               &
+                                                             )                                     &
                           / ( r_ros**4 * ( r_ros + r0 )**2 )
 
@@ -5545,15 +5378,15 @@
                 r_err = r_ros
 
-                drdt  = ddenom * ventilation_effect(n) * ( e_a / e_s - 1.0_wp - &
-                                                           afactor / r_ros +    &
-                                                           bfactor / r_ros**3   &
+                drdt  = ddenom * ventilation_effect(n) * ( e_a / e_s - 1.0_wp -                    &
+                                                           afactor / r_ros +                       &
+                                                           bfactor / r_ros**3                      &
                                                          ) / ( r_ros + r0 )
 
-                k2 = ( drdt - dt_ros * 2.0 * gamma * d2rdtdr * k1 ) / &
+                k2 = ( drdt - dt_ros * 2.0 * gamma * d2rdtdr * k1 ) /                              &
                      ( 1.0_wp - dt_ros * gamma * d2rdtdr )
 
                 r_ros = MAX(r_ros_ini + dt_ros * ( 1.5_wp * k1 + 0.5_wp * k2), particles(n)%aux1)
-   !
-   !--          Check error of the solution, and reduce dt_ros if necessary.
+!
+!--             Check error of the solution, and reduce dt_ros if necessary.
                 error = ABS(r_err - r_ros) / r_ros
                 IF ( error > prec )  THEN
@@ -5569,5 +5402,5 @@
              END DO
 
-          END DO !Rosenbrock loop
+          END DO  !Rosenbrock loop
 !
 !--       Store new particle radius
@@ -5583,41 +5416,39 @@
     DO  n = 1, number_of_particles
 !
-!--    Sum up the change in liquid water for the respective grid
-!--    box for the computation of the release/depletion of water vapor
-!--    and heat.
-       ql_c(k,j,i) = ql_c(k,j,i) + particles(n)%weight_factor *          &
-                                   rho_l * 1.33333333_wp * pi *                &
-                                   ( new_r(n)**3 - particles(n)%radius**3 ) /  &
+!--    Sum up the change in liquid water for the respective grid box for the computation of the
+!--    release/depletion of water vapor and heat.
+       ql_c(k,j,i) = ql_c(k,j,i) + particles(n)%weight_factor *                                    &
+                                   rho_l * 1.33333333_wp * pi *                                    &
+                                   ( new_r(n)**3 - particles(n)%radius**3 ) /                      &
                                    ( rho_surface * dx * dy * dzw(k) )
 !
-!--    Check if the increase in liqid water is not too big. If this is the case,
-!--    the model timestep might be too long.
+!--    Check if the increase in liqid water is not too big. If this is the case, the model timestep
+!--    might be too long.
        IF ( ql_c(k,j,i) > 100.0_wp )  THEN
-          WRITE( message_string, * ) 'k=',k,' j=',j,' i=',i,                &
-                       ' ql_c=',ql_c(k,j,i), '&part(',n,')%wf=',            &
-                       particles(n)%weight_factor,' delta_r=',delta_r
+          WRITE( message_string, * ) 'k=',k,' j=',j,' i=',i,                                       &
+                                     ' ql_c=',ql_c(k,j,i), '&part(',n,')%wf=',                     &
+                                     particles(n)%weight_factor,' delta_r=',delta_r
           CALL message( 'lpm_droplet_condensation', 'PA0143', 2, 2, -1, 6, 1 )
        ENDIF
 !
-!--    Check if the change in the droplet radius is not too big. If this is the
-!--    case, the model timestep might be too long.
+!--    Check if the change in the droplet radius is not too big. If this is the case, the model
+!--    timestep might be too long.
        delta_r = new_r(n) - particles(n)%radius
        IF ( delta_r < 0.0_wp  .AND.  new_r(n) < 0.0_wp )  THEN
-          WRITE( message_string, * ) '#1 k=',k,' j=',j,' i=',i,                &
-                       ' e_s=',e_s, ' e_a=',e_a,' t_int=',t_int,               &
-                       '&delta_r=',delta_r,                                    &
-                       ' particle_radius=',particles(n)%radius
+          WRITE( message_string, * ) '#1 k=',k,' j=',j,' i=',i,                                    &
+                                     ' e_s=',e_s, ' e_a=',e_a,' t_int=',t_int,                     &
+                                     '&delta_r=',delta_r,                                          &
+                                     ' particle_radius=',particles(n)%radius
           CALL message( 'lpm_droplet_condensation', 'PA0144', 2, 2, -1, 6, 1 )
        ENDIF
 !
-!--    Sum up the total volume of liquid water (needed below for
-!--    re-calculating the weighting factors)
+!--    Sum up the total volume of liquid water (needed below for re-calculating the weighting
+!--    factors)
        ql_v(k,j,i) = ql_v(k,j,i) + particles(n)%weight_factor * new_r(n)**3
 !
 !--    Determine radius class of the particle needed for collision
        IF ( use_kernel_tables )  THEN
-          particles(n)%class = ( LOG( new_r(n) ) - rclass_lbound ) /           &
-                               ( rclass_ubound - rclass_lbound ) *             &
-                               radius_classes
+          particles(n)%class = ( LOG( new_r(n) ) - rclass_lbound ) /                               &
+                               ( rclass_ubound - rclass_lbound ) * radius_classes
           particles(n)%class = MIN( particles(n)%class, radius_classes )
           particles(n)%class = MAX( particles(n)%class, 1 )
@@ -5635,10 +5466,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Release of latent heat and change of mixing ratio due to condensation /
-!> evaporation of droplets.
-!------------------------------------------------------------------------------!
+!> Release of latent heat and change of mixing ratio due to condensation / evaporation of droplets.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_interaction_droplets_ptq
 
@@ -5657,6 +5487,5 @@
 
              q(k,j,i)  = q(k,j,i)  - ql_c(k,j,i) * flag
-             pt(k,j,i) = pt(k,j,i) + lv_d_cp * ql_c(k,j,i) * d_exner(k) &
-                                                           * flag
+             pt(k,j,i) = pt(k,j,i) + lv_d_cp * ql_c(k,j,i) * d_exner(k) * flag
           ENDDO
        ENDDO
@@ -5666,10 +5495,10 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Release of latent heat and change of mixing ratio due to condensation /
-!> evaporation of droplets. Call for grid point i,j
-!------------------------------------------------------------------------------!
+!> Release of latent heat and change of mixing ratio due to condensation / evaporation of droplets.
+!> Call for grid point i,j
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_interaction_droplets_ptq_ij( i, j )
 
@@ -5693,9 +5522,9 @@
 
 
-!------------------------------------------------------------------------------! 
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Calculate the liquid water content for each grid box.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_calc_liquid_water_content
 
@@ -5721,21 +5550,16 @@
              particles => grid_particles(k,j,i)%particles(1:number_of_particles)
 !
-!--          Calculate the total volume in the boxes (ql_v, weighting factor
-!--          has to beincluded)
+!--          Calculate the total volume in the boxes (ql_v, weighting factor has to beincluded)
              DO  n = 1, prt_count(k,j,i)
-                ql_v(k,j,i)  = ql_v(k,j,i)  + particles(n)%weight_factor *     &
-                                              particles(n)%radius**3
+                ql_v(k,j,i)  = ql_v(k,j,i)  + particles(n)%weight_factor * particles(n)%radius**3
              ENDDO
 !
 !--          Calculate the liquid water content
              IF ( ql_v(k,j,i) /= 0.0_wp )  THEN
-                ql(k,j,i) = ql(k,j,i) + rho_l * 1.33333333_wp * pi *           &
-                                        ql_v(k,j,i) /                          &
-                                        ( rho_surface * dx * dy * dzw(k) )
+                ql(k,j,i) = ql(k,j,i) + rho_l * 1.33333333_wp * pi *                               &
+                                        ql_v(k,j,i) / ( rho_surface * dx * dy * dzw(k) )
                 IF ( ql(k,j,i) < 0.0_wp )  THEN
-                   WRITE( message_string, * )  'LWC out of range: ' , &
-                                               ql(k,j,i),i,j,k
-                   CALL message( 'lpm_calc_liquid_water_content', 'PA0719',    &
-                                   2, 2, -1, 6, 1 )
+                   WRITE( message_string, * )  'LWC out of range: ' , ql(k,j,i),i,j,k
+                   CALL message( 'lpm_calc_liquid_water_content', 'PA0719', 2, 2, -1, 6, 1 )
                 ENDIF
              ELSE
@@ -5751,21 +5575,20 @@
 
 
-!------------------------------------------------------------------------------! 
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Calculates change in droplet radius by collision. Droplet collision is
-!> calculated for each grid box seperately. Collision is parameterized by
-!> using collision kernels. Two different kernels are available:
-!> Hall kernel: Kernel from Hall (1980, J. Atmos. Sci., 2486-2507), which
-!>              considers collision due to pure gravitational effects.
-!> Wang kernel: Beside gravitational effects (treated with the Hall-kernel) also
-!>              the effects of turbulence on the collision are considered using
-!>              parameterizations of Ayala et al. (2008, New J. Phys., 10,
-!>              075015) and Wang and Grabowski (2009, Atmos. Sci. Lett., 10,
-!>              1-8). This kernel includes three possible effects of turbulence:
+!> Calculates change in droplet radius by collision. Droplet collision is calculated for each grid
+!> box seperately. Collision is parameterized by using collision kernels. Two different kernels are
+!> available:
+!> Hall kernel: Kernel from Hall (1980, J. Atmos. Sci., 2486-2507), which considers collision due to
+!>              pure gravitational effects.
+!> Wang kernel: Beside gravitational effects (treated with the Hall-kernel) also the effects of
+!>              turbulence on the collision are considered using parameterizations of Ayala et al.
+!>              (2008, New J. Phys., 10, 075015) and Wang and Grabowski (2009, Atmos. Sci. Lett.,
+!>              10, 1-8). This kernel includes three possible effects of turbulence:
 !>              the modification of the relative velocity between the droplets,
-!>              the effect of preferential concentration, and the enhancement of
-!>              collision efficiencies.
-!------------------------------------------------------------------------------! 
+!>              the effect of preferential concentration,
+!>              and the enhancement of collision efficiencies.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_droplet_collision (i,j,k)
 
@@ -5789,7 +5612,7 @@
     REAL(wp) ::  xsn                     !< aerosol mass of super-droplet n
 
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  aero_mass !< total aerosol mass of super droplet
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  mass      !< total mass of super droplet
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  weight    !< weighting factor
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  mass      !< total mass of super droplet
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  aero_mass !< total aerosol mass of super droplet
 
     CALL cpu_log( log_point_s(43), 'lpm_droplet_coll', 'start' )
@@ -5804,9 +5627,8 @@
        IF ( use_kernel_tables )  THEN
 !
-!--       Fast method with pre-calculated collection kernels for
-!--       discrete radius- and dissipation-classes.
+!--       Fast method with pre-calculated collection kernels for discrete radius- and
+!--       dissipation-classes.
           IF ( wang_kernel )  THEN
-             eclass = INT( diss(k,j,i) * 1.0E4_wp / 600.0_wp * &
-                           dissipation_classes ) + 1
+             eclass = INT( diss(k,j,i) * 1.0E4_wp / 600.0_wp * dissipation_classes ) + 1
              epsilon_collision = diss(k,j,i)
           ELSE
@@ -5822,23 +5644,22 @@
        ELSE
 !
-!--       Collection kernels are re-calculated for every new
-!--       grid box. First, allocate memory for kernel table.
-!--       Third dimension is 1, because table is re-calculated for
-!--       every new dissipation value.
+!--       Collection kernels are re-calculated for every new grid box. First, allocate memory for
+!--       kernel table.
+!--       Third dimension is 1, because table is re-calculated for every new dissipation value.
           ALLOCATE( ckernel(1:number_of_particles,1:number_of_particles,1:1) )
 !
-!--       Now calculate collection kernel for this box. Note that
-!--       the kernel is based on the previous time step
+!--       Now calculate collection kernel for this box. Note that the kernel is based on the
+!--       previous time step
           CALL recalculate_kernel( i, j, k )
 
        ENDIF
 !
-!--    Temporary fields for total mass of super-droplet, aerosol mass, and
-!--    weighting factor are allocated.
+!--    Temporary fields for total mass of super-droplet, aerosol mass, and weighting factor are
+!--    allocated.
        ALLOCATE(mass(1:number_of_particles), weight(1:number_of_particles))
        IF ( curvature_solution_effects )  ALLOCATE(aero_mass(1:number_of_particles))
 
-       mass(1:number_of_particles)   = particles(1:number_of_particles)%weight_factor * &
-                                       particles(1:number_of_particles)%radius**3     * &
+       mass(1:number_of_particles)   = particles(1:number_of_particles)%weight_factor *            &
+                                       particles(1:number_of_particles)%radius**3     *            &
                                        factor_volume_to_mass
 
@@ -5846,6 +5667,6 @@
 
        IF ( curvature_solution_effects )  THEN
-          aero_mass(1:number_of_particles) = particles(1:number_of_particles)%weight_factor * &
-                                             particles(1:number_of_particles)%aux1**3       * &
+          aero_mass(1:number_of_particles) = particles(1:number_of_particles)%weight_factor *      &
+                                             particles(1:number_of_particles)%aux1**3       *      &
                                              4.0_wp / 3.0_wp * pi * rho_s
        ENDIF
@@ -5856,6 +5677,6 @@
           DO  m = n, number_of_particles
 !
-!--          For collisions, the weighting factor of at least one super-droplet
-!--          needs to be larger or equal to one.
+!--          For collisions, the weighting factor of at least one super-droplet needs to be larger
+!--          or equal to one.
              IF ( MIN( weight(n), weight(m) ) < 1.0_wp )  CYCLE
 !
@@ -5873,8 +5694,8 @@
                 rclass_s = particles(m)%class
 
-                collection_probability  = MAX( weight(n), weight(m) ) *     &
+                collection_probability  = MAX( weight(n), weight(m) ) *                            &
                                           ckernel(rclass_l,rclass_s,eclass) * ddV * dt_3d
              ELSE
-                collection_probability  = MAX( weight(n), weight(m) ) *     &
+                collection_probability  = MAX( weight(n), weight(m) ) *                            &
                                           ckernel(n,m,1) * ddV * dt_3d
              ENDIF
@@ -5883,6 +5704,5 @@
 !--          (Accordingly, p_crit will be 0.0, 1.0, 2.0, ...)
              CALL random_number_parallel( random_dummy )
-             IF ( collection_probability - FLOOR(collection_probability)    &
-                  > random_dummy )  THEN
+             IF ( collection_probability - FLOOR(collection_probability) > random_dummy )  THEN
                 collection_probability = FLOOR(collection_probability) + 1.0_wp
              ELSE
@@ -5919,11 +5739,9 @@
 !--                particle m collects 1/2 weight(m) droplets of particle n.
 !--                The total mass mass changes accordingly.
-!--                If n = m, the first half of the droplets coalesces with the
-!--                second half of the droplets; mass is unchanged because
-!--                xm = xn for n = m.
+!--                If n = m, the first half of the droplets coalesces with the second half of the
+!--                droplets; mass is unchanged because xm = xn for n = m.
 !--
-!--                Note: For m = n this equation is an approximation only
-!--                valid for weight >> 1 (which is usually the case). The
-!--                approximation is weight(n)-1 = weight(n).
+!--                Note: For m = n this equation is an approximation only valid for weight >> 1
+!--                (which is usually the case). The approximation is weight(n)-1 = weight(n).
                    mass(n)   = mass(n)   + 0.5_wp * weight(n) * ( xm - xn )
                    mass(m)   = mass(m)   + 0.5_wp * weight(m) * ( xn - xm )
@@ -5947,19 +5765,18 @@
        IF ( ANY(weight < 0.0_wp) )  THEN
              WRITE( message_string, * ) 'negative weighting factor'
-             CALL message( 'lpm_droplet_collision', 'PA0028',      &
-                            2, 2, -1, 6, 1 )
+             CALL message( 'lpm_droplet_collision', 'PA0028', 2, 2, -1, 6, 1 )
        ENDIF
 
-       particles(1:number_of_particles)%radius = ( mass(1:number_of_particles) /   &
-                                                   ( weight(1:number_of_particles) &
-                                                     * factor_volume_to_mass       &
-                                                   )                               &
+       particles(1:number_of_particles)%radius = ( mass(1:number_of_particles) /                   &
+                                                    ( weight(1:number_of_particles)                &
+                                                      * factor_volume_to_mass                      &
+                                                    )                                              &
                                                  )**0.33333333333333_wp
 
        IF ( curvature_solution_effects )  THEN
-          particles(1:number_of_particles)%aux1 = ( aero_mass(1:number_of_particles) / &
-                                                    ( weight(1:number_of_particles)    &
-                                                      * 4.0_wp / 3.0_wp * pi * rho_s   &
-                                                    )                                  &
+          particles(1:number_of_particles)%aux1 = ( aero_mass(1:number_of_particles) /             &
+                                                     ( weight(1:number_of_particles)               &
+                                                       * 4.0_wp / 3.0_wp * pi * rho_s              &
+                                                     )                                             &
                                                   )**0.33333333333333_wp
        ENDIF
@@ -5974,9 +5791,8 @@
 !--    Check if LWC is conserved during collision process
        IF ( ql_v(k,j,i) /= 0.0_wp )  THEN
-          IF ( ql_vp(k,j,i) / ql_v(k,j,i) >= 1.0001_wp  .OR.                      &
+          IF ( ql_vp(k,j,i) / ql_v(k,j,i) >= 1.0001_wp  .OR.                                       &
                ql_vp(k,j,i) / ql_v(k,j,i) <= 0.9999_wp )  THEN
-             WRITE( message_string, * ) ' LWC is not conserved during',           &
-                                        ' collision! ',                           &
-                                        ' LWC after condensation: ', ql_v(k,j,i), &
+             WRITE( message_string, * ) ' LWC is not conserved during',' collision! ',             &
+                                        ' LWC after condensation: ', ql_v(k,j,i),                  &
                                         ' LWC after collision: ', ql_vp(k,j,i)
              CALL message( 'lpm_droplet_collision', 'PA0040', 2, 2, -1, 6, 1 )
@@ -5989,11 +5805,11 @@
 
  END SUBROUTINE lpm_droplet_collision
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Initialization of the collision efficiency matrix with fixed radius and
-!> dissipation classes, calculated at simulation start only.
-!------------------------------------------------------------------------------! 
+!> Initialization of the collision efficiency matrix with fixed radius and dissipation classes,
+!> calculated at simulation start only.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_init_kernels
 
@@ -6001,23 +5817,22 @@
     INTEGER(iwp) ::  j !<
     INTEGER(iwp) ::  k !<
-    
-!
-!-- Calculate collision efficiencies for fixed radius- and dissipation
-!-- classes
+
+!
+!-- Calculate collision efficiencies for fixed radius- and dissipation classes
     IF ( collision_kernel(6:9) == 'fast' )  THEN
 
-       ALLOCATE( ckernel(1:radius_classes,1:radius_classes,                 &
-                 0:dissipation_classes), epsclass(1:dissipation_classes),   &
+       ALLOCATE( ckernel(1:radius_classes,1:radius_classes,0:dissipation_classes),                 &
+                 epsclass(1:dissipation_classes),                                                  &
                  radclass(1:radius_classes) )
 
 !
-!--    Calculate the radius class bounds with logarithmic distances
-!--    in the interval [1.0E-6, 1000.0E-6] m
+!--    Calculate the radius class bounds with logarithmic distances in the interval
+!--    [1.0E-6, 1000.0E-6] m
        rclass_lbound = LOG( 1.0E-6_wp )
        rclass_ubound = LOG( 1000.0E-6_wp )
        radclass(1)   = EXP( rclass_lbound )
        DO  i = 2, radius_classes
-          radclass(i) = EXP( rclass_lbound +                                &
-                             ( rclass_ubound - rclass_lbound ) *            &
+          radclass(i) = EXP( rclass_lbound +                                                       &
+                             ( rclass_ubound - rclass_lbound ) *                                   &
                              ( i - 1.0_wp ) / ( radius_classes - 1.0_wp ) )
        ENDDO
@@ -6030,7 +5845,7 @@
 !
 !--    Calculate collision efficiencies of the Wang/ayala kernel
-       ALLOCATE( ec(1:radius_classes,1:radius_classes),  &
-                 ecf(1:radius_classes,1:radius_classes), &
-                 gck(1:radius_classes,1:radius_classes), &
+       ALLOCATE( ec(1:radius_classes,1:radius_classes),                                            &
+                 ecf(1:radius_classes,1:radius_classes),                                           &
+                 gck(1:radius_classes,1:radius_classes),                                           &
                  winf(1:radius_classes) )
 
@@ -6054,5 +5869,5 @@
 !
 !--    Calculate collision efficiencies of the Hall kernel
-       ALLOCATE( hkernel(1:radius_classes,1:radius_classes), &
+       ALLOCATE( hkernel(1:radius_classes,1:radius_classes),                                       &
                  hwratio(1:radius_classes,1:radius_classes) )
 
@@ -6062,5 +5877,5 @@
        DO  j = 1, radius_classes
           DO  i =  1, radius_classes
-             hkernel(i,j) = pi * ( radclass(j) + radclass(i) )**2 &
+             hkernel(i,j) = pi * ( radclass(j) + radclass(i) )**2                                  &
                                * ec(i,j) * ABS( winf(j) - winf(i) )
              ckernel(i,j,0) = hkernel(i,j)  ! hall kernel stored on index 0
@@ -6072,9 +5887,7 @@
        IF ( j == -1 )  THEN
           PRINT*, '*** Hall kernel'
-          WRITE ( *,'(5X,20(F4.0,1X))' ) ( radclass(i)*1.0E6_wp, &
-                                           i = 1,radius_classes )
+          WRITE ( *,'(5X,20(F4.0,1X))' ) ( radclass(i)*1.0E6_wp, i = 1,radius_classes )
           DO  j = 1, radius_classes
-             WRITE ( *,'(F4.0,1X,20(F8.4,1X))' ) radclass(j),  &
-                                       ( hkernel(i,j), i = 1,radius_classes )
+             WRITE ( *,'(F4.0,1X,20(F8.4,1X))' ) radclass(j), ( hkernel(i,j), i = 1,radius_classes )
           ENDDO
 
@@ -6091,9 +5904,8 @@
 
              PRINT*, '*** epsilon = ', epsclass(k)
-             WRITE ( *,'(5X,20(F4.0,1X))' ) ( radclass(i) * 1.0E6_wp, &
-                                              i = 1,radius_classes )
+             WRITE ( *,'(5X,20(F4.0,1X))' ) ( radclass(i) * 1.0E6_wp, i = 1,radius_classes )
              DO  j = 1, radius_classes
-                WRITE ( *,'(F4.0,1X,20(F8.4,1X))' ) radclass(j) * 1.0E6_wp, &
-                                       ( hwratio(i,j), i = 1,radius_classes )
+                WRITE ( *,'(F4.0,1X,20(F8.4,1X))' ) radclass(j) * 1.0E6_wp,                        &
+                                                    ( hwratio(i,j), i = 1,radius_classes )
              ENDDO
           ENDDO
@@ -6105,10 +5917,10 @@
 
  END SUBROUTINE lpm_init_kernels
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Calculation of collision kernels during each timestep and for each grid box
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE recalculate_kernel( i1, j1, k1 )
 
@@ -6123,8 +5935,8 @@
     number_of_particles = prt_count(k1,j1,i1)
     radius_classes      = number_of_particles   ! necessary to use the same
-                                                ! subroutines as for 
+                                                ! subroutines as for
                                                 ! precalculated kernels
 
-    ALLOCATE( ec(1:number_of_particles,1:number_of_particles), &
+    ALLOCATE( ec(1:number_of_particles,1:number_of_particles),                                     &
               radclass(1:number_of_particles), winf(1:number_of_particles) )
 
@@ -6143,5 +5955,5 @@
 !
 !--    Call routines to calculate efficiencies for the Wang kernel
-       ALLOCATE( gck(1:number_of_particles,1:number_of_particles), &
+       ALLOCATE( gck(1:number_of_particles,1:number_of_particles),                                 &
                  ecf(1:number_of_particles,1:number_of_particles) )
 
@@ -6165,5 +5977,5 @@
        DO  j = 1, number_of_particles
           DO  i =  1, number_of_particles
-             ckernel(i,j,1) = pi * ( radclass(j) + radclass(i) )**2         &
+             ckernel(i,j,1) = pi * ( radclass(j) + radclass(i) )**2                                &
                                  * ec(i,j) * ABS( winf(j) - winf(i) )
           ENDDO
@@ -6175,16 +5987,14 @@
  END SUBROUTINE recalculate_kernel
 
-!------------------------------------------------------------------------------! 
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Calculation of effects of turbulence on the geometric collision kernel 
-!> (by including the droplets' average radial relative velocities and their 
-!> radial distribution function) following the analytic model by Aayala et al. 
-!> (2008, New J. Phys.). For details check the second part 2 of the publication,
-!> page 37ff.
+!> Calculation of effects of turbulence on the geometric collision kernel (by including the
+!> droplets' average radial relative velocities and their radial distribution function) following
+!> the analytic model by Aayala et al. (2008, New J. Phys.). For details check the second part 2 of
+!> the publication, page 37ff.
 !>
-!> Input parameters, which need to be replaced by PALM parameters:
-!>    water density, air density
-!------------------------------------------------------------------------------!
+!> Input parameters, which need to be replaced by PALM parameters: water density, air density
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE turbsd
 
@@ -6284,11 +6094,11 @@
           t2  = tau(j)
 
-          v1xysq  = b1 * d1 * phi_w(c1,e1,v1,t1) - b1 * d2 * phi_w(c1,e2,v1,t1) &
-                  - b2 * d1 * phi_w(c2,e1,v1,t1) + b2 * d2 * phi_w(c2,e2,v1,t1)
+          v1xysq  =   b1 * d1 * phi_w(c1,e1,v1,t1) - b1 * d2 * phi_w(c1,e2,v1,t1)                  &
+                    - b2 * d1 * phi_w(c2,e1,v1,t1) + b2 * d2 * phi_w(c2,e2,v1,t1)
           v1xysq  = v1xysq * urms**2 / t1
           vrms1xy = SQRT( v1xysq )
 
-          v2xysq  = b1 * d1 * phi_w(c1,e1,v2,t2) - b1 * d2 * phi_w(c1,e2,v2,t2) &
-                  - b2 * d1 * phi_w(c2,e1,v2,t2) + b2 * d2 * phi_w(c2,e2,v2,t2)
+          v2xysq  =   b1 * d1 * phi_w(c1,e1,v2,t2) - b1 * d2 * phi_w(c1,e2,v2,t2)                  &
+                    - b2 * d1 * phi_w(c2,e1,v2,t2) + b2 * d2 * phi_w(c2,e2,v2,t2)
           v2xysq  = v2xysq * urms**2 / t2
           vrms2xy = SQRT( v2xysq )
@@ -6306,7 +6116,7 @@
           ENDIF
 
-          v1v2xy   =  b1 * d1 * zhi(c1,e1,v1,t1,v2,t2) - &
-                      b1 * d2 * zhi(c1,e2,v1,t1,v2,t2) - &
-                      b2 * d1 * zhi(c2,e1,v1,t1,v2,t2) + &
+          v1v2xy   =  b1 * d1 * zhi(c1,e1,v1,t1,v2,t2) -                                           &
+                      b1 * d2 * zhi(c1,e2,v1,t1,v2,t2) -                                           &
+                      b2 * d1 * zhi(c2,e1,v1,t1,v2,t2) +                                           &
                       b2 * d2* zhi(c2,e2,v1,t1,v2,t2)
           fr       = d1 * EXP( -rrp / e1 ) - d2 * EXP( -rrp / e2 )
@@ -6325,6 +6135,5 @@
           ENDIF
 
-          xx = -0.1988_wp * sst**4 + 1.5275_wp * sst**3 - 4.2942_wp *       &
-                sst**2 + 5.3406_wp * sst
+          xx = -0.1988_wp * sst**4 + 1.5275_wp * sst**3 - 4.2942_wp * sst**2 + 5.3406_wp * sst
           IF ( xx < 0.0_wp )  xx = 0.0_wp
           yy = 0.1886_wp * EXP( 20.306_wp / lambda_re )
@@ -6340,6 +6149,5 @@
 
 !
-!--       Calculate general collection kernel (without the consideration of
-!--       collection efficiencies)
+!--       Calculate general collection kernel (without the consideration of collection efficiencies)
           gck(i,j) = 2.0_wp * pi * rrp**2 * wrfin * grfin
           gck(j,i) = gck(i,j)
@@ -6352,7 +6160,7 @@
  REAL(wp) FUNCTION phi_w( a, b, vsett, tau0 )
 !
-!-- Function used in the Ayala et al. (2008) analytical model for turbulent
-!-- effects on the collision kernel
-    
+!-- Function used in the Ayala et al. (2008) analytical model for turbulent effects on the
+!-- collision kernel
+
 
     REAL(wp) ::  a     !<
@@ -6369,6 +6177,6 @@
  REAL(wp) FUNCTION zhi( a, b, vsett1, tau1, vsett2, tau2 )
 !
-!-- Function used in the Ayala et al. (2008) analytical model for turbulent
-!-- effects on the collision kernel
+!-- Function used in the Ayala et al. (2008) analytical model for turbulent effects on the collision
+!-- kernel
 
     REAL(wp) ::  a      !<
@@ -6390,9 +6198,8 @@
     aa4 = ( vsett2 / b )**2 - ( 1.0_wp / tau2 + 1.0_wp / a )**2
     aa5 = vsett2 / b + 1.0_wp / tau2 + 1.0_wp / a
-    aa6 = 1.0_wp / tau1 - 1.0_wp / a + ( 1.0_wp / tau2 + 1.0_wp / a) *      &
-          vsett1 / vsett2
-    zhi = (1.0_wp / aa1 - 1.0_wp / aa2 ) * ( vsett1 - vsett2 ) * 0.5_wp /   &
-          b / aa3**2 + ( 4.0_wp / aa4 - 1.0_wp / aa5**2 - 1.0_wp / aa1**2 ) &
-          * vsett2 * 0.5_wp / b /aa6 + ( 2.0_wp * ( b / aa2 - b / aa1 ) -   &
+    aa6 = 1.0_wp / tau1 - 1.0_wp / a + ( 1.0_wp / tau2 + 1.0_wp / a) * vsett1 / vsett2
+    zhi = ( 1.0_wp / aa1 - 1.0_wp / aa2 ) * ( vsett1 - vsett2 ) * 0.5_wp /                         &
+          b / aa3**2 + ( 4.0_wp / aa4 - 1.0_wp / aa5**2 - 1.0_wp / aa1**2 )                        &
+          * vsett2 * 0.5_wp / b /aa6 + ( 2.0_wp * ( b / aa2 - b / aa1 ) -                          &
           vsett1 / aa2**2 + vsett2 / aa1**2 ) * 0.5_wp / b / aa3
 
@@ -6400,20 +6207,19 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Parameterization of terminal velocity following Rogers et al. (1993, J. Appl.
-!> Meteorol.)
-!------------------------------------------------------------------------------!
+!> Parameterization of terminal velocity following Rogers et al. (1993, J. Appl.Meteorol.)
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE fallg
 
     INTEGER(iwp) ::  j                            !<
 
-    REAL(wp), PARAMETER ::  k_cap_rog = 4.0_wp    !< parameter
-    REAL(wp), PARAMETER ::  k_low_rog = 12.0_wp   !< parameter
     REAL(wp), PARAMETER ::  a_rog     = 9.65_wp   !< parameter
     REAL(wp), PARAMETER ::  b_rog     = 10.43_wp  !< parameter
     REAL(wp), PARAMETER ::  c_rog     = 0.6_wp    !< parameter
     REAL(wp), PARAMETER ::  d0_rog    = 0.745_wp  !< seperation diameter
+    REAL(wp), PARAMETER ::  k_cap_rog = 4.0_wp    !< parameter
+    REAL(wp), PARAMETER ::  k_low_rog = 12.0_wp   !< parameter
 
     REAL(wp)            ::  diameter              !< droplet diameter in mm
@@ -6425,6 +6231,5 @@
 
        IF ( diameter <= d0_rog )  THEN
-          winf(j) = k_cap_rog * diameter * ( 1.0_wp -                       &
-                                             EXP( -k_low_rog * diameter ) )
+          winf(j) = k_cap_rog * diameter * ( 1.0_wp - EXP( -k_low_rog * diameter ) )
        ELSE
           winf(j) = a_rog - b_rog * EXP( -c_rog * diameter )
@@ -6436,11 +6241,11 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Interpolation of collision efficiencies (Hall, 1980, J. Atmos. Sci.)
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE effic
- 
+
     INTEGER(iwp) ::  i  !<
     INTEGER(iwp) ::  iq !<
@@ -6460,7 +6265,7 @@
 
     REAL(wp), DIMENSION(1:21), SAVE ::  rat        !<
-    
+
     REAL(wp), DIMENSION(1:15), SAVE ::  r0         !<
-    
+
     REAL(wp), DIMENSION(1:15,1:21), SAVE ::  ecoll !<
 
@@ -6470,81 +6275,81 @@
 
       first = .FALSE.
-      r0  = (/   6.0_wp,   8.0_wp,  10.0_wp, 15.0_wp,  20.0_wp,  25.0_wp,   &
-                30.0_wp,  40.0_wp,  50.0_wp, 60.0_wp,  70.0_wp, 100.0_wp,   &
+      r0  = (/   6.0_wp,   8.0_wp,  10.0_wp, 15.0_wp,  20.0_wp,  25.0_wp,                          &
+                30.0_wp,  40.0_wp,  50.0_wp, 60.0_wp,  70.0_wp, 100.0_wp,                          &
                150.0_wp, 200.0_wp, 300.0_wp /)
 
-      rat = (/ 0.00_wp, 0.05_wp, 0.10_wp, 0.15_wp, 0.20_wp, 0.25_wp,        &
-               0.30_wp, 0.35_wp, 0.40_wp, 0.45_wp, 0.50_wp, 0.55_wp,        &
-               0.60_wp, 0.65_wp, 0.70_wp, 0.75_wp, 0.80_wp, 0.85_wp,        &
+      rat = (/ 0.00_wp, 0.05_wp, 0.10_wp, 0.15_wp, 0.20_wp, 0.25_wp,                               &
+               0.30_wp, 0.35_wp, 0.40_wp, 0.45_wp, 0.50_wp, 0.55_wp,                               &
+               0.60_wp, 0.65_wp, 0.70_wp, 0.75_wp, 0.80_wp, 0.85_wp,                               &
                0.90_wp, 0.95_wp, 1.00_wp /)
 
-      ecoll(:,1)  = (/ 0.001_wp, 0.001_wp, 0.001_wp, 0.001_wp, 0.001_wp,    &
-                       0.001_wp, 0.001_wp, 0.001_wp, 0.001_wp, 0.001_wp,    &
+      ecoll(:,1)  = (/ 0.001_wp, 0.001_wp, 0.001_wp, 0.001_wp, 0.001_wp,                           &
+                       0.001_wp, 0.001_wp, 0.001_wp, 0.001_wp, 0.001_wp,                           &
                        0.001_wp, 0.001_wp, 0.001_wp, 0.001_wp, 0.001_wp /)
-      ecoll(:,2)  = (/ 0.003_wp, 0.003_wp, 0.003_wp, 0.004_wp, 0.005_wp,    &
-                       0.005_wp, 0.005_wp, 0.010_wp, 0.100_wp, 0.050_wp,    &
+      ecoll(:,2)  = (/ 0.003_wp, 0.003_wp, 0.003_wp, 0.004_wp, 0.005_wp,                           &
+                       0.005_wp, 0.005_wp, 0.010_wp, 0.100_wp, 0.050_wp,                           &
                        0.200_wp, 0.500_wp, 0.770_wp, 0.870_wp, 0.970_wp /)
-      ecoll(:,3)  = (/ 0.007_wp, 0.007_wp, 0.007_wp, 0.008_wp, 0.009_wp,    &
-                       0.010_wp, 0.010_wp, 0.070_wp, 0.400_wp, 0.430_wp,    &
+      ecoll(:,3)  = (/ 0.007_wp, 0.007_wp, 0.007_wp, 0.008_wp, 0.009_wp,                           &
+                       0.010_wp, 0.010_wp, 0.070_wp, 0.400_wp, 0.430_wp,                           &
                        0.580_wp, 0.790_wp, 0.930_wp, 0.960_wp, 1.000_wp /)
-      ecoll(:,4)  = (/ 0.009_wp, 0.009_wp, 0.009_wp, 0.012_wp, 0.015_wp,    &
-                       0.010_wp, 0.020_wp, 0.280_wp, 0.600_wp, 0.640_wp,    &
+      ecoll(:,4)  = (/ 0.009_wp, 0.009_wp, 0.009_wp, 0.012_wp, 0.015_wp,                           &
+                       0.010_wp, 0.020_wp, 0.280_wp, 0.600_wp, 0.640_wp,                           &
                        0.750_wp, 0.910_wp, 0.970_wp, 0.980_wp, 1.000_wp /)
-      ecoll(:,5)  = (/ 0.014_wp, 0.014_wp, 0.014_wp, 0.015_wp, 0.016_wp,    &
-                       0.030_wp, 0.060_wp, 0.500_wp, 0.700_wp, 0.770_wp,    &
+      ecoll(:,5)  = (/ 0.014_wp, 0.014_wp, 0.014_wp, 0.015_wp, 0.016_wp,                           &
+                       0.030_wp, 0.060_wp, 0.500_wp, 0.700_wp, 0.770_wp,                           &
                        0.840_wp, 0.950_wp, 0.970_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,6)  = (/ 0.017_wp, 0.017_wp, 0.017_wp, 0.020_wp, 0.022_wp,    &
-                       0.060_wp, 0.100_wp, 0.620_wp, 0.780_wp, 0.840_wp,    &
+      ecoll(:,6)  = (/ 0.017_wp, 0.017_wp, 0.017_wp, 0.020_wp, 0.022_wp,                           &
+                       0.060_wp, 0.100_wp, 0.620_wp, 0.780_wp, 0.840_wp,                           &
                        0.880_wp, 0.950_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,7)  = (/ 0.030_wp, 0.030_wp, 0.024_wp, 0.022_wp, 0.032_wp,    &
-                       0.062_wp, 0.200_wp, 0.680_wp, 0.830_wp, 0.870_wp,    &
+      ecoll(:,7)  = (/ 0.030_wp, 0.030_wp, 0.024_wp, 0.022_wp, 0.032_wp,                           &
+                       0.062_wp, 0.200_wp, 0.680_wp, 0.830_wp, 0.870_wp,                           &
                        0.900_wp, 0.950_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,8)  = (/ 0.025_wp, 0.025_wp, 0.025_wp, 0.036_wp, 0.043_wp,    &
-                       0.130_wp, 0.270_wp, 0.740_wp, 0.860_wp, 0.890_wp,    &
+      ecoll(:,8)  = (/ 0.025_wp, 0.025_wp, 0.025_wp, 0.036_wp, 0.043_wp,                           &
+                       0.130_wp, 0.270_wp, 0.740_wp, 0.860_wp, 0.890_wp,                           &
                        0.920_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,9)  = (/ 0.027_wp, 0.027_wp, 0.027_wp, 0.040_wp, 0.052_wp,    &
-                       0.200_wp, 0.400_wp, 0.780_wp, 0.880_wp, 0.900_wp,    &
+      ecoll(:,9)  = (/ 0.027_wp, 0.027_wp, 0.027_wp, 0.040_wp, 0.052_wp,                           &
+                       0.200_wp, 0.400_wp, 0.780_wp, 0.880_wp, 0.900_wp,                           &
                        0.940_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,10) = (/ 0.030_wp, 0.030_wp, 0.030_wp, 0.047_wp, 0.064_wp,    &
-                       0.250_wp, 0.500_wp, 0.800_wp, 0.900_wp, 0.910_wp,    &
+      ecoll(:,10) = (/ 0.030_wp, 0.030_wp, 0.030_wp, 0.047_wp, 0.064_wp,                           &
+                       0.250_wp, 0.500_wp, 0.800_wp, 0.900_wp, 0.910_wp,                           &
                        0.950_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,11) = (/ 0.040_wp, 0.040_wp, 0.033_wp, 0.037_wp, 0.068_wp,    &
-                       0.240_wp, 0.550_wp, 0.800_wp, 0.900_wp, 0.910_wp,    &
+      ecoll(:,11) = (/ 0.040_wp, 0.040_wp, 0.033_wp, 0.037_wp, 0.068_wp,                           &
+                       0.240_wp, 0.550_wp, 0.800_wp, 0.900_wp, 0.910_wp,                           &
                        0.950_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,12) = (/ 0.035_wp, 0.035_wp, 0.035_wp, 0.055_wp, 0.079_wp,    &
-                       0.290_wp, 0.580_wp, 0.800_wp, 0.900_wp, 0.910_wp,    &
+      ecoll(:,12) = (/ 0.035_wp, 0.035_wp, 0.035_wp, 0.055_wp, 0.079_wp,                           &
+                       0.290_wp, 0.580_wp, 0.800_wp, 0.900_wp, 0.910_wp,                           &
                        0.950_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,13) = (/ 0.037_wp, 0.037_wp, 0.037_wp, 0.062_wp, 0.082_wp,    &
-                       0.290_wp, 0.590_wp, 0.780_wp, 0.900_wp, 0.910_wp,    &
+      ecoll(:,13) = (/ 0.037_wp, 0.037_wp, 0.037_wp, 0.062_wp, 0.082_wp,                           &
+                       0.290_wp, 0.590_wp, 0.780_wp, 0.900_wp, 0.910_wp,                           &
                        0.950_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,14) = (/ 0.037_wp, 0.037_wp, 0.037_wp, 0.060_wp, 0.080_wp,    &
-                       0.290_wp, 0.580_wp, 0.770_wp, 0.890_wp, 0.910_wp,    &
+      ecoll(:,14) = (/ 0.037_wp, 0.037_wp, 0.037_wp, 0.060_wp, 0.080_wp,                           &
+                       0.290_wp, 0.580_wp, 0.770_wp, 0.890_wp, 0.910_wp,                           &
                        0.950_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,15) = (/ 0.037_wp, 0.037_wp, 0.037_wp, 0.041_wp, 0.075_wp,    &
-                       0.250_wp, 0.540_wp, 0.760_wp, 0.880_wp, 0.920_wp,    &
+      ecoll(:,15) = (/ 0.037_wp, 0.037_wp, 0.037_wp, 0.041_wp, 0.075_wp,                           &
+                       0.250_wp, 0.540_wp, 0.760_wp, 0.880_wp, 0.920_wp,                           &
                        0.950_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,16) = (/ 0.037_wp, 0.037_wp, 0.037_wp, 0.052_wp, 0.067_wp,    &
-                       0.250_wp, 0.510_wp, 0.770_wp, 0.880_wp, 0.930_wp,    &
+      ecoll(:,16) = (/ 0.037_wp, 0.037_wp, 0.037_wp, 0.052_wp, 0.067_wp,                           &
+                       0.250_wp, 0.510_wp, 0.770_wp, 0.880_wp, 0.930_wp,                           &
                        0.970_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,17) = (/ 0.037_wp, 0.037_wp, 0.037_wp, 0.047_wp, 0.057_wp,    &
-                       0.250_wp, 0.490_wp, 0.770_wp, 0.890_wp, 0.950_wp,    &
+      ecoll(:,17) = (/ 0.037_wp, 0.037_wp, 0.037_wp, 0.047_wp, 0.057_wp,                           &
+                       0.250_wp, 0.490_wp, 0.770_wp, 0.890_wp, 0.950_wp,                           &
                        1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp, 1.000_wp /)
-      ecoll(:,18) = (/ 0.036_wp, 0.036_wp, 0.036_wp, 0.042_wp, 0.048_wp,    &
-                       0.230_wp, 0.470_wp, 0.780_wp, 0.920_wp, 1.000_wp,    &
+      ecoll(:,18) = (/ 0.036_wp, 0.036_wp, 0.036_wp, 0.042_wp, 0.048_wp,                           &
+                       0.230_wp, 0.470_wp, 0.780_wp, 0.920_wp, 1.000_wp,                           &
                        1.020_wp, 1.020_wp, 1.020_wp, 1.020_wp, 1.020_wp /)
-      ecoll(:,19) = (/ 0.040_wp, 0.040_wp, 0.035_wp, 0.033_wp, 0.040_wp,    &
-                       0.112_wp, 0.450_wp, 0.790_wp, 1.010_wp, 1.030_wp,    &
+      ecoll(:,19) = (/ 0.040_wp, 0.040_wp, 0.035_wp, 0.033_wp, 0.040_wp,                           &
+                       0.112_wp, 0.450_wp, 0.790_wp, 1.010_wp, 1.030_wp,                           &
                        1.040_wp, 1.040_wp, 1.040_wp, 1.040_wp, 1.040_wp /)
-      ecoll(:,20) = (/ 0.033_wp, 0.033_wp, 0.033_wp, 0.033_wp, 0.033_wp,    &
-                       0.119_wp, 0.470_wp, 0.950_wp, 1.300_wp, 1.700_wp,    &
+      ecoll(:,20) = (/ 0.033_wp, 0.033_wp, 0.033_wp, 0.033_wp, 0.033_wp,                           &
+                       0.119_wp, 0.470_wp, 0.950_wp, 1.300_wp, 1.700_wp,                           &
                        2.300_wp, 2.300_wp, 2.300_wp, 2.300_wp, 2.300_wp /)
-      ecoll(:,21) = (/ 0.027_wp, 0.027_wp, 0.027_wp, 0.027_wp, 0.027_wp,    &
-                       0.125_wp, 0.520_wp, 1.400_wp, 2.300_wp, 3.000_wp,    &
+      ecoll(:,21) = (/ 0.027_wp, 0.027_wp, 0.027_wp, 0.027_wp, 0.027_wp,                           &
+                       0.125_wp, 0.520_wp, 1.400_wp, 2.300_wp, 3.000_wp,                           &
                        4.000_wp, 4.000_wp, 4.000_wp, 4.000_wp, 4.000_wp /)
     ENDIF
 
 !
-!-- Calculate the radius class index of particles with respect to array r
-!-- Radius has to be in microns
+!-- Calculate the radius class index of particles with respect to array r.
+!-- Radius has to be in microns.
     ALLOCATE( ira(1:radius_classes) )
     DO  j = 1, radius_classes
@@ -6561,5 +6366,5 @@
 !
 !-- Two-dimensional linear interpolation of the collision efficiency.
-!-- Radius has to be in microns
+!-- Radius has to be in microns.
     DO  j = 1, radius_classes
        DO  i = 1, j
@@ -6572,11 +6377,10 @@
           IF ( ir < 16 )  THEN
              IF ( ir >= 2 )  THEN
-                pp = ( ( MAX( radclass(j), radclass(i) ) * 1.0E6_wp ) -     &
-                       r0(ir-1) ) / ( r0(ir) - r0(ir-1) )
+                pp = ( ( MAX( radclass(j), radclass(i) ) * 1.0E6_wp ) - r0(ir-1) )                 &
+                     / ( r0(ir) - r0(ir-1) )
                 qq = ( rq - rat(iq-1) ) / ( rat(iq) - rat(iq-1) )
-                ec(j,i) = ( 1.0_wp - pp ) * ( 1.0_wp - qq )                 &
-                          * ecoll(ir-1,iq-1)                                &
-                          + pp * ( 1.0_wp - qq ) * ecoll(ir,iq-1)           &
-                          + qq * ( 1.0_wp - pp ) * ecoll(ir-1,iq)           &
+                ec(j,i) = ( 1.0_wp - pp ) * ( 1.0_wp - qq ) * ecoll(ir-1,iq-1)                     &
+                          + pp * ( 1.0_wp - qq ) * ecoll(ir,iq-1)                                  &
+                          + qq * ( 1.0_wp - pp ) * ecoll(ir-1,iq)                                  &
                           + pp * qq * ecoll(ir,iq)
              ELSE
@@ -6602,10 +6406,10 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Interpolation of turbulent enhancement factor for collision efficencies
-!> following Wang and Grabowski (2009, Atmos. Sci. Let.)
-!------------------------------------------------------------------------------!
+!> Interpolation of turbulent enhancement factor for collision efficencies following
+!> Wang and Grabowski (2009, Atmos. Sci. Let.)
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE turb_enhance_eff
 
@@ -6641,56 +6445,55 @@
        first = .FALSE.
 
-       r0  = (/  10.0_wp, 20.0_wp, 30.0_wp, 40.0_wp, 50.0_wp, 60.0_wp,  &
-                100.0_wp /)
-
-       rat = (/ 0.0_wp, 0.1_wp, 0.2_wp, 0.3_wp, 0.4_wp, 0.5_wp, 0.6_wp, &
-                0.7_wp, 0.8_wp, 0.9_wp, 1.0_wp /)
+       r0  = (/  10.0_wp, 20.0_wp, 30.0_wp, 40.0_wp, 50.0_wp, 60.0_wp, 100.0_wp /)
+
+       rat = (/ 0.0_wp, 0.1_wp, 0.2_wp, 0.3_wp, 0.4_wp, 0.5_wp, 0.6_wp, 0.7_wp, 0.8_wp, 0.9_wp,    &
+                1.0_wp /)
 !
 !--    Tabulated turbulent enhancement factor at 100 cm**2/s**3
-       ecoll_100(:,1)  = (/  1.74_wp,   1.74_wp,   1.773_wp, 1.49_wp,  &
+       ecoll_100(:,1)  = (/  1.74_wp,   1.74_wp,   1.773_wp, 1.49_wp,                              &
                              1.207_wp,  1.207_wp,  1.0_wp /)
-       ecoll_100(:,2)  = (/  1.46_wp,   1.46_wp,   1.421_wp, 1.245_wp, &
+       ecoll_100(:,2)  = (/  1.46_wp,   1.46_wp,   1.421_wp, 1.245_wp,                             &
                              1.069_wp,  1.069_wp,  1.0_wp /)
-       ecoll_100(:,3)  = (/  1.32_wp,   1.32_wp,   1.245_wp, 1.123_wp, &
+       ecoll_100(:,3)  = (/  1.32_wp,   1.32_wp,   1.245_wp, 1.123_wp,                             &
                              1.000_wp,  1.000_wp,  1.0_wp /)
-       ecoll_100(:,4)  = (/  1.250_wp,  1.250_wp,  1.148_wp, 1.087_wp, &
+       ecoll_100(:,4)  = (/  1.250_wp,  1.250_wp,  1.148_wp, 1.087_wp,                             &
                              1.025_wp,  1.025_wp,  1.0_wp /)
-       ecoll_100(:,5)  = (/  1.186_wp,  1.186_wp,  1.066_wp, 1.060_wp, &
+       ecoll_100(:,5)  = (/  1.186_wp,  1.186_wp,  1.066_wp, 1.060_wp,                             &
                              1.056_wp,  1.056_wp,  1.0_wp /)
-       ecoll_100(:,6)  = (/  1.045_wp,  1.045_wp,  1.000_wp, 1.014_wp, &
+       ecoll_100(:,6)  = (/  1.045_wp,  1.045_wp,  1.000_wp, 1.014_wp,                             &
                              1.028_wp,  1.028_wp,  1.0_wp /)
-       ecoll_100(:,7)  = (/  1.070_wp,  1.070_wp,  1.030_wp, 1.038_wp, &
+       ecoll_100(:,7)  = (/  1.070_wp,  1.070_wp,  1.030_wp, 1.038_wp,                             &
                              1.046_wp,  1.046_wp,  1.0_wp /)
-       ecoll_100(:,8)  = (/  1.000_wp,  1.000_wp,  1.054_wp, 1.042_wp, &
+       ecoll_100(:,8)  = (/  1.000_wp,  1.000_wp,  1.054_wp, 1.042_wp,                             &
                              1.029_wp,  1.029_wp,  1.0_wp /)
-       ecoll_100(:,9)  = (/  1.223_wp,  1.223_wp,  1.117_wp, 1.069_wp, &
+       ecoll_100(:,9)  = (/  1.223_wp,  1.223_wp,  1.117_wp, 1.069_wp,                             &
                              1.021_wp,  1.021_wp,  1.0_wp /)
-       ecoll_100(:,10) = (/  1.570_wp,  1.570_wp,  1.244_wp, 1.166_wp, &
+       ecoll_100(:,10) = (/  1.570_wp,  1.570_wp,  1.244_wp, 1.166_wp,                             &
                              1.088_wp,  1.088_wp,  1.0_wp /)
-       ecoll_100(:,11) = (/ 20.3_wp,   20.3_wp,   14.6_wp,   8.61_wp,  &
+       ecoll_100(:,11) = (/ 20.3_wp,   20.3_wp,   14.6_wp,   8.61_wp,                              &
                              2.60_wp,   2.60_wp,   1.0_wp /)
 !
 !--    Tabulated turbulent enhancement factor at 400 cm**2/s**3
-       ecoll_400(:,1)  = (/  4.976_wp,  4.976_wp,  3.593_wp,  2.519_wp, &
+       ecoll_400(:,1)  = (/  4.976_wp,  4.976_wp,  3.593_wp,  2.519_wp,                            &
                              1.445_wp,  1.445_wp,  1.0_wp /)
-       ecoll_400(:,2)  = (/  2.984_wp,  2.984_wp,  2.181_wp,  1.691_wp, &
+       ecoll_400(:,2)  = (/  2.984_wp,  2.984_wp,  2.181_wp,  1.691_wp,                            &
                              1.201_wp,  1.201_wp,  1.0_wp /)
-       ecoll_400(:,3)  = (/  1.988_wp,  1.988_wp,  1.475_wp,  1.313_wp, &
+       ecoll_400(:,3)  = (/  1.988_wp,  1.988_wp,  1.475_wp,  1.313_wp,                            &
                              1.150_wp,  1.150_wp,  1.0_wp /)
-       ecoll_400(:,4)  = (/  1.490_wp,  1.490_wp,  1.187_wp,  1.156_wp, &
+       ecoll_400(:,4)  = (/  1.490_wp,  1.490_wp,  1.187_wp,  1.156_wp,                            &
                              1.126_wp,  1.126_wp,  1.0_wp /)
-       ecoll_400(:,5)  = (/  1.249_wp,  1.249_wp,  1.088_wp,  1.090_wp, &
+       ecoll_400(:,5)  = (/  1.249_wp,  1.249_wp,  1.088_wp,  1.090_wp,                            &
                              1.092_wp,  1.092_wp,  1.0_wp /)
-       ecoll_400(:,6)  = (/  1.139_wp,  1.139_wp,  1.130_wp,  1.091_wp, &
+       ecoll_400(:,6)  = (/  1.139_wp,  1.139_wp,  1.130_wp,  1.091_wp,                            &
                              1.051_wp,  1.051_wp,  1.0_wp /)
-       ecoll_400(:,7)  = (/  1.220_wp,  1.220_wp,  1.190_wp,  1.138_wp, &
+       ecoll_400(:,7)  = (/  1.220_wp,  1.220_wp,  1.190_wp,  1.138_wp,                            &
                              1.086_wp,  1.086_wp,  1.0_wp /)
-       ecoll_400(:,8)  = (/  1.325_wp,  1.325_wp,  1.267_wp,  1.165_wp, &
+       ecoll_400(:,8)  = (/  1.325_wp,  1.325_wp,  1.267_wp,  1.165_wp,                            &
                              1.063_wp,  1.063_wp,  1.0_wp /)
-       ecoll_400(:,9)  = (/  1.716_wp,  1.716_wp,  1.345_wp,  1.223_wp, &
+       ecoll_400(:,9)  = (/  1.716_wp,  1.716_wp,  1.345_wp,  1.223_wp,                            &
                              1.100_wp,  1.100_wp,  1.0_wp /)
-       ecoll_400(:,10) = (/  3.788_wp,  3.788_wp,  1.501_wp,  1.311_wp, &
+       ecoll_400(:,10) = (/  3.788_wp,  3.788_wp,  1.501_wp,  1.311_wp,                            &
                              1.120_wp,  1.120_wp,  1.0_wp /)
-       ecoll_400(:,11) = (/ 36.52_wp,  36.52_wp,  19.16_wp,  22.80_wp,  &
+       ecoll_400(:,11) = (/ 36.52_wp,  36.52_wp,  19.16_wp,  22.80_wp,                             &
                             26.0_wp,   26.0_wp,    1.0_wp /)
 
@@ -6698,5 +6501,5 @@
 
 !
-!-- Calculate the radius class index of particles with respect to array r0
+!-- Calculate the radius class index of particles with respect to array r0.
 !-- The droplet radius has to be given in microns.
     ALLOCATE( ira(1:radius_classes) )
@@ -6733,14 +6536,14 @@
           IF ( ir < 8 )  THEN
              IF ( ir >= 2 )  THEN
-                pp = ( MAX( radclass(j), radclass(i) ) * 1.0E6_wp -  &
-                       r0(ir-1) ) / ( r0(ir) - r0(ir-1) )
+                pp = ( MAX( radclass(j), radclass(i) ) * 1.0E6_wp - r0(ir-1) )                     &
+                     / ( r0(ir) - r0(ir-1) )
                 qq = ( rq - rat(iq-1) ) / ( rat(iq) - rat(iq-1) )
-                y2 = ( 1.0_wp - pp ) * ( 1.0_wp - qq ) * ecoll_100(ir-1,iq-1) + &
-                             pp * ( 1.0_wp - qq ) * ecoll_100(ir,iq-1)        + &
-                             qq * ( 1.0_wp - pp ) * ecoll_100(ir-1,iq)        + &
+                y2 = ( 1.0_wp - pp ) * ( 1.0_wp - qq ) * ecoll_100(ir-1,iq-1) +                    &
+                             pp * ( 1.0_wp - qq ) * ecoll_100(ir,iq-1)        +                    &
+                             qq * ( 1.0_wp - pp ) * ecoll_100(ir-1,iq)        +                    &
                              pp * qq              * ecoll_100(ir,iq)
-                y3 = ( 1.0-pp ) * ( 1.0_wp - qq ) * ecoll_400(ir-1,iq-1)      + &
-                             pp * ( 1.0_wp - qq ) * ecoll_400(ir,iq-1)        + &
-                             qq * ( 1.0_wp - pp ) * ecoll_400(ir-1,iq)        + &
+                y3 = ( 1.0-pp ) * ( 1.0_wp - qq ) * ecoll_400(ir-1,iq-1)      +                    &
+                             pp * ( 1.0_wp - qq ) * ecoll_400(ir,iq-1)        +                    &
+                             qq * ( 1.0_wp - pp ) * ecoll_400(ir-1,iq)        +                    &
                              pp * qq              * ecoll_400(ir,iq)
              ELSE
@@ -6757,12 +6560,12 @@
 !--       Linear interpolation of turbulent enhancement factor
           IF ( epsilon_collision <= 0.01_wp )  THEN
-             ecf(j,i) = ( epsilon_collision - 0.01_wp ) / ( 0.0_wp  - 0.01_wp ) * y1 &
-                      + ( epsilon_collision - 0.0_wp  ) / ( 0.01_wp - 0.0_wp  ) * y2
+             ecf(j,i) =   ( epsilon_collision - 0.01_wp ) / ( 0.0_wp  - 0.01_wp ) * y1             &
+                        + ( epsilon_collision - 0.0_wp  ) / ( 0.01_wp - 0.0_wp  ) * y2
           ELSEIF ( epsilon_collision <= 0.06_wp )  THEN
-             ecf(j,i) = ( epsilon_collision - 0.04_wp ) / ( 0.01_wp - 0.04_wp ) * y2 &
-                      + ( epsilon_collision - 0.01_wp ) / ( 0.04_wp - 0.01_wp ) * y3
+             ecf(j,i) =   ( epsilon_collision - 0.04_wp ) / ( 0.01_wp - 0.04_wp ) * y2             &
+                        + ( epsilon_collision - 0.01_wp ) / ( 0.04_wp - 0.01_wp ) * y3
           ELSE
-             ecf(j,i) = ( 0.06_wp - 0.04_wp ) / ( 0.01_wp - 0.04_wp ) * y2 &
-                      + ( 0.06_wp - 0.01_wp ) / ( 0.04_wp - 0.01_wp ) * y3
+             ecf(j,i) =   ( 0.06_wp - 0.04_wp ) / ( 0.01_wp - 0.04_wp ) * y2                       &
+                        + ( 0.06_wp - 0.01_wp ) / ( 0.04_wp - 0.01_wp ) * y3
           ENDIF
 
@@ -6775,21 +6578,21 @@
 
  END SUBROUTINE turb_enhance_eff
- 
- 
- !------------------------------------------------------------------------------!
+
+
+ !-------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-! This routine is a part of the Lagrangian particle model. Super droplets which 
-! fulfill certain criterion's (e.g. a big weighting factor and a large radius) 
-! can be split into several super droplets with a reduced number of 
-! represented particles of every super droplet. This mechanism ensures an
-! improved representation of the right tail of the drop size distribution with 
-! a feasible amount of computational costs. The limits of particle creation 
-! should be chosen carefully! The idea of this algorithm is based on 
-! Unterstrasser and Soelch, 2014. 
-!------------------------------------------------------------------------------!
+! This routine is a part of the Lagrangian particle model. Super droplets which fulfill certain
+! criterion's (e.g. a big weighting factor and a large radius) can be split into several super
+! droplets with a reduced number of represented particles of every super droplet. This mechanism
+! ensures an improved representation of the right tail of the drop size distribution with a feasible
+! amount of computational costs. The limits of particle creation should be chosen carefully! The
+! idea of this algorithm is based on Unterstrasser and Soelch, 2014.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_splitting
 
-    INTEGER(iwp) ::  i                !< 
+    INTEGER(iwp), PARAMETER ::  n_max = 100 !< number of radii bin for splitting functions
+
+    INTEGER(iwp) ::  i                !<
     INTEGER(iwp) ::  j                !<
     INTEGER(iwp) ::  jpp              !<
@@ -6798,8 +6601,6 @@
     INTEGER(iwp) ::  new_particles_gb !< counter of created particles within one grid box
     INTEGER(iwp) ::  new_size         !< new particle array size
-    INTEGER(iwp) ::  np               !< 
+    INTEGER(iwp) ::  np               !<
     INTEGER(iwp) ::  old_size         !< old particle array size
-
-    INTEGER(iwp), PARAMETER ::  n_max = 100 !< number of radii bin for splitting functions    
 
     LOGICAL ::  first_loop_stride_sp = .TRUE. !< flag to calculate constants only once
@@ -6818,5 +6619,5 @@
     REAL(wp) ::  m3_total                 !< average average over all PEs third moment of DSD
     REAL(wp) ::  mu                       !< spectral shape parameter of gamma distribution
-    REAL(wp) ::  nrclgb                   !< number of cloudy grid boxes (ql >= 1.0E-5 kg/kg) 
+    REAL(wp) ::  nrclgb                   !< number of cloudy grid boxes (ql >= 1.0E-5 kg/kg)
     REAL(wp) ::  nrclgb_total             !< average over all PEs of number of cloudy grid boxes
     REAL(wp) ::  nr                       !< number concentration of cloud droplets
@@ -6824,9 +6625,8 @@
     REAL(wp) ::  nr0                      !< intercept parameter of gamma distribution
     REAL(wp) ::  pirho_l                  !< pi * rho_l / 6.0
-    REAL(wp) ::  ql_crit = 1.0E-5_wp      !< threshold lwc for cloudy grid cells 
-                                          !< (Siebesma et al 2003, JAS, 60)
+    REAL(wp) ::  ql_crit = 1.0E-5_wp      !< threshold lwc for cloudy grid cells (Siebesma et al 2003, JAS, 60)
     REAL(wp) ::  rm                       !< volume averaged mean radius
     REAL(wp) ::  rm_total                 !< average over all PEs of volume averaged mean radius
-    REAL(wp) ::  r_min = 1.0E-6_wp        !< minimum radius of approximated spectra 
+    REAL(wp) ::  r_min = 1.0E-6_wp        !< minimum radius of approximated spectra
     REAL(wp) ::  r_max = 1.0E-3_wp        !< maximum radius of approximated spectra
     REAL(wp) ::  sigma_log = 1.5_wp       !< standard deviation of the LOG-distribution
@@ -6849,9 +6649,9 @@
           ENDDO
           r_bin(n_max) = 10.0_wp**( LOG10(r_min) + n_max * dlog - 0.5_wp * dlog )
-       ENDIF   
+       ENDIF
        factor_volume_to_mass =  4.0_wp / 3.0_wp * pi * rho_l
        pirho_l  = pi * rho_l / 6.0_wp
        IF ( weight_factor_split == -1.0_wp )  THEN
-          weight_factor_split = 0.1_wp * initial_weighting_factor 
+          weight_factor_split = 0.1_wp * initial_weighting_factor
        ENDIF
     ENDIF
@@ -6866,21 +6666,18 @@
                 new_particles_gb = 0
                 number_of_particles = prt_count(k,j,i)
-                IF ( number_of_particles <= 0  .OR.                            &  
-                     ql(k,j,i) < ql_crit )  CYCLE
+                IF ( number_of_particles <= 0  .OR.  ql(k,j,i) < ql_crit )  CYCLE
                 particles => grid_particles(k,j,i)%particles(1:number_of_particles)
 !
-!--             Start splitting operations. Each particle is checked if it
-!--             fulfilled the splitting criterion's. In splitting mode 'const'   
-!--             a critical radius  (radius_split) a critical weighting factor
-!--             (weight_factor_split) and a splitting factor (splitting_factor)
-!--             must  be prescribed (see particle_parameters). Super droplets 
-!--             which have a larger radius and larger weighting factor are split 
-!--             into 'splitting_factor' super droplets. Therefore, the weighting 
-!--             factor of  the super droplet and all created clones is reduced 
-!--             by the factor of 'splitting_factor'.
+!--             Start splitting operations. Each particle is checked if it fulfilled the splitting
+!--             criterion's. In splitting mode 'const' a critical radius  (radius_split) a critical
+!--             weighting factor (weight_factor_split) and a splitting factor (splitting_factor)
+!--             must be prescribed (see particle_parameters). Super droplets which have a larger
+!--             radius and larger weighting factor are split into 'splitting_factor' super droplets.
+!--             Therefore, the weighting factor of the super droplet and all created clones is
+!--             reduced by the factor of 'splitting_factor'.
                 DO  n = 1, number_of_particles
-                   IF ( particles(n)%particle_mask  .AND.                      &
-                        particles(n)%radius >= radius_split  .AND.             & 
-                        particles(n)%weight_factor >= weight_factor_split )    &
+                   IF ( particles(n)%particle_mask           .AND.                                 &
+                        particles(n)%radius >= radius_split  .AND.                                 &
+                        particles(n)%weight_factor >= weight_factor_split )                        &
                    THEN
 !
@@ -6888,10 +6685,10 @@
                       new_size = prt_count(k,j,i) + splitting_factor - 1
 !
-!--                   Cycle if maximum number of particles per grid box
-!--                   is greater than the allowed maximum number.
+!--                   Cycle if maximum number of particles per grid box is greater than the allowed
+!--                   maximum number.
                       IF ( new_size >= max_number_particles_per_gridbox )  CYCLE
 !
-!--                   Reallocate particle array if necessary. 
-                      IF ( new_size > SIZE(particles) )  THEN 
+!--                   Reallocate particle array if necessary.
+                      IF ( new_size > SIZE( particles ) )  THEN
                          CALL realloc_particles_array( i, j, k, new_size )
                       ENDIF
@@ -6899,18 +6696,15 @@
 !
 !--                   Calculate new weighting factor.
-                      particles(n)%weight_factor =  & 
-                         particles(n)%weight_factor / splitting_factor
+                      particles(n)%weight_factor = particles(n)%weight_factor / splitting_factor
                       tmp_particle = particles(n)
 !
 !--                   Create splitting_factor-1 new particles.
                       DO  jpp = 1, splitting_factor-1
-                         grid_particles(k,j,i)%particles(jpp+old_size) =       & 
-                            tmp_particle
-                      ENDDO  
+                         grid_particles(k,j,i)%particles(jpp+old_size) = tmp_particle
+                      ENDDO
                       new_particles_gb = new_particles_gb + splitting_factor - 1
-!   
+!
 !--                   Save the new number of super droplets for every grid box.
-                      prt_count(k,j,i) = prt_count(k,j,i) +                    &
-                                         splitting_factor - 1
+                      prt_count(k,j,i) = prt_count(k,j,i) + splitting_factor - 1
                    ENDIF
                 ENDDO
@@ -6920,9 +6714,9 @@
        ENDDO
 
-    ELSEIF ( i_splitting_mode == 2 )  THEN 
+    ELSEIF ( i_splitting_mode == 2 )  THEN
 !
 !--    Initialize summing variables.
        lwc          = 0.0_wp
-       lwc_total    = 0.0_wp 
+       lwc_total    = 0.0_wp
        m1           = 0.0_wp
        m1_total     = 0.0_wp
@@ -6942,6 +6736,5 @@
              DO  k = nzb+1, nzt
                 number_of_particles = prt_count(k,j,i)
-                IF ( number_of_particles <= 0  .OR.                            & 
-                     ql(k,j,i) < ql_crit )  CYCLE
+                IF ( number_of_particles <= 0  .OR.  ql(k,j,i) < ql_crit )  CYCLE
                 particles => grid_particles(k,j,i)%particles(1:number_of_particles)
                 nrclgb = nrclgb + 1.0_wp
@@ -6949,16 +6742,15 @@
 !--             Calculate moments of DSD.
                 DO  n = 1, number_of_particles
-                   IF ( particles(n)%particle_mask  .AND.                      &
-                        particles(n)%radius >= r_min )                         &
+                   IF ( particles(n)%particle_mask  .AND.  particles(n)%radius >= r_min )          &
                    THEN
                       nr  = nr  + particles(n)%weight_factor
-                      rm  = rm  + factor_volume_to_mass  *                     &
-                                 particles(n)%radius**3  *                     &
+                      rm  = rm  + factor_volume_to_mass  *                                         &
+                                 particles(n)%radius**3  *                                         &
                                  particles(n)%weight_factor
-                      IF ( isf == 1 )  THEN           
+                      IF ( isf == 1 )  THEN
                          diameter   = particles(n)%radius * 2.0_wp
-                         lwc = lwc + factor_volume_to_mass *                   &
-                                     particles(n)%radius**3 *                  & 
-                                     particles(n)%weight_factor 
+                         lwc = lwc + factor_volume_to_mass *                                       &
+                                     particles(n)%radius**3 *                                      &
+                                     particles(n)%weight_factor
                          m1  = m1  + particles(n)%weight_factor * diameter
                          m2  = m2  + particles(n)%weight_factor * diameter**2
@@ -6966,5 +6758,5 @@
                       ENDIF
                    ENDIF
-                ENDDO 
+                ENDDO
              ENDDO
           ENDDO
@@ -6973,78 +6765,56 @@
 #if defined( __parallel )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( nr, nr_total, 1 , &
-       MPI_REAL, MPI_SUM, comm2d, ierr )
-       CALL MPI_ALLREDUCE( rm, rm_total, 1 , &
-       MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( nr, nr_total, 1 , MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( rm, rm_total, 1 , MPI_REAL, MPI_SUM, comm2d, ierr )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( nrclgb, nrclgb_total, 1 , &
-       MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( nrclgb, nrclgb_total, 1 , MPI_REAL, MPI_SUM, comm2d, ierr )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( lwc, lwc_total, 1 , &
-       MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( lwc, lwc_total, 1 , MPI_REAL, MPI_SUM, comm2d, ierr )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( m1, m1_total, 1 , &
-       MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( m1, m1_total, 1 , MPI_REAL, MPI_SUM, comm2d, ierr )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( m2, m2_total, 1 , &
-       MPI_REAL, MPI_SUM, comm2d, ierr )
+       CALL MPI_ALLREDUCE( m2, m2_total, 1 , MPI_REAL, MPI_SUM, comm2d, ierr )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( m3, m3_total, 1 , &
-       MPI_REAL, MPI_SUM, comm2d, ierr )
-#endif 
+       CALL MPI_ALLREDUCE( m3, m3_total, 1 , MPI_REAL, MPI_SUM, comm2d, ierr )
+#endif
 
 !
 !--    Calculate number concentration and mean volume averaged radius.
-       nr_total = MERGE( nr_total / nrclgb_total,                              &
-                         0.0_wp, nrclgb_total > 0.0_wp                         &
-                       )
-       rm_total = MERGE( ( rm_total /                                          &
-                            ( nr_total * factor_volume_to_mass )               &
-                          )**0.3333333_wp, 0.0_wp, nrclgb_total > 0.0_wp       &
+       nr_total = MERGE( nr_total / nrclgb_total, 0.0_wp, nrclgb_total > 0.0_wp )
+       rm_total = MERGE( ( rm_total / ( nr_total * factor_volume_to_mass ) )**0.3333333_wp, 0.0_wp,&
+                          nrclgb_total > 0.0_wp                                                    &
                        )
 !
 !--    Check which function should be used to approximate the DSD.
        IF ( isf == 1 )  THEN
-          lwc_total = MERGE( lwc_total / nrclgb_total,                         &
-                             0.0_wp, nrclgb_total > 0.0_wp                     &
-                           )
-          m1_total  = MERGE( m1_total / nrclgb_total,                          &
-                             0.0_wp, nrclgb_total > 0.0_wp                     &
-                           )
-          m2_total  = MERGE( m2_total / nrclgb_total,                          &
-                             0.0_wp, nrclgb_total > 0.0_wp                     &
-                           )
-          m3_total  = MERGE( m3_total / nrclgb_total,                          &
-                             0.0_wp, nrclgb_total > 0.0_wp                     &
-                           )
+          lwc_total = MERGE( lwc_total / nrclgb_total, 0.0_wp, nrclgb_total > 0.0_wp )
+          m1_total  = MERGE( m1_total  / nrclgb_total, 0.0_wp, nrclgb_total > 0.0_wp )
+          m2_total  = MERGE( m2_total  / nrclgb_total, 0.0_wp, nrclgb_total > 0.0_wp )
+          m3_total  = MERGE( m3_total  / nrclgb_total, 0.0_wp, nrclgb_total > 0.0_wp )
           zeta = m1_total * m3_total / m2_total**2
-          mu   = MAX( ( ( 1.0_wp - zeta ) * 2.0_wp + 1.0_wp ) /                &
-                        ( zeta - 1.0_wp ), 0.0_wp                              &
-                    )
-
-          lambda = ( pirho_l * nr_total / lwc_total *                          &
-                     ( mu + 3.0_wp ) * ( mu + 2.0_wp ) * ( mu + 1.0_wp )       &
+          mu   = MAX( ( ( 1.0_wp - zeta ) * 2.0_wp + 1.0_wp ) / ( zeta - 1.0_wp ), 0.0_wp )
+
+          lambda = ( pirho_l * nr_total / lwc_total *                                              &
+                     ( mu + 3.0_wp ) * ( mu + 2.0_wp ) * ( mu + 1.0_wp )                           &
                    )**0.3333333_wp
-          nr0 = nr_total / gamma( mu + 1.0_wp ) * lambda**( mu + 1.0_wp ) 
+          nr0 = nr_total / gamma( mu + 1.0_wp ) * lambda**( mu + 1.0_wp )
 
           DO  n = 0, n_max-1
              diameter  = r_bin_mid(n) * 2.0_wp
-             an_spl(n) = nr0 * diameter**mu * EXP( -lambda * diameter ) *      & 
-                         ( r_bin(n+1) - r_bin(n) ) * 2.0_wp 
+             an_spl(n) = nr0 * diameter**mu * EXP( -lambda * diameter ) *                          &
+                         ( r_bin(n+1) - r_bin(n) ) * 2.0_wp
           ENDDO
        ELSEIF ( isf == 2 )  THEN
           DO  n = 0, n_max-1
-             an_spl(n) = nr_total / ( SQRT( 2.0_wp * pi ) *                    &
-                                     LOG(sigma_log) * r_bin_mid(n)             &
-                                     ) *                                       &
-                         EXP( -( LOG( r_bin_mid(n) / rm_total )**2 ) /         &
-                               ( 2.0_wp * LOG(sigma_log)**2 )                  & 
-                             ) *                                               & 
+             an_spl(n) = nr_total / ( SQRT( 2.0_wp * pi ) * LOG(sigma_log) * r_bin_mid(n) ) *      &
+                         EXP( -( LOG( r_bin_mid(n) / rm_total )**2 ) /                             &
+                               ( 2.0_wp * LOG(sigma_log)**2 )                                      &
+                            ) *                                                                    &
                          ( r_bin(n+1) - r_bin(n) )
           ENDDO
        ELSEIF( isf == 3 )  THEN
-          DO  n = 0, n_max-1 
-             an_spl(n) = 3.0_wp * nr_total * r_bin_mid(n)**2 / rm_total**3  *  &
-                         EXP( - ( r_bin_mid(n)**3 / rm_total**3 ) )         *  &
+          DO  n = 0, n_max-1
+             an_spl(n) = 3.0_wp * nr_total * r_bin_mid(n)**2 / rm_total**3  *                      &
+                         EXP( -( r_bin_mid(n)**3 / rm_total**3 ) )          *                      &
                          ( r_bin(n+1) - r_bin(n) )
           ENDDO
@@ -7058,38 +6828,33 @@
              DO  k = nzb+1, nzt
                 number_of_particles = prt_count(k,j,i)
-                IF ( number_of_particles <= 0  .OR.                            &
-                     ql(k,j,i) < ql_crit )  CYCLE
+                IF ( number_of_particles <= 0  .OR.  ql(k,j,i) < ql_crit )  CYCLE
                 particles => grid_particles(k,j,i)%particles(1:number_of_particles)
                 new_particles_gb = 0
 !
-!--             Start splitting operations. Each particle is checked if it
-!--             fulfilled the splitting criterion's. In splitting mode 'cl_av'
-!--             a critical radius (radius_split) and a splitting function must
-!--             be prescribed (see particles_par). The critical weighting factor
-!--             is calculated while approximating a 'gamma', 'log' or 'exp'-
-!--             drop size distribution. In this mode the DSD is calculated as
-!--             an average over all cloudy grid boxes. Super droplets which
-!--             have a larger radius and larger weighting factor are split into
-!--             'splitting_factor' super droplets. In this case the splitting
-!--             factor is calculated of weighting factor of the super droplet
-!--             and the approximated number concentration for droplet of such
-!--             a size. Due to the splitting, the weighting factor of the
-!--             super droplet and all created clones is reduced by the factor
-!--             of 'splitting_facor'.
+!--             Start splitting operations. Each particle is checked if it fulfilled the splitting
+!--             criterion's. In splitting mode 'cl_av' a critical radius (radius_split) and a
+!--             splitting function must be prescribed (see particles_par). The critical weighting
+!--             factor is calculated while approximating a 'gamma', 'log' or 'exp'- drop size
+!--             distribution. In this mode the DSD is calculated as an average over all cloudy grid
+!--             boxes. Super droplets which have a larger radius and larger weighting factor are
+!--             split into 'splitting_factor' super droplets. In this case the splitting factor is
+!--             calculated of weighting factor of the super droplet and the approximated number
+!--             concentration for droplet of such a size. Due to the splitting, the weighting factor
+!--             of the super droplet and all created clones is reduced by the factor of
+!--             'splitting_facor'.
                 DO  n = 1, number_of_particles
                    DO  np = 0, n_max-1
-                      IF ( r_bin(np) >= radius_split  .AND.                    &
-                           particles(n)%particle_mask  .AND.                   &
-                           particles(n)%radius >= r_bin(np)  .AND.             &
-                           particles(n)%radius < r_bin(np+1)  .AND.            &
-                           particles(n)%weight_factor >= an_spl(np)  )         &
+                      IF ( r_bin(np) >= radius_split          .AND.                                &
+                           particles(n)%particle_mask         .AND.                                &
+                           particles(n)%radius >= r_bin(np)   .AND.                                &
+                           particles(n)%radius < r_bin(np+1)  .AND.                                &
+                           particles(n)%weight_factor >= an_spl(np)  )                             &
                       THEN
 !
 !--                      Calculate splitting factor
-                         splitting_factor =                                    & 
-                             MIN( INT( particles(n)%weight_factor /            &
-                                        an_spl(np)                             &
-                                     ), splitting_factor_max                   &
-                                )
+                         splitting_factor = MIN( INT( particles(n)%weight_factor /                 &
+                                                       an_spl(np)                                  &
+                                                    ), splitting_factor_max                        &
+                                               )
                          IF ( splitting_factor < 2 )  CYCLE
 !
@@ -7097,34 +6862,29 @@
                          new_size = prt_count(k,j,i) + splitting_factor - 1
 !
-!--                      Cycle if maximum number of particles per grid box
-!--                      is greater than the allowed maximum number.
-                         IF ( new_size >= max_number_particles_per_gridbox )   & 
-                         CYCLE
-!
-!--                      Reallocate particle array if necessary. 
-                         IF ( new_size > SIZE(particles) )  THEN 
+!--                      Cycle if maximum number of particles per grid box is greater than the
+!--                      allowed maximum number.
+                         IF ( new_size >= max_number_particles_per_gridbox )  CYCLE
+!
+!--                      Reallocate particle array if necessary.
+                         IF ( new_size > SIZE( particles ) )  THEN
                             CALL realloc_particles_array( i, j, k, new_size )
                          ENDIF
                          old_size  = prt_count(k,j,i)
-                         new_particles_gb = new_particles_gb +                 &
-                                            splitting_factor - 1
+                         new_particles_gb = new_particles_gb + splitting_factor - 1
 !
 !--                      Calculate new weighting factor.
-                         particles(n)%weight_factor =                          & 
-                            particles(n)%weight_factor / splitting_factor
+                         particles(n)%weight_factor = particles(n)%weight_factor / splitting_factor
                          tmp_particle = particles(n)
 !
 !--                      Create splitting_factor-1 new particles.
                          DO  jpp = 1, splitting_factor-1
-                            grid_particles(k,j,i)%particles(jpp+old_size) =    &
-                                                                    tmp_particle
+                            grid_particles(k,j,i)%particles(jpp+old_size) = tmp_particle
                          ENDDO
 !
-!--                      Save the new number of super droplets. 
-                         prt_count(k,j,i) = prt_count(k,j,i) +                 &
-                                            splitting_factor - 1
+!--                      Save the new number of super droplets.
+                         prt_count(k,j,i) = prt_count(k,j,i) + splitting_factor - 1
                       ENDIF
                    ENDDO
-                ENDDO 
+                ENDDO
 
              ENDDO
@@ -7132,5 +6892,5 @@
        ENDDO
 
-    ELSEIF ( i_splitting_mode == 3 )  THEN 
+    ELSEIF ( i_splitting_mode == 3 )  THEN
 
        DO  i = nxl, nxr
@@ -7145,26 +6905,24 @@
                 m3  = 0.0_wp
                 nr  = 0.0_wp
-                rm  = 0.0_wp  
+                rm  = 0.0_wp
 
                 new_particles_gb = 0
                 number_of_particles = prt_count(k,j,i)
-                IF ( number_of_particles <= 0  .OR.                            & 
-                     ql(k,j,i) < ql_crit )  CYCLE
+                IF ( number_of_particles <= 0  .OR.  ql(k,j,i) < ql_crit )  CYCLE
                 particles => grid_particles(k,j,i)%particles
 !
 !--             Calculate moments of DSD.
                 DO  n = 1, number_of_particles
-                   IF ( particles(n)%particle_mask  .AND.                      &
-                        particles(n)%radius >= r_min )                         &
+                   IF ( particles(n)%particle_mask  .AND.  particles(n)%radius >= r_min )          &
                    THEN
                       nr  = nr + particles(n)%weight_factor
-                      rm  = rm + factor_volume_to_mass  *                      &
-                                 particles(n)%radius**3  *                     &
+                      rm  = rm + factor_volume_to_mass  *                                          &
+                                 particles(n)%radius**3  *                                         &
                                  particles(n)%weight_factor
                       IF ( isf == 1 )  THEN
                          diameter   = particles(n)%radius * 2.0_wp
-                         lwc = lwc + factor_volume_to_mass *                   &
-                                     particles(n)%radius**3 *                  &
-                                     particles(n)%weight_factor 
+                         lwc = lwc + factor_volume_to_mass *                                       &
+                                     particles(n)%radius**3 *                                      &
+                                     particles(n)%weight_factor
                          m1  = m1 + particles(n)%weight_factor * diameter
                          m2  = m2 + particles(n)%weight_factor * diameter**2
@@ -7182,43 +6940,40 @@
                 IF ( isf == 1 )  THEN
 !
-!--                Gamma size distribution to calculate  
+!--                Gamma size distribution to calculate
 !--                critical weight_factor (e.g. Marshall + Palmer, 1948).
                    zeta = m1 * m3 / m2**2
-                   mu   = MAX( ( ( 1.0_wp - zeta ) * 2.0_wp + 1.0_wp ) /       &
-                                ( zeta - 1.0_wp ), 0.0_wp                      &
-                             )   
-                   lambda = ( pirho_l * nr / lwc *                             &
-                              ( mu + 3.0_wp ) * ( mu + 2.0_wp ) *              &
-                              ( mu + 1.0_wp )                                  &
+                   mu   = MAX( ( ( 1.0_wp - zeta ) * 2.0_wp + 1.0_wp ) / ( zeta - 1.0_wp ), 0.0_wp )
+                   lambda = ( pirho_l * nr / lwc *                                                 &
+                              ( mu + 3.0_wp ) * ( mu + 2.0_wp ) * ( mu + 1.0_wp )                  &
                             )**0.3333333_wp
-                   nr0 =  ( nr / (gamma( mu + 1.0_wp ) ) ) *                   &
-                          lambda**( mu + 1.0_wp ) 
+                   nr0 =  ( nr / (gamma( mu + 1.0_wp ) ) ) *                                       &
+                          lambda**( mu + 1.0_wp )
 
                    DO  n = 0, n_max-1
                       diameter         = r_bin_mid(n) * 2.0_wp
-                      an_spl(n) = nr0 * diameter**mu *                         &
-                                  EXP( -lambda * diameter ) *                  & 
-                                  ( r_bin(n+1) - r_bin(n) ) * 2.0_wp 
+                      an_spl(n) = nr0 * diameter**mu *                                             &
+                                  EXP( -lambda * diameter ) *                                      &
+                                  ( r_bin(n+1) - r_bin(n) ) * 2.0_wp
                    ENDDO
                 ELSEIF ( isf == 2 )  THEN
 !
-!--                Lognormal size distribution to calculate critical 
+!--                Lognormal size distribution to calculate critical
 !--                weight_factor (e.g. Levin, 1971, Bradley + Stow, 1974).
                    DO  n = 0, n_max-1
-                      an_spl(n) = nr / ( SQRT( 2.0_wp * pi ) *                 &
-                                              LOG(sigma_log) * r_bin_mid(n)    &
-                                        ) *                                    &
-                                  EXP( -( LOG( r_bin_mid(n) / rm )**2 ) /      &
-                                        ( 2.0_wp * LOG(sigma_log)**2 )         &
-                                      ) *                                      &
+                      an_spl(n) = nr / ( SQRT( 2.0_wp * pi ) *                                     &
+                                              LOG(sigma_log) * r_bin_mid(n)                        &
+                                       ) *                                                         &
+                                  EXP( -( LOG( r_bin_mid(n) / rm )**2 ) /                          &
+                                        ( 2.0_wp * LOG(sigma_log)**2 )                             &
+                                     ) *                                                           &
                                   ( r_bin(n+1) - r_bin(n) )
                    ENDDO
                 ELSEIF ( isf == 3 )  THEN
 !
-!--                Exponential size distribution to calculate critical 
-!--                weight_factor (e.g. Berry + Reinhardt, 1974).  
+!--                Exponential size distribution to calculate critical weight_factor
+!--                (e.g. Berry + Reinhardt, 1974).
                    DO  n = 0, n_max-1
-                      an_spl(n) = 3.0_wp * nr * r_bin_mid(n)**2 / rm**3 *     &
-                                  EXP( - ( r_bin_mid(n)**3 / rm**3 ) ) *      &
+                      an_spl(n) = 3.0_wp * nr * r_bin_mid(n)**2 / rm**3 *                          &
+                                  EXP( - ( r_bin_mid(n)**3 / rm**3 ) ) *                           &
                                   ( r_bin(n+1) - r_bin(n) )
                    ENDDO
@@ -7229,33 +6984,28 @@
                 an_spl = MAX(an_spl, 1.0_wp)
 !
-!--             Start splitting operations. Each particle is checked if it
-!--             fulfilled the splitting criterion's. In splitting mode 'gb_av'
-!--             a critical radius (radius_split) and a splitting function must 
-!--             be prescribed (see particles_par). The critical weighting factor
-!--             is calculated while appoximating a 'gamma', 'log' or 'exp'-
-!--             drop size distribution. In this mode a DSD is calculated for 
-!--             every cloudy grid box. Super droplets which have a larger 
-!--             radius and larger weighting factor are split into
-!--             'splitting_factor' super droplets. In this case the splitting  
-!--             factor is calculated of weighting factor of the super droplet  
-!--             and theapproximated number concentration for droplet of such 
-!--             a size. Due to the splitting, the weighting factor of the  
-!--             super droplet and all created clones is reduced by the factor  
-!--             of 'splitting_facor'.
+!--             Start splitting operations. Each particle is checked if it fulfilled the splitting
+!--             criterions. In splitting mode 'gb_av' a critical radius (radius_split) and a
+!--             splitting function must be prescribed (see particles_par). The critical weighting
+!--             factor is calculated while appoximating a 'gamma', 'log' or 'exp'-drop size
+!--             distribution. In this mode a DSD is calculated for every cloudy grid box. Super
+!--             droplets which have a larger radius and larger weighting factor are split into
+!--             'splitting_factor' super droplets. In this case the splitting factor is calculated
+!--             by the weighting factor of the super droplet  and the approximated number
+!--             concentration for droplets of such size. Due to the splitting, the weighting factor
+!--             of the super droplet and all created clones are reduced by the factor  of
+!--             'splitting_facor'.
                 DO  n = 1, number_of_particles
                    DO  np = 0, n_max-1
-                      IF ( r_bin(np) >= radius_split  .AND.                    &
-                           particles(n)%particle_mask  .AND.                   &
-                           particles(n)%radius >= r_bin(np)    .AND.           &
-                           particles(n)%radius < r_bin(np+1)   .AND.           &
-                           particles(n)%weight_factor >= an_spl(np) )          &
+                      IF ( r_bin(np) >= radius_split           .AND.                               &
+                           particles(n)%particle_mask          .AND.                               &
+                           particles(n)%radius >= r_bin(np)    .AND.                               &
+                           particles(n)%radius < r_bin(np+1)   .AND.                               &
+                           particles(n)%weight_factor >= an_spl(np) )                              &
                       THEN
 !
 !--                      Calculate splitting factor.
-                         splitting_factor =                                    & 
-                             MIN( INT( particles(n)%weight_factor /            &
-                                        an_spl(np)                             &
-                                     ), splitting_factor_max                   &
-                                )
+                         splitting_factor = MIN( INT( particles(n)%weight_factor / an_spl(np) ),   &
+                                                 splitting_factor_max                              &
+                                               )
                          IF ( splitting_factor < 2 )  CYCLE
 
@@ -7266,15 +7016,13 @@
 !--                      Cycle if maximum number of particles per grid box
 !--                      is greater than the allowed maximum number.
-                         IF ( new_size >= max_number_particles_per_gridbox )   &
-                         CYCLE
+                         IF ( new_size >= max_number_particles_per_gridbox )  CYCLE
 !
 !--                      Reallocate particle array if necessary.
-                         IF ( new_size > SIZE(particles) )  THEN 
+                         IF ( new_size > SIZE( particles ) )  THEN
                             CALL realloc_particles_array( i, j, k, new_size )
                          ENDIF
 !
 !--                      Calculate new weighting factor.
-                         particles(n)%weight_factor = & 
-                            particles(n)%weight_factor / splitting_factor
+                         particles(n)%weight_factor = particles(n)%weight_factor / splitting_factor
                          tmp_particle               = particles(n)
                          old_size                   = prt_count(k,j,i)
@@ -7282,13 +7030,10 @@
 !--                      Create splitting_factor-1 new particles.
                          DO  jpp = 1, splitting_factor-1
-                            grid_particles(k,j,i)%particles( jpp + old_size ) = &
-                               tmp_particle
+                            grid_particles(k,j,i)%particles( jpp + old_size ) = tmp_particle
                          ENDDO
 !
 !--                      Save the new number of droplets for every grid box.
-                         prt_count(k,j,i)    = prt_count(k,j,i) +              &
-                                               splitting_factor - 1
-                         new_particles_gb    = new_particles_gb +              &
-                                               splitting_factor - 1
+                         prt_count(k,j,i)    = prt_count(k,j,i) + splitting_factor - 1
+                         new_particles_gb    = new_particles_gb + splitting_factor - 1
                       ENDIF
                    ENDDO
@@ -7302,17 +7047,15 @@
 
  END SUBROUTINE lpm_splitting
- 
-
-!------------------------------------------------------------------------------!
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-! This routine is a part of the Lagrangian particle model. Two Super droplets 
-! which fulfill certain criterion's (e.g. a big weighting factor and a small
-! radius) can be merged into one super droplet with a increased number of 
-! represented particles of the super droplet. This mechanism ensures an
-! improved a feasible amount of computational costs. The limits of particle 
-! creation should be chosen carefully! The idea of this algorithm is based on 
-! Unterstrasser and Soelch, 2014. 
-!------------------------------------------------------------------------------!
+! This routine is a part of the Lagrangian particle model. Two Super droplets which fulfill certain
+! criterions (e.g. a big weighting factor and a small radius) can be merged into one super droplet
+! with a increased number of represented particles of the super droplet. This mechanism ensures an
+! improved feasible amount of computational costs. The limits of particle creation should be chosen
+! carefully! The idea of this algorithm is based on Unterstrasser and Soelch, 2014.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_merging
 
@@ -7324,5 +7067,5 @@
 
 
-    REAL(wp) ::  ql_crit = 1.0E-5_wp  !< threshold lwc for cloudy grid cells 
+    REAL(wp) ::  ql_crit = 1.0E-5_wp  !< threshold lwc for cloudy grid cells
                                       !< (e.g. Siebesma et al 2003, JAS, 60)
 
@@ -7332,5 +7075,5 @@
 
     IF ( weight_factor_merge == -1.0_wp )  THEN
-       weight_factor_merge = 0.5_wp * initial_weighting_factor 
+       weight_factor_merge = 0.5_wp * initial_weighting_factor
     ENDIF
 
@@ -7340,30 +7083,27 @@
 
              number_of_particles = prt_count(k,j,i)
-             IF ( number_of_particles <= 0  .OR.                               &
-                   ql(k,j,i) >= ql_crit )  CYCLE
+             IF ( number_of_particles <= 0  .OR.  ql(k,j,i) >= ql_crit )  CYCLE
              particles => grid_particles(k,j,i)%particles(1:number_of_particles)
 !
-!--          Start merging operations: This routine delete super droplets with
-!--          a small radius (radius <= radius_merge) and a low weighting 
-!--          factor (weight_factor  <= weight_factor_merge). The number of 
-!--          represented particles will be added to the next particle of the 
-!--          particle array. Tests showed that this simplified method can be 
-!--          used because it will only take place outside of cloudy grid 
-!--          boxes where ql <= 1.0E-5 kg/kg. Therefore, especially former cloned
-!--          and subsequent evaporated super droplets will be merged.
+!--          Start merging operations: This routine deletes super droplets with a small radius
+!--          (radius <= radius_merge) and a low weighting factor (weight_factor  <=
+!--          weight_factor_merge). The number of represented particles will be added to the next
+!--          particle of the particle array. Tests showed that this simplified method can be used
+!--          because it will only take place outside of cloudy grid boxes where ql <= 1.0E-5 kg/kg.
+!--          Therefore, especially former cloned and subsequent evaporated super droplets will be
+!--          merged.
              DO  n = 1, number_of_particles-1
-                IF ( particles(n)%particle_mask                    .AND.       &
-                     particles(n+1)%particle_mask                  .AND.       &
-                     particles(n)%radius        <= radius_merge    .AND.       &
-                     particles(n)%weight_factor <= weight_factor_merge )       &
+                IF ( particles(n)%particle_mask                    .AND.                           &
+                     particles(n+1)%particle_mask                  .AND.                           &
+                     particles(n)%radius        <= radius_merge    .AND.                           &
+                     particles(n)%weight_factor <= weight_factor_merge )                           &
                 THEN
-                   particles(n+1)%weight_factor  =                             &
-                                       particles(n+1)%weight_factor +          &
-                                       ( particles(n)%radius**3     /          &
-                                         particles(n+1)%radius**3   *          &
-                                         particles(n)%weight_factor            &
-                                       )
+                   particles(n+1)%weight_factor  = particles(n+1)%weight_factor +                  &
+                                                   ( particles(n)%radius**3     /                  &
+                                                     particles(n+1)%radius**3   *                  &
+                                                     particles(n)%weight_factor                    &
+                                                   )
                    particles(n)%particle_mask = .FALSE.
-                   deleted_particles          = deleted_particles + 1 
+                   deleted_particles          = deleted_particles + 1
                    merge_drp                  = merge_drp + 1
 
@@ -7379,21 +7119,18 @@
  END SUBROUTINE lpm_merging
 
- 
-
- 
-!------------------------------------------------------------------------------!
+
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Exchange between subdomains.
-!> As soon as one particle has moved beyond the boundary of the domain, it
-!> is included in the relevant transfer arrays and marked for subsequent
-!> deletion on this PE.
-!> First sweep for crossings in x direction. Find out first the number of
-!> particles to be transferred and allocate temporary arrays needed to store
-!> them.
-!> For a one-dimensional decomposition along y, no transfer is necessary,
-!> because the particle remains on the PE, but the particle coordinate has to
-!> be adjusted.
-!------------------------------------------------------------------------------!
+!> As soon as one particle has moved beyond the boundary of the domain, it is included in the
+!> relevant transfer arrays and marked for subsequent deletion on this PE.
+!> First sweep for crossings in x direction. Find out first the number of particles to be
+!> transferred and allocate temporary arrays needed to store them.
+!> For a one-dimensional decomposition along y, no transfer is necessary, because the particle
+!> remains on the PE, but the particle coordinate has to be adjusted.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_exchange_horiz
 
@@ -7401,5 +7138,5 @@
     INTEGER(iwp) ::  jp                !< index variable along y
     INTEGER(iwp) ::  kp                !< index variable along z
-    INTEGER(iwp) ::  n                 !< particle index variable 
+    INTEGER(iwp) ::  n                 !< particle index variable
 
 #if defined( __parallel )
@@ -7432,13 +7169,10 @@
 !
 !-- Exchange between subdomains.
-!-- As soon as one particle has moved beyond the boundary of the domain, it
-!-- is included in the relevant transfer arrays and marked for subsequent
-!-- deletion on this PE.
-!-- First sweep for crossings in x direction. Find out first the number of
-!-- particles to be transferred and allocate temporary arrays needed to store
-!-- them.
-!-- For a one-dimensional decomposition along y, no transfer is necessary,
-!-- because the particle remains on the PE, but the particle coordinate has to
-!-- be adjusted.
+!-- As soon as one particle has moved beyond the boundary of the domain, it is included in the
+!-- relevant transfer arrays and marked for subsequent deletion on this PE.
+!-- First sweep for crossings in x direction. Find out first the number of particles to be
+!-- transferred and allocate temporary arrays needed to store them.
+!-- For a one-dimensional decomposition along y, no transfer is necessary, because the particle
+!-- remains on the PE, but the particle coordinate has to be adjusted.
     trlp_count  = 0
     trrp_count  = 0
@@ -7449,6 +7183,6 @@
     IF ( pdims(1) /= 1 )  THEN
 !
-!--    First calculate the storage necessary for sending and receiving the data.
-!--    Compute only first (nxl) and last (nxr) loop iterration.
+!--    First calculate the storage necessary for sending and receiving the data. Compute only first
+!--    (nxl) and last (nxr) loop iterration.
        DO  ip = nxl, nxr, nxr - nxl
           DO  jp = nys, nyn
@@ -7499,6 +7233,5 @@
              DO  n = 1, number_of_particles
 !
-!--             Only those particles that have not been marked as 'deleted' may
-!--             be moved.
+!--             Only those particles that have not been marked as 'deleted' may be moved.
                 IF ( particles(n)%particle_mask )  THEN
 
@@ -7551,6 +7284,6 @@
                       ELSE
 !
-!--                      Store particle data in the transfer array, which will be 
-!--                      send to the neighbouring PE
+!--                      Store particle data in the transfer array, which will be send to the
+!--                      neighbouring PE
                          trlp_count = trlp_count + 1
                          trlp(trlp_count) = particles(n)
@@ -7569,12 +7302,11 @@
                             IF ( pdims(1) == 1 )  THEN
                                particles(n)%x = particles(n)%x - ( nx + 1 ) * dx
-                               particles(n)%origin_x = particles(n)%origin_x - &
-                               ( nx + 1 ) * dx
+                               particles(n)%origin_x = particles(n)%origin_x - ( nx + 1 ) * dx
                             ELSE
                                trrp_count = trrp_count + 1
                                trrp(trrp_count) = particles(n)
                                trrp(trrp_count)%x = trrp(trrp_count)%x - ( nx + 1 ) * dx
-                               trrp(trrp_count)%origin_x = trrp(trrp_count)%origin_x - &
-                               ( nx + 1 ) * dx
+                               trrp(trrp_count)%origin_x = trrp(trrp_count)%origin_x -             &
+                                                           ( nx + 1 ) * dx
                                particles(n)%particle_mask = .FALSE.
                                deleted_particles = deleted_particles + 1
@@ -7597,6 +7329,6 @@
                       ELSE
 !
-!--                      Store particle data in the transfer array, which will be send
-!--                      to the neighbouring PE
+!--                      Store particle data in the transfer array, which will be send to the
+!--                      neighbouring PE
                          trrp_count = trrp_count + 1
                          trrp(trrp_count) = particles(n)
@@ -7615,32 +7347,31 @@
 
 !
-!-- STORAGE_SIZE returns the storage size of argument A in bits. However , it 
+!-- STORAGE_SIZE returns the storage size of argument A in bits. However , it
 !-- is needed in bytes. The function C_SIZEOF which produces this value directly
 !-- causes problems with gfortran. For this reason the use of C_SIZEOF is avoided
-    par_size = STORAGE_SIZE(trlp(1))/8
-
-
-!
-!-- Allocate arrays required for north-south exchange, as these
-!-- are used directly after particles are exchange along x-direction.
-    ALLOCATE( move_also_north(1:NR_2_direction_move) )
-    ALLOCATE( move_also_south(1:NR_2_direction_move) )
+    par_size = STORAGE_SIZE( trlp(1) ) / 8
+
+
+!
+!-- Allocate arrays required for north-south exchange, as these are used directly after particles
+!-- are exchange along x-direction.
+    ALLOCATE( move_also_north(1:nr_2_direction_move) )
+    ALLOCATE( move_also_south(1:nr_2_direction_move) )
 
     nr_move_north = 0
     nr_move_south = 0
 !
-!-- Send left boundary, receive right boundary (but first exchange how many
-!-- and check, if particle storage must be extended)
+!-- Send left boundary, receive right boundary (but first exchange how many and check, if particle
+!-- storage must be extended)
     IF ( pdims(1) /= 1 )  THEN
 
-       CALL MPI_SENDRECV( trlp_count,      1, MPI_INTEGER, pleft,  0, &
-                          trrp_count_recv, 1, MPI_INTEGER, pright, 0, &
+       CALL MPI_SENDRECV( trlp_count,      1, MPI_INTEGER, pleft,  0,                              &
+                          trrp_count_recv, 1, MPI_INTEGER, pright, 0,                              &
                           comm2d, status, ierr )
 
        ALLOCATE(rvrp(MAX(1,trrp_count_recv)))
 
-       CALL MPI_SENDRECV( trlp, max(1,trlp_count)*par_size, MPI_BYTE,&
-                          pleft, 1, rvrp,                            &
-                          max(1,trrp_count_recv)*par_size, MPI_BYTE, pright, 1,&
+       CALL MPI_SENDRECV( trlp, MAX(1,trlp_count)*par_size,      MPI_BYTE, pleft, 1,               &
+                          rvrp, MAX(1,trrp_count_recv)*par_size, MPI_BYTE, pright, 1,              &
                           comm2d, status, ierr )
 
@@ -7651,15 +7382,14 @@
 !
 !--    Send right boundary, receive left boundary
-       CALL MPI_SENDRECV( trrp_count,      1, MPI_INTEGER, pright, 0, &
-                          trlp_count_recv, 1, MPI_INTEGER, pleft,  0, &
+       CALL MPI_SENDRECV( trrp_count,      1, MPI_INTEGER, pright, 0,                              &
+                          trlp_count_recv, 1, MPI_INTEGER, pleft,  0,                              &
                           comm2d, status, ierr )
 
        ALLOCATE(rvlp(MAX(1,trlp_count_recv)))
 !
-!--    This MPI_SENDRECV should work even with odd mixture on 32 and 64 Bit 
-!--    variables in structure particle_type (due to the calculation of par_size)
-       CALL MPI_SENDRECV( trrp, max(1,trrp_count)*par_size, MPI_BYTE,&
-                          pright, 1, rvlp,                           &
-                          max(1,trlp_count_recv)*par_size, MPI_BYTE, pleft, 1, &
+!--    This MPI_SENDRECV should work even with odd mixture on 32 and 64 Bit variables in structure
+!--    particle_type (due to the calculation of par_size)
+       CALL MPI_SENDRECV( trrp, MAX(1,trrp_count)*par_size,      MPI_BYTE, pright, 1,              &
+                          rvlp, MAX(1,trlp_count_recv)*par_size, MPI_BYTE,  pleft, 1,              &
                           comm2d, status, ierr )
 
@@ -7672,11 +7402,10 @@
 
 !
-!-- Check whether particles have crossed the boundaries in y direction. Note 
-!-- that this case can also apply to particles that have just been received
-!-- from the adjacent right or left PE.
-!-- Find out first the number of particles to be transferred and allocate
-!-- temporary arrays needed to store them.
-!-- For a one-dimensional decomposition along y, no transfer is necessary,
-!-- because the particle remains on the PE.
+!-- Check whether particles have crossed the boundaries in y direction. Note that this case can also
+!-- apply to particles that have just been received from the adjacent right or left PE.
+!-- Find out first the number of particles to be transferred and allocate temporary arrays needed to
+!-- store them.
+!-- For a one-dimensional decomposition along y, no transfer is necessary, because the particle
+!-- remains on the PE.
     trsp_count  = nr_move_south
     trnp_count  = nr_move_north
@@ -7687,6 +7416,5 @@
     IF ( pdims(2) /= 1 )  THEN
 !
-!--    First calculate the storage necessary for sending and receiving the
-!--    data
+!--    First calculate the storage necessary for sending and receiving the data
        DO  ip = nxl, nxr
           DO  jp = nys, nyn, nyn-nys    !compute only first (nys) and last (nyn) loop iterration
@@ -7737,6 +7465,5 @@
              DO  n = 1, number_of_particles
 !
-!--             Only those particles that have not been marked as 'deleted' may
-!--             be moved.
+!--             Only those particles that have not been marked as 'deleted' may be moved.
                 IF ( particles(n)%particle_mask )  THEN
 
@@ -7755,13 +7482,11 @@
                             IF ( pdims(2) == 1 )  THEN
                                particles(n)%y = ( ny + 1 ) * dy + particles(n)%y
-                               particles(n)%origin_y = ( ny + 1 ) * dy + &
-                                                     particles(n)%origin_y
+                               particles(n)%origin_y = ( ny + 1 ) * dy + particles(n)%origin_y
                             ELSE
                                trsp_count         = trsp_count + 1
                                trsp(trsp_count)   = particles(n)
-                               trsp(trsp_count)%y = ( ny + 1 ) * dy + &
-                                                 trsp(trsp_count)%y
-                               trsp(trsp_count)%origin_y = trsp(trsp_count)%origin_y &
-                                                + ( ny + 1 ) * dy
+                               trsp(trsp_count)%y = ( ny + 1 ) * dy + trsp(trsp_count)%y
+                               trsp(trsp_count)%origin_y = trsp(trsp_count)%origin_y               &
+                                                           + ( ny + 1 ) * dy
                                particles(n)%particle_mask = .FALSE.
                                deleted_particles = deleted_particles + 1
@@ -7770,6 +7495,5 @@
                                   trsp(trsp_count)%y = trsp(trsp_count)%y - 1.0E-10_wp
                                   !++ why is 1 subtracted in next statement???
-                                  trsp(trsp_count)%origin_y =                        &
-                                                  trsp(trsp_count)%origin_y - 1
+                                  trsp(trsp_count)%origin_y = trsp(trsp_count)%origin_y - 1
                                ENDIF
 
@@ -7791,6 +7515,6 @@
                       ELSE
 !
-!--                      Store particle data in the transfer array, which will 
-!--                      be send to the neighbouring PE
+!--                      Store particle data in the transfer array, which will be send to the
+!--                      neighbouring PE
                          trsp_count = trsp_count + 1
                          trsp(trsp_count) = particles(n)
@@ -7809,13 +7533,11 @@
                             IF ( pdims(2) == 1 )  THEN
                                particles(n)%y        = particles(n)%y - ( ny + 1 ) * dy
-                               particles(n)%origin_y =                         &
-                                          particles(n)%origin_y - ( ny + 1 ) * dy
+                               particles(n)%origin_y = particles(n)%origin_y - ( ny + 1 ) * dy
                             ELSE
                                trnp_count         = trnp_count + 1
                                trnp(trnp_count)   = particles(n)
-                               trnp(trnp_count)%y =                            &
-                                          trnp(trnp_count)%y - ( ny + 1 ) * dy
-                               trnp(trnp_count)%origin_y =                     &
-                                         trnp(trnp_count)%origin_y - ( ny + 1 ) * dy
+                               trnp(trnp_count)%y = trnp(trnp_count)%y - ( ny + 1 ) * dy
+                               trnp(trnp_count)%origin_y =                                         &
+                                                         trnp(trnp_count)%origin_y - ( ny + 1 ) * dy
                                particles(n)%particle_mask = .FALSE.
                                deleted_particles          = deleted_particles + 1
@@ -7837,6 +7559,6 @@
                       ELSE
 !
-!--                      Store particle data in the transfer array, which will 
-!--                      be send to the neighbouring PE
+!--                      Store particle data in the transfer array, which will be send to the
+!--                      neighbouring PE
                          trnp_count = trnp_count + 1
                          trnp(trnp_count) = particles(n)
@@ -7854,6 +7576,6 @@
 
 !
-!-- Send front boundary, receive back boundary (but first exchange how many
-!-- and check, if particle storage must be extended)
+!-- Send front boundary, receive back boundary (but first exchange how many and check, if particle
+!-- storage must be extended)
     IF ( pdims(2) /= 1 )  THEN
 
@@ -7864,9 +7586,8 @@
        ALLOCATE(rvnp(MAX(1,trnp_count_recv)))
 !
-!--    This MPI_SENDRECV should work even with odd mixture on 32 and 64 Bit 
-!--    variables in structure particle_type (due to the calculation of par_size)
-       CALL MPI_SENDRECV( trsp, trsp_count*par_size, MPI_BYTE,      &
-                          psouth, 1, rvnp,                             &
-                          trnp_count_recv*par_size, MPI_BYTE, pnorth, 1,   &
+!--    This MPI_SENDRECV should work even with odd mixture on 32 and 64 Bit variables in structure
+!--    particle_type (due to the calculation of par_size)
+       CALL MPI_SENDRECV( trsp, trsp_count*par_size,      MPI_BYTE, psouth, 1,                     &
+                          rvnp, trnp_count_recv*par_size, MPI_BYTE, pnorth, 1,                     &
                           comm2d, status, ierr )
 
@@ -7877,15 +7598,14 @@
 !
 !--    Send back boundary, receive front boundary
-       CALL MPI_SENDRECV( trnp_count,      1, MPI_INTEGER, pnorth, 0, &
-                          trsp_count_recv, 1, MPI_INTEGER, psouth, 0, &
+       CALL MPI_SENDRECV( trnp_count,      1, MPI_INTEGER, pnorth, 0,                              &
+                          trsp_count_recv, 1, MPI_INTEGER, psouth, 0,                              &
                           comm2d, status, ierr )
 
        ALLOCATE(rvsp(MAX(1,trsp_count_recv)))
 !
-!--    This MPI_SENDRECV should work even with odd mixture on 32 and 64 Bit 
-!--    variables in structure particle_type (due to the calculation of par_size)
-       CALL MPI_SENDRECV( trnp, trnp_count*par_size, MPI_BYTE,      &
-                          pnorth, 1, rvsp,                          &
-                          trsp_count_recv*par_size, MPI_BYTE, psouth, 1,   &
+!--    This MPI_SENDRECV should work even with odd mixture on 32 and 64 Bit variables in structure
+!--    particle_type (due to the calculation of par_size)
+       CALL MPI_SENDRECV( trnp, trnp_count*par_size,      MPI_BYTE, pnorth, 1,                     &
+                          rvsp, trsp_count_recv*par_size, MPI_BYTE, psouth, 1,                     &
                           comm2d, status, ierr )
 
@@ -7922,6 +7642,5 @@
 !--                   Cyclic boundary. Relevant coordinate has to be changed.
                       particles(n)%x = ( nx + 1 ) * dx + particles(n)%x
-                      particles(n)%origin_x = ( nx + 1 ) * dx + &
-                               particles(n)%origin_x
+                      particles(n)%origin_x = ( nx + 1 ) * dx + particles(n)%origin_x
                    ELSEIF ( ibc_par_lr == 1 )  THEN
 !
@@ -7943,6 +7662,5 @@
 !--                   Cyclic boundary. Relevant coordinate has to be changed.
                       particles(n)%x = particles(n)%x - ( nx + 1 ) * dx
-                      particles(n)%origin_x = particles(n)%origin_x - &
-                               ( nx + 1 ) * dx
+                      particles(n)%origin_x = particles(n)%origin_x - ( nx + 1 ) * dx
 
                    ELSEIF ( ibc_par_lr == 1 )  THEN
@@ -7979,6 +7697,5 @@
 !--                   Cyclic boundary. Relevant coordinate has to be changed.
                       particles(n)%y = ( ny + 1 ) * dy + particles(n)%y
-                      particles(n)%origin_y = ( ny + 1 ) * dy + &
-                           particles(n)%origin_y
+                      particles(n)%origin_y = ( ny + 1 ) * dy + particles(n)%origin_y
 
                    ELSEIF ( ibc_par_ns == 1 )  THEN
@@ -8001,6 +7718,5 @@
 !--                   Cyclic boundary. Relevant coordinate has to be changed.
                       particles(n)%y = particles(n)%y - ( ny + 1 ) * dy
-                      particles(n)%origin_y = particles(n)%origin_y - &
-                                ( ny + 1 ) * dy
+                      particles(n)%origin_y = particles(n)%origin_y - ( ny + 1 ) * dy
 
                    ELSEIF ( ibc_par_ns == 1 )  THEN
@@ -8043,11 +7759,11 @@
 
 #if defined( __parallel )
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> If a particle moves from one processor to another, this subroutine moves 
-!> the corresponding elements from the particle arrays of the old grid cells 
-!> to the particle arrays of the new grid cells.
-!------------------------------------------------------------------------------!
+!> If a particle moves from one processor to another, this subroutine moves the corresponding
+!> elements from the particle arrays of the old grid cells to the particle arrays of the new grid
+!> cells.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_add_particles_to_gridcell (particle_array)
 
@@ -8065,7 +7781,8 @@
     TYPE(particle_type), DIMENSION(:), ALLOCATABLE ::  temp_ns        !< temporary particle array for reallocation
 
+
     pack_done     = .FALSE.
 
-    DO  n = 1, SIZE(particle_array)
+    DO  n = 1, SIZE( particle_array )
 
        IF ( .NOT. particle_array(n)%particle_mask )  CYCLE
@@ -8075,6 +7792,6 @@
 !
 !--    In case of stretching the actual k index must be found
-       IF ( dz_stretch_level /= -9999999.9_wp  .OR.         &
-            dz_stretch_level_start(1) /= -9999999.9_wp )  THEN
+       IF ( dz_stretch_level /= -9999999.9_wp  .OR.  dz_stretch_level_start(1) /= -9999999.9_wp )  &
+       THEN
           kp = MAX( MINLOC( ABS( particle_array(n)%z - zu ), DIM = 1 ) - 1, 1 )
        ELSE
@@ -8082,11 +7799,12 @@
        ENDIF
 
-       IF ( ip >= nxl  .AND.  ip <= nxr  .AND.  jp >= nys  .AND.  jp <= nyn    &
-            .AND.  kp >= nzb+1  .AND.  kp <= nzt)  THEN ! particle stays on processor
+       IF ( ip >= nxl    .AND.  ip <= nxr  .AND.  jp >= nys  .AND.  jp <= nyn  .AND.               &
+            kp >= nzb+1  .AND.  kp <= nzt)  THEN  ! particle stays on processor
+
           number_of_particles = prt_count(kp,jp,ip)
           particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
 
           pindex = prt_count(kp,jp,ip)+1
-          IF( pindex > SIZE(grid_particles(kp,jp,ip)%particles) )  THEN
+          IF( pindex > SIZE( grid_particles(kp,jp,ip)%particles ) )  THEN
              IF ( pack_done )  THEN
                 CALL realloc_particles_array ( ip, jp, kp )
@@ -8095,5 +7813,5 @@
                 prt_count(kp,jp,ip) = number_of_particles
                 pindex = prt_count(kp,jp,ip)+1
-                IF ( pindex > SIZE(grid_particles(kp,jp,ip)%particles) )  THEN
+                IF ( pindex > SIZE( grid_particles(kp,jp,ip)%particles ) )  THEN
                    CALL realloc_particles_array ( ip, jp, kp )
                 ENDIF
@@ -8103,19 +7821,20 @@
           grid_particles(kp,jp,ip)%particles(pindex) = particle_array(n)
           prt_count(kp,jp,ip) = pindex
+
        ELSE
+
           IF ( jp <= nys - 1 )  THEN
+
              nr_move_south = nr_move_south+1
 !
-!--          Before particle information is swapped to exchange-array, check 
-!--          if enough memory is allocated. If required, reallocate exchange
-!--          array.
-             IF ( nr_move_south > SIZE(move_also_south) )  THEN
-!
-!--             At first, allocate further temporary array to swap particle 
-!--             information.
-                ALLOCATE( temp_ns(SIZE(move_also_south)+NR_2_direction_move) )
+!--          Before particle information is swapped to exchange-array, check if enough memory is
+!--          allocated. If required, reallocate exchange array.
+             IF ( nr_move_south > SIZE( move_also_south ) )  THEN
+!
+!--             At first, allocate further temporary array to swap particle information.
+                ALLOCATE( temp_ns(SIZE( move_also_south )+nr_2_direction_move) )
                 temp_ns(1:nr_move_south-1) = move_also_south(1:nr_move_south-1)
                 DEALLOCATE( move_also_south )
-                ALLOCATE( move_also_south(SIZE(temp_ns)) )
+                ALLOCATE( move_also_south(SIZE( temp_ns )) )
                 move_also_south(1:nr_move_south-1) = temp_ns(1:nr_move_south-1)
                 DEALLOCATE( temp_ns )
@@ -8129,8 +7848,8 @@
 !--             Apply boundary condition along y
                 IF ( ibc_par_ns == 0 )  THEN
-                   move_also_south(nr_move_south)%y =                          &
-                      move_also_south(nr_move_south)%y + ( ny + 1 ) * dy
-                   move_also_south(nr_move_south)%origin_y =                   &
-                      move_also_south(nr_move_south)%origin_y + ( ny + 1 ) * dy
+                   move_also_south(nr_move_south)%y =                                              &
+                                                  move_also_south(nr_move_south)%y + ( ny + 1 ) * dy
+                   move_also_south(nr_move_south)%origin_y =                                       &
+                                           move_also_south(nr_move_south)%origin_y + ( ny + 1 ) * dy
                 ELSEIF ( ibc_par_ns == 1 )  THEN
 !
@@ -8142,25 +7861,24 @@
 !
 !--                Particle reflection
-                   move_also_south(nr_move_south)%y       =                    &
-                      -move_also_south(nr_move_south)%y
-                   move_also_south(nr_move_south)%speed_y =                    &
-                      -move_also_south(nr_move_south)%speed_y
+                   move_also_south(nr_move_south)%y       = -move_also_south(nr_move_south)%y
+                   move_also_south(nr_move_south)%speed_y = -move_also_south(nr_move_south)%speed_y
 
                 ENDIF
+
              ENDIF
+
           ELSEIF ( jp >= nyn+1 )  THEN
+
              nr_move_north = nr_move_north+1
 !
-!--          Before particle information is swapped to exchange-array, check 
-!--          if enough memory is allocated. If required, reallocate exchange
-!--          array.
-             IF ( nr_move_north > SIZE(move_also_north) )  THEN
-!
-!--             At first, allocate further temporary array to swap particle 
-!--             information.
-                ALLOCATE( temp_ns(SIZE(move_also_north)+NR_2_direction_move) )
+!--          Before particle information is swapped to exchange-array, check if enough memory is
+!--          allocated. If required, reallocate exchange array.
+             IF ( nr_move_north > SIZE( move_also_north ) )  THEN
+!
+!--             At first, allocate further temporary array to swap particle information.
+                ALLOCATE( temp_ns(SIZE( move_also_north )+nr_2_direction_move) )
                 temp_ns(1:nr_move_north-1) = move_also_south(1:nr_move_north-1)
                 DEALLOCATE( move_also_north )
-                ALLOCATE( move_also_north(SIZE(temp_ns)) )
+                ALLOCATE( move_also_north(SIZE( temp_ns )) )
                 move_also_north(1:nr_move_north-1) = temp_ns(1:nr_move_north-1)
                 DEALLOCATE( temp_ns )
@@ -8174,8 +7892,8 @@
                 IF ( ibc_par_ns == 0 )  THEN
 
-                   move_also_north(nr_move_north)%y =                          &
-                      move_also_north(nr_move_north)%y - ( ny + 1 ) * dy
-                   move_also_north(nr_move_north)%origin_y =                   &
-                      move_also_north(nr_move_north)%origin_y - ( ny + 1 ) * dy
+                   move_also_north(nr_move_north)%y =                                              &
+                                                  move_also_north(nr_move_north)%y - ( ny + 1 ) * dy
+                   move_also_north(nr_move_north)%origin_y =                                       &
+                                           move_also_north(nr_move_north)%origin_y - ( ny + 1 ) * dy
                 ELSEIF ( ibc_par_ns == 1 )  THEN
 !
@@ -8187,33 +7905,37 @@
 !
 !--                Particle reflection
-                   move_also_north(nr_move_north)%y       =                    &
-                      -move_also_north(nr_move_north)%y
-                   move_also_north(nr_move_north)%speed_y =                    &
-                      -move_also_north(nr_move_north)%speed_y
+                   move_also_north(nr_move_north)%y       = -move_also_north(nr_move_north)%y
+                   move_also_north(nr_move_north)%speed_y = -move_also_north(nr_move_north)%speed_y
 
                 ENDIF
+
              ENDIF
+
           ELSE
+
              IF ( .NOT. child_domain )  THEN
                 WRITE(0,'(a,8i7)') 'particle out of range ',myid,ip,jp,kp,nxl,nxr,nys,nyn
+
              ENDIF
+
           ENDIF
+
        ENDIF
+
     ENDDO
 
  END SUBROUTINE lpm_add_particles_to_gridcell
 #endif
- 
- 
-!------------------------------------------------------------------------------!
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> If a particle moves from one grid cell to another (on the current 
-!> processor!), this subroutine moves the corresponding element from the
-!> particle array of the old grid cell to the particle array of the new grid 
-!> cell.
-!------------------------------------------------------------------------------!
+!> If a particle moves from one grid cell to another (on the current processor!), this subroutine
+!> moves the corresponding element from the particle array of the old grid cell to the particle
+!> array of the new grid cell.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE lpm_move_particle
- 
+
     INTEGER(iwp)        ::  i           !< grid index (x) of particle position
     INTEGER(iwp)        ::  ip          !< index variable along x
@@ -8243,12 +7965,12 @@
                 k = kp
 !
-!--             Find correct vertical particle grid box (necessary in case of grid stretching)
-!--             Due to the CFL limitations only the neighbouring grid boxes are considered. 
+!--             Find correct vertical particle grid box (necessary in case of grid stretching).
+!--             Due to the CFL limitations only the neighbouring grid boxes are considered.
                 IF( zw(k)   < particles_before_move(n)%z ) k = k + 1
-                IF( zw(k-1) > particles_before_move(n)%z ) k = k - 1 
-
-!--             For lpm_exchange_horiz to work properly particles need to be moved to the outermost gridboxes
-!--             of the respective processor. If the particle index is inside the processor the following lines
-!--             will not change the index
+                IF( zw(k-1) > particles_before_move(n)%z ) k = k - 1
+
+!--             For lpm_exchange_horiz to work properly particles need to be moved to the outermost
+!--             gridboxes of the respective processor. If the particle index is inside the processor
+!--             the following lines will not change the index.
                 i = MIN ( i , nxr )
                 i = MAX ( i , nxl )
@@ -8263,12 +7985,11 @@
                 IF ( i /= ip  .OR.  j /= jp  .OR.  k /= kp )  THEN
 !!
-!--                If the particle stays on the same processor, the particle
-!--                will be added to the particle array of the new processor.
+!--                If the particle stays on the same processor, the particle will be added to the
+!--                particle array of the new processor.
                    number_of_particles = prt_count(k,j,i)
                    particles => grid_particles(k,j,i)%particles(1:number_of_particles)
 
                    pindex = prt_count(k,j,i)+1
-                   IF (  pindex > SIZE(grid_particles(k,j,i)%particles)  )     &
-                   THEN
+                   IF (  pindex > SIZE( grid_particles(k,j,i)%particles )  )  THEN
                       CALL realloc_particles_array( i, j, k )
                    ENDIF
@@ -8290,13 +8011,13 @@
 
  END SUBROUTINE lpm_move_particle
- 
-
-!------------------------------------------------------------------------------!
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Check CFL-criterion for each particle. If one particle violated the 
-!> criterion the particle will be deleted and a warning message is given.
-!------------------------------------------------------------------------------!
- SUBROUTINE lpm_check_cfl  
+!> Check CFL-criterion for each particle. If one particle violated the criterion the particle will
+!> be deleted and a warning message is given.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE lpm_check_cfl
 
     IMPLICIT NONE
@@ -8312,20 +8033,20 @@
              number_of_particles = prt_count(k,j,i)
              IF ( number_of_particles <= 0 )  CYCLE
-             particles => grid_particles(k,j,i)%particles(1:number_of_particles)         
+             particles => grid_particles(k,j,i)%particles(1:number_of_particles)
              DO  n = 1, number_of_particles
 !
-!--             Note, check for CFL does not work at first particle timestep 
-!--             when both, age and age_m are zero. 
+!--             Note, check for CFL does not work at first particle timestep when both, age and
+!--             age_m are zero.
                 IF ( particles(n)%age - particles(n)%age_m > 0.0_wp )  THEN
-                   IF( ABS( particles(n)%speed_x ) >                           &
-                      ( dx / ( particles(n)%age - particles(n)%age_m) )  .OR.  &
-                       ABS( particles(n)%speed_y ) >                           & 
-                      ( dy / ( particles(n)%age - particles(n)%age_m) )  .OR.  &
-                       ABS( particles(n)%speed_z ) >                           &
-                      ( ( zw(k)-zw(k-1) )                                      &
-                      / ( particles(n)%age - particles(n)%age_m) ) )  THEN
-                      WRITE( message_string, * )                               &
-                      'Particle violated CFL-criterion: &particle with id ',   &
-                      particles(n)%id, ' will be deleted!'   
+                   IF( ABS( particles(n)%speed_x ) >                                               &
+                       ( dx / ( particles(n)%age - particles(n)%age_m) )  .OR.                     &
+                       ABS( particles(n)%speed_y ) >                                               &
+                       ( dy / ( particles(n)%age - particles(n)%age_m) )  .OR.                     &
+                       ABS( particles(n)%speed_z ) >                                               &
+                       ( ( zw(k)-zw(k-1) ) / ( particles(n)%age - particles(n)%age_m) ) )          &
+                   THEN
+                      WRITE( message_string, * )                                                   &
+                         'Particle violated CFL-criterion: &particle with id ', particles(n)%id,   &
+                         ' will be deleted!'
                       CALL message( 'lpm_check_cfl', 'PA0475', 0, 1, -1, 6, 0 )
 
@@ -8336,16 +8057,16 @@
           ENDDO
        ENDDO
-    ENDDO   
+    ENDDO
 
  END SUBROUTINE lpm_check_cfl
- 
- 
-!------------------------------------------------------------------------------!
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> If the allocated memory for the particle array do not suffice to add arriving
-!> particles from neighbour grid cells, this subrouting reallocates the 
-!> particle array to assure enough memory is available. 
-!------------------------------------------------------------------------------!
+!> If the allocated memory for the particle array does not suffice to add arriving particles from
+!> neighbour grid cells, this subrouting reallocates the particle array to assure enough memory is
+!> available.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE realloc_particles_array ( i, j, k, size_in )
 
@@ -8355,12 +8076,12 @@
     INTEGER(iwp), INTENT(IN), OPTIONAL             ::  size_in        !<
 
+    INTEGER(iwp)                                   ::  new_size        !<
     INTEGER(iwp)                                   ::  old_size        !<
-    INTEGER(iwp)                                   ::  new_size        !<
     TYPE(particle_type), DIMENSION(:), ALLOCATABLE ::  tmp_particles_d !<
     TYPE(particle_type), DIMENSION(500)            ::  tmp_particles_s !<
 
-    old_size = SIZE(grid_particles(k,j,i)%particles)
-
-    IF ( PRESENT(size_in) )   THEN
+    old_size = SIZE( grid_particles(k,j,i)%particles )
+
+    IF ( PRESENT( size_in) )  THEN
        new_size = size_in
     ELSE
@@ -8397,16 +8118,16 @@
 
     RETURN
-    
+
  END SUBROUTINE realloc_particles_array
- 
- 
-!------------------------------------------------------------------------------!
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Not needed but allocated space for particles is dealloced. 
-!------------------------------------------------------------------------------!
+!> Not needed but allocated space for particles is dealloced.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE dealloc_particles_array
 
- 
+
     INTEGER(iwp) ::  i               !<
     INTEGER(iwp) ::  j               !<
@@ -8431,14 +8152,14 @@
 !
 !--          Check for large unused memory
-             dealloc = ( ( number_of_particles < 1 .AND.         &
-                           old_size            > 1 )  .OR.       &
-                         ( number_of_particles > 1 .AND.         &
-                           old_size - number_of_particles *                    &
-                              ( 1.0_wp + 0.01_wp * alloc_factor ) > 0.0_wp ) )
+             dealloc = ( ( number_of_particles < 1 .AND. old_size > 1 )  .OR.                      &
+                         ( number_of_particles > 1 .AND.                                           &
+                           old_size - number_of_particles * ( 1.0_wp + 0.01_wp * alloc_factor )    &
+                           > 0.0_wp )                                                              &
+                       )
 
              IF ( dealloc )  THEN
                 IF ( number_of_particles < 1 )  THEN
                    new_size = 1
-                ELSE 
+                ELSE
                    new_size = INT( number_of_particles * ( 1.0_wp + 0.01_wp * alloc_factor ) )
                 ENDIF
@@ -8474,15 +8195,14 @@
     ENDDO
 
- END SUBROUTINE dealloc_particles_array 
- 
- 
-!------------------------------------------------------------------------------!
+ END SUBROUTINE dealloc_particles_array
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! -----------
-!> Routine for the whole processor
-!> Sort all particles into the 8 respective subgrid boxes (in case of trilinear
-!> interpolation method) and free space of particles which has been marked for
-!> deletion.
-!------------------------------------------------------------------------------!
+!> Routine for the whole processor.
+!> Sort all particles into the 8 respective subgrid boxes (in case of trilinear interpolation
+!> method) and free space of particles which has been marked for deletion.
+!--------------------------------------------------------------------------------------------------!
    SUBROUTINE lpm_sort_and_delete
 
@@ -8520,8 +8240,8 @@
                          nn = nn + 1
 !
-!--                      Sorting particles with a binary scheme
+!--                      Sorting particles with a binary scheme.
 !--                      sort_index=111_2=7_10 -> particle at the left,south,bottom subgridbox
 !--                      sort_index=000_2=0_10 -> particle at the right,north,top subgridbox
-!--                      For this the center of the gridbox is calculated
+!--                      For this the center of the gridbox is calculated.
                          i = (particles(n)%x + 0.5_wp * dx) * ddx
                          j = (particles(n)%y + 0.5_wp * dy) * ddy
@@ -8538,6 +8258,6 @@
                    ENDDO
 !
-!--                Delete and resort particles by overwritting and set
-!--                the number_of_particles to the actual value.
+!--                Delete and resort particles by overwritting and set the number_of_particles to
+!--                the actual value.
                    nn = 0
                    DO  is = 0,7
@@ -8557,8 +8277,7 @@
           ENDDO
 
-!--    In case of the simple interpolation method the particles must not
-!--    be sorted in subboxes. Particles marked for deletion however, must be
-!--    deleted and number of particles must be recalculated as it is also
-!--    done for the trilinear particle advection interpolation method.
+!--    In case of the simple interpolation method the particles must not be sorted in subboxes.
+!--    Particles marked for deletion however, must be deleted and number of particles must be
+!--    recalculated as it is also done for the trilinear particle advection interpolation method.
        ELSE
 
@@ -8571,6 +8290,5 @@
                    particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
 !
-!--                Repack particles array, i.e. delete particles and recalculate
-!--                number of particles
+!--                Repack particles array, i.e. delete particles and recalculate number of particles
                    CALL lpm_pack
                    prt_count(kp,jp,ip) = number_of_particles
@@ -8583,10 +8301,10 @@
     END SUBROUTINE lpm_sort_and_delete
 
- 
-!------------------------------------------------------------------------------!
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Move all particles not marked for deletion to lowest indices (packing)
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE lpm_pack
 
@@ -8594,6 +8312,6 @@
        INTEGER(iwp) ::  nn      !<
 !
-!--    Find out elements marked for deletion and move data from highest index
-!--    values to these free indices
+!--    Find out elements marked for deletion and move data from highest index values to these free
+!--    indices
        nn = number_of_particles
 
@@ -8618,18 +8336,17 @@
 
 !
-!--    The number of deleted particles has been determined in routines
-!--    lpm_boundary_conds, lpm_droplet_collision, and lpm_exchange_horiz
+!--    The number of deleted particles has been determined in routines lpm_boundary_conds,
+!--    lpm_droplet_collision, and lpm_exchange_horiz
        number_of_particles = nn
 
-    END SUBROUTINE lpm_pack 
-
-
-!------------------------------------------------------------------------------!
+    END SUBROUTINE lpm_pack
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Sort particles in each sub-grid box into two groups: particles that already
-!> completed the LES timestep, and particles that need further timestepping to
-!> complete the LES timestep. 
-!------------------------------------------------------------------------------!
+!> Sort particles in each sub-grid box into two groups: particles that already completed the LES
+!> timestep, and particles that need further timestepping to complete the LES timestep.
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE lpm_sort_timeloop_done
 
@@ -8661,9 +8378,9 @@
                    end_index   = grid_particles(k,j,i)%end_index(nb)
 !
-!--                Allocate temporary array used for sorting. 
+!--                Allocate temporary array used for sorting.
                    ALLOCATE( sort_particles(start_index:end_index) )
 !
-!--                Determine number of particles already completed the LES 
-!--                timestep, and write them into a temporary array. 
+!--                Determine number of particles already completed the LES timestep, and write them
+!--                into a temporary array.
                    nf = start_index
                    num_finalized = 0
@@ -8676,6 +8393,6 @@
                    ENDDO
 !
-!--                Determine number of particles that not completed the LES 
-!--                timestep, and write them into a temporary array. 
+!--                Determine number of particles that not completed the LES timestep, and write them
+!--                into a temporary array.
                    nnf = nf
                    DO  n = start_index, end_index
@@ -8687,20 +8404,17 @@
 !
 !--                Write back sorted particles
-                   particles(start_index:end_index) =                          &
-                                           sort_particles(start_index:end_index)
-!
-!--                Determine updated start_index, used to masked already 
-!--                completed particles. 
-                   grid_particles(k,j,i)%start_index(nb) =                     &
-                                      grid_particles(k,j,i)%start_index(nb)    &
-                                    + num_finalized
+                   particles(start_index:end_index) = sort_particles(start_index:end_index)
+!
+!--                Determine updated start_index, used to masked already
+!--                completed particles.
+                   grid_particles(k,j,i)%start_index(nb) = grid_particles(k,j,i)%start_index(nb)   &
+                                                           + num_finalized
 !
 !--                Deallocate dummy array
                    DEALLOCATE ( sort_particles )
 !
-!--                Finally, if number of non-completed particles is non zero 
-!--                in any of the sub-boxes, set control flag appropriately. 
-                   IF ( nnf > nf )                                             &
-                      grid_particles(k,j,i)%time_loop_done = .FALSE.
+!--                Finally, if number of non-completed particles is non zero
+!--                in any of the sub-boxes, set control flag appropriately.
+                   IF ( nnf > nf )  grid_particles(k,j,i)%time_loop_done = .FALSE.
 
                 ENDDO
@@ -8709,5 +8423,5 @@
        ENDDO
 
-    END SUBROUTINE lpm_sort_timeloop_done 
+    END SUBROUTINE lpm_sort_timeloop_done
 
 END MODULE lagrangian_particle_model_mod
