Index: palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3371)
+++ palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3378)
@@ -28,4 +28,11 @@
 ! -----------------
 ! $Id$
+! merge from radiation branch (r3362) into trunk
+! (moh.hefny):
+! - check the requested output variables if they are correct
+! - added unscheduled_radiation_calls switch to control force_radiation_call
+! - minor formate changes
+! 
+! 3371 2018-10-18 13:40:12Z knoop
 ! Set flag indicating that albedo at urban surfaces is already initialized
 ! 
@@ -399,5 +406,5 @@
                idcsf, ndcsf, kdcsf, pct,                                       &
                startland, endland, startwall, endwall, skyvf, skyvft, nzub,    &
-               nzut, nzpt, npcbl, pcbl
+               nzut, npcbl, pcbl, unscheduled_radiation_calls
 
     USE statistics,                                                            &
@@ -2399,10 +2406,61 @@
         IMPLICIT NONE
  
-        CHARACTER (len=*),INTENT(IN)    ::  variable !:
-        CHARACTER (len=*),INTENT(OUT)   ::  unit     !:
-        
-        CHARACTER (len=varnamelength)   :: var
-
+        CHARACTER(LEN=*),INTENT(IN)    ::  variable !:
+        CHARACTER(LEN=*),INTENT(OUT)   ::  unit     !:
+
+        INTEGER(iwp)                                  :: i,j          !< index
+        CHARACTER(LEN=varnamelength)                  :: var
+        INTEGER(iwp), PARAMETER                       :: nl1 = 32     !< number of directional usm variables
+        CHARACTER(LEN=varnamelength), DIMENSION(nl1)  :: varlist1 = & !< list of directional usm variables
+                  (/'usm_rad_net','usm_rad_insw','usm_rad_inlw','usm_rad_inswdir',     &
+                    'usm_rad_inswdif','usm_rad_inswref','usm_rad_inlwdif','usm_wshf',  &
+                    'usm_rad_inlwref','usm_rad_outsw','usm_rad_outlw','usm_rad_hf',    &
+                    'usm_rad_ressw','usm_rad_reslw','usm_wghf','usm_wghf_window',      &
+                    'usm_wghf_green','usm_iwghf','usm_iwghf_window','usm_surfz',       &
+                    'usm_surfwintrans','usm_surfcat','usm_surfalb','usm_surfemis',     &
+                    'usm_t_surf','usm_t_surf_window','usm_t_surf_green','usm_t_green', &
+                    'usm_t_surf_10cm','usm_t_wall','usm_t_window','usm_t_green'/)
+
+        INTEGER(iwp), PARAMETER                       :: nl2 = 9      !< number of other variables
+        CHARACTER(LEN=varnamelength), DIMENSION(nl2)  :: varlist2 = & !< list of other usm variables
+                  (/'usm_skyvf','usm_skyvft','usm_svf','usm_dif','usm_rad_pc_inlw',    &
+                  'usm_rad_pc_insw','usm_rad_pc_inswdir','usm_rad_pc_inswdif',         &
+                  'usm_rad_pc_inswref'/)
+
+        INTEGER(iwp), PARAMETER                       :: nd = 5     !< number of directions
+        CHARACTER(LEN=6), DIMENSION(nd), PARAMETER  :: dirname = &  !< direction names
+                  (/'_roof ','_south','_north','_west ','_east '/)
+        LOGICAL                                       :: lfound     !< flag if the variable is found
+
+
+        lfound = .FALSE.
         var = TRIM(variable)
+
+!--     check if variable exists
+!       directional variables
+        DO i = 1, nl1
+           DO j = 1, nd
+              IF ( TRIM(var) == TRIM(varlist1(i))//TRIM(dirname(j)) ) THEN
+                 lfound = .TRUE.
+                 EXIT
+              ENDIF
+              IF ( lfound ) EXIT
+           ENDDO
+        ENDDO
+        IF ( lfound ) GOTO 10
+!       other variables
+        DO i = 1, nl2
+           IF ( TRIM(var) == TRIM(varlist2(i)) ) THEN
+              lfound = .TRUE.
+              EXIT
+           ENDIF
+        ENDDO
+        IF ( .NOT.  lfound ) THEN
+           unit = 'illegal'
+           RETURN
+        ENDIF
+10      CONTINUE
+
+!--     check if variable exists
         IF ( var(1:12) == 'usm_rad_net_'  .OR.  var(1:13) == 'usm_rad_insw_'  .OR.        &
              var(1:13) == 'usm_rad_inlw_'  .OR.  var(1:16) == 'usm_rad_inswdir_'  .OR.    &
@@ -2593,5 +2651,5 @@
 
           CASE ( 'usm_surfz' )
-!--           array of lw radiation falling to local surface after i-th reflection
+!--           array of surface height (z)
               IF ( idsint == iup_u )  THEN
                  DO  m = 1, surf_usm_h%ns
@@ -5332,10 +5390,4 @@
               ENDIF
            ENDDO
-!!!!!!!!!!!!!HACK!!!!!!!!!!!!!!!!!!!
-!           t_window_v_p(l)%t = t_wall_v_p(l)%t
-!           surf_usm_v(l)%tt_window_m  = surf_usm_v(l)%tt_wall_m
-!           t_green_v_p(l)%t = t_wall_v_p(l)%t
-!           surf_usm_v(l)%tt_green_m  = surf_usm_v(l)%tt_wall_m
-!!!!!!!!!!!!!HACK!!!!!!!!!!!!!!!!!!!
         ENDDO
 
@@ -6914,7 +6966,5 @@
         INTEGER(iwp)                                          :: wtc
         REAL(wp), DIMENSION(n_surface_params)                 :: wtp
-        
         LOGICAL                                               :: ascii_file = .FALSE.
-    
         INTEGER(iwp), DIMENSION(0:17, nysg:nyng, nxlg:nxrg)   :: usm_par
         REAL(wp), DIMENSION(1:14, nysg:nyng, nxlg:nxrg)       :: usm_val
@@ -7742,7 +7792,8 @@
 !--        in case of fast changes in the skin temperature, it is required to
 !--        update the radiative fluxes in order to keep the solution stable
-           IF ( ( ABS( t_surf_h_p(m) - t_surf_h(m) ) > 1.0_wp ) .OR. &
+           IF ( ( ( ABS( t_surf_h_p(m) - t_surf_h(m) ) > 1.0_wp ) .OR.           &
                 ( ABS( t_surf_green_h_p(m) - t_surf_green_h(m) ) > 1.0_wp ) .OR. &
-                ( ABS( t_surf_window_h_p(m) - t_surf_window_h(m) ) > 1.0_wp ) ) THEN
+                ( ABS( t_surf_window_h_p(m) - t_surf_window_h(m) ) > 1.0_wp ) )  &
+                 .AND.  unscheduled_radiation_calls  ) THEN
               force_radiation_call_l = .TRUE.
            ENDIF
@@ -7897,5 +7948,5 @@
 
 !--           add RK3 term
-              t_surf_v_p(l)%t(m) = t_surf_v_p(l)%t(m) + dt_3d * tsc(3) *       &
+              t_surf_v_p(l)%t(m) = t_surf_v_p(l)%t(m) + dt_3d * tsc(3) *                   &
                                 surf_usm_v(l)%tt_surface_m(m)
               t_surf_window_v_p(l)%t(m) = t_surf_window_v_p(l)%t(m) + dt_3d * tsc(3) *     &
@@ -7907,6 +7958,6 @@
 !--           store also vpt_surface, which is, due to the lack of moisture on roofs simply
 !--           assumed to be the surface temperature.     
-              surf_usm_v(l)%pt_surface(m) =  ( surf_usm_v(l)%frac(ind_veg_wall,m) * t_surf_v_p(l)%t(m)  &
-                                      + surf_usm_v(l)%frac(ind_wat_win,m) * t_surf_window_v_p(l)%t(m)  &
+              surf_usm_v(l)%pt_surface(m) =  ( surf_usm_v(l)%frac(ind_veg_wall,m) * t_surf_v_p(l)%t(m)   &
+                                      + surf_usm_v(l)%frac(ind_wat_win,m) * t_surf_window_v_p(l)%t(m)    &
                                       + surf_usm_v(l)%frac(ind_pav_green,m) * t_surf_green_v_p(l)%t(m) ) &
                                       / exner(k)
@@ -7920,5 +7971,5 @@
               stend_window = ( t_surf_window_v_p(l)%t(m) - t_surf_window_v(l)%t(m) - dt_3d * tsc(3) *&
                         surf_usm_v(l)%tt_surface_window_m(m) ) / ( dt_3d  * tsc(2) )
-              stend_green = ( t_surf_green_v_p(l)%t(m) - t_surf_green_v(l)%t(m) - dt_3d * tsc(3) *&
+              stend_green = ( t_surf_green_v_p(l)%t(m) - t_surf_green_v(l)%t(m) - dt_3d * tsc(3) *   &
                         surf_usm_v(l)%tt_surface_green_m(m) ) / ( dt_3d  * tsc(2) )
 
@@ -7929,11 +7980,11 @@
                     surf_usm_v(l)%tt_surface_window_m(m) = stend_window
                     surf_usm_v(l)%tt_surface_green_m(m) = stend_green
-                 ELSEIF ( intermediate_timestep_count <                        &
+                 ELSEIF ( intermediate_timestep_count <                                 &
                           intermediate_timestep_count_max )  THEN
-                    surf_usm_v(l)%tt_surface_m(m) = -9.5625_wp * stend +       &
+                    surf_usm_v(l)%tt_surface_m(m) = -9.5625_wp * stend +                &
                                      5.3125_wp * surf_usm_v(l)%tt_surface_m(m)
-                    surf_usm_v(l)%tt_surface_green_m(m) = -9.5625_wp * stend_green +       &
+                    surf_usm_v(l)%tt_surface_green_m(m) = -9.5625_wp * stend_green +    &
                                      5.3125_wp * surf_usm_v(l)%tt_surface_green_m(m)
-                    surf_usm_v(l)%tt_surface_window_m(m) = -9.5625_wp * stend_window +       &
+                    surf_usm_v(l)%tt_surface_window_m(m) = -9.5625_wp * stend_window +  &
                                      5.3125_wp * surf_usm_v(l)%tt_surface_window_m(m)
                  ENDIF
@@ -7943,7 +7994,8 @@
 !--           update the radiative fluxes in order to keep the solution stable
 
-              IF ( ( ABS( t_surf_v_p(l)%t(m) - t_surf_v(l)%t(m) ) > 1.0_wp ) .OR. &
+              IF ( ( ( ABS( t_surf_v_p(l)%t(m) - t_surf_v(l)%t(m) ) > 1.0_wp ) .OR.            &
                    ( ABS( t_surf_green_v_p(l)%t(m) - t_surf_green_v(l)%t(m) ) > 1.0_wp ) .OR.  &
-                   ( ABS( t_surf_window_v_p(l)%t(m) - t_surf_window_v(l)%t(m) ) > 1.0_wp ) ) THEN
+                   ( ABS( t_surf_window_v_p(l)%t(m) - t_surf_window_v(l)%t(m) ) > 1.0_wp ) )   &
+                     .AND.  unscheduled_radiation_calls ) THEN
                  force_radiation_call_l = .TRUE.
               ENDIF
