Index: /palm/trunk/SOURCE/dynamics_mod.f90
===================================================================
--- /palm/trunk/SOURCE/dynamics_mod.f90	(revision 4625)
+++ /palm/trunk/SOURCE/dynamics_mod.f90	(revision 4626)
@@ -3,15 +3,14 @@
 ! 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
@@ -20,30 +19,33 @@
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4517 2020-05-03 14:29:30Z raasch
 ! added restart with MPI-IO for reading local arrays
-! 
+!
 ! 4505 2020-04-20 15:37:15Z schwenkel
 ! Add flag for saturation check
-! 
+!
 ! 4495 2020-04-13 20:11:20Z resler
 ! restart data handling with MPI-IO added
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Bugfix for last commit.
-! 
+!
 ! 4359 2019-12-30 13:36:50Z suehring
 ! Refine post-initialization check for realistically inital values of mixing ratio. Give an error
-! message for faulty initial values, but only a warning in a restart run. 
-! 
+! message for faulty initial values, but only a warning in a restart run.
+!
 ! 4347 2019-12-18 13:18:33Z suehring
 ! Implement post-initialization check for realistically inital values of mixing ratio
-! 
+!
 ! 4281 2019-10-29 15:15:39Z schwenkel
 ! Moved boundary conditions in dynamics module
-! 
+!
 ! 4097 2019-07-15 11:59:11Z suehring
 ! Avoid overlong lines - limit is 132 characters per line
@@ -60,14 +62,14 @@
 
 
-    USE arrays_3d, &
-        ONLY:  c_u, c_u_m, c_u_m_l, c_v, c_v_m, c_v_m_l, c_w, c_w_m, c_w_m_l,  &
-               dzu, &
-               exner, &
-               hyp, &
-               pt, pt_1, pt_2, pt_init, pt_p, &
-               q, q_1, q_2, q_p, &
-               s, s_1, s_2, s_p, &
-               u, u_1, u_2, u_init, u_p, u_m_l, u_m_n, u_m_r, u_m_s, &
-               v, v_1, v_2, v_p, v_init, v_m_l, v_m_n, v_m_r, v_m_s, &
+    USE arrays_3d,                                                                                 &
+        ONLY:  c_u, c_u_m, c_u_m_l, c_v, c_v_m, c_v_m_l, c_w, c_w_m, c_w_m_l,                      &
+               dzu,                                                                                &
+               exner,                                                                              &
+               hyp,                                                                                &
+               pt, pt_1, pt_2, pt_init, pt_p,                                                      &
+               q, q_1, q_2, q_p,                                                                   &
+               s, s_1, s_2, s_p,                                                                   &
+               u, u_1, u_2, u_init, u_p, u_m_l, u_m_n, u_m_r, u_m_s,                               &
+               v, v_1, v_2, v_p, v_init, v_m_l, v_m_n, v_m_r, v_m_s,                               &
                w, w_1, w_2, w_p, w_m_l, w_m_n, w_m_r, w_m_s
 
@@ -76,58 +78,58 @@
                rd_d_rv
 
-    USE control_parameters, &
-        ONLY:  bc_dirichlet_l, &
-               bc_dirichlet_s, &
-               bc_radiation_l, &
-               bc_radiation_n, &
-               bc_radiation_r, &
-               bc_radiation_s, &
-               bc_pt_t_val, &
-               bc_q_t_val, &
-               bc_s_t_val, &
-               check_realistic_q, &
-               child_domain, &
-               coupling_mode, &
-               dt_3d, &
-               ibc_pt_b, &
-               ibc_pt_t, &
-               ibc_q_b, &
-               ibc_q_t, &
-               ibc_s_b, &
-               ibc_s_t, &
-               ibc_uv_b, &
-               ibc_uv_t, &
-               initializing_actions, &
-               intermediate_timestep_count, &
-               length, &
-               message_string, &
-               nesting_offline, &
-               nudging, &
-               restart_string, &
-               humidity, &
-               neutral, &
-               passive_scalar, &
-               tsc, &
+    USE control_parameters,                                                                        &
+        ONLY:  bc_dirichlet_l,                                                                     &
+               bc_dirichlet_s,                                                                     &
+               bc_radiation_l,                                                                     &
+               bc_radiation_n,                                                                     &
+               bc_radiation_r,                                                                     &
+               bc_radiation_s,                                                                     &
+               bc_pt_t_val,                                                                        &
+               bc_q_t_val,                                                                         &
+               bc_s_t_val,                                                                         &
+               check_realistic_q,                                                                  &
+               child_domain,                                                                       &
+               coupling_mode,                                                                      &
+               dt_3d,                                                                              &
+               humidity,                                                                           &
+               ibc_pt_b,                                                                           &
+               ibc_pt_t,                                                                           &
+               ibc_q_b,                                                                            &
+               ibc_q_t,                                                                            &
+               ibc_s_b,                                                                            &
+               ibc_s_t,                                                                            &
+               ibc_uv_b,                                                                           &
+               ibc_uv_t,                                                                           &
+               initializing_actions,                                                               &
+               intermediate_timestep_count,                                                        &
+               length,                                                                             &
+               message_string,                                                                     &
+               nesting_offline,                                                                    &
+               neutral,                                                                            &
+               nudging,                                                                            &
+               passive_scalar,                                                                     &
+               restart_string,                                                                     &
+               tsc,                                                                                &
                use_cmax
 
-    USE grid_variables, &
-        ONLY:  ddx, &
-               ddy, &
-               dx, &
+    USE grid_variables,                                                                            &
+        ONLY:  ddx,                                                                                &
+               ddy,                                                                                &
+               dx,                                                                                 &
                dy
 
-    USE indices, &
-        ONLY:  nbgp, &
-               nx, &
-               nxl, &
-               nxlg, &
-               nxr, &
-               nxrg, &
-               ny, &
-               nys, &
-               nysg, &
-               nyn, &
-               nyng, &
-               nzb, &
+    USE indices,                                                                                   &
+        ONLY:  nbgp,                                                                               &
+               nx,                                                                                 &
+               nxl,                                                                                &
+               nxlg,                                                                               &
+               nxr,                                                                                &
+               nxrg,                                                                               &
+               ny,                                                                                 &
+               nys,                                                                                &
+               nysg,                                                                               &
+               nyn,                                                                                &
+               nyng,                                                                               &
+               nzb,                                                                                &
                nzt
 
@@ -136,5 +138,5 @@
     USE pegrid
 
-    USE pmc_interface, &
+    USE pmc_interface,                                                                             &
         ONLY : nesting_mode
 
@@ -142,5 +144,5 @@
 !        ONLY:
 
-    USE surface_mod, &
+    USE surface_mod,                                                                               &
         ONLY :  bc_h
 
@@ -156,35 +158,35 @@
 !
 !-- Public functions
-    PUBLIC &
-       dynamics_parin, &
-       dynamics_check_parameters, &
-       dynamics_check_data_output_ts, &
-       dynamics_check_data_output_pr, &
-       dynamics_check_data_output, &
-       dynamics_init_masks, &
-       dynamics_define_netcdf_grid, &
-       dynamics_init_arrays, &
-       dynamics_init, &
-       dynamics_init_checks, &
-       dynamics_header, &
-       dynamics_actions, &
-       dynamics_non_advective_processes, &
-       dynamics_exchange_horiz, &
-       dynamics_prognostic_equations, &
-       dynamics_boundary_conditions, &
-       dynamics_swap_timelevel, &
-       dynamics_3d_data_averaging, &
-       dynamics_data_output_2d, &
-       dynamics_data_output_3d, &
-       dynamics_statistics, &
-       dynamics_rrd_global, &
-       dynamics_rrd_local, &
-       dynamics_wrd_global, &
-       dynamics_wrd_local, &
+    PUBLIC                                                                                         &
+       dynamics_parin,                                                                             &
+       dynamics_check_parameters,                                                                  &
+       dynamics_check_data_output_ts,                                                              &
+       dynamics_check_data_output_pr,                                                              &
+       dynamics_check_data_output,                                                                 &
+       dynamics_init_masks,                                                                        &
+       dynamics_define_netcdf_grid,                                                                &
+       dynamics_init_arrays,                                                                       &
+       dynamics_init,                                                                              &
+       dynamics_init_checks,                                                                       &
+       dynamics_header,                                                                            &
+       dynamics_actions,                                                                           &
+       dynamics_non_advective_processes,                                                           &
+       dynamics_exchange_horiz,                                                                    &
+       dynamics_prognostic_equations,                                                              &
+       dynamics_boundary_conditions,                                                               &
+       dynamics_swap_timelevel,                                                                    &
+       dynamics_3d_data_averaging,                                                                 &
+       dynamics_data_output_2d,                                                                    &
+       dynamics_data_output_3d,                                                                    &
+       dynamics_statistics,                                                                        &
+       dynamics_rrd_global,                                                                        &
+       dynamics_rrd_local,                                                                         &
+       dynamics_wrd_global,                                                                        &
+       dynamics_wrd_local,                                                                         &
        dynamics_last_actions
 
 !
 !-- Public parameters, constants and initial values
-    PUBLIC &
+    PUBLIC                                                                                         &
        dynamics_module_enabled
 
@@ -312,6 +314,7 @@
     CHARACTER (LEN=80)  ::  line  !< dummy string that contains the current line of the parameter file
 
-    NAMELIST /dynamics_parameters/  &
+    NAMELIST /dynamics_parameters/                                                                 &
        dynamics_module_enabled
+
 
     line = ' '
@@ -360,9 +363,9 @@
  SUBROUTINE dynamics_check_data_output_ts( dots_max, dots_num, dots_label, dots_unit )
 
+    CHARACTER (LEN=*), DIMENSION(dots_max), INTENT(INOUT)  :: dots_label
+    CHARACTER (LEN=*), DIMENSION(dots_max), INTENT(INOUT)  :: dots_unit
 
     INTEGER(iwp),      INTENT(IN)     ::  dots_max
     INTEGER(iwp),      INTENT(INOUT)  ::  dots_num
-    CHARACTER (LEN=*), DIMENSION(dots_max), INTENT(INOUT)  :: dots_label
-    CHARACTER (LEN=*), DIMENSION(dots_max), INTENT(INOUT)  :: dots_unit
 
 !
@@ -384,7 +387,7 @@
 
 
+    CHARACTER (LEN=*) ::  dopr_unit !< local value of dopr_unit
     CHARACTER (LEN=*) ::  unit     !<
     CHARACTER (LEN=*) ::  variable !<
-    CHARACTER (LEN=*) ::  dopr_unit !< local value of dopr_unit
 
     INTEGER(iwp) ::  var_count     !<
@@ -433,10 +436,10 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Description:
 ! ------------
 !> Initialize module-specific masked output
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE dynamics_init_masks( variable, unit )
 
@@ -499,10 +502,10 @@
 
 !
-!-- Check for realistic initial mixing ratio. This must be in a realistic phyiscial range and must 
-!-- not exceed the saturation mixing ratio by more than 2 percent. Please note, the check is 
-!-- performed for each grid point (not just for a vertical profile), in order to cover also 
+!-- Check for realistic initial mixing ratio. This must be in a realistic phyiscial range and must
+!-- not exceed the saturation mixing ratio by more than 2 percent. Please note, the check is
+!-- performed for each grid point (not just for a vertical profile), in order to cover also
 !-- three-dimensional initialization. Note, this check gives an error only for the initial run not
 !-- for a restart run. In case there are no cloud physics considered, the mixing ratio can exceed
-!-- the saturation moisture. This case a warning is given. 
+!-- the saturation moisture. This case a warning is given.
     IF ( humidity  .AND.  .NOT. neutral  .AND.  check_realistic_q )  THEN
        DO  i = nxl, nxr
@@ -516,10 +519,10 @@
                 q_s = rd_d_rv * e_s / ( hyp(k) - e_s )
 
-                IF ( q(k,j,i) > 1.02_wp * q_s )  realistic_q = .FALSE. 
+                IF ( q(k,j,i) > 1.02_wp * q_s )  realistic_q = .FALSE.
              ENDDO
           ENDDO
        ENDDO
 !
-!--    Since the check is performed locally, merge the logical flag from all mpi ranks, 
+!--    Since the check is performed locally, merge the logical flag from all mpi ranks,
 !--    in order to do not print the error message multiple times.
 #if defined( __parallel )
@@ -598,6 +601,6 @@
 !-- Format-descriptors
 100 FORMAT (//' *** dynamic module disabled'/)
-110 FORMAT (//1X,78('#')                                                       &
-            //' User-defined variables and actions:'/                          &
+110 FORMAT (//1X,78('#')                                                                           &
+            //' User-defined variables and actions:'/                                              &
               ' -----------------------------------'//)
 
@@ -621,6 +624,6 @@
 !
 !-- Here the user-defined actions follow
-!-- No calls for single grid points are allowed at locations before and
-!-- after the timestep, since these calls are not within an i,j-loop
+!-- No calls for single grid points are allowed at locations before and after the timestep, since
+!-- these calls are not within an i,j-loop
     SELECT CASE ( location )
 
@@ -688,4 +691,5 @@
        CASE ( 'u-tendency' )
 
+!
 !--       Next line is to avoid compiler warning about unused variables. Please remove.
           IF ( i +  j < 0 )  CONTINUE
@@ -784,6 +788,6 @@
 
     INTEGER(iwp), INTENT(IN) ::  i            !< grid index in x-direction
+    INTEGER(iwp), INTENT(IN) ::  i_omp_start  !< first loop index of i-loop in prognostic_equations
     INTEGER(iwp), INTENT(IN) ::  j            !< grid index in y-direction
-    INTEGER(iwp), INTENT(IN) ::  i_omp_start  !< first loop index of i-loop in prognostic_equations
     INTEGER(iwp), INTENT(IN) ::  tn           !< task number of openmp task
 
@@ -848,6 +852,6 @@
 !
 !-- Vertical nesting: Vertical velocity not zero at the top of the fine grid
-    IF (  .NOT.  child_domain  .AND.  .NOT.  nesting_offline  .AND.            &
-                 TRIM(coupling_mode) /= 'vnested_fine' )  THEN
+    IF ( .NOT.  child_domain  .AND.  .NOT.  nesting_offline  .AND.                                 &
+         TRIM(coupling_mode) /= 'vnested_fine' )  THEN
        !$ACC KERNELS PRESENT(w_p)
        w_p(nzt:nzt+1,:,:) = 0.0_wp  !< nzt is not a prognostic level (but cf. pres)
@@ -857,6 +861,6 @@
 !
 !-- Temperature at bottom and top boundary.
-!-- In case of coupled runs (ibc_pt_b = 2) the temperature is given by
-!-- the sea surface temperature of the coupled ocean model.
+!-- In case of coupled runs (ibc_pt_b = 2) the temperature is given by the sea surface temperature
+!-- of the coupled ocean model.
 !-- Dirichlet
     IF ( .NOT. neutral )  THEN
@@ -906,12 +910,10 @@
     ENDIF
 !
-!-- Boundary conditions for total water content,
-!-- bottom and top boundary (see also temperature)
+!-- Boundary conditions for total water content, bottom and top boundary (see also temperature)
     IF ( humidity )  THEN
 !
 !--    Surface conditions for constant_humidity_flux
-!--    Run loop over all non-natural and natural walls. Note, in wall-datatype
-!--    the k coordinate belongs to the atmospheric grid point, therefore, set
-!--    q_p at k-1
+!--    Run loop over all non-natural and natural walls. Note, in wall-datatype the k coordinate
+!--    belongs to the atmospheric grid point, therefore, set q_p at k-1
        IF ( ibc_q_b == 0 ) THEN
 
@@ -947,12 +949,10 @@
     ENDIF
 !
-!-- Boundary conditions for scalar,
-!-- bottom and top boundary (see also temperature)
+!-- Boundary conditions for scalar, bottom and top boundary (see also temperature)
     IF ( passive_scalar )  THEN
 !
 !--    Surface conditions for constant_humidity_flux
-!--    Run loop over all non-natural and natural walls. Note, in wall-datatype
-!--    the k coordinate belongs to the atmospheric grid point, therefore, set
-!--    s_p at k-1
+!--    Run loop over all non-natural and natural walls. Note, in wall-datatype the k coordinate
+!--    belongs to the atmospheric grid point, therefore, set s_p at k-1
        IF ( ibc_s_b == 0 ) THEN
 
@@ -991,9 +991,8 @@
     ENDIF
 !
-!-- In case of inflow or nest boundary at the south boundary the boundary for v
-!-- is at nys and in case of inflow or nest boundary at the left boundary the
-!-- boundary for u is at nxl. Since in prognostic_equations (cache optimized
-!-- version) these levels are handled as a prognostic level, boundary values
-!-- have to be restored here.
+!-- In case of inflow or nest boundary at the south boundary the boundary for v is at nys and in
+!-- case of inflow or nest boundary at the left boundary the boundary for u is at nxl. Since in
+!-- prognostic_equations (cache optimized version) these levels are handled as a prognostic level,
+!-- boundary values have to be restored here.
     IF ( bc_dirichlet_s )  THEN
        v_p(:,nys,:) = v_p(:,nys-1,:)
@@ -1003,9 +1002,8 @@
 
 !
-!-- The same restoration for u at i=nxl and v at j=nys as above must be made
-!-- in case of nest boundaries. This must not be done in case of vertical nesting
-!-- mode as in that case the lateral boundaries are actually cyclic.
-!-- Lateral oundary conditions for TKE and dissipation are set
-!-- in tcm_boundary_conds.
+!-- The same restoration for u at i=nxl and v at j=nys as above must be made in case of nest
+!-- boundaries. This must not be done in case of vertical nesting mode as in that case the lateral
+!-- boundaries are actually cyclic.
+!-- Lateral oundary conditions for TKE and dissipation are set in tcm_boundary_conds.
     IF ( nesting_mode /= 'vertical'  .OR.  nesting_offline )  THEN
        IF ( bc_dirichlet_s )  THEN
@@ -1019,6 +1017,5 @@
 !
 !-- Lateral boundary conditions for scalar quantities at the outflow.
-!-- Lateral oundary conditions for TKE and dissipation are set
-!-- in tcm_boundary_conds.
+!-- Lateral oundary conditions for TKE and dissipation are set in tcm_boundary_conds.
     IF ( bc_radiation_s )  THEN
        pt_p(:,nys-1,:)     = pt_p(:,nys,:)
@@ -1049,7 +1046,7 @@
 !
 !-- Radiation boundary conditions for the velocities at the respective outflow.
-!-- The phase velocity is either assumed to the maximum phase velocity that
-!-- ensures numerical stability (CFL-condition) or calculated after
-!-- Orlanski(1976) and averaged along the outflow boundary.
+!-- The phase velocity is either assumed to the maximum phase velocity that ensures numerical
+!-- stability (CFL-condition) or calculated after Orlanski(1976) and averaged along the outflow
+!-- boundary.
     IF ( bc_radiation_s )  THEN
 
@@ -1071,6 +1068,6 @@
 
 !
-!--       Calculate the phase speeds for u, v, and w, first local and then
-!--       average along the outflow boundary.
+!--       Calculate the phase speeds for u, v, and w, first local and then average along the outflow
+!--       boundary.
           DO  k = nzb+1, nzt+1
              DO  i = nxl, nxr
@@ -1124,12 +1121,12 @@
 #if defined( __parallel )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
-          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dx, ierr )
+          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dx,   &
+                              ierr )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
-          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dx, ierr )
+          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dx,   &
+                              ierr )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
-          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dx, ierr )
+          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dx,   &
+                              ierr )
 #else
           c_u_m = c_u_m_l
@@ -1154,12 +1151,12 @@
           DO  k = nzb+1, nzt+1
              DO  i = nxlg, nxrg
-                u_p(k,-1,i) = u(k,-1,i) - dt_3d * tsc(2) * c_u_m(k) *          &
-                                       ( u(k,-1,i) - u(k,0,i) ) * ddy
-
-                v_p(k,0,i)  = v(k,0,i)  - dt_3d * tsc(2) * c_v_m(k) *          &
-                                       ( v(k,0,i) - v(k,1,i) ) * ddy
-
-                w_p(k,-1,i) = w(k,-1,i) - dt_3d * tsc(2) * c_w_m(k) *          &
-                                       ( w(k,-1,i) - w(k,0,i) ) * ddy
+                u_p(k,-1,i) = u(k,-1,i) - dt_3d * tsc(2) * c_u_m(k) *                              &
+                                          ( u(k,-1,i) - u(k,0,i) ) * ddy
+
+                v_p(k,0,i)  = v(k,0,i)  - dt_3d * tsc(2) * c_v_m(k) *                              &
+                                          ( v(k,0,i) - v(k,1,i) ) * ddy
+
+                w_p(k,-1,i) = w(k,-1,i) - dt_3d * tsc(2) * c_w_m(k) *                              &
+                                          ( w(k,-1,i) - w(k,0,i) ) * ddy
              ENDDO
           ENDDO
@@ -1210,6 +1207,6 @@
 
 !
-!--       Calculate the phase speeds for u, v, and w, first local and then
-!--       average along the outflow boundary.
+!--       Calculate the phase speeds for u, v, and w, first local and then average along the outflow
+!--       boundary.
           DO  k = nzb+1, nzt+1
              DO  i = nxl, nxr
@@ -1263,12 +1260,12 @@
 #if defined( __parallel )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
-          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dx, ierr )
+          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dx,   &
+                              ierr )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
-          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dx, ierr )
+          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dx,   &
+                              ierr )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
-          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dx, ierr )
+          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dx,   &
+                              ierr )
 #else
           c_u_m = c_u_m_l
@@ -1293,12 +1290,12 @@
           DO  k = nzb+1, nzt+1
              DO  i = nxlg, nxrg
-                u_p(k,ny+1,i) = u(k,ny+1,i) - dt_3d * tsc(2) * c_u_m(k) *      &
-                                       ( u(k,ny+1,i) - u(k,ny,i) ) * ddy
-
-                v_p(k,ny+1,i) = v(k,ny+1,i)  - dt_3d * tsc(2) * c_v_m(k) *     &
-                                       ( v(k,ny+1,i) - v(k,ny,i) ) * ddy
-
-                w_p(k,ny+1,i) = w(k,ny+1,i) - dt_3d * tsc(2) * c_w_m(k) *      &
-                                       ( w(k,ny+1,i) - w(k,ny,i) ) * ddy
+                u_p(k,ny+1,i) = u(k,ny+1,i) - dt_3d * tsc(2) * c_u_m(k) *                          &
+                                              ( u(k,ny+1,i) - u(k,ny,i) ) * ddy
+
+                v_p(k,ny+1,i) = v(k,ny+1,i)  - dt_3d * tsc(2) * c_v_m(k) *                         &
+                                               ( v(k,ny+1,i) - v(k,ny,i) ) * ddy
+
+                w_p(k,ny+1,i) = w(k,ny+1,i) - dt_3d * tsc(2) * c_w_m(k) *                          &
+                                              ( w(k,ny+1,i) - w(k,ny,i) ) * ddy
              ENDDO
           ENDDO
@@ -1349,6 +1346,6 @@
 
 !
-!--       Calculate the phase speeds for u, v, and w, first local and then
-!--       average along the outflow boundary.
+!--       Calculate the phase speeds for u, v, and w, first local and then average along the outflow
+!--       boundary.
           DO  k = nzb+1, nzt+1
              DO  j = nys, nyn
@@ -1402,12 +1399,12 @@
 #if defined( __parallel )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
-          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dy, ierr )
+          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dy,   &
+                              ierr )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
-          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dy, ierr )
+          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dy,   &
+                              ierr )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
-          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dy, ierr )
+          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dy,   &
+                              ierr )
 #else
           c_u_m = c_u_m_l
@@ -1432,12 +1429,12 @@
           DO  k = nzb+1, nzt+1
              DO  j = nysg, nyng
-                u_p(k,j,0) = u(k,j,0) - dt_3d * tsc(2) * c_u_m(k) *            &
-                                       ( u(k,j,0) - u(k,j,1) ) * ddx
-
-                v_p(k,j,-1) = v(k,j,-1) - dt_3d * tsc(2) * c_v_m(k) *          &
-                                       ( v(k,j,-1) - v(k,j,0) ) * ddx
-
-                w_p(k,j,-1) = w(k,j,-1) - dt_3d * tsc(2) * c_w_m(k) *          &
-                                       ( w(k,j,-1) - w(k,j,0) ) * ddx
+                u_p(k,j,0)  = u(k,j,0) - dt_3d * tsc(2) * c_u_m(k) *                               &
+                                         ( u(k,j,0) - u(k,j,1) ) * ddx
+
+                v_p(k,j,-1) = v(k,j,-1) - dt_3d * tsc(2) * c_v_m(k) *                              &
+                                          ( v(k,j,-1) - v(k,j,0) ) * ddx
+
+                w_p(k,j,-1) = w(k,j,-1) - dt_3d * tsc(2) * c_w_m(k) *                              &
+                                          ( w(k,j,-1) - w(k,j,0) ) * ddx
              ENDDO
           ENDDO
@@ -1488,6 +1485,6 @@
 
 !
-!--       Calculate the phase speeds for u, v, and w, first local and then
-!--       average along the outflow boundary.
+!--       Calculate the phase speeds for u, v, and w, first local and then average along the outflow
+!--       boundary.
           DO  k = nzb+1, nzt+1
              DO  j = nys, nyn
@@ -1541,12 +1538,12 @@
 #if defined( __parallel )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
-          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dy, ierr )
+          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dy,   &
+                              ierr )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
-          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dy, ierr )
+          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dy,   &
+                              ierr )
           IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
-          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
-                              MPI_SUM, comm1dy, ierr )
+          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, MPI_SUM, comm1dy,   &
+                              ierr )
 #else
           c_u_m = c_u_m_l
@@ -1571,12 +1568,12 @@
           DO  k = nzb+1, nzt+1
              DO  j = nysg, nyng
-                u_p(k,j,nx+1) = u(k,j,nx+1) - dt_3d * tsc(2) * c_u_m(k) *      &
-                                       ( u(k,j,nx+1) - u(k,j,nx) ) * ddx
-
-                v_p(k,j,nx+1) = v(k,j,nx+1) - dt_3d * tsc(2) * c_v_m(k) *      &
-                                       ( v(k,j,nx+1) - v(k,j,nx) ) * ddx
-
-                w_p(k,j,nx+1) = w(k,j,nx+1) - dt_3d * tsc(2) * c_w_m(k) *      &
-                                       ( w(k,j,nx+1) - w(k,j,nx) ) * ddx
+                u_p(k,j,nx+1) = u(k,j,nx+1) - dt_3d * tsc(2) * c_u_m(k) *                          &
+                                              ( u(k,j,nx+1) - u(k,j,nx) ) * ddx
+
+                v_p(k,j,nx+1) = v(k,j,nx+1) - dt_3d * tsc(2) * c_v_m(k) *                          &
+                                              ( v(k,j,nx+1) - v(k,j,nx) ) * ddx
+
+                w_p(k,j,nx+1) = w(k,j,nx+1) - dt_3d * tsc(2) * c_w_m(k) *                          &
+                                              ( w(k,j,nx+1) - w(k,j,nx) ) * ddx
              ENDDO
           ENDDO
@@ -1609,9 +1606,9 @@
 
  END SUBROUTINE dynamics_boundary_conditions
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Swap timelevels of module-specific array pointers
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE dynamics_swap_timelevel ( mod_count )
 
@@ -1660,6 +1657,6 @@
 ! Description:
 ! ------------
-!> Sum up and time-average module-specific output quantities
-!> as well as allocate the array necessary for storing the average.
+!> Sum up and time-average module-specific output quantities as well as allocate the array necessary
+!> for storing the average.
 !--------------------------------------------------------------------------------------------------!
  SUBROUTINE dynamics_3d_data_averaging( mode, variable )
@@ -1709,15 +1706,15 @@
 ! Description:
 ! ------------
-!> Resorts the module-specific output quantity with indices (k,j,i) to a
-!> temporary array with indices (i,j,k) and sets the grid on which it is defined.
+!> Resorts the module-specific output quantity with indices (k,j,i) to a temporary array with
+!> indices (i,j,k) and sets the grid on which it is defined.
 !> Allowed values for grid are "zu" and "zw".
 !--------------------------------------------------------------------------------------------------!
- SUBROUTINE dynamics_data_output_2d( av, variable, found, grid, mode, local_pf, &
-                                     two_d, nzb_do, nzt_do, fill_value )
-
-
-    CHARACTER (LEN=*) ::  grid     !<
+ SUBROUTINE dynamics_data_output_2d( av, variable, found, grid, mode, local_pf, two_d, nzb_do,     &
+                                     nzt_do, fill_value )
+
+
+    CHARACTER (LEN=*)             ::  grid       !<
     CHARACTER (LEN=*), INTENT(IN) ::  mode       !< either 'xy', 'xz' or 'yz'
-    CHARACTER (LEN=*) ::  variable !<
+    CHARACTER (LEN=*)             ::  variable   !<
 
     INTEGER(iwp) ::  av     !< flag to control data output of instantaneous or time-averaged data
@@ -1759,6 +1756,6 @@
 ! Description:
 ! ------------
-!> Resorts the module-specific output quantity with indices (k,j,i)
-!> to a temporary array with indices (i,j,k).
+!> Resorts the module-specific output quantity with indices (k,j,i) to a temporary array with
+!> indices (i,j,k).
 !--------------------------------------------------------------------------------------------------!
  SUBROUTINE dynamics_data_output_3d( av, variable, found, local_pf, fill_value, nzb_do, nzt_do )
@@ -1836,5 +1833,4 @@
  SUBROUTINE dynamics_rrd_global_ftn( found )
 
-
     LOGICAL, INTENT(OUT)  ::  found
 
@@ -1864,5 +1860,4 @@
 !--------------------------------------------------------------------------------------------------!
  SUBROUTINE dynamics_rrd_global_mpi
-
 
 !    CALL rrd_mpi_io( 'global_parameter', global_parameter )
@@ -1880,6 +1875,7 @@
 !> to the subdomain of the current PE (c). They have been calculated in routine rrd_local.
 !--------------------------------------------------------------------------------------------------!
- SUBROUTINE dynamics_rrd_local_ftn( k, nxlf, nxlc, nxl_on_file, nxrf, nxrc, nxr_on_file, nynf, nync,   &
-                                    nyn_on_file, nysf, nysc, nys_on_file, tmp_2d, tmp_3d, found )
+ SUBROUTINE dynamics_rrd_local_ftn( k, nxlf, nxlc, nxl_on_file, nxrf, nxrc, nxr_on_file, nynf,     &
+                                    nync, nyn_on_file, nysf, nysc, nys_on_file, tmp_2d, tmp_3d,    &
+                                    found )
 
 
@@ -1905,6 +1901,6 @@
 !
 !-- Next line is to avoid compiler warning about unused variables. Please remove.
-    IF ( k + nxlc + nxlf + nxrc + nxrf + nync + nynf + nysc + nysf +           &
-         tmp_2d(nys_on_file,nxl_on_file) +                                     &
+    IF ( k + nxlc + nxlf + nxrc + nxrf + nync + nynf + nysc + nysf +                               &
+         tmp_2d(nys_on_file,nxl_on_file) +                                                         &
          tmp_3d(nzb,nys_on_file,nxl_on_file) < 0.0 )  CONTINUE
 !
Index: /palm/trunk/SOURCE/exchange_horiz_mod.f90
===================================================================
--- /palm/trunk/SOURCE/exchange_horiz_mod.f90	(revision 4625)
+++ /palm/trunk/SOURCE/exchange_horiz_mod.f90	(revision 4626)
@@ -1,46 +1,48 @@
 !> @file exchange_horiz.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
+!
+! 4474 2020-03-26 09:32:18Z raasch
 ! bugfix for correct usage of alternative communicators in case of 1d-decompositions and in
 ! non-parallel mode
-! 
+!
 ! 4461 2020-03-12 16:51:59Z raasch
 ! optional communicator added to exchange_horiz
-! 
+!
 ! 4457 2020-03-11 14:20:43Z raasch
 ! routine has been modularized, file exchange_horiz_2d has been merged
-! 
+!
 ! 4429 2020-02-27 15:24:30Z raasch
 ! bugfix: cpp-directives added for serial mode
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Corrected "Former revisions" section
-! 
+!
 ! 3761 2019-02-25 15:31:42Z raasch
 ! OpenACC directives re-formatted
-! 
+!
 ! 3657 2019-01-07 20:14:18Z knoop
 ! OpenACC port for SPEC
@@ -52,7 +54,7 @@
 ! Description:
 ! ------------
-!> Exchange of ghost point layers for subdomains (in parallel mode) and setting
-!> of cyclic lateral boundary conditions for the total domain .
-!------------------------------------------------------------------------------!
+!> Exchange of ghost point layers for subdomains (in parallel mode) and setting of cyclic lateral
+!> boundary conditions for the total domain .
+!--------------------------------------------------------------------------------------------------!
  MODULE exchange_horiz_mod
 
@@ -91,27 +93,27 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Exchange of ghost point layers for subdomains (in parallel mode) and setting
-!> of cyclic lateral boundary conditions for the total domain.
+!> Exchange of ghost point layers for subdomains (in parallel mode) and setting of cyclic lateral
+!> boundary conditions for the total domain.
 !> This routine is for REAL 3d-arrays.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE exchange_horiz( ar, nbgp_local, alternative_communicator)
 
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  bc_lr_cyc, bc_ns_cyc
 
 #if defined( __parallel )
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  grid_level, mg_switch_to_pe0, synchronous_exchange
 #endif
-                
-    USE cpulog,                                                                &
+
+    USE cpulog,                                                                                    &
         ONLY:  cpu_log, log_point_s
-        
-    USE indices,                                                               &
+
+    USE indices,                                                                                   &
         ONLY:  nxl, nxr, nyn, nys, nzb, nzt
-        
+
 
 #if defined( _OPENACC )
@@ -120,4 +122,5 @@
 
     INTEGER(iwp), OPTIONAL ::  alternative_communicator  !< alternative MPI communicator to be used
+
     INTEGER(iwp) ::  communicator  !< communicator that is used as argument in MPI calls
     INTEGER(iwp) ::  left_pe       !< id of left pe that is used as argument in MPI calls
@@ -126,8 +129,8 @@
     INTEGER(iwp) ::  right_pe      !< id of right pe that is used as argument in MPI calls
     INTEGER(iwp) ::  south_pe      !< id of south pe that is used as argument in MPI calls
-    
-    REAL(wp), DIMENSION(nzb:nzt+1,nys-nbgp_local:nyn+nbgp_local,               &
+
+    REAL(wp), DIMENSION(nzb:nzt+1,nys-nbgp_local:nyn+nbgp_local,                                   &
                         nxl-nbgp_local:nxr+nbgp_local) ::  ar !< 3d-array for which exchange is done
-                        
+
 
     CALL cpu_log( log_point_s(2), 'exchange_horiz', 'start' )
@@ -184,6 +187,5 @@
     IF ( pdims(1) == 1  .OR.  mg_switch_to_pe0 )  THEN
 !
-!--    One-dimensional decomposition along y, boundary values can be exchanged
-!--    within the PE memory
+!--    One-dimensional decomposition along y, boundary values can be exchanged within the PE memory.
        IF ( PRESENT( alternative_communicator ) )  THEN
           IF ( alternative_communicator <= 2 )  THEN
@@ -253,6 +255,5 @@
     IF ( pdims(2) == 1  .OR.  mg_switch_to_pe0 )  THEN
 !
-!--    One-dimensional decomposition along x, boundary values can be exchanged
-!--    within the PE memory
+!--    One-dimensional decomposition along x, boundary values can be exchanged within the PE memory
        IF ( PRESENT( alternative_communicator ) )  THEN
           IF ( alternative_communicator == 1  .OR.  alternative_communicator == 3 )  THEN
@@ -317,7 +318,7 @@
 !
 !-- Lateral boundary conditions in the non-parallel case.
-!-- Case dependent, because in GPU mode still not all arrays are on device. This
-!-- workaround has to be removed later. Also, since PGI compiler 12.5 has problems
-!-- with array syntax, explicit loops are used.
+!-- Case dependent, because in GPU mode still not all arrays are on device. This workaround has to
+!-- be removed later. Also, since PGI compiler 12.5 has problems with array syntax, explicit loops
+!-- are used.
     IF ( PRESENT( alternative_communicator ) )  THEN
        IF ( alternative_communicator <= 2 )  THEN
@@ -371,23 +372,24 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE exchange_horiz_int( ar, nys_l, nyn_l, nxl_l, nxr_l, nzt_l, nbgp_local )
 
 
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  bc_lr_cyc, bc_ns_cyc
 
 #if defined( __parallel )
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  grid_level
 #endif
-                       
-    USE indices,                                                               &
+
+    USE indices,                                                                                   &
         ONLY:  nzb
 
+    INTEGER(iwp) ::  nbgp_local  !< number of ghost points
     INTEGER(iwp) ::  nxl_l       !< local index bound at current grid level, left side
     INTEGER(iwp) ::  nxr_l       !< local index bound at current grid level, right side
@@ -395,7 +397,6 @@
     INTEGER(iwp) ::  nys_l       !< local index bound at current grid level, south side
     INTEGER(iwp) ::  nzt_l       !< local index bound at current grid level, top
-    INTEGER(iwp) ::  nbgp_local  !< number of ghost points
-    
-    INTEGER(iwp), DIMENSION(nzb:nzt_l+1,nys_l-nbgp_local:nyn_l+nbgp_local,     &
+
+    INTEGER(iwp), DIMENSION(nzb:nzt_l+1,nys_l-nbgp_local:nyn_l+nbgp_local,                         &
                             nxl_l-nbgp_local:nxr_l+nbgp_local) ::  ar  !< treated array
 
@@ -404,6 +405,5 @@
     IF ( pdims(1) == 1 )  THEN
 !
-!--    One-dimensional decomposition along y, boundary values can be exchanged
-!--    within the PE memory
+!--    One-dimensional decomposition along y, boundary values can be exchanged within the PE memory
        IF ( bc_lr_cyc )  THEN
           ar(:,:,nxl_l-nbgp_local:nxl_l-1) = ar(:,:,nxr_l-nbgp_local+1:nxr_l)
@@ -413,16 +413,14 @@
 !
 !--    Send left boundary, receive right one (synchronous)
-       CALL MPI_SENDRECV(                                                          &
-           ar(nzb,nys_l-nbgp_local,nxl_l),   1, type_yz_int(grid_level), pleft,  0,&
-           ar(nzb,nys_l-nbgp_local,nxr_l+1), 1, type_yz_int(grid_level), pright, 0,&
-           comm2d, status, ierr )
+       CALL MPI_SENDRECV( ar(nzb,nys_l-nbgp_local,nxl_l),   1, type_yz_int(grid_level), pleft,  0, &
+                          ar(nzb,nys_l-nbgp_local,nxr_l+1), 1, type_yz_int(grid_level), pright, 0, &
+                          comm2d, status, ierr )
 !
 !--    Send right boundary, receive left one (synchronous)
-       CALL MPI_SENDRECV(                                                          &
-           ar(nzb,nys_l-nbgp_local,nxr_l+1-nbgp_local), 1, type_yz_int(grid_level),&
-           pright, 1,                                                              &
-           ar(nzb,nys_l-nbgp_local,nxl_l-nbgp_local),   1, type_yz_int(grid_level),&
-           pleft,  1,                                                              &
-           comm2d, status, ierr )
+       CALL MPI_SENDRECV( ar(nzb,nys_l-nbgp_local,nxr_l+1-nbgp_local), 1, type_yz_int(grid_level), &
+                          pright, 1,                                                               &
+                          ar(nzb,nys_l-nbgp_local,nxl_l-nbgp_local),   1, type_yz_int(grid_level), &
+                          pleft,  1,                                                               &
+                          comm2d, status, ierr )
     ENDIF
 
@@ -430,6 +428,5 @@
     IF ( pdims(2) == 1 )  THEN
 !
-!--    One-dimensional decomposition along x, boundary values can be exchanged
-!--    within the PE memory
+!--    One-dimensional decomposition along x, boundary values can be exchanged within the PE memory
        IF ( bc_ns_cyc )  THEN
           ar(:,nys_l-nbgp_local:nys_l-1,:) = ar(:,nyn_l-nbgp_local+1:nyn_l,:)
@@ -441,14 +438,13 @@
 !
 !--    Send front boundary, receive rear one (synchronous)
-       CALL MPI_SENDRECV(                                                          &
-           ar(nzb,nys_l,nxl_l-nbgp_local),   1, type_xz_int(grid_level), psouth, 0,&
-           ar(nzb,nyn_l+1,nxl_l-nbgp_local), 1, type_xz_int(grid_level), pnorth, 0,&
-           comm2d, status, ierr )
+       CALL MPI_SENDRECV( ar(nzb,nys_l,nxl_l-nbgp_local),   1, type_xz_int(grid_level), psouth, 0, &
+                          ar(nzb,nyn_l+1,nxl_l-nbgp_local), 1, type_xz_int(grid_level), pnorth, 0, &
+                          comm2d, status, ierr )
 !
 !--    Send rear boundary, receive front one (synchronous)
-       CALL MPI_SENDRECV( ar(nzb,nyn_l-nbgp_local+1,nxl_l-nbgp_local), 1,          &
-                          type_xz_int(grid_level), pnorth, 1,                      &
-                          ar(nzb,nys_l-nbgp_local,nxl_l-nbgp_local),   1,          &
-                          type_xz_int(grid_level), psouth, 1,                      &
+       CALL MPI_SENDRECV( ar(nzb,nyn_l-nbgp_local+1,nxl_l-nbgp_local), 1,                          &
+                          type_xz_int(grid_level), pnorth, 1,                                      &
+                          ar(nzb,nys_l-nbgp_local,nxl_l-nbgp_local),   1,                          &
+                          type_xz_int(grid_level), psouth, 1,                                      &
                           comm2d, status, ierr )
 
@@ -473,22 +469,21 @@
 ! Description:
 ! ------------
-!> Exchange of lateral (ghost) boundaries (parallel computers) and cyclic
-!> boundary conditions, respectively, for 2D-arrays.
-!------------------------------------------------------------------------------!
+!> Exchange of lateral (ghost) boundaries (parallel computers) and cyclic boundary conditions,
+!> respectively, for 2D-arrays.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE exchange_horiz_2d( ar )
 
-    USE control_parameters,                                                    &
-        ONLY :  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r,                &
-                bc_dirichlet_s, bc_radiation_l,                                &
-                bc_radiation_n, bc_radiation_r, bc_radiation_s
-
-    USE cpulog,                                                                &
+    USE control_parameters,                                                                        &
+        ONLY :  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s,                    &
+                bc_radiation_l, bc_radiation_n, bc_radiation_r, bc_radiation_s
+
+    USE cpulog,                                                                                    &
         ONLY :  cpu_log, log_point_s
 
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY :  nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg
 
 #if ! defined( __parallel )
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  bc_lr_cyc, bc_ns_cyc
 #endif
@@ -509,6 +504,5 @@
 
 !
-!--    One-dimensional decomposition along y, boundary values can be exchanged
-!--    within the PE memory
+!--    One-dimensional decomposition along y, boundary values can be exchanged within the PE memory
        ar(:,nxlg:nxl-1) = ar(:,nxr-nbgp+1:nxr)
        ar(:,nxr+1:nxrg) = ar(:,nxl:nxl+nbgp-1)
@@ -518,11 +512,11 @@
 !--    Send left boundary, receive right one
 
-       CALL MPI_SENDRECV( ar(nysg,nxl), 1, type_y, pleft,  0,                 &
-                          ar(nysg,nxr+1), 1, type_y, pright, 0,               &
+       CALL MPI_SENDRECV( ar(nysg,nxl), 1, type_y, pleft,  0,                                      &
+                          ar(nysg,nxr+1), 1, type_y, pright, 0,                                    &
                           comm2d, status, ierr )
 !
 !--    Send right boundary, receive left one
-       CALL MPI_SENDRECV( ar(nysg,nxr+1-nbgp), 1, type_y, pright,  1,         &
-                          ar(nysg,nxlg), 1, type_y, pleft,   1,               &
+       CALL MPI_SENDRECV( ar(nysg,nxr+1-nbgp), 1, type_y, pright,  1,                              &
+                          ar(nysg,nxlg), 1, type_y, pleft,   1,                                    &
                           comm2d, status, ierr )
 
@@ -532,6 +526,5 @@
     IF ( pdims(2) == 1 )  THEN
 !
-!--    One-dimensional decomposition along x, boundary values can be exchanged
-!--    within the PE memory
+!--    One-dimensional decomposition along x, boundary values can be exchanged within the PE memory
        ar(nysg:nys-1,:) = ar(nyn-nbgp+1:nyn,:)
        ar(nyn+1:nyng,:) = ar(nys:nys+nbgp-1,:)
@@ -541,11 +534,11 @@
 !--    Send front boundary, receive rear one
 
-       CALL MPI_SENDRECV( ar(nys,nxlg), 1, type_x, psouth, 0,                 &
-                          ar(nyn+1,nxlg), 1, type_x, pnorth, 0,               &
+       CALL MPI_SENDRECV( ar(nys,nxlg), 1, type_x, psouth, 0,                                      &
+                          ar(nyn+1,nxlg), 1, type_x, pnorth, 0,                                    &
                           comm2d, status, ierr )
 !
 !--    Send rear boundary, receive front one
-       CALL MPI_SENDRECV( ar(nyn+1-nbgp,nxlg), 1, type_x, pnorth, 1,          &
-                          ar(nysg,nxlg), 1, type_x, psouth, 1,                &
+       CALL MPI_SENDRECV( ar(nyn+1-nbgp,nxlg), 1, type_x, pnorth, 1,                               &
+                          ar(nysg,nxlg), 1, type_x, psouth, 1,                                     &
                           comm2d, status, ierr )
 
@@ -596,26 +589,26 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Exchange of lateral (ghost) boundaries (parallel computers) and cyclic
-!> boundary conditions, respectively, for 2D 8-bit integer arrays.
-!------------------------------------------------------------------------------!
+!> Exchange of lateral (ghost) boundaries (parallel computers) and cyclic boundary conditions,
+!> respectively, for 2D 8-bit integer arrays.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE exchange_horiz_2d_byte( ar, nys_l, nyn_l, nxl_l, nxr_l, nbgp_local )
 
 
-    USE control_parameters,                                                    &
-        ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s, &
-               bc_radiation_l, bc_radiation_n, bc_radiation_r, bc_radiation_s, &
+    USE control_parameters,                                                                        &
+        ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s,                     &
                bc_radiation_l, bc_radiation_n, bc_radiation_r, bc_radiation_s
 
-    USE cpulog,                                                                &
+    USE cpulog,                                                                                    &
         ONLY:  cpu_log, log_point_s
 
 #if ! defined( __parallel )
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  bc_lr_cyc, bc_ns_cyc
 #endif
 
+    INTEGER(iwp) ::  nbgp_local  !< number of ghost layers to be exchanged
     INTEGER(iwp) ::  i           !< dummy index to zero-gradient conditions at in/outflow boundaries
     INTEGER(iwp) ::  nxl_l       !< local index bound at current grid level, left side
@@ -623,7 +616,6 @@
     INTEGER(iwp) ::  nyn_l       !< local index bound at current grid level, north side
     INTEGER(iwp) ::  nys_l       !< local index bound at current grid level, south side
-    INTEGER(iwp) ::  nbgp_local  !< number of ghost layers to be exchanged
-
-    INTEGER(KIND=1), DIMENSION(nys_l-nbgp_local:nyn_l+nbgp_local,              &
+
+    INTEGER(KIND=1), DIMENSION(nys_l-nbgp_local:nyn_l+nbgp_local,                                  &
                                nxl_l-nbgp_local:nxr_l+nbgp_local) ::  ar  !< treated array
 
@@ -637,6 +629,5 @@
 
 !
-!--    One-dimensional decomposition along y, boundary values can be exchanged
-!--    within the PE memory
+!--    One-dimensional decomposition along y, boundary values can be exchanged within the PE memory
        ar(:,nxl_l-nbgp_local:nxl_l-1) = ar(:,nxr_l-nbgp_local+1:nxr_l)
        ar(:,nxr_l+1:nxr_l+nbgp_local) = ar(:,nxl_l:nxl_l+nbgp_local-1)
@@ -645,15 +636,15 @@
 !
 !--    Send left boundary, receive right one
-       CALL MPI_SENDRECV( ar(nys_l-nbgp_local,nxl_l),   1,                     &
-                          type_y_byte, pleft,  0,                              &
-                          ar(nys_l-nbgp_local,nxr_l+1), 1,                     &
-                          type_y_byte, pright, 0,                              &
+       CALL MPI_SENDRECV( ar(nys_l-nbgp_local,nxl_l),   1,                                         &
+                          type_y_byte, pleft,  0,                                                  &
+                          ar(nys_l-nbgp_local,nxr_l+1), 1,                                         &
+                          type_y_byte, pright, 0,                                                  &
                           comm2d, status, ierr )
 !
 !--    Send right boundary, receive left one
-       CALL MPI_SENDRECV( ar(nys_l-nbgp_local,nxr_l+1-nbgp_local), 1,          &
-                          type_y_byte, pright, 1,                              &
-                          ar(nys_l-nbgp_local,nxl_l-nbgp_local),   1,          &
-                          type_y_byte, pleft,  1,                              &
+       CALL MPI_SENDRECV( ar(nys_l-nbgp_local,nxr_l+1-nbgp_local), 1,                              &
+                          type_y_byte, pright, 1,                                                  &
+                          ar(nys_l-nbgp_local,nxl_l-nbgp_local),   1,                              &
+                          type_y_byte, pleft,  1,                                                  &
                           comm2d, status, ierr )
 
@@ -662,6 +653,5 @@
     IF ( pdims(2) == 1 )  THEN
 !
-!--    One-dimensional decomposition along x, boundary values can be exchanged
-!--    within the PE memory
+!--    One-dimensional decomposition along x, boundary values can be exchanged within the PE memory
        ar(nys_l-nbgp_local:nys_l-1,:) = ar(nyn_l+1-nbgp_local:nyn_l,:)
        ar(nyn_l+1:nyn_l+nbgp_local,:) = ar(nys_l:nys_l-1+nbgp_local,:)
@@ -671,16 +661,16 @@
 !
 !--    Send front boundary, receive rear one
-       CALL MPI_SENDRECV( ar(nys_l,nxl_l-nbgp_local),   1,                    &
-                          type_x_byte, psouth, 0,                             &
-                          ar(nyn_l+1,nxl_l-nbgp_local), 1,                    &
-                          type_x_byte, pnorth, 0,                             &
+       CALL MPI_SENDRECV( ar(nys_l,nxl_l-nbgp_local),   1,                                         &
+                          type_x_byte, psouth, 0,                                                  &
+                          ar(nyn_l+1,nxl_l-nbgp_local), 1,                                         &
+                          type_x_byte, pnorth, 0,                                                  &
                           comm2d, status, ierr )
 
 !
 !--    Send rear boundary, receive front one
-       CALL MPI_SENDRECV( ar(nyn_l+1-nbgp_local,nxl_l-nbgp_local), 1,         &
-                          type_x_byte, pnorth, 1,                             &
-                          ar(nys_l-nbgp_local,nxl_l-nbgp_local),   1,         &
-                          type_x_byte, psouth, 1,                             &
+       CALL MPI_SENDRECV( ar(nyn_l+1-nbgp_local,nxl_l-nbgp_local), 1,                              &
+                          type_x_byte, pnorth, 1,                                                  &
+                          ar(nys_l-nbgp_local,nxl_l-nbgp_local),   1,                              &
+                          type_x_byte, psouth, 1,                                                  &
                           comm2d, status, ierr )
 
@@ -730,31 +720,31 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Exchange of lateral (ghost) boundaries (parallel computers) and cyclic
-!> boundary conditions, respectively, for 2D 32-bit integer arrays.
-!------------------------------------------------------------------------------!
+!> Exchange of lateral (ghost) boundaries (parallel computers) and cyclic boundary conditions,
+!> respectively, for 2D 32-bit integer arrays.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE exchange_horiz_2d_int( ar, nys_l, nyn_l, nxl_l, nxr_l, nbgp_local )
 
 
-    USE control_parameters,                                                    &
-        ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s, &
-               bc_radiation_l, bc_radiation_n, bc_radiation_r, bc_radiation_s, &
+    USE control_parameters,                                                                        &
+        ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s,                     &
                bc_radiation_l, bc_radiation_n, bc_radiation_r, bc_radiation_s
 
 #if defined( __parallel )
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  grid_level
 #endif
 
-    USE cpulog,                                                                &
+    USE cpulog,                                                                                    &
         ONLY:  cpu_log, log_point_s
 
 #if ! defined( __parallel )
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  bc_lr_cyc, bc_ns_cyc
 #endif
 
+    INTEGER(iwp) ::  nbgp_local  !< number of ghost layers to be exchanged
     INTEGER(iwp) ::  i           !< dummy index to zero-gradient conditions at in/outflow boundaries
     INTEGER(iwp) ::  nxl_l       !< local index bound at current grid level, left side
@@ -762,7 +752,6 @@
     INTEGER(iwp) ::  nyn_l       !< local index bound at current grid level, north side
     INTEGER(iwp) ::  nys_l       !< local index bound at current grid level, south side
-    INTEGER(iwp) ::  nbgp_local  !< number of ghost layers to be exchanged
-
-    INTEGER(iwp), DIMENSION(nys_l-nbgp_local:nyn_l+nbgp_local,                 &
+
+    INTEGER(iwp), DIMENSION(nys_l-nbgp_local:nyn_l+nbgp_local,                                     &
                             nxl_l-nbgp_local:nxr_l+nbgp_local) ::  ar  !< treated array
 
@@ -776,6 +765,5 @@
 
 !
-!--    One-dimensional decomposition along y, boundary values can be exchanged
-!--    within the PE memory
+!--    One-dimensional decomposition along y, boundary values can be exchanged within the PE memory
        ar(:,nxl_l-nbgp_local:nxl_l-1) = ar(:,nxr_l-nbgp_local+1:nxr_l)
        ar(:,nxr_l+1:nxr_l+nbgp_local) = ar(:,nxl_l:nxl_l+nbgp_local-1)
@@ -784,15 +772,15 @@
 !
 !--    Send left boundary, receive right one
-       CALL MPI_SENDRECV( ar(nys_l-nbgp_local,nxl_l),   1,                     &
-                          type_y_int(grid_level), pleft,  0,                   &
-                          ar(nys_l-nbgp_local,nxr_l+1), 1,                     &
-                          type_y_int(grid_level), pright, 0,                   &
+       CALL MPI_SENDRECV( ar(nys_l-nbgp_local,nxl_l),   1,                                         &
+                          type_y_int(grid_level), pleft,  0,                                       &
+                          ar(nys_l-nbgp_local,nxr_l+1), 1,                                         &
+                          type_y_int(grid_level), pright, 0,                                       &
                           comm2d, status, ierr )
 !
 !--    Send right boundary, receive left one
-       CALL MPI_SENDRECV( ar(nys_l-nbgp_local,nxr_l+1-nbgp_local), 1,          &
-                          type_y_int(grid_level), pright, 1,                   &
-                          ar(nys_l-nbgp_local,nxl_l-nbgp_local),   1,          &
-                          type_y_int(grid_level), pleft,  1,                   &
+       CALL MPI_SENDRECV( ar(nys_l-nbgp_local,nxr_l+1-nbgp_local), 1,                              &
+                          type_y_int(grid_level), pright, 1,                                       &
+                          ar(nys_l-nbgp_local,nxl_l-nbgp_local),   1,                              &
+                          type_y_int(grid_level), pleft,  1,                                       &
                           comm2d, status, ierr )
 
@@ -801,6 +789,5 @@
     IF ( pdims(2) == 1 )  THEN
 !
-!--    One-dimensional decomposition along x, boundary values can be exchanged
-!--    within the PE memory
+!--    One-dimensional decomposition along x, boundary values can be exchanged within the PE memory
        ar(nys_l-nbgp_local:nys_l-1,:) = ar(nyn_l+1-nbgp_local:nyn_l,:)
        ar(nyn_l+1:nyn_l+nbgp_local,:) = ar(nys_l:nys_l-1+nbgp_local,:)
@@ -810,16 +797,16 @@
 !
 !--    Send front boundary, receive rear one
-       CALL MPI_SENDRECV( ar(nys_l,nxl_l-nbgp_local),   1,                    &
-                          type_x_int(grid_level), psouth, 0,                  &
-                          ar(nyn_l+1,nxl_l-nbgp_local), 1,                    &
-                          type_x_int(grid_level), pnorth, 0,                  &
+       CALL MPI_SENDRECV( ar(nys_l,nxl_l-nbgp_local),   1,                                         &
+                          type_x_int(grid_level), psouth, 0,                                       &
+                          ar(nyn_l+1,nxl_l-nbgp_local), 1,                                         &
+                          type_x_int(grid_level), pnorth, 0,                                       &
                           comm2d, status, ierr )
 
 !
 !--    Send rear boundary, receive front one
-       CALL MPI_SENDRECV( ar(nyn_l+1-nbgp_local,nxl_l-nbgp_local), 1,         &
-                          type_x_int(grid_level), pnorth, 1,                  &
-                          ar(nys_l-nbgp_local,nxl_l-nbgp_local),   1,         &
-                          type_x_int(grid_level), psouth, 1,                  &
+       CALL MPI_SENDRECV( ar(nyn_l+1-nbgp_local,nxl_l-nbgp_local), 1,                              &
+                          type_x_int(grid_level), pnorth, 1,                                       &
+                          ar(nys_l-nbgp_local,nxl_l-nbgp_local),   1,                              &
+                          type_x_int(grid_level), psouth, 1,                                       &
                           comm2d, status, ierr )
 
