Index: palm/trunk/SOURCE/disturb_heatflux.f90
===================================================================
--- palm/trunk/SOURCE/disturb_heatflux.f90	(revision 2101)
+++ palm/trunk/SOURCE/disturb_heatflux.f90	(revision 2232)
@@ -20,5 +20,7 @@
 ! Current revisions:
 ! ------------------
-! 
+! Adjustment according new surface data type.
+! Implemented parallel random number generator to obtain always the same 
+! random number distribution regardless of the processor distribution.
 ! 
 ! Former revisions:
@@ -60,16 +62,13 @@
 !> Generate random, normally distributed heatflux values and store them as the
 !> near-surface heatflux.
-!> On parallel computers, too, this random generator is called at all grid points
-!> of the total array in order to guarantee the same random distribution of the
-!> total array regardless of the number of processors used during the model run.
 !------------------------------------------------------------------------------!
- SUBROUTINE disturb_heatflux
+ SUBROUTINE disturb_heatflux( surf )
  
 
     USE arrays_3d,                                                             &
-        ONLY:  shf, heatflux_input_conversion
+        ONLY:  heatflux_input_conversion
         
     USE control_parameters,                                                    &
-        ONLY:  iran, surface_heatflux, wall_heatflux
+        ONLY:  iran, surface_heatflux, random_generator, wall_heatflux
         
     USE cpulog,                                                                &
@@ -79,13 +78,24 @@
     
     USE indices,                                                               &
-        ONLY:  nx, nxl, nxr, ny, nyn, nys, nzb, nzb_s_inner
+        ONLY:  nzb
+
+    USE random_generator_parallel,                                             &
+        ONLY:  random_number_parallel, random_seed_parallel, random_dummy,     &
+               id_random_array, seq_random_array
+
+    USE surface_mod,                                                           &
+        ONLY:  surf_type
 
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  j  !<
-    INTEGER(iwp) ::  i  !<
+    INTEGER(iwp) ::  i  !< grid index, x direction
+    INTEGER(iwp) ::  j  !< grid index, y direction
+    INTEGER(iwp) ::  k  !< grid index, z direction
+    INTEGER(iwp) ::  m  !< loop variables over surface elements
     
     REAL(wp) ::  random_gauss  !<
     REAL(wp) ::  randomnumber  !<
+
+    TYPE(surf_type) ::  surf   !< surface-type variable
 
 
@@ -93,26 +103,51 @@
 
 !
-!-- Generate random disturbances and store them
-    DO  i = 0, nx
-       DO  j = 0, ny
-          randomnumber = random_gauss( iran, 5.0_wp )
-          IF ( nxl <= i  .AND.  nxr >= i  .AND.  nys <= j  .AND.  nyn >= j )   &
-          THEN
-             IF ( nzb_s_inner(j,i) == 0 )  THEN
-                shf(j,i) = randomnumber * surface_heatflux                     &
-                           * heatflux_input_conversion(nzb)
-             ELSE
+!-- Generate random disturbances and store them. Note, if 
+!-- random_generator /= 'random-parallel' it is not guaranteed to obtain  
+!-- the same random distribution if the number of processors is changed. 
+    IF ( random_generator /= 'random-parallel' )  THEN
+
+       DO  m = 1, surf%ns
+
+          k = surf%k(m)
+
+          randomnumber = random_gauss( iran, 5.0_wp )      
 !
-!--             Over topography surface_heatflux is replaced by wall_heatflux(0)
-                shf(j,i) = randomnumber * wall_heatflux(0)                     &
-                           * heatflux_input_conversion(nzb_s_inner(j,i))
-             ENDIF
+!--       k-1 is topography top index. If this is 0, set surface heatflux. Over
+!--       topography surface_heatflux is replaced by wall_heatflux(0).
+          IF ( k-1 == 0 )  THEN
+             surf%shf(m) = randomnumber * surface_heatflux                     &
+                              * heatflux_input_conversion(nzb)
+          ELSE
+             surf%shf(m) = randomnumber * wall_heatflux(0)                     &
+                              * heatflux_input_conversion(k-1)
           ENDIF
        ENDDO
-    ENDDO
+    ELSE
 
+       DO  m = 1, surf%ns
+
+          i = surf%i(m)
+          j = surf%j(m)
+          k = surf%k(m)
+
+          CALL random_seed_parallel( put=seq_random_array(:, j, i) )
+          CALL random_number_parallel( random_dummy )    
 !
-!-- Exchange lateral boundary conditions for the heatflux array
-    CALL exchange_horiz_2d( shf )
+!--       k-1 is topography top index. If this is 0, set surface heatflux. Over
+!--       topography surface_heatflux is replaced by wall_heatflux(0).
+          IF ( k-1 == 0 )  THEN
+             surf%shf(m) = ( random_dummy - 0.5_wp ) * surface_heatflux        &
+                              * heatflux_input_conversion(nzb)
+          ELSE
+             surf%shf(m) = ( random_dummy - 0.5_wp ) * wall_heatflux(0)        &
+                              * heatflux_input_conversion(k-1)
+          ENDIF
+
+          CALL random_seed_parallel( get=seq_random_array(:, j, i) )
+
+       ENDDO
+
+    ENDIF
 
     CALL cpu_log( log_point(23), 'disturb_heatflux', 'stop' )
