Index: /palm/trunk/SOURCE/exchange_horiz.f90
===================================================================
--- /palm/trunk/SOURCE/exchange_horiz.f90	(revision 1676)
+++ /palm/trunk/SOURCE/exchange_horiz.f90	(revision 1677)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Added new routine for exchange of three-dimensional integer arrays
 !
 ! Former revisions:
@@ -285,2 +285,95 @@
 #endif
  END SUBROUTINE exchange_horiz
+
+
+ SUBROUTINE exchange_horiz_int( ar, nbgp_local)
+
+    USE control_parameters,                                                    &
+        ONLY:  bc_lr, bc_lr_cyc, bc_ns, bc_ns_cyc
+                       
+    USE indices,                                                               &
+        ONLY:  nxl, nxr, nyn, nys, nzb, nzt
+        
+    USE kinds
+    
+    USE pegrid
+
+    IMPLICIT NONE
+
+
+    INTEGER(iwp) ::  nbgp_local  !: number of ghost points
+    
+    INTEGER(iwp), DIMENSION(nzb:nzt+1,nys-nbgp_local:nyn+nbgp_local,           &
+                        nxl-nbgp_local:nxr+nbgp_local) ::  ar  !: treated array
+
+#if ! defined( __check )
+
+#if defined( __parallel )
+    IF ( pdims(1) == 1 )  THEN
+!
+!--    One-dimensional decomposition along y, boundary values can be exchanged
+!--    within the PE memory
+       IF ( bc_lr_cyc )  THEN
+          ar(:,:,nxl-nbgp_local:nxl-1) = ar(:,:,nxr-nbgp_local+1:nxr)
+          ar(:,:,nxr+1:nxr+nbgp_local) = ar(:,:,nxl:nxl+nbgp_local-1)
+       ENDIF
+    ELSE
+!
+!--    Send left boundary, receive right one (synchronous)
+       CALL MPI_SENDRECV(                                                      &
+           ar(nzb,nys-nbgp_local,nxl),   1, type_yz_int, pleft,  0,            &
+           ar(nzb,nys-nbgp_local,nxr+1), 1, type_yz_int, pright, 0,            &
+           comm2d, status, ierr )
+!
+!--    Send right boundary, receive left one (synchronous)
+       CALL MPI_SENDRECV(                                                      &
+           ar(nzb,nys-nbgp_local,nxr+1-nbgp_local), 1, type_yz_int, pright, 1, &
+           ar(nzb,nys-nbgp_local,nxl-nbgp_local),   1, type_yz_int, pleft,  1, &
+           comm2d, status, ierr )
+    ENDIF
+
+
+    IF ( pdims(2) == 1 )  THEN
+!
+!--    One-dimensional decomposition along x, boundary values can be exchanged
+!--    within the PE memory
+       IF ( bc_ns_cyc )  THEN
+          ar(:,nys-nbgp_local:nys-1,:) = ar(:,nyn-nbgp_local+1:nyn,:)
+          ar(:,nyn+1:nyn+nbgp_local,:) = ar(:,nys:nys+nbgp_local-1,:)
+       ENDIF
+
+    ELSE
+
+!
+!--    Send front boundary, receive rear one (synchronous)
+       CALL MPI_SENDRECV(                                                      &
+           ar(nzb,nys,nxl-nbgp_local),   1, type_xz_int, psouth, 0,            &
+           ar(nzb,nyn+1,nxl-nbgp_local), 1, type_xz_int, pnorth, 0,            &
+           comm2d, status, ierr )
+!
+!--    Send rear boundary, receive front one (synchronous)
+       CALL MPI_SENDRECV( ar(nzb,nyn-nbgp_local+1,nxl-nbgp_local), 1,          &
+                          type_xz_int, pnorth, 1,                              &
+                          ar(nzb,nys-nbgp_local,nxl-nbgp_local),   1,          &
+                          type_xz_int, psouth, 1,                              &
+                          comm2d, status, ierr )
+
+    ENDIF
+
+#else
+
+    IF ( bc_lr == 'cyclic' )  THEN
+       ar(:,:,nxl-nbgp_local:nxl-1) = ar(:,:,nxr-nbgp_local+1:nxr)
+       ar(:,:,nxr+1:nxr+nbgp_local) = ar(:,:,nxl:nxl+nbgp_local-1)
+    ENDIF
+
+    IF ( bc_ns == 'cyclic' )  THEN
+       ar(:,nys-nbgp_local:nys-1,:) = ar(:,nyn-nbgp_local+1:nyn,:)
+       ar(:,nyn+1:nyn+nbgp_local,:) = ar(:,nys:nys+nbgp_local-1,:)
+    ENDIF
+
+#endif
+#endif
+
+
+ END SUBROUTINE exchange_horiz_int
Index: /palm/trunk/SOURCE/init_grid.f90
===================================================================
--- /palm/trunk/SOURCE/init_grid.f90	(revision 1676)
+++ /palm/trunk/SOURCE/init_grid.f90	(revision 1677)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Bugfix: Ghost points are included in wall_flags_0 and wall_flags_00
 ! 
 ! Former revisions:
@@ -717,5 +717,5 @@
 !-- In case of non-cyclic lateral boundaries, the order of the advection
 !-- scheme have to be reduced up to nzt (required at the lateral boundaries).
-    nzb_max = MAXVAL( nzb_local )
+    nzb_max = MAXVAL( nzb_local ) + 1
     IF ( inflow_l .OR. outflow_l .OR. inflow_r .OR. outflow_r .OR.             &
          inflow_n .OR. outflow_n .OR. inflow_s .OR. outflow_s )  THEN
@@ -1188,6 +1188,6 @@
 !
 !-- Allocate flags needed for masking walls.
-    ALLOCATE( wall_flags_0(nzb:nzt,nys:nyn,nxl:nxr), &
-              wall_flags_00(nzb:nzt,nys:nyn,nxl:nxr) )
+    ALLOCATE( wall_flags_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                     &
+              wall_flags_00(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
     wall_flags_0  = 0
     wall_flags_00 = 0
@@ -1453,5 +1453,5 @@
 !
 !--             w component - z-direction
-!--             WS1 (33), WS3 (34), WS5 (35)
+!--             WS1 (33), WS3 (34)IF ( inflow_l .OR. outflow_l )  THEN, WS5 (35)
                 flag_set = .FALSE.
                 IF ( k == nzb_w_inner(j,i) .OR. k == nzb_w_inner(j,i) + 1      &
@@ -1479,4 +1479,37 @@
 
 !
+!-- Exchange 3D integer wall_flags.
+    IF ( momentum_advec == 'ws-scheme' .OR. scalar_advec == 'ws-scheme'     &
+    .OR. scalar_advec == 'ws-scheme-mono' )  THEN  
+!
+!--    Exchange ghost points for advection flags
+       CALL exchange_horiz_int( wall_flags_0,  nbgp )
+       CALL exchange_horiz_int( wall_flags_00, nbgp )
+!
+!--    Set boundary flags at inflow and outflow boundary in case of 
+!--    non-cyclic boundary conditions.
+       IF ( inflow_l .OR. outflow_l )  THEN
+          wall_flags_0(:,:,nxl-1)  = wall_flags_0(:,:,nxl)
+          wall_flags_00(:,:,nxl-1) = wall_flags_00(:,:,nxl)
+       ENDIF
+
+       IF ( inflow_r .OR. outflow_r )  THEN
+          wall_flags_0(:,:,nxr+1)  = wall_flags_0(:,:,nxr)
+          wall_flags_00(:,:,nxr+1) = wall_flags_00(:,:,nxr)
+       ENDIF
+
+       IF ( inflow_n .OR. outflow_n )  THEN
+          wall_flags_0(:,nyn+1,:)  = wall_flags_0(:,nyn,:)
+          wall_flags_00(:,nyn+1,:) = wall_flags_00(:,nyn,:)
+       ENDIF
+
+       IF ( inflow_s .OR. outflow_s )  THEN
+          wall_flags_0(:,nys-1,:)  = wall_flags_0(:,nys,:)
+          wall_flags_00(:,nys-1,:) = wall_flags_00(:,nys,:)
+       ENDIF
+
+    ENDIF
+
+!
 !-- In case of topography: limit near-wall mixing length l_wall further:
 !-- Go through all points of the subdomain one by one and look for the closest
Index: /palm/trunk/SOURCE/init_pegrid.f90
===================================================================
--- /palm/trunk/SOURCE/init_pegrid.f90	(revision 1676)
+++ /palm/trunk/SOURCE/init_pegrid.f90	(revision 1677)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! New MPI-data types for exchange of 3D integer arrays.
 !
 ! Former revisions:
@@ -1035,4 +1035,16 @@
 
     ENDIF
+!
+!-- Define data types for exchange of 3D Integer arrays.
+    ngp_yz_int = (nzt - nzb + 2) * (nyn - nys + 1 + 2 * nbgp)
+
+    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp*(nzt-nzb+2), ngp_yz_int, &
+                          MPI_INTEGER, type_xz_int, ierr )
+    CALL MPI_TYPE_COMMIT( type_xz_int, ierr )
+
+    CALL MPI_TYPE_VECTOR( nbgp, ngp_yz_int, ngp_yz_int, MPI_INTEGER, type_yz_int, &
+                          ierr )
+    CALL MPI_TYPE_COMMIT( type_yz_int, ierr )
+
 #endif
 
Index: /palm/trunk/SOURCE/modules.f90
===================================================================
--- /palm/trunk/SOURCE/modules.f90	(revision 1676)
+++ /palm/trunk/SOURCE/modules.f90	(revision 1677)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! +ngp_yz_int, type_xz_int, type_yz_int
 ! 
 ! Former revisions:
@@ -1315,5 +1315,5 @@
 #endif
 
-
+    INTEGER(iwp) :: ngp_yz_int, type_xz_int, type_yz_int
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  ngp_xz, ngp_yz, type_xz, type_yz
 
