Index: palm/trunk/SOURCE/pmc_particle_interface.f90
===================================================================
--- palm/trunk/SOURCE/pmc_particle_interface.f90	(revision 3948)
+++ palm/trunk/SOURCE/pmc_particle_interface.f90	(revision 4017)
@@ -90,10 +90,7 @@
        ONLY:  prt_count, particles, grid_particles,                            &
               particle_type, number_of_particles, zero_particle,               &
-              ibc_par_t, ibc_par_lr, ibc_par_ns, alloc_factor
-
-   USE lpm_pack_and_sort_mod
-
-   USE lpm_exchange_horiz_mod,                                                 &
-       ONLY: realloc_particles_array
+              ibc_par_t, ibc_par_lr, ibc_par_ns, alloc_factor, min_nr_particle
+
+!    USE lpm_pack_and_sort_mod
 
 #if defined( __parallel )
@@ -956,5 +953,5 @@
                    prt_count(kp,jp,ip) = prt_count(kp,jp,ip) + 1
                    IF ( prt_count(kp,jp,ip) > SIZE( grid_particles(kp,jp,ip)%particles ) ) THEN
-                      CALL realloc_particles_array( ip, jp, kp )
+                      CALL pmc_realloc_particles_array( ip, jp, kp )
                    ENDIF
                    coarse_particles(jc,ic)%parent_particles(n)%x = xc                   ! Adjust coordinates to child grid
@@ -1082,5 +1079,5 @@
 !- Pack particles (eliminate those marked for deletion),
 !- determine new number of particles
-   CALL lpm_sort_in_subboxes
+!    CALL lpm_sort_in_subboxes
 
 #endif
@@ -1137,5 +1134,5 @@
                 prt_count(k,j,i) = prt_count(k,j,i) + 1
                 IF ( prt_count(k,j,i) > SIZE( grid_particles(k,j,i)%particles ) ) THEN
-                   CALL realloc_particles_array( i, j, k )
+                   CALL pmc_realloc_particles_array( i, j, k )
                 ENDIF
                 grid_particles(k,j,i)%particles(prt_count(k,j,i)) = particle_in_win(pindex)
@@ -1155,5 +1152,63 @@
 #endif
  END SUBROUTINE p_copy_particle_to_org_grid
-
+ 
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> If the allocated memory for the particle array do not suffice to add arriving
+!> particles from neighbour grid cells, this subrouting reallocates the 
+!> particle array to assure enough memory is available. 
+!------------------------------------------------------------------------------!
+ SUBROUTINE pmc_realloc_particles_array ( i, j, k, size_in )
+
+    INTEGER(iwp), INTENT(IN)                       ::  i              !<
+    INTEGER(iwp), INTENT(IN)                       ::  j              !<
+    INTEGER(iwp), INTENT(IN)                       ::  k              !<
+    INTEGER(iwp), INTENT(IN), OPTIONAL             ::  size_in        !<
+
+    INTEGER(iwp)                                   ::  old_size        !<
+    INTEGER(iwp)                                   ::  new_size        !<
+    TYPE(particle_type), DIMENSION(:), ALLOCATABLE ::  tmp_particles_d !<
+    TYPE(particle_type), DIMENSION(500)            ::  tmp_particles_s !<
+
+    old_size = SIZE(grid_particles(k,j,i)%particles)
+
+    IF ( PRESENT(size_in) )   THEN
+       new_size = size_in
+    ELSE
+       new_size = old_size * ( 1.0_wp + alloc_factor / 100.0_wp )
+    ENDIF
+
+    new_size = MAX( new_size, min_nr_particle, old_size + 1 )
+
+    IF ( old_size <= 500 )  THEN
+
+       tmp_particles_s(1:old_size) = grid_particles(k,j,i)%particles(1:old_size)
+
+       DEALLOCATE(grid_particles(k,j,i)%particles)
+       ALLOCATE(grid_particles(k,j,i)%particles(new_size))
+
+       grid_particles(k,j,i)%particles(1:old_size)          = tmp_particles_s(1:old_size)
+       grid_particles(k,j,i)%particles(old_size+1:new_size) = zero_particle
+
+    ELSE
+
+       ALLOCATE(tmp_particles_d(new_size))
+       tmp_particles_d(1:old_size) = grid_particles(k,j,i)%particles
+
+       DEALLOCATE(grid_particles(k,j,i)%particles)
+       ALLOCATE(grid_particles(k,j,i)%particles(new_size))
+
+       grid_particles(k,j,i)%particles(1:old_size)          = tmp_particles_d(1:old_size)
+       grid_particles(k,j,i)%particles(old_size+1:new_size) = zero_particle
+
+       DEALLOCATE(tmp_particles_d)
+
+    ENDIF
+    particles => grid_particles(k,j,i)%particles(1:new_size)
+
+    RETURN
+    
+ END SUBROUTINE pmc_realloc_particles_array
 
 END MODULE pmc_particle_interface
