Index: /palm/trunk/SOURCE/advec_ws.f90
===================================================================
--- /palm/trunk/SOURCE/advec_ws.f90	(revision 861)
+++ /palm/trunk/SOURCE/advec_ws.f90	(revision 862)
@@ -21,4 +21,6 @@
 ! boundary_flags and logicals steering the degradation are removed.
 ! Empty SUBROUTINE local_diss removed.
+!
+! Further formatting adjustments.
 !
 ! Former revisions:
@@ -274,14 +276,14 @@
        IMPLICIT NONE
 
-       INTEGER ::  i, i_omp, j, k, tn, k_ppp, k_pp, k_mm
-       REAL    ::  flux_d, diss_d, u_comp, v_comp, div
+       INTEGER ::  i, i_omp, j, k, k_mm, k_pp, k_ppp,  tn
+       REAL    ::  diss_d, div, flux_d, u_comp, v_comp
        REAL, DIMENSION(:,:,:), POINTER    :: sk
-       REAL, DIMENSION(nzb:nzt+1)         :: flux_t, diss_t, flux_r, diss_r,  &
-                                             flux_n, diss_n
-       REAL, DIMENSION(nzb+1:nzt,0:threads_per_task-1) :: swap_flux_y_local,  &
-                                                          swap_diss_y_local
+       REAL, DIMENSION(nzb:nzt+1)         :: diss_n, diss_r, diss_t, flux_n,  &
+                                             flux_r, flux_t
+       REAL, DIMENSION(nzb+1:nzt,0:threads_per_task-1) :: swap_diss_y_local,  &
+                                                          swap_flux_y_local
        REAL, DIMENSION(nzb+1:nzt,nys:nyn,0:threads_per_task-1) ::             &
-                                                          swap_flux_x_local,  &
-                                                          swap_diss_x_local
+                                                          swap_diss_x_local,  &
+                                                          swap_flux_x_local
        CHARACTER (LEN = *), INTENT(IN)    :: sk_char
 
@@ -671,8 +673,8 @@
        IMPLICIT NONE
 
-       INTEGER ::  i, i_omp, j, k, tn, k_ppp, k_pp, k_mm
-       REAL    ::  gu, gv, flux_d, diss_d, u_comp_l, v_comp, w_comp, div
-       REAL, DIMENSION(nzb:nzt+1) ::  flux_t, diss_t, flux_r, diss_r,        &
-                                      flux_n, diss_n, u_comp
+       INTEGER ::  i, i_omp, j, k, k_mm, k_pp, k_ppp, tn
+       REAL    ::  diss_d, div, flux_d, gu, gv, u_comp_l, v_comp, w_comp
+       REAL, DIMENSION(nzb:nzt+1) :: diss_n, diss_r, diss_t, flux_n, flux_r,  &
+                                     flux_t, u_comp
 
        gu = 2.0 * u_gtrans
@@ -1058,8 +1060,8 @@
        IMPLICIT NONE
 
-       INTEGER  ::  i, i_omp, j, k, tn, k_ppp, k_pp, k_mm
-       REAL     ::  gu, gv, flux_d, diss_d, u_comp, v_comp_l, w_comp, div
-       REAL, DIMENSION(nzb:nzt+1)  ::  flux_t, diss_t, flux_n,                &
-                                       diss_n, flux_r, diss_r, v_comp
+       INTEGER  ::  i, i_omp, j, k, k_mm, k_pp, k_ppp, tn
+       REAL     ::  diss_d, div, flux_d, gu, gv, u_comp, v_comp_l, w_comp
+       REAL, DIMENSION(nzb:nzt+1)  :: diss_n, diss_r, diss_t, flux_n, flux_r,  &
+                                      flux_t, v_comp
 
        gu = 2.0 * u_gtrans
@@ -1451,8 +1453,8 @@
        IMPLICIT NONE
 
-       INTEGER ::  i, i_omp, j, k, tn, k_ppp, k_pp, k_mm
-       REAL    ::  gu, gv, flux_d, diss_d, u_comp, v_comp, w_comp, div
-       REAL, DIMENSION(nzb:nzt+1)  ::  flux_t, diss_t, flux_r, diss_r, flux_n, &
-                                       diss_n
+       INTEGER ::  i, i_omp, j, k, k_mm, k_pp, k_ppp, tn
+       REAL    ::  diss_d, div, flux_d, gu, gv, u_comp, v_comp, w_comp
+       REAL, DIMENSION(nzb:nzt+1)  :: diss_n, diss_r, diss_t, flux_n, flux_r, &
+                                      flux_t
 
        gu = 2.0 * u_gtrans
@@ -1465,5 +1467,5 @@
           DO  k = nzb+1, nzb_max
 
-             v_comp      = v(k+1,j,i) + v(k,j,i) - gv
+             v_comp         = v(k+1,j,i) + v(k,j,i) - gv
              flux_s_w(k,tn) = v_comp * (                                      &
                          ( 37.0 * IBITS(wall_flags_0(k,j,i),32,1) * adv_mom_5 &
@@ -1519,5 +1521,5 @@
           DO  k = nzb+1, nzb_max
 
-             u_comp         = u(k+1,j,i) + u(k,j,i) - gu
+             u_comp           = u(k+1,j,i) + u(k,j,i) - gu
              flux_l_w(k,j,tn) = u_comp * (                                     &
                           ( 37.0 * IBITS(wall_flags_0(k,j,i),29,1) * adv_mom_5 &
@@ -1567,9 +1569,14 @@
 
        ENDIF
-
-       flux_t(0) = 0.0
-       diss_t(0) = 0.0
-       flux_d    = 0.0
-       diss_d    = 0.0
+!
+!--    The lower flux has to be calculated explicetely for the tendency at
+!--    the first w-level. For topography wall this is done implicitely by
+!--    wall_flags_0.
+       k         = nzb + 1
+       w_comp    = w(k,j,i) + w(k-1,j,i)
+       flux_t(0) = w_comp       * ( w(k,j,i) + w(k-1,j,i) ) * adv_mom_1
+       diss_t(0) = -ABS(w_comp) * ( w(k,j,i) - w(k-1,j,i) ) * adv_mom_1
+       flux_d    = flux_t(0)
+       diss_d    = diss_t(0)
 !
 !--    Now compute the fluxes and tendency terms for the horizontal
@@ -1675,4 +1682,5 @@
                              ( w(k_ppp,j,i) - w(k_mm,j,i) )                  &
                                          )
+
 !
 !--       Calculate the divergence of the velocity field. A respective
@@ -1817,13 +1825,13 @@
        IMPLICIT NONE
 
-       INTEGER ::  i, j, k, tn = 0, k_ppp, k_pp, k_mm
+       INTEGER ::  i, j, k, k_mm, k_pp, k_ppp, tn = 0
        REAL, DIMENSION(:,:,:), POINTER ::  sk
-       REAL    :: flux_d, diss_d, u_comp, v_comp, div
-       REAL, DIMENSION(nzb:nzt)  ::  flux_r, diss_r, flux_n, diss_n, flux_t,  &
-                                     diss_t
-       REAL, DIMENSION(nzb+1:nzt) :: swap_flux_y_local, swap_diss_y_local
-       REAL, DIMENSION(nzb+1:nzt,nys:nyn) :: swap_flux_x_local,               &
-                                             swap_diss_x_local
-       CHARACTER (LEN = *), INTENT(IN) :: sk_char
+       REAL    :: diss_d, div, flux_d, u_comp, v_comp
+       REAL, DIMENSION(nzb:nzt)   :: diss_n, diss_r, diss_t, flux_n, flux_r,  &
+                                     flux_t
+       REAL, DIMENSION(nzb+1:nzt) :: swap_diss_y_local, swap_flux_y_local
+       REAL, DIMENSION(nzb+1:nzt,nys:nyn) :: swap_diss_x_local,               &
+                                             swap_flux_x_local
+       CHARACTER (LEN = *), INTENT(IN)    :: sk_char
 
 !
@@ -2197,11 +2205,11 @@
        IMPLICIT NONE
 
-       INTEGER ::  i, j, k, tn = 0,  k_ppp, k_pp, k_mm
-       REAL    ::  gu, gv, flux_d, diss_d, v_comp, w_comp, div
-       REAL, DIMENSION(nzb+1:nzt) :: swap_flux_y_local_u, swap_diss_y_local_u
-       REAL, DIMENSION(nzb+1:nzt,nys:nyn) :: swap_flux_x_local_u,           &
-                                             swap_diss_x_local_u
-       REAL, DIMENSION(nzb:nzt) :: flux_t, diss_t, flux_r, diss_r, flux_n,  &
-                                     diss_n, u_comp
+       INTEGER ::  i, j, k, k_mm, k_pp, k_ppp, tn = 0
+       REAL    ::  diss_d, div, flux_d, gu, gv, v_comp, w_comp
+       REAL, DIMENSION(nzb+1:nzt) :: swap_diss_y_local_u, swap_flux_y_local_u
+       REAL, DIMENSION(nzb+1:nzt,nys:nyn) :: swap_diss_x_local_u,              &
+                                             swap_flux_x_local_u
+       REAL, DIMENSION(nzb:nzt) :: diss_n, diss_r, diss_t, flux_n, flux_r,     &
+                                   flux_t, u_comp
  
        gu = 2.0 * u_gtrans
@@ -2591,11 +2599,11 @@
 
 
-       INTEGER ::  i, j, k, tn = 0, k_ppp, k_pp, k_mm
-       REAL    ::  gu, gv, flux_d, diss_d, u_comp, w_comp, div
-       REAL, DIMENSION(nzb+1:nzt) :: swap_flux_y_local_v, swap_diss_y_local_v
-       REAL, DIMENSION(nzb+1:nzt,nys:nyn) :: swap_flux_x_local_v,             &
-                                             swap_diss_x_local_v
-       REAL, DIMENSION(nzb:nzt) :: flux_t, diss_t, flux_n, diss_n, flux_r,    &
-                                   diss_r, v_comp
+       INTEGER ::  i, j, k, k_mm, k_pp, k_ppp, tn = 0
+       REAL    ::  diss_d, div, flux_d, gu, gv, u_comp, w_comp
+       REAL, DIMENSION(nzb+1:nzt) :: swap_diss_y_local_v, swap_flux_y_local_v
+       REAL, DIMENSION(nzb+1:nzt,nys:nyn) :: swap_diss_x_local_v,             &
+                                             swap_flux_x_local_v
+       REAL, DIMENSION(nzb:nzt) :: diss_n, diss_r, diss_t, flux_n, flux_r,    &
+                                   flux_t, v_comp
 
        gu = 2.0 * u_gtrans
@@ -2993,12 +3001,12 @@
        IMPLICIT NONE
 
-       INTEGER ::  i, j, k, tn = 0, k_ppp, k_pp, k_mm
-       REAL    ::  gu, gv, flux_d, diss_d, u_comp, v_comp, w_comp, div
-       REAL, DIMENSION(nzb:nzt)    ::  flux_t, diss_t
-       REAL, DIMENSION(nzb+1:nzt)  ::  flux_r, diss_r, flux_n, diss_n,        &
-                                       swap_flux_y_local_w,                   &
-                                       swap_diss_y_local_w
-       REAL, DIMENSION(nzb+1:nzt,nys:nyn) :: swap_flux_x_local_w,             &
-                                             swap_diss_x_local_w
+       INTEGER ::  i, j, k, k_mm, k_pp, k_ppp, tn = 0
+       REAL    ::  diss_d, div, flux_d, gu, gv, u_comp, v_comp, w_comp
+       REAL, DIMENSION(nzb:nzt)    ::  diss_t, flux_t
+       REAL, DIMENSION(nzb+1:nzt)  ::  diss_n, diss_r, flux_n, flux_r,        &
+                                       swap_diss_y_local_w,                   &
+                                       swap_flux_y_local_w
+       REAL, DIMENSION(nzb+1:nzt,nys:nyn) :: swap_diss_x_local_w,             &
+                                             swap_flux_x_local_w
  
        gu = 2.0 * u_gtrans
@@ -3113,8 +3121,14 @@
           DO  j = nys, nyn
 
-             flux_t(0) = 0.0
-             diss_t(0) = 0.0
-             flux_d    = 0.0
-             diss_d    = 0.0
+!
+!--          The lower flux has to be calculated explicetely for the tendency
+!--          at the first w-level. For topography wall this is done implicitely
+!--          by wall_flags_0.
+             k         = nzb + 1
+             w_comp    = w(k,j,i) + w(k-1,j,i)
+             flux_t(0) = w_comp       * ( w(k,j,i) + w(k-1,j,i) ) * adv_mom_1
+             diss_t(0) = -ABS(w_comp) * ( w(k,j,i) - w(k-1,j,i) ) * adv_mom_1
+             flux_d    = flux_t(0)
+             diss_d    = diss_t(0)
 
              DO  k = nzb+1, nzb_max
