Index: /palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 4258)
+++ /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 4259)
@@ -28,4 +28,8 @@
 ! -----------------
 ! $Id$
+! Instead of terminate the job in case the relative wall fractions do not 
+! sum-up to one, give only an informative message and normalize the fractions.
+! 
+! 4258 2019-10-07 13:29:08Z suehring
 ! - Add checks to ensure that relative fractions of walls, windowns and green
 !   surfaces sum-up to one.
@@ -3512,9 +3516,12 @@
         INTEGER(iwp) ::  l                   !< loop index surface orientation
         INTEGER(iwp) ::  m                   !< loop index surface element
-        INTEGER(iwp) ::  st                  !< dummy  
+        INTEGER(iwp) ::  st                  !< dummy
+
+        LOGICAL      ::  relative_fractions_corrected !< flag indicating if relative surface fractions require normalization
 
         REAL(wp)     ::  c, tin, twin
         REAL(wp)     ::  ground_floor_level_l         !< local height of ground floor level
-        REAL(wp)     ::  z_agl                        !< height above ground
+        REAL(wp)     ::  sum_frac                     !< sum of the relative material fractions at a surface element
+        REAL(wp)     ::  z_agl                        !< height of the surface element above terrain
 
         IF ( debug_output )  CALL debug_message( 'usm_init', 'start' )
@@ -4438,10 +4445,5 @@
                  surf_usm_h%lambda_surf(m) =                                   &
                                     building_pars_f%pars_xy(ind_lambda_surf,j,i)
-              
-              write(9,*) m, SUM( surf_usm_h%frac(:,m) ), "indiv", surf_usm_h%frac(0,m), surf_usm_h%frac(1,m), surf_usm_h%frac(2,m) 
            ENDDO
-           flush(9)
-
-
 
            DO  l = 0, 3
@@ -5037,28 +5039,74 @@
 !
 !--     Run further checks to ensure that the respecitve material fractions are 
-!--     prescribed properly.
+!--     prescribed properly. Start with horizontal surfaces (roofs).
+        relative_fractions_corrected = .FALSE.
         DO  m = 1, surf_usm_h%ns
-           IF ( SUM( surf_usm_h%frac(:,m) ) /= 1.0_wp )  THEN
-              WRITE(message_string,*) 'The relative material fractions do ' // &
-                                      'not sum-up to one at horizotal ' //     &
-                                      'surface. (i,j) = ',                     &
-                                      surf_usm_h%i(m), surf_usm_h%j(m)
-              CALL message( 'urban_surface_model_mod', 'PA0686', 2, 2, myid, 6, 0 )
+           sum_frac = SUM( surf_usm_h%frac(:,m) )
+           IF ( sum_frac /= 1.0_wp )  THEN
+              relative_fractions_corrected = .TRUE.
+!
+!--           Normalize relative fractions to 1. Deviations from 1 can
+!--           arise, e.g. by rounding errors but also by inconsistent 
+!--           driver creation. 
+              IF ( sum_frac /= 0.0_wp )  THEN
+                 surf_usm_h%frac(:,m) = surf_usm_h%frac(:,m) / sum_frac
+!
+!--           In case all relative fractions are erroneously set to zero,
+!--           set wall fraction to 1.
+              ELSE
+                 surf_usm_h%frac(ind_veg_wall,m)  = 1.0_wp
+                 surf_usm_h%frac(ind_wat_win,m)   = 0.0_wp
+                 surf_usm_h%frac(ind_pav_green,m) = 0.0_wp
+              ENDIF
            ENDIF
         ENDDO
-        
+!
+!--     If fractions were normalized, give an informative message.
+#if defined( __parallel )
+        CALL MPI_ALLREDUCE( MPI_IN_PLACE, relative_fractions_corrected, 1,     &
+                            MPI_LOGICAL, MPI_LOR, comm2d, ierr )
+#endif
+        IF ( relative_fractions_corrected )  THEN
+           message_string = 'At some horizotal surfaces the relative '   //    &
+                            'material fractions do not sum-up to one . ' //    &
+                            'Hence, the respective fractions were normalized.'
+           CALL message( 'urban_surface_model_mod', 'PA0686', 0, 0, 0, 6, 0 )
+        ENDIF
+!
+!--     Check relative fractions at vertical surfaces.
+        relative_fractions_corrected = .FALSE.
         DO  l = 0, 3
            DO  m = 1, surf_usm_v(l)%ns
-              IF ( SUM( surf_usm_v(l)%frac(:,m) ) /= 1.0_wp )  THEN
-                 WRITE(message_string,*)                                       &
-                                      'The relative material fractions do ' // &
-                                      'not sum-up to one at vertical ' //      &
-                                      'surface. (i,j) = ',                     &
-                                      surf_usm_v(l)%i(m), surf_usm_v(l)%j(m)
-                 CALL message( 'urban_surface_model_mod', 'PA0686', 2, 2, myid, 6, 0 )
+              sum_frac = SUM( surf_usm_v(l)%frac(:,m) )
+              IF ( sum_frac /= 1.0_wp )  THEN
+                 relative_fractions_corrected = .TRUE.
+!
+!--              Normalize relative fractions to 1.
+                 IF ( sum_frac /= 0.0_wp )  THEN
+                    surf_usm_v(l)%frac(:,m) = surf_usm_v(l)%frac(:,m) / sum_frac
+!
+!--              In case all relative fractions are erroneously set to zero,
+!--              set wall fraction to 1.
+                 ELSE
+                    surf_usm_v(l)%frac(ind_veg_wall,m)  = 1.0_wp
+                    surf_usm_v(l)%frac(ind_wat_win,m)   = 0.0_wp
+                    surf_usm_v(l)%frac(ind_pav_green,m) = 0.0_wp
+                 ENDIF
               ENDIF
            ENDDO
         ENDDO
-!       
+!
+!--     Also here, ff fractions were normalized, give an informative message.
+#if defined( __parallel )
+        CALL MPI_ALLREDUCE( MPI_IN_PLACE, relative_fractions_corrected, 1,     &
+                            MPI_LOGICAL, MPI_LOR, comm2d, ierr )
+#endif
+        IF ( relative_fractions_corrected )  THEN
+           message_string = 'At some vertical surfaces the relative '    //    &
+                            'material fractions do not sum-up to one . ' //    &
+                            'Hence, the respective fractions were normalized.'
+           CALL message( 'urban_surface_model_mod', 'PA0686', 0, 0, 0, 6, 0 )
+        ENDIF
+!
 !--     Read the surface_types array.
 !--     Please note, here also initialization of surface attributes is done as
