Index: palm/trunk/SOURCE/init_grid.f90
===================================================================
--- palm/trunk/SOURCE/init_grid.f90	(revision 1885)
+++ palm/trunk/SOURCE/init_grid.f90	(revision 1886)
@@ -19,5 +19,7 @@
 ! Current revisions:
 ! -----------------
-! 
+! Bugfix: setting advection flags near walls
+! reformulated index values for nzb_v_inner
+! variable discriptions added in declaration block
 ! 
 ! Former revisions:
@@ -198,53 +200,65 @@
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  bh      !<
-    INTEGER(iwp) ::  blx     !<
-    INTEGER(iwp) ::  bly     !<
-    INTEGER(iwp) ::  bxl     !<
-    INTEGER(iwp) ::  bxr     !<
-    INTEGER(iwp) ::  byn     !<
-    INTEGER(iwp) ::  bys     !<
-    INTEGER(iwp) ::  ch      !<
-    INTEGER(iwp) ::  cwx     !<
-    INTEGER(iwp) ::  cwy     !<
-    INTEGER(iwp) ::  cxl     !<
-    INTEGER(iwp) ::  cxr     !<
-    INTEGER(iwp) ::  cyn     !<
-    INTEGER(iwp) ::  cys     !<
-    INTEGER(iwp) ::  gls     !<
-    INTEGER(iwp) ::  i       !<
-    INTEGER(iwp) ::  ii      !<
-    INTEGER(iwp) ::  inc     !<
-    INTEGER(iwp) ::  j       !<
-    INTEGER(iwp) ::  k       !<
-    INTEGER(iwp) ::  l       !<
-    INTEGER(iwp) ::  nxl_l   !<
-    INTEGER(iwp) ::  nxr_l   !<
-    INTEGER(iwp) ::  nyn_l   !<
-    INTEGER(iwp) ::  nys_l   !<
-    INTEGER(iwp) ::  nzb_si  !<
-    INTEGER(iwp) ::  nzt_l   !<
-    INTEGER(iwp) ::  vi      !<
-
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE   ::  vertical_influence  !<
-
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_nl  !<
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_nr  !<
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_sl  !<
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_sr  !<
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_l     !<
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_n     !<
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_r     !<
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_s     !<
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  nzb_local  !<
-    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  nzb_tmp    !<
-
-    LOGICAL :: flag_set = .FALSE.  !<
-
-    REAL(wp) ::  dx_l          !<
-    REAL(wp) ::  dy_l          !<
-    REAL(wp) ::  dz_stretched  !<
-
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  topo_height  !<
+    INTEGER(iwp) ::  bh      !< temporary vertical index of building height
+    INTEGER(iwp) ::  blx     !< grid point number of building size along x
+    INTEGER(iwp) ::  bly     !< grid point number of building size along y
+    INTEGER(iwp) ::  bxl     !< index for left building wall
+    INTEGER(iwp) ::  bxr     !< index for right building wall
+    INTEGER(iwp) ::  byn     !< index for north building wall
+    INTEGER(iwp) ::  bys     !< index for south building wall
+    INTEGER(iwp) ::  ch      !< temporary vertical index for canyon height
+    INTEGER(iwp) ::  cwx     !< grid point number of canyon size along x
+    INTEGER(iwp) ::  cwy     !< grid point number of canyon size along y
+    INTEGER(iwp) ::  cxl     !< index for left canyon wall
+    INTEGER(iwp) ::  cxr     !< index for right canyon wall
+    INTEGER(iwp) ::  cyn     !< index for north canyon wall
+    INTEGER(iwp) ::  cys     !< index for south canyon wall
+    INTEGER(iwp) ::  gls     !< number of lateral ghost points at total model
+                             !< domain boundaries required for multigrid solver
+    INTEGER(iwp) ::  i       !< index variable along x
+    INTEGER(iwp) ::  ii      !< loop variable for reading topography file
+    INTEGER(iwp) ::  inc     !< incremental parameter for coarsening grid level
+    INTEGER(iwp) ::  j       !< index variable along y
+    INTEGER(iwp) ::  k       !< index variable along z
+    INTEGER(iwp) ::  l       !< loop variable 
+    INTEGER(iwp) ::  nxl_l   !< index of left PE boundary for multigrid level
+    INTEGER(iwp) ::  nxr_l   !< index of right PE boundary for multigrid level
+    INTEGER(iwp) ::  nyn_l   !< index of north PE boundary for multigrid level
+    INTEGER(iwp) ::  nys_l   !< index of south PE boundary for multigrid level
+    INTEGER(iwp) ::  nzb_si  !< dummy index for local nzb_s_inner
+    INTEGER(iwp) ::  nzt_l   !< index of top PE boundary for multigrid level
+    INTEGER(iwp) ::  vi      !< dummy for vertical influence
+
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE   ::                               &
+                     vertical_influence  !< number of vertical grid points above
+                                         !< obstacle where adjustment of near-
+                                         !< wall mixing length is required
+                                         
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_nl  !< index of
+                                         !< north-left corner location to limit 
+                                         !< near-wall mixing length
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_nr  !< north-right
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_sl  !< south-left
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_sr  !< south-right
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_l     !< distance to 
+                                                             !< adjacent left-facing 
+                                                             !< wall
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_n     !< north-facing
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_r     !< right-facing
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_s     !< right-facing
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  nzb_local  !< index for topography
+                                                             !< top at cell-center
+    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  nzb_tmp    !< dummy to calculate
+                                                             !< topography indices
+                                                             !< on u- and v-grid
+
+    LOGICAL  :: flag_set = .FALSE.  !< steering variable for advection flags
+
+    REAL(wp) ::  dx_l          !< grid spacing along x on different multigrid level
+    REAL(wp) ::  dy_l          !< grid spacing along y on different multigrid level
+    REAL(wp) ::  dz_stretched  !< stretched vertical grid spacing
+
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  topo_height  !< input variable for 
+                                                           !< topography height
 
     
@@ -908,5 +922,5 @@
           ENDDO
        ENDDO
-       nzb_v_inner = nzb_tmp(nys-nbgp:nyn+nbgp,nxl-nbgp:nxr+nbgp)
+       nzb_v_inner = nzb_tmp(nysg:nyng,nxlg:nxrg)
 
 !
@@ -1219,5 +1233,5 @@
     wall_flags_00 = 0
 
-    IF ( scalar_advec == 'ws-scheme' .OR.                                     &
+    IF ( scalar_advec == 'ws-scheme' .OR.                                      &
          scalar_advec == 'ws-scheme-mono' )  THEN
 !
@@ -1232,6 +1246,7 @@
 !--             scalar - x-direction
 !--             WS1 (0), WS3 (1), WS5 (2)
-                IF ( k <= nzb_s_inner(j,i+1) .OR.                              &
-                         ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )       &
+                IF ( ( k <= nzb_s_inner(j,i+1) .OR. k <= nzb_s_inner(j,i+2)    &   
+                  .OR. k <= nzb_s_inner(j,i-1) )                               &
+                    .OR. ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )       &
                            .AND. i == nxl   )    .OR.                          &
                          ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )       &
@@ -1239,5 +1254,12 @@
                 THEN
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 0 )
-                ELSEIF ( k <= nzb_s_inner(j,i+2) .OR. k <= nzb_s_inner(j,i-1)  &
+                ELSEIF ( ( k <= nzb_s_inner(j,i+3) .AND. k > nzb_s_inner(j,i+1)&
+                                                   .AND. k > nzb_s_inner(j,i+2)&
+                                                   .AND. k > nzb_s_inner(j,i-1)&
+                         )                       .OR.                          &
+                         ( k <= nzb_s_inner(j,i-2) .AND. k > nzb_s_inner(j,i+1)&
+                                                   .AND. k > nzb_s_inner(j,i+2)&
+                                                   .AND. k > nzb_s_inner(j,i-1)&
+                         )                                                     &
                                                  .OR.                          &
                          ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )       &
@@ -1247,5 +1269,8 @@
                 THEN
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 1 )
-                ELSE
+                ELSEIF ( k > nzb_s_inner(j,i+1) .AND. k > nzb_s_inner(j,i+2)   &
+                   .AND. k > nzb_s_inner(j,i+3) .AND. k > nzb_s_inner(j,i-1)   &
+                   .AND. k > nzb_s_inner(j,i-2) )                              &
+                THEN 
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 2 )
                 ENDIF
@@ -1253,5 +1278,7 @@
 !--             scalar - y-direction
 !--             WS1 (3), WS3 (4), WS5 (5)
-                IF ( k <= nzb_s_inner(j+1,i) .OR.                              &
+                IF ( ( k <= nzb_s_inner(j+1,i)  .OR. k <= nzb_s_inner(j+2,i)   &   
+                                                .OR. k <= nzb_s_inner(j-1,i) ) &
+                                                 .OR.                          &
                          ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )       &
                            .AND. j == nys   )    .OR.                          &
@@ -1262,6 +1289,13 @@
 !
 !--             WS3
-                ELSEIF ( k <= nzb_s_inner(j+2,i) .OR. k <= nzb_s_inner(j-1,i)  &
-                                                 .OR.                          &
+                ELSEIF ( ( k <= nzb_s_inner(j+3,i) .AND. k > nzb_s_inner(j+1,i)&
+                                                   .AND. k > nzb_s_inner(j+2,i)&
+                                                   .AND. k > nzb_s_inner(j-1,i)&
+                         )                           .OR.                      &
+                         ( k <= nzb_s_inner(j-2,i) .AND. k > nzb_s_inner(j+1,i)&
+                                                   .AND. k > nzb_s_inner(j+2,i)&
+                                                   .AND. k > nzb_s_inner(j-1,i)&
+                         )                                                     &
+                                                     .OR.                      &
                          ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )       &
                            .AND. j == nysv  )    .OR.                          &
@@ -1272,5 +1306,8 @@
 !
 !--             WS5
-                ELSE
+                ELSEIF ( k > nzb_s_inner(j+1,i) .AND. k > nzb_s_inner(j+2,i)   &
+                   .AND. k > nzb_s_inner(j+3,i) .AND. k > nzb_s_inner(j-1,i)   &
+                   .AND. k > nzb_s_inner(j-2,i) )                              &
+                THEN 
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 5 )
                 ENDIF
@@ -1288,4 +1325,5 @@
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 8 )
                 ENDIF
+
              ENDDO
           ENDDO
@@ -1312,5 +1350,5 @@
 !--             u component - x-direction
 !--             WS1 (9), WS3 (10), WS5 (11)
-                IF ( k <= nzb_u_inner(j,i+1) .OR.                              &
+                IF ( k <= nzb_u_inner(j,i+1)     .OR.                          &
                          ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )       &
                            .AND. i <= nxlu  )    .OR.                          &
@@ -1319,6 +1357,8 @@
                 THEN
                     wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 9 )
-                ELSEIF ( k <= nzb_u_inner(j,i+2) .OR. k <= nzb_u_inner(j,i-1)  &
-                                                 .OR.                          &
+                ELSEIF ( ( k <= nzb_u_inner(j,i+2) .AND.                       &
+                           k >  nzb_u_inner(j,i+1) ) .OR.                      &
+                           k <= nzb_u_inner(j,i-1)                             &
+                                                     .OR.                      &
                          ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )       &
                            .AND. i == nxr-1 )    .OR.                          &
@@ -1330,5 +1370,7 @@
 !--                Clear flag for WS1
                    wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 9 )
-                ELSE
+                ELSEIF ( k > nzb_u_inner(j,i+1) .AND. k > nzb_u_inner(j,i+2)   &
+                                                .AND. k > nzb_u_inner(j,i-1) ) &
+                THEN    
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 11 )
 !
@@ -1346,6 +1388,8 @@
                 THEN
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 12 )
-                ELSEIF ( k <= nzb_u_inner(j+2,i) .OR. k <= nzb_u_inner(j-1,i)  &
-                                                 .OR.                          &
+                ELSEIF ( ( k <= nzb_u_inner(j+2,i) .AND.                       &
+                           k >  nzb_u_inner(j+1,i) ) .OR.                      &
+                           k <= nzb_u_inner(j-1,i)                             &
+                                                     .OR.                      &
                          ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )       &
                            .AND. j == nysv  )    .OR.                          &
@@ -1357,5 +1401,7 @@
 !--                Clear flag for WS1
                    wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 12 )
-                ELSE
+                ELSEIF ( k > nzb_u_inner(j+1,i) .AND. k > nzb_u_inner(j+2,i)   &
+                                                .AND. k > nzb_u_inner(j-1,i) ) &
+                THEN
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 14 )
 !
@@ -1402,5 +1448,7 @@
 !
 !--             WS3
-                ELSEIF ( k <= nzb_v_inner(j,i+2) .OR. k <= nzb_v_inner(j,i-1)  &
+                ELSEIF ( ( k <= nzb_v_inner(j,i+2) .AND.                       &
+                           k >  nzb_v_inner(j,i+1) ) .OR.                      &
+                           k <= nzb_v_inner(j,i-1)                             &
                                                  .OR.                          &
                          ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )       &
@@ -1413,5 +1461,7 @@
 !--                Clear flag for WS1
                    wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 18 )
-                ELSE
+                ELSEIF ( k > nzb_v_inner(j,i+1) .AND. k > nzb_v_inner(j,i+2)   &
+                                                .AND. k > nzb_v_inner(j,i-1) ) &
+                THEN
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 20 )
 !
@@ -1429,6 +1479,8 @@
                 THEN
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 21 )
-                ELSEIF ( k <= nzb_v_inner(j+2,i) .OR. k <= nzb_v_inner(j-1,i)  &
-                                                 .OR.                          &
+                ELSEIF ( ( k <= nzb_v_inner(j+2,i) .AND.                       &
+                           k >  nzb_v_inner(j+1,i) ) .OR.                      &
+                           k <= nzb_v_inner(j-1,i)                             &
+                                                     .OR.                      &
                          ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )       &
                            .AND. j == nysv+1)    .OR.                          &
@@ -1440,5 +1492,7 @@
 !--                Clear flag for WS1
                    wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 21 )
-                ELSE
+                ELSEIF ( k > nzb_v_inner(j+1,i) .AND. k > nzb_v_inner(j+2,i)   &
+                                                .AND. k > nzb_v_inner(j-1,i) ) &
+                THEN
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 23 )
 !
@@ -1482,6 +1536,8 @@
                 THEN
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 27 )
-                ELSEIF ( k <= nzb_w_inner(j,i+2) .OR. k <= nzb_w_inner(j,i-1)  &
-                                                 .OR.                          &
+                ELSEIF ( ( k <= nzb_w_inner(j,i+2) .AND.                       &
+                           k >  nzb_w_inner(j,i+1) ) .OR.                      &
+                           k <= nzb_w_inner(j,i-1)                             &
+                                                     .OR.                      &
                          ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )       &
                            .AND. i == nxr-1 )    .OR.                          &
@@ -1493,5 +1549,7 @@
 !--                Clear flag for WS1
                    wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 27 )
-                ELSE
+                ELSEIF ( k > nzb_w_inner(j,i+1) .AND. k > nzb_w_inner(j,i+2)   &
+                                                .AND. k > nzb_w_inner(j,i-1) ) &
+                THEN
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i),29 )
 !
@@ -1509,6 +1567,8 @@
                 THEN
                    wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 30 )
-                ELSEIF ( k <= nzb_w_inner(j+2,i) .OR. k <= nzb_w_inner(j-1,i)  &
-                                                 .OR.                          &
+                ELSEIF ( ( k <= nzb_w_inner(j+2,i) .AND.                       &
+                           k >  nzb_w_inner(j+1,i) ) .OR.                      &
+                           k <= nzb_w_inner(j-1,i)                             &
+                                                     .OR.                      &
                          ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )       &
                            .AND. j == nysv  )    .OR.                          &
@@ -1520,5 +1580,7 @@
 !--                Clear flag for WS1
                    wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 30 )
-                ELSE
+                ELSEIF ( k > nzb_w_inner(j+1,i) .AND. k > nzb_w_inner(j+2,i)   &
+                                                .AND. k > nzb_w_inner(j-1,i) ) &
+                THEN
                    wall_flags_00(k,j,i) = IBSET( wall_flags_00(k,j,i), 0 )
 !
