Index: palm/trunk/SOURCE/prognostic_equations.f90
===================================================================
--- palm/trunk/SOURCE/prognostic_equations.f90	(revision 102)
+++ palm/trunk/SOURCE/prognostic_equations.f90	(revision 106)
@@ -4,5 +4,7 @@
 ! Actual revisions:
 ! -----------------
-! +uswst, vswst as arguments in calls of diffusion_u|v
+! +uswst, vswst as arguments in calls of diffusion_u|v,
+! loops for u and v are starting from index nxlu, nysv, respectively (needed
+! for non-cyclic boundary conditions)
 !
 ! Former revisions:
@@ -133,5 +135,5 @@
 !
 !-- u-tendency terms with no communication
-    DO  i = nxl, nxr
+    DO  i = nxlu, nxr
        DO  j = nys, nyn
 !
@@ -202,5 +204,5 @@
 !-- v-tendency terms with no communication
     DO  i = nxl, nxr
-       DO  j = nys, nyn
+       DO  j = nysv, nyn
 !
 !--       Tendency terms
@@ -806,5 +808,5 @@
 !
 !--       Tendency terms for u-velocity component
-          IF ( j < nyn+1 )  THEN
+          IF ( .NOT. outflow_l  .OR.  i > nxl )  THEN
 
              tend(:,j,i) = 0.0
@@ -857,5 +859,5 @@
 !
 !--       Tendency terms for v-velocity component
-          IF ( i < nxr+1 )  THEN
+          IF ( .NOT. outflow_s  .OR.  j > nys )  THEN
 
              tend(:,j,i) = 0.0
@@ -906,96 +908,139 @@
 !
 !--       Tendency terms for w-velocity component
-          IF ( i < nxr+1  .AND.  j < nyn+1 )  THEN
-
+          tend(:,j,i) = 0.0
+          IF ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' )  THEN
+             CALL advec_w_pw( i, j )
+          ELSE
+             CALL advec_w_up( i, j )
+          ENDIF
+          IF ( tsc(2) == 2.0  .AND.  timestep_scheme(1:8) == 'leapfrog' ) &
+          THEN
+             CALL diffusion_w( i, j, ddzu, ddzw, km_m, km_damp_x,          &
+                               km_damp_y, tend, u_m, v_m, w_m )
+          ELSE
+             CALL diffusion_w( i, j, ddzu, ddzw, km, km_damp_x, km_damp_y, &
+                               tend, u, v, w )
+          ENDIF
+          CALL coriolis( i, j, 3 )
+          IF ( ocean )  THEN
+             CALL buoyancy( i, j, rho, prho_reference, 3, 64 )
+          ELSE
+             IF ( .NOT. humidity )  THEN
+                CALL buoyancy( i, j, pt, pt_reference, 3, 4 )
+             ELSE
+                CALL buoyancy( i, j, vpt, pt_reference, 3, 44 )
+             ENDIF
+          ENDIF
+          CALL user_actions( i, j, 'w-tendency' )
+
+!
+!--       Prognostic equation for w-velocity component
+          DO  k = nzb_w_inner(j,i)+1, nzt-1
+             w_p(k,j,i) = ( 1.0-tsc(1) ) * w_m(k,j,i) + tsc(1) * w(k,j,i) + &
+                          dt_3d * (                                         &
+                                tsc(2) * tend(k,j,i) + tsc(3) * tw_m(k,j,i) &
+                           - tsc(4) * ( p(k+1,j,i) - p(k,j,i) ) * ddzu(k+1) &
+                                  ) -                                       &
+                          tsc(5) * rdf(k) * w(k,j,i)
+          ENDDO
+
+!
+!--       Calculate tendencies for the next Runge-Kutta step
+          IF ( timestep_scheme(1:5) == 'runge' )  THEN
+             IF ( intermediate_timestep_count == 1 )  THEN
+                DO  k = nzb_w_inner(j,i)+1, nzt-1
+                   tw_m(k,j,i) = tend(k,j,i)
+                ENDDO
+             ELSEIF ( intermediate_timestep_count < &
+                      intermediate_timestep_count_max )  THEN
+                DO  k = nzb_w_inner(j,i)+1, nzt-1
+                   tw_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tw_m(k,j,i)
+                ENDDO
+             ENDIF
+          ENDIF
+
+!
+!--       Tendency terms for potential temperature
+          tend(:,j,i) = 0.0
+          IF ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' )  THEN
+             CALL advec_s_pw( i, j, pt )
+          ELSE
+             CALL advec_s_up( i, j, pt )
+          ENDIF
+          IF ( tsc(2) == 2.0  .AND.  timestep_scheme(1:8) == 'leapfrog' ) &
+          THEN
+             CALL diffusion_s( i, j, ddzu, ddzw, kh_m, pt_m, shf_m, &
+                               tswst_m, tend )
+          ELSE
+             CALL diffusion_s( i, j, ddzu, ddzw, kh, pt, shf, tswst, tend )
+          ENDIF
+
+!
+!--       If required compute heating/cooling due to long wave radiation
+!--       processes
+          IF ( radiation )  THEN
+             CALL calc_radiation( i, j )
+          ENDIF
+
+!
+!--       If required compute impact of latent heat due to precipitation
+          IF ( precipitation )  THEN
+             CALL impact_of_latent_heat( i, j )
+          ENDIF
+          CALL user_actions( i, j, 'pt-tendency' )
+
+!
+!--       Prognostic equation for potential temperature
+          DO  k = nzb_s_inner(j,i)+1, nzt
+             pt_p(k,j,i) = ( 1.0-tsc(1) ) * pt_m(k,j,i) + tsc(1)*pt(k,j,i) +&
+                           dt_3d * (                                        &
+                               tsc(2) * tend(k,j,i) + tsc(3) * tpt_m(k,j,i) &
+                                   ) -                                      &
+                           tsc(5) * rdf(k) * ( pt(k,j,i) - pt_init(k) )
+          ENDDO
+
+!
+!--       Calculate tendencies for the next Runge-Kutta step
+          IF ( timestep_scheme(1:5) == 'runge' )  THEN
+             IF ( intermediate_timestep_count == 1 )  THEN
+                DO  k = nzb_s_inner(j,i)+1, nzt
+                   tpt_m(k,j,i) = tend(k,j,i)
+                ENDDO
+             ELSEIF ( intermediate_timestep_count < &
+                      intermediate_timestep_count_max )  THEN
+                DO  k = nzb_s_inner(j,i)+1, nzt
+                   tpt_m(k,j,i) = -9.5625 * tend(k,j,i) + &
+                                   5.3125 * tpt_m(k,j,i)
+                ENDDO
+             ENDIF
+          ENDIF
+
+!
+!--       If required, compute prognostic equation for salinity
+          IF ( ocean )  THEN
+
+!
+!--          Tendency-terms for salinity
              tend(:,j,i) = 0.0
-             IF ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' )  THEN
-                CALL advec_w_pw( i, j )
-             ELSE
-                CALL advec_w_up( i, j )
-             ENDIF
-             IF ( tsc(2) == 2.0  .AND.  timestep_scheme(1:8) == 'leapfrog' ) &
+             IF ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' ) &
              THEN
-                CALL diffusion_w( i, j, ddzu, ddzw, km_m, km_damp_x,          &
-                                  km_damp_y, tend, u_m, v_m, w_m )
-             ELSE
-                CALL diffusion_w( i, j, ddzu, ddzw, km, km_damp_x, km_damp_y, &
-                                  tend, u, v, w )
-             ENDIF
-             CALL coriolis( i, j, 3 )
-             IF ( ocean )  THEN
-                CALL buoyancy( i, j, rho, prho_reference, 3, 64 )
-             ELSE
-                IF ( .NOT. humidity )  THEN
-                   CALL buoyancy( i, j, pt, pt_reference, 3, 4 )
-                ELSE
-                   CALL buoyancy( i, j, vpt, pt_reference, 3, 44 )
-                ENDIF
-             ENDIF
-             CALL user_actions( i, j, 'w-tendency' )
-
-!
-!--          Prognostic equation for w-velocity component
-             DO  k = nzb_w_inner(j,i)+1, nzt-1
-                w_p(k,j,i) = ( 1.0-tsc(1) ) * w_m(k,j,i) + tsc(1) * w(k,j,i) + &
-                             dt_3d * (                                         &
-                                   tsc(2) * tend(k,j,i) + tsc(3) * tw_m(k,j,i) &
-                              - tsc(4) * ( p(k+1,j,i) - p(k,j,i) ) * ddzu(k+1) &
-                                     ) -                                       &
-                             tsc(5) * rdf(k) * w(k,j,i)
-             ENDDO
-
-!
-!--          Calculate tendencies for the next Runge-Kutta step
-             IF ( timestep_scheme(1:5) == 'runge' )  THEN
-                IF ( intermediate_timestep_count == 1 )  THEN
-                   DO  k = nzb_w_inner(j,i)+1, nzt-1
-                      tw_m(k,j,i) = tend(k,j,i)
-                   ENDDO
-                ELSEIF ( intermediate_timestep_count < &
-                         intermediate_timestep_count_max )  THEN
-                   DO  k = nzb_w_inner(j,i)+1, nzt-1
-                      tw_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tw_m(k,j,i)
-                   ENDDO
-                ENDIF
-             ENDIF
-
-!
-!--          Tendency terms for potential temperature
-             tend(:,j,i) = 0.0
-             IF ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' )  THEN
-                CALL advec_s_pw( i, j, pt )
-             ELSE
-                CALL advec_s_up( i, j, pt )
-             ENDIF
-             IF ( tsc(2) == 2.0  .AND.  timestep_scheme(1:8) == 'leapfrog' ) &
-             THEN
-                CALL diffusion_s( i, j, ddzu, ddzw, kh_m, pt_m, shf_m, &
-                                  tswst_m, tend )
-             ELSE
-                CALL diffusion_s( i, j, ddzu, ddzw, kh, pt, shf, tswst, tend )
-             ENDIF
-
-!
-!--          If required compute heating/cooling due to long wave radiation
-!--          processes
-             IF ( radiation )  THEN
-                CALL calc_radiation( i, j )
-             ENDIF
-
-!
-!--          If required compute impact of latent heat due to precipitation
-             IF ( precipitation )  THEN
-                CALL impact_of_latent_heat( i, j )
-             ENDIF
-             CALL user_actions( i, j, 'pt-tendency' )
-
-!
-!--          Prognostic equation for potential temperature
+                CALL advec_s_pw( i, j, sa )
+             ELSE
+                CALL advec_s_up( i, j, sa )
+             ENDIF
+             CALL diffusion_s( i, j, ddzu, ddzw, kh, sa, saswsb, saswst, &
+                               tend )
+
+             CALL user_actions( i, j, 'sa-tendency' )
+
+!
+!--          Prognostic equation for salinity
              DO  k = nzb_s_inner(j,i)+1, nzt
-                pt_p(k,j,i) = ( 1.0-tsc(1) ) * pt_m(k,j,i) + tsc(1)*pt(k,j,i) +&
-                              dt_3d * (                                        &
-                                  tsc(2) * tend(k,j,i) + tsc(3) * tpt_m(k,j,i) &
-                                      ) -                                      &
-                              tsc(5) * rdf(k) * ( pt(k,j,i) - pt_init(k) )
+                sa_p(k,j,i) = tsc(1) * sa(k,j,i) +                          &
+                              dt_3d * (                                     &
+                               tsc(2) * tend(k,j,i) + tsc(3) * tsa_m(k,j,i) &
+                                      ) -                                   &
+                             tsc(5) * rdf(k) * ( sa(k,j,i) - sa_init(k) )
+                IF ( sa_p(k,j,i) < 0.0 )  sa_p(k,j,i) = 0.1 * sa(k,j,i)
              ENDDO
 
@@ -1005,203 +1050,156 @@
                 IF ( intermediate_timestep_count == 1 )  THEN
                    DO  k = nzb_s_inner(j,i)+1, nzt
-                      tpt_m(k,j,i) = tend(k,j,i)
+                      tsa_m(k,j,i) = tend(k,j,i)
                    ENDDO
                 ELSEIF ( intermediate_timestep_count < &
                          intermediate_timestep_count_max )  THEN
                    DO  k = nzb_s_inner(j,i)+1, nzt
-                      tpt_m(k,j,i) = -9.5625 * tend(k,j,i) + &
-                                      5.3125 * tpt_m(k,j,i)
-                   ENDDO
-                ENDIF
-             ENDIF
-
-!
-!--          If required, compute prognostic equation for salinity
-             IF ( ocean )  THEN
-
-!
-!--             Tendency-terms for salinity
-                tend(:,j,i) = 0.0
-                IF ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' ) &
-                THEN
-                   CALL advec_s_pw( i, j, sa )
+                      tsa_m(k,j,i) = -9.5625 * tend(k,j,i) + &
+                                      5.3125 * tsa_m(k,j,i)
+                   ENDDO
+                ENDIF
+             ENDIF
+
+!
+!--          Calculate density by the equation of state for seawater
+             CALL eqn_state_seawater( i, j )
+
+          ENDIF
+
+!
+!--       If required, compute prognostic equation for total water content /
+!--       scalar
+          IF ( humidity  .OR.  passive_scalar )  THEN
+
+!
+!--          Tendency-terms for total water content / scalar
+             tend(:,j,i) = 0.0
+             IF ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' ) &
+             THEN
+                CALL advec_s_pw( i, j, q )
+             ELSE
+                CALL advec_s_up( i, j, q )
+             ENDIF
+             IF ( tsc(2) == 2.0  .AND.  timestep_scheme(1:8) == 'leapfrog' )&
+             THEN
+                CALL diffusion_s( i, j, ddzu, ddzw, kh_m, q_m, qsws_m, &
+                                  qswst_m, tend )
+             ELSE
+                CALL diffusion_s( i, j, ddzu, ddzw, kh, q, qsws, qswst, &
+                                  tend )
+             ENDIF
+       
+!
+!--          If required compute decrease of total water content due to
+!--          precipitation
+             IF ( precipitation )  THEN
+                CALL calc_precipitation( i, j )
+             ENDIF
+             CALL user_actions( i, j, 'q-tendency' )
+
+!
+!--          Prognostic equation for total water content / scalar
+             DO  k = nzb_s_inner(j,i)+1, nzt
+                q_p(k,j,i) = ( 1.0-tsc(1) ) * q_m(k,j,i) + tsc(1)*q(k,j,i) +&
+                             dt_3d * (                                      &
+                                tsc(2) * tend(k,j,i) + tsc(3) * tq_m(k,j,i) &
+                                     ) -                                    &
+                             tsc(5) * rdf(k) * ( q(k,j,i) - q_init(k) )
+                IF ( q_p(k,j,i) < 0.0 )  q_p(k,j,i) = 0.1 * q(k,j,i)
+             ENDDO
+
+!
+!--          Calculate tendencies for the next Runge-Kutta step
+             IF ( timestep_scheme(1:5) == 'runge' )  THEN
+                IF ( intermediate_timestep_count == 1 )  THEN
+                   DO  k = nzb_s_inner(j,i)+1, nzt
+                      tq_m(k,j,i) = tend(k,j,i)
+                   ENDDO
+                ELSEIF ( intermediate_timestep_count < &
+                         intermediate_timestep_count_max )  THEN
+                   DO  k = nzb_s_inner(j,i)+1, nzt
+                      tq_m(k,j,i) = -9.5625 * tend(k,j,i) + &
+                                     5.3125 * tq_m(k,j,i)
+                   ENDDO
+                ENDIF
+             ENDIF
+
+          ENDIF
+
+!
+!--       If required, compute prognostic equation for turbulent kinetic 
+!--       energy (TKE)
+          IF ( .NOT. constant_diffusion )  THEN
+
+!
+!--          Tendency-terms for TKE
+             tend(:,j,i) = 0.0
+             IF ( ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' )  &
+                  .AND.  .NOT. use_upstream_for_tke )  THEN
+                CALL advec_s_pw( i, j, e )
+             ELSE
+                CALL advec_s_up( i, j, e )
+             ENDIF
+             IF ( tsc(2) == 2.0  .AND.  timestep_scheme(1:8) == 'leapfrog' )&
+             THEN
+                IF ( .NOT. humidity )  THEN
+                   CALL diffusion_e( i, j, ddzu, dd2zu, ddzw, diss, e_m, &
+                                     km_m, l_grid, pt_m, pt_reference,   &
+                                     rif_m, tend, zu, zw )
                 ELSE
-                   CALL advec_s_up( i, j, sa )
-                ENDIF
-                CALL diffusion_s( i, j, ddzu, ddzw, kh, sa, saswsb, saswst, &
-                                  tend )
-       
-                CALL user_actions( i, j, 'sa-tendency' )
-
-!
-!--             Prognostic equation for salinity
-                DO  k = nzb_s_inner(j,i)+1, nzt
-                   sa_p(k,j,i) = tsc(1) * sa(k,j,i) +                          &
-                                 dt_3d * (                                     &
-                                  tsc(2) * tend(k,j,i) + tsc(3) * tsa_m(k,j,i) &
-                                         ) -                                   &
-                                tsc(5) * rdf(k) * ( sa(k,j,i) - sa_init(k) )
-                   IF ( sa_p(k,j,i) < 0.0 )  sa_p(k,j,i) = 0.1 * sa(k,j,i)
-                ENDDO
-
-!
-!--             Calculate tendencies for the next Runge-Kutta step
-                IF ( timestep_scheme(1:5) == 'runge' )  THEN
-                   IF ( intermediate_timestep_count == 1 )  THEN
-                      DO  k = nzb_s_inner(j,i)+1, nzt
-                         tsa_m(k,j,i) = tend(k,j,i)
-                      ENDDO
-                   ELSEIF ( intermediate_timestep_count < &
-                            intermediate_timestep_count_max )  THEN
-                      DO  k = nzb_s_inner(j,i)+1, nzt
-                         tsa_m(k,j,i) = -9.5625 * tend(k,j,i) + &
-                                         5.3125 * tsa_m(k,j,i)
-                      ENDDO
-                   ENDIF
-                ENDIF
-
-!
-!--             Calculate density by the equation of state for seawater
-                CALL eqn_state_seawater( i, j )
-
-             ENDIF
-
-!
-!--          If required, compute prognostic equation for total water content /
-!--          scalar
-             IF ( humidity  .OR.  passive_scalar )  THEN
-
-!
-!--             Tendency-terms for total water content / scalar
-                tend(:,j,i) = 0.0
-                IF ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' ) &
-                THEN
-                   CALL advec_s_pw( i, j, q )
-                ELSE
-                   CALL advec_s_up( i, j, q )
-                ENDIF
-                IF ( tsc(2) == 2.0  .AND.  timestep_scheme(1:8) == 'leapfrog' )&
-                THEN
-                   CALL diffusion_s( i, j, ddzu, ddzw, kh_m, q_m, qsws_m, &
-                                     qswst_m, tend )
-                ELSE
-                   CALL diffusion_s( i, j, ddzu, ddzw, kh, q, qsws, qswst, &
-                                     tend )
-                ENDIF
-       
-!
-!--             If required compute decrease of total water content due to
-!--             precipitation
-                IF ( precipitation )  THEN
-                   CALL calc_precipitation( i, j )
-                ENDIF
-                CALL user_actions( i, j, 'q-tendency' )
-
-!
-!--             Prognostic equation for total water content / scalar
-                DO  k = nzb_s_inner(j,i)+1, nzt
-                   q_p(k,j,i) = ( 1.0-tsc(1) ) * q_m(k,j,i) + tsc(1)*q(k,j,i) +&
-                                dt_3d * (                                      &
-                                   tsc(2) * tend(k,j,i) + tsc(3) * tq_m(k,j,i) &
-                                        ) -                                    &
-                                tsc(5) * rdf(k) * ( q(k,j,i) - q_init(k) )
-                   IF ( q_p(k,j,i) < 0.0 )  q_p(k,j,i) = 0.1 * q(k,j,i)
-                ENDDO
-
-!
-!--             Calculate tendencies for the next Runge-Kutta step
-                IF ( timestep_scheme(1:5) == 'runge' )  THEN
-                   IF ( intermediate_timestep_count == 1 )  THEN
-                      DO  k = nzb_s_inner(j,i)+1, nzt
-                         tq_m(k,j,i) = tend(k,j,i)
-                      ENDDO
-                   ELSEIF ( intermediate_timestep_count < &
-                            intermediate_timestep_count_max )  THEN
-                      DO  k = nzb_s_inner(j,i)+1, nzt
-                         tq_m(k,j,i) = -9.5625 * tend(k,j,i) + &
-                                        5.3125 * tq_m(k,j,i)
-                      ENDDO
-                   ENDIF
-                ENDIF
-
-             ENDIF
-
-!
-!--          If required, compute prognostic equation for turbulent kinetic 
-!--          energy (TKE)
-             IF ( .NOT. constant_diffusion )  THEN
-
-!
-!--             Tendency-terms for TKE
-                tend(:,j,i) = 0.0
-                IF ( ( tsc(2) == 2.0  .OR.  timestep_scheme(1:5) == 'runge' )  &
-                     .AND.  .NOT. use_upstream_for_tke )  THEN
-                   CALL advec_s_pw( i, j, e )
-                ELSE
-                   CALL advec_s_up( i, j, e )
-                ENDIF
-                IF ( tsc(2) == 2.0  .AND.  timestep_scheme(1:8) == 'leapfrog' )&
-                THEN
-                   IF ( .NOT. humidity )  THEN
-                      CALL diffusion_e( i, j, ddzu, dd2zu, ddzw, diss, e_m, &
-                                        km_m, l_grid, pt_m, pt_reference,   &
-                                        rif_m, tend, zu, zw )
+                   CALL diffusion_e( i, j, ddzu, dd2zu, ddzw, diss, e_m, &
+                                     km_m, l_grid, vpt_m, pt_reference,  &
+                                     rif_m, tend, zu, zw )
+                ENDIF
+             ELSE
+                IF ( .NOT. humidity )  THEN
+                   IF ( ocean )  THEN
+                      CALL diffusion_e( i, j, ddzu, dd2zu, ddzw, diss, e, &
+                                        km, l_grid, rho, prho_reference,  &
+                                        rif, tend, zu, zw )
                    ELSE
-                      CALL diffusion_e( i, j, ddzu, dd2zu, ddzw, diss, e_m, &
-                                        km_m, l_grid, vpt_m, pt_reference,  &
-                                        rif_m, tend, zu, zw )
+                      CALL diffusion_e( i, j, ddzu, dd2zu, ddzw, diss, e,  &
+                                        km, l_grid, pt, pt_reference, rif, &
+                                        tend, zu, zw )
                    ENDIF
                 ELSE
-                   IF ( .NOT. humidity )  THEN
-                      IF ( ocean )  THEN
-                         CALL diffusion_e( i, j, ddzu, dd2zu, ddzw, diss, e, &
-                                           km, l_grid, rho, prho_reference,  &
-                                           rif, tend, zu, zw )
-                      ELSE
-                         CALL diffusion_e( i, j, ddzu, dd2zu, ddzw, diss, e,  &
-                                           km, l_grid, pt, pt_reference, rif, &
-                                           tend, zu, zw )
-                      ENDIF
-                   ELSE
-                      CALL diffusion_e( i, j, ddzu, dd2zu, ddzw, diss, e, km, &
-                                        l_grid, vpt, pt_reference, rif, tend, &
-                                        zu, zw )
-                   ENDIF
-                ENDIF
-                CALL production_e( i, j )
-                CALL user_actions( i, j, 'e-tendency' )
-
-!
-!--             Prognostic equation for TKE.
-!--             Eliminate negative TKE values, which can occur due to numerical
-!--             reasons in the course of the integration. In such cases the old
-!--             TKE value is reduced by 90%.
-                DO  k = nzb_s_inner(j,i)+1, nzt
-                   e_p(k,j,i) = ( 1.0-tsc(1) ) * e_m(k,j,i) + tsc(1)*e(k,j,i) +&
-                                dt_3d * (                                      &
-                                   tsc(2) * tend(k,j,i) + tsc(3) * te_m(k,j,i) &
-                                        )
-                   IF ( e_p(k,j,i) < 0.0 )  e_p(k,j,i) = 0.1 * e(k,j,i)
-                ENDDO
-
-!
-!--             Calculate tendencies for the next Runge-Kutta step
-                IF ( timestep_scheme(1:5) == 'runge' )  THEN
-                   IF ( intermediate_timestep_count == 1 )  THEN
-                      DO  k = nzb_s_inner(j,i)+1, nzt
-                         te_m(k,j,i) = tend(k,j,i)
-                      ENDDO
-                   ELSEIF ( intermediate_timestep_count < &
-                            intermediate_timestep_count_max )  THEN
-                      DO  k = nzb_s_inner(j,i)+1, nzt
-                         te_m(k,j,i) = -9.5625 * tend(k,j,i) + &
-                                        5.3125 * te_m(k,j,i)
-                      ENDDO
-                   ENDIF
-                ENDIF
-
-             ENDIF   ! TKE equation
-
-          ENDIF   ! Gridpoints excluding the non-cyclic wall
+                   CALL diffusion_e( i, j, ddzu, dd2zu, ddzw, diss, e, km, &
+                                     l_grid, vpt, pt_reference, rif, tend, &
+                                     zu, zw )
+                ENDIF
+             ENDIF
+             CALL production_e( i, j )
+             CALL user_actions( i, j, 'e-tendency' )
+
+!
+!--          Prognostic equation for TKE.
+!--          Eliminate negative TKE values, which can occur due to numerical
+!--          reasons in the course of the integration. In such cases the old
+!--          TKE value is reduced by 90%.
+             DO  k = nzb_s_inner(j,i)+1, nzt
+                e_p(k,j,i) = ( 1.0-tsc(1) ) * e_m(k,j,i) + tsc(1)*e(k,j,i) +&
+                             dt_3d * (                                      &
+                                tsc(2) * tend(k,j,i) + tsc(3) * te_m(k,j,i) &
+                                     )
+                IF ( e_p(k,j,i) < 0.0 )  e_p(k,j,i) = 0.1 * e(k,j,i)
+             ENDDO
+
+!
+!--          Calculate tendencies for the next Runge-Kutta step
+             IF ( timestep_scheme(1:5) == 'runge' )  THEN
+                IF ( intermediate_timestep_count == 1 )  THEN
+                   DO  k = nzb_s_inner(j,i)+1, nzt
+                      te_m(k,j,i) = tend(k,j,i)
+                   ENDDO
+                ELSEIF ( intermediate_timestep_count < &
+                         intermediate_timestep_count_max )  THEN
+                   DO  k = nzb_s_inner(j,i)+1, nzt
+                      te_m(k,j,i) = -9.5625 * tend(k,j,i) + &
+                                     5.3125 * te_m(k,j,i)
+                   ENDDO
+                ENDIF
+             ENDIF
+
+          ENDIF   ! TKE equation
 
        ENDDO
@@ -1268,5 +1266,5 @@
 !
 !-- Prognostic equation for u-velocity component
-    DO  i = nxl, nxr
+    DO  i = nxlu, nxr
        DO  j = nys, nyn
           DO  k = nzb_u_inner(j,i)+1, nzt
@@ -1285,5 +1283,5 @@
     IF ( timestep_scheme(1:5) == 'runge' )  THEN
        IF ( intermediate_timestep_count == 1 )  THEN
-          DO  i = nxl, nxr
+          DO  i = nxlu, nxr
              DO  j = nys, nyn
                 DO  k = nzb_u_inner(j,i)+1, nzt
@@ -1294,5 +1292,5 @@
        ELSEIF ( intermediate_timestep_count < &
                 intermediate_timestep_count_max )  THEN
-          DO  i = nxl, nxr
+          DO  i = nxlu, nxr
              DO  j = nys, nyn
                 DO  k = nzb_u_inner(j,i)+1, nzt
@@ -1340,5 +1338,5 @@
 !-- Prognostic equation for v-velocity component
     DO  i = nxl, nxr
-       DO  j = nys, nyn
+       DO  j = nysv, nyn
           DO  k = nzb_v_inner(j,i)+1, nzt
              v_p(k,j,i) = ( 1.0-tsc(1) ) * v_m(k,j,i) + tsc(1) * v(k,j,i) +    &
@@ -1357,5 +1355,5 @@
        IF ( intermediate_timestep_count == 1 )  THEN
           DO  i = nxl, nxr
-             DO  j = nys, nyn
+             DO  j = nysv, nyn
                 DO  k = nzb_v_inner(j,i)+1, nzt
                    tv_m(k,j,i) = tend(k,j,i)
@@ -1366,5 +1364,5 @@
                 intermediate_timestep_count_max )  THEN
           DO  i = nxl, nxr
-             DO  j = nys, nyn
+             DO  j = nysv, nyn
                 DO  k = nzb_v_inner(j,i)+1, nzt
                    tv_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tv_m(k,j,i)
