Index: palm/trunk/SOURCE/lpm_boundary_conds.f90
===================================================================
--- palm/trunk/SOURCE/lpm_boundary_conds.f90	(revision 2233)
+++ palm/trunk/SOURCE/lpm_boundary_conds.f90	(revision 2317)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Get topography top index via Function call 
 ! 
 ! Former revisions:
@@ -98,5 +98,5 @@
 
     USE indices,                                                               &
-        ONLY:  nxl, nxr, nyn, nys, nz, nzb, nzb_max, wall_flags_0
+        ONLY:  nxl, nxr, nyn, nys, nz, nzb
 
     USE kinds
@@ -108,4 +108,7 @@
 
     USE pegrid
+
+    USE surface_mod,                                                           &
+        ONLY:  get_topography_top_index
 
     IMPLICIT NONE
@@ -289,24 +292,8 @@
 !--       The construct of MERGE and BTEST is used to determine the topography-
 !--       top index (former nzb_s_inner). 
-          zwall1 = zw( MAXLOC(                                                 &
-                          MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j2,i2), 12 )  &
-                               ), DIM = 1                                      &
-                             ) - 1 )                                             
-          zwall2 = zw( MAXLOC(                                                 &
-                          MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j1,i1), 12 )  &
-                               ), DIM = 1                                      &
-                             ) - 1 )  
-          zwall3 = zw( MAXLOC(                                                 &
-                          MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j1,i2), 12 )  &
-                               ), DIM = 1                                      &
-                             ) - 1 )  
-          zwall4 = zw( MAXLOC(                                                 &
-                          MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j2,i1), 12 )  &
-                               ), DIM = 1                                      &
-                             ) - 1 )  
+          zwall1 = zw( get_topography_top_index( j2, i2, 's' ) )                                             
+          zwall2 = zw( get_topography_top_index( j1, i1, 's' ) ) 
+          zwall3 = zw( get_topography_top_index( j1, i2, 's' ) )
+          zwall4 = zw( get_topography_top_index( j2, i1, 's' ) )
 !
 !--       Initialize flags to check if particle reflection is necessary
@@ -493,9 +480,5 @@
 !--             necessarily exactly match the wall location due to rounding 
 !--             errors. At first, determine index of topography top at (j3,i3)  
-                k_wall = MAXLOC(                                               &
-                            MERGE( 1, 0,                                       &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j3,i3), 12 )  &
-                                 ), DIM = 1                                    &
-                               ) - 1  
+                k_wall = get_topography_top_index( j3, i3, 's' ) 
                 IF ( ABS( pos_x - xwall ) < eps      .AND.                     &
                      pos_z <= zw(k_wall)             .AND.                     &
@@ -534,9 +517,5 @@
 !--             necessary, carry out reflection. At first, determine index of
 !--             topography top at (j3,i3)  
-                k_wall = MAXLOC(                                               &
-                            MERGE( 1, 0,                                       &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j3,i3), 12 )  &
-                                 ), DIM = 1                                    &
-                               ) - 1  
+                k_wall = get_topography_top_index( j3, i3, 's' ) 
                 IF ( ABS( pos_y - ywall ) < eps      .AND.                     &
                      pos_z <= zw(k_wall)             .AND.                     &
@@ -565,9 +544,5 @@
 !--                Determine index of topography top at (j3,i3) and chick if
 !--                particle is below.  
-                   k_wall = MAXLOC(                                            &
-                          MERGE( 1, 0,                                         &
-                                   BTEST( wall_flags_0(nzb:nzb_max,j3,i3), 12 )&
-                               ), DIM = 1                                      &
-                                  ) - 1  
+                   k_wall = get_topography_top_index( j3, i3, 's' ) 
                    IF ( pos_z - zw(k_wall) < eps ) THEN
   
