Index: palm/trunk/SOURCE/lpm.f90
===================================================================
--- palm/trunk/SOURCE/lpm.f90	(revision 2605)
+++ palm/trunk/SOURCE/lpm.f90	(revision 2606)
@@ -25,4 +25,11 @@
 ! -----------------
 ! $Id$
+! Changed particle box locations: center of particle box now coincides 
+! with scalar grid point of same index.
+! Renamed module and subroutines: lpm_pack_arrays_mod -> lpm_pack_and_sort_mod
+! lpm_pack_all_arrays -> lpm_sort_in_subboxes, lpm_pack_arrays -> lpm_pack
+! lpm_sort -> lpm_sort_timeloop_done
+! 
+! 2418 2017-09-06 15:24:24Z suehring
 ! Major bugfixes in modeling SGS particle speeds (since revision 1359).
 ! Particle sorting added to distinguish between already completed and 
@@ -144,6 +151,6 @@
         ONLY: lpm_create_particle, PHASE_RELEASE
 
-    USE lpm_pack_arrays_mod,                                                   &
-        ONLY:  lpm_pack_all_arrays, lpm_sort
+    USE lpm_pack_and_sort_mod,                                                   &
+        ONLY:  lpm_sort_in_subboxes, lpm_sort_timeloop_done
 
     USE particle_attributes,                                                   &
@@ -281,5 +288,5 @@
 !--    according to their sub-boxes. 
        IF ( .NOT. first_loop_stride  .AND.  use_sgs_for_particles )            &
-          CALL lpm_sort
+          CALL lpm_sort_timeloop_done
 
        DO  i = nxl, nxr
@@ -408,5 +415,5 @@
 !--    Pack particles (eliminate those marked for deletion),
 !--    determine new number of particles
-       CALL lpm_pack_all_arrays
+       CALL lpm_sort_in_subboxes
 !
 !--    Initialize variables for the next (sub-) timestep, i.e., for marking 
Index: palm/trunk/SOURCE/lpm_advec.f90
===================================================================
--- palm/trunk/SOURCE/lpm_advec.f90	(revision 2605)
+++ palm/trunk/SOURCE/lpm_advec.f90	(revision 2606)
@@ -25,4 +25,11 @@
 ! -----------------
 ! $Id$
+! Changed particle box locations: center of particle box now coincides 
+! with scalar grid point of same index.
+! Renamed module and subroutines: lpm_pack_arrays_mod -> lpm_pack_and_sort_mod
+! lpm_pack_all_arrays -> lpm_sort_in_subboxes, lpm_pack_arrays -> lpm_pack
+! lpm_sort -> lpm_sort_timeloop_done 
+! 
+! 2417 2017-09-06 15:22:27Z suehring
 ! Particle loops adapted for sub-box structure, i.e. for each sub-box the 
 ! particle loop runs from start_index up to end_index instead from 1 to 
@@ -273,10 +280,10 @@
 
     DO  nb = 0, 7
-       
+!
+!--    Interpolate u velocity-component       
        i = ip
        j = jp + block_offset(nb)%j_off
        k = kp + block_offset(nb)%k_off
-!
-!--    Interpolate u velocity-component
+
        DO  n = start_index(nb), end_index(nb)
 !
@@ -289,6 +296,6 @@
 !--       First, check if particle is located below first vertical grid level 
 !--       above topography (Prandtl-layer height)
-          ilog = ( particles(n)%x + 0.5_wp * dx ) * ddx
-          jlog = ( particles(n)%y + 0.5_wp * dy ) * ddy
+          ilog = particles(n)%x * ddx
+          jlog = particles(n)%y * ddy
 !
 !--       Determine vertical index of topography top
@@ -378,14 +385,14 @@
 
        ENDDO
-
+!
+!--    Same procedure for interpolation of the v velocity-component 
        i = ip + block_offset(nb)%i_off
        j = jp
        k = kp + block_offset(nb)%k_off
-!
-!--    Same procedure for interpolation of the v velocity-component 
+
        DO  n = start_index(nb), end_index(nb)
 
-          ilog = ( particles(n)%x + 0.5_wp * dx ) * ddx
-          jlog = ( particles(n)%y + 0.5_wp * dy ) * ddy
+          ilog = particles(n)%x * ddx
+          jlog = particles(n)%y * ddy
 !
 !--       Determine vertical index of topography top
@@ -474,10 +481,10 @@
 
        ENDDO
-
+!
+!--    Same procedure for interpolation of the w velocity-component
        i = ip + block_offset(nb)%i_off
        j = jp + block_offset(nb)%j_off
        k = kp - 1
-!
-!--    Same procedure for interpolation of the w velocity-component
+
        DO  n = start_index(nb), end_index(nb)
 
@@ -660,5 +667,5 @@
                 i = particles(n)%x * ddx
                 j = particles(n)%y * ddy
-                k = ( zv(n) + 0.5_wp * dz * atmos_ocean_sign ) / dz  &
+                k = ( zv(n) + dz * atmos_ocean_sign ) / dz  &
                     + offset_ocean_nzt                      ! only exact if eq.dist
 !
Index: palm/trunk/SOURCE/lpm_boundary_conds.f90
===================================================================
--- palm/trunk/SOURCE/lpm_boundary_conds.f90	(revision 2605)
+++ palm/trunk/SOURCE/lpm_boundary_conds.f90	(revision 2606)
@@ -25,4 +25,11 @@
 ! -----------------
 ! $Id$
+! Changed particle box locations: center of particle box now coincides 
+! with scalar grid point of same index.
+! Renamed module and subroutines: lpm_pack_arrays_mod -> lpm_pack_and_sort_mod
+! lpm_pack_all_arrays -> lpm_sort_in_subboxes, lpm_pack_arrays -> lpm_pack
+! lpm_sort -> lpm_sort_timeloop_done
+! 
+! 2318 2017-07-20 17:27:44Z suehring
 ! Get topography top index via Function call 
 ! 
@@ -254,6 +261,6 @@
 !
 !--       Obtain x/y indices for current particle position
-          i2 = ( particles(n)%x + 0.5_wp * dx ) * ddx
-          j2 = ( particles(n)%y + 0.5_wp * dy ) * ddy
+          i2 = particles(n)%x * ddx
+          j2 = particles(n)%y * ddy
 !
 !--       Save current particle positions
@@ -268,6 +275,6 @@
 !
 !--       Obtain x/y indices for old particle positions
-          i1 = ( pos_x_old + 0.5_wp * dx ) * ddx
-          j1 = ( pos_y_old + 0.5_wp * dy ) * ddy
+          i1 = pos_x_old * ddx
+          j1 = pos_y_old * ddy
 !
 !--       Determine horizontal as well as vertical walls at which particle can 
Index: palm/trunk/SOURCE/lpm_exchange_horiz.f90
===================================================================
--- palm/trunk/SOURCE/lpm_exchange_horiz.f90	(revision 2605)
+++ palm/trunk/SOURCE/lpm_exchange_horiz.f90	(revision 2606)
@@ -25,4 +25,15 @@
 ! -----------------
 ! $Id$
+! Changed particle box locations: center of particle box now coincides 
+! with scalar grid point of same index.
+! lpm_move_particle now moves inner particles that would leave the core 
+! to the respective boundary gridbox. Afterwards they get transferred by 
+! lpm_exchange_horiz. This allows particles to move more than one gridbox 
+! independent of domain composition.  
+! Renamed module and subroutines: lpm_pack_arrays_mod -> lpm_pack_and_sort_mod
+! lpm_pack_all_arrays -> lpm_sort_in_subboxes, lpm_pack_arrays -> lpm_pack
+! lpm_sort -> lpm_sort_timeloop_done
+! 
+! 2330 2017-08-03 14:26:02Z schwenkel
 ! Bugfix: Also for gfortran compilable, function c_sizeof is not used. 
 ! 
@@ -128,6 +139,6 @@
     USE kinds
 
-    USE lpm_pack_arrays_mod,                                                   &
-        ONLY:  lpm_pack_arrays
+    USE lpm_pack_and_sort_mod,                                                   &
+        ONLY:  lpm_pack
 
     USE netcdf_interface,                                                      &
@@ -255,8 +266,8 @@
                 DO  n = 1, number_of_particles
                    IF ( particles(n)%particle_mask )  THEN
-                      i = ( particles(n)%x + 0.5_wp * dx ) * ddx
+                      i = particles(n)%x * ddx
 !
 !--                   Above calculation does not work for indices less than zero
-                      IF ( particles(n)%x < -0.5_wp * dx )  i = -1
+                      IF ( particles(n)%x < 0.0_wp)  i = -1
 
                       IF ( i < nxl )  THEN
@@ -298,8 +309,8 @@
                 IF ( particles(n)%particle_mask )  THEN
 
-                   i = ( particles(n)%x + 0.5_wp * dx ) * ddx
+                   i = particles(n)%x * ddx
 !
 !--                Above calculation does not work for indices less than zero
-                   IF ( particles(n)%x < - 0.5_wp * dx )  i = -1
+                   IF ( particles(n)%x < 0.0_wp )  i = -1
 
                    IF ( i <  nxl )  THEN
@@ -323,5 +334,5 @@
                                deleted_particles = deleted_particles + 1
 
-                               IF ( trlp(trlp_count)%x >= (nx + 0.5_wp)* dx - 1.0E-12_wp )  THEN
+                               IF ( trlp(trlp_count)%x >= (nx + 1)* dx - 1.0E-12_wp )  THEN
                                   trlp(trlp_count)%x = trlp(trlp_count)%x - 1.0E-10_wp
                                   !++ why is 1 subtracted in next statement???
@@ -501,8 +512,8 @@
                 DO  n = 1, number_of_particles
                    IF ( particles(n)%particle_mask )  THEN
-                      j = ( particles(n)%y + 0.5_wp * dy ) * ddy
+                      j = particles(n)%y * ddy
 !
 !--                   Above calculation does not work for indices less than zero
-                      IF ( particles(n)%y < -0.5_wp * dy )  j = -1
+                      IF ( particles(n)%y < 0.0_wp)  j = -1
 
                       IF ( j < nys )  THEN
@@ -545,8 +556,8 @@
                 IF ( particles(n)%particle_mask )  THEN
 
-                   j = ( particles(n)%y + 0.5_wp * dy ) * ddy
+                   j = particles(n)%y * ddy
 !
 !--                Above calculation does not work for indices less than zero
-                   IF ( particles(n)%y < -0.5_wp * dy )  j = -1
+                   IF ( particles(n)%y < 0.0_wp )  j = -1
 
                    IF ( j < nys )  THEN
@@ -571,5 +582,5 @@
                                deleted_particles = deleted_particles + 1
 
-                               IF ( trsp(trsp_count)%y >= (ny+0.5_wp)* dy - 1.0E-12_wp )  THEN
+                               IF ( trsp(trsp_count)%y >= (ny+1)* dy - 1.0E-12_wp )  THEN
                                   trsp(trsp_count)%y = trsp(trsp_count)%y - 1.0E-10_wp
                                   !++ why is 1 subtracted in next statement???
@@ -719,5 +730,5 @@
 !--             Apply boundary conditions
 
-                IF ( particles(n)%x < -0.5_wp * dx )  THEN
+                IF ( particles(n)%x < 0.0_wp )  THEN
 
                    IF ( ibc_par_lr == 0 )  THEN
@@ -725,5 +736,6 @@
 !--                   Cyclic boundary. Relevant coordinate has to be changed.
                       particles(n)%x = ( nx + 1 ) * dx + particles(n)%x
-
+                      particles(n)%origin_x = ( nx + 1 ) * dx + &
+                               particles(n)%origin_x
                    ELSEIF ( ibc_par_lr == 1 )  THEN
 !
@@ -739,5 +751,5 @@
                    ENDIF
 
-                ELSEIF ( particles(n)%x >= ( nx + 0.5_wp ) * dx )  THEN
+                ELSEIF ( particles(n)%x >= ( nx + 1) * dx )  THEN
 
                    IF ( ibc_par_lr == 0 )  THEN
@@ -745,4 +757,6 @@
 !--                   Cyclic boundary. Relevant coordinate has to be changed.
                       particles(n)%x = particles(n)%x - ( nx + 1 ) * dx
+                      particles(n)%origin_x = particles(n)%origin_x - &
+                               ( nx + 1 ) * dx
 
                    ELSEIF ( ibc_par_lr == 1 )  THEN
@@ -773,5 +787,5 @@
              DO  n = 1, number_of_particles
 
-                IF ( particles(n)%y < -0.5_wp * dy )  THEN
+                IF ( particles(n)%y < 0.0_wp)  THEN
 
                    IF ( ibc_par_ns == 0 )  THEN
@@ -779,4 +793,6 @@
 !--                   Cyclic boundary. Relevant coordinate has to be changed.
                       particles(n)%y = ( ny + 1 ) * dy + particles(n)%y
+                      particles(n)%origin_y = ( ny + 1 ) * dy + &
+                           particles(n)%origin_y
 
                    ELSEIF ( ibc_par_ns == 1 )  THEN
@@ -793,5 +809,5 @@
                    ENDIF
 
-                ELSEIF ( particles(n)%y >= ( ny + 0.5_wp ) * dy )  THEN
+                ELSEIF ( particles(n)%y >= ( ny + 1) * dy )  THEN
 
                    IF ( ibc_par_ns == 0 )  THEN
@@ -799,4 +815,6 @@
 !--                   Cyclic boundary. Relevant coordinate has to be changed.
                       particles(n)%y = particles(n)%y - ( ny + 1 ) * dy
+                      particles(n)%origin_y = particles(n)%origin_y - &
+                                ( ny + 1 ) * dy
 
                    ELSEIF ( ibc_par_ns == 1 )  THEN
@@ -866,7 +884,7 @@
        IF ( .NOT. particle_array(n)%particle_mask )  CYCLE
 
-       ip = ( particle_array(n)%x + 0.5_wp * dx ) * ddx
-       jp = ( particle_array(n)%y + 0.5_wp * dy ) * ddy
-       kp =   particle_array(n)%z / dz + 1 + offset_ocean_nzt
+       ip = particle_array(n)%x * ddx
+       jp = particle_array(n)%y * ddy
+       kp = particle_array(n)%z / dz + 1 + offset_ocean_nzt
 
        IF ( ip >= nxl  .AND.  ip <= nxr  .AND.  jp >= nys  .AND.  jp <= nyn    &
@@ -880,5 +898,5 @@
                 CALL realloc_particles_array (ip,jp,kp)
              ELSE
-                CALL lpm_pack_arrays
+                CALL lpm_pack
                 prt_count(kp,jp,ip) = number_of_particles
                 pindex = prt_count(kp,jp,ip)+1
@@ -1014,11 +1032,8 @@
     INTEGER(iwp)        ::  kp          !< index variable along z
     INTEGER(iwp)        ::  n           !< index variable for particle array
-    INTEGER(iwp)        ::  np_old_cell !< number of particles per grid box before moving
-    INTEGER(iwp)        ::  n_start     !< start index
+    INTEGER(iwp)        ::  np_before_move !< number of particles per grid box before moving
     INTEGER(iwp)        ::  pindex      !< dummy argument for number of new particle per grid box
 
-    LOGICAL             ::  pack_done   !<
-
-    TYPE(particle_type), DIMENSION(:), POINTER  ::  particles_old_cell !< particles before moving
+    TYPE(particle_type), DIMENSION(:), POINTER  ::  particles_before_move !< particles before moving
 
     CALL cpu_log( log_point_s(41), 'lpm_move_particle', 'start' )
@@ -1028,90 +1043,44 @@
           DO  kp = nzb+1, nzt
 
-             np_old_cell = prt_count(kp,jp,ip)
-             IF ( np_old_cell <= 0 )  CYCLE
-             particles_old_cell => grid_particles(kp,jp,ip)%particles(1:np_old_cell)
-             n_start = -1
+             np_before_move = prt_count(kp,jp,ip)
+             IF ( np_before_move <= 0 )  CYCLE
+             particles_before_move => grid_particles(kp,jp,ip)%particles(1:np_before_move)
              
-             DO  n = 1, np_old_cell
-                i = ( particles_old_cell(n)%x + 0.5_wp * dx ) * ddx
-                j = ( particles_old_cell(n)%y + 0.5_wp * dy ) * ddy
-                k = particles_old_cell(n)%z / dz + 1 + offset_ocean_nzt
+             DO  n = 1, np_before_move
+                i = particles_before_move(n)%x * ddx
+                j = particles_before_move(n)%y * ddy
+                k = particles_before_move(n)%z / dz + 1 + offset_ocean_nzt
+
+!--             For lpm_exchange_horiz to work properly particles need to be moved to the outermost gridboxes
+!--             of the respective processor. If the particle index is inside the processor the following lines
+!--             will not change the index
+                i = MIN ( i , nxr )
+                i = MAX ( i , nxl )
+                j = MIN ( j , nyn )
+                j = MAX ( j , nys )
+                k = MIN ( k , nzt )
+                k = MAX ( k , nzb+1 )
 !
 !--             Check, if particle has moved to another grid cell.
                 IF ( i /= ip  .OR.  j /= jp  .OR.  k /= kp )  THEN
-!
-!--                The particle has moved to another grid cell. Now check, if 
-!--                particle stays on the same processor.
-                   IF ( i >= nxl  .AND.  i <= nxr  .AND.  j >= nys  .AND.      &
-                        j <= nyn  .AND.  k >= nzb+1  .AND.  k <= nzt)  THEN
-!
-!--                   If the particle stays on the same processor, the particle
-!--                   will be added to the particle array of the new processor.
-                      number_of_particles = prt_count(k,j,i)
-                      particles => grid_particles(k,j,i)%particles(1:number_of_particles)
-
-                      pindex = prt_count(k,j,i)+1
-                      IF (  pindex > SIZE(grid_particles(k,j,i)%particles)  )  &
-                      THEN
-                         n_start = n
-                         EXIT
-                      ENDIF
-
-                      grid_particles(k,j,i)%particles(pindex) = particles_old_cell(n)
-                      prt_count(k,j,i) = pindex
-
-                      particles_old_cell(n)%particle_mask = .FALSE.
+!!
+!--                If the particle stays on the same processor, the particle
+!--                will be added to the particle array of the new processor.
+                   number_of_particles = prt_count(k,j,i)
+                   particles => grid_particles(k,j,i)%particles(1:number_of_particles)
+
+                   pindex = prt_count(k,j,i)+1
+                   IF (  pindex > SIZE(grid_particles(k,j,i)%particles)  )     &
+                   THEN
+                      CALL realloc_particles_array(i,j,k)
                    ENDIF
+
+                   grid_particles(k,j,i)%particles(pindex) = particles_before_move(n)
+                   prt_count(k,j,i) = pindex
+
+                   particles_before_move(n)%particle_mask = .FALSE.
                 ENDIF
              ENDDO
 
-             IF ( n_start >= 0 )  THEN
-                pack_done = .FALSE.
-                DO  n = n_start, np_old_cell
-                   i = ( particles_old_cell(n)%x + 0.5_wp * dx ) * ddx
-                   j = ( particles_old_cell(n)%y + 0.5_wp * dy ) * ddy
-                   k = particles_old_cell(n)%z / dz + 1 + offset_ocean_nzt
-                   IF ( i /= ip  .OR.  j /= jp  .OR.  k /= kp )  THEN
-!
-!--                   Particle is in different box
-                      IF ( i >= nxl  .AND.  i <= nxr  .AND.  j >= nys  .AND.   &
-                           j <= nyn  .AND.  k >= nzb+1  .AND.  k <= nzt)  THEN
-!
-!--                      Particle stays on processor
-                         number_of_particles = prt_count(k,j,i)
-                         particles => grid_particles(k,j,i)%particles(1:number_of_particles)
-
-                         pindex = prt_count(k,j,i)+1
-                         IF ( pindex > SIZE(grid_particles(k,j,i)%particles) ) &
-                         THEN
-                            IF ( pack_done )  THEN
-                               CALL realloc_particles_array(i,j,k)
-                            ELSE
-                               CALL lpm_pack_arrays
-                               prt_count(k,j,i) = number_of_particles
-!
-!--                            Set pindex to next index of the modified
-!--                            particle-array (due to lpm_pack_arrays)
-                               pindex = prt_count(k,j,i)+1
-!
-!--                            If number of particles in the new grid box 
-!--                            exceeds its allocated memory, the particle array
-!--                            will be reallocated
-                               IF ( pindex > SIZE(grid_particles(k,j,i)%particles) )  THEN
-                                  CALL realloc_particles_array(i,j,k)
-                               ENDIF
-
-                               pack_done = .TRUE.
-                            ENDIF
-                         ENDIF
-
-                         grid_particles(k,j,i)%particles(pindex) = particles_old_cell(n)
-                         prt_count(k,j,i) = pindex
-
-                         particles_old_cell(n)%particle_mask = .FALSE.
-                      ENDIF
-                   ENDIF
-                ENDDO
-             ENDIF
           ENDDO
        ENDDO
Index: palm/trunk/SOURCE/lpm_init.f90
===================================================================
--- palm/trunk/SOURCE/lpm_init.f90	(revision 2605)
+++ palm/trunk/SOURCE/lpm_init.f90	(revision 2606)
@@ -25,4 +25,11 @@
 ! -----------------
 ! $Id$
+! Changed particle box locations: center of particle box now coincides 
+! with scalar grid point of same index.
+! Renamed module and subroutines: lpm_pack_arrays_mod -> lpm_pack_and_sort_mod
+! lpm_pack_all_arrays -> lpm_sort_in_subboxes, lpm_pack_arrays -> lpm_pack
+! lpm_sort -> lpm_sort_timeloop_done
+! 
+! 2375 2017-08-29 14:10:28Z schwenkel
 ! Initialization of chemical aerosol composition
 ! 
@@ -277,13 +284,14 @@
 !
 !-- Define block offsets for dividing a gridcell in 8 sub cells
-
-    block_offset(0) = block_offset_def (-1,-1,-1)
-    block_offset(1) = block_offset_def (-1,-1, 0)
-    block_offset(2) = block_offset_def (-1, 0,-1)
-    block_offset(3) = block_offset_def (-1, 0, 0)
-    block_offset(4) = block_offset_def ( 0,-1,-1)
-    block_offset(5) = block_offset_def ( 0,-1, 0)
-    block_offset(6) = block_offset_def ( 0, 0,-1)
-    block_offset(7) = block_offset_def ( 0, 0, 0)
+!-- See documentation for List of subgrid boxes
+!-- See pack_and_sort in lpm_pack_arrays.f90 for assignment of the subgrid boxes
+    block_offset(0) = block_offset_def ( 0, 0, 0)
+    block_offset(1) = block_offset_def ( 0, 0,-1)
+    block_offset(2) = block_offset_def ( 0,-1, 0)
+    block_offset(3) = block_offset_def ( 0,-1,-1)
+    block_offset(4) = block_offset_def (-1, 0, 0)
+    block_offset(5) = block_offset_def (-1, 0,-1)
+    block_offset(6) = block_offset_def (-1,-1, 0)
+    block_offset(7) = block_offset_def (-1,-1,-1)
 !
 !-- Check the number of particle groups.
@@ -309,8 +317,8 @@
 !
 !-- Set default start positions, if necessary
-    IF ( psl(1) == 9999999.9_wp )  psl(1) = -0.5_wp * dx
-    IF ( psr(1) == 9999999.9_wp )  psr(1) = ( nx + 0.5_wp ) * dx
-    IF ( pss(1) == 9999999.9_wp )  pss(1) = -0.5_wp * dy
-    IF ( psn(1) == 9999999.9_wp )  psn(1) = ( ny + 0.5_wp ) * dy
+    IF ( psl(1) == 9999999.9_wp )  psl(1) = 0.0_wp
+    IF ( psr(1) == 9999999.9_wp )  psr(1) = ( nx +1 ) * dx
+    IF ( pss(1) == 9999999.9_wp )  pss(1) = 0.0_wp
+    IF ( psn(1) == 9999999.9_wp )  psn(1) = ( ny +1 ) * dy
     IF ( psb(1) == 9999999.9_wp )  psb(1) = zu(nz/2)
     IF ( pst(1) == 9999999.9_wp )  pst(1) = psb(1)
@@ -617,6 +625,6 @@
         ONLY: lpm_exchange_horiz, lpm_move_particle, realloc_particles_array
 
-    USE lpm_pack_arrays_mod,                                                   &
-        ONLY: lpm_pack_all_arrays
+    USE lpm_pack_and_sort_mod,                                                   &
+        ONLY: lpm_sort_in_subboxes
 
     USE particle_attributes,                                                   &
@@ -683,6 +691,6 @@
                 DO WHILE ( pos_y <= psn(i) )
 
-                   IF ( pos_y >= ( nys - 0.5_wp ) * dy  .AND.                  &
-                        pos_y <  ( nyn + 0.5_wp ) * dy )  THEN
+                   IF ( pos_y >= nys * dy  .AND.                  &
+                        pos_y <  ( nyn + 1 ) * dy  ) THEN
 
                       pos_x = psl(i)
@@ -690,6 +698,6 @@
                xloop: DO WHILE ( pos_x <= psr(i) )
 
-                         IF ( pos_x >= ( nxl - 0.5_wp ) * dx  .AND.            &
-                              pos_x <  ( nxr + 0.5_wp ) * dx )  THEN
+                         IF ( pos_x >= nxl * dx  .AND.            &
+                              pos_x <  ( nxr + 1) * dx ) THEN
 
                             DO  j = 1, particles_per_point
@@ -729,6 +737,6 @@
 !
 !--                            Determine the grid indices of the particle position
-                               ip = ( tmp_particle%x + 0.5_wp * dx ) * ddx
-                               jp = ( tmp_particle%y + 0.5_wp * dy ) * ddy
+                               ip = tmp_particle%x * ddx
+                               jp = tmp_particle%y * ddy
                                kp = tmp_particle%z / dz + 1 + offset_ocean_nzt
 !
@@ -916,6 +924,6 @@
                        grid_particles(kp,jp,ip)%particles(1:number_of_particles)
                 DO  n = local_start(kp,jp,ip), number_of_particles
-                   i = ( particles(n)%x + 0.5_wp * dx ) * ddx
-                   j = ( particles(n)%y + 0.5_wp * dy ) * ddy
+                   i = particles(n)%x * ddx
+                   j = particles(n)%y * ddy
                    k =   particles(n)%z / dz + 1 + offset_ocean_nzt
 !
@@ -941,5 +949,5 @@
 !-- which is needed for a fast interpolation of the LES fields on the particle
 !-- position.
-    CALL lpm_pack_all_arrays
+    CALL lpm_sort_in_subboxes
 
 !
Index: palm/trunk/SOURCE/lpm_pack_arrays.f90
===================================================================
--- palm/trunk/SOURCE/lpm_pack_arrays.f90	(revision 2605)
+++ palm/trunk/SOURCE/lpm_pack_arrays.f90	(revision 2606)
@@ -25,4 +25,11 @@
 ! -----------------
 ! $Id$
+! Changed particle box locations: center of particle box now coincides 
+! with scalar grid point of same index.
+! Renamed module and subroutines: lpm_pack_arrays_mod -> lpm_pack_and_sort_mod
+! lpm_pack_all_arrays -> lpm_sort_in_subboxes, lpm_pack_arrays -> lpm_pack
+! lpm_sort -> lpm_sort_timeloop_done
+! 
+! 2417 2017-09-06 15:22:27Z suehring
 ! New routine which sorts particles into particles that completed and not 
 ! completed the LES timestep. 
@@ -68,5 +75,5 @@
 !> its timestep. 
 !------------------------------------------------------------------------------!
- MODULE lpm_pack_arrays_mod
+ MODULE lpm_pack_and_sort_mod
  
 
@@ -76,65 +83,74 @@
 
     PRIVATE
-    PUBLIC lpm_pack_all_arrays, lpm_pack_arrays, lpm_sort
-
-    INTERFACE lpm_pack_all_arrays
-       MODULE PROCEDURE lpm_pack_all_arrays
-    END INTERFACE lpm_pack_all_arrays
-
-    INTERFACE lpm_pack_arrays
-       MODULE PROCEDURE lpm_pack_arrays
-    END INTERFACE lpm_pack_arrays
-
-    INTERFACE lpm_sort
-       MODULE PROCEDURE lpm_sort
-    END INTERFACE lpm_sort
+    PUBLIC lpm_sort_in_subboxes, lpm_pack, lpm_sort_timeloop_done
+
+    INTERFACE lpm_sort_in_subboxes
+       MODULE PROCEDURE lpm_sort_in_subboxes
+    END INTERFACE lpm_sort_in_subboxes
+
+    INTERFACE lpm_pack
+       MODULE PROCEDURE lpm_pack
+    END INTERFACE lpm_pack
+
+    INTERFACE lpm_sort_timeloop_done
+       MODULE PROCEDURE lpm_sort_timeloop_done
+    END INTERFACE lpm_sort_timeloop_done
 
 
  CONTAINS
+
+!------------------------------------------------------------------------------!
+! Description:
+! -----------
+!> Routine for the whole processor
+!> Sort all particles into the 8 respective subgrid boxes
+!------------------------------------------------------------------------------!
+    SUBROUTINE lpm_sort_in_subboxes
+
+       USE cpulog,                                                              &
+           ONLY:  cpu_log, log_point_s
+
+       USE indices,                                                             &
+           ONLY:  nxl, nxr, nys, nyn, nzb, nzt
+
+       USE kinds
+
+       USE control_parameters,                                                  &
+           ONLY: dz
+       
+       USE grid_variables,                                                      &
+           ONLY: dx,dy,ddx, ddy
+          
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  ip !<
+       INTEGER(iwp) ::  jp !<
+       INTEGER(iwp) ::  kp !<
+
+       CALL cpu_log( log_point_s(51), 'lpm_sort_in_subboxes', 'start' )
+       DO  ip = nxl, nxr
+          DO  jp = nys, nyn
+             DO  kp = nzb+1, nzt
+                number_of_particles = prt_count(kp,jp,ip)
+                IF ( number_of_particles <= 0 )  CYCLE
+                particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
+                
+                CALL lpm_pack_and_sort(ip,jp,kp)
+                
+                prt_count(kp,jp,ip) = number_of_particles
+             ENDDO
+          ENDDO
+       ENDDO
+       CALL cpu_log( log_point_s(51), 'lpm_sort_in_subboxes', 'stop' )
+       RETURN
+
+    END SUBROUTINE lpm_sort_in_subboxes
 
 !------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
-    SUBROUTINE lpm_pack_all_arrays
-
-       USE cpulog,                                                             &
-           ONLY:  cpu_log, log_point_s
-
-       USE indices,                                                            &
-           ONLY:  nxl, nxr, nys, nyn, nzb, nzt
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i !<
-       INTEGER(iwp) ::  j !<
-       INTEGER(iwp) ::  k !<
-
-       CALL cpu_log( log_point_s(51), 'lpm_pack_all_arrays', 'start' )
-       DO  i = nxl, nxr
-          DO  j = nys, nyn
-             DO  k = nzb+1, nzt
-                number_of_particles = prt_count(k,j,i)
-                IF ( number_of_particles <= 0 )  CYCLE
-                particles => grid_particles(k,j,i)%particles(1:number_of_particles)
-                CALL lpm_pack_and_sort(i,j,k)
-                prt_count(k,j,i) = number_of_particles
-             ENDDO
-          ENDDO
-       ENDDO
-       CALL cpu_log( log_point_s(51), 'lpm_pack_all_arrays', 'stop' )
-       RETURN
-
-    END SUBROUTINE lpm_pack_all_arrays
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
-    SUBROUTINE lpm_pack_arrays
+!> Move all particles not marked for deletion to lowest indices (packing)
+!------------------------------------------------------------------------------!
+    SUBROUTINE lpm_pack
 
        USE kinds
@@ -173,43 +189,38 @@
        number_of_particles = nn
 
-    END SUBROUTINE lpm_pack_arrays
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+    END SUBROUTINE lpm_pack 
+
     SUBROUTINE lpm_pack_and_sort (ip,jp,kp)
 
-      USE control_parameters,                                                  &
-          ONLY: dz
-
-      USE kinds
-
-      USE grid_variables,                                                      &
-          ONLY: ddx, ddy
-
-      IMPLICIT NONE
-
-      INTEGER(iwp), INTENT(IN) :: ip
-      INTEGER(iwp), INTENT(IN) :: jp
-      INTEGER(iwp), INTENT(IN) :: kp
-
-      INTEGER(iwp)             :: i
-      INTEGER(iwp)             :: is
-      INTEGER(iwp)             :: j
-      INTEGER(iwp)             :: k
-      INTEGER(iwp)             :: n
-      INTEGER(iwp)             :: nn
-      INTEGER(iwp)             :: m
-      INTEGER(iwp)             :: sort_index
-
-      INTEGER(iwp), DIMENSION(0:7) :: sort_count
-
-      TYPE(particle_type), DIMENSION(number_of_particles,0:7) :: sort_particles
-
+       USE control_parameters,                                                 &
+           ONLY: dz
+
+       USE kinds
+
+       USE grid_variables,                                                     &
+           ONLY: dx,dy,ddx, ddy
+
+       IMPLICIT NONE
+
+       INTEGER(iwp), INTENT(IN) :: ip
+       INTEGER(iwp), INTENT(IN) :: jp
+       INTEGER(iwp), INTENT(IN) :: kp
+
+       INTEGER(iwp)             :: i
+       INTEGER(iwp)             :: is
+       INTEGER(iwp)             :: j
+       INTEGER(iwp)             :: k
+       INTEGER(iwp)             :: n
+       INTEGER(iwp)             :: nn
+       INTEGER(iwp)             :: m
+       INTEGER(iwp)             :: sort_index
+
+       INTEGER(iwp), DIMENSION(0:7) :: sort_count
+
+       TYPE(particle_type), DIMENSION(number_of_particles,0:7) :: sort_particles
+      
        nn = 0
        sort_count = 0
-
+                
        DO  n = 1, number_of_particles
           sort_index = 0
@@ -217,11 +228,18 @@
           IF ( particles(n)%particle_mask )  THEN
              nn = nn + 1
-             i = particles(n)%x * ddx
-             j = particles(n)%y * ddy
-             k = ( particles(n)%z + 0.5_wp * dz ) / dz + offset_ocean_nzt
-             IF ( i == ip )  sort_index = sort_index+4
-             IF ( j == jp )  sort_index = sort_index+2
-             IF ( k == kp )  sort_index = sort_index+1
-             sort_count(sort_index) = sort_count(sort_index)+1
+!
+!--          Sorting particles with a binary scheme
+!--          sort_index=111_2=7_10 -> particle at the left,south,bottom subgridbox
+!--          sort_index=000_2=0_10 -> particle at the right,north,top subgridbox
+!--          For this the center of the gridbox is calculated 
+             i = (particles(n)%x + 0.5_wp * dx) * ddx
+             j = (particles(n)%y + 0.5_wp * dy) * ddy
+             k = ( particles(n)%z+ 0.5_wp *dz ) / dz+1 + offset_ocean_nzt
+                      
+             IF ( i == ip )  sort_index = sort_index + 4 
+             IF ( j == jp )  sort_index = sort_index + 2
+             IF ( k == kp )  sort_index = sort_index + 1
+                      
+             sort_count(sort_index) = sort_count(sort_index) + 1
              m = sort_count(sort_index)
              sort_particles(m,sort_index) = particles(n)
@@ -236,15 +254,14 @@
           grid_particles(kp,jp,ip)%start_index(is) = nn + 1
           DO n = 1,sort_count(is)
-             nn = nn+1
+             nn = nn + 1
              particles(nn) = sort_particles(n,is)
-          ENDDO
-          grid_particles(kp,jp,ip)%end_index(is) = nn
-       ENDDO
-
-       number_of_particles = nn
-       RETURN
-
+             ENDDO
+             grid_particles(kp,jp,ip)%end_index(is) = nn
+       ENDDO
+
+       number_of_particles = nn    
+                
     END SUBROUTINE lpm_pack_and_sort
-
+                
 !------------------------------------------------------------------------------!
 ! Description:
@@ -254,5 +271,5 @@
 !> complete the LES timestep. 
 !------------------------------------------------------------------------------!
-    SUBROUTINE lpm_sort
+    SUBROUTINE lpm_sort_timeloop_done
 
        USE control_parameters,                                                 &
@@ -342,6 +359,6 @@
        ENDDO
 
-    END SUBROUTINE lpm_sort
-
-
- END module lpm_pack_arrays_mod
+    END SUBROUTINE lpm_sort_timeloop_done
+
+
+ END module lpm_pack_and_sort_mod
Index: palm/trunk/SOURCE/lpm_read_restart_file.f90
===================================================================
--- palm/trunk/SOURCE/lpm_read_restart_file.f90	(revision 2605)
+++ palm/trunk/SOURCE/lpm_read_restart_file.f90	(revision 2606)
@@ -20,9 +20,16 @@
 ! Current revisions:
 ! ------------------
-!
-!
+! 
+! 
 ! Former revisions:
 ! -----------------
 ! $Id$
+! Changed particle box locations: center of particle box now coincides 
+! with scalar grid point of same index.
+! Renamed module and subroutines: lpm_pack_arrays_mod -> lpm_pack_and_sort_mod
+! lpm_pack_all_arrays -> lpm_sort_in_subboxes, lpm_pack_arrays -> lpm_pack
+! lpm_sort -> lpm_sort_timeloop_done
+!
+! 2312 2017-07-14 20:26:51Z hoffmann
 ! Extended particle data type.
 !
@@ -74,6 +81,6 @@
     USE kinds
 
-    USE lpm_pack_arrays_mod,                                                   &
-        ONLY:  lpm_pack_all_arrays
+    USE lpm_pack_and_sort_mod,                                                   &
+        ONLY:  lpm_sort_in_subboxes
 
     USE particle_attributes,                                                   &
@@ -178,5 +185,5 @@
 !-- Must be called to sort particles into blocks, which is needed for a fast
 !-- interpolation of the LES fields on the particle position.
-    CALL lpm_pack_all_arrays
+    CALL lpm_sort_in_subboxes
 
 
