Index: palm/trunk/SOURCE/radiation_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3116)
+++ palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3117)
@@ -28,4 +28,9 @@
 ! -----------------
 ! $Id$
+! Bugfix: water vapor was not transfered to RRTMG when cloud_physics = .F.
+! Bugfix: changed the calculation of RRTMG boundary conditions (Mohamed Salim)
+! Bugfix: dry residual atmosphere is replaced by standard RRTMG atmosphere
+! 
+! 3116 2018-07-10 14:31:58Z suehring
 ! Output of long/shortwave radiation at surface
 ! 
@@ -370,4 +375,5 @@
     USE control_parameters,                                                    &
         ONLY:  cloud_droplets, cloud_physics, coupling_char, dz, g,            &
+               humidity,                                                       &
                initializing_actions, io_blocks, io_group,                      &
                latitude, longitude, large_scale_forcing, lsf_surf,             &
@@ -618,5 +624,4 @@
 
     REAL(wp), DIMENSION(:), ALLOCATABLE :: hyp_snd,     & !< hypostatic pressure from sounding data (hPa)
-                                           q_snd,       & !< mixing ratio from sounding data (kg/kg) - dummy at the moment
                                            rrtm_tsfc,   & !< dummy array for storing surface temperature
                                            t_snd          !< actual temperature from sounding data (hPa)
@@ -829,4 +834,5 @@
     REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfoutlw        !< array of total lw radiation outgoing from nonvirtual surfaces surfaces after all reflection
     REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfhf           !< array of total radiation flux incoming to minus outgoing from local surface
+    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfemitlwl      !< array of emitted lw radiation for local surface used to calculate effective surface temperature for radiation model
 
 !-- block variables needed for calculation of the plant canopy model inside the urban surface model
@@ -2850,5 +2856,9 @@
           CALL calc_mean_profile( pt, 4 )
           pt_av = hom(:, 1, 4, 0)
-
+          
+          IF ( humidity )  THEN
+             CALL calc_mean_profile( q, 41 )
+             q_av  = hom(:, 1, 41, 0)
+          ENDIF
 !
 !--       Prepare profiles of temperature and H2O volume mixing ratio
@@ -2856,7 +2866,5 @@
 
           IF ( cloud_physics )  THEN
-             CALL calc_mean_profile( q, 41 )
-             ! average  q is now in hom(:, 1, 41, 0)
-             q_av = hom(:, 1, 41, 0)
+
              CALL calc_mean_profile( ql, 54 )
              ! average ql is now in hom(:, 1, 54, 0)
@@ -2872,6 +2880,13 @@
                 rrtm_tlay(0,k) = pt_av(k) * ( (hyp(k) ) / 100000._wp       &
                                  )**.286_wp
-                rrtm_h2ovmr(0,k) = 0._wp
-              ENDDO
+             ENDDO
+
+             IF ( humidity )  THEN
+                DO k = nzb+1, nzt+1
+                   rrtm_h2ovmr(0,k) = mol_mass_air_d_wv * q_av(k)
+                ENDDO
+             ELSE
+                rrtm_h2ovmr(0,nzb+1:nzt+1) = 0.0_wp
+             ENDIF
           ENDIF
 
@@ -2943,5 +2958,5 @@
 !--       Set surface temperature
           rrtm_tsfc = t_rad_urb
-
+          
           IF ( lw_radiation )  THEN
              CALL rrtmg_lw( 1, nzt_rad      , rrtm_icld    , rrtm_idrv      ,&
@@ -3081,6 +3096,13 @@
                       rrtm_tlay(0,k) = pt(k,j,i) * ( (hyp(k) ) / 100000.0_wp   &
                                        )**0.286_wp
-                      rrtm_h2ovmr(0,k) = 0.0_wp
                    ENDDO
+
+                   IF ( humidity )  THEN
+                      DO k = nzb+1, nzt+1
+                         rrtm_h2ovmr(0,k) =  mol_mass_air_d_wv * q(k,j,i)
+                      ENDDO   
+                   ELSE
+                      rrtm_h2ovmr(0,nzb+1:nzt+1) = 0.0_wp
+                   ENDIF
                 ENDIF
 
@@ -3742,5 +3764,4 @@
           DEALLOCATE( hyp_snd )
           DEALLOCATE( t_snd )
-          DEALLOCATE( q_snd  )
           DEALLOCATE ( rrtm_play )
           DEALLOCATE ( rrtm_plev )
@@ -3748,5 +3769,4 @@
           DEALLOCATE ( rrtm_tlev )
 
-          DEALLOCATE ( rrtm_h2ovmr )
           DEALLOCATE ( rrtm_cicewp )
           DEALLOCATE ( rrtm_cldfr )
@@ -3844,12 +3864,9 @@
 
 !
-!--    Save data above LES domain in hyp_snd, t_snd and q_snd
-!--    Note: q_snd_tmp is not calculated at the moment (dry residual atmosphere)
+!--    Save data above LES domain in hyp_snd, t_snd
        ALLOCATE( hyp_snd(nzb+1:nzt_rad) )
        ALLOCATE( t_snd(nzb+1:nzt_rad)   )
-       ALLOCATE( q_snd(nzb+1:nzt_rad)   )
        hyp_snd = 0.0_wp
        t_snd = 0.0_wp
-       q_snd = 0.0_wp
 
        hyp_snd(nzt+2:nzt_rad) = hyp_snd_tmp(nz_snd_start+1:nz_snd_end)
@@ -3891,9 +3908,7 @@
        ALLOCATE ( rrtm_tlay(0:0,nzb+1:nzt_rad+1)   )
        ALLOCATE ( rrtm_tlev(0:0,nzb+1:nzt_rad+2)   )
-       ALLOCATE ( rrtm_h2ovmr(0:0,nzb+1:nzt_rad+1) )
 
        DO k = nzt+8, nzt_rad
           rrtm_tlay(0,k)   = t_snd(k)
-          rrtm_h2ovmr(0,k) = q_snd(k)
        ENDDO
        rrtm_tlay(0,nzt_rad+1) = 2.0_wp * rrtm_tlay(0,nzt_rad)                  &
@@ -3905,5 +3920,4 @@
                              * ( rrtm_plev(0,k) - rrtm_play(0,k-1) )
        ENDDO
-       rrtm_h2ovmr(0,nzt_rad+1) = rrtm_h2ovmr(0,nzt_rad)
 
        rrtm_tlev(0,nzt_rad+2)   = 2.0_wp * rrtm_tlay(0,nzt_rad+1)              &
@@ -3994,9 +4008,9 @@
        IMPLICIT NONE
 
-       INTEGER(iwp), PARAMETER :: num_trace_gases = 9 !< number of trace gases (absorbers)
+       INTEGER(iwp), PARAMETER :: num_trace_gases = 10 !< number of trace gases (absorbers)
 
        CHARACTER(LEN=5), DIMENSION(num_trace_gases), PARAMETER ::              & !< trace gas names
            trace_names = (/'O3   ', 'CO2  ', 'CH4  ', 'N2O  ', 'O2   ',        &
-                           'CFC11', 'CFC12', 'CFC22', 'CCL4 '/)
+                           'CFC11', 'CFC12', 'CFC22', 'CCL4 ', 'H2O'/)
 
        INTEGER(iwp) :: id,     & !< NetCDF id
@@ -4036,4 +4050,5 @@
           DEALLOCATE ( rrtm_cfc22vmr )
           DEALLOCATE ( rrtm_ccl4vmr  )
+          DEALLOCATE ( rrtm_h2ovmr  )     
        ENDIF
 
@@ -4049,4 +4064,5 @@
        ALLOCATE ( rrtm_cfc22vmr(0:0,1:nzt_rad+1) )
        ALLOCATE ( rrtm_ccl4vmr(0:0,1:nzt_rad+1)  )
+       ALLOCATE ( rrtm_h2ovmr(0:0,1:nzt_rad+1)  )
 
 !
@@ -4226,4 +4242,8 @@
                 rrtm_ccl4vmr(0,:) = trace_path_tmp(:)
 
+             CASE ( 'H2O' )
+
+                rrtm_h2ovmr(0,:) = trace_path_tmp(:)
+                
              CASE DEFAULT
 
@@ -4388,4 +4408,6 @@
      REAL(wp)                          :: area_surfl         !< total area of surfaces in local processor
      REAL(wp)                          :: area_surf          !< total area of surfaces in all processor
+     REAL(wp)                          :: area_horl          !< total horizontal area of domain in local processor
+     REAL(wp)                          :: area_hor           !< total horizontal area of domain in all processor
 
 
@@ -4605,4 +4627,5 @@
      surfoutsw = 0.0_wp
      surfoutlw = surfoutll
+     surfemitlwl = surfoutll
 !        surfhf = surfinsw + surfinlw - surfoutsw - surfoutlw
 
@@ -4826,4 +4849,7 @@
         IF ( kdir(d) == 0 ) facearea(d) = facearea(d) * dz(1)
      ENDDO
+!--  calculate horizontal area
+! !!! ATTENTION!!! uniform grid is assumed here
+     area_hor = (nx+1) * (ny+1) * dx * dy
 !
 !--  absorbed/received SW & LW and emitted LW energy of all physical
@@ -4839,6 +4865,6 @@
         d = surfl(id, i)
 !--  received SW & LW
-        pinswl = pinswl + surfinsw(i) * facearea(d)
-        pinlwl = pinlwl + surfinlw(i) * facearea(d)
+        pinswl = pinswl + (surfinswdir(i) + surfinswdif(i)) * facearea(d)
+        pinlwl = pinlwl + surfinlwdif(i) * facearea(d)
 !--   absorbed SW & LW
         pabsswl = pabsswl + (1._wp - albedo_surf(i)) *                   &
@@ -4846,5 +4872,5 @@
         pabslwl = pabslwl + emiss_surf(i) * surfinlw(i) * facearea(d)
 !--   emitted LW
-        pemitlwl = pemitlwl + surfoutlw(i) * facearea(d)
+        pemitlwl = pemitlwl + surfemitlwl(i) * facearea(d)
 !--   emissivity and area sum
         emiss_sum_surfl = emiss_sum_surfl + emiss_surf(i) * facearea(d)
@@ -4856,4 +4882,5 @@
         pabsswl = pabsswl + SUM(pcbinsw)
         pabslwl = pabslwl + SUM(pcbinlw)
+        pinswl = pinswl + SUM(pcbinswdir) + SUM(pcbinswdif)
      ENDIF
 !
@@ -4871,6 +4898,6 @@
      pinlw = pinlwl
      pabssw = pabsswl
-     pabslwl = pabslw
-     pemitlwl = pemitlw
+     pabslw = pabslwl
+     pemitlw = pemitlwl
      emiss_sum_surf = emiss_sum_surfl
      area_surf = area_surfl
@@ -4878,13 +4905,13 @@
 
 !--  (1) albedo
-     IF ( pinsw /= 0.0_wp )  albedo_urb = 1._wp - pabssw / pinsw
-
+     IF ( pinsw /= 0.0_wp )  &
+          albedo_urb = (pinsw - pabssw) / pinsw
 !--  (2) average emmsivity
-     IF ( area_surf /= 0.0_wp ) emissivity_urb = emiss_sum_surf / area_surf
-
+     IF ( area_surf /= 0.0_wp ) &
+          emissivity_urb = emiss_sum_surf / area_surf
 !--  (3) temperature
-     t_rad_urb = ((pemitlw - pabslw + emissivity_urb*pinlw)/(emissivity_urb*sigma_sb*area_surf))**0.25_wp
+     t_rad_urb = ( (pemitlw - pabslw + emissivity_urb*pinlw) / &
+          (emissivity_urb*sigma_sb * area_hor) )**0.25_wp
      
-
     CONTAINS
 
@@ -5356,4 +5383,5 @@
        ALLOCATE( skyvf(nsurfl) )
        ALLOCATE( skyvft(nsurfl) )
+       ALLOCATE( surfemitlwl(nsurfl) )
 
 !
@@ -5362,6 +5390,6 @@
 !--    For now set an arbitrary initial value.
        IF ( average_radiation )  THEN
-          albedo_urb = 0.5_wp
-          emissivity_urb = 0.5_wp
+          albedo_urb = 0.1_wp
+          emissivity_urb = 0.9_wp
           t_rad_urb = pt_surface
        ENDIF
