Index: palm/trunk/SOURCE/exchange_horiz_2d.f90
===================================================================
--- palm/trunk/SOURCE/exchange_horiz_2d.f90	(revision 484)
+++ palm/trunk/SOURCE/exchange_horiz_2d.f90	(revision 667)
@@ -4,5 +4,6 @@
 ! Current revisions:
 ! -----------------
-! 
+! Dynamic exchange of ghost points with nbgp, which depends on the advection
+! scheme. Exchange between left and right PEs is now done with MPI-vectors.
 !
 ! Former revisions:
@@ -37,5 +38,6 @@
     IMPLICIT NONE
 
-    REAL ::  ar(nys-1:nyn+1,nxl-1:nxr+1)
+    REAL ::  ar(nysg:nyng,nxlg:nxrg)
+    INTEGER :: i
 
 
@@ -51,17 +53,18 @@
 !--    One-dimensional decomposition along y, boundary values can be exchanged
 !--    within the PE memory
-       ar(nys:nyn,nxl-1) = ar(nys:nyn,nxr)
-       ar(nys:nyn,nxr+1) = ar(nys:nyn,nxl)
+       ar(:,nxl-nbgp:nxl-1) = ar(:,nxr-nbgp+1:nxr)
+       ar(:,nxr+1:nxr+nbgp) = ar(:,nxl:nxl+nbgp-1)
 
     ELSE
 !
 !--    Send left boundary, receive right one
-       CALL MPI_SENDRECV( ar(nys,nxl),   ngp_y, MPI_REAL, pleft,  0, &
-                          ar(nys,nxr+1), ngp_y, MPI_REAL, pright, 0, &
+
+       CALL MPI_SENDRECV( ar(nysg,nxl), 1, type_y, pleft,  0, &
+                          ar(nysg,nxr+1), 1, type_y, pright, 0, &
                           comm2d, status, ierr )
 !
 !--    Send right boundary, receive left one
-       CALL MPI_SENDRECV( ar(nys,nxr),   ngp_y, MPI_REAL, pright,  1, &
-                          ar(nys,nxl-1), ngp_y, MPI_REAL, pleft,   1, &
+       CALL MPI_SENDRECV( ar(nysg,nxr+1-nbgp), 1, type_y, pright,  1, &
+                          ar(nysg,nxlg), 1, type_y, pleft,   1, &
                           comm2d, status, ierr )
     ENDIF
@@ -71,18 +74,20 @@
 !--    One-dimensional decomposition along x, boundary values can be exchanged
 !--    within the PE memory
-       ar(nys-1,:) = ar(nyn,:)
-       ar(nyn+1,:) = ar(nys,:)
+       ar(nys-nbgp:nys-1,:) = ar(nyn-nbgp+1:nyn,:)
+       ar(nyn+1:nyn+nbgp,:) = ar(nys:nys+nbgp-1,:)
 
     ELSE
 !
 !--    Send front boundary, receive rear one
-       CALL MPI_SENDRECV( ar(nys,nxl-1),   1, type_x, psouth, 0, &
-                          ar(nyn+1,nxl-1), 1, type_x, pnorth, 0, &
+
+       CALL MPI_SENDRECV( ar(nys,nxlg), 1, type_x, psouth, 0, &        !replace number of sended elements from 
+                          ar(nyn+1,nxlg), 1, type_x, pnorth, 0, &      ! nbgp to 1
                           comm2d, status, ierr )
 !
 !--    Send rear boundary, receive front one
-       CALL MPI_SENDRECV( ar(nyn,nxl-1),   1, type_x, pnorth, 1, &
-                          ar(nys-1,nxl-1), 1, type_x, psouth, 1, &
-                          comm2d, status, ierr )
+       CALL MPI_SENDRECV( ar(nyn+1-nbgp,nxlg), 1, type_x, pnorth, 1, &
+                          ar(nysg,nxlg), 1, type_x, psouth, 1, &
+                          comm2d, status, ierr )
+
     ENDIF
 
@@ -92,12 +97,13 @@
 !-- Lateral boundary conditions in the non-parallel case
     IF ( bc_lr == 'cyclic' )  THEN
-       ar(nys:nyn,nxl-1) = ar(nys:nyn,nxr)
-       ar(nys:nyn,nxr+1) = ar(nys:nyn,nxl)
+       ar(:,nxl-nbgp:nxl-1) = ar(:,nxr-nbgp+1:nxr)
+       ar(:,nxr+1:nxr+nbgp) = ar(:,nxl:nxl+nbgp-1)
     ENDIF
 
     IF ( bc_ns == 'cyclic' )  THEN
-       ar(nys-1,:) = ar(nyn,:)
-       ar(nyn+1,:) = ar(nys,:)
-    ENDIF
+       ar(nys-nbgp:nys-1,:) = ar(nyn-nbgp+1:nyn,:)
+       ar(nyn+1:nyn+nbgp,:) = ar(nys:nys+nbgp-1,:)
+    ENDIF
+
 
 #endif
@@ -106,9 +112,24 @@
 !-- Neumann-conditions at inflow/outflow in case of non-cyclic boundary
 !-- conditions
-    IF ( inflow_l .OR. outflow_l )  ar(:,nxl-1) = ar(:,nxl)
-    IF ( inflow_r .OR. outflow_r )  ar(:,nxr+1) = ar(:,nxr)
-    IF ( inflow_s .OR. outflow_s )  ar(nys-1,:) = ar(nys,:)
-    IF ( inflow_n .OR. outflow_n )  ar(nyn+1,:) = ar(nyn,:)
-
+    IF ( inflow_l .OR. outflow_l )  THEN
+       DO i=nbgp, 1, -1
+         ar(:,nxl-i) = ar(:,nxl)
+       END DO
+    END IF
+    IF ( inflow_r .OR. outflow_r )  THEN 
+       DO i=1, nbgp
+          ar(:,nxr+i) = ar(:,nxr)
+       END DO
+    END IF
+    IF ( inflow_s .OR. outflow_s )  THEN
+       DO i=nbgp, 1, -1
+         ar(nys-i,:) = ar(nys,:)
+       END DO
+    END IF
+    IF ( inflow_n .OR. outflow_n )  THEN
+       DO i=1, nbgp
+         ar(nyn+i,:) = ar(nyn,:)
+       END DO
+    END IF
     CALL cpu_log( log_point_s(13), 'exchange_horiz_2d', 'stop' )
 
@@ -134,5 +155,7 @@
     IMPLICIT NONE
 
-    INTEGER ::  ar(nys-1:nyn+1,nxl-1:nxr+1)
+    REAL ::  ar(nysg:nyng,nxlg:nxrg)
+    INTEGER :: i
+
 
 
@@ -154,12 +177,13 @@
 !
 !--    Send left boundary, receive right one
-       CALL MPI_SENDRECV( ar(nys,nxl),   ngp_y, MPI_INTEGER, pleft,  0, &
-                          ar(nys,nxr+1), ngp_y, MPI_INTEGER, pright, 0, &
+       CALL MPI_SENDRECV( ar(nysg,nxl), 1, type_y_int, pleft,  0, &
+                          ar(nysg,nxr+1), 1, type_y_int, pright, 0, &
                           comm2d, status, ierr )
 !
 !--    Send right boundary, receive left one
-       CALL MPI_SENDRECV( ar(nys,nxr),   ngp_y, MPI_INTEGER, pright,  1, &
-                          ar(nys,nxl-1), ngp_y, MPI_INTEGER, pleft,   1, &
-                          comm2d, status, ierr )
+       CALL MPI_SENDRECV( ar(nysg,nxr+1-nbgp), 1, type_y_int, pright,  1, &
+                          ar(nysg,nxlg), 1, type_y_int, pleft,   1, &
+                          comm2d, status, ierr )
+
     ENDIF
 
@@ -168,18 +192,21 @@
 !--    One-dimensional decomposition along x, boundary values can be exchanged
 !--    within the PE memory
-       ar(nys-1,:) = ar(nyn,:)
-       ar(nyn+1,:) = ar(nys,:)
+       ar(nysg:nys-1,:) = ar(nyn+1-nbgp:nyn,:)
+       ar(nyn+1:nyng,:) = ar(nys:nys-1+nbgp,:)
+
 
     ELSE
 !
 !--    Send front boundary, receive rear one
-       CALL MPI_SENDRECV( ar(nys,nxl-1),   1, type_x_int, psouth, 0, &
-                          ar(nyn+1,nxl-1), 1, type_x_int, pnorth, 0, &
-                          comm2d, status, ierr )
+       CALL MPI_SENDRECV( ar(nys,nxlg),1, type_x_int, psouth, 0, &
+                          ar(nyn+1,nxlg),1, type_x_int, pnorth, 0, &
+                          comm2d, status, ierr )
+
 !
 !--    Send rear boundary, receive front one
-       CALL MPI_SENDRECV( ar(nyn,nxl-1),   1, type_x_int, pnorth, 1, &
-                          ar(nys-1,nxl-1), 1, type_x_int, psouth, 1, &
-                          comm2d, status, ierr )
+       CALL MPI_SENDRECV( ar(nyn+1-nbgp,nxlg), nbgp, type_x_int, pnorth, 1, &
+                          ar(nysg,nxlg), nbgp, type_x_int, psouth, 1, &
+                          comm2d, status, ierr )
+
     ENDIF
 
@@ -194,6 +221,6 @@
 
     IF ( bc_ns == 'cyclic' )  THEN
-       ar(nys-1,:) = ar(nyn,:)
-       ar(nyn+1,:) = ar(nys,:)
+       ar(nysg:nys-1,:) = ar(nyn+1-nbgp:nyn,:)
+       ar(nyn+1:nyng,:) = ar(nys:nys-1+nbgp,:)
     ENDIF
 
