Index: palm/trunk/SOURCE/radiation_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3168)
+++ palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3170)
@@ -28,4 +28,7 @@
 ! -----------------
 ! $Id$
+! Bugfix, map signle-column radiation forcing profiles on top of any topography
+! 
+! 3156 2018-07-19 16:30:54Z knoop
 ! Bugfix: replaced usage of the pt array with the surf%pt_surface array
 !
@@ -2997,8 +3000,16 @@
 
 !
-!--          Save heating rates (convert from K/d to K/h)
-             DO k = nzb+1, nzt+1
-                rad_lw_hr(k,:,:)     = rrtm_lwhr(0,k)  * d_hours_day
-                rad_lw_cs_hr(k,:,:)  = rrtm_lwhrc(0,k) * d_hours_day
+!--          Save heating rates (convert from K/d to K/h). 
+!--          Further, even though an aggregated radiation is computed, map
+!--          signle-column profiles on top of any topography, in order to 
+!--          obtain correct near surface radiation heating/cooling rates.
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   k_topo = get_topography_top_index_ji( j, i, 's' )
+                   DO k = k_topo+1, nzt+1
+                      rad_lw_hr(k,j,i)     = rrtm_lwhr(0,k)  * d_hours_day
+                      rad_lw_cs_hr(k,j,i)  = rrtm_lwhrc(0,k) * d_hours_day
+                   ENDDO
+                ENDDO
              ENDDO
 
Index: palm/trunk/SOURCE/sum_up_3d_data.f90
===================================================================
--- palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3168)
+++ palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3170)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Revise output of surface quantities in case of overhanging structures
+! 
+! 3151 2018-07-19 08:45:38Z raasch
 ! Remaining preprocessor directive __chem removed
 ! 
@@ -247,4 +250,8 @@
     IMPLICIT NONE
 
+    LOGICAL      ::  match_def !< flag indicating default-type surface
+    LOGICAL      ::  match_lsm !< flag indicating natural-type surface
+    LOGICAL      ::  match_usm !< flag indicating urban-type surface
+    
     INTEGER(iwp) ::  i   !< grid index x direction
     INTEGER(iwp) ::  ii  !< running index
@@ -571,19 +578,34 @@
           CASE ( 'ghf*' )
              IF ( ALLOCATED( ghf_av ) ) THEN
-                DO  m = 1, surf_lsm_h%ns
-                   i   = surf_lsm_h%i(m)            
-                   j   = surf_lsm_h%j(m)
-                   ghf_av(j,i) = ghf_av(j,i) + surf_lsm_h%ghf(m)
-                ENDDO
-
-                DO  m = 1, surf_usm_h%ns
-                   i   = surf_usm_h%i(m)            
-                   j   = surf_usm_h%j(m)
-                   ghf_av(j,i) = ghf_av(j,i) + surf_usm_h%frac(ind_veg_wall,m)  * &
-                                               surf_usm_h%wghf_eb(m)        +     &
-                                               surf_usm_h%frac(ind_pav_green,m) * &
-                                               surf_usm_h%wghf_eb_green(m)  +     &
-                                               surf_usm_h%frac(ind_wat_win,m)   * &
-                                               surf_usm_h%wghf_eb_window(m)
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+!
+!--                   Check whether grid point is a natural- or urban-type 
+!--                   surface.
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+!
+!--                   In order to avoid double-counting of surface properties,
+!--                   always assume that natural-type surfaces are below urban-
+!--                   type surfaces, e.g. in case of bridges.
+!--                   Further, take only the last suface element, i.e. the
+!--                   uppermost surface which would be visible from above
+                      IF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%ghf(m)
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%frac(ind_veg_wall,m)  *    &
+                                         surf_usm_h%wghf_eb(m)        +        &
+                                         surf_usm_h%frac(ind_pav_green,m) *    &
+                                         surf_usm_h%wghf_eb_green(m)  +        &
+                                         surf_usm_h%frac(ind_wat_win,m)   *    &
+                                         surf_usm_h%wghf_eb_window(m)
+                      ENDIF
+                   ENDDO
                 ENDDO
              ENDIF
@@ -645,18 +667,27 @@
           CASE ( 'ol*' )
              IF ( ALLOCATED( ol_av ) ) THEN
-                DO  m = 1, surf_def_h(0)%ns
-                   i = surf_def_h(0)%i(m)
-                   j = surf_def_h(0)%j(m)
-                   ol_av(j,i) = ol_av(j,i) + surf_def_h(0)%ol(m)
-                ENDDO
-                DO  m = 1, surf_lsm_h%ns
-                   i = surf_lsm_h%i(m)
-                   j = surf_lsm_h%j(m)
-                   ol_av(j,i) = ol_av(j,i) + surf_lsm_h%ol(m)
-                ENDDO
-                DO  m = 1, surf_usm_h%ns
-                   i = surf_usm_h%i(m)
-                   j = surf_usm_h%j(m)
-                   ol_av(j,i) = ol_av(j,i) + surf_usm_h%ol(m)
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      match_def = surf_def_h(0)%start_index(j,i) <=            &
+                                  surf_def_h(0)%end_index(j,i)
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+
+                      IF ( match_def )  THEN
+                         m = surf_def_h(0)%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_def_h(0)%ol(m)
+                      ELSEIF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%ol(m)
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%ol(m)
+                      ENDIF
+                   ENDDO
                 ENDDO
              ENDIF
@@ -842,20 +873,28 @@
 !--          dynamic units.
              IF ( ALLOCATED( qsws_av ) ) THEN 
-                DO  m = 1, surf_def_h(0)%ns
-                   i = surf_def_h(0)%i(m)
-                   j = surf_def_h(0)%j(m)
-                   k = surf_def_h(0)%k(m)
-                   qsws_av(j,i) = qsws_av(j,i) + surf_def_h(0)%qsws(m) *          &
-                                                 waterflux_output_conversion(k)
-                ENDDO
-                DO  m = 1, surf_lsm_h%ns
-                   i = surf_lsm_h%i(m)
-                   j = surf_lsm_h%j(m)
-                   qsws_av(j,i) = qsws_av(j,i) + surf_lsm_h%qsws(m) * l_v
-                ENDDO
-                DO  m = 1, surf_usm_h%ns
-                   i = surf_usm_h%i(m)
-                   j = surf_usm_h%j(m)
-                   qsws_av(j,i) = qsws_av(j,i) + surf_usm_h%qsws(m) * l_v
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      match_def = surf_def_h(0)%start_index(j,i) <=            &
+                                  surf_def_h(0)%end_index(j,i)
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+
+                      IF ( match_def )  THEN
+                         m = surf_def_h(0)%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_def_h(0)%qsws(m) *               &
+                                         waterflux_output_conversion(k)
+                      ELSEIF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%qsws(m) * l_v
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%qsws(m) * l_v
+                      ENDIF
+                   ENDDO
                 ENDDO
              ENDIF
@@ -874,24 +913,26 @@
           CASE ( 'r_a*' )
              IF ( ALLOCATED( r_a_av ) ) THEN 
-                DO  m = 1, surf_lsm_h%ns
-                   i   = surf_lsm_h%i(m)            
-                   j   = surf_lsm_h%j(m)
-                   r_a_av(j,i) = r_a_av(j,i) + surf_lsm_h%r_a(m)
-                ENDDO
-!
-!--             Please note, resistance is also applied at urban-type surfaces, 
-!--             and is output only as a single variable. Here, tile approach is
-!--             already implemented, so for each surface fraction resistance 
-!--             need to be summed-up.
-                DO  m = 1, surf_usm_h%ns
-                   i   = surf_usm_h%i(m)            
-                   j   = surf_usm_h%j(m)
-                   r_a_av(j,i) = r_a_av(j,i) +                                    &
-                              ( surf_usm_h%frac(ind_veg_wall,m)  *                &
-                                surf_usm_h%r_a(m)       +                         & 
-                                surf_usm_h%frac(ind_pav_green,m) *                &
-                                surf_usm_h%r_a_green(m) +                         & 
-                                surf_usm_h%frac(ind_wat_win,m)   *                &
-                                surf_usm_h%r_a_window(m) )
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+
+                      IF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%r_a(m)
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%frac(ind_veg_wall,m)  *    &
+                                         surf_usm_h%r_a(m)       +             & 
+                                         surf_usm_h%frac(ind_pav_green,m) *    &
+                                         surf_usm_h%r_a_green(m) +             & 
+                                         surf_usm_h%frac(ind_wat_win,m)   *    &
+                                         surf_usm_h%r_a_window(m)
+                      ENDIF
+                   ENDDO
                 ENDDO
              ENDIF
@@ -936,20 +977,28 @@
 !--          dynamic units.
              IF ( ALLOCATED( shf_av ) ) THEN 
-                DO  m = 1, surf_def_h(0)%ns
-                   i = surf_def_h(0)%i(m)
-                   j = surf_def_h(0)%j(m)
-                   k = surf_def_h(0)%k(m)
-                   shf_av(j,i) = shf_av(j,i) + surf_def_h(0)%shf(m)  *            &
-                                               heatflux_output_conversion(k)
-                ENDDO
-                DO  m = 1, surf_lsm_h%ns
-                   i = surf_lsm_h%i(m)
-                   j = surf_lsm_h%j(m)
-                   shf_av(j,i) = shf_av(j,i) + surf_lsm_h%shf(m) * cp
-                ENDDO
-                DO  m = 1, surf_usm_h%ns
-                   i = surf_usm_h%i(m)
-                   j = surf_usm_h%j(m)
-                   shf_av(j,i) = shf_av(j,i) + surf_usm_h%shf(m) * cp
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      match_def = surf_def_h(0)%start_index(j,i) <=            &
+                                  surf_def_h(0)%end_index(j,i)
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+
+                      IF ( match_def )  THEN
+                         m = surf_def_h(0)%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_def_h(0)%shf(m)  *               &
+                                         heatflux_output_conversion(k)
+                      ELSEIF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%shf(m) * cp
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%shf(m) * cp
+                      ENDIF
+                   ENDDO
                 ENDDO
              ENDIF
@@ -957,18 +1006,27 @@
           CASE ( 'ssws*' )
              IF ( ALLOCATED( ssws_av ) ) THEN 
-                DO  m = 1, surf_def_h(0)%ns
-                   i = surf_def_h(0)%i(m)
-                   j = surf_def_h(0)%j(m)
-                   ssws_av(j,i) = ssws_av(j,i) + surf_def_h(0)%ssws(m)
-                ENDDO
-                DO  m = 1, surf_lsm_h%ns
-                   i = surf_lsm_h%i(m)
-                   j = surf_lsm_h%j(m)
-                   ssws_av(j,i) = ssws_av(j,i) + surf_lsm_h%ssws(m)
-                ENDDO
-                DO  m = 1, surf_usm_h%ns
-                   i = surf_usm_h%i(m)
-                   j = surf_usm_h%j(m)
-                   ssws_av(j,i) = ssws_av(j,i) + surf_usm_h%ssws(m)
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      match_def = surf_def_h(0)%start_index(j,i) <=            &
+                                  surf_def_h(0)%end_index(j,i)
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+
+                      IF ( match_def )  THEN
+                         m = surf_def_h(0)%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_def_h(0)%ssws(m)
+                      ELSEIF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%ssws(m)
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%ssws(m)
+                      ENDIF
+                   ENDDO
                 ENDDO
              ENDIF
@@ -976,39 +1034,55 @@
           CASE ( 't*' )
              IF ( ALLOCATED( ts_av ) ) THEN 
-                DO  m = 1, surf_def_h(0)%ns
-                   i = surf_def_h(0)%i(m)
-                   j = surf_def_h(0)%j(m)
-                   ts_av(j,i) = ts_av(j,i) + surf_def_h(0)%ts(m)
-                ENDDO
-                DO  m = 1, surf_lsm_h%ns
-                   i = surf_lsm_h%i(m)
-                   j = surf_lsm_h%j(m)
-                   ts_av(j,i) = ts_av(j,i) + surf_lsm_h%ts(m)
-                ENDDO
-                DO  m = 1, surf_usm_h%ns
-                   i = surf_usm_h%i(m)
-                   j = surf_usm_h%j(m)
-                   ts_av(j,i) = ts_av(j,i) + surf_usm_h%ts(m)
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      match_def = surf_def_h(0)%start_index(j,i) <=            &
+                                  surf_def_h(0)%end_index(j,i)
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+
+                      IF ( match_def )  THEN
+                         m = surf_def_h(0)%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_def_h(0)%ts(m)
+                      ELSEIF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%ts(m)
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%ts(m)
+                      ENDIF
+                   ENDDO
                 ENDDO
              ENDIF
 
           CASE ( 'tsurf*' )
-             IF ( ALLOCATED( tsurf_av ) ) THEN             
-                DO  m = 1, surf_def_h(0)%ns
-                   i   = surf_def_h(0)%i(m)            
-                   j   = surf_def_h(0)%j(m)
-                   tsurf_av(j,i) = tsurf_av(j,i) + surf_def_h(0)%pt_surface(m)
-                ENDDO
-
-                DO  m = 1, surf_lsm_h%ns
-                   i   = surf_lsm_h%i(m)            
-                   j   = surf_lsm_h%j(m)
-                   tsurf_av(j,i) = tsurf_av(j,i) + surf_lsm_h%pt_surface(m)
-                ENDDO
-
-                DO  m = 1, surf_usm_h%ns
-                   i   = surf_usm_h%i(m)            
-                   j   = surf_usm_h%j(m)
-                   tsurf_av(j,i) = tsurf_av(j,i) + surf_usm_h%pt_surface(m)
+             IF ( ALLOCATED( tsurf_av ) ) THEN    
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      match_def = surf_def_h(0)%start_index(j,i) <=            &
+                                  surf_def_h(0)%end_index(j,i)
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+
+                      IF ( match_def )  THEN
+                         m = surf_def_h(0)%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_def_h(0)%pt_surface(m)
+                      ELSEIF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%pt_surface(m)
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%pt_surface(m)
+                      ENDIF
+                   ENDDO
                 ENDDO
              ENDIF
@@ -1027,18 +1101,27 @@
           CASE ( 'u*' )
              IF ( ALLOCATED( us_av ) ) THEN   
-                DO  m = 1, surf_def_h(0)%ns
-                   i = surf_def_h(0)%i(m)
-                   j = surf_def_h(0)%j(m)
-                   us_av(j,i) = us_av(j,i) + surf_def_h(0)%us(m)
-                ENDDO
-                DO  m = 1, surf_lsm_h%ns
-                   i = surf_lsm_h%i(m)
-                   j = surf_lsm_h%j(m)
-                   us_av(j,i) = us_av(j,i) + surf_lsm_h%us(m)
-                ENDDO
-                DO  m = 1, surf_usm_h%ns
-                   i = surf_usm_h%i(m)
-                   j = surf_usm_h%j(m)
-                   us_av(j,i) = us_av(j,i) + surf_usm_h%us(m)
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      match_def = surf_def_h(0)%start_index(j,i) <=            &
+                                  surf_def_h(0)%end_index(j,i)
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+
+                      IF ( match_def )  THEN
+                         m = surf_def_h(0)%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_def_h(0)%us(m)
+                      ELSEIF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%us(m)
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%us(m)
+                      ENDIF
+                   ENDDO
                 ENDDO
              ENDIF
@@ -1079,37 +1162,55 @@
           CASE ( 'z0*' )
              IF ( ALLOCATED( z0_av ) ) THEN 
-                DO  m = 1, surf_def_h(0)%ns
-                   i = surf_def_h(0)%i(m)
-                   j = surf_def_h(0)%j(m)
-                   z0_av(j,i) = z0_av(j,i) + surf_def_h(0)%z0(m)
-                ENDDO
-                DO  m = 1, surf_lsm_h%ns
-                   i = surf_lsm_h%i(m)
-                   j = surf_lsm_h%j(m)
-                   z0_av(j,i) = z0_av(j,i) + surf_lsm_h%z0(m)
-                ENDDO
-                DO  m = 1, surf_usm_h%ns
-                   i = surf_usm_h%i(m)
-                   j = surf_usm_h%j(m)
-                   z0_av(j,i) = z0_av(j,i) + surf_usm_h%z0(m)
-                ENDDO
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      match_def = surf_def_h(0)%start_index(j,i) <=            &
+                                  surf_def_h(0)%end_index(j,i)
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+
+                      IF ( match_def )  THEN
+                         m = surf_def_h(0)%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_def_h(0)%z0(m)
+                      ELSEIF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%z0(m)
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%z0(m)
+                      ENDIF
+                   ENDDO
+                ENDDO   
              ENDIF
 
           CASE ( 'z0h*' )
              IF ( ALLOCATED( z0h_av ) ) THEN 
-                DO  m = 1, surf_def_h(0)%ns
-                   i = surf_def_h(0)%i(m)
-                   j = surf_def_h(0)%j(m)
-                   z0h_av(j,i) = z0h_av(j,i) + surf_def_h(0)%z0h(m)
-                ENDDO
-                DO  m = 1, surf_lsm_h%ns
-                   i = surf_lsm_h%i(m)
-                   j = surf_lsm_h%j(m)
-                   z0h_av(j,i) = z0h_av(j,i) + surf_lsm_h%z0h(m)
-                ENDDO
-                DO  m = 1, surf_usm_h%ns
-                   i = surf_usm_h%i(m)
-                   j = surf_usm_h%j(m)
-                   z0h_av(j,i) = z0h_av(j,i) + surf_usm_h%z0h(m)
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      match_def = surf_def_h(0)%start_index(j,i) <=            &
+                                  surf_def_h(0)%end_index(j,i)
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+
+                      IF ( match_def )  THEN
+                         m = surf_def_h(0)%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_def_h(0)%z0h(m)
+                      ELSEIF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%z0h(m)
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%z0h(m)
+                      ENDIF
+                   ENDDO
                 ENDDO
              ENDIF
@@ -1117,18 +1218,27 @@
           CASE ( 'z0q*' )
              IF ( ALLOCATED( z0q_av ) ) THEN 
-                DO  m = 1, surf_def_h(0)%ns
-                   i = surf_def_h(0)%i(m)
-                   j = surf_def_h(0)%j(m)
-                   z0q_av(j,i) = z0q_av(j,i) + surf_def_h(0)%z0q(m)
-                ENDDO
-                DO  m = 1, surf_lsm_h%ns
-                   i = surf_lsm_h%i(m)
-                   j = surf_lsm_h%j(m)
-                   z0q_av(j,i) = z0q_av(j,i) + surf_lsm_h%z0q(m)
-                ENDDO
-                DO  m = 1, surf_usm_h%ns
-                   i = surf_usm_h%i(m)
-                   j = surf_usm_h%j(m)
-                   z0q_av(j,i) = z0q_av(j,i) + surf_usm_h%z0q(m)
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      match_def = surf_def_h(0)%start_index(j,i) <=            &
+                                  surf_def_h(0)%end_index(j,i)
+                      match_lsm = surf_lsm_h%start_index(j,i) <=               &
+                                  surf_lsm_h%end_index(j,i)
+                      match_usm = surf_usm_h%start_index(j,i) <=               &
+                                  surf_usm_h%end_index(j,i)
+
+                      IF ( match_def )  THEN
+                         m = surf_def_h(0)%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_def_h(0)%z0q(m)
+                      ELSEIF ( match_lsm  .AND.  .NOT. match_usm )  THEN
+                         m = surf_lsm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_lsm_h%z0q(m)
+                      ELSEIF ( match_usm )  THEN
+                         m = surf_usm_h%end_index(j,i)
+                         tsurf_av(j,i) = tsurf_av(j,i) +                       &
+                                         surf_usm_h%z0q(m)
+                      ENDIF
+                   ENDDO
                 ENDDO
              ENDIF
