Index: palm/trunk/SOURCE/surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/surface_mod.f90	(revision 4331)
+++ palm/trunk/SOURCE/surface_mod.f90	(revision 4346)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Introduction of wall_flags_total_0, which currently sets bits based on static
+! topography information used in wall_flags_static_0
+! 
+! 4331 2019-12-10 18:25:02Z suehring
 ! -pt_2m - array is moved to diagnostic_output_quantities
 ! 
@@ -114,5 +118,6 @@
 
     USE indices,                                                               &
-        ONLY:  nxl, nxlg, nxr, nxrg, nys, nysg, nyn, nyng, nzb, nzt, wall_flags_static_0
+        ONLY:  nxl, nxlg, nxr, nxrg, nys, nysg, nyn, nyng, nzb, nzt,           &
+               wall_flags_total_0
 
     USE grid_variables,                                                        &
@@ -590,6 +595,6 @@
 !         
 !--                Check if current gridpoint belongs to the atmosphere
-                   IF ( BTEST( wall_flags_static_0(k,j,i), 0 ) )  THEN
-                      IF ( .NOT. BTEST( wall_flags_static_0(k+bc_h(l)%koff,           &
+                   IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )  THEN
+                      IF ( .NOT. BTEST( wall_flags_total_0(k+bc_h(l)%koff,     &
                                                      j+bc_h(l)%joff,           &
                                                      i+bc_h(l)%ioff), 0 ) )    &
@@ -621,8 +626,8 @@
 !         
 !--                Check if current gridpoint belongs to the atmosphere
-                   IF ( BTEST( wall_flags_static_0(k,j,i), 0 ) )  THEN
+                   IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )  THEN
 !         
 !--                   Upward-facing
-                      IF ( .NOT. BTEST( wall_flags_static_0(k+bc_h(l)%koff,           &
+                      IF ( .NOT. BTEST( wall_flags_total_0(k+bc_h(l)%koff,     &
                                                      j+bc_h(l)%joff,           &
                                                      i+bc_h(l)%ioff), 0 )      &
@@ -657,6 +662,6 @@
 !         
 !--                Check if current gridpoint belongs to the atmosphere
-                   IF ( BTEST( wall_flags_static_0(k,j,i), 0 ) )  THEN
-                      IF ( .NOT. BTEST( wall_flags_static_0(k+bc_v(l)%koff,           &
+                   IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )  THEN
+                      IF ( .NOT. BTEST( wall_flags_total_0(k+bc_v(l)%koff,     &
                                                      j+bc_v(l)%joff,           &
                                                      i+bc_v(l)%ioff), 0 ) )    &
@@ -690,8 +695,8 @@
 !         
 !--                Check if current gridpoint belongs to the atmosphere
-                   IF ( BTEST( wall_flags_static_0(k,j,i), 0 ) )  THEN
+                   IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )  THEN
 !         
 !--                   Upward-facing
-                      IF ( .NOT. BTEST( wall_flags_static_0(k+bc_v(l)%koff,           &
+                      IF ( .NOT. BTEST( wall_flags_total_0(k+bc_v(l)%koff,     &
                                                      j+bc_v(l)%joff,           &
                                                      i+bc_v(l)%ioff), 0 )      &
@@ -770,16 +775,16 @@
 !
 !--             Check if current gridpoint belongs to the atmosphere
-                IF ( BTEST( wall_flags_static_0(k,j,i), 0 ) )  THEN
+                IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )  THEN
 !
 !--                Check if grid point adjoins to any upward-facing horizontal
 !--                surface, e.g. the Earth surface, plane roofs, or ceilings.
 
-                   IF ( .NOT. BTEST( wall_flags_static_0(k-1,j,i), 0 ) )  THEN
+                   IF ( .NOT. BTEST( wall_flags_total_0(k-1,j,i), 0 ) )  THEN
 !
 !--                   Determine flags indicating a terrain surface, a building
 !--                   surface, 
-                      terrain  = BTEST( wall_flags_static_0(k-1,j,i), 5 )  .OR.       &
+                      terrain  = BTEST( wall_flags_total_0(k-1,j,i), 5 )  .OR.       &
                                  topo_no_distinct
-                      building = BTEST( wall_flags_static_0(k-1,j,i), 6 )  .OR.       &
+                      building = BTEST( wall_flags_total_0(k-1,j,i), 6 )  .OR.       &
                                  topo_no_distinct
 !
@@ -787,6 +792,6 @@
 !--                   as terrain but with a non-grid resolved building on top.
 !--                   These surfaces will be flagged as urban surfaces.
-                      unresolved_building = BTEST( wall_flags_static_0(k-1,j,i), 5 )  &
-                                     .AND.  BTEST( wall_flags_static_0(k-1,j,i), 6 )
+                      unresolved_building = BTEST( wall_flags_total_0(k-1,j,i), 5 )  &
+                                     .AND.  BTEST( wall_flags_total_0(k-1,j,i), 6 )
 !
 !--                   Land-surface type
@@ -822,5 +827,5 @@
 !--                Check for any other downward-facing surface. So far only for 
 !--                default surface type.
-                   ELSEIF ( .NOT. BTEST( wall_flags_static_0(k+1,j,i), 0 ) )  THEN
+                   ELSEIF ( .NOT. BTEST( wall_flags_total_0(k+1,j,i), 0 ) )  THEN
                       num_def_h(1) = num_def_h(1) + 1
                    ENDIF 
@@ -835,18 +840,18 @@
           DO  j = nys, nyn
              DO  k = nzb+1, nzt
-                IF ( BTEST( wall_flags_static_0(k,j,i), 0 ) )  THEN
+                IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )  THEN
 !
 !--                Northward-facing
-                   IF ( .NOT. BTEST( wall_flags_static_0(k,j-1,i), 0 ) )  THEN
+                   IF ( .NOT. BTEST( wall_flags_total_0(k,j-1,i), 0 ) )  THEN
 !
 !--                   Determine flags indicating terrain or building
 
-                      terrain  = BTEST( wall_flags_static_0(k,j-1,i), 5 )  .OR.       &
+                      terrain  = BTEST( wall_flags_total_0(k,j-1,i), 5 )  .OR.       &
                                  topo_no_distinct
-                      building = BTEST( wall_flags_static_0(k,j-1,i), 6 )   .OR.      &
+                      building = BTEST( wall_flags_total_0(k,j-1,i), 6 )   .OR.      &
                                  topo_no_distinct
 
-                      unresolved_building = BTEST( wall_flags_static_0(k,j-1,i), 5 )  &
-                                     .AND.  BTEST( wall_flags_static_0(k,j-1,i), 6 )
+                      unresolved_building = BTEST( wall_flags_total_0(k,j-1,i), 5 )  &
+                                     .AND.  BTEST( wall_flags_total_0(k,j-1,i), 6 )
                                      
                       IF (  land_surface  .AND.  terrain  .AND.                &
@@ -873,14 +878,14 @@
 !
 !--                Southward-facing
-                   IF ( .NOT. BTEST( wall_flags_static_0(k,j+1,i), 0 ) )  THEN
+                   IF ( .NOT. BTEST( wall_flags_total_0(k,j+1,i), 0 ) )  THEN
 !
 !--                   Determine flags indicating terrain or building
-                      terrain  = BTEST( wall_flags_static_0(k,j+1,i), 5 )  .OR.       &
+                      terrain  = BTEST( wall_flags_total_0(k,j+1,i), 5 )  .OR.       &
                                  topo_no_distinct
-                      building = BTEST( wall_flags_static_0(k,j+1,i), 6 )  .OR.       &
+                      building = BTEST( wall_flags_total_0(k,j+1,i), 6 )  .OR.       &
                                  topo_no_distinct
                                  
-                      unresolved_building = BTEST( wall_flags_static_0(k,j+1,i), 5 )  &
-                                     .AND.  BTEST( wall_flags_static_0(k,j+1,i), 6 ) 
+                      unresolved_building = BTEST( wall_flags_total_0(k,j+1,i), 5 )  &
+                                     .AND.  BTEST( wall_flags_total_0(k,j+1,i), 6 ) 
                                 
                       IF (  land_surface  .AND.  terrain  .AND.                &
@@ -907,14 +912,14 @@
 !
 !--                Eastward-facing
-                   IF ( .NOT. BTEST( wall_flags_static_0(k,j,i-1), 0 ) )  THEN
+                   IF ( .NOT. BTEST( wall_flags_total_0(k,j,i-1), 0 ) )  THEN
 !
 !--                   Determine flags indicating terrain or building
-                      terrain  = BTEST( wall_flags_static_0(k,j,i-1), 5 )  .OR.       &
+                      terrain  = BTEST( wall_flags_total_0(k,j,i-1), 5 )  .OR.       &
                                  topo_no_distinct
-                      building = BTEST( wall_flags_static_0(k,j,i-1), 6 )  .OR.       &
+                      building = BTEST( wall_flags_total_0(k,j,i-1), 6 )  .OR.       &
                                  topo_no_distinct
                                  
-                      unresolved_building = BTEST( wall_flags_static_0(k,j,i-1), 5 )  &
-                                     .AND.  BTEST( wall_flags_static_0(k,j,i-1), 6 )
+                      unresolved_building = BTEST( wall_flags_total_0(k,j,i-1), 5 )  &
+                                     .AND.  BTEST( wall_flags_total_0(k,j,i-1), 6 )
                                      
                       IF (  land_surface  .AND.  terrain  .AND.                &
@@ -941,14 +946,14 @@
 !
 !--                Westward-facing
-                   IF ( .NOT. BTEST( wall_flags_static_0(k,j,i+1), 0 ) )  THEN
+                   IF ( .NOT. BTEST( wall_flags_total_0(k,j,i+1), 0 ) )  THEN
 !
 !--                   Determine flags indicating terrain or building
-                      terrain  = BTEST( wall_flags_static_0(k,j,i+1), 5 )  .OR.       &
+                      terrain  = BTEST( wall_flags_total_0(k,j,i+1), 5 )  .OR.       &
                                  topo_no_distinct
-                      building = BTEST( wall_flags_static_0(k,j,i+1), 6 )  .OR.       &
+                      building = BTEST( wall_flags_total_0(k,j,i+1), 6 )  .OR.       &
                                  topo_no_distinct
                                  
-                      unresolved_building = BTEST( wall_flags_static_0(k,j,i+1), 5 )  &
-                                     .AND.  BTEST( wall_flags_static_0(k,j,i+1), 6 )
+                      unresolved_building = BTEST( wall_flags_total_0(k,j,i+1), 5 )  &
+                                     .AND.  BTEST( wall_flags_total_0(k,j,i+1), 6 )
                                  
                       IF (  land_surface  .AND.  terrain  .AND.                &
@@ -2139,15 +2144,15 @@
 !
 !--             Check if current gridpoint belongs to the atmosphere
-                IF ( BTEST( wall_flags_static_0(k,j,i), 0 ) )  THEN
+                IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) )  THEN
 !
 !--                Upward-facing surface. Distinguish between differet surface types.
 !--                To do, think about method to flag natural and non-natural 
 !--                surfaces. 
-                   IF ( .NOT. BTEST( wall_flags_static_0(k-1,j,i), 0 ) )  THEN 
+                   IF ( .NOT. BTEST( wall_flags_total_0(k-1,j,i), 0 ) )  THEN 
 !
 !--                   Determine flags indicating terrain or building
-                      terrain  = BTEST( wall_flags_static_0(k-1,j,i), 5 )  .OR.       &
+                      terrain  = BTEST( wall_flags_total_0(k-1,j,i), 5 )  .OR.       &
                                  topo_no_distinct
-                      building = BTEST( wall_flags_static_0(k-1,j,i), 6 )  .OR.       &
+                      building = BTEST( wall_flags_total_0(k-1,j,i), 6 )  .OR.       &
                                  topo_no_distinct
                                  
@@ -2156,6 +2161,6 @@
 !--                   as terrain but with a non-grid resolved building on top.
 !--                   These surfaces will be flagged as urban surfaces.
-                      unresolved_building = BTEST( wall_flags_static_0(k-1,j,i), 5 )  &
-                                     .AND.  BTEST( wall_flags_static_0(k-1,j,i), 6 )
+                      unresolved_building = BTEST( wall_flags_total_0(k-1,j,i), 5 )  &
+                                     .AND.  BTEST( wall_flags_total_0(k-1,j,i), 6 )
 !
 !--                   Natural surface type          
@@ -2195,5 +2200,5 @@
 !--                Check for any other downward-facing surface. So far only for 
 !--                default surface type.
-                   ELSEIF ( .NOT. BTEST( wall_flags_static_0(k+1,j,i), 0 ) )  THEN
+                   ELSEIF ( .NOT. BTEST( wall_flags_total_0(k+1,j,i), 0 ) )  THEN
                       CALL initialize_horizontal_surfaces( k, j, i,            &
                                                            surf_def_h(1),      &
@@ -2205,14 +2210,14 @@
 !--                Check for vertical walls and, if required, initialize it.
 !                  Start with northward-facing surface.
-                   IF ( .NOT. BTEST( wall_flags_static_0(k,j-1,i), 0 ) )  THEN
+                   IF ( .NOT. BTEST( wall_flags_total_0(k,j-1,i), 0 ) )  THEN
 !
 !--                   Determine flags indicating terrain or building
-                      terrain  = BTEST( wall_flags_static_0(k,j-1,i), 5 )  .OR.       &
+                      terrain  = BTEST( wall_flags_total_0(k,j-1,i), 5 )  .OR.       &
                                  topo_no_distinct
-                      building = BTEST( wall_flags_static_0(k,j-1,i), 6 )  .OR.       &
+                      building = BTEST( wall_flags_total_0(k,j-1,i), 6 )  .OR.       &
                                  topo_no_distinct
 
-                      unresolved_building = BTEST( wall_flags_static_0(k,j-1,i), 5 )  &
-                                     .AND.  BTEST( wall_flags_static_0(k,j-1,i), 6 )
+                      unresolved_building = BTEST( wall_flags_total_0(k,j-1,i), 5 )  &
+                                     .AND.  BTEST( wall_flags_total_0(k,j-1,i), 6 )
                                      
                       IF ( land_surface  .AND.  terrain  .AND.                 &
@@ -2242,14 +2247,14 @@
 !
 !--                southward-facing surface
-                   IF ( .NOT. BTEST( wall_flags_static_0(k,j+1,i), 0 ) )  THEN
+                   IF ( .NOT. BTEST( wall_flags_total_0(k,j+1,i), 0 ) )  THEN
 !
 !--                   Determine flags indicating terrain or building
-                      terrain  = BTEST( wall_flags_static_0(k,j+1,i), 5 )  .OR.       &
+                      terrain  = BTEST( wall_flags_total_0(k,j+1,i), 5 )  .OR.       &
                                  topo_no_distinct
-                      building = BTEST( wall_flags_static_0(k,j+1,i), 6 )  .OR.       &
+                      building = BTEST( wall_flags_total_0(k,j+1,i), 6 )  .OR.       &
                                  topo_no_distinct
                                  
-                      unresolved_building = BTEST( wall_flags_static_0(k,j+1,i), 5 )  &
-                                     .AND.  BTEST( wall_flags_static_0(k,j+1,i), 6 )
+                      unresolved_building = BTEST( wall_flags_total_0(k,j+1,i), 5 )  &
+                                     .AND.  BTEST( wall_flags_total_0(k,j+1,i), 6 )
                                      
                       IF ( land_surface  .AND.  terrain  .AND.                 &
@@ -2279,14 +2284,14 @@
 !
 !--                eastward-facing surface
-                   IF ( .NOT. BTEST( wall_flags_static_0(k,j,i-1), 0 ) )  THEN
+                   IF ( .NOT. BTEST( wall_flags_total_0(k,j,i-1), 0 ) )  THEN
 !
 !--                   Determine flags indicating terrain or building
-                      terrain  = BTEST( wall_flags_static_0(k,j,i-1), 5 )  .OR.       &
+                      terrain  = BTEST( wall_flags_total_0(k,j,i-1), 5 )  .OR.       &
                                  topo_no_distinct
-                      building = BTEST( wall_flags_static_0(k,j,i-1), 6 )  .OR.       &
+                      building = BTEST( wall_flags_total_0(k,j,i-1), 6 )  .OR.       &
                                  topo_no_distinct
                                  
-                      unresolved_building = BTEST( wall_flags_static_0(k,j,i-1), 5 )  &
-                                     .AND.  BTEST( wall_flags_static_0(k,j,i-1), 6 )
+                      unresolved_building = BTEST( wall_flags_total_0(k,j,i-1), 5 )  &
+                                     .AND.  BTEST( wall_flags_total_0(k,j,i-1), 6 )
                                  
                       IF ( land_surface  .AND.  terrain  .AND.                 &
@@ -2316,14 +2321,14 @@
 !   
 !--                westward-facing surface
-                   IF ( .NOT. BTEST( wall_flags_static_0(k,j,i+1), 0 ) )  THEN
+                   IF ( .NOT. BTEST( wall_flags_total_0(k,j,i+1), 0 ) )  THEN
 !
 !--                   Determine flags indicating terrain or building
-                      terrain  = BTEST( wall_flags_static_0(k,j,i+1), 5 )  .OR.       &
+                      terrain  = BTEST( wall_flags_total_0(k,j,i+1), 5 )  .OR.       &
                                  topo_no_distinct
-                      building = BTEST( wall_flags_static_0(k,j,i+1), 6 )  .OR.       &
+                      building = BTEST( wall_flags_total_0(k,j,i+1), 6 )  .OR.       &
                                  topo_no_distinct
                                  
-                      unresolved_building = BTEST( wall_flags_static_0(k,j,i+1), 5 )  &
-                                     .AND.  BTEST( wall_flags_static_0(k,j,i+1), 6 )
+                      unresolved_building = BTEST( wall_flags_total_0(k,j,i+1), 5 )  &
+                                     .AND.  BTEST( wall_flags_total_0(k,j,i+1), 6 )
                                   
                       IF ( land_surface  .AND.  terrain  .AND.                 &
