Index: palm/trunk/SOURCE/pmc_interface_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_interface_mod.f90	(revision 2282)
+++ palm/trunk/SOURCE/pmc_interface_mod.f90	(revision 2283)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Bugfixes in inititalization of log-law correction concerning 
+! new topography concept
+! 
+! 2281 2017-06-13 11:34:50Z suehring
 ! Bugfix, add pre-preprocessor directives to enable non-parrallel mode
 ! 
@@ -1320,37 +1324,35 @@
        IMPLICIT NONE
 
-       INTEGER(iwp) ::  direction    !:  Wall normal index: 1=k, 2=j, 3=i.
-       INTEGER(iwp) ::  end_index    !:  End index of present surface data type
-       INTEGER(iwp) ::  i            !:
-       INTEGER(iwp) ::  icorr        !:
-       INTEGER(iwp) ::  inc          !:  Wall outward-normal index increment -1
-                                     !: or 1, for direction=1, inc=1 always
-       INTEGER(iwp) ::  iw           !:
-       INTEGER(iwp) ::  j            !:
-       INTEGER(iwp) ::  jcorr        !:
-       INTEGER(iwp) ::  jw           !:
-       INTEGER(iwp) ::  k            !:
-       INTEGER(iwp) ::  k_wall_u_ji    !:
-       INTEGER(iwp) ::  k_wall_u_ji_p  !:
-       INTEGER(iwp) ::  k_wall_u_ji_m  !:
-       INTEGER(iwp) ::  k_wall_v_ji    !:
-       INTEGER(iwp) ::  k_wall_v_ji_p  !:
-       INTEGER(iwp) ::  k_wall_v_ji_m  !:
-       INTEGER(iwp) ::  k_wall_w_ji    !:
-       INTEGER(iwp) ::  k_wall_w_ji_p  !:
-       INTEGER(iwp) ::  k_wall_w_ji_m  !:
-       INTEGER(iwp) ::  kb           !:
-       INTEGER(iwp) ::  kcorr        !:
-       INTEGER(iwp) ::  lc           !:
-       INTEGER(iwp) ::  m            !: Running index for surface data type
-       INTEGER(iwp) ::  ni           !:
-       INTEGER(iwp) ::  nj           !:
-       INTEGER(iwp) ::  nk           !:
-       INTEGER(iwp) ::  nzt_topo_max !:
-       INTEGER(iwp) ::  start_index  !:  Start index of present surface data type
-       INTEGER(iwp) ::  wall_index   !:  Index of the wall-node coordinate
-
-       REAL(wp)     ::  z0_topo      !:  roughness at vertical walls
-       REAL(wp), ALLOCATABLE, DIMENSION(:) ::  lcr   !:
+       INTEGER(iwp) ::  direction      !<  Wall normal index: 1=k, 2=j, 3=i.
+       INTEGER(iwp) ::  i              !<
+       INTEGER(iwp) ::  icorr          !<
+       INTEGER(iwp) ::  inc            !<  Wall outward-normal index increment -1
+                                       !< or 1, for direction=1, inc=1 always
+       INTEGER(iwp) ::  iw             !<
+       INTEGER(iwp) ::  j              !<
+       INTEGER(iwp) ::  jcorr          !<
+       INTEGER(iwp) ::  jw             !<
+       INTEGER(iwp) ::  k              !<
+       INTEGER(iwp) ::  k_wall_u_ji    !< topography top index on u-grid
+       INTEGER(iwp) ::  k_wall_u_ji_p  !< topography top index on u-grid
+       INTEGER(iwp) ::  k_wall_u_ji_m  !< topography top index on u-grid
+       INTEGER(iwp) ::  k_wall_v_ji    !< topography top index on v-grid
+       INTEGER(iwp) ::  k_wall_v_ji_p  !< topography top index on v-grid
+       INTEGER(iwp) ::  k_wall_v_ji_m  !< topography top index on v-grid
+       INTEGER(iwp) ::  k_wall_w_ji    !< topography top index on w-grid
+       INTEGER(iwp) ::  k_wall_w_ji_p  !< topography top index on w-grid
+       INTEGER(iwp) ::  k_wall_w_ji_m  !< topography top index on w-grid
+       INTEGER(iwp) ::  kb             !<
+       INTEGER(iwp) ::  kcorr          !<
+       INTEGER(iwp) ::  lc             !<
+       INTEGER(iwp) ::  m              !< Running index for surface data type
+       INTEGER(iwp) ::  ni             !<
+       INTEGER(iwp) ::  nj             !<
+       INTEGER(iwp) ::  nk             !<
+       INTEGER(iwp) ::  nzt_topo_max   !<
+       INTEGER(iwp) ::  wall_index     !<  Index of the wall-node coordinate
+
+       REAL(wp)     ::  z0_topo      !<  roughness at vertical walls
+       REAL(wp), ALLOCATABLE, DIMENSION(:) ::  lcr   !<
 
 !
@@ -1452,5 +1454,5 @@
                   MAXLOC(                                                      &
                           MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 12 )  &
+                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 12 )    &
                                ), DIM = 1                                      &
                         ) - 1          )
@@ -1460,5 +1462,5 @@
                   MAXLOC(                                                      &
                           MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 14 )  &
+                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 14 )    &
                                ), DIM = 1                                      &
                         ) - 1          )
@@ -1468,5 +1470,5 @@
                   MAXLOC(                                                      &
                           MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 16 )  &
+                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 16 )    &
                                ), DIM = 1                                      &
                         ) - 1          )
@@ -1476,5 +1478,5 @@
                   MAXLOC(                                                      &
                           MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 18 )  &
+                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 18 )    &
                                ), DIM = 1                                      &
                         ) - 1          )
@@ -1494,5 +1496,5 @@
                   MAXLOC(                                                      &
                           MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 12 )  &
+                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 12 )    &
                                ), DIM = 1                                      &
                         ) - 1          )
@@ -1502,5 +1504,5 @@
                   MAXLOC(                                                      &
                           MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 14 )  &
+                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 14 )    &
                                ), DIM = 1                                      &
                         ) - 1          )
@@ -1510,5 +1512,5 @@
                   MAXLOC(                                                      &
                           MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 16 )  &
+                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 16 )    &
                                ), DIM = 1                                      &
                         ) - 1          )
@@ -1518,5 +1520,5 @@
                   MAXLOC(                                                      &
                           MERGE( 1, 0,                                         &
-                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 18 )  &
+                                 BTEST( wall_flags_0(nzb:nzb_max,j,i), 18 )    &
                                ), DIM = 1                                      &
                         ) - 1          )
@@ -1544,4 +1546,6 @@
        ALLOCATE( lcr(0:ncorr-1) )
        lcr = 1.0_wp
+
+       z0_topo = roughness_length
 
 !
@@ -1572,48 +1576,17 @@
 !
 !--          For loglaw correction the roughness z0 is required. z0, however, 
-!--          is part of the surfacetypes now, so call subroutine according
-!--          to the present surface tpye. 
-!--          Default surface type
-             IF ( surf_def_h(0)%start_index(j,i) <=                            &
-                  surf_def_h(0)%end_index(j,i) )  THEN
-                start_index = surf_def_h(0)%start_index(j,i)
-                end_index   = surf_def_h(0)%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_def_h(0)%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_def_h(0)%z0(m), &
+!--          is part of the surfacetypes now. Set default roughness instead. 
+!--          Determine topography top index on u-grid
+             kb  = MAXLOC( MERGE( 1, 0,                                        &
+                          BTEST( wall_flags_0(nzb:nzt_topo_nestbc_l,j,i), 14 ) &
+                                ), DIM = 1                                     &
+                         ) - 1
+             k   = kb + 1
+             wall_index = kb
+
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,        &
+                            j, inc, wall_index, z0_topo,                       &
                             kb, direction, ncorr )
-                ENDDO
-!
-!--          Natural surface type
-             ELSEIF ( surf_lsm_h%start_index(j,i) <=                           &
-                      surf_lsm_h%end_index(j,i) )  THEN
-                start_index = surf_lsm_h%start_index(j,i)
-                end_index   = surf_lsm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_lsm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_lsm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Urban surface type
-             ELSEIF ( surf_usm_h%start_index(j,i) <=                           &
-                      surf_usm_h%end_index(j,i) )  THEN
-                start_index = surf_usm_h%start_index(j,i)
-                end_index = surf_usm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_usm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_usm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-             ENDIF
+
              logc_u_l(1,k,j) = lc
              logc_ratio_u_l(1,0:ncorr-1,k,j) = lcr(0:ncorr-1)
@@ -1623,49 +1596,16 @@
              i   = -1
 !
-!--          For loglaw correction the roughness z0 is required. z0, however, 
-!--          is part of the surfacetypes now, so call subroutine according
-!--          to the present surface tpye. 
-!--          Default surface type
-             IF ( surf_def_h(0)%start_index(j,i) <=                            &
-                  surf_def_h(0)%end_index(j,i) )  THEN
-                start_index = surf_def_h(0)%start_index(j,i)
-                end_index   = surf_def_h(0)%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_def_h(0)%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_def_h(0)%z0(m), &
+!--          Determine topography top index on v-grid
+             kb  = MAXLOC( MERGE( 1, 0,                                        &
+                          BTEST( wall_flags_0(nzb:nzt_topo_nestbc_l,j,i), 16 ) &
+                                ), DIM = 1                                     &
+                         ) - 1
+             k   = kb + 1
+             wall_index = kb
+
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,        &
+                            j, inc, wall_index, z0_topo,                       &
                             kb, direction, ncorr )
-                ENDDO
-!
-!--          Natural surface type
-             ELSEIF ( surf_lsm_h%start_index(j,i) <=                           &
-                      surf_lsm_h%end_index(j,i) )  THEN
-                start_index = surf_lsm_h%start_index(j,i)
-                end_index   = surf_lsm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_lsm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_lsm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Urban surface type
-             ELSEIF ( surf_usm_h%start_index(j,i) <=                           &
-                      surf_usm_h%end_index(j,i) )  THEN
-                start_index = surf_usm_h%start_index(j,i)
-                end_index = surf_usm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_usm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_usm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-             ENDIF
+
              logc_v_l(1,k,j) = lc
              logc_ratio_v_l(1,0:ncorr-1,k,j) = lcr(0:ncorr-1)
@@ -1703,46 +1643,15 @@
 !--          is part of the surfacetypes now, so call subroutine according
 !--          to the present surface tpye. 
-!--          Default surface type
-             IF ( surf_def_h(0)%start_index(j,i) <=                            &
-                  surf_def_h(0)%end_index(j,i) )  THEN
-                start_index = surf_def_h(0)%start_index(j,i)
-                end_index   = surf_def_h(0)%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_def_h(0)%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_def_h(0)%z0(m), &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Natural surface type
-             ELSEIF ( surf_lsm_h%start_index(j,i) <=                           &
-                      surf_lsm_h%end_index(j,i) )  THEN
-                start_index = surf_lsm_h%start_index(j,i)
-                end_index   = surf_lsm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_lsm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_lsm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Urban surface type
-             ELSEIF ( surf_usm_h%start_index(j,i) <=                           &
-                      surf_usm_h%end_index(j,i) )  THEN
-                start_index = surf_usm_h%start_index(j,i)
-                end_index = surf_usm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_usm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_usm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-             ENDIF
+!--          Determine topography top index on u-grid
+             kb  = MAXLOC( MERGE( 1, 0,                                        &
+                          BTEST( wall_flags_0(nzb:nzt_topo_nestbc_l,j,i), 14 ) &
+                                ), DIM = 1                                     &
+                         ) - 1
+             k   = kb + 1
+             wall_index = kb
+
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,        &
+                                                 j, inc, wall_index, z0_topo,  &
+                                                 kb, direction, ncorr )
 
              logc_u_r(1,k,j) = lc
@@ -1753,49 +1662,16 @@
              i   = nxr + 1
 !
-!--          For loglaw correction the roughness z0 is required. z0, however, 
-!--          is part of the surfacetypes now, so call subroutine according
-!--          to the present surface tpye. 
-!--          Default surface type
-             IF ( surf_def_h(0)%start_index(j,i) <=                            &
-                  surf_def_h(0)%end_index(j,i) )  THEN
-                start_index = surf_def_h(0)%start_index(j,i)
-                end_index   = surf_def_h(0)%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_def_h(0)%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_def_h(0)%z0(m), &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Natural surface type
-             ELSEIF ( surf_lsm_h%start_index(j,i) <=                           &
-                      surf_lsm_h%end_index(j,i) )  THEN
-                start_index = surf_lsm_h%start_index(j,i)
-                end_index   = surf_lsm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_lsm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_lsm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Urban surface type
-             ELSEIF ( surf_usm_h%start_index(j,i) <=                           &
-                      surf_usm_h%end_index(j,i) )  THEN
-                start_index = surf_usm_h%start_index(j,i)
-                end_index = surf_usm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_usm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_usm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-             ENDIF
+!--          Determine topography top index on v-grid
+             kb  = MAXLOC( MERGE( 1, 0,                                        &
+                          BTEST( wall_flags_0(nzb:nzt_topo_nestbc_l,j,i), 16 ) &
+                                ), DIM = 1                                     &
+                         ) - 1
+             k   = kb + 1
+             wall_index = kb
+
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,        &
+                                                 j, inc, wall_index, z0_topo,  &
+                                                 kb, direction, ncorr )
+
              logc_v_r(1,k,j) = lc
              logc_ratio_v_r(1,0:ncorr-1,k,j) = lcr(0:ncorr-1)
@@ -1830,49 +1706,16 @@
              j   = -1
 !
-!--          For loglaw correction the roughness z0 is required. z0, however, 
-!--          is part of the surfacetypes now, so call subroutine according
-!--          to the present surface tpye. 
-!--          Default surface type
-             IF ( surf_def_h(0)%start_index(j,i) <=                            &
-                  surf_def_h(0)%end_index(j,i) )  THEN
-                start_index = surf_def_h(0)%start_index(j,i)
-                end_index   = surf_def_h(0)%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_def_h(0)%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_def_h(0)%z0(m), &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Natural surface type
-             ELSEIF ( surf_lsm_h%start_index(j,i) <=                           &
-                      surf_lsm_h%end_index(j,i) )  THEN
-                start_index = surf_lsm_h%start_index(j,i)
-                end_index   = surf_lsm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_lsm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_lsm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Urban surface type
-             ELSEIF ( surf_usm_h%start_index(j,i) <=                           &
-                      surf_usm_h%end_index(j,i) )  THEN
-                start_index = surf_usm_h%start_index(j,i)
-                end_index = surf_usm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_usm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_usm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-             ENDIF
+!--          Determine topography top index on u-grid
+             kb  = MAXLOC( MERGE( 1, 0,                                        &
+                          BTEST( wall_flags_0(nzb:nzt_topo_nestbc_l,j,i), 14 ) &
+                                ), DIM = 1                                     &
+                         ) - 1
+             k   = kb + 1
+             wall_index = kb
+
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,        &
+                                                 j, inc, wall_index, z0_topo,  &
+                                                 kb, direction, ncorr )
+
              logc_u_s(1,k,i) = lc
              logc_ratio_u_s(1,0:ncorr-1,k,i) = lcr(0:ncorr-1)
@@ -1882,49 +1725,16 @@
              j   = 0
 !
-!--          For loglaw correction the roughness z0 is required. z0, however, 
-!--          is part of the surfacetypes now, so call subroutine according
-!--          to the present surface tpye. 
-!--          Default surface type
-             IF ( surf_def_h(0)%start_index(j,i) <=                            &
-                  surf_def_h(0)%end_index(j,i) )  THEN
-                start_index = surf_def_h(0)%start_index(j,i)
-                end_index   = surf_def_h(0)%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_def_h(0)%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_def_h(0)%z0(m), &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Natural surface type
-             ELSEIF ( surf_lsm_h%start_index(j,i) <=                           &
-                      surf_lsm_h%end_index(j,i) )  THEN
-                start_index = surf_lsm_h%start_index(j,i)
-                end_index   = surf_lsm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_lsm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_lsm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Urban surface type
-             ELSEIF ( surf_usm_h%start_index(j,i) <=                           &
-                      surf_usm_h%end_index(j,i) )  THEN
-                start_index = surf_usm_h%start_index(j,i)
-                end_index = surf_usm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_usm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_usm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-             ENDIF
+!--          Determine topography top index on v-grid
+             kb  = MAXLOC( MERGE( 1, 0,                                        &
+                          BTEST( wall_flags_0(nzb:nzt_topo_nestbc_l,j,i), 16 ) &
+                                ), DIM = 1                                     &
+                         ) - 1
+             k   = kb + 1
+             wall_index = kb
+
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,        &
+                                                 j, inc, wall_index, z0_topo,  &
+                                                 kb, direction, ncorr )
+
              logc_v_s(1,k,i) = lc
              logc_ratio_v_s(1,0:ncorr-1,k,i) = lcr(0:ncorr-1)
@@ -1959,49 +1769,16 @@
              j   = nyn + 1
 !
-!--          For loglaw correction the roughness z0 is required. z0, however, 
-!--          is part of the surfacetypes now, so call subroutine according
-!--          to the present surface tpye. 
-!--          Default surface type
-             IF ( surf_def_h(0)%start_index(j,i) <=                            &
-                  surf_def_h(0)%end_index(j,i) )  THEN
-                start_index = surf_def_h(0)%start_index(j,i)
-                end_index   = surf_def_h(0)%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_def_h(0)%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_def_h(0)%z0(m), &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Natural surface type
-             ELSEIF ( surf_lsm_h%start_index(j,i) <=                           &
-                      surf_lsm_h%end_index(j,i) )  THEN
-                start_index = surf_lsm_h%start_index(j,i)
-                end_index   = surf_lsm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_lsm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_lsm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Urban surface type
-             ELSEIF ( surf_usm_h%start_index(j,i) <=                           &
-                      surf_usm_h%end_index(j,i) )  THEN
-                start_index = surf_usm_h%start_index(j,i)
-                end_index = surf_usm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_usm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_usm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-             ENDIF
+!--          Determine topography top index on v-grid
+             kb  = MAXLOC( MERGE( 1, 0,                                        &
+                          BTEST( wall_flags_0(nzb:nzt_topo_nestbc_l,j,i), 14 ) &
+                                ), DIM = 1                                     &
+                         ) - 1
+             k   = kb + 1
+             wall_index = kb
+
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,        &
+                                                 j, inc, wall_index, z0_topo,  &
+                                                 kb, direction, ncorr )
+
              logc_u_n(1,k,i) = lc
              logc_ratio_u_n(1,0:ncorr-1,k,i) = lcr(0:ncorr-1)
@@ -2011,49 +1788,15 @@
              j   = nyn + 1
 !
-!--          For loglaw correction the roughness z0 is required. z0, however, 
-!--          is part of the surfacetypes now, so call subroutine according
-!--          to the present surface tpye. 
-!--          Default surface type
-             IF ( surf_def_h(0)%start_index(j,i) <=                            &
-                  surf_def_h(0)%end_index(j,i) )  THEN
-                start_index = surf_def_h(0)%start_index(j,i)
-                end_index   = surf_def_h(0)%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_def_h(0)%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_def_h(0)%z0(m), &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Natural surface type
-             ELSEIF ( surf_lsm_h%start_index(j,i) <=                           &
-                      surf_lsm_h%end_index(j,i) )  THEN
-                start_index = surf_lsm_h%start_index(j,i)
-                end_index   = surf_lsm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_lsm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_lsm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-!
-!--          Urban surface type
-             ELSEIF ( surf_usm_h%start_index(j,i) <=                           &
-                      surf_usm_h%end_index(j,i) )  THEN
-                start_index = surf_usm_h%start_index(j,i)
-                end_index = surf_usm_h%end_index(j,i)
-                DO  m = start_index, end_index
-                   k          = surf_usm_h%k(m)
-                   wall_index = k - 1 
-                   kb         = k - 1
-                   CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,  &
-                            j, inc, wall_index, surf_usm_h%z0(m),    &
-                            kb, direction, ncorr )
-                ENDDO
-             ENDIF
+!--          Determine topography top index on v-grid
+             kb  = MAXLOC( MERGE( 1, 0,                                        &
+                          BTEST( wall_flags_0(nzb:nzt_topo_nestbc_l,j,i), 16 ) &
+                                ), DIM = 1                                     &
+                         ) - 1
+             k   = kb + 1
+             wall_index = kb
+
+             CALL pmci_define_loglaw_correction_parameters( lc, lcr, k,        &
+                                                 j, inc, wall_index, z0_topo,  &
+                                                 kb, direction, ncorr )
              logc_v_n(1,k,i) = lc
              logc_ratio_v_n(1,0:ncorr-1,k,i) = lcr(0:ncorr-1)
@@ -5671,5 +5414,5 @@
 !--          For simplicity anterpolate within buildings and under elevated
 !--          terrain too
-             DO  kk = kcb, kct-1
+             DO  kk = kcb, kct
 !
 !--             ijfc and kfc are precomputed in pmci_init_anterp_tophat
@@ -5690,5 +5433,4 @@
 
              ENDDO
-             fc(kct,jj,ii) = fc(kct,jj,ii)
 
           ENDDO
