Index: palm/trunk/SOURCE/data_output_dvrp.f90
===================================================================
--- palm/trunk/SOURCE/data_output_dvrp.f90	(revision 226)
+++ palm/trunk/SOURCE/data_output_dvrp.f90	(revision 242)
@@ -33,5 +33,4 @@
 ! -----------------
 ! TEST: different colours for isosurfaces
-! TEST: write statements
 !
 ! Former revisions:
@@ -90,7 +89,11 @@
     CHARACTER (LEN=2) ::  section_chr
     CHARACTER (LEN=6) ::  output_variable
-    INTEGER ::  c_mode, c_size_x, c_size_y, c_size_z, gradient_normals, i, j, &
-                k, l, m, n, nn, section_mode, tv, vn
+    INTEGER ::  c_mode, c_size_x, c_size_y, c_size_z, dvrp_nop, dvrp_not,     &
+                gradient_normals, i, ip, j, jp, k, l, m, n, nn, section_mode, &
+                tv, vn
     INTEGER, DIMENSION(:), ALLOCATABLE ::  p_c, p_t
+
+    LOGICAL, DIMENSION(:), ALLOCATABLE ::  dvrp_mask
+
     REAL(4) ::  center(3), distance, slicer_position, surface_value,         &
                 tmp_alpha, tmp_alpha_w, tmp_b, tmp_c_alpha, tmp_g, tmp_norm, &
@@ -101,6 +104,4 @@
 
 
-    WRITE ( 9, * ) '*** myid=', myid, ' Anfang data_output_dvrp'
-    CALL local_flush( 9 )
     CALL cpu_log( log_point(27), 'data_output_dvrp', 'start' )
 
@@ -117,9 +118,5 @@
 !--       Set lock to avoid recursive calls of DVRP_STEERING_UPDATE
           lock_steering_update = .TRUE.
-!   WRITE ( 9, * ) '*** myid=', myid, ' data_output_dvrp: vor steering_update'
-!   CALL local_flush( 9 )
 !          CALL DVRP_STEERING_UPDATE( m-1, data_output_dvrp )
-!   WRITE ( 9, * ) '*** myid=', myid, ' data_output_dvrp: nach steering_update'
-!   CALL local_flush( 9 )
           lock_steering_update = .FALSE.
        ENDIF
@@ -155,7 +152,4 @@
        IF ( mode_dvrp(m)(1:9) == 'particles'  .AND.  particle_advection  .AND. &
             simulated_time >= particle_advection_start )  THEN
-
-!   WRITE ( 9, * ) '*** myid=', myid, ' data_output_dvrp: anfang particles'
-!   CALL local_flush( 9 )
 !
 !--       DVRP-Calls for plotting particles:
@@ -169,31 +163,78 @@
 
 !
+!--       If clipping is active and if this subdomain is clipped, find out the
+!--       number of particles and tails to be plotted; otherwise, all
+!--       particles/tails are plotted
+          IF ( .NOT. use_particle_tails )  THEN
+             ALLOCATE( dvrp_mask(number_of_particles) )
+          ELSE
+             ALLOCATE( dvrp_mask(number_of_tails*maximum_number_of_tailpoints) )
+          ENDIF
+          dvrp_mask = .TRUE.
+          IF ( dvrp_total_overlap )  THEN
+             dvrp_nop = number_of_particles
+             dvrp_not = number_of_tails
+          ELSE
+             dvrp_nop = 0
+             dvrp_not = 0
+             IF ( dvrp_overlap )  THEN
+                IF ( .NOT. use_particle_tails )  THEN
+                   DO  n = 1, number_of_particles
+                      ip = particles(n)%x / dx
+                      jp = particles(n)%y / dy
+                      IF ( ip >= nxl_dvrp  .AND.  ip <= nxr_dvrp  .AND.  &
+                           jp >= nys_dvrp  .AND.  jp <= nyn_dvrp )  THEN
+                         dvrp_nop = dvrp_nop + 1
+                      ELSE
+                         dvrp_mask(n) = .FALSE.
+                      ENDIF
+                   ENDDO
+                ELSE
+                   k = 0
+                   DO  n = 1, number_of_particles
+                      IF ( particles(n)%tail_id /= 0 )  THEN
+                         k = k + 1
+                         ip = particles(n)%x / dx
+                         jp = particles(n)%y / dy
+                         IF ( ip >= nxl_dvrp  .AND.  ip <= nxr_dvrp  .AND.  &
+                              jp >= nys_dvrp  .AND.  jp <= nyn_dvrp )  THEN
+                            dvrp_not = dvrp_not + 1
+                         ELSE
+                            dvrp_mask(k) = .FALSE.
+                         ENDIF
+                      ENDIF
+                   ENDDO
+                ENDIF
+             ENDIF
+          ENDIF
+
+!
 !--       Move particle coordinates to one-dimensional arrays
           IF ( .NOT. use_particle_tails )  THEN
 !
 !--          All particles are output
-             ALLOCATE( psize(number_of_particles), p_t(number_of_particles), &
-                       p_c(number_of_particles), p_x(number_of_particles),   &
-                       p_y(number_of_particles), p_z(number_of_particles) )
+             ALLOCATE( psize(dvrp_nop), p_t(dvrp_nop), p_c(dvrp_nop), &
+                       p_x(dvrp_nop), p_y(dvrp_nop), p_z(dvrp_nop) )
              psize = 0.0;  p_t = 0;  p_c = 0.0;  p_x = 0.0;  p_y = 0.0
-             p_z   = 0.0;
-             psize = particles(1:number_of_particles)%dvrp_psize
-             p_x   = particles(1:number_of_particles)%x * superelevation_x
-             p_y   = particles(1:number_of_particles)%y * superelevation_y
-             p_z   = particles(1:number_of_particles)%z * superelevation
-             p_c   = particles(1:number_of_particles)%color
+             p_z   = 0.0
+             k = 0
+             DO  n = 1, number_of_particles
+                IF ( dvrp_mask(n) )  THEN
+                   k = k + 1
+                   psize(k) = particles(n)%dvrp_psize
+                   p_x(k)   = particles(n)%x * superelevation_x
+                   p_y(k)   = particles(n)%y * superelevation_y
+                   p_z(k)   = particles(n)%z * superelevation
+                   p_c(k)   = particles(n)%color
+                ENDIF
+             ENDDO
           ELSE
 !
 !--          Particles have a tail
-!            WRITE (9,*) '--- before ALLOCATE  simtime=',simulated_time,' #of_tails=', number_of_tails, &
-!                          ' max#of_tp=', maximum_number_of_tailpoints
-!   CALL local_flush( 9 )
-             ALLOCATE( psize(number_of_tails), p_t(number_of_tails),      &
-                       p_c(number_of_tails*maximum_number_of_tailpoints), &
-                       p_x(number_of_tails*maximum_number_of_tailpoints), &
-                       p_y(number_of_tails*maximum_number_of_tailpoints), &
-                       p_z(number_of_tails*maximum_number_of_tailpoints) )
-!            WRITE (9,*) '--- after ALLOCATE'
-!   CALL local_flush( 9 )
+             ALLOCATE( psize(dvrp_not), p_t(dvrp_not),             &
+                       p_c(dvrp_not*maximum_number_of_tailpoints), &
+                       p_x(dvrp_not*maximum_number_of_tailpoints), &
+                       p_y(dvrp_not*maximum_number_of_tailpoints), &
+                       p_z(dvrp_not*maximum_number_of_tailpoints) )
              psize = 0.0;  p_t = 0;  p_c = 0.0;  p_x = 0.0;  p_y = 0.0
              p_z   = 0.0;
@@ -202,10 +243,6 @@
              DO  n = 1, number_of_particles
                 nn = particles(n)%tail_id
-                IF ( nn /= 0 )  THEN
+                IF ( nn /= 0  .AND.  dvrp_mask(n) )  THEN
                    k = k + 1
-!                  IF ( simulated_time > 1338.0 )  THEN
-!                     WRITE (9,*) '--- particle ',n,' tail_id=',nn,' #of_tp=',particles(n)%tailpoints
-!   CALL local_flush( 9 )
-!                  ENDIF
                    DO  j = 1, particles(n)%tailpoints
                       i = i + 1
@@ -217,20 +254,9 @@
                                                                 superelevation
                       p_c(i) = particle_tail_coordinates(j,4,nn)
-!                     IF ( simulated_time > 1338.0 )  THEN
-!                        WRITE (9,*) '--- tp= ',i,' x=',p_x(i),' y=',p_y(i), &
-!                                                ' z=',p_z(i),' c=',p_c(i)
-!   CALL local_flush( 9 )
-!                     ENDIF
                    ENDDO
                    psize(k) = particles(n)%dvrp_psize
                    p_t(k)   = particles(n)%tailpoints - 1
-!                  IF ( simulated_time > 1338.0 )  THEN
-!                     WRITE (9,*) '--- t= ',k,' psize=',psize(k),' p_t=',p_t(k)
-!   CALL local_flush( 9 )
-!                  ENDIF
                 ENDIF                
              ENDDO
-!            WRITE (9,*) '--- after locally storing the particle attributes'
-!   CALL local_flush( 9 )
           ENDIF
 
@@ -252,30 +278,15 @@
 
              IF ( .NOT. use_particle_tails )  THEN
-                CALL DVRP_PARTICLES( m-1, number_of_particles, p_x, p_y, p_z, &
-                                     3, psize, p_c, p_t )
+                CALL DVRP_PARTICLES( m-1, dvrp_nop, p_x, p_y, p_z, 3, psize, &
+                                     p_c, p_t )
              ELSE
-!               WRITE (9,*) '--- before DVRP_PARTICLES'
-!   CALL local_flush( 9 )
-                CALL DVRP_PARTICLES( m-1, number_of_tails, p_x, p_y, p_z, 15, &
-                                     psize, p_c, p_t )
-!               WRITE (9,*) '--- after DVRP_PARTICLES'
-!               WRITE (9,*) 'm-1 = ',m-1
-!               WRITE (9,*) 'number_of_tails=', number_of_tails
-!               WRITE (9,*) 'p_x =', p_x
-!               WRITE (9,*) 'p_y =', p_y
-!               WRITE (9,*) 'p_z =', p_z
-!               WRITE (9,*) 'psize =', psize
-!               WRITE (9,*) 'p_c =', p_c
-!               WRITE (9,*) 'p_t =', p_t
-
-!   CALL local_flush( 9 )
+                CALL DVRP_PARTICLES( m-1, dvrp_not, p_x, p_y, p_z, 15, psize, &
+                                     p_c, p_t )
              ENDIF
           ENDIF
 
           CALL DVRP_VISUALIZE( m-1, 3, dvrp_filecount )
-!   WRITE ( 9, * ) '*** myid=', myid, ' data_output_dvrp: ende particles'
-!   CALL local_flush( 9 )
-
-          DEALLOCATE( psize, p_c, p_t, p_x, p_y, p_z )
+
+          DEALLOCATE( dvrp_mask, psize, p_c, p_t, p_x, p_y, p_z )
 
           CALL cpu_log( log_point_s(28), 'dvrp_particles', 'stop' )
@@ -436,7 +447,4 @@
 
           IF ( mode_dvrp(m)(1:10) == 'isosurface' )  THEN
-
-!   WRITE ( 9, * ) '*** myid=', myid, ' data_output_dvrp: anfang isosurface'
-!   CALL local_flush( 9 )
 !
 !--          DVRP-Calls for plotting isosurfaces:
@@ -485,13 +493,7 @@
              CALL DVRP_VISUALIZE( m-1, 21, dvrp_filecount )
 
-!   WRITE ( 9, * ) '*** myid=', myid, ' data_output_dvrp: ende isosurface'
-!   CALL local_flush( 9 )
-
              CALL cpu_log( log_point_s(26), 'dvrp_isosurface', 'stop' )
 
           ELSEIF ( mode_dvrp(m)(1:6) == 'slicer' )  THEN
-
-!   WRITE ( 9, * ) '*** myid=', myid, ' data_output_dvrp: anfang slicer'
-!   CALL local_flush( 9 )
 !
 !--          DVRP-Calls for plotting slicers:
@@ -532,6 +534,4 @@
              CALL cpu_log( log_point_s(27), 'dvrp_slicer', 'stop' )
 
-!   WRITE ( 9, * ) '*** myid=', myid, ' data_output_dvrp: ende slicer'
-!   CALL local_flush( 9 )
           ENDIF
 
@@ -578,6 +578,4 @@
 
     CALL cpu_log( log_point(27), 'data_output_dvrp', 'stop' )
-!   WRITE ( 9, * ) '*** myid=', myid, ' Ende data_output_dvrp'
-!   CALL local_flush( 9 )
 
 #endif
