Index: palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/urban_surface_mod.f90	(revision 2296)
+++ palm/trunk/SOURCE/urban_surface_mod.f90	(revision 2317)
@@ -21,5 +21,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! Get topography top index via Function call 
 ! 
 ! Former revisions:
@@ -603,8 +603,6 @@
 !
 !--                 Find topography top index
-                    k_topo = MAXLOC( MERGE( 1, 0,                              &
-                                             BTEST( wall_flags_0(:,j,i), 12 )  &
-                                           ), DIM = 1                          &
-                                   ) - 1
+                    k_topo = get_topography_top_index( j, i, 's' )
+
                     DO k = nzt+1, 0, -1
                         IF ( lad_s(k,j,i) /= 0.0_wp )  THEN
@@ -706,12 +704,6 @@
                  DO  j = ijdb(3,ids), ijdb(4,ids)
 
-                    k_topo =   MAXLOC( MERGE( 1, 0,                            &
-                                             BTEST( wall_flags_0(:,j,i), 12 )  &
-                                            ), DIM = 1                         &
-                                     ) - 1
-                    k_topo2 =  MAXLOC( MERGE( 1, 0,                            &
-                                             BTEST( wall_flags_0(:,j-jdir(ids),i-idir(ids)), 12 )  &
-                                            ), DIM = 1                         &
-                                     ) - 1 
+                    k_topo  = get_topography_top_index( j, i, 's' )
+                    k_topo2 = get_topography_top_index( j-jdir(ids), i-idir(ids), 's' )
 
                     k = nzut - MAX( k_topo, k_topo2 )
@@ -732,8 +724,6 @@
 !
 !--                 Find topography top index
-                    k_topo = MAXLOC( MERGE( 1, 0,                              &
-                                             BTEST( wall_flags_0(:,j,i), 12 )  &
-                                          ), DIM = 1                           &
-                                   ) - 1
+                    k_topo = get_topography_top_index( j, i, 's' )
+
                     DO k = k_topo + 1, pct(j,i)
                         ipcgb = ipcgb + 1
@@ -813,12 +803,7 @@
                 DO i = ijdb(1,ids), ijdb(2,ids)
                     DO j = ijdb(3,ids), ijdb(4,ids)
-                        k_topo =   MAXLOC( MERGE( 1, 0,                        &
-                                             BTEST( wall_flags_0(:,j,i), 12 )  &
-                                                ), DIM = 1                     &
-                                         ) - 1
-                        k_topo2 =  MAXLOC( MERGE( 1, 0,                        &
-                                             BTEST( wall_flags_0(:,j-jdir(ids),i-idir(ids)), 12 )  &
-                                                ), DIM = 1                     &
-                                         ) - 1 
+                        k_topo  = get_topography_top_index( j, i, 's' )
+                        k_topo2 = get_topography_top_index( j-jdir(ids), i-idir(ids), 's' )
+
                         DO k = MAX(k_topo,k_topo2)+1, nzut
                             isurf = isurf + 1
@@ -1929,9 +1914,5 @@
             DO i = nxl, nxr
                 DO j = nys, nyn
-                    k = MAXLOC(                                                &
-                                MERGE( 1, 0,                                   &
-                                       BTEST( wall_flags_0(:,j,i), 12 )        &
-                                     ), DIM = 1                                &
-                              ) - 1
+                    k = get_topography_top_index( j, i, 's' )
 
                     usm_lad(k:nzut, j, i) = lad_s(0:nzut-k, j, i)
@@ -3806,10 +3787,5 @@
 !
 !--             Following expression equals former kk = k - nzb_s_inner(j,i) 
-                kk = k - ( MAXLOC(                                             &
-                                MERGE( 1, 0,                                   &
-                                       BTEST( wall_flags_0(:,j,i), 12 )        &
-                                     ), DIM = 1                                &
-                               ) - 1                                           &
-                         )  !- lad arrays are defined flat
+                kk = k - ( get_topography_top_index( j, i, 's' ) )  !- lad arrays are defined flat
                 pc_heating_rate(kk, j, i) = (pcbinsw(ipcgb) + pcbinlw(ipcgb)) &
                     * pchf_prep(k) * pt(k, j, i) !-- = dT/dt
