Index: palm/trunk/SOURCE/init_grid.f90
===================================================================
--- palm/trunk/SOURCE/init_grid.f90	(revision 4867)
+++ palm/trunk/SOURCE/init_grid.f90	(revision 4868)
@@ -24,4 +24,8 @@
 ! -----------------
 ! $Id$
+! Height of level k=0 for the u,v-grid is always set 0.0,
+! small changes to follow coding standard
+!
+! 4828 2021-01-05 11:21:41Z Giersch
 ! Bugfix in building mapping when static driver is available but no actual building is present
 ! within the model domain
@@ -161,5 +165,5 @@
                dz_stretch_factor_array, dz_stretch_level, dz_stretch_level_end,                    &
                dz_stretch_level_end_index, dz_stretch_level_start_index,                           &
-               dz_stretch_level_start, ibc_uv_b, message_string,                                   &
+               dz_stretch_level_start, message_string,                                             &
                number_stretch_level_end,                                                           &
                number_stretch_level_start,                                                         &
@@ -386,16 +390,10 @@
 
 !
-!--    Grid for atmosphere with surface at z=0 (k=0, w-grid).
-!--    First compute the u- and v-levels. In case of dirichlet bc for u and v the first u/v- and
-!--    w-level (k=0) are defined at same height (z=0).
-!--    The second u-level (k=1) corresponds to the top of the surface layer. In case of symmetric
-!--    boundaries (closed channel flow), the first grid point is always at z=0.
-       IF ( ibc_uv_b == 0  .OR.  ibc_uv_b == 2  .OR.  topography == 'closed_channel' )  THEN
-          zu(0) = 0.0_wp
-       ELSE
-          zu(0) = - dz(1) * 0.5_wp
-       ENDIF
-
-       zu(1) =   dz(1) * 0.5_wp
+!--    Grid for atmosphere with surface at z=0. This corresponds to k=0 on the w-grid AND
+!--    the u-grid.
+!--    First compute the u- and v-levels.
+!--    The second u-level (k=1) corresponds to the top of the surface layer.
+       zu(0) = 0.0_wp
+       zu(1) = dz(1) * 0.5_wp
 
 !
@@ -430,5 +428,5 @@
           dz_level_end = ABS( zu(k) - dz_stretch_level_end(n) )
 
-          IF ( dz_level_end  < dz(n+1)/3.0 )  THEN
+          IF ( dz_level_end  <  dz(n+1) / 3.0 )  THEN
              zu(k) = dz_stretch_level_end(n)
              dz_stretched = dz(n+1)
@@ -572,7 +570,7 @@
 !
 !--    Compute the w-levels. They are always staggered half-way between the corresponding u-levels,
-!--    except in case of dirichlet bc for u and v at the ground. In this case the first u- and
+!--    except for u and v at the ground. In this case the first u- and
 !--    w-level are defined at same height. The top w-level (nzt+1) is not used but set for
-!--    consistency, since w and all scalar variables are defined up tp nzt+1.
+!--    consistency, since w and all scalar variables are defined up to nzt+1.
        zw(nzt+1) = dz(1)
        zw(nzt)   = 0.0_wp
@@ -582,8 +580,6 @@
 
 !
-!--    In case of dirichlet bc for u and v the first u- and w-level are defined at same height.
-       IF ( ibc_uv_b == 0 ) THEN
-          zu(0) = zw(0)
-       ENDIF
+!--    Like for the atmosphere, the first u-grid and w-grid-level are defined at same height.
+       zu(0) = zw(0)
 
     ENDIF !End of defining the vertical grid levels
@@ -822,4 +818,5 @@
 !--    Second branch for stretching from fine to rough
        ELSEIF ( dz(n) < dz(n+1) )  THEN
+
           DO WHILE ( stretch_factor_1 <= stretch_factor_upper_limit )
 
@@ -853,4 +850,5 @@
 
        ELSE
+
           message_string= 'Two adjacent values of dz must be different'
           CALL message( 'init_grid', 'PA0228', 1, 2, 0, 6, 0 )
@@ -872,4 +870,5 @@
 
        ENDIF
+
     ENDDO
 
@@ -1280,5 +1279,6 @@
 !-- Topography input via ASCII format.
     ELSE
-       ocean_offset     = MERGE( zw(0), 0.0_wp, ocean_mode )
+
+       ocean_offset = MERGE( zw(0), 0.0_wp, ocean_mode )
 !
 !--    Initialize topography bit 0 (indicates obstacle) everywhere to zero and clear all grid points
@@ -1305,4 +1305,5 @@
           ENDDO
        ENDDO
+
     ENDIF
 
@@ -1353,7 +1354,7 @@
     INTEGER(iwp) ::  num_wall   !< number of surrounding vertical walls for a single grid point
 
-    INTEGER(iwp), DIMENSION(:,:,:), ALLOCATABLE            ::  topo_tmp          !< temporary 3D-topography used to fill holes
-    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  topo_3d           !< 3D-topography array merging buildings and
-                                                                                 !< orography
+    INTEGER(iwp), DIMENSION(:,:,:), ALLOCATABLE            ::  topo_tmp  !< temporary 3D-topography used to fill holes
+    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  topo_3d   !< 3D-topography array merging buildings and
+                                                                         !< orography
 
     LOGICAL      ::  filled = .FALSE. !< flag indicating if holes were filled
@@ -1790,5 +1791,4 @@
 
        CASE ( 'tunnel' )
-
 !
 !--       Tunnel height
@@ -2075,6 +2075,6 @@
     ENDIF
 
-
  END SUBROUTINE init_topo
+
 
  SUBROUTINE set_topo_flags(topo)
@@ -2126,5 +2126,5 @@
           ENDDO
 
-          DO k = nzb, nzt
+          DO  k = nzb, nzt
 !
 !--          w grid
@@ -2145,11 +2145,10 @@
 !-- Set outer array for scalars to mask near-surface grid points. Note, on basis of flag 24 futher
 !-- flags will be derived which are used to control production of subgrid TKE production near walls.
-
     ALLOCATE( wall_flags_total_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
     wall_flags_total_0 = 0
 
-    DO i = nxl, nxr
-       DO j = nys, nyn
-          DO k = nzb, nzt+1
+    DO  i = nxl, nxr
+       DO  j = nys, nyn
+          DO  k = nzb, nzt+1
              wall_flags_total_0(k,j,i) = IOR( wall_flags_total_0(k,j,i), wall_flags_static_0(k,j,i) )
           ENDDO
@@ -2159,7 +2158,7 @@
     CALL exchange_horiz_int( wall_flags_total_0, nys, nyn, nxl, nxr, nzt, nbgp )
 
-    DO i = nxl, nxr
-       DO j = nys, nyn
-          DO k = nzb, nzt+1
+    DO  i = nxl, nxr
+       DO  j = nys, nyn
+          DO  k = nzb, nzt+1
              IF ( BTEST( wall_flags_total_0(k,j-1,i), 0 )    .AND.                                 &
                   BTEST( wall_flags_total_0(k,j+1,i), 0 )    .AND.                                 &
@@ -2176,7 +2175,7 @@
 !
 !-- Set further special flags
-    DO i = nxl, nxr
-       DO j = nys, nyn
-          DO k = nzb, nzt+1
+    DO  i = nxl, nxr
+       DO  j = nys, nyn
+          DO  k = nzb, nzt+1
 !
 !--          scalar grid, former nzb_diff_s_inner.
@@ -2205,5 +2204,5 @@
 
 
-          DO k = nzb+1, nzt
+          DO  k = nzb+1, nzt
 !
 !--          Special flag on u grid, former nzb_u_inner + 1, required for disturb_field and
@@ -2254,5 +2253,5 @@
 !
 !--       Flags indicating downward facing walls
-          DO k = nzb+1, nzt+1
+          DO  k = nzb+1, nzt+1
 !
 !--          Scalar grid
@@ -2278,5 +2277,5 @@
 !
 !--       Flags indicating upward facing walls
-          DO k = nzb, nzt
+          DO  k = nzb, nzt
 !
 !--          Upward facing wall on scalar grid
@@ -2331,5 +2330,5 @@
 !--       species or aerosols.
           IF ( scalar_advec == 'ws-scheme' )  THEN
-             DO k = nzb, nzt
+             DO  k = nzb, nzt
                 IF ( BTEST( wall_flags_total_0(k,j,i), 0 )  .AND. (                                &
                      ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i-1), 0 ) )  .OR.              &
@@ -2364,7 +2363,7 @@
        wall_flags_static_0(nzb,:,:) = IBSET( wall_flags_static_0(nzb,:,:), 5 )
     ELSE
-       DO i = nxl, nxr
-          DO j = nys, nyn
-             DO k = nzb, nzt+1
+       DO  i = nxl, nxr
+          DO  j = nys, nyn
+             DO  k = nzb, nzt+1
 !
 !--             Natural terrain grid point
@@ -2377,7 +2376,7 @@
 !
 !-- Building grid points.
-    DO i = nxl, nxr
-       DO j = nys, nyn
-          DO k = nzb, nzt+1
+    DO  i = nxl, nxr
+       DO  j = nys, nyn
+          DO  k = nzb, nzt+1
              IF ( BTEST( topo(k,j,i), 2 ) )                                                        &
                 wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 6 )
@@ -2387,7 +2386,7 @@
 !
 !-- Set flag 4, indicating new topography grid points due to filtering.
-    DO i = nxl, nxr
-       DO j = nys, nyn
-          DO k = nzb, nzt+1
+    DO  i = nxl, nxr
+       DO  j = nys, nyn
+          DO  k = nzb, nzt+1
              IF ( BTEST( topo(k,j,i), 4 ) )                                                        &
                 wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 4 )
@@ -2398,7 +2397,7 @@
     CALL exchange_horiz_int( wall_flags_static_0, nys, nyn, nxl, nxr, nzt, nbgp )
 
-    DO i = nxl, nxr
-       DO j = nys, nyn
-          DO k = nzb, nzt+1
+    DO  i = nxl, nxr
+       DO  j = nys, nyn
+          DO  k = nzb, nzt+1
              wall_flags_total_0(k,j,i) = IOR( wall_flags_total_0(k,j,i), wall_flags_static_0(k,j,i) )
           ENDDO
