Index: /palm/trunk/SOURCE/large_scale_forcing_nudging_mod.f90
===================================================================
--- /palm/trunk/SOURCE/large_scale_forcing_nudging_mod.f90	(revision 4699)
+++ /palm/trunk/SOURCE/large_scale_forcing_nudging_mod.f90	(revision 4700)
@@ -1,20 +1,19 @@
 !> @file large_scale_forcing_nudging_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,21 +24,25 @@
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4671 2020-09-09 20:27:58Z pavelkrc
 ! Implementation of downward facing USM and LSM surfaces
-! 
+!
 ! 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
-! 
+!
 ! 3719 2019-02-06 13:10:18Z kanani
 ! Removed USE cpulog (unused)
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! unused variables removed
+!
 ! 2320 2017-07-21 12:47:43Z suehring
 ! initial revision
@@ -47,39 +50,35 @@
 ! Description:
 ! ------------
-!> Calculates large scale forcings (geostrophic wind and subsidence velocity) as 
-!> well as surfaces fluxes dependent on time given in an external file (LSF_DATA).
-!> Moreover, module contains nudging routines, where u, v, pt and q are nudged 
-!> to given profiles on a relaxation timescale tnudge. 
-!> Profiles are read in from NUDGING_DATA. 
+!> Calculates large scale forcings (geostrophic wind and subsidence velocity) as well as surfaces
+!> fluxes dependent on time given in an external file (LSF_DATA).
+!> Moreover, module contains nudging routines, where u, v, pt and q are nudged  to given profiles on
+!> a relaxation timescale tnudge.
+!> Profiles are read in from NUDGING_DATA.
 !> Code is based on Neggers et al. (2012) and also in parts on DALES and UCLA-LES.
 !> @todo: Revise reading of ASCII-files
 !> @todo: Remove unused variables and control flags
 !> @todo: Revise large-scale facing of surface variables
-!> @todo: Revise control flags lsf_exception, lsf_surf, lsf_vert, etc. 
-!--------------------------------------------------------------------------------!
+!> @todo: Revise control flags lsf_exception, lsf_surf, lsf_vert, etc.
+!--------------------------------------------------------------------------------------------------!
  MODULE lsf_nudging_mod
 
-    USE arrays_3d,                                                             &
-        ONLY:  dzw, e, diss, heatflux_input_conversion, pt, pt_init, q,        &
-               q_init, s, tend, u, u_init, ug, v, v_init, vg, w, w_subs,       &
-               waterflux_input_conversion, zu, zw                  
-
-    USE control_parameters,                                                    &
-        ONLY:  bc_lr, bc_ns, bc_pt_b, bc_q_b, constant_diffusion,              &
-               constant_heatflux, constant_waterflux,                          &
-               data_output_pr, dt_3d, end_time,                                &
-               humidity, initializing_actions, intermediate_timestep_count,    &
-               ibc_pt_b, ibc_q_b,                                              &
-               large_scale_forcing, large_scale_subsidence, lsf_surf, lsf_vert,&
-               lsf_exception, message_string, neutral,                         &
-               nudging, passive_scalar, pt_surface, ocean_mode, q_surface,     &
-               surface_heatflux, surface_pressure, surface_waterflux,          &
-               topography, use_subsidence_tendencies
-               
+    USE arrays_3d,                                                                                 &
+        ONLY:  dzw, diss, e, heatflux_input_conversion, pt, pt_init, q, q_init, s, tend, u, u_init,&
+               ug, v, v_init, vg, w, w_subs, waterflux_input_conversion, zu, zw
+
+    USE control_parameters,                                                                        &
+        ONLY:  bc_lr, bc_ns, bc_pt_b, bc_q_b, constant_diffusion, constant_heatflux,               &
+               constant_waterflux, data_output_pr, dt_3d, end_time, humidity, initializing_actions,&
+               intermediate_timestep_count, ibc_pt_b, ibc_q_b,                                     &
+               large_scale_forcing, large_scale_subsidence, lsf_surf, lsf_vert, lsf_exception,     &
+               message_string, neutral, nudging, passive_scalar, pt_surface, ocean_mode, q_surface,&
+               surface_heatflux, surface_pressure, surface_waterflux, topography,                  &
+               use_subsidence_tendencies
+
     USE grid_variables
 
-    USE indices,                                                               &
-        ONLY:  nbgp, ngp_sums_ls, nx, nxl, nxlg, nxlu, nxr, nxrg, ny, nys,     &
-               nysv, nysg, nyn, nyng, nzb, nz, nzt, wall_flags_total_0
+    USE indices,                                                                                   &
+        ONLY:  nbgp, ngp_sums_ls, nx, nxl, nxlg, nxlu, nxr, nxrg, ny, nys, nysv, nysg, nyn, nyng,  &
+               nzb, nz, nzt, wall_flags_total_0
 
     USE kinds
@@ -87,33 +86,12 @@
     USE pegrid
 
-    USE surface_mod,                                                           &
+    USE surface_mod,                                                                               &
         ONLY:  surf_def_h, surf_lsm_h, surf_usm_h
 
-    USE statistics,                                                            &
+    USE statistics,                                                                                &
         ONLY:  hom, statistic_regions, sums_ls_l, weight_substep
 
     INTEGER(iwp) ::  nlsf = 1000                       !< maximum number of profiles in LSF_DATA (large scale forcing)
     INTEGER(iwp) ::  ntnudge = 1000                    !< maximum number of profiles in NUDGING_DATA (nudging)
-
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ptnudge     !< vertical profile of pot. temperature interpolated to vertical grid (nudging)
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  qnudge      !< vertical profile of water vapor mixing ratio interpolated to vertical grid (nudging) 
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  tnudge      !< vertical profile of nudging time scale interpolated to vertical grid (nudging)  
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  td_lsa_lpt  !< temperature tendency due to large scale advection (large scale forcing)
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  td_lsa_q    !< water vapor mixing ratio tendency due to large scale advection (large scale forcing)
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  td_sub_lpt  !< temperature tendency due to subsidence/ascent (large scale forcing)
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  td_sub_q    !< water vapor mixing ratio tendency due to subsidence/ascent (large scale forcing)
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ug_vert     !< vertical profile of geostrophic wind component in x-direction interpolated to vertical grid (large scale forcing)
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  unudge      !< vertical profile of wind component in x-direction interpolated to vertical grid (nudging) 
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  vnudge      !< vertical profile of wind component in y-direction interpolated to vertical grid (nudging) 
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  vg_vert     !< vertical profile of geostrophic wind component in y-direction interpolated to vertical grid (large scale forcing)
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  wnudge      !< vertical profile of subsidence/ascent velocity interpolated to vertical grid (nudging) ???
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  wsubs_vert  !< vertical profile of wind component in z-direction interpolated to vertical grid (nudging) ???
-
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  shf_surf      !< time-dependent surface sensible heat flux (large scale forcing)
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  timenudge     !< times at which vertical profiles are defined in NUDGING_DATA (nudging)
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  time_surf     !< times at which surface values/fluxes are defined in LSF_DATA (large scale forcing)
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  time_vert     !< times at which vertical profiles are defined in LSF_DATA (large scale forcing)
-
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  tmp_tnudge    !< current nudging time scale
 
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  p_surf        !< time-dependent surface pressure (large scale forcing)
@@ -121,4 +99,37 @@
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  qsws_surf     !< time-dependent surface latent heat flux (large scale forcing)
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  q_surf        !< time-dependent surface water vapor mixing ratio (large scale forcing)
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  shf_surf      !< time-dependent surface sensible heat flux (large scale forcing)
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  timenudge     !< times at which vertical profiles are defined in NUDGING_DATA (nudging)
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  time_surf     !< times at which surface values/fluxes are defined in LSF_DATA (large
+                                                          !< scale forcing)
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  time_vert     !< times at which vertical profiles are defined in LSF_DATA (large scale
+                                                          !< forcing)
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  tmp_tnudge    !< current nudging time scale
+
+
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ptnudge     !< vertical profile of pot. temperature interpolated to vertical grid
+                                                          !< (nudging)
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  qnudge      !< vertical profile of water vapor mixing ratio interpolated to vertical
+                                                          !< grid (nudging)
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  tnudge      !< vertical profile of nudging time scale interpolated to vertical grid
+                                                          !< (nudging)
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  td_lsa_lpt  !< temperature tendency due to large scale advection (large scale forcing)
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  td_lsa_q    !< water vapor mixing ratio tendency due to large scale advection (large
+                                                          !< scale forcing)
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  td_sub_lpt  !< temperature tendency due to subsidence/ascent (large scale forcing)
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  td_sub_q    !< water vapor mixing ratio tendency due to subsidence/ascent (large scale
+                                                          !< forcing)
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ug_vert     !< vertical profile of geostrophic wind component in x-direction
+                                                          !< interpolated to vertical grid (large scale forcing)
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  unudge      !< vertical profile of wind component in x-direction interpolated to
+                                                          !< vertical grid (nudging)
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  vnudge      !< vertical profile of wind component in y-direction interpolated to
+                                                          !< vertical grid (nudging)
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  vg_vert     !< vertical profile of geostrophic wind component in y-direction
+                                                          !< interpolated to vertical grid (large scale forcing)
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  wnudge      !< vertical profile of subsidence/ascent velocity interpolated to vertical
+                                                          !< grid (nudging) ???
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  wsubs_vert  !< vertical profile of wind component in z-direction interpolated to
+                                                          !< vertical grid (nudging) ???
 
     SAVE
@@ -126,13 +137,11 @@
 !
 !-- Public subroutines
-    PUBLIC calc_tnudge, ls_forcing_surf, ls_forcing_vert, ls_advec, lsf_init,  &
-           lsf_nudging_check_parameters, nudge_init,                           &
-           lsf_nudging_check_data_output_pr, lsf_nudging_header,               &
-           nudge, nudge_ref
-           
+    PUBLIC calc_tnudge, ls_forcing_surf, ls_forcing_vert, ls_advec, lsf_init,                      &
+           lsf_nudging_check_parameters, nudge_init, lsf_nudging_check_data_output_pr,             &
+           lsf_nudging_header, nudge, nudge_ref
+
 !
 !-- Public variables
-    PUBLIC qsws_surf, shf_surf, td_lsa_lpt, td_lsa_q, td_sub_lpt,              &
-           td_sub_q, time_vert
+    PUBLIC qsws_surf, shf_surf, td_lsa_lpt, td_lsa_q, td_sub_lpt, td_sub_q, time_vert
 
 
@@ -150,9 +159,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE lsf_nudging_check_parameters
 
@@ -161,39 +170,37 @@
 !--    Check nudging and large scale forcing from external file
        IF ( nudging  .AND.  (  .NOT.  large_scale_forcing ) )  THEN
-          message_string = 'Nudging requires large_scale_forcing = .T.. &'//   &
-                        'Surface fluxes and geostrophic wind should be &'//    &
-                        'prescribed in file LSF_DATA'
+          message_string = 'Nudging requires large_scale_forcing = .T.. &'//                       &
+                           'Surface fluxes and geostrophic wind should be &'//                     &
+                           'prescribed in file LSF_DATA'
           CALL message( 'check_parameters', 'PA0374', 1, 2, 0, 6, 0 )
        ENDIF
 
-       IF ( large_scale_forcing  .AND.  ( bc_lr /= 'cyclic'  .OR.              &
-                                          bc_ns /= 'cyclic' ) )  THEN
-          message_string = 'Non-cyclic lateral boundaries do not allow for &'//&
-                        'the usage of large scale forcing from external file.'
+       IF ( large_scale_forcing  .AND.  ( bc_lr /= 'cyclic' .OR. bc_ns /= 'cyclic' ) )  THEN
+          message_string = 'Non-cyclic lateral boundaries do not allow for &'//                    &
+                           'the usage of large scale forcing from external file.'
           CALL message( 'check_parameters', 'PA0375', 1, 2, 0, 6, 0 )
        ENDIF
 
-       IF ( large_scale_forcing  .AND.  (  .NOT.  humidity ) )  THEN
-          message_string = 'The usage of large scale forcing from external &'//&
-                        'file LSF_DATA requires humidity = .T..'
+       IF ( large_scale_forcing  .AND.  ( .NOT. humidity ) )  THEN
+          message_string = 'The usage of large scale forcing from external &'//                    &
+                           'file LSF_DATA requires humidity = .T..'
           CALL message( 'check_parameters', 'PA0376', 1, 2, 0, 6, 0 )
        ENDIF
 
        IF ( large_scale_forcing  .AND.  passive_scalar )  THEN
-          message_string = 'The usage of large scale forcing from external &'// &
-                        'file LSF_DATA is not implemented for passive scalars'
+          message_string = 'The usage of large scale forcing from external &'//                    &
+                           'file LSF_DATA is not implemented for passive scalars'
           CALL message( 'check_parameters', 'PA0440', 1, 2, 0, 6, 0 )
        ENDIF
 
-       IF ( large_scale_forcing  .AND.  topography /= 'flat'                   &
-                              .AND.  .NOT.  lsf_exception )  THEN
-          message_string = 'The usage of large scale forcing from external &'//&
-                        'file LSF_DATA is not implemented for non-flat topography'
+       IF ( large_scale_forcing  .AND.  topography /= 'flat'  .AND. .NOT. lsf_exception )  THEN
+          message_string = 'The usage of large scale forcing from external &'//                    &
+                           'file LSF_DATA is not implemented for non-flat topography'
           CALL message( 'check_parameters', 'PA0377', 1, 2, 0, 6, 0 )
        ENDIF
 
        IF ( large_scale_forcing  .AND.  ocean_mode )  THEN
-          message_string = 'The usage of large scale forcing from external &'//&
-                        'file LSF_DATA is not implemented for ocean mode'
+          message_string = 'The usage of large scale forcing from external &'//                    &
+                           'file LSF_DATA is not implemented for ocean mode'
           CALL message( 'check_parameters', 'PA0378', 1, 2, 0, 6, 0 )
        ENDIF
@@ -201,33 +208,31 @@
     END SUBROUTINE lsf_nudging_check_parameters
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Check data output of profiles for land surface model
-!------------------------------------------------------------------------------!
-    SUBROUTINE lsf_nudging_check_data_output_pr( variable, var_count, unit,    &
-                                                 dopr_unit )
- 
+!--------------------------------------------------------------------------------------------------!
+    SUBROUTINE lsf_nudging_check_data_output_pr( variable, var_count, unit, dopr_unit )
+
        USE profil_parameter
 
        IMPLICIT NONE
-   
-       CHARACTER (LEN=*) ::  unit      !< 
-       CHARACTER (LEN=*) ::  variable  !< 
+
+       CHARACTER (LEN=*) ::  unit      !<
+       CHARACTER (LEN=*) ::  variable  !<
        CHARACTER (LEN=*) ::  dopr_unit !< local value of dopr_unit
- 
-       INTEGER(iwp) ::  var_count     !< 
+
+       INTEGER(iwp) ::  var_count     !<
 
        SELECT CASE ( TRIM( variable ) )
-       
+
 
           CASE ( 'td_lsa_thetal' )
-             IF (  .NOT.  large_scale_forcing )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(var_count) ) //          &
-                                 ' is not implemented for ' //                 &
+             IF ( .NOT. large_scale_forcing )  THEN
+                message_string = 'data_output_pr = ' //                                            &
+                                 TRIM( data_output_pr(var_count) ) //                              &
+                                 ' is not implemented for ' //                                     &
                                  'large_scale_forcing = .FALSE.'
-                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0393',    &
-                               1, 2, 0, 6, 0 )
+                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0393', 1, 2, 0, 6, 0 )
              ELSE
                 dopr_index(var_count) = 81
@@ -238,11 +243,10 @@
 
           CASE ( 'td_lsa_q' )
-             IF (  .NOT.  large_scale_forcing )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(var_count) ) //          &
-                                 ' is not implemented for ' //                 &
+             IF ( .NOT. large_scale_forcing )  THEN
+                message_string = 'data_output_pr = ' //                                            &
+                                 TRIM( data_output_pr(var_count) ) //                              &
+                                 ' is not implemented for ' //                                     &
                                  'large_scale_forcing = .FALSE.'
-                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0393',    &
-                               1, 2, 0, 6, 0 )
+                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0393', 1, 2, 0, 6, 0 )
              ELSE
                 dopr_index(var_count) = 82
@@ -252,11 +256,10 @@
              ENDIF
           CASE ( 'td_sub_thetal' )
-             IF (  .NOT.  large_scale_forcing )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(var_count) ) //          &
-                                 ' is not implemented for ' //                 &
+             IF ( .NOT. large_scale_forcing )  THEN
+                message_string = 'data_output_pr = ' //                                            &
+                                 TRIM( data_output_pr(var_count) ) //                              &
+                                 ' is not implemented for ' //                                     &
                                  'large_scale_forcing = .FALSE.'
-                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0393',    &
-                               1, 2, 0, 6, 0 )
+                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0393', 1, 2, 0, 6, 0 )
              ELSE
                 dopr_index(var_count) = 83
@@ -267,11 +270,10 @@
 
           CASE ( 'td_sub_q' )
-             IF (  .NOT.  large_scale_forcing )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(var_count) ) //          &
-                                 ' is not implemented for ' //                 &
+             IF ( .NOT. large_scale_forcing )  THEN
+                message_string = 'data_output_pr = ' //                                            &
+                                 TRIM( data_output_pr(var_count) ) //                              &
+                                 ' is not implemented for ' //                                     &
                                  'large_scale_forcing = .FALSE.'
-                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0393',    &
-                               1, 2, 0, 6, 0 )
+                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0393', 1, 2, 0, 6, 0 )
              ELSE
                 dopr_index(var_count) = 84
@@ -282,11 +284,10 @@
 
           CASE ( 'td_nud_thetal' )
-             IF (  .NOT.  nudging )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(var_count) ) //          &
-                                 ' is not implemented for ' //                 &
+             IF ( .NOT. nudging )  THEN
+                message_string = 'data_output_pr = ' //                                            &
+                                 TRIM( data_output_pr(var_count) ) //                              &
+                                 ' is not implemented for ' //                                     &
                                  'nudging = .FALSE.'
-                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0394',    &
-                               1, 2, 0, 6, 0 )
+                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0394', 1, 2, 0, 6, 0 )
              ELSE
                 dopr_index(var_count) = 85
@@ -297,11 +298,10 @@
 
           CASE ( 'td_nud_q' )
-             IF (  .NOT.  nudging )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(var_count) ) //          &
-                                 ' is not implemented for ' //                 &
+             IF ( .NOT. nudging )  THEN
+                message_string = 'data_output_pr = ' //                                            &
+                                 TRIM( data_output_pr(var_count) ) //                              &
+                                 ' is not implemented for ' //                                     &
                                  'nudging = .FALSE.'
-                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0394',    &
-                               1, 2, 0, 6, 0 )
+                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0394', 1, 2, 0, 6, 0 )
              ELSE
                 dopr_index(var_count) = 86
@@ -312,11 +312,10 @@
 
           CASE ( 'td_nud_u' )
-             IF (  .NOT.  nudging )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(var_count) ) //          &
-                                 ' is not implemented for ' //                 &
+             IF ( .NOT. nudging )  THEN
+                message_string = 'data_output_pr = ' //                                            &
+                                 TRIM( data_output_pr(var_count) ) //                              &
+                                 ' is not implemented for ' //                                     &
                                  'nudging = .FALSE.'
-                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0394',    &
-                               1, 2, 0, 6, 0 )
+                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0394', 1, 2, 0, 6, 0 )
              ELSE
                 dopr_index(var_count) = 87
@@ -327,11 +326,10 @@
 
           CASE ( 'td_nud_v' )
-             IF (  .NOT.  nudging )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(var_count) ) //          &
-                                 ' is not implemented for ' //                 &
+             IF ( .NOT. nudging )  THEN
+                message_string = 'data_output_pr = ' //                                            &
+                                 TRIM( data_output_pr(var_count) ) //                              &
+                                 ' is not implemented for ' //                                     &
                                  'nudging = .FALSE.'
-                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0394',    &
-                               1, 2, 0, 6, 0 )
+                CALL message( 'lsf_nudging_check_data_output_pr', 'PA0394', 1, 2, 0, 6, 0 )
              ELSE
                 dopr_index(var_count) = 88
@@ -344,14 +342,14 @@
           CASE DEFAULT
              unit = 'illegal'
-   
+
        END SELECT
 
     END SUBROUTINE lsf_nudging_check_data_output_pr
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE lsf_nudging_header ( io )
 
@@ -370,5 +368,5 @@
              ELSE
                 WRITE ( io, 6 )
-             ENDIF 
+             ENDIF
           ENDIF
 
@@ -399,5 +397,5 @@
 
 
-1 FORMAT (//' Large scale forcing and nudging:'/ &
+1 FORMAT (//' Large scale forcing and nudging:'/                                                   &
               ' -------------------------------'/)
 2 FORMAT (' --> No large scale forcing from external is used (default) ')
@@ -407,5 +405,5 @@
 6 FORMAT ('     - large scale subsidence tendencies ')
 7 FORMAT ('     - and geostrophic wind components ug and vg')
-8 FORMAT (' --> Large-scale vertical motion is used in the ', &
+8 FORMAT (' --> Large-scale vertical motion is used in the ',                                      &
                   'prognostic equation(s) for')
 9 FORMAT ('     the scalar(s) only')
@@ -417,11 +415,11 @@
 15 FORMAT ('     - prescribed surface fluxes for humidity')
 
-    END SUBROUTINE lsf_nudging_header 
-
-!------------------------------------------------------------------------------!
+    END SUBROUTINE lsf_nudging_header
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE lsf_init
 
@@ -437,28 +435,28 @@
 
        REAL(wp) ::  fac               !<
+       REAL(wp) ::  high_td_lsa_lpt   !<
+       REAL(wp) ::  high_td_lsa_q     !<
+       REAL(wp) ::  high_td_sub_lpt   !<
+       REAL(wp) ::  high_td_sub_q     !<
        REAL(wp) ::  highheight        !<
        REAL(wp) ::  highug_vert       !<
        REAL(wp) ::  highvg_vert       !<
        REAL(wp) ::  highwsubs_vert    !<
+       REAL(wp) ::  low_td_lsa_lpt    !<
+       REAL(wp) ::  low_td_lsa_q      !<
+       REAL(wp) ::  low_td_sub_lpt    !<
+       REAL(wp) ::  low_td_sub_q      !<
        REAL(wp) ::  lowheight         !<
        REAL(wp) ::  lowug_vert        !<
        REAL(wp) ::  lowvg_vert        !<
        REAL(wp) ::  lowwsubs_vert     !<
-       REAL(wp) ::  high_td_lsa_lpt   !<
-       REAL(wp) ::  low_td_lsa_lpt    !<
-       REAL(wp) ::  high_td_lsa_q     !<
-       REAL(wp) ::  low_td_lsa_q      !<
-       REAL(wp) ::  high_td_sub_lpt   !<
-       REAL(wp) ::  low_td_sub_lpt    !<
-       REAL(wp) ::  high_td_sub_q     !<
-       REAL(wp) ::  low_td_sub_q      !<
        REAL(wp) ::  r_dummy           !<
 
-       ALLOCATE( p_surf(0:nlsf), pt_surf(0:nlsf), q_surf(0:nlsf),              &
-                 qsws_surf(0:nlsf), shf_surf(0:nlsf),                          &
-                 td_lsa_lpt(nzb:nzt+1,0:nlsf), td_lsa_q(nzb:nzt+1,0:nlsf),     &
-                 td_sub_lpt(nzb:nzt+1,0:nlsf), td_sub_q(nzb:nzt+1,0:nlsf),     &
-                 time_vert(0:nlsf), time_surf(0:nlsf),                         &
-                 ug_vert(nzb:nzt+1,0:nlsf), vg_vert(nzb:nzt+1,0:nlsf),         &
+       ALLOCATE( p_surf(0:nlsf), pt_surf(0:nlsf), q_surf(0:nlsf),                                  &
+                 qsws_surf(0:nlsf), shf_surf(0:nlsf),                                              &
+                 td_lsa_lpt(nzb:nzt+1,0:nlsf), td_lsa_q(nzb:nzt+1,0:nlsf),                         &
+                 td_sub_lpt(nzb:nzt+1,0:nlsf), td_sub_q(nzb:nzt+1,0:nlsf),                         &
+                 time_vert(0:nlsf), time_surf(0:nlsf),                                             &
+                 ug_vert(nzb:nzt+1,0:nlsf), vg_vert(nzb:nzt+1,0:nlsf),                             &
                  wsubs_vert(nzb:nzt+1,0:nlsf) )
 
@@ -470,6 +468,5 @@
 
 !
-!--    Array for storing large scale forcing and nudging tendencies at each 
-!--    timestep for data output
+!--    Array for storing large scale forcing and nudging tendencies at each timestep for data output
        ALLOCATE( sums_ls_l(nzb:nzt+1,0:7) )
        sums_ls_l = 0.0_wp
@@ -477,6 +474,5 @@
        ngp_sums_ls = (nz+2)*6
 
-       OPEN ( finput, FILE='LSF_DATA', STATUS='OLD', &
-              FORM='FORMATTED', IOSTAT=ierrn )
+       OPEN ( finput, FILE='LSF_DATA', STATUS='OLD', FORM='FORMATTED', IOSTAT=ierrn )
 
        IF ( ierrn /= 0 )  THEN
@@ -504,11 +500,10 @@
        DO WHILE ( time_surf(nt) < end_time )
           nt = nt + 1
-          READ ( finput, *, IOSTAT = ierrn ) time_surf(nt), shf_surf(nt),      &
-                                             qsws_surf(nt), pt_surf(nt),       &
-                                             q_surf(nt), p_surf(nt)
+          READ ( finput, *, IOSTAT = ierrn ) time_surf(nt), shf_surf(nt), qsws_surf(nt),           &
+                                             pt_surf(nt), q_surf(nt), p_surf(nt)
 
           IF ( ierrn /= 0 )  THEN
-            WRITE ( message_string, * ) 'No time dependent surface ' //        &
-                              'variables in & LSF_DATA for end of run found'
+            WRITE ( message_string, * ) 'No time dependent surface ' //                            &
+                                        'variables in & LSF_DATA for end of run found'
 
              CALL message( 'ls_forcing', 'PA0363', 1, 2, 0, 6, 0 )
@@ -517,6 +512,6 @@
 
        IF ( time_surf(1) > end_time )  THEN
-          WRITE ( message_string, * ) 'Time dependent surface variables in ' //&
-                                      '&LSF_DATA set in after end of ' ,       &
+          WRITE ( message_string, * ) 'Time dependent surface variables in ' //                    &
+                                      '&LSF_DATA set in after end of ' ,                           &
                                       'simulation - lsf_surf is set to FALSE'
           CALL message( 'ls_forcing', 'PA0371', 0, 0, 0, 6, 0 )
@@ -539,11 +534,11 @@
           ierrn = 1 ! not zero
 !
-!--       Search for the next line consisting of "# time", 
-!--       from there onwards the profiles will be read
-          DO WHILE ( .NOT. ( hash == "#" .AND. ierrn == 0 ) ) 
+!--       Search for the next line consisting of "# time", from there onwards the profiles will be
+!--       read.
+          DO WHILE ( .NOT. ( hash == "#" .AND. ierrn == 0 ) )
              READ ( finput, *, IOSTAT=ierrn ) hash, time_vert(nt)
-             IF ( ierrn < 0 )  THEN 
-                WRITE( message_string, * ) 'No time dependent vertical profiles',&
-                                 ' in & LSF_DATA for end of run found'
+             IF ( ierrn < 0 )  THEN
+                WRITE( message_string, * ) 'No time dependent vertical profiles',                  &
+                                           ' in & LSF_DATA for end of run found'
                 CALL message( 'ls_forcing', 'PA0372', 1, 2, 0, 6, 0 )
              ENDIF
@@ -552,7 +547,6 @@
           IF ( nt == 1 .AND. time_vert(nt) > end_time ) EXIT
 
-          READ ( finput, *, IOSTAT=ierrn ) lowheight, lowug_vert, lowvg_vert,  &
-                                           lowwsubs_vert, low_td_lsa_lpt,      &
-                                           low_td_lsa_q, low_td_sub_lpt,       &
+          READ ( finput, *, IOSTAT=ierrn ) lowheight, lowug_vert, lowvg_vert, lowwsubs_vert,       &
+                                           low_td_lsa_lpt, low_td_lsa_q, low_td_sub_lpt,           &
                                            low_td_sub_q
           IF ( ierrn /= 0 )  THEN
@@ -561,9 +555,8 @@
           ENDIF
 
-          READ ( finput, *, IOSTAT=ierrn ) highheight, highug_vert,            &
-                                           highvg_vert, highwsubs_vert,        &
-                                           high_td_lsa_lpt, high_td_lsa_q,     &
-                                           high_td_sub_lpt, high_td_sub_q
-       
+          READ ( finput, *, IOSTAT=ierrn ) highheight, highug_vert, highvg_vert, highwsubs_vert,   &
+                                           high_td_lsa_lpt, high_td_lsa_q, high_td_sub_lpt,        &
+                                           high_td_sub_q
+
           IF ( ierrn /= 0 )  THEN
              message_string = 'errors in file LSF_DATA'
@@ -584,15 +577,13 @@
 
                 ierrn = 0
-                READ ( finput, *, IOSTAT=ierrn ) highheight, highug_vert,      &
-                                                 highvg_vert, highwsubs_vert,  &
-                                                 high_td_lsa_lpt,              &
-                                                 high_td_lsa_q,                &
+                READ ( finput, *, IOSTAT=ierrn ) highheight, highug_vert, highvg_vert,             &
+                                                 highwsubs_vert, high_td_lsa_lpt, high_td_lsa_q,   &
                                                  high_td_sub_lpt, high_td_sub_q
 
                 IF ( ierrn /= 0 )  THEN
-                   WRITE( message_string, * ) 'zu(',k,') = ', zu(k), 'm ',     &
-                        'is higher than the maximum height in LSF_DATA ',      &
-                        'which is ', lowheight, 'm. Interpolation on PALM ',   &
-                        'grid is not possible.'
+                   WRITE( message_string, * ) 'zu(',k,') = ', zu(k), 'm ',                         &
+                                              'is higher than the maximum height in LSF_DATA ',    &
+                                              'which is ', lowheight, 'm. Interpolation on PALM ', &
+                                              'grid is not possible.'
                    CALL message( 'ls_forcing', 'PA0395', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -601,35 +592,28 @@
 
 !
-!--          Interpolation of prescribed profiles in space 
+!--          Interpolation of prescribed profiles in space
              fac = (highheight-zu(k))/(highheight - lowheight)
 
-             ug_vert(k,nt)    = fac * lowug_vert                               &
-                                + ( 1.0_wp - fac ) * highug_vert
-             vg_vert(k,nt)    = fac * lowvg_vert                               &
-                                + ( 1.0_wp - fac ) * highvg_vert
-             wsubs_vert(k,nt) = fac * lowwsubs_vert                            &
-                                + ( 1.0_wp - fac ) * highwsubs_vert
-
-             td_lsa_lpt(k,nt) = fac * low_td_lsa_lpt                           &
-                                + ( 1.0_wp - fac ) * high_td_lsa_lpt
-             td_lsa_q(k,nt)   = fac * low_td_lsa_q                             &
-                                + ( 1.0_wp - fac ) * high_td_lsa_q
-             td_sub_lpt(k,nt) = fac * low_td_sub_lpt                           &
-                                + ( 1.0_wp - fac ) * high_td_sub_lpt
-             td_sub_q(k,nt)   = fac * low_td_sub_q                             &
-                                + ( 1.0_wp - fac ) * high_td_sub_q
+             ug_vert(k,nt)    = fac * lowug_vert    + ( 1.0_wp - fac ) * highug_vert
+             vg_vert(k,nt)    = fac * lowvg_vert    + ( 1.0_wp - fac ) * highvg_vert
+             wsubs_vert(k,nt) = fac * lowwsubs_vert + ( 1.0_wp - fac ) * highwsubs_vert
+
+             td_lsa_lpt(k,nt) = fac * low_td_lsa_lpt + ( 1.0_wp - fac ) * high_td_lsa_lpt
+             td_lsa_q(k,nt)   = fac * low_td_lsa_q   + ( 1.0_wp - fac ) * high_td_lsa_q
+             td_sub_lpt(k,nt) = fac * low_td_sub_lpt + ( 1.0_wp - fac ) * high_td_sub_lpt
+             td_sub_q(k,nt)   = fac * low_td_sub_q   + ( 1.0_wp - fac ) * high_td_sub_q
 
           ENDDO
 
-       ENDDO 
+       ENDDO
 
 !
 !--    Large scale vertical velocity has to be zero at the surface
        wsubs_vert(nzb,:) = 0.0_wp
-    
+
        IF ( time_vert(1) > end_time )  THEN
-          WRITE ( message_string, * ) 'Time dependent large scale profile ',   &
-                             'forcing from&LSF_DATA sets in after end of ' ,   &
-                             'simulation - lsf_vert is set to FALSE'
+          WRITE ( message_string, * ) 'Time dependent large scale profile ',                       &
+                                      'forcing from&LSF_DATA sets in after end of ' ,              &
+                                      'simulation - lsf_vert is set to FALSE'
           CALL message( 'ls_forcing', 'PA0373', 0, 0, 0, 6, 0 )
           lsf_vert = .FALSE.
@@ -640,9 +624,9 @@
     END SUBROUTINE lsf_init
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE ls_forcing_surf ( time )
 
@@ -669,18 +653,16 @@
        IF ( ibc_pt_b == 0 )  THEN
 !
-!--       In case of Dirichlet boundary condition shf must not 
-!--       be set - it is calculated via MOST in prandtl_fluxes
+!--       In case of Dirichlet boundary condition shf must not be set - it is calculated via MOST in
+!--       prandtl_fluxes
           pt_surface = pt_surf(nt) + fac * ( pt_surf(nt+1) - pt_surf(nt) )
 
        ELSEIF ( ibc_pt_b == 1 )  THEN
 !
-!--       In case of Neumann boundary condition pt_surface is needed for 
+!--       In case of Neumann boundary condition pt_surface is needed for
 !--       calculation of reference density
-          dum_surf_flux = ( shf_surf(nt) + fac *                               &
-                            ( shf_surf(nt+1) - shf_surf(nt) )                  &
+          dum_surf_flux = ( shf_surf(nt) + fac * ( shf_surf(nt+1) - shf_surf(nt) )                 &
                           ) * heatflux_input_conversion(nzb)
 !
-!--       Save surface sensible heat flux on default, natural and urban surface
-!--       type, if required 
+!--       Save surface sensible heat flux on default, natural and urban surface type, if required.
           IF ( surf_def_h(0)%ns >= 1 )  surf_def_h(0)%shf(:) = dum_surf_flux
           IF ( surf_lsm_h(0)%ns >= 1 )  surf_lsm_h(0)%shf(:) = dum_surf_flux
@@ -693,15 +675,13 @@
        IF ( ibc_q_b == 0 )  THEN
 !
-!--       In case of Dirichlet boundary condition qsws must not 
-!--       be set - it is calculated via MOST in prandtl_fluxes
+!--       In case of Dirichlet boundary condition qsws must not be set - it is calculated via MOST
+!--       in prandtl_fluxes
           q_surface = q_surf(nt) + fac * ( q_surf(nt+1) - q_surf(nt) )
 
        ELSEIF ( ibc_q_b == 1 )  THEN
-          dum_surf_flux = ( qsws_surf(nt) + fac *                              &
-                             ( qsws_surf(nt+1) - qsws_surf(nt) )               &
-                             ) * waterflux_input_conversion(nzb)
-!
-!--       Save surface sensible heat flux on default, natural and urban surface
-!--       type, if required 
+          dum_surf_flux = ( qsws_surf(nt) + fac * ( qsws_surf(nt+1) - qsws_surf(nt) )              &
+                          ) * waterflux_input_conversion(nzb)
+!
+!--       Save surface sensible heat flux on default, natural and urban surface type, if required
           IF ( surf_def_h(0)%ns >= 1 )  surf_def_h(0)%qsws(:) = dum_surf_flux
           IF ( surf_lsm_h(0)%ns >= 1 )  surf_lsm_h(0)%qsws(:) = dum_surf_flux
@@ -710,26 +690,26 @@
        ENDIF
 !
-!--    Surface heat- and waterflux will be written later onto surface elements 
-       IF ( .NOT.  neutral  .AND.  constant_heatflux  .AND.                    &
+!--    Surface heat- and waterflux will be written later onto surface elements
+       IF ( .NOT. neutral  .AND.  constant_heatflux  .AND.                                         &
             TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
-             surface_heatflux = shf_surf(1)
-       ENDIF
-       IF ( humidity  .AND.  constant_waterflux  .AND.                         &
+          surface_heatflux = shf_surf(1)
+       ENDIF
+       IF ( humidity  .AND.  constant_waterflux  .AND.                                             &
             TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
-             surface_waterflux = qsws_surf(1)
+          surface_waterflux = qsws_surf(1)
        ENDIF
 
        surface_pressure = p_surf(nt) + fac * ( p_surf(nt+1) - p_surf(nt) )
 
-    END SUBROUTINE ls_forcing_surf 
-
-
-
-
-!------------------------------------------------------------------------------!
+    END SUBROUTINE ls_forcing_surf
+
+
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE ls_forcing_vert ( time )
 
@@ -758,6 +738,5 @@
 
        IF ( large_scale_subsidence )  THEN
-          w_subs = wsubs_vert(:,nt)                                            &
-                   + fac * ( wsubs_vert(:,nt+1) - wsubs_vert(:,nt) )
+          w_subs = wsubs_vert(:,nt) + fac * ( wsubs_vert(:,nt+1) - wsubs_vert(:,nt) )
        ENDIF
 
@@ -765,26 +744,26 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Call for all grid points
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE ls_advec ( time, prog_var )
-      
+
 
        IMPLICIT NONE
 
-       CHARACTER (LEN=*) ::  prog_var   !< 
-
-       REAL(wp), INTENT(in)  :: time    !< 
-       REAL(wp) :: fac                  !<  
-
-       INTEGER(iwp) ::  i               !< 
-       INTEGER(iwp) ::  j               !< 
-       INTEGER(iwp) ::  k               !< 
-       INTEGER(iwp) ::  nt               !< 
-
-!
-!--    Interpolation in time of LSF_DATA 
+       CHARACTER (LEN=*) ::  prog_var   !<
+
+       INTEGER(iwp) ::  i               !<
+       INTEGER(iwp) ::  j               !<
+       INTEGER(iwp) ::  k               !<
+       INTEGER(iwp) ::  nt               !<
+
+       REAL(wp) :: fac                  !<
+       REAL(wp), INTENT(in)  :: time    !<
+
+!
+!--    Interpolation in time of LSF_DATA
        nt = 1
        DO WHILE ( time > time_vert(nt) )
@@ -798,5 +777,5 @@
 
 !
-!--    Add horizontal large scale advection tendencies of pt and q 
+!--    Add horizontal large scale advection tendencies of pt and q
        SELECT CASE ( prog_var )
 
@@ -806,8 +785,8 @@
                 DO  j = nys, nyn
                    DO  k = nzb+1, nzt
-                      tend(k,j,i) = tend(k,j,i) + td_lsa_lpt(k,nt) + fac *     &
-                                    ( td_lsa_lpt(k,nt+1) - td_lsa_lpt(k,nt) ) *&
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                      tend(k,j,i) = tend(k,j,i) + td_lsa_lpt(k,nt) + fac *                         &
+                                       ( td_lsa_lpt(k,nt+1) - td_lsa_lpt(k,nt) ) *                 &
+                                       MERGE( 1.0_wp, 0.0_wp,                                     &
+                                              BTEST( wall_flags_total_0(k,j,i), 0 ) )
                    ENDDO
                 ENDDO
@@ -819,8 +798,8 @@
                 DO  j = nys, nyn
                    DO  k = nzb+1, nzt
-                      tend(k,j,i) = tend(k,j,i) + td_lsa_q(k,nt) + fac *       &
-                                    ( td_lsa_q(k,nt+1) - td_lsa_q(k,nt) ) *    &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                      tend(k,j,i) = tend(k,j,i) + td_lsa_q(k,nt) + fac *                           &
+                                       ( td_lsa_q(k,nt+1) - td_lsa_q(k,nt) ) *                     &
+                                       MERGE( 1.0_wp, 0.0_wp,                                     &
+                                              BTEST( wall_flags_total_0(k,j,i), 0 ) )
                    ENDDO
                 ENDDO
@@ -840,12 +819,12 @@
                    DO  j = nys, nyn
                       DO  k = nzb+1, nzt
-                         tend(k,j,i) = tend(k,j,i) + td_sub_lpt(k,nt) + fac *  &
-                                     ( td_sub_lpt(k,nt+1) - td_sub_lpt(k,nt) )*&
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                         tend(k,j,i) = tend(k,j,i) + td_sub_lpt(k,nt) + fac *                      &
+                                       ( td_sub_lpt(k,nt+1) - td_sub_lpt(k,nt) ) *                 &
+                                       MERGE( 1.0_wp, 0.0_wp,                                      &
+                                              BTEST( wall_flags_total_0(k,j,i), 0 ) )
                       ENDDO
                    ENDDO
                 ENDDO
-  
+
              CASE ( 'q' )
 
@@ -853,8 +832,8 @@
                    DO  j = nys, nyn
                       DO  k = nzb+1, nzt
-                         tend(k,j,i) = tend(k,j,i) + td_sub_q(k,nt) + fac *    &
-                                       ( td_sub_q(k,nt+1) - td_sub_q(k,nt) ) * &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                         tend(k,j,i) = tend(k,j,i) + td_sub_q(k,nt) + fac *                        &
+                                          ( td_sub_q(k,nt+1) - td_sub_q(k,nt) ) *                  &
+                                          MERGE( 1.0_wp, 0.0_wp,                                   &
+                                                 BTEST( wall_flags_total_0(k,j,i), 0 ) )
                       ENDDO
                    ENDDO
@@ -868,25 +847,26 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Call for grid point i,j
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE ls_advec_ij ( i, j, time, prog_var )
 
        IMPLICIT NONE
 
-       CHARACTER (LEN=*) ::  prog_var   !< 
-
-       REAL(wp), INTENT(in)  :: time    !< 
-       REAL(wp) :: fac                  !< 
-
-       INTEGER(iwp) ::  i               !< 
-       INTEGER(iwp) ::  j               !< 
-       INTEGER(iwp) ::  k               !< 
-       INTEGER(iwp) ::  nt               !< 
-
-!
-!--    Interpolation in time of LSF_DATA 
+       CHARACTER (LEN=*) ::  prog_var   !<
+
+       INTEGER(iwp) ::  i               !<
+       INTEGER(iwp) ::  j               !<
+       INTEGER(iwp) ::  k               !<
+       INTEGER(iwp) ::  nt              !<
+
+       REAL(wp) :: fac                  !<
+       REAL(wp), INTENT(in)  :: time    !<
+
+
+!
+!--    Interpolation in time of LSF_DATA
        nt = 1
        DO WHILE ( time > time_vert(nt) )
@@ -900,5 +880,5 @@
 
 !
-!--    Add horizontal large scale advection tendencies of pt and q 
+!--    Add horizontal large scale advection tendencies of pt and q
        SELECT CASE ( prog_var )
 
@@ -906,8 +886,8 @@
 
              DO  k = nzb+1, nzt
-                tend(k,j,i) = tend(k,j,i) + td_lsa_lpt(k,nt)                   &
-                             + fac * ( td_lsa_lpt(k,nt+1) - td_lsa_lpt(k,nt) )*&
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                tend(k,j,i) = tend(k,j,i) + td_lsa_lpt(k,nt)                                       &
+                             + fac * ( td_lsa_lpt(k,nt+1) - td_lsa_lpt(k,nt) )*                    &
+                                        MERGE( 1.0_wp, 0.0_wp,                                     &
+                                               BTEST( wall_flags_total_0(k,j,i), 0 ) )
              ENDDO
 
@@ -915,8 +895,8 @@
 
              DO  k = nzb+1, nzt
-                tend(k,j,i) = tend(k,j,i) + td_lsa_q(k,nt)                     &
-                              + fac * ( td_lsa_q(k,nt+1) - td_lsa_q(k,nt) ) *  &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                tend(k,j,i) = tend(k,j,i) + td_lsa_q(k,nt)                                         &
+                              + fac * ( td_lsa_q(k,nt+1) - td_lsa_q(k,nt) ) *                      &
+                                        MERGE( 1.0_wp, 0.0_wp,                                     &
+                                               BTEST( wall_flags_total_0(k,j,i), 0 ) )
              ENDDO
 
@@ -932,17 +912,17 @@
 
                 DO  k = nzb+1, nzt
-                   tend(k,j,i) = tend(k,j,i) + td_sub_lpt(k,nt) + fac *        &
-                                 ( td_sub_lpt(k,nt+1) - td_sub_lpt(k,nt) ) *   &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                   tend(k,j,i) = tend(k,j,i) + td_sub_lpt(k,nt)                                    &
+                                 + fac * ( td_sub_lpt(k,nt+1) - td_sub_lpt(k,nt) ) *               &
+                                   MERGE( 1.0_wp, 0.0_wp,                                          &
+                                          BTEST( wall_flags_total_0(k,j,i), 0 ) )
                 ENDDO
-  
+
              CASE ( 'q' )
 
                 DO  k = nzb+1, nzt
-                   tend(k,j,i) = tend(k,j,i) + td_sub_q(k,nt) + fac *          &
-                                 ( td_sub_q(k,nt+1) - td_sub_q(k,nt) ) *       &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
+                   tend(k,j,i) = tend(k,j,i) + td_sub_q(k,nt)                                      &
+                                 + fac * ( td_sub_q(k,nt+1) - td_sub_q(k,nt) ) *                   &
+                                   MERGE( 1.0_wp, 0.0_wp,                                          &
+                                          BTEST( wall_flags_total_0(k,j,i), 0 ) )
                 ENDDO
 
@@ -954,13 +934,14 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE nudge_init
 
        IMPLICIT NONE
 
+       CHARACTER(1) ::  hash     !<
 
        INTEGER(iwp) ::  finput = 90  !<
@@ -969,26 +950,25 @@
        INTEGER(iwp) ::  nt            !<
 
-       CHARACTER(1) ::  hash     !<
+       REAL(wp) ::  fac          !<
 
        REAL(wp) ::  highheight   !<
        REAL(wp) ::  highqnudge   !<
        REAL(wp) ::  highptnudge  !<
+       REAL(wp) ::  hightnudge   !<
        REAL(wp) ::  highunudge   !<
        REAL(wp) ::  highvnudge   !<
        REAL(wp) ::  highwnudge   !<
-       REAL(wp) ::  hightnudge   !<
 
        REAL(wp) ::  lowheight    !<
        REAL(wp) ::  lowqnudge    !<
        REAL(wp) ::  lowptnudge   !<
+       REAL(wp) ::  lowtnudge    !<
        REAL(wp) ::  lowunudge    !<
        REAL(wp) ::  lowvnudge    !<
        REAL(wp) ::  lowwnudge    !<
-       REAL(wp) ::  lowtnudge    !<
-
-       REAL(wp) ::  fac          !<
-
-       ALLOCATE( ptnudge(nzb:nzt+1,1:ntnudge), qnudge(nzb:nzt+1,1:ntnudge), &
-                 tnudge(nzb:nzt+1,1:ntnudge), unudge(nzb:nzt+1,1:ntnudge),  &
+
+
+       ALLOCATE( ptnudge(nzb:nzt+1,1:ntnudge), qnudge(nzb:nzt+1,1:ntnudge),                        &
+                 tnudge(nzb:nzt+1,1:ntnudge), unudge(nzb:nzt+1,1:ntnudge),                         &
                  vnudge(nzb:nzt+1,1:ntnudge), wnudge(nzb:nzt+1,1:ntnudge)  )
 
@@ -1019,8 +999,8 @@
           ierrn = 1 ! not zero
 !
-!--       Search for the next line consisting of "# time", 
-!--       from there onwards the profiles will be read
-          DO WHILE ( .NOT. ( hash == "#" .AND. ierrn == 0 ) ) 
-          
+!--       Search for the next line consisting of "# time", from there onwards the profiles will be
+!--       read.
+          DO WHILE ( .NOT. ( hash == "#" .AND. ierrn == 0 ) )
+
             READ ( finput, *, IOSTAT=ierrn ) hash, timenudge(nt)
             IF ( ierrn < 0 )  EXIT rloop
@@ -1029,7 +1009,6 @@
 
           ierrn = 0
-          READ ( finput, *, IOSTAT=ierrn ) lowheight, lowtnudge, lowunudge,   &
-                                           lowvnudge, lowwnudge , lowptnudge, &
-                                           lowqnudge
+          READ ( finput, *, IOSTAT=ierrn ) lowheight, lowtnudge, lowunudge, lowvnudge, lowwnudge , &
+                                           lowptnudge, lowqnudge
 
           IF ( ierrn /= 0 )  THEN
@@ -1039,7 +1018,6 @@
 
           ierrn = 0
-          READ ( finput, *, IOSTAT=ierrn ) highheight, hightnudge, highunudge,   &
-                                           highvnudge, highwnudge , highptnudge, &
-                                           highqnudge
+          READ ( finput, *, IOSTAT=ierrn ) highheight, hightnudge, highunudge, highvnudge,         &
+                                           highwnudge , highptnudge, highqnudge
 
           IF ( ierrn /= 0 )  THEN
@@ -1057,15 +1035,13 @@
                 lowptnudge = highptnudge
                 lowqnudge  = highqnudge
- 
+
                 ierrn = 0
-                READ ( finput, *, IOSTAT=ierrn )  highheight , hightnudge ,    &
-                                                  highunudge , highvnudge ,    &
-                                                  highwnudge , highptnudge,    &
-                                                  highqnudge
+                READ ( finput, *, IOSTAT=ierrn )  highheight , hightnudge , highunudge ,           &
+                                                  highvnudge , highwnudge , highptnudge, highqnudge
                 IF (ierrn /= 0 )  THEN
-                   WRITE( message_string, * ) 'zu(',k,') = ', zu(k), 'm is ',  &
-                        'higher than the maximum height in NUDING_DATA which ',&
-                        'is ', lowheight, 'm. Interpolation on PALM ',         &
-                        'grid is not possible.'
+                   WRITE( message_string, * ) 'zu(',k,') = ', zu(k), 'm is ',                      &
+                                            'higher than the maximum height in NUDING_DATA which ',&
+                                            'is ', lowheight, 'm. Interpolation on PALM ',         &
+                                            'grid is not possible.'
                    CALL message( 'nudging', 'PA0364', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -1073,5 +1049,5 @@
 
 !
-!--          Interpolation of prescribed profiles in space 
+!--          Interpolation of prescribed profiles in space
 
              fac = ( highheight - zu(k) ) / ( highheight - lowheight )
@@ -1099,5 +1075,5 @@
           ENDIF
 
-          WRITE( message_string, * ) 'Initial profiles of u, v, pt and q ',    &
+          WRITE( message_string, * ) 'Initial profiles of u, v, pt and q ',                        &
                                      'from NUDGING_DATA are used.'
           CALL message( 'large_scale_forcing_nudging', 'PA0370', 0, 0, 0, 6, 0 )
@@ -1107,20 +1083,19 @@
     END SUBROUTINE nudge_init
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE calc_tnudge ( time )
 
        IMPLICIT NONE
 
+       INTEGER(iwp) ::  k   !<
+       INTEGER(iwp) ::  nt  !<
 
        REAL(wp) ::  dtm         !<
        REAL(wp) ::  dtp         !<
        REAL(wp) ::  time        !<
-
-       INTEGER(iwp) ::  k   !<
-       INTEGER(iwp) ::  nt  !<
 
        nt = 1
@@ -1141,9 +1116,9 @@
     END SUBROUTINE calc_tnudge
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Call for all grid points
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE nudge ( time, prog_var )
 
@@ -1151,9 +1126,4 @@
 
        CHARACTER (LEN=*) ::  prog_var  !<
-
-       REAL(wp) ::  tmp_tend    !<
-       REAL(wp) ::  dtm         !<
-       REAL(wp) ::  dtp         !<
-       REAL(wp) ::  time        !<
 
        INTEGER(iwp) ::  i  !<
@@ -1161,4 +1131,9 @@
        INTEGER(iwp) ::  k  !<
        INTEGER(iwp) ::  nt  !<
+
+       REAL(wp) ::  dtm         !<
+       REAL(wp) ::  dtp         !<
+       REAL(wp) ::  time        !<
+       REAL(wp) ::  tmp_tend    !<
 
 
@@ -1183,17 +1158,17 @@
                    DO  k = nzb+1, nzt
 
-                      tmp_tend = - ( hom(k,1,1,0) - ( unudge(k,nt) * dtp +     &
-                                     unudge(k,nt+1) * dtm ) ) / tmp_tnudge(k)
-
-                      tend(k,j,i) = tend(k,j,i) + tmp_tend *                   &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 1 ) )
-
-                      sums_ls_l(k,6) = sums_ls_l(k,6) + tmp_tend *             &
-                                     weight_substep(intermediate_timestep_count)
+                      tmp_tend = - ( hom(k,1,1,0) - ( unudge(k,nt) * dtp + unudge(k,nt+1) * dtm ) )&
+                                   / tmp_tnudge(k)
+
+                      tend(k,j,i) = tend(k,j,i)                                                    &
+                                    + tmp_tend * MERGE( 1.0_wp, 0.0_wp,                            &
+                                                        BTEST( wall_flags_total_0(k,j,i), 1 ) )
+
+                      sums_ls_l(k,6) = sums_ls_l(k,6)                                              &
+                                       + tmp_tend * weight_substep(intermediate_timestep_count)
                    ENDDO
-                  
+
                    sums_ls_l(nzt+1,6) = sums_ls_l(nzt,6)
- 
+
                 ENDDO
             ENDDO
@@ -1206,15 +1181,15 @@
                    DO  k = nzb+1, nzt
 
-                      tmp_tend = - ( hom(k,1,2,0) - ( vnudge(k,nt) * dtp +     &
-                                     vnudge(k,nt+1) * dtm ) ) / tmp_tnudge(k)
-
-                      tend(k,j,i) = tend(k,j,i) + tmp_tend *                   &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 2 ) )
-
-                      sums_ls_l(k,7) = sums_ls_l(k,7) + tmp_tend *             &
-                                     weight_substep(intermediate_timestep_count)
+                      tmp_tend = - ( hom(k,1,2,0) - ( vnudge(k,nt) * dtp + vnudge(k,nt+1) * dtm ) )&
+                                   / tmp_tnudge(k)
+
+                      tend(k,j,i) = tend(k,j,i)                                                    &
+                                    + tmp_tend * MERGE( 1.0_wp, 0.0_wp,                            &
+                                                        BTEST( wall_flags_total_0(k,j,i), 2 ) )
+
+                      sums_ls_l(k,7) = sums_ls_l(k,7)                                              &
+                                       + tmp_tend * weight_substep(intermediate_timestep_count)
                    ENDDO
-                  
+
                    sums_ls_l(nzt+1,7) = sums_ls_l(nzt,7)
 
@@ -1229,13 +1204,13 @@
                    DO  k = nzb+1, nzt
 
-                      tmp_tend = - ( hom(k,1,4,0) - ( ptnudge(k,nt) * dtp +    &
+                      tmp_tend = - ( hom(k,1,4,0) - ( ptnudge(k,nt) * dtp +                        &
                                      ptnudge(k,nt+1) * dtm ) ) / tmp_tnudge(k)
 
-                      tend(k,j,i) = tend(k,j,i) + tmp_tend *                   &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
-
-                      sums_ls_l(k,4) = sums_ls_l(k,4) + tmp_tend *             &
-                                     weight_substep(intermediate_timestep_count)
+                      tend(k,j,i) = tend(k,j,i)                                                    &
+                                    + tmp_tend * MERGE( 1.0_wp, 0.0_wp,                            &
+                                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
+
+                      sums_ls_l(k,4) = sums_ls_l(k,4)                                              &
+                                       + tmp_tend * weight_substep(intermediate_timestep_count)
                    ENDDO
 
@@ -1252,15 +1227,15 @@
                    DO  k = nzb+1, nzt
 
-                      tmp_tend = - ( hom(k,1,41,0) - ( qnudge(k,nt) * dtp +    &
+                      tmp_tend = - ( hom(k,1,41,0) - ( qnudge(k,nt) * dtp +                        &
                                      qnudge(k,nt+1) * dtm ) ) / tmp_tnudge(k)
 
-                      tend(k,j,i) = tend(k,j,i) + tmp_tend *                   &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
-
-                      sums_ls_l(k,5) = sums_ls_l(k,5) + tmp_tend *             &
-                                     weight_substep(intermediate_timestep_count)
+                      tend(k,j,i) = tend(k,j,i)                                                    &
+                                    + tmp_tend * MERGE( 1.0_wp, 0.0_wp,                            &
+                                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
+
+                      sums_ls_l(k,5) = sums_ls_l(k,5)                                              &
+                                       + tmp_tend * weight_substep(intermediate_timestep_count)
                    ENDDO
-                  
+
                    sums_ls_l(nzt+1,5) = sums_ls_l(nzt,5)
 
@@ -1277,9 +1252,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Call for grid point i,j
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 
     SUBROUTINE nudge_ij( i, j, time, prog_var )
@@ -1289,9 +1264,4 @@
 
        CHARACTER (LEN=*) ::  prog_var  !<
-
-       REAL(wp) ::  tmp_tend    !<
-       REAL(wp) ::  dtm         !<
-       REAL(wp) ::  dtp         !<
-       REAL(wp) ::  time        !<
 
        INTEGER(iwp) ::  i  !<
@@ -1299,4 +1269,9 @@
        INTEGER(iwp) ::  k  !<
        INTEGER(iwp) ::  nt  !<
+
+       REAL(wp) ::  dtm         !<
+       REAL(wp) ::  dtp         !<
+       REAL(wp) ::  time        !<
+       REAL(wp) ::  tmp_tend    !<
 
 
@@ -1318,13 +1293,13 @@
              DO  k = nzb+1, nzt
 
-                tmp_tend = - ( hom(k,1,1,0) - ( unudge(k,nt) * dtp +           &
-                               unudge(k,nt+1) * dtm ) ) / tmp_tnudge(k)
-
-                tend(k,j,i) = tend(k,j,i) + tmp_tend *                         &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 1 ) )
-
-                sums_ls_l(k,6) = sums_ls_l(k,6) + tmp_tend                     &
-                                 * weight_substep(intermediate_timestep_count)
+                tmp_tend = - ( hom(k,1,1,0) - ( unudge(k,nt) * dtp + unudge(k,nt+1) * dtm ) )      &
+                             / tmp_tnudge(k)
+
+                tend(k,j,i) = tend(k,j,i)                                                          &
+                              + tmp_tend * MERGE( 1.0_wp, 0.0_wp,                                  &
+                                                  BTEST( wall_flags_total_0(k,j,i), 1 ) )
+
+                sums_ls_l(k,6) = sums_ls_l(k,6)                                                    &
+                                 + tmp_tend * weight_substep(intermediate_timestep_count)
              ENDDO
 
@@ -1335,13 +1310,13 @@
              DO  k = nzb+1, nzt
 
-                tmp_tend = - ( hom(k,1,2,0) - ( vnudge(k,nt) * dtp +           &
-                               vnudge(k,nt+1) * dtm ) ) / tmp_tnudge(k)
-
-                tend(k,j,i) = tend(k,j,i) + tmp_tend *                         &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 2 ) )
-
-                sums_ls_l(k,7) = sums_ls_l(k,7) + tmp_tend                     &
-                                 * weight_substep(intermediate_timestep_count)
+                tmp_tend = - ( hom(k,1,2,0) - ( vnudge(k,nt) * dtp + vnudge(k,nt+1) * dtm ) )      &
+                             / tmp_tnudge(k)
+
+                tend(k,j,i) = tend(k,j,i)                                                          &
+                              + tmp_tend * MERGE( 1.0_wp, 0.0_wp,                                  &
+                                                  BTEST( wall_flags_total_0(k,j,i), 2 ) )
+
+                sums_ls_l(k,7) = sums_ls_l(k,7)                                                    &
+                                 + tmp_tend * weight_substep(intermediate_timestep_count)
              ENDDO
 
@@ -1352,13 +1327,13 @@
              DO  k = nzb+1, nzt
 
-                tmp_tend = - ( hom(k,1,4,0) - ( ptnudge(k,nt) * dtp +          &
-                               ptnudge(k,nt+1) * dtm ) ) / tmp_tnudge(k)
-
-                tend(k,j,i) = tend(k,j,i) + tmp_tend *                         &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
-
-                sums_ls_l(k,4) = sums_ls_l(k,4) + tmp_tend                     &
-                                 * weight_substep(intermediate_timestep_count)
+                tmp_tend = - ( hom(k,1,4,0) - ( ptnudge(k,nt) * dtp + ptnudge(k,nt+1) * dtm ) )    &
+                             / tmp_tnudge(k)
+
+                tend(k,j,i) = tend(k,j,i)                                                          &
+                              + tmp_tend * MERGE( 1.0_wp, 0.0_wp,                                  &
+                                                  BTEST( wall_flags_total_0(k,j,i), 0 ) )
+
+                sums_ls_l(k,4) = sums_ls_l(k,4)                                                    &
+                                 + tmp_tend * weight_substep(intermediate_timestep_count)
              ENDDO
 
@@ -1370,13 +1345,13 @@
              DO  k = nzb+1, nzt
 
-                tmp_tend = - ( hom(k,1,41,0) - ( qnudge(k,nt) * dtp +          &
-                               qnudge(k,nt+1) * dtm ) ) / tmp_tnudge(k)
-
-                tend(k,j,i) = tend(k,j,i) + tmp_tend *                         &
-                                        MERGE( 1.0_wp, 0.0_wp,                 &
-                                        BTEST( wall_flags_total_0(k,j,i), 0 ) )
-
-                sums_ls_l(k,5) = sums_ls_l(k,5) + tmp_tend                     &
-                                 * weight_substep(intermediate_timestep_count)
+                tmp_tend = - ( hom(k,1,41,0) - ( qnudge(k,nt) * dtp + qnudge(k,nt+1) * dtm ) )     &
+                             / tmp_tnudge(k)
+
+                tend(k,j,i) = tend(k,j,i)                                                          &
+                              + tmp_tend * MERGE( 1.0_wp, 0.0_wp,                                  &
+                                                  BTEST( wall_flags_total_0(k,j,i), 0 ) )
+
+                sums_ls_l(k,5) = sums_ls_l(k,5)                                                    &
+                                 + tmp_tend * weight_substep(intermediate_timestep_count)
              ENDDO
 
@@ -1393,9 +1368,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE nudge_ref ( time )
 
@@ -1408,7 +1383,7 @@
 
 !
-!--    Interpolation in time of NUDGING_DATA for pt_init and q_init. This is 
-!--    needed for correct upper boundary conditions for pt and q and in case that 
-!      large scale subsidence as well as scalar Rayleigh-damping are used
+!--    Interpolation in time of NUDGING_DATA for pt_init and q_init. This is needed for correct
+!--    upper boundary conditions for pt and q and in case that large scale subsidence as well as
+!--    scalar Rayleigh-damping are used.
        nt = 1
        DO WHILE ( time > time_vert(nt) )
