Index: palm/trunk/SOURCE/radiation_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3528)
+++ palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3572)
@@ -28,4 +28,9 @@
 ! -----------------
 ! $Id$
+! Add filling the short- and longwave radiation flux arrays (e.g. diffuse, 
+! direct, reflected, resedual) for all surfaces. This is required to surface
+! outputs in suface_output_mod. (M. Salim)
+! 
+! 3571 2018-11-28 09:24:03Z moh.hefny
 ! Add an epsilon value to compare values in if statement to fix possible 
 ! precsion related errors in raytrace routines.
@@ -692,5 +697,5 @@
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  rad_sw_out_xy_av !< average of outgoing shortwave radiation at surface
 !
-!-- Land surface albedos for solar zenith angle of 60Â° after Briegleb (1992)     
+!-- Land surface albedos for solar zenith angle of 60° after Briegleb (1992)     
 !-- (shortwave, longwave, broadband):   sw,      lw,      bb,
     REAL(wp), DIMENSION(0:2,1:33), PARAMETER :: albedo_pars = RESHAPE( (/& 
@@ -788,7 +793,7 @@
                                              rrtm_cfc22vmr,  & !< CFC22 volume mixing ratio (g/mol)
                                              rrtm_ch4vmr,    & !< CH4 volume mixing ratio
-                                             rrtm_cicewp,    & !< in-cloud ice water path (g/mÂ²)
+                                             rrtm_cicewp,    & !< in-cloud ice water path (g/m2)
                                              rrtm_cldfr,     & !< cloud fraction (0,1)
-                                             rrtm_cliqwp,    & !< in-cloud liquid water path (g/mÂ²)
+                                             rrtm_cliqwp,    & !< in-cloud liquid water path (g/m2)
                                              rrtm_co2vmr,    & !< CO2 volume mixing ratio (g/mol)
                                              rrtm_emis,      & !< surface emissivity (0-1)  
@@ -1710,10 +1715,24 @@
           ALLOCATE( surf_lsm_h%rad_sw_in(1:surf_lsm_h%ns)  )
           ALLOCATE( surf_lsm_h%rad_sw_out(1:surf_lsm_h%ns) )
+          ALLOCATE( surf_lsm_h%rad_sw_dir(1:surf_lsm_h%ns) )
+          ALLOCATE( surf_lsm_h%rad_sw_dif(1:surf_lsm_h%ns) )
+          ALLOCATE( surf_lsm_h%rad_sw_ref(1:surf_lsm_h%ns) )
+          ALLOCATE( surf_lsm_h%rad_sw_res(1:surf_lsm_h%ns) )
           ALLOCATE( surf_lsm_h%rad_lw_in(1:surf_lsm_h%ns)  )
           ALLOCATE( surf_lsm_h%rad_lw_out(1:surf_lsm_h%ns) )
+          ALLOCATE( surf_lsm_h%rad_lw_dif(1:surf_lsm_h%ns) )
+          ALLOCATE( surf_lsm_h%rad_lw_ref(1:surf_lsm_h%ns) )
+          ALLOCATE( surf_lsm_h%rad_lw_res(1:surf_lsm_h%ns) )
           surf_lsm_h%rad_sw_in  = 0.0_wp 
           surf_lsm_h%rad_sw_out = 0.0_wp 
+          surf_lsm_h%rad_sw_dir = 0.0_wp 
+          surf_lsm_h%rad_sw_dif = 0.0_wp 
+          surf_lsm_h%rad_sw_ref = 0.0_wp 
+          surf_lsm_h%rad_sw_res = 0.0_wp 
           surf_lsm_h%rad_lw_in  = 0.0_wp 
           surf_lsm_h%rad_lw_out = 0.0_wp 
+          surf_lsm_h%rad_lw_dif = 0.0_wp 
+          surf_lsm_h%rad_lw_ref = 0.0_wp 
+          surf_lsm_h%rad_lw_res = 0.0_wp 
        ENDIF
        IF ( .NOT. ALLOCATED ( surf_usm_h%rad_sw_in )  .AND.                    &
@@ -1721,10 +1740,24 @@
           ALLOCATE( surf_usm_h%rad_sw_in(1:surf_usm_h%ns)  )
           ALLOCATE( surf_usm_h%rad_sw_out(1:surf_usm_h%ns) )
+          ALLOCATE( surf_usm_h%rad_sw_dir(1:surf_usm_h%ns) )
+          ALLOCATE( surf_usm_h%rad_sw_dif(1:surf_usm_h%ns) )
+          ALLOCATE( surf_usm_h%rad_sw_ref(1:surf_usm_h%ns) )
+          ALLOCATE( surf_usm_h%rad_sw_res(1:surf_usm_h%ns) )
           ALLOCATE( surf_usm_h%rad_lw_in(1:surf_usm_h%ns)  )
           ALLOCATE( surf_usm_h%rad_lw_out(1:surf_usm_h%ns) )
+          ALLOCATE( surf_usm_h%rad_lw_dif(1:surf_usm_h%ns) )
+          ALLOCATE( surf_usm_h%rad_lw_ref(1:surf_usm_h%ns) )
+          ALLOCATE( surf_usm_h%rad_lw_res(1:surf_usm_h%ns) )
           surf_usm_h%rad_sw_in  = 0.0_wp 
           surf_usm_h%rad_sw_out = 0.0_wp 
+          surf_usm_h%rad_sw_dir = 0.0_wp 
+          surf_usm_h%rad_sw_dif = 0.0_wp 
+          surf_usm_h%rad_sw_ref = 0.0_wp 
+          surf_usm_h%rad_sw_res = 0.0_wp 
           surf_usm_h%rad_lw_in  = 0.0_wp 
           surf_usm_h%rad_lw_out = 0.0_wp 
+          surf_usm_h%rad_lw_dif = 0.0_wp 
+          surf_usm_h%rad_lw_ref = 0.0_wp 
+          surf_usm_h%rad_lw_res = 0.0_wp 
        ENDIF
        DO  l = 0, 3
@@ -1733,10 +1766,27 @@
              ALLOCATE( surf_lsm_v(l)%rad_sw_in(1:surf_lsm_v(l)%ns)  )
              ALLOCATE( surf_lsm_v(l)%rad_sw_out(1:surf_lsm_v(l)%ns) )
+             ALLOCATE( surf_lsm_v(l)%rad_sw_dir(1:surf_lsm_v(l)%ns) )
+             ALLOCATE( surf_lsm_v(l)%rad_sw_dif(1:surf_lsm_v(l)%ns) )
+             ALLOCATE( surf_lsm_v(l)%rad_sw_ref(1:surf_lsm_v(l)%ns) )
+             ALLOCATE( surf_lsm_v(l)%rad_sw_res(1:surf_lsm_v(l)%ns) )
+
              ALLOCATE( surf_lsm_v(l)%rad_lw_in(1:surf_lsm_v(l)%ns)  )
              ALLOCATE( surf_lsm_v(l)%rad_lw_out(1:surf_lsm_v(l)%ns) )
+             ALLOCATE( surf_lsm_v(l)%rad_lw_dif(1:surf_lsm_v(l)%ns) )
+             ALLOCATE( surf_lsm_v(l)%rad_lw_ref(1:surf_lsm_v(l)%ns) )
+             ALLOCATE( surf_lsm_v(l)%rad_lw_res(1:surf_lsm_v(l)%ns) )
+
              surf_lsm_v(l)%rad_sw_in  = 0.0_wp 
-             surf_lsm_v(l)%rad_sw_out = 0.0_wp 
+             surf_lsm_v(l)%rad_sw_out = 0.0_wp
+             surf_lsm_v(l)%rad_sw_dir = 0.0_wp
+             surf_lsm_v(l)%rad_sw_dif = 0.0_wp
+             surf_lsm_v(l)%rad_sw_ref = 0.0_wp
+             surf_lsm_v(l)%rad_sw_res = 0.0_wp
+
              surf_lsm_v(l)%rad_lw_in  = 0.0_wp 
              surf_lsm_v(l)%rad_lw_out = 0.0_wp 
+             surf_lsm_v(l)%rad_lw_dif = 0.0_wp 
+             surf_lsm_v(l)%rad_lw_ref = 0.0_wp 
+             surf_lsm_v(l)%rad_lw_res = 0.0_wp 
           ENDIF
           IF ( .NOT. ALLOCATED ( surf_usm_v(l)%rad_sw_in )  .AND.              &
@@ -1744,10 +1794,24 @@
              ALLOCATE( surf_usm_v(l)%rad_sw_in(1:surf_usm_v(l)%ns)  )
              ALLOCATE( surf_usm_v(l)%rad_sw_out(1:surf_usm_v(l)%ns) )
+             ALLOCATE( surf_usm_v(l)%rad_sw_dir(1:surf_usm_v(l)%ns) )
+             ALLOCATE( surf_usm_v(l)%rad_sw_dif(1:surf_usm_v(l)%ns) )
+             ALLOCATE( surf_usm_v(l)%rad_sw_ref(1:surf_usm_v(l)%ns) )
+             ALLOCATE( surf_usm_v(l)%rad_sw_res(1:surf_usm_v(l)%ns) )
              ALLOCATE( surf_usm_v(l)%rad_lw_in(1:surf_usm_v(l)%ns)  )
              ALLOCATE( surf_usm_v(l)%rad_lw_out(1:surf_usm_v(l)%ns) )
+             ALLOCATE( surf_usm_v(l)%rad_lw_dif(1:surf_usm_v(l)%ns) )
+             ALLOCATE( surf_usm_v(l)%rad_lw_ref(1:surf_usm_v(l)%ns) )
+             ALLOCATE( surf_usm_v(l)%rad_lw_res(1:surf_usm_v(l)%ns) )
              surf_usm_v(l)%rad_sw_in  = 0.0_wp 
-             surf_usm_v(l)%rad_sw_out = 0.0_wp 
+             surf_usm_v(l)%rad_sw_out = 0.0_wp
+             surf_usm_v(l)%rad_sw_dir = 0.0_wp
+             surf_usm_v(l)%rad_sw_dif = 0.0_wp
+             surf_usm_v(l)%rad_sw_ref = 0.0_wp
+             surf_usm_v(l)%rad_sw_res = 0.0_wp
              surf_usm_v(l)%rad_lw_in  = 0.0_wp 
              surf_usm_v(l)%rad_lw_out = 0.0_wp 
+             surf_usm_v(l)%rad_lw_dif = 0.0_wp 
+             surf_usm_v(l)%rad_lw_ref = 0.0_wp 
+             surf_usm_v(l)%rad_lw_res = 0.0_wp 
           ENDIF
        ENDDO
@@ -3200,5 +3264,5 @@
 !
 !--       Calculate liquid water path and cloud fraction for each column.
-!--       Note that LWP is required in g/mÂ² instead of kg/kg m.
+!--       Note that LWP is required in g/m2 instead of kg/kg m.
           rrtm_cldfr  = 0.0_wp
           rrtm_reliq  = 0.0_wp
@@ -3386,5 +3450,5 @@
 !
 !--             Calculate liquid water path and cloud fraction for each column.
-!--             Note that LWP is required in g/mÂ² instead of kg/kg m.
+!--             Note that LWP is required in g/m2 instead of kg/kg m.
                 rrtm_cldfr  = 0.0_wp
                 rrtm_reliq  = 0.0_wp
@@ -5136,4 +5200,9 @@
            surf_usm_h%rad_sw_in(m)  = surfinsw(i)
            surf_usm_h%rad_sw_out(m) = surfoutsw(i)
+           surf_usm_h%rad_sw_dir(m) = surfinswdir(i)
+           surf_usm_h%rad_sw_dif(m) = surfinswdif(i)
+           surf_usm_h%rad_sw_ref(m) = surfinsw(i) - surfinswdir(i) -        &
+                                      surfinswdif(i)
+           surf_usm_h%rad_sw_res(m) = surfins(i)
            surf_usm_h%rad_lw_in(m)  = surfinlw(i)
            surf_usm_h%rad_lw_out(m) = surfoutlw(i)
@@ -5141,4 +5210,7 @@
                                       surfinlw(i) - surfoutlw(i)
            surf_usm_h%rad_net_l(m)  = surf_usm_h%rad_net(m)
+           surf_usm_h%rad_lw_dif(m) = surfinlwdif(i)
+           surf_usm_h%rad_lw_ref(m) = surfinlw(i) - surfinlwdif(i)
+           surf_usm_h%rad_lw_res(m) = surfinl(i)
 !
 !--     northward-facding
@@ -5146,4 +5218,9 @@
            surf_usm_v(0)%rad_sw_in(m)  = surfinsw(i)
            surf_usm_v(0)%rad_sw_out(m) = surfoutsw(i)
+           surf_usm_v(0)%rad_sw_dir(m) = surfinswdir(i)
+           surf_usm_v(0)%rad_sw_dif(m) = surfinswdif(i)
+           surf_usm_v(0)%rad_sw_ref(m) = surfinsw(i) - surfinswdir(i) -     &
+                                         surfinswdif(i)
+           surf_usm_v(0)%rad_sw_res(m) = surfins(i)
            surf_usm_v(0)%rad_lw_in(m)  = surfinlw(i)
            surf_usm_v(0)%rad_lw_out(m) = surfoutlw(i)
@@ -5151,4 +5228,7 @@
                                          surfinlw(i) - surfoutlw(i)
            surf_usm_v(0)%rad_net_l(m)  = surf_usm_v(0)%rad_net(m)
+           surf_usm_v(0)%rad_lw_dif(m) = surfinlwdif(i)
+           surf_usm_v(0)%rad_lw_ref(m) = surfinlw(i) - surfinlwdif(i)
+           surf_usm_v(0)%rad_lw_res(m) = surfinl(i)
 !
 !--     southward-facding
@@ -5156,4 +5236,9 @@
            surf_usm_v(1)%rad_sw_in(m)  = surfinsw(i)
            surf_usm_v(1)%rad_sw_out(m) = surfoutsw(i)
+           surf_usm_v(1)%rad_sw_dir(m) = surfinswdir(i)
+           surf_usm_v(1)%rad_sw_dif(m) = surfinswdif(i)
+           surf_usm_v(1)%rad_sw_ref(m) = surfinsw(i) - surfinswdir(i) -     &
+                                         surfinswdif(i)
+           surf_usm_v(1)%rad_sw_res(m) = surfins(i)
            surf_usm_v(1)%rad_lw_in(m)  = surfinlw(i)
            surf_usm_v(1)%rad_lw_out(m) = surfoutlw(i)
@@ -5161,4 +5246,7 @@
                                          surfinlw(i) - surfoutlw(i)
            surf_usm_v(1)%rad_net_l(m)  = surf_usm_v(1)%rad_net(m)
+           surf_usm_v(1)%rad_lw_dif(m) = surfinlwdif(i)
+           surf_usm_v(1)%rad_lw_ref(m) = surfinlw(i) - surfinlwdif(i)
+           surf_usm_v(1)%rad_lw_res(m) = surfinl(i)
 !
 !--     eastward-facing
@@ -5166,4 +5254,9 @@
            surf_usm_v(2)%rad_sw_in(m)  = surfinsw(i)
            surf_usm_v(2)%rad_sw_out(m) = surfoutsw(i)
+           surf_usm_v(2)%rad_sw_dir(m) = surfinswdir(i)
+           surf_usm_v(2)%rad_sw_dif(m) = surfinswdif(i)
+           surf_usm_v(2)%rad_sw_ref(m) = surfinsw(i) - surfinswdir(i) -     &
+                                         surfinswdif(i)
+           surf_usm_v(2)%rad_sw_res(m) = surfins(i)
            surf_usm_v(2)%rad_lw_in(m)  = surfinlw(i)
            surf_usm_v(2)%rad_lw_out(m) = surfoutlw(i)
@@ -5171,4 +5264,7 @@
                                          surfinlw(i) - surfoutlw(i)
            surf_usm_v(2)%rad_net_l(m)  = surf_usm_v(2)%rad_net(m)
+           surf_usm_v(2)%rad_lw_dif(m) = surfinlwdif(i)
+           surf_usm_v(2)%rad_lw_ref(m) = surfinlw(i) - surfinlwdif(i)
+           surf_usm_v(2)%rad_lw_res(m) = surfinl(i)
 !
 !--     westward-facding
@@ -5176,4 +5272,9 @@
            surf_usm_v(3)%rad_sw_in(m)  = surfinsw(i)
            surf_usm_v(3)%rad_sw_out(m) = surfoutsw(i)
+           surf_usm_v(3)%rad_sw_dir(m) = surfinswdir(i)
+           surf_usm_v(3)%rad_sw_dif(m) = surfinswdif(i)
+           surf_usm_v(3)%rad_sw_ref(m) = surfinsw(i) - surfinswdir(i) -     &
+                                         surfinswdif(i)
+           surf_usm_v(3)%rad_sw_res(m) = surfins(i)
            surf_usm_v(3)%rad_lw_in(m)  = surfinlw(i)
            surf_usm_v(3)%rad_lw_out(m) = surfoutlw(i)
@@ -5181,4 +5282,7 @@
                                          surfinlw(i) - surfoutlw(i)
            surf_usm_v(3)%rad_net_l(m)  = surf_usm_v(3)%rad_net(m)
+           surf_usm_v(3)%rad_lw_dif(m) = surfinlwdif(i)
+           surf_usm_v(3)%rad_lw_ref(m) = surfinlw(i) - surfinlwdif(i)
+           surf_usm_v(3)%rad_lw_res(m) = surfinl(i)
 !
 !--     (2) land surfaces
@@ -5187,8 +5291,16 @@
            surf_lsm_h%rad_sw_in(m)  = surfinsw(i)
            surf_lsm_h%rad_sw_out(m) = surfoutsw(i)
+           surf_lsm_h%rad_sw_dir(m) = surfinswdir(i)
+           surf_lsm_h%rad_sw_dif(m) = surfinswdif(i)
+           surf_lsm_h%rad_sw_ref(m) = surfinsw(i) - surfinswdir(i) -        &
+                                         surfinswdif(i)
+           surf_lsm_h%rad_sw_res(m) = surfins(i)
            surf_lsm_h%rad_lw_in(m)  = surfinlw(i)
            surf_lsm_h%rad_lw_out(m) = surfoutlw(i)
            surf_lsm_h%rad_net(m)    = surfinsw(i) - surfoutsw(i) +          &
                                       surfinlw(i) - surfoutlw(i)
+           surf_lsm_h%rad_lw_dif(m) = surfinlwdif(i)
+           surf_lsm_h%rad_lw_ref(m) = surfinlw(i) - surfinlwdif(i)
+           surf_lsm_h%rad_lw_res(m) = surfinl(i)
 !
 !--     northward-facding
@@ -5196,8 +5308,16 @@
            surf_lsm_v(0)%rad_sw_in(m)  = surfinsw(i)
            surf_lsm_v(0)%rad_sw_out(m) = surfoutsw(i)
+           surf_lsm_v(0)%rad_sw_dir(m) = surfinswdir(i)
+           surf_lsm_v(0)%rad_sw_dif(m) = surfinswdif(i)
+           surf_lsm_v(0)%rad_sw_ref(m) = surfinsw(i) - surfinswdir(i) -     &
+                                         surfinswdif(i)
+           surf_lsm_v(0)%rad_sw_res(m) = surfins(i)
            surf_lsm_v(0)%rad_lw_in(m)  = surfinlw(i)
            surf_lsm_v(0)%rad_lw_out(m) = surfoutlw(i)
            surf_lsm_v(0)%rad_net(m)    = surfinsw(i) - surfoutsw(i) +       &
                                          surfinlw(i) - surfoutlw(i)
+           surf_lsm_v(0)%rad_lw_dif(m) = surfinlwdif(i)
+           surf_lsm_v(0)%rad_lw_ref(m) = surfinlw(i) - surfinlwdif(i)
+           surf_lsm_v(0)%rad_lw_res(m) = surfinl(i)
 !
 !--     southward-facding
@@ -5205,8 +5325,16 @@
            surf_lsm_v(1)%rad_sw_in(m)  = surfinsw(i)
            surf_lsm_v(1)%rad_sw_out(m) = surfoutsw(i)
+           surf_lsm_v(1)%rad_sw_dir(m) = surfinswdir(i)
+           surf_lsm_v(1)%rad_sw_dif(m) = surfinswdif(i)
+           surf_lsm_v(1)%rad_sw_ref(m) = surfinsw(i) - surfinswdir(i) -     &
+                                         surfinswdif(i)
+           surf_lsm_v(1)%rad_sw_res(m) = surfins(i)
            surf_lsm_v(1)%rad_lw_in(m)  = surfinlw(i)
            surf_lsm_v(1)%rad_lw_out(m) = surfoutlw(i)
            surf_lsm_v(1)%rad_net(m)    = surfinsw(i) - surfoutsw(i) +       &
                                          surfinlw(i) - surfoutlw(i)
+           surf_lsm_v(1)%rad_lw_dif(m) = surfinlwdif(i)
+           surf_lsm_v(1)%rad_lw_ref(m) = surfinlw(i) - surfinlwdif(i)
+           surf_lsm_v(1)%rad_lw_res(m) = surfinl(i)
 !
 !--     eastward-facing
@@ -5214,8 +5342,16 @@
            surf_lsm_v(2)%rad_sw_in(m)  = surfinsw(i)
            surf_lsm_v(2)%rad_sw_out(m) = surfoutsw(i)
+           surf_lsm_v(2)%rad_sw_dir(m) = surfinswdir(i)
+           surf_lsm_v(2)%rad_sw_dif(m) = surfinswdif(i)
+           surf_lsm_v(2)%rad_sw_ref(m) = surfinsw(i) - surfinswdir(i) -     &
+                                         surfinswdif(i)
+           surf_lsm_v(2)%rad_sw_res(m) = surfins(i)
            surf_lsm_v(2)%rad_lw_in(m)  = surfinlw(i)
            surf_lsm_v(2)%rad_lw_out(m) = surfoutlw(i)
            surf_lsm_v(2)%rad_net(m)    = surfinsw(i) - surfoutsw(i) +       &
                                          surfinlw(i) - surfoutlw(i)
+           surf_lsm_v(2)%rad_lw_dif(m) = surfinlwdif(i)
+           surf_lsm_v(2)%rad_lw_ref(m) = surfinlw(i) - surfinlwdif(i)
+           surf_lsm_v(2)%rad_lw_res(m) = surfinl(i)
 !
 !--     westward-facing
@@ -5223,8 +5359,16 @@
            surf_lsm_v(3)%rad_sw_in(m)  = surfinsw(i)
            surf_lsm_v(3)%rad_sw_out(m) = surfoutsw(i)
+           surf_lsm_v(3)%rad_sw_dir(m) = surfinswdir(i)
+           surf_lsm_v(3)%rad_sw_dif(m) = surfinswdif(i)
+           surf_lsm_v(3)%rad_sw_ref(m) = surfinsw(i) - surfinswdir(i) -     &
+                                         surfinswdif(i)
+           surf_lsm_v(3)%rad_sw_res(m) = surfins(i)
            surf_lsm_v(3)%rad_lw_in(m)  = surfinlw(i)
            surf_lsm_v(3)%rad_lw_out(m) = surfoutlw(i)
            surf_lsm_v(3)%rad_net(m)    = surfinsw(i) - surfoutsw(i) +       &
                                          surfinlw(i) - surfoutlw(i)
+           surf_lsm_v(3)%rad_lw_dif(m) = surfinlwdif(i)
+           surf_lsm_v(3)%rad_lw_ref(m) = surfinlw(i) - surfinlwdif(i)
+           surf_lsm_v(3)%rad_lw_res(m) = surfinl(i)
         ENDIF
 
