Index: palm/trunk/SOURCE/average_3d_data.f90
===================================================================
--- palm/trunk/SOURCE/average_3d_data.f90	(revision 2734)
+++ palm/trunk/SOURCE/average_3d_data.f90	(revision 2735)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of r_a moved from land-surface to consider also urban-type surfaces
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -360,4 +363,12 @@
              ENDDO
 
+         CASE ( 'r_a*' )
+             DO  i = nxlg, nxrg
+                DO  j = nysg, nyng
+                   r_a_av(j,i) = r_a_av(j,i) / REAL( average_count_3d, KIND=wp )
+                ENDDO
+             ENDDO
+             CALL exchange_horiz_2d( r_a_av, nbgp )
+
           CASE ( 'rho_ocean' )
              DO  i = nxlg, nxrg
Index: palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- palm/trunk/SOURCE/check_parameters.f90	(revision 2734)
+++ palm/trunk/SOURCE/check_parameters.f90	(revision 2735)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of r_a moved from land-surface to consider also urban-type surfaces
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -3282,6 +3285,6 @@
              CONTINUE
 
-          CASE ( 'lwp*', 'ol*', 'pra*', 'prr*', 'qsws*', 'shf*', 'ssws*', 't*', &
-                 'u*', 'z0*', 'z0h*', 'z0q*' )
+          CASE ( 'lwp*', 'ol*', 'pra*', 'prr*', 'qsws*', 'r_a*', 'shf*',       &
+                 'ssws*', 't*', 'u*', 'z0*', 'z0h*', 'z0q*' )
              IF ( k == 0  .OR.  data_output(i)(ilen-2:ilen) /= '_xy' )  THEN
                 message_string = 'illegal value for data_output: "' //         &
@@ -3318,4 +3321,12 @@
                 CALL message( 'check_parameters', 'PA0322', 1, 2, 0, 6, 0 )
              ENDIF
+             IF ( TRIM( var ) == 'r_a*'  .AND.  .NOT.  land_surface  .AND.     &
+                                                .NOT.  urban_surface )         &         
+             THEN
+                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
+                                 'res land_surface = .TRUE. or ' //            &
+                                 'urban_surface = .TRUE.'
+                CALL message( 'check_parameters', 'PA0404', 1, 2, 0, 6, 0 )
+             ENDIF
              IF ( TRIM( var ) == 'ssws*'  .AND.  .NOT.  passive_scalar )  THEN
                 message_string = 'output of "' // TRIM( var ) // '" requi' //  &
@@ -3325,8 +3336,9 @@
 
              IF ( TRIM( var ) == 'lwp*'   )  unit = 'kg/m2'
-             IF ( TRIM( var ) == 'ol*'   )   unit = 'm'
+             IF ( TRIM( var ) == 'ol*'    )  unit = 'm'
              IF ( TRIM( var ) == 'pra*'   )  unit = 'mm'
              IF ( TRIM( var ) == 'prr*'   )  unit = 'mm/s'
              IF ( TRIM( var ) == 'qsws*'  )  unit = 'kgm/kgs'
+             IF ( TRIM( var ) == 'r_a*'   )  unit = 's/m'     
              IF ( TRIM( var ) == 'shf*'   )  unit = 'K*m/s'
              IF ( TRIM( var ) == 'ssws*'  )  unit = 'kg/m2*s'
Index: palm/trunk/SOURCE/data_output_2d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_2d.f90	(revision 2734)
+++ palm/trunk/SOURCE/data_output_2d.f90	(revision 2735)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of r_a moved from land-surface to consider also urban-type surfaces
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -844,5 +847,31 @@
                 IF ( mode == 'xy' )  level_z = zu
 
-
+             CASE ( 'r_a*_xy' )        ! 2d-array
+                IF ( av == 0 )  THEN
+                   DO  m = 1, surf_lsm_h%ns
+                      i                   = surf_lsm_h%i(m)            
+                      j                   = surf_lsm_h%j(m)
+                      local_pf(i,j,nzb+1) = surf_lsm_h%r_a(m)
+                   ENDDO
+
+                   DO  m = 1, surf_usm_h%ns
+                      i   = surf_usm_h%i(m)            
+                      j   = surf_usm_h%j(m)
+                      local_pf(i,j,nzb+1) =                                          &
+                                 ( surf_usm_h%frac(0,m) * surf_usm_h%r_a(m)       +  & 
+                                   surf_usm_h%frac(1,m) * surf_usm_h%r_a_green(m) +  & 
+                                   surf_usm_h%frac(2,m) * surf_usm_h%r_a_window(m) )
+                   ENDDO
+
+                ELSE
+                   DO  i = nxl, nxr
+                      DO  j = nys, nyn
+                         local_pf(i,j,nzb+1) = r_a_av(j,i)
+                      ENDDO
+                   ENDDO
+                ENDIF
+                resorted       = .TRUE.
+                two_d          = .TRUE.
+                level_z(nzb+1) = zu(nzb+1)
 
              CASE ( 'rho_ocean_xy', 'rho_ocean_xz', 'rho_ocean_yz' )
Index: palm/trunk/SOURCE/land_surface_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 2734)
+++ palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 2735)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of r_a moved from land-surface to consider also urban-type surfaces
+! 
+! 2729 2018-01-09 11:22:28Z maronga
 ! Separated deep soil temperature from soil_temperature array
 ! 
@@ -597,5 +600,4 @@
               qsws_soil_av,     & !< average of qsws_soil
               qsws_veg_av,      & !< average of qsws_veg
-              r_a_av,           & !< average of r_a
               r_s_av              !< average of r_s
                    
@@ -1040,6 +1042,5 @@
              
        CASE ( 'lai*', 'c_liq*', 'c_soil*', 'c_veg*', 'ghf*', 'm_liq*',         &
-              'qsws_liq*', 'qsws_soil*', 'qsws_veg*',                          &
-              'r_a*', 'r_s*' )
+              'qsws_liq*', 'qsws_soil*', 'qsws_veg*', 'r_s*' )
           IF ( k == 0  .OR.  data_output(i)(ilen-2:ilen) /= '_xy' )  THEN
              message_string = 'illegal value for data_output: "' //            &
@@ -1091,10 +1092,4 @@
           ENDIF
           IF ( TRIM( var ) == 'qsws_veg*'  .AND.  .NOT. land_surface )         &
-          THEN
-             message_string = 'output of "' // TRIM( var ) // '" requi' //     &
-                              'res land_surface = .TRUE.'
-             CALL message( 'check_parameters', 'PA0404', 1, 2, 0, 6, 0 )
-          ENDIF
-          IF ( TRIM( var ) == 'r_a*'  .AND.  .NOT.  land_surface )             &
           THEN
              message_string = 'output of "' // TRIM( var ) // '" requi' //     &
@@ -1118,5 +1113,4 @@
           IF ( TRIM( var ) == 'qsws_soil*' )  unit = 'W/m2'
           IF ( TRIM( var ) == 'qsws_veg*'  )  unit = 'W/m2'
-          IF ( TRIM( var ) == 'r_a*')         unit = 's/m'     
           IF ( TRIM( var ) == 'r_s*')         unit = 's/m' 
              
@@ -5065,10 +5059,4 @@
                 qsws_veg_av = 0.0_wp
 
-             CASE ( 'r_a*' )
-                IF ( .NOT. ALLOCATED( r_a_av ) )  THEN
-                   ALLOCATE( r_a_av(nysg:nyng,nxlg:nxrg) )
-                ENDIF
-                r_a_av = 0.0_wp
-
              CASE ( 'r_s*' )
                 IF ( .NOT. ALLOCATED( r_s_av ) )  THEN
@@ -5165,11 +5153,4 @@
                 qsws_veg_av(j,i) = qsws_veg_av(j,i) +                          &
                                       surf_lsm_h%qsws_veg(m)
-             ENDDO
-
-          CASE ( 'r_a*' )
-             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
 
@@ -5281,11 +5262,4 @@
              ENDDO
 
-          CASE ( 'r_a*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   r_a_av(j,i) = r_a_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-
           CASE ( 'r_s*' )
              DO  i = nxl, nxr
@@ -5579,22 +5553,4 @@
           grid = 'zu1'
 
-
-       CASE ( 'r_a*_xy' )        ! 2d-array
-          IF ( av == 0 )  THEN
-             DO  m = 1, surf_lsm_h%ns
-                i                   = surf_lsm_h%i(m)            
-                j                   = surf_lsm_h%j(m)
-                local_pf(i,j,nzb+1) = surf_lsm_h%r_a(m)
-             ENDDO
-          ELSE
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   local_pf(i,j,nzb+1) = r_a_av(j,i)
-                ENDDO
-             ENDDO
-          ENDIF
-
-          two_d = .TRUE.
-          grid = 'zu1'
 
        CASE ( 'r_s*_xy' )        ! 2d-array
Index: palm/trunk/SOURCE/modules.f90
===================================================================
--- palm/trunk/SOURCE/modules.f90	(revision 2734)
+++ palm/trunk/SOURCE/modules.f90	(revision 2735)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! +r_a_av
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -884,4 +887,5 @@
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ol_av                  !< avg. Obukhov length
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  qsws_av                !< avg. surface moisture flux
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  r_a_av                 !< avg. resistance
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ssws_av                !< avg. surface scalar flux
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  shf_av                 !< avg. surface heat flux
Index: palm/trunk/SOURCE/sum_up_3d_data.f90
===================================================================
--- palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 2734)
+++ palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 2735)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! output of r_a moved from land-surface to consider also urban-type surfaces
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -158,6 +161,6 @@
                ol_av, p_av, pc_av, pr_av, prr_av, precipitation_rate_av, pt_av,&
                q_av, qc_av, ql_av, ql_c_av, ql_v_av, ql_vp_av, qr_av, qsws_av, &
-               qv_av, rho_ocean_av, s_av, sa_av, shf_av, ssws_av, ts_av, u_av, &
-               us_av, v_av, vpt_av, w_av, z0_av, z0h_av, z0q_av
+               qv_av, r_a_av, rho_ocean_av, s_av, sa_av, shf_av, ssws_av,      &
+               ts_av, u_av, us_av, v_av, vpt_av, w_av, z0_av, z0h_av, z0q_av
 #if defined( __chem )
     USE chemistry_model_mod,                                                   &
@@ -364,4 +367,10 @@
                 ENDIF
                 qv_av = 0.0_wp
+
+             CASE ( 'r_a*' )
+                IF ( .NOT. ALLOCATED( r_a_av ) )  THEN
+                   ALLOCATE( r_a_av(nysg:nyng,nxlg:nxrg) )
+                ENDIF
+                r_a_av = 0.0_wp
 
              CASE ( 'rho_ocean' )
@@ -746,4 +755,24 @@
              ENDDO
 
+          CASE ( 'r_a*' )
+             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(0,m) * surf_usm_h%r_a(m)       +  & 
+                             surf_usm_h%frac(1,m) * surf_usm_h%r_a_green(m) +  & 
+                             surf_usm_h%frac(2,m) * surf_usm_h%r_a_window(m) )
+             ENDDO
+
           CASE ( 'rho_ocean' )
              DO  i = nxlg, nxrg
Index: palm/trunk/SOURCE/surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/surface_mod.f90	(revision 2734)
+++ palm/trunk/SOURCE/surface_mod.f90	(revision 2735)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! +r_a_green, r_a_window
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Changes from last commit documented
 ! 
@@ -264,4 +267,6 @@
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  qsws_veg            !< surface flux of latent heat (vegetation portion)
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  r_a                 !< aerodynamic resistance 
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  r_a_green           !< aerodynamic resistance at green fraction
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  r_a_window          !< aerodynamic resistance at window fraction
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  r_canopy            !< canopy resistance
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  r_soil              !< soil resistance
Index: palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/urban_surface_mod.f90	(revision 2734)
+++ palm/trunk/SOURCE/urban_surface_mod.f90	(revision 2735)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! resistances are saved in surface attributes
+! 
+! 2723 2018-01-05 09:27:03Z maronga
 ! Bugfix for spinups (end_time was increased twice in case of LSM + USM runs)
 ! 
@@ -826,4 +829,7 @@
         ALLOCATE ( surf_usm_h%lai(1:surf_usm_h%ns)             )
         ALLOCATE ( surf_usm_h%emissivity(0:2,1:surf_usm_h%ns)  )
+        ALLOCATE ( surf_usm_h%r_a(1:surf_usm_h%ns)             )
+        ALLOCATE ( surf_usm_h%r_a_green(1:surf_usm_h%ns)       )
+        ALLOCATE ( surf_usm_h%r_a_window(1:surf_usm_h%ns)      )
 
 !
@@ -838,6 +844,8 @@
            ALLOCATE ( surf_usm_v(l)%transmissivity(1:surf_usm_v(l)%ns)  )
            ALLOCATE ( surf_usm_v(l)%lai(1:surf_usm_v(l)%ns)             )
-
            ALLOCATE ( surf_usm_v(l)%emissivity(0:2,1:surf_usm_v(l)%ns)  )
+           ALLOCATE ( surf_usm_v(l)%r_a(1:surf_usm_v(l)%ns)             )
+           ALLOCATE ( surf_usm_v(l)%r_a_green(1:surf_usm_v(l)%ns)       )
+           ALLOCATE ( surf_usm_v(l)%r_a_window(1:surf_usm_v(l)%ns)      )
         ENDDO
 
@@ -6859,7 +6867,4 @@
         REAL(wp)                              :: coef_green_2       !< second  coeficient for prognostic green wall equation
         REAL(wp)                              :: rho_cp             !< rho_wall_surface * cp
-        REAL(wp)                              :: r_a                !< aerodynamic resistance for horizontal and vertical surfaces
-        REAL(wp)                              :: r_a_window         !< aerodynamic resistance for horizontal and vertical window surfaces
-        REAL(wp)                              :: r_a_green          !< aerodynamic resistance for horizontal and vertical green surfaces
         REAL(wp)                              :: f_shf              !< factor for shf_eb
         REAL(wp)                              :: f_shf_window       !< factor for shf_eb window
@@ -6918,8 +6923,9 @@
 !--        Workaround: use single r_a as stability is only treated for the
 !--        average temperature
-           r_a = ( surf_usm_h%pt1(m) - surf_usm_h%pt_surface(m) ) /                            &
-                 ( surf_usm_h%ts(m) * surf_usm_h%us(m) + 1.0E-20_wp )   
-           r_a_window = r_a
-           r_a_green  = r_a
+           surf_usm_h%r_a(m) = ( surf_usm_h%pt1(m) - surf_usm_h%pt_surface(m) ) /&
+                               ( surf_usm_h%ts(m) * surf_usm_h%us(m) + 1.0E-20_wp )   
+           surf_usm_h%r_a_window(m) = surf_usm_h%r_a(m)
+           surf_usm_h%r_a_green(m)  = surf_usm_h%r_a(m)
+
 !            r_a = ( surf_usm_h%pt1(m) - t_surf_h(m) / exn(k) ) /                              &
 !                  ( surf_usm_h%ts(m) * surf_usm_h%us(m) + 1.0E-20_wp )
@@ -6930,7 +6936,10 @@
                 
 !--        make sure that the resistance does not drop to zero
-           IF ( r_a        < 1.0_wp )  r_a        = 1.0_wp
-           IF ( r_a_window < 1.0_wp )  r_a_window = 1.0_wp
-           IF ( r_a_green  < 1.0_wp )  r_a_green  = 1.0_wp
+           IF ( surf_usm_h%r_a(m)        < 1.0_wp )                            &
+               surf_usm_h%r_a(m)        = 1.0_wp
+           IF ( surf_usm_h%r_a_green(m)  < 1.0_wp )                            &
+               surf_usm_h%r_a_green(m) = 1.0_wp
+           IF ( surf_usm_h%r_a_window(m) < 1.0_wp )                            &
+               surf_usm_h%r_a_window(m) = 1.0_wp
 
                 
@@ -6941,12 +6950,12 @@
 !--        A temporary solution would be multiplication by magic constant :-(.
 !--        For the moment this is comment out.
-           r_a        = r_a        !* ra_horiz_coef
-           r_a_window = r_a_window !* ra_horiz_coef
-           r_a_green  = r_a_green  !* ra_horiz_coef
+           surf_usm_h%r_a(m)        = surf_usm_h%r_a(m)        !* ra_horiz_coef
+           surf_usm_h%r_a_window(m) = surf_usm_h%r_a_window(m) !* ra_horiz_coef
+           surf_usm_h%r_a_green(m)  = surf_usm_h%r_a_green(m)  !* ra_horiz_coef
                 
 !--        factor for shf_eb
-           f_shf  = rho_cp / r_a
-           f_shf_window  = rho_cp / r_a_window
-           f_shf_green  = rho_cp / r_a_green
+           f_shf  = rho_cp / surf_usm_h%r_a(m)
+           f_shf_window  = rho_cp / surf_usm_h%r_a_window(m)
+           f_shf_green  = rho_cp / surf_usm_h%r_a_green(m)
         
 !--        add LW up so that it can be removed in prognostic equation
