Index: /palm/trunk/SOURCE/average_3d_data.f90
===================================================================
--- /palm/trunk/SOURCE/average_3d_data.f90	(revision 2796)
+++ /palm/trunk/SOURCE/average_3d_data.f90	(revision 2797)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Enable output of ground-heat flux also at urban surfaces.
+! 
+! 2766 2018-01-22 17:17:47Z kanani
 ! Removed preprocessor directive __chem
 ! 
@@ -200,4 +203,13 @@
              ENDDO
 
+          CASE ( 'ghf*' )
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   ghf_av(j,i) = ghf_av(j,i)                                   &
+                                 / REAL( average_count_3d, KIND=wp )
+                ENDDO
+             ENDDO
+             CALL exchange_horiz_2d( ghf_av, nbgp )
+
           CASE ( 'qsws*' )
              DO  i = nxlg, nxrg
Index: /palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- /palm/trunk/SOURCE/check_parameters.f90	(revision 2796)
+++ /palm/trunk/SOURCE/check_parameters.f90	(revision 2797)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Enable output of ground-heat flux also at urban surfaces.
+! 
+! 2776 2018-01-31 10:44:42Z Giersch
 ! Variable synthetic_turbulence_generator has been abbreviated
 ! 
@@ -3322,6 +3325,6 @@
              CONTINUE
 
-          CASE ( 'lwp*', 'ol*', 'pra*', 'prr*', 'qsws*', 'r_a*', 'shf*',       &
-                 'ssws*', 't*', 'tsurf*', 'u*', 'z0*', 'z0h*', 'z0q*' )
+          CASE ( 'ghf*', 'lwp*', 'ol*', 'pra*', 'prr*', 'qsws*', 'r_a*',       &
+                 'shf*', 'ssws*', 't*', 'tsurf*', 'u*', 'z0*', 'z0h*', 'z0q*' )
              IF ( k == 0  .OR.  data_output(i)(ilen-2:ilen) /= '_xy' )  THEN
                 message_string = 'illegal value for data_output: "' //         &
@@ -3358,5 +3361,13 @@
                 CALL message( 'check_parameters', 'PA0322', 1, 2, 0, 6, 0 )
              ENDIF
-             IF ( ( TRIM( var ) == 'r_a*' .OR.  TRIM( var ) == 'tsurf*' )      &
+
+          IF ( TRIM( var ) == 'ghf*'  .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*' .OR.  TRIM( var ) == 'tsurf*'  .OR.  &
+                    TRIM( var ) == 'ghf*' )                                    &
                  .AND.  .NOT.  land_surface  .AND.  .NOT.  urban_surface )     &         
              THEN
@@ -3372,4 +3383,5 @@
              ENDIF
 
+             IF ( TRIM( var ) == 'ghf*'   )  unit = 'W/m2'
              IF ( TRIM( var ) == 'lwp*'   )  unit = 'kg/m2'
              IF ( TRIM( var ) == 'ol*'    )  unit = 'm'
Index: /palm/trunk/SOURCE/data_output_2d.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_2d.f90	(revision 2796)
+++ /palm/trunk/SOURCE/data_output_2d.f90	(revision 2797)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Enable output of ground-heat flux also at urban surfaces.
+! 
+! 2743 2018-01-12 16:03:39Z suehring
 ! In case of natural- and urban-type surfaces output surfaces fluxes in W/m2.
 ! 
@@ -545,4 +548,33 @@
                 ENDIF
                 IF ( mode == 'xy' )  level_z = zu
+
+             CASE ( 'ghf*_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%ghf(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%wghf_eb(m)        +      &
+                                            surf_usm_h%frac(1,m)     *          &
+                                            surf_usm_h%wghf_eb_green(m)  +      &
+                                            surf_usm_h%frac(2,m)     *          &
+                                            surf_usm_h%wghf_eb_window(m)
+                   ENDDO
+                ELSE
+                   DO  i = nxl, nxr
+                      DO  j = nys, nyn
+                         local_pf(i,j,nzb+1) = ghf_av(j,i)
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+                resorted = .TRUE.
+                two_d = .TRUE.
+                level_z(nzb+1) = zu(nzb+1)
 
              CASE ( 'ol*_xy' )        ! 2d-array
Index: /palm/trunk/SOURCE/land_surface_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 2796)
+++ /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 2797)
@@ -25,4 +25,10 @@
 ! -----------------
 ! $Id$
+! Move output of ghf to general 2D output to output ghf also at urban-type 
+! surfaces. 
+! Move restart data of ghf_av to read/write_3d_binary, as this is not a 
+! exclusively LSM variable anymore.   
+! 
+! 2765 2018-01-22 11:34:58Z maronga
 ! Major bugfix in calculation of f_shf for vertical surfaces
 ! 
@@ -598,5 +604,4 @@
               c_soil_av,        & !< average of c_soil
               c_veg_av,         & !< average of c_veg
-              ghf_av,           & !< average of ghf
               lai_av,           & !< average of lai
               qsws_liq_av,      & !< average of qsws_liq
@@ -1044,5 +1049,5 @@
           unit = 'K'   
              
-       CASE ( 'lai*', 'c_liq*', 'c_soil*', 'c_veg*', 'ghf*', 'm_liq*',         &
+       CASE ( 'lai*', 'c_liq*', 'c_soil*', 'c_veg*', 'm_liq*',                 &
               'qsws_liq*', 'qsws_soil*', 'qsws_veg*', 'r_s*' )
           IF ( k == 0  .OR.  data_output(i)(ilen-2:ilen) /= '_xy' )  THEN
@@ -1072,9 +1077,4 @@
              CALL message( 'check_parameters', 'PA0404', 1, 2, 0, 6, 0 )
           ENDIF
-          IF ( TRIM( var ) == 'ghf*'  .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 ) == 'm_liq*'  .AND.  .NOT.  land_surface )  THEN
              message_string = 'output of "' // TRIM( var ) // '" requi' //     &
@@ -1111,5 +1111,4 @@
           IF ( TRIM( var ) == 'c_soil*')      unit = 'none'
           IF ( TRIM( var ) == 'c_veg*' )      unit = 'none'
-          IF ( TRIM( var ) == 'ghf*')         unit = 'W/m2'
           IF ( TRIM( var ) == 'm_liq*'     )  unit = 'm'
           IF ( TRIM( var ) == 'qsws_liq*'  )  unit = 'W/m2'
@@ -5042,10 +5041,4 @@
                 c_veg_av = 0.0_wp
 
-             CASE ( 'ghf*' )
-                IF ( .NOT. ALLOCATED( ghf_av ) )  THEN
-                   ALLOCATE( ghf_av(nysg:nyng,nxlg:nxrg) )
-                ENDIF
-                ghf_av = 0.0_wp
-
              CASE ( 'lai*' )
                 IF ( .NOT. ALLOCATED( lai_av ) )  THEN
@@ -5124,11 +5117,4 @@
                 j   = surf_lsm_h%j(m)
                 c_veg_av(j,i) = c_veg_av(j,i) + surf_lsm_h%c_veg(m)
-             ENDDO
-
-          CASE ( 'ghf*' )
-             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
 
@@ -5226,12 +5212,4 @@
                    c_veg_av(j,i) = c_veg_av(j,i)                               &
                                    / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-
-          CASE ( 'ghf*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   ghf_av(j,i) = ghf_av(j,i)                                   &
-                                 / REAL( average_count_3d, KIND=wp )
                 ENDDO
              ENDDO
@@ -5439,22 +5417,4 @@
                 DO  j = nys, nyn
                    local_pf(i,j,nzb+1) = c_veg_av(j,i)
-                ENDDO
-             ENDDO
-          ENDIF
-
-          two_d = .TRUE.
-          grid = 'zu1'
-
-       CASE ( 'ghf*_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%ghf(m)
-             ENDDO
-          ELSE
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   local_pf(i,j,nzb+1) = ghf_av(j,i)
                 ENDDO
              ENDDO
@@ -5750,7 +5710,4 @@
        IF ( ALLOCATED( c_veg_av ) )  THEN
           WRITE ( 14 )  'c_veg_av            ';  WRITE ( 14 ) c_veg_av
-       ENDIF
-       IF ( ALLOCATED( ghf_av ) )  THEN
-          WRITE ( 14 )  'ghf_av              ';  WRITE ( 14 )  ghf_av
        ENDIF
        IF ( ALLOCATED( lai_av ) )  THEN
@@ -5993,12 +5950,4 @@
                                   tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
-                CASE ( 'ghf_av' )
-                   IF ( .NOT. ALLOCATED( ghf_av ) )  THEN
-                      ALLOCATE( ghf_av(nysg:nyng,nxlg:nxrg) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   ghf_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =           &
-                                  tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
                 CASE ( 'lai_av' )
                    IF ( .NOT. ALLOCATED( lai_av ) )  THEN
Index: /palm/trunk/SOURCE/modules.f90
===================================================================
--- /palm/trunk/SOURCE/modules.f90	(revision 2796)
+++ /palm/trunk/SOURCE/modules.f90	(revision 2797)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! +ghf_av
+! 
+! 2776 2018-01-31 10:44:42Z Giersch
 ! Variable synthetic_turbulence_generator has been abbreviated and _prerun flags
 ! for skipping module related restart data has beed introduced
@@ -896,4 +899,5 @@
     USE kinds
 
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ghf_av                 !< avg. ground heat flux
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  lwp_av                 !< avg. liquid water path
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  precipitation_rate_av  !< avg. precipitation rate
Index: /palm/trunk/SOURCE/read_3d_binary.f90
===================================================================
--- /palm/trunk/SOURCE/read_3d_binary.f90	(revision 2796)
+++ /palm/trunk/SOURCE/read_3d_binary.f90	(revision 2797)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Enable restarts for land- and urban-surface variables ghf_av, r_a_av and 
+! tsurf_av.
+! 
+! 2766 2018-01-22 17:17:47Z kanani
 ! Removed preprocessor directive __chem
 ! 
@@ -481,4 +485,12 @@
              SELECT CASE ( TRIM( field_chr ) )
 
+                CASE ( 'ghf_av' )
+                   IF ( .NOT. ALLOCATED( ghf_av ) )  THEN
+                      ALLOCATE( ghf_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   ghf_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =           &
+                                  tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
                 CASE ( 'e' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
@@ -729,4 +741,12 @@
                    qv_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
                              tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'r_a_av' )
+                   IF ( .NOT. ALLOCATED( r_a_av ) )  THEN
+                      ALLOCATE( r_a_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   r_a_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =           &
+                                  tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'random_iv' )  ! still unresolved issue
@@ -840,4 +860,12 @@
                    ts_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'tsurf_av' )
+                   IF ( .NOT. ALLOCATED( tsurf_av ) )  THEN
+                      ALLOCATE( tsurf_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   tsurf_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =         &
+                                  tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'u' )
Index: /palm/trunk/SOURCE/sum_up_3d_data.f90
===================================================================
--- /palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 2796)
+++ /palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 2797)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Enable output of ground-heat flux also at urban surfaces.
+! 
+! 2790 2018-02-06 11:57:19Z suehring
 ! Bugfix in summation of surface sensible and latent heat flux
 ! 
@@ -172,5 +175,6 @@
 
     USE averaging,                                                             &
-        ONLY:  diss_av, e_av, kh_av, km_av, lpt_av, lwp_av, nc_av, nr_av,      &
+        ONLY:  diss_av, e_av, ghf_av, kh_av, km_av, lpt_av, lwp_av, nc_av,     &
+               nr_av,                                                          &
                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, &
@@ -255,4 +259,10 @@
           SELECT CASE ( trimvar )
 
+             CASE ( 'ghf*' )
+                IF ( .NOT. ALLOCATED( ghf_av ) )  THEN
+                   ALLOCATE( ghf_av(nysg:nyng,nxlg:nxrg) )
+                ENDIF
+                ghf_av = 0.0_wp
+
              CASE ( 'e' )
                 IF ( .NOT. ALLOCATED( e_av ) )  THEN
@@ -538,4 +548,22 @@
 !--    Store the array chosen on the temporary array.
        SELECT CASE ( trimvar )
+
+          CASE ( 'ghf*' )
+             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(0,m)     *          &
+                                            surf_usm_h%wghf_eb(m)        +      &
+                                            surf_usm_h%frac(1,m)     *          &
+                                            surf_usm_h%wghf_eb_green(m)  +      &
+                                            surf_usm_h%frac(2,m)     *          &
+                                            surf_usm_h%wghf_eb_window(m)
+             ENDDO
 
           CASE ( 'e' )
Index: /palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 2796)
+++ /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 2797)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Comment concerning output of ground-heat flux added.
+! 
+! 2766 2018-01-22 17:17:47Z kanani
 ! Removed redundant commas, added some blanks
 ! 
@@ -1332,5 +1335,9 @@
                        ENDIF
                     ENDDO
-
+!
+!--             Please note, the following output quantities belongs to the 
+!--             individual tile fractions - ground heat flux at wall-, window-, 
+!--             and green fraction. Aggregated ground-heat flux is treated
+!--             accordingly in average_3d_data, sum_up_3d_data, etc..
                 CASE ( 'usm_wghf' )
 !--                 array of heat flux from ground (wall, roof, land)
Index: /palm/trunk/SOURCE/write_3d_binary.f90
===================================================================
--- /palm/trunk/SOURCE/write_3d_binary.f90	(revision 2796)
+++ /palm/trunk/SOURCE/write_3d_binary.f90	(revision 2797)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Enable restarts for land- and urban-surface variables ghf_av, r_a_av and 
+! tsurf_av.
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -135,6 +139,7 @@
 
     USE control_parameters,                                                    &
-        ONLY:  iran, humidity, passive_scalar, cloud_physics, cloud_droplets,  &
-               microphysics_morrison, microphysics_seifert, ocean, topography
+        ONLY:  cloud_physics, cloud_droplets, humidity, iran,                  &
+               land_surface, microphysics_morrison, microphysics_seifert,      &
+               ocean, passive_scalar, topography, urban_surface
                 
     USE indices,                                                               &
@@ -378,4 +383,15 @@
        WRITE ( 14 )  'z0q_av              ';  WRITE ( 14 )  z0q_av
     ENDIF
+    IF ( land_surface  .OR.  urban_surface )  THEN
+       IF ( ALLOCATED( ghf_av ) )  THEN
+          WRITE ( 14 )  'ghf_av              ';  WRITE ( 14 )  ghf_av
+       ENDIF
+       IF ( ALLOCATED( r_a_av ) )  THEN
+          WRITE ( 14 )  'r_a_av              ';  WRITE ( 14 )  r_a_av
+       ENDIF
+       IF ( ALLOCATED( tsurf_av ) )  THEN
+          WRITE ( 14 )  'tsurf_av            ';  WRITE ( 14 )  tsurf_av
+       ENDIF
+    ENDIF
 
 !
