Index: palm/trunk/SOURCE/lpm_read_restart_file.f90
===================================================================
--- palm/trunk/SOURCE/lpm_read_restart_file.f90	(revision 1321)
+++ palm/trunk/SOURCE/lpm_read_restart_file.f90	(revision 1359)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! ------------------
-!
+! New particle structure integrated. 
 !
 ! Former revisions:
@@ -49,14 +49,19 @@
         ONLY:  nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nz, nzb, nzt
 
+    USE kinds
+
+    USE lpm_pack_arrays_mod,                                                   &
+        ONLY:  lpm_pack_all_arrays
+
     USE particle_attributes,                                                   &
-        ONLY:  bc_par_b, bc_par_lr, bc_par_ns, bc_par_t, initial_particles,    &
-               number_of_initial_particles, maximum_number_of_particles,       &
+        ONLY:  alloc_factor, bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,         &
+               grid_particles, maximum_number_of_particles,                    &
                maximum_number_of_tailpoints, maximum_number_of_tails,          &
-               new_tail_id, number_of_particles, number_of_particle_groups,    &
-               number_of_tails, particles, particle_groups, particle_mask,     &
-               particle_tail_coordinates, particle_type, part_1, part_2,       &
-               prt_count, prt_start_index,  sort_count, tail_mask, time_prel,  &
-               time_write_particle_data, uniform_particles, use_particle_tails
-
+               min_nr_particle, new_tail_id, number_of_particles,              &
+               number_of_particle_groups, number_of_tails, particles,          &
+               particle_groups, particle_tail_coordinates, particle_type,      &
+               prt_count, sort_count, tail_mask, time_prel,                    &
+               time_write_particle_data, uniform_particles,                    &
+               use_particle_tails, zero_particle
 
     USE pegrid
@@ -66,4 +71,11 @@
     CHARACTER (LEN=10) ::  particle_binary_version    !:
     CHARACTER (LEN=10) ::  version_on_file            !:
+
+    INTEGER(iwp) :: alloc_size !:
+    INTEGER(iwp) :: ip         !:
+    INTEGER(iwp) :: jp         !:
+    INTEGER(iwp) :: kp         !:
+
+    TYPE(particle_type), DIMENSION(:), ALLOCATABLE :: tmp_particles !:
 
 !
@@ -81,5 +93,5 @@
 !-- First compare the version numbers
     READ ( 90 )  version_on_file
-    particle_binary_version = '3.0'
+    particle_binary_version = '3.2'
     IF ( TRIM( version_on_file ) /= TRIM( particle_binary_version ) )  THEN
        message_string = 'version mismatch concerning data from prior ' // &
@@ -92,48 +104,85 @@
 
 !
+!-- If less particles are stored on the restart file than prescribed by 
+!-- min_nr_particle, the remainder is initialized by zero_particle to avoid
+!-- errors.
+#if defined( __twocachelines )
+    zero_particle = particle_type( 0.0_wp, 0.0_sp, 0.0_sp, 0.0_sp, 0.0_sp,  &
+                                   0.0_sp, 0.0_sp, 0.0_wp, 0.0_wp, 0.0_wp,  &
+                                   0, .FALSE., 0.0_wp, 0.0_wp, 0.0_wp,      &
+                                   0.0_sp, 0.0_sp, 0.0_sp, 0.0_sp, 0.0_sp,  &
+                                   0.0_sp, 0, 0, 0, -1)
+#else
+    zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
+                                   0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
+                                   0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
+                                   0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0, 0, 0, &
+                                   0, .FALSE., -1)
+#endif
+
+!
 !-- Read some particle parameters and the size of the particle arrays,
 !-- allocate them and read their contents.
     READ ( 90 )  bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,                  &
-                 maximum_number_of_particles, maximum_number_of_tailpoints, &
-                 maximum_number_of_tails, number_of_initial_particles,      &
-                 number_of_particles, number_of_particle_groups,            &
-                 number_of_tails, particle_groups, time_prel,               &
-                 time_write_particle_data, uniform_particles
+                 maximum_number_of_tailpoints, maximum_number_of_tails,     &
+                 number_of_particle_groups, number_of_tails,                &
+                 particle_groups, time_prel, time_write_particle_data,      &
+                 uniform_particles
 
-    IF ( number_of_initial_particles /= 0 )  THEN
-       ALLOCATE( initial_particles(1:number_of_initial_particles) )
-       READ ( 90 )  initial_particles
-    ENDIF
+    ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                     &
+              grid_particles(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 
-    ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg),       &
-              prt_start_index(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
-              particle_mask(maximum_number_of_particles),     &
-              part_1(maximum_number_of_particles),            &
-              part_2(maximum_number_of_particles) )
+    READ ( 90 )  prt_count
 
-    part_1 = particle_type( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &
-                            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &
-                            0.0, 0, 0, 0, 0 )
+    maximum_number_of_particles = 0
+    DO  ip = nxl, nxr
+       DO  jp = nys, nyn
+          DO  kp = nzb+1, nzt
 
-    part_2 = particle_type( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &
-                            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, &
-                            0.0, 0, 0, 0, 0 )
+             number_of_particles = prt_count(kp,jp,ip)
+             IF ( number_of_particles > 0 )  THEN
+                alloc_size = MAX( INT( number_of_particles *                   &
+                             ( 1.0_wp + alloc_factor / 100.0_wp ) ),           &
+                             min_nr_particle )
+             ELSE
+                alloc_size = min_nr_particle
+             ENDIF
 
-    sort_count = 0
+             ALLOCATE( grid_particles(kp,jp,ip)%particles(1:alloc_size) )
 
-    particles => part_1
+             IF ( number_of_particles > 0 )  THEN
+                ALLOCATE( tmp_particles(1:number_of_particles) )
+                READ ( 90 )  tmp_particles
+                grid_particles(kp,jp,ip)%particles(1:number_of_particles) = tmp_particles
+                DEALLOCATE( tmp_particles )
+                IF ( number_of_particles < alloc_size )  THEN
+                   grid_particles(kp,jp,ip)%particles(number_of_particles+1:alloc_size) &
+                      = zero_particle
+                ENDIF
+             ELSE
+                grid_particles(kp,jp,ip)%particles(1:alloc_size) = zero_particle
+             ENDIF
 
-    READ ( 90 )  prt_count, prt_start_index
-    READ ( 90 )  particles
+             maximum_number_of_particles = maximum_number_of_particles + alloc_size
 
-    IF ( use_particle_tails )  THEN
-       ALLOCATE( particle_tail_coordinates(maximum_number_of_tailpoints,5, &
-                 maximum_number_of_tails),                                 &
-                 new_tail_id(maximum_number_of_tails),                     &
-                 tail_mask(maximum_number_of_tails) )
-       READ ( 90 )  particle_tail_coordinates
-    ENDIF
+          ENDDO
+       ENDDO
+    ENDDO
+
+!
+!-- particle tails currently not available
+!    IF ( use_particle_tails )  THEN
+!       ALLOCATE( particle_tail_coordinates(maximum_number_of_tailpoints,5, &
+!                 maximum_number_of_tails),                                 &
+!                 new_tail_id(maximum_number_of_tails),                     &
+!                 tail_mask(maximum_number_of_tails) )
+!       READ ( 90 )  particle_tail_coordinates
+!    ENDIF
 
     CLOSE ( 90 )
+!
+!-- 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
 
 
