Index: palm/trunk/SOURCE/large_scale_forcing_nudging_mod.f90
===================================================================
--- palm/trunk/SOURCE/large_scale_forcing_nudging_mod.f90	(revision 3294)
+++ palm/trunk/SOURCE/large_scale_forcing_nudging_mod.f90	(revision 3347)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Offline nesting parts are moved to an independent module nesting_offl_mod
+! 
+! 3341 2018-10-15 10:31:27Z suehring
 ! ocean renamed ocean_mode
 ! 
@@ -87,6 +90,5 @@
 
     USE control_parameters,                                                    &
-        ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s, &
-               bc_lr, bc_ns, bc_pt_b, bc_q_b, constant_diffusion,              &
+        ONLY:  bc_lr, bc_ns, bc_pt_b, bc_q_b, constant_diffusion,              &
                constant_heatflux, constant_waterflux,                          &
                data_output_pr, dt_3d, end_time,                                &
@@ -94,8 +96,11 @@
                ibc_pt_b, ibc_q_b,                                              &
                large_scale_forcing, large_scale_subsidence, lsf_surf, lsf_vert,&
-               lsf_exception, message_string, nesting_offline, neutral,        &
+               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 cpulog,                                                                &
+        ONLY:  cpu_log, log_point
 
     USE grid_variables
@@ -107,7 +112,4 @@
     USE kinds
 
-    USE netcdf_data_input_mod,                                                 &
-        ONLY:  nest_offl
-
     USE pegrid
 
@@ -120,6 +122,4 @@
     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) ::  d_area_t
 
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ptnudge     !< vertical profile of pot. temperature interpolated to vertical grid (nudging)
@@ -156,5 +156,4 @@
            lsf_nudging_check_parameters, nudge_init,                           &
            lsf_nudging_check_data_output_pr, lsf_nudging_header,               &
-           lsf_nesting_offline, lsf_nesting_offline_mass_conservation,         & 
            nudge, nudge_ref
            
@@ -177,482 +176,4 @@
  CONTAINS
 
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> In this subroutine a constant mass within the model domain is guaranteed. 
-!> Larger-scale models may be based on a compressible equation system, which is
-!> not consistent with PALMs incompressible equation system. In order to avoid
-!> a decrease or increase of mass during the simulation, non-divergent flow
-!> through the lateral and top boundaries is compensated by the vertical wind 
-!> component at the top boundary. 
-!------------------------------------------------------------------------------!
-    SUBROUTINE lsf_nesting_offline_mass_conservation
-
-       USE control_parameters,                                                 &
-           ONLY:  volume_flow
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i !< grid index in x-direction
-       INTEGER(iwp) ::  j !< grid index in y-direction
-       INTEGER(iwp) ::  k !< grid index in z-direction
-
-       REAL(wp) ::  w_correct                       !< vertical velocity increment required to compensate non-divergent flow through the boundaries
-       REAL(wp), DIMENSION(1:3) ::  volume_flow_l   !< local volume flow
-
-       volume_flow   = 0.0_wp
-       volume_flow_l = 0.0_wp
-
-       d_area_t = 1.0_wp / ( ( nx + 1 ) * dx * ( ny + 1 ) * dy )
-
-       IF ( bc_dirichlet_l )  THEN
-          i = nxl
-          DO  j = nys, nyn
-             DO  k = nzb+1, nzt
-                volume_flow_l(1) = volume_flow_l(1) + u(k,j,i) * dzw(k) * dy   &
-                                     * MERGE( 1.0_wp, 0.0_wp,                  &
-                                              BTEST( wall_flags_0(k,j,i), 1 ) )
-             ENDDO
-          ENDDO
-       ENDIF
-       IF ( bc_dirichlet_r )  THEN
-          i = nxr+1
-          DO  j = nys, nyn
-             DO  k = nzb+1, nzt
-                volume_flow_l(1) = volume_flow_l(1) - u(k,j,i) * dzw(k) * dy   &
-                                     * MERGE( 1.0_wp, 0.0_wp,                  &
-                                              BTEST( wall_flags_0(k,j,i), 1 ) )
-             ENDDO
-          ENDDO
-       ENDIF
-       IF ( bc_dirichlet_s )  THEN
-          j = nys
-          DO  i = nxl, nxr
-             DO  k = nzb+1, nzt
-                volume_flow_l(2) = volume_flow_l(2) + v(k,j,i) * dzw(k) * dx   &
-                                     * MERGE( 1.0_wp, 0.0_wp,                  &
-                                              BTEST( wall_flags_0(k,j,i), 2 ) )
-             ENDDO
-          ENDDO
-       ENDIF
-       IF ( bc_dirichlet_n )  THEN
-          j = nyn+1
-          DO  i = nxl, nxr
-             DO  k = nzb+1, nzt
-                volume_flow_l(2) = volume_flow_l(2) - v(k,j,i) * dzw(k) * dx   &
-                                     * MERGE( 1.0_wp, 0.0_wp,                  &
-                                              BTEST( wall_flags_0(k,j,i), 2 ) )
-             ENDDO
-          ENDDO
-       ENDIF
-!
-!--    Top boundary
-       k = nzt
-       DO  i = nxl, nxr
-          DO  j = nys, nyn
-             volume_flow_l(3) = volume_flow_l(3) - w(k,j,i) * dx * dy
-          ENDDO
-       ENDDO
-
-#if defined( __parallel )
-       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( volume_flow_l, volume_flow, 3, MPI_REAL, MPI_SUM,      &
-                           comm2d, ierr )
-#else
-       volume_flow = volume_flow_l
-#endif
-
-       w_correct = SUM( volume_flow ) * d_area_t
-
-       DO  i = nxl, nxr
-          DO  j = nys, nyn
-             DO  k = nzt, nzt + 1
-                w(k,j,i) = w(k,j,i) + w_correct
-             ENDDO
-          ENDDO
-       ENDDO
-
-    END SUBROUTINE lsf_nesting_offline_mass_conservation
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Set the lateral and top boundary conditions in case the PALM domain is 
-!> nested offline in a mesoscale model. 
-!------------------------------------------------------------------------------!
-    SUBROUTINE lsf_nesting_offline
-
-       USE control_parameters,                                                 &
-           ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r,              &
-                  bc_dirichlet_s, humidity, neutral, passive_scalar, rans_mode,&
-                  rans_tke_e, time_since_reference_point                      
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i !< running index x-direction
-       INTEGER(iwp) ::  j !< running index y-direction
-       INTEGER(iwp) ::  k !< running index z-direction
-
-       REAL(wp) ::  ddt_lsf !< inverse value of time resolution of forcing data
-       REAL(wp) ::  t_ref   !< time past since last reference step
-     
-!
-!--    Calculate time interval of forcing data       
-       ddt_lsf = 1.0_wp / ( nest_offl%time(nest_offl%tind_p) -                 &
-                            nest_offl%time(nest_offl%tind) )
-!
-!--    Calculate reziproke time past since last reference step. Please note, 
-!--    the time coordinate is still not updated, so that the actual time need
-!--    to be incremented by dt_3d. Moreover, note that the simulation time
-!--    passed since simulation start is time_since_reference_point, not 
-!--    simulated_time!
-       t_ref = time_since_reference_point + dt_3d -                            &
-                                            nest_offl%time(nest_offl%tind)
-                                            
-       IF ( bc_dirichlet_l )  THEN
-
-          DO  j = nys, nyn
-             DO  k = nzb+1, nzt
-                u(k,j,nxlg:nxl) = nest_offl%u_left(0,k,j) + ddt_lsf * t_ref  * &
-                       ( nest_offl%u_left(1,k,j) - nest_offl%u_left(0,k,j) ) * &
-                         MERGE( 1.0_wp, 0.0_wp,                                &
-                                BTEST( wall_flags_0(k,j,nxlg:nxl), 1 ) )
-             ENDDO
-          ENDDO
-
-          DO  j = nys, nyn
-             DO  k = nzb+1, nzt-1
-                w(k,j,nxlg:nxl-1) = nest_offl%w_left(0,k,j) + ddt_lsf * t_ref *&
-                       ( nest_offl%w_left(1,k,j) - nest_offl%w_left(0,k,j) )  *&
-                         MERGE( 1.0_wp, 0.0_wp,                                &
-                                BTEST( wall_flags_0(k,j,nxlg:nxl-1), 3 ) )
-             ENDDO
-          ENDDO
-
-          DO  j = nysv, nyn
-             DO  k = nzb+1, nzt
-                v(k,j,nxlg:nxl-1) = nest_offl%v_left(0,k,j) + ddt_lsf * t_ref *&
-                       ( nest_offl%v_left(1,k,j) - nest_offl%v_left(0,k,j) )  *&
-                         MERGE( 1.0_wp, 0.0_wp,                                &
-                                BTEST( wall_flags_0(k,j,nxlg:nxl-1), 2 ) )
-             ENDDO
-          ENDDO
-
-          IF ( .NOT. neutral )  THEN
-             DO  j = nys, nyn
-                DO  k = nzb+1, nzt
-                   pt(k,j,nxlg:nxl-1) = nest_offl%pt_left(0,k,j) + ddt_lsf *   &
-                                                                   t_ref   *   &
-                       ( nest_offl%pt_left(1,k,j) - nest_offl%pt_left(0,k,j) )
- 
-                ENDDO
-             ENDDO
-          ENDIF
-
-          IF ( humidity )  THEN
-             DO  j = nys, nyn
-                DO  k = nzb+1, nzt
-                   q(k,j,nxlg:nxl-1) = nest_offl%q_left(0,k,j) + ddt_lsf   *   &
-                                                                 t_ref     *   &
-                       ( nest_offl%q_left(1,k,j) - nest_offl%q_left(0,k,j) )
- 
-                ENDDO
-             ENDDO
-          ENDIF
-
-       ENDIF
-
-       IF ( bc_dirichlet_r )  THEN
-
-          DO  j = nys, nyn
-             DO  k = nzb+1, nzt
-                u(k,j,nxr+1:nxrg) = nest_offl%u_right(0,k,j) + ddt_lsf * t_ref *&
-                      ( nest_offl%u_right(1,k,j) - nest_offl%u_right(0,k,j) )  *&
-                         MERGE( 1.0_wp, 0.0_wp,                                 &
-                                BTEST( wall_flags_0(k,j,nxr+1:nxrg), 1 ) )
-
-             ENDDO
-          ENDDO
-          DO  j = nys, nyn
-             DO  k = nzb+1, nzt-1
-                w(k,j,nxr+1:nxrg) = nest_offl%w_right(0,k,j) + ddt_lsf * t_ref *&
-                      ( nest_offl%w_right(1,k,j) - nest_offl%w_right(0,k,j) )  *&
-                         MERGE( 1.0_wp, 0.0_wp,                                 &
-                                BTEST( wall_flags_0(k,j,nxr+1:nxrg), 3 ) )
-             ENDDO
-          ENDDO
-
-          DO  j = nysv, nyn
-             DO  k = nzb+1, nzt
-                v(k,j,nxr+1:nxrg) = nest_offl%v_right(0,k,j) + ddt_lsf * t_ref *&
-                      ( nest_offl%v_right(1,k,j) - nest_offl%v_right(0,k,j) )  *&
-                         MERGE( 1.0_wp, 0.0_wp,                                 &
-                                BTEST( wall_flags_0(k,j,nxr+1:nxrg), 2 ) )
-             ENDDO
-          ENDDO
-
-          IF ( .NOT. neutral )  THEN
-             DO  j = nys, nyn
-                DO  k = nzb+1, nzt
-                   pt(k,j,nxr+1:nxrg) = nest_offl%pt_right(0,k,j) + ddt_lsf *  &
-                                                                    t_ref   *  &
-                     ( nest_offl%pt_right(1,k,j) - nest_offl%pt_right(0,k,j) )
- 
-                ENDDO
-             ENDDO
-          ENDIF
-
-          IF ( humidity )  THEN
-             DO  j = nys, nyn
-                DO  k = nzb+1, nzt
-                   q(k,j,nxr+1:nxrg) = nest_offl%q_right(0,k,j) + ddt_lsf   *  &
-                                                                    t_ref   *  &
-                       ( nest_offl%q_right(1,k,j) - nest_offl%q_right(0,k,j) )
- 
-                ENDDO
-             ENDDO
-          ENDIF
-
-       ENDIF
-
-       IF ( bc_dirichlet_s )  THEN
-
-          DO  i = nxl, nxr
-             DO  k = nzb+1, nzt
-                v(k,nysg:nys,i)   = nest_offl%v_south(0,k,i) + ddt_lsf * t_ref *&
-                      ( nest_offl%v_south(1,k,i) - nest_offl%v_south(0,k,i) )  *&
-                         MERGE( 1.0_wp, 0.0_wp,                                 &
-                                BTEST( wall_flags_0(k,nysg:nys,i), 2 ) )
-             ENDDO
-          ENDDO
-
-          DO  i = nxl, nxr
-             DO  k = nzb+1, nzt-1
-                w(k,nysg:nys-1,i) = nest_offl%w_south(0,k,i) + ddt_lsf * t_ref  *&
-                        ( nest_offl%w_south(1,k,i) - nest_offl%w_south(0,k,i) ) *&
-                           MERGE( 1.0_wp, 0.0_wp,                                &
-                                  BTEST( wall_flags_0(k,nysg:nys-1,i), 3 ) )
-             ENDDO
-          ENDDO
-
-          DO  i = nxlu, nxr
-             DO  k = nzb+1, nzt
-                u(k,nysg:nys-1,i) = nest_offl%u_south(0,k,i) + ddt_lsf * t_ref  *&
-                        ( nest_offl%u_south(1,k,i) - nest_offl%u_south(0,k,i) ) *&
-                           MERGE( 1.0_wp, 0.0_wp,                                &
-                                  BTEST( wall_flags_0(k,nysg:nys-1,i), 1 ) )
-             ENDDO
-          ENDDO
-
-          IF ( .NOT. neutral )  THEN
-             DO  i = nxl, nxr
-                DO  k = nzb+1, nzt
-                   pt(k,nysg:nys-1,i) = nest_offl%pt_south(0,k,i) + ddt_lsf *  &
-                                                                    t_ref   *  &
-                     ( nest_offl%pt_south(1,k,i) - nest_offl%pt_south(0,k,i) )
- 
-                ENDDO
-             ENDDO
-          ENDIF
-
-          IF ( humidity )  THEN
-             DO  i = nxl, nxr
-                DO  k = nzb+1, nzt
-                   q(k,nysg:nys-1,i) = nest_offl%q_south(0,k,i) + ddt_lsf   *  &
-                                                                    t_ref   *  &
-                       ( nest_offl%q_south(1,k,i) - nest_offl%q_south(0,k,i) )
- 
-                ENDDO
-             ENDDO
-          ENDIF
-
-       ENDIF
-
-       IF ( bc_dirichlet_n )  THEN
-
-          DO  i = nxl, nxr
-             DO  k = nzb+1, nzt
-                v(k,nyn+1:nyng,i)   = nest_offl%v_north(0,k,i) + ddt_lsf * t_ref *&
-                        ( nest_offl%v_north(1,k,i) - nest_offl%v_north(0,k,i) )  *&
-                           MERGE( 1.0_wp, 0.0_wp,                                 &
-                                  BTEST( wall_flags_0(k,nyn+1:nyng,i), 2 ) )
-             ENDDO
-          ENDDO
-          DO  i = nxl, nxr
-             DO  k = nzb+1, nzt-1
-                w(k,nyn+1:nyng,i) = nest_offl%w_north(0,k,i) + ddt_lsf * t_ref  *&
-                        ( nest_offl%w_north(1,k,i) - nest_offl%w_north(0,k,i) ) *&
-                           MERGE( 1.0_wp, 0.0_wp,                                &
-                                  BTEST( wall_flags_0(k,nyn+1:nyng,i), 3 ) )
-             ENDDO
-          ENDDO
-
-          DO  i = nxlu, nxr
-             DO  k = nzb+1, nzt
-                u(k,nyn+1:nyng,i) = nest_offl%u_north(0,k,i) + ddt_lsf * t_ref  *&
-                        ( nest_offl%u_north(1,k,i) - nest_offl%u_north(0,k,i) ) *&
-                           MERGE( 1.0_wp, 0.0_wp,                                &
-                                  BTEST( wall_flags_0(k,nyn+1:nyng,i), 1 ) )
-
-             ENDDO
-          ENDDO
-
-          IF ( .NOT. neutral )  THEN
-             DO  i = nxl, nxr
-                DO  k = nzb+1, nzt
-                   pt(k,nyn+1:nyng,i) = nest_offl%pt_north(0,k,i) + ddt_lsf *  &
-                                                                    t_ref   *  &
-                     ( nest_offl%pt_north(1,k,i) - nest_offl%pt_north(0,k,i) )
- 
-                ENDDO
-             ENDDO
-          ENDIF
-
-          IF ( humidity )  THEN
-             DO  i = nxl, nxr
-                DO  k = nzb+1, nzt
-                   q(k,nyn+1:nyng,i) = nest_offl%q_north(0,k,i) + ddt_lsf   *  &
-                                                                    t_ref   *  &
-                       ( nest_offl%q_north(1,k,i) - nest_offl%q_north(0,k,i) )
- 
-                ENDDO
-             ENDDO
-          ENDIF
-
-       ENDIF
-!
-!--    Top boundary. 
-       DO  i = nxlu, nxr
-          DO  j = nys, nyn
-             u(nzt+1,j,i) = nest_offl%u_top(0,j,i) + ddt_lsf * t_ref *         &
-                        ( nest_offl%u_top(1,j,i) - nest_offl%u_top(0,j,i) ) *  &
-                           MERGE( 1.0_wp, 0.0_wp,                              &
-                                  BTEST( wall_flags_0(nzt+1,j,i), 1 ) )
-          ENDDO
-       ENDDO
-
-       DO  i = nxl, nxr
-          DO  j = nysv, nyn
-             v(nzt+1,j,i) = nest_offl%v_top(0,j,i) + ddt_lsf * t_ref *         &
-                        ( nest_offl%v_top(1,j,i) - nest_offl%v_top(0,j,i) ) *  &
-                           MERGE( 1.0_wp, 0.0_wp,                              &
-                                  BTEST( wall_flags_0(nzt+1,j,i), 2 ) )
-          ENDDO
-       ENDDO
-
-       DO  i = nxl, nxr
-          DO  j = nys, nyn
-             w(nzt:nzt+1,j,i) = nest_offl%w_top(0,j,i) + ddt_lsf * t_ref *     &
-                        ( nest_offl%w_top(1,j,i) - nest_offl%w_top(0,j,i) ) *  &
-                           MERGE( 1.0_wp, 0.0_wp,                              &
-                                  BTEST( wall_flags_0(nzt:nzt+1,j,i), 3 ) )
-          ENDDO
-       ENDDO
-
-
-       IF ( .NOT. neutral )  THEN
-          DO  i = nxl, nxr
-             DO  j = nys, nyn
-                pt(nzt+1,j,i) = nest_offl%pt_top(0,j,i) + ddt_lsf * t_ref *    &
-                        ( nest_offl%pt_top(1,j,i) - nest_offl%pt_top(0,j,i) )
-             ENDDO
-          ENDDO
-       ENDIF
-
-       IF ( humidity )  THEN
-          DO  i = nxl, nxr
-             DO  j = nys, nyn
-                q(nzt+1,j,i) = nest_offl%q_top(0,j,i) + ddt_lsf * t_ref *      &
-                        ( nest_offl%q_top(1,j,i) - nest_offl%q_top(0,j,i) )
-             ENDDO
-          ENDDO
-       ENDIF
-!
-!--    At the edges( left-south, left-north, right-south and right-north) set 
-!--    data on ghost points. 
-       IF ( bc_dirichlet_l  .AND.  bc_dirichlet_s )  THEN
-          DO  i = 1, nbgp
-             u(:,nys-i,nxlg:nxl)   = u(:,nys,nxlg:nxl)
-             w(:,nys-i,nxlg:nxl-1) = w(:,nys,nxlg:nxl-1)
-             IF ( .NOT. neutral )  pt(:,nys-i,nxlg:nxl-1) = pt(:,nys,nxlg:nxl-1)
-             IF ( humidity      )  q(:,nys-i,nxlg:nxl-1)  = q(:,nys,nxlg:nxl-1)
-          ENDDO
-          DO  i = 1, nbgp+1
-             v(:,nysv-i,nxlg:nxl-1) = v(:,nysv,nxlg:nxl-1)
-          ENDDO
-       ENDIF
-       IF ( bc_dirichlet_l  .AND.  bc_dirichlet_n )  THEN
-          DO  i = 1, nbgp
-             u(:,nyn+i,nxlg:nxl)   = u(:,nyn,nxlg:nxl)
-             v(:,nyn+i,nxlg:nxl-1) = v(:,nyn,nxlg:nxl-1)
-             w(:,nyn+i,nxlg:nxl-1) = w(:,nyn,nxlg:nxl-1)
-             IF ( .NOT. neutral )  pt(:,nyn+i,nxlg:nxl-1) = pt(:,nyn,nxlg:nxl-1)
-             IF ( humidity      )  q(:,nyn+i,nxlg:nxl-1)  = q(:,nyn,nxlg:nxl-1)
-          ENDDO
-       ENDIF
-       IF ( bc_dirichlet_r  .AND.  bc_dirichlet_s )  THEN
-          DO  i = 1, nbgp
-             u(:,nys-i,nxr+1:nxrg) = u(:,nys,nxr+1:nxrg)
-             w(:,nys-i,nxr+1:nxrg) = w(:,nys,nxr+1:nxrg)
-             IF ( .NOT. neutral )  pt(:,nys-i,nxr+1:nxrg) = pt(:,nys,nxr+1:nxrg)
-             IF ( humidity      )  q(:,nys-i,nxr+1:nxrg)  = q(:,nys,nxr+1:nxrg)
-          ENDDO
-          DO  i = 1, nbgp+1
-             v(:,nysv-i,nxr+1:nxrg) = v(:,nysv,nxr+1:nxrg)
-          ENDDO
-       ENDIF
-       IF ( bc_dirichlet_r  .AND.  bc_dirichlet_n )  THEN
-          DO  i = 1, nbgp
-             u(:,nyn+i,nxr+1:nxrg) = u(:,nyn,nxr+1:nxrg)
-             v(:,nyn+i,nxr+1:nxrg) = v(:,nyn,nxr+1:nxrg)
-             w(:,nyn+i,nxr+1:nxrg) = w(:,nyn,nxr+1:nxrg)
-             IF ( .NOT. neutral )  pt(:,nyn+i,nxr+1:nxrg) = pt(:,nyn,nxr+1:nxrg)
-             IF ( humidity      )  q(:,nyn+i,nxr+1:nxrg)  = q(:,nyn,nxr+1:nxrg)
-          ENDDO
-       ENDIF
-!
-!--    Moreover, set Neumann boundary condition for subgrid-scale TKE, 
-!--    passive scalar, dissipation, and chemical species if required
-       IF ( rans_mode  .AND.  rans_tke_e )  THEN
-          IF (  bc_dirichlet_l )  diss(:,:,nxl-1) = diss(:,:,nxl)
-          IF (  bc_dirichlet_r )  diss(:,:,nxr+1) = diss(:,:,nxr)
-          IF (  bc_dirichlet_s )  diss(:,nys-1,:) = diss(:,nys,:)
-          IF (  bc_dirichlet_n )  diss(:,nyn+1,:) = diss(:,nyn,:)
-       ENDIF
-       IF ( .NOT. constant_diffusion )  THEN
-          IF (  bc_dirichlet_l )  e(:,:,nxl-1) = e(:,:,nxl)
-          IF (  bc_dirichlet_r )  e(:,:,nxr+1) = e(:,:,nxr)
-          IF (  bc_dirichlet_s )  e(:,nys-1,:) = e(:,nys,:)
-          IF (  bc_dirichlet_n )  e(:,nyn+1,:) = e(:,nyn,:)
-          e(nzt+1,:,:) = e(nzt,:,:)
-       ENDIF
-       IF ( passive_scalar )  THEN
-          IF (  bc_dirichlet_l )  s(:,:,nxl-1) = s(:,:,nxl)
-          IF (  bc_dirichlet_r )  s(:,:,nxr+1) = s(:,:,nxr)
-          IF (  bc_dirichlet_s )  s(:,nys-1,:) = s(:,nys,:)
-          IF (  bc_dirichlet_n )  s(:,nyn+1,:) = s(:,nyn,:)
-       ENDIF
-
-
-
-       CALL exchange_horiz( u, nbgp )
-       CALL exchange_horiz( v, nbgp )
-       CALL exchange_horiz( w, nbgp )
-       IF ( .NOT. neutral )  CALL exchange_horiz( pt, nbgp )
-       IF ( humidity      )  CALL exchange_horiz( q,  nbgp )
-
-!
-!--    Set surface pressure. Please note, time-dependent surface
-!--    pressure would require changes in anelastic approximation and 
-!--    treatment of fluxes. 
-!--    For the moment, comment this out! 
-!      surface_pressure = nest_offl%surface_pressure(nest_offl%tind) +                 &
-!                                                      ddt_lsf * t_ref *       &
-!                                    ( nest_offl%surface_pressure(nest_offl%tind_p)    &
-!                                    - nest_offl%surface_pressure(nest_offl%tind) )
-
-    END SUBROUTINE lsf_nesting_offline
 
 !------------------------------------------------------------------------------!
@@ -935,7 +456,4 @@
            ONLY:  bc_lr_cyc, bc_ns_cyc
 
-       USE netcdf_data_input_mod,                                              &
-           ONLY:  netcdf_data_input_lsf  
-
        IMPLICIT NONE
 
@@ -967,107 +485,105 @@
        REAL(wp) ::  r_dummy           !<
 
-       IF ( nesting_offline )  THEN
-!
-!--       Allocate arrays for geostrophic wind components. Arrays will 
-!--       incorporate 2 time levels in order to interpolate in between. Please
-!--       note, forcing using geostrophic wind components is only required in 
-!--       case of cyclic boundary conditions.
-          IF ( bc_lr_cyc  .AND.  bc_ns_cyc )  THEN
-             ALLOCATE( nest_offl%ug(0:1,nzb:nzt+1) )
-             ALLOCATE( nest_offl%vg(0:1,nzb:nzt+1) )
+       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) )
+
+       p_surf = 0.0_wp; pt_surf = 0.0_wp; q_surf = 0.0_wp; qsws_surf = 0.0_wp
+       shf_surf = 0.0_wp; time_vert = 0.0_wp; td_lsa_lpt = 0.0_wp
+       td_lsa_q = 0.0_wp; td_sub_lpt = 0.0_wp; td_sub_q = 0.0_wp
+       time_surf = 0.0_wp; ug_vert = 0.0_wp; vg_vert = 0.0_wp
+       wsubs_vert = 0.0_wp
+
+!
+!--    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
+
+       ngp_sums_ls = (nz+2)*6
+
+       OPEN ( finput, FILE='LSF_DATA', STATUS='OLD', &
+              FORM='FORMATTED', IOSTAT=ierrn )
+
+       IF ( ierrn /= 0 )  THEN
+          message_string = 'file LSF_DATA does not exist'
+          CALL message( 'ls_forcing', 'PA0368', 1, 2, 0, 6, 0 )
+       ENDIF
+
+       ierrn = 0
+!
+!--    First three lines of LSF_DATA contain header
+       READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
+       READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
+       READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
+
+       IF ( ierrn /= 0 )  THEN
+          message_string = 'errors in file LSF_DATA'
+          CALL message( 'ls_forcing', 'PA0369', 1, 2, 0, 6, 0 )
+       ENDIF
+
+!
+!--    Surface values are read in
+       nt     = 0
+       ierrn = 0
+
+       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)
+
+          IF ( ierrn /= 0 )  THEN
+            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 )
           ENDIF
-!
-!--       Allocate arrays for reading boundary values. Arrays will incorporate 2 
-!--       time levels in order to interpolate in between. 
-          IF ( bc_dirichlet_l )  THEN
-             ALLOCATE( nest_offl%u_left(0:1,nzb+1:nzt,nys:nyn)  )
-             ALLOCATE( nest_offl%v_left(0:1,nzb+1:nzt,nysv:nyn) )
-             ALLOCATE( nest_offl%w_left(0:1,nzb+1:nzt-1,nys:nyn) )
-             IF ( humidity )      ALLOCATE( nest_offl%q_left(0:1,nzb+1:nzt,nys:nyn)  )
-             IF ( .NOT. neutral ) ALLOCATE( nest_offl%pt_left(0:1,nzb+1:nzt,nys:nyn) )
-          ENDIF
-          IF ( bc_dirichlet_r )  THEN
-             ALLOCATE( nest_offl%u_right(0:1,nzb+1:nzt,nys:nyn)  )
-             ALLOCATE( nest_offl%v_right(0:1,nzb+1:nzt,nysv:nyn) )
-             ALLOCATE( nest_offl%w_right(0:1,nzb+1:nzt-1,nys:nyn) )
-             IF ( humidity )      ALLOCATE( nest_offl%q_right(0:1,nzb+1:nzt,nys:nyn)  )
-             IF ( .NOT. neutral ) ALLOCATE( nest_offl%pt_right(0:1,nzb+1:nzt,nys:nyn) )
-          ENDIF
-          IF ( bc_dirichlet_n )  THEN
-             ALLOCATE( nest_offl%u_north(0:1,nzb+1:nzt,nxlu:nxr) )
-             ALLOCATE( nest_offl%v_north(0:1,nzb+1:nzt,nxl:nxr)  )
-             ALLOCATE( nest_offl%w_north(0:1,nzb+1:nzt-1,nxl:nxr) )
-             IF ( humidity )      ALLOCATE( nest_offl%q_north(0:1,nzb+1:nzt,nxl:nxr)  )
-             IF ( .NOT. neutral ) ALLOCATE( nest_offl%pt_north(0:1,nzb+1:nzt,nxl:nxr) )
-          ENDIF
-          IF ( bc_dirichlet_s )  THEN
-             ALLOCATE( nest_offl%u_south(0:1,nzb+1:nzt,nxlu:nxr) )
-             ALLOCATE( nest_offl%v_south(0:1,nzb+1:nzt,nxl:nxr)  )
-             ALLOCATE( nest_offl%w_south(0:1,nzb+1:nzt-1,nxl:nxr)    )
-             IF ( humidity )      ALLOCATE( nest_offl%q_south(0:1,nzb+1:nzt,nxl:nxr)  )
-             IF ( .NOT. neutral ) ALLOCATE( nest_offl%pt_south(0:1,nzb+1:nzt,nxl:nxr) )
-          ENDIF
-          
-          ALLOCATE( nest_offl%u_top(0:1,nys:nyn,nxlu:nxr) )
-          ALLOCATE( nest_offl%v_top(0:1,nysv:nyn,nxl:nxr) )
-          ALLOCATE( nest_offl%w_top(0:1,nys:nyn,nxl:nxr)  )
-          IF ( humidity )      ALLOCATE( nest_offl%q_top(0:1,nys:nyn,nxl:nxr)  )
-          IF ( .NOT. neutral ) ALLOCATE( nest_offl%pt_top(0:1,nys:nyn,nxl:nxr) )
-
-!
-!--       Read COSMO data at lateral and top boundaries
-          CALL netcdf_data_input_lsf
-!
-!--       Write COSMO data at lateral and top boundaries
-          CALL lsf_nesting_offline
-!
-!--       After 3D data is initialized, ensure mass conservation
-          CALL lsf_nesting_offline_mass_conservation
-!
-!--       Initialize surface pressure. Please note, time-dependent surface
-!--       pressure would require changes in anelastic approximation and 
-!--       treatment of fluxes. 
-!--       For the moment, comment this out! 
-!         surface_pressure = nest_offl%surface_pressure(0)
-
-       ELSE
-
-          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) )
-
-          p_surf = 0.0_wp; pt_surf = 0.0_wp; q_surf = 0.0_wp; qsws_surf = 0.0_wp
-          shf_surf = 0.0_wp; time_vert = 0.0_wp; td_lsa_lpt = 0.0_wp
-          td_lsa_q = 0.0_wp; td_sub_lpt = 0.0_wp; td_sub_q = 0.0_wp
-          time_surf = 0.0_wp; ug_vert = 0.0_wp; vg_vert = 0.0_wp
-          wsubs_vert = 0.0_wp
-
-!
-!--       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
-
-          ngp_sums_ls = (nz+2)*6
-
-          OPEN ( finput, FILE='LSF_DATA', STATUS='OLD', &
-                 FORM='FORMATTED', IOSTAT=ierrn )
-
-          IF ( ierrn /= 0 )  THEN
-             message_string = 'file LSF_DATA does not exist'
-             CALL message( 'ls_forcing', 'PA0368', 1, 2, 0, 6, 0 )
-          ENDIF
-
-          ierrn = 0
-!
-!--       First three lines of LSF_DATA contain header
-          READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
-          READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
-          READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
-
+       ENDDO
+
+       IF ( time_surf(1) > end_time )  THEN
+          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 )
+          lsf_surf = .FALSE.
+       ENDIF
+
+!
+!--    Go to the end of the list with surface variables
+       DO WHILE ( ierrn == 0 )
+          READ ( finput, *, IOSTAT = ierrn ) r_dummy
+       ENDDO
+
+!
+!--    Profiles of ug, vg and w_subs are read in (large scale forcing)
+
+       nt = 0
+       DO WHILE ( time_vert(nt) < end_time )
+          nt = nt + 1
+          hash = "#"
+          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 ) ) 
+             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'
+                CALL message( 'ls_forcing', 'PA0372', 1, 2, 0, 6, 0 )
+             ENDIF
+          ENDDO
+
+          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,       &
+                                           low_td_sub_q
           IF ( ierrn /= 0 )  THEN
              message_string = 'errors in file LSF_DATA'
@@ -1075,146 +591,80 @@
           ENDIF
 
-!
-!--       Surface values are read in
-          nt     = 0
-          ierrn = 0
-
-          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)
-
-             IF ( ierrn /= 0 )  THEN
-               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 )
+          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'
+             CALL message( 'ls_forcing', 'PA0369', 1, 2, 0, 6, 0 )
+          ENDIF
+
+
+          DO  k = nzb, nzt+1
+             IF ( highheight < zu(k) )  THEN
+                lowheight      = highheight
+                lowug_vert     = highug_vert
+                lowvg_vert     = highvg_vert
+                lowwsubs_vert  = highwsubs_vert
+                low_td_lsa_lpt = high_td_lsa_lpt
+                low_td_lsa_q   = high_td_lsa_q
+                low_td_sub_lpt = high_td_sub_lpt
+                low_td_sub_q   = high_td_sub_q
+
+                ierrn = 0
+                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.'
+                   CALL message( 'ls_forcing', 'PA0395', 1, 2, 0, 6, 0 )
+                ENDIF
+
              ENDIF
+
+!
+!--          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
+
           ENDDO
 
-          IF ( time_surf(1) > end_time )  THEN
-             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 )
-             lsf_surf = .FALSE.
-          ENDIF
-
-!
-!--       Go to the end of the list with surface variables
-          DO WHILE ( ierrn == 0 )
-             READ ( finput, *, IOSTAT = ierrn ) r_dummy
-          ENDDO
-
-!
-!--       Profiles of ug, vg and w_subs are read in (large scale forcing)
-
-          nt = 0
-          DO WHILE ( time_vert(nt) < end_time )
-             nt = nt + 1
-             hash = "#"
-             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 ) ) 
-                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'
-                   CALL message( 'ls_forcing', 'PA0372', 1, 2, 0, 6, 0 )
-                ENDIF
-             ENDDO
-
-             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,     &
-                                              low_td_sub_q
-             IF ( ierrn /= 0 )  THEN
-                message_string = 'errors in file LSF_DATA'
-                CALL message( 'ls_forcing', 'PA0369', 1, 2, 0, 6, 0 )
-             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
-         
-             IF ( ierrn /= 0 )  THEN
-                message_string = 'errors in file LSF_DATA'
-                CALL message( 'ls_forcing', 'PA0369', 1, 2, 0, 6, 0 )
-             ENDIF
-
-
-             DO  k = nzb, nzt+1
-                IF ( highheight < zu(k) )  THEN
-                   lowheight      = highheight
-                   lowug_vert     = highug_vert
-                   lowvg_vert     = highvg_vert
-                   lowwsubs_vert  = highwsubs_vert
-                   low_td_lsa_lpt = high_td_lsa_lpt
-                   low_td_lsa_q   = high_td_lsa_q
-                   low_td_sub_lpt = high_td_sub_lpt
-                   low_td_sub_q   = high_td_sub_q
-
-                   ierrn = 0
-                   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.'
-                      CALL message( 'ls_forcing', 'PA0395', 1, 2, 0, 6, 0 )
-                   ENDIF
-
-                ENDIF
-
-!
-!--             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
-
-             ENDDO
-
-          ENDDO 
-
-!
-!--       Large scale vertical velocity has to be zero at the surface
-          wsubs_vert(nzb,:) = 0.0_wp
+       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'
-             CALL message( 'ls_forcing', 'PA0373', 0, 0, 0, 6, 0 )
-             lsf_vert = .FALSE.
-          ENDIF
-
-          CLOSE( finput )
-
-       ENDIF
+       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'
+          CALL message( 'ls_forcing', 'PA0373', 0, 0, 0, 6, 0 )
+          lsf_vert = .FALSE.
+       ENDIF
+
+       CLOSE( finput )
 
     END SUBROUTINE lsf_init
