Index: palm/trunk/SOURCE/advec_ws.f90
===================================================================
--- palm/trunk/SOURCE/advec_ws.f90	(revision 1877)
+++ palm/trunk/SOURCE/advec_ws.f90	(revision 1942)
@@ -19,5 +19,5 @@
 ! Current revisions:
 ! ------------------
-! 
+! Initialization of flags for ws-scheme moved from init_grid.
 ! 
 ! Former revisions:
@@ -167,9 +167,13 @@
     PUBLIC   advec_s_ws, advec_s_ws_acc, advec_u_ws, advec_u_ws_acc,          &
              advec_v_ws, advec_v_ws_acc, advec_w_ws, advec_w_ws_acc,          &
-             ws_init, ws_statistics
+             ws_init, ws_init_flags, ws_statistics
 
     INTERFACE ws_init
        MODULE PROCEDURE ws_init
     END INTERFACE ws_init
+
+    INTERFACE ws_init_flags
+       MODULE PROCEDURE ws_init_flags
+    END INTERFACE ws_init_flags
 
     INTERFACE ws_statistics
@@ -364,4 +368,452 @@
 
     END SUBROUTINE ws_init
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Initialization of flags for WS-scheme used to degrade the order of the scheme
+!> near walls.
+!------------------------------------------------------------------------------!
+    SUBROUTINE ws_init_flags
+
+       USE control_parameters,                                                 &
+           ONLY:  inflow_l, inflow_n, inflow_r, inflow_s, momentum_advec,      &
+                  nest_bound_l, nest_bound_n, nest_bound_r, nest_bound_s,      &
+                  outflow_l, outflow_n, outflow_r, outflow_s, scalar_advec
+
+       USE indices,                                                            &
+           ONLY:  nbgp, nxl, nxlu, nxr, nyn, nys, nysv, nzb, nzb_s_inner,      &
+                  nzb_u_inner, nzb_v_inner, nzb_w_inner, nzt, wall_flags_0,    &
+                  wall_flags_00
+
+       USE kinds
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i  !< index variable along x
+       INTEGER(iwp) ::  j  !< index variable along y
+       INTEGER(iwp) ::  k  !< index variable along z
+
+       LOGICAL      ::  flag_set !< steering variable for advection flags
+   
+
+       IF ( scalar_advec == 'ws-scheme' .OR.                                   &
+            scalar_advec == 'ws-scheme-mono' )  THEN
+!
+!--       Set flags to steer the degradation of the advection scheme in advec_ws
+!--       near topography, inflow- and outflow boundaries as well as bottom and
+!--       top of model domain. wall_flags_0 remains zero for all non-prognostic
+!--       grid points.
+          DO  i = nxl, nxr
+             DO  j = nys, nyn
+                DO  k = nzb_s_inner(j,i)+1, nzt
+!
+!--                scalar - x-direction
+!--                WS1 (0), WS3 (1), WS5 (2)
+                   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 )    &
+                              .AND. i == nxr   ) )                             &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 0 )
+                   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 )       &
+                              .AND. i == nxr-1 )    .OR.                          &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )       &
+                              .AND. i == nxlu  ) )                                &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 1 )
+                   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
+!
+!--                scalar - y-direction
+!--                WS1 (3), WS3 (4), WS5 (5)
+                   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.                          &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )       &
+                              .AND. j == nyn   ) )                                &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 3 )
+!
+!--                WS3
+                   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.                          &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )       &
+                              .AND. j == nyn-1 ) )                                &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 4 )
+!
+!--                WS5
+                   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
+! 
+!--                scalar - z-direction
+!--                WS1 (6), WS3 (7), WS5 (8)
+                   flag_set = .FALSE.
+                   IF ( k == nzb_s_inner(j,i) + 1 .OR. k == nzt )  THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 6 )
+                      flag_set = .TRUE.
+                   ELSEIF ( k == nzb_s_inner(j,i) + 2 .OR. k == nzt - 1 )  THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 7 )
+                      flag_set = .TRUE.
+                   ELSEIF ( k > nzb_s_inner(j,i) .AND. .NOT. flag_set )  THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 8 )
+                   ENDIF
+
+                ENDDO
+             ENDDO
+          ENDDO
+       ENDIF
+
+       IF ( momentum_advec == 'ws-scheme' )  THEN
+!
+!--       Set wall_flags_0 to steer the degradation of the advection scheme in advec_ws
+!--       near topography, inflow- and outflow boundaries as well as bottom and
+!--       top of model domain. wall_flags_0 remains zero for all non-prognostic
+!--       grid points.
+          DO  i = nxl, nxr
+             DO  j = nys, nyn
+                DO  k = nzb+1, nzt
+!  
+!--                At first, set flags to WS1. 
+!--                Since fluxes are swapped in advec_ws.f90, this is necessary to 
+!--                in order to handle the left/south flux.
+!--                near vertical walls. 
+                   wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 9 )
+                   wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 12 )
+!
+!--                u component - x-direction
+!--                WS1 (9), WS3 (10), WS5 (11)
+                   IF ( k <= nzb_u_inner(j,i+1)     .OR.                       &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
+                              .AND. i <= nxlu  )    .OR.                       &
+                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )    &
+                              .AND. i == nxr   ) )                             &
+                   THEN
+                       wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 9 )
+                   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.                       &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
+                              .AND. i == nxlu+1) )                             &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 10 )
+!
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 9 )
+                   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 )
+!
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 9 )
+                   ENDIF
+!
+!--                u component - y-direction
+!--                WS1 (12), WS3 (13), WS5 (14)
+                   IF ( k <= nzb_u_inner(j+1,i) .OR.                           &
+                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )    &
+                              .AND. j == nys   )    .OR.                       &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                              .AND. j == nyn   ) )                             &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 12 )
+                   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.                       &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                              .AND. j == nyn-1 ) )                             &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 13 )
+!
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 12 )
+                   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 )
+!
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 12 )
+                   ENDIF
+!
+!--                u component - z-direction
+!--                WS1 (15), WS3 (16), WS5 (17)
+                   flag_set = .FALSE.
+                   IF ( k == nzb_u_inner(j,i) + 1 .OR. k == nzt )  THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 15 )
+                      flag_set = .TRUE.
+                   ELSEIF ( k == nzb_u_inner(j,i) + 2 .OR. k == nzt - 1 )  THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 16 )
+                      flag_set = .TRUE.
+                   ELSEIF ( k > nzb_u_inner(j,i) .AND. .NOT. flag_set )  THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 17 )
+                   ENDIF
+
+                ENDDO
+             ENDDO
+          ENDDO
+
+          DO  i = nxl, nxr
+             DO  j = nys, nyn
+                DO  k = nzb+1, nzt
+!
+!--                At first, set flags to WS1. 
+!--                Since fluxes are swapped in advec_ws.f90, this is necessary to 
+!--                in order to handle the left/south flux.
+                   wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 18 )
+                   wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 21 )
+!
+!--                v component - x-direction
+!--                WS1 (18), WS3 (19), WS5 (20)
+                   IF ( k <= nzb_v_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 )    &
+                              .AND. i == nxr   ) )                             &
+                  THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 18 )
+!
+!--                WS3
+                   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 )    &
+                              .AND. i == nxr-1 )    .OR.                       &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
+                              .AND. i == nxlu  ) )                             &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 19 )
+!
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 18 )
+                   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 )
+!
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 18 )
+                   ENDIF
+!
+!--                v component - y-direction
+!--                WS1 (21), WS3 (22), WS5 (23)
+                   IF ( k <= nzb_v_inner(j+1,i) .OR.                           &
+                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )    &
+                              .AND. j <= nysv  )    .OR.                       &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                              .AND. j == nyn   ) )                             &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 21 )
+                   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.                       &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                              .AND. j == nyn-1 ) )                             &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 22 )
+!
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 21 )
+                   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 )
+!
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 21 )
+                   ENDIF
+!
+!--                v component - z-direction
+!--                WS1 (24), WS3 (25), WS5 (26)
+                   flag_set = .FALSE.
+                   IF ( k == nzb_v_inner(j,i) + 1 .OR. k == nzt )  THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 24 )
+                      flag_set = .TRUE.
+                   ELSEIF ( k == nzb_v_inner(j,i) + 2 .OR. k == nzt - 1 )  THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 25 )
+                      flag_set = .TRUE.
+                   ELSEIF ( k > nzb_v_inner(j,i) .AND. .NOT. flag_set )  THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 26 )
+                   ENDIF
+
+                ENDDO
+             ENDDO
+          ENDDO
+          DO  i = nxl, nxr
+             DO  j = nys, nyn
+                DO  k = nzb+1, nzt
+!
+!--                At first, set flags to WS1. 
+!--                Since fluxes are swapped in advec_ws.f90, this is necessary to 
+!--                in order to handle the left/south flux.
+                   wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 27 )
+                   wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 30 )
+!
+!--                w component - x-direction
+!--                WS1 (27), WS3 (28), WS5 (29)
+                   IF ( k <= nzb_w_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 )    &
+                              .AND. i == nxr   ) )                             &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 27 )
+                   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.                       &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
+                              .AND. i == nxlu  ) )                             &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 28 )
+!   
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 27 )
+                   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 )
+!   
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 27 )
+                   ENDIF
+!
+!--                w component - y-direction
+!--                WS1 (30), WS3 (31), WS5 (32)
+                   IF ( k <= nzb_w_inner(j+1,i) .OR.                           &
+                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )    &
+                              .AND. j == nys   )    .OR.                       &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                              .AND. j == nyn   ) )                             &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 30 )
+                   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.                       &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                              .AND. j == nyn-1 ) )                             &
+                   THEN
+                      wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 31 )
+!
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 30 )
+                   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 )
+!
+!--                   Clear flag for WS1
+                      wall_flags_0(k,j,i) = IBCLR( wall_flags_0(k,j,i), 30 )
+                   ENDIF
+!
+!--                w component - z-direction
+!--                WS1 (33), WS3 (34), WS5 (35)
+                   flag_set = .FALSE.
+                   IF ( k == nzb_w_inner(j,i) .OR. k == nzb_w_inner(j,i) + 1   &
+                                              .OR. k == nzt )  THEN
+!
+!--                   Please note, at k == nzb_w_inner(j,i) a flag is explictely
+!--                   set, although this is not a prognostic level. However, 
+!--                   contrary to the advection of u,v and s this is necessary
+!--                   because flux_t(nzb_w_inner(j,i)) is used for the tendency
+!--                   at k == nzb_w_inner(j,i)+1.
+                      wall_flags_00(k,j,i) = IBSET( wall_flags_00(k,j,i), 1 )
+                      flag_set = .TRUE.
+                   ELSEIF ( k == nzb_w_inner(j,i) + 2 .OR. k == nzt - 1 )  THEN
+                      wall_flags_00(k,j,i) = IBSET( wall_flags_00(k,j,i), 2 )
+                      flag_set = .TRUE.
+                   ELSEIF ( k > nzb_w_inner(j,i) .AND. .NOT. flag_set )  THEN
+                      wall_flags_00(k,j,i) = IBSET( wall_flags_00(k,j,i), 3 )
+                   ENDIF
+
+                ENDDO
+             ENDDO
+          ENDDO
+
+       ENDIF
+
+
+!
+!--    Exchange 3D integer wall_flags.
+       IF ( momentum_advec == 'ws-scheme' .OR. scalar_advec == 'ws-scheme'  &
+       .OR. scalar_advec == 'ws-scheme-mono' )  THEN  
+!
+!--       Exchange ghost points for advection flags
+          CALL exchange_horiz_int( wall_flags_0,  nbgp )
+          CALL exchange_horiz_int( wall_flags_00, nbgp )
+!
+!--       Set boundary flags at inflow and outflow boundary in case of 
+!--       non-cyclic boundary conditions.
+         IF ( inflow_l .OR. outflow_l .OR. nest_bound_l )  THEN
+             wall_flags_0(:,:,nxl-1)  = wall_flags_0(:,:,nxl)
+             wall_flags_00(:,:,nxl-1) = wall_flags_00(:,:,nxl)
+         ENDIF
+
+         IF ( inflow_r .OR. outflow_r .OR. nest_bound_r )  THEN
+            wall_flags_0(:,:,nxr+1)  = wall_flags_0(:,:,nxr)
+            wall_flags_00(:,:,nxr+1) = wall_flags_00(:,:,nxr)
+          ENDIF
+
+          IF ( inflow_n .OR. outflow_n .OR. nest_bound_n )  THEN
+             wall_flags_0(:,nyn+1,:)  = wall_flags_0(:,nyn,:)
+             wall_flags_00(:,nyn+1,:) = wall_flags_00(:,nyn,:)
+          ENDIF
+
+          IF ( inflow_s .OR. outflow_s  .OR. nest_bound_s )  THEN
+             wall_flags_0(:,nys-1,:)  = wall_flags_0(:,nys,:)
+             wall_flags_00(:,nys-1,:) = wall_flags_00(:,nys,:)
+          ENDIF
+  
+       ENDIF
+
+
+    END SUBROUTINE ws_init_flags
 
 
