Index: palm/trunk/SOURCE/large_scale_forcing_nudging_mod.f90
===================================================================
--- palm/trunk/SOURCE/large_scale_forcing_nudging_mod.f90	(revision 2718)
+++ palm/trunk/SOURCE/large_scale_forcing_nudging_mod.f90	(revision 2938)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Further improvements for nesting in larger-scale model
+! 
+! 2863 2018-03-08 11:36:25Z suehring
 ! Corrected "Former revisions" section
 ! 
@@ -210,5 +213,5 @@
        ENDIF
 !
-!--       Top boundary
+!--    Top boundary
        k = nzt
        DO  i = nxl, nxr
@@ -235,4 +238,7 @@
           ENDDO
        ENDDO
+
+write(9,*) "w correction", w_correct
+flush(9)
 
     END SUBROUTINE forcing_bc_mass_conservation
@@ -581,50 +587,91 @@
 !--    identical to the Inifor grid. At the top boundary an extrapolation is 
 !--    not possible. 
-       IF ( ANY( zu(1:nzt+1) /= force%zu_atmos(1:force%nzu) ) )  THEN
-          DO  i = nxlu, nxr
-             DO  j = nys, nyn
-                u(nzt+1,j,i) = force%u_top(0,j,i) + ddt_lsf * t_ref *          &
-                           ( force%u_top(1,j,i) - force%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) = force%v_top(0,j,i) + ddt_lsf * t_ref *          &
-                           ( force%v_top(1,j,i) - force%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 = nxlu, nxr
+          DO  j = nys, nyn
+             u(nzt+1,j,i) = force%u_top(0,j,i) + ddt_lsf * t_ref *             &
+                        ( force%u_top(1,j,i) - force%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) = force%v_top(0,j,i) + ddt_lsf * t_ref *             &
+                        ( force%v_top(1,j,i) - force%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) = force%w_top(0,j,i) + ddt_lsf * t_ref *         &
+                        ( force%w_top(1,j,i) - force%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
-                w(nzt:nzt+1,j,i) = force%w_top(0,j,i) + ddt_lsf * t_ref *      &
-                           ( force%w_top(1,j,i) - force%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) = force%pt_top(0,j,i) + ddt_lsf * t_ref *     &
-                           ( force%pt_top(1,j,i) - force%pt_top(0,j,i) )
-                ENDDO
-             ENDDO
-          ENDIF
-
-          IF ( humidity )  THEN
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   q(nzt+1,j,i) = force%q_top(0,j,i) + ddt_lsf * t_ref *       &
-                           ( force%q_top(1,j,i) - force%q_top(0,j,i) )
-                ENDDO
-             ENDDO
-          ENDIF
+                pt(nzt+1,j,i) = force%pt_top(0,j,i) + ddt_lsf * t_ref *        &
+                        ( force%pt_top(1,j,i) - force%pt_top(0,j,i) )
+             ENDDO
+          ENDDO
+       ENDIF
+
+       IF ( humidity )  THEN
+          DO  i = nxl, nxr
+             DO  j = nys, nyn
+                q(nzt+1,j,i) = force%q_top(0,j,i) + ddt_lsf * t_ref *          &
+                        ( force%q_top(1,j,i) - force%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 ( force_bound_l  .AND.  force_bound_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 ( force_bound_l  .AND.  force_bound_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 ( force_bound_r  .AND.  force_bound_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 ( force_bound_r  .AND.  force_bound_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
 !
@@ -941,4 +988,7 @@
     SUBROUTINE lsf_init
 
+       USE control_parameters,                                                 &
+           ONLY:  bc_lr_cyc, bc_ns_cyc
+
        USE netcdf_data_input_mod,                                              &
            ONLY:  netcdf_data_input_lsf  
@@ -975,4 +1025,13 @@
 
        IF ( forcing )  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( force%ug(0:1,nzb:nzt+1) )
+             ALLOCATE( force%vg(0:1,nzb:nzt+1) )
+          ENDIF
 !
 !--       Allocate arrays for reading boundary values. Arrays will incorporate 2 
