Index: /palm/trunk/SOURCE/poismg_fast_mod.f90
===================================================================
--- /palm/trunk/SOURCE/poismg_fast_mod.f90	(revision 1903)
+++ /palm/trunk/SOURCE/poismg_fast_mod.f90	(revision 1904)
@@ -19,5 +19,6 @@
 ! Current revisions:
 ! -----------------
-!
+! Bugfix: enable special_exchange_horiz only for finer grid levels.
+! Some formatting adjustments and variable descriptions.
 ! 
 ! Former revisions:
@@ -1791,6 +1792,6 @@
            ONLY:  bc_lr_cyc, bc_ns_cyc, grid_level, ibc_p_b, ibc_p_t,          &
                   inflow_l, inflow_n, inflow_r, inflow_s, maximum_grid_level,  &
-                  outflow_l, outflow_n, outflow_r, outflow_s,                  &
-                  synchronous_exchange
+                  mg_switch_to_pe0_level, outflow_l, outflow_n, outflow_r,     &
+                  outflow_s, synchronous_exchange
 
        USE indices,                                                            &
@@ -1802,23 +1803,28 @@
        REAL(wp), DIMENSION(nzb:nzt_mg(grid_level)+1,                           &
                            nys_mg(grid_level)-1:nyn_mg(grid_level)+1,          &
-                           nxl_mg(grid_level)-1:nxr_mg(grid_level)+1) ::  p_mg  !<
-
-       INTEGER(iwp), intent(IN) ::  color  !<
+                           nxl_mg(grid_level)-1:nxr_mg(grid_level)+1) ::       &
+                                    p_mg   !< treated array
+
+       INTEGER(iwp), intent(IN) ::  color  !< flag for grid point type (red or black)
 !
 !--    Local variables
-       INTEGER(iwp) ::  i,i1,i2  !<
-       INTEGER(iwp) ::  j,j1,j2  !<
-       INTEGER(iwp) ::  k        !<
-       INTEGER(iwp) ::  l        !<
-       INTEGER(iwp) ::  jys      !<
-       INTEGER(iwp) ::  jyn      !<
-       INTEGER(iwp) ::  ixl      !<
-       INTEGER(iwp) ::  ixr      !<
-       logical      ::  sendrecv_in_background_save  !<
-       logical      ::  synchronous_exchange_save    !<
-
-       REAL(wp), DIMENSION(nzb:nzt_mg(grid_level-1)+1,                         &
-                           nys_mg(grid_level-1)-1:nyn_mg(grid_level-1)+1,      &
-                           nxl_mg(grid_level-1)-1:nxr_mg(grid_level-1)+1) ::  temp  !<
+       INTEGER(iwp) ::  i        !< index variable along x
+       INTEGER(iwp) ::  i1       !< index variable along x on coarse level 
+       INTEGER(iwp) ::  i2       !< index variable along x on coarse level 
+
+       INTEGER(iwp) ::  j        !< index variable along y
+       INTEGER(iwp) ::  j1       !< index variable along y on coarse level 
+       INTEGER(iwp) ::  j2       !< index variable along y on coarse level 
+       INTEGER(iwp) ::  k        !< index variable along z
+       INTEGER(iwp) ::  l        !< short for grid level
+       INTEGER(iwp) ::  jys      !< index for lower local PE boundary along y
+       INTEGER(iwp) ::  jyn      !< index for upper local PE boundary along y
+       INTEGER(iwp) ::  ixl      !< index for lower local PE boundary along x
+       INTEGER(iwp) ::  ixr      !< index for upper local PE boundary along x 
+
+       LOGICAL      ::  sendrecv_in_background_save  !< dummy to reset sendrecv_in_background to prescribed value
+       LOGICAL      ::  synchronous_exchange_save    !< dummy to reset synchronous_exchange to prescribed value
+
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  temp  !< temporary array on next coarser grid level
 
 #if defined ( __parallel )
@@ -1832,12 +1838,18 @@
        ind_even_odd = even_odd_level(grid_level)
 
-       jys = nys_mg(grid_level-1)
-       jyn = nyn_mg(grid_level-1)
-       ixl = nxl_mg(grid_level-1)
-       ixr = nxr_mg(grid_level-1)
-
-!
-!--    Restricted transfer only on finer levels with enough data
-       IF ( ngp_xz(grid_level) >= 900 .OR. ngp_yz(grid_level) >= 900 )  THEN
+!
+!--    Restricted transfer only on finer levels with enough data.
+!--    Restricted transfer is not possible for levels smaller or equal to 
+!--    'switch to PE0 levels', since array bounds does not fit. Moreover, 
+!--    it is not possible for the coarsest grid level, since the dimensions
+!--    of temp are not defined. For such cases, normal exchange_horiz is called.
+       IF ( l > 1 .AND. l > mg_switch_to_pe0_level + 1 .AND.                   &
+            ( ngp_xz(grid_level) >= 900 .OR. ngp_yz(grid_level) >= 900 ) )  THEN
+
+          jys = nys_mg(grid_level-1)
+          jyn = nyn_mg(grid_level-1)
+          ixl = nxl_mg(grid_level-1)
+          ixr = nxr_mg(grid_level-1)
+          ALLOCATE( temp(nzb:nzt_mg(l-1)+1,jys-1:jyn+1,ixl-1:ixr+1) )
 !
 !--       Handling the even k Values
@@ -2305,4 +2317,6 @@
           ENDDO
 
+          DEALLOCATE( temp )
+
        ELSE
 
