Index: palm/trunk/SOURCE/turbulence_closure_mod.f90
===================================================================
--- palm/trunk/SOURCE/turbulence_closure_mod.f90	(revision 3776)
+++ palm/trunk/SOURCE/turbulence_closure_mod.f90	(revision 4048)
@@ -274,4 +274,23 @@
     PUBLIC c_0, rans_const_c, rans_const_sigma
 
+    SAVE
+
+    PRIVATE
+
+
+    PUBLIC &
+       tcm_check_parameters, &
+       tcm_check_data_output, &
+       tcm_define_netcdf_grid, &
+       tcm_init_arrays, &
+       tcm_init, &
+       tcm_actions, &
+       tcm_prognostic_equations, &
+       tcm_swap_timelevel, &
+       tcm_3d_data_averaging, &
+       tcm_data_output_2d, &
+       tcm_data_output_3d, &
+       tcm_diffusivities
+
 !
 !-- PALM interfaces:
@@ -294,20 +313,8 @@
 
 !
-!-- Averaging of 3D data for output
-    INTERFACE tcm_3d_data_averaging
-       MODULE PROCEDURE tcm_3d_data_averaging
-    END INTERFACE tcm_3d_data_averaging
-
-!
-!-- Data output of 2D quantities
-    INTERFACE tcm_data_output_2d
-       MODULE PROCEDURE tcm_data_output_2d
-    END INTERFACE tcm_data_output_2d
-
-!
-!-- Data output of 3D data
-    INTERFACE tcm_data_output_3d
-       MODULE PROCEDURE tcm_data_output_3d
-    END INTERFACE tcm_data_output_3d
+!-- Initialization of arrays
+    INTERFACE tcm_init_arrays
+       MODULE PROCEDURE tcm_init_arrays
+    END INTERFACE tcm_init_arrays
 
 !
@@ -318,14 +325,9 @@
 
 !
-!-- Initialization of arrays
-    INTERFACE tcm_init_arrays
-       MODULE PROCEDURE tcm_init_arrays
-    END INTERFACE tcm_init_arrays
-
-!
-!-- Initialization of TKE production term
-    INTERFACE production_e_init
-       MODULE PROCEDURE production_e_init
-    END INTERFACE production_e_init
+!-- Location specific actions
+    INTERFACE tcm_actions
+       MODULE PROCEDURE tcm_actions
+       MODULE PROCEDURE tcm_actions_ij
+    END INTERFACE tcm_actions
 
 !
@@ -337,35 +339,26 @@
 
 !
-!-- Production term for TKE
-    INTERFACE production_e
-       MODULE PROCEDURE production_e
-       MODULE PROCEDURE production_e_ij
-    END INTERFACE production_e
-
-!
-!-- Diffusion term for TKE
-    INTERFACE diffusion_e
-       MODULE PROCEDURE diffusion_e
-       MODULE PROCEDURE diffusion_e_ij
-    END INTERFACE diffusion_e
-
-!
-!-- Diffusion term for TKE dissipation rate
-    INTERFACE diffusion_diss
-       MODULE PROCEDURE diffusion_diss
-       MODULE PROCEDURE diffusion_diss_ij
-    END INTERFACE diffusion_diss
-
-!
-!-- Mixing length for LES case
-    INTERFACE mixing_length_les
-       MODULE PROCEDURE mixing_length_les
-    END INTERFACE mixing_length_les
-
-!
-!-- Mixing length for RANS case
-    INTERFACE mixing_length_rans
-       MODULE PROCEDURE mixing_length_rans
-    END INTERFACE mixing_length_rans
+!-- Swapping of time levels (required for prognostic variables)
+    INTERFACE tcm_swap_timelevel
+       MODULE PROCEDURE tcm_swap_timelevel
+    END INTERFACE tcm_swap_timelevel
+
+!
+!-- Averaging of 3D data for output
+    INTERFACE tcm_3d_data_averaging
+       MODULE PROCEDURE tcm_3d_data_averaging
+    END INTERFACE tcm_3d_data_averaging
+
+!
+!-- Data output of 2D quantities
+    INTERFACE tcm_data_output_2d
+       MODULE PROCEDURE tcm_data_output_2d
+    END INTERFACE tcm_data_output_2d
+
+!
+!-- Data output of 3D data
+    INTERFACE tcm_data_output_3d
+       MODULE PROCEDURE tcm_data_output_3d
+    END INTERFACE tcm_data_output_3d
 
 !
@@ -374,39 +367,4 @@
        MODULE PROCEDURE tcm_diffusivities
     END INTERFACE tcm_diffusivities
-
-!
-!-- Calculate diffusivities
-    INTERFACE tcm_diffusivities_default
-       MODULE PROCEDURE tcm_diffusivities_default
-    END INTERFACE tcm_diffusivities_default
-
-!
-!-- Calculate diffusivities according to dynamic sgs model
-    INTERFACE tcm_diffusivities_dynamic
-       MODULE PROCEDURE tcm_diffusivities_dynamic
-    END INTERFACE tcm_diffusivities_dynamic
-
-!
-!-- Box-filter method for dynamic sgs model
-    INTERFACE tcm_box_filter_2d
-       MODULE PROCEDURE tcm_box_filter_2d_single
-       MODULE PROCEDURE tcm_box_filter_2d_array
-    END INTERFACE tcm_box_filter_2d
-
-!
-!-- Swapping of time levels (required for prognostic variables)
-    INTERFACE tcm_swap_timelevel
-       MODULE PROCEDURE tcm_swap_timelevel
-    END INTERFACE tcm_swap_timelevel
-
-    SAVE
-
-    PRIVATE
-!
-!-- Add INTERFACES that must be available to other modules (alphabetical order)
-    PUBLIC production_e_init, tcm_3d_data_averaging, tcm_check_data_output,    &
-           tcm_check_parameters, tcm_data_output_2d, tcm_data_output_3d,       &
-           tcm_define_netcdf_grid, tcm_diffusivities, tcm_init,                &
-           tcm_init_arrays, tcm_prognostic_equations, tcm_swap_timelevel
 
 
@@ -1923,4 +1881,121 @@
 
 
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Execute module-specific actions for all grid points
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE tcm_actions( location )
+
+
+    CHARACTER (LEN=*) ::  location !<
+
+!    INTEGER(iwp) ::  i !<
+!    INTEGER(iwp) ::  j !<
+!    INTEGER(iwp) ::  k !<
+
+!
+!-- Here the module-specific actions follow
+!-- No calls for single grid points are allowed at locations before and
+!-- after the timestep, since these calls are not within an i,j-loop
+    SELECT CASE ( location )
+
+       CASE ( 'before_timestep' )
+
+
+       CASE ( 'before_prognostic_equations' )
+
+          IF ( .NOT. constant_diffusion )  CALL production_e_init
+
+
+       CASE ( 'after_integration' )
+
+
+       CASE ( 'after_timestep' )
+
+
+       CASE ( 'u-tendency' )
+
+
+       CASE ( 'v-tendency' )
+
+
+       CASE ( 'w-tendency' )
+
+
+       CASE ( 'pt-tendency' )
+
+
+       CASE ( 'sa-tendency' )
+
+
+       CASE ( 'e-tendency' )
+
+
+       CASE ( 'q-tendency' )
+
+
+       CASE ( 's-tendency' )
+
+
+       CASE DEFAULT
+          CONTINUE
+
+    END SELECT
+
+ END SUBROUTINE tcm_actions
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Execute module-specific actions for grid point i,j
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE tcm_actions_ij( i, j, location )
+
+
+    CHARACTER (LEN=*) ::  location
+
+    INTEGER(iwp) ::  i
+    INTEGER(iwp) ::  j
+
+!
+!-- Here the module-specific actions follow
+    SELECT CASE ( location )
+
+       CASE ( 'u-tendency' )
+
+!--       Next line is to avoid compiler warning about unused variables. Please remove.
+          IF ( i +  j < 0 )  CONTINUE
+
+       CASE ( 'v-tendency' )
+
+
+       CASE ( 'w-tendency' )
+
+
+       CASE ( 'pt-tendency' )
+
+
+       CASE ( 'sa-tendency' )
+
+
+       CASE ( 'e-tendency' )
+
+
+       CASE ( 'q-tendency' )
+
+
+       CASE ( 's-tendency' )
+
+
+       CASE DEFAULT
+          CONTINUE
+
+    END SELECT
+
+ END SUBROUTINE tcm_actions_ij
+
+
 !------------------------------------------------------------------------------!
 ! Description:
@@ -2205,14 +2280,14 @@
        ENDIF
 
-       CALL production_e( i, j, .FALSE. )
+       CALL production_e_ij( i, j, .FALSE. )
 
        IF ( .NOT. humidity )  THEN
           IF ( ocean_mode )  THEN
-             CALL diffusion_e( i, j, prho, prho_reference )
+             CALL diffusion_e_ij( i, j, prho, prho_reference )
           ELSE
-             CALL diffusion_e( i, j, pt, pt_reference )
+             CALL diffusion_e_ij( i, j, pt, pt_reference )
           ENDIF
        ELSE
-          CALL diffusion_e( i, j, vpt, pt_reference )
+          CALL diffusion_e_ij( i, j, vpt, pt_reference )
        ENDIF
 
@@ -2275,8 +2350,8 @@
 !
 !--    Production of TKE dissipation rate
-       CALL production_e( i, j, .TRUE. )
+       CALL production_e_ij( i, j, .TRUE. )
 !
 !--    Diffusion term of TKE dissipation rate
-       CALL diffusion_diss( i, j )
+       CALL diffusion_diss_ij( i, j )
 !
 !--    Additional sink term for flows through plant canopies
@@ -4012,5 +4087,5 @@
 !> Vector-optimized version
 !------------------------------------------------------------------------------!
- SUBROUTINE diffusion_diss()
+ SUBROUTINE diffusion_diss
     USE arrays_3d,                                                             &
         ONLY:  ddzu, ddzw, drho_air, rho_air_zw
@@ -4702,7 +4777,7 @@
 !
 !-- velocities on grid centers:
-    CALL tcm_box_filter_2d( u, ut )
-    CALL tcm_box_filter_2d( v, vt )
-    CALL tcm_box_filter_2d( w, wt )
+    CALL tcm_box_filter_2d_array( u, ut )
+    CALL tcm_box_filter_2d_array( v, vt )
+    CALL tcm_box_filter_2d_array( w, wt )
 
     DO  i = nxl, nxr
@@ -4787,13 +4862,13 @@
              ENDDO
 
-             CALL tcm_box_filter_2d( uc, uct )
-             CALL tcm_box_filter_2d( vc, vct )
-             CALL tcm_box_filter_2d( wc, wct )
-             CALL tcm_box_filter_2d( uc**2, u2t )
-             CALL tcm_box_filter_2d( vc**2, v2t )
-             CALL tcm_box_filter_2d( wc**2, w2t )
-             CALL tcm_box_filter_2d( uc*vc, uvt )
-             CALL tcm_box_filter_2d( uc*wc, uwt )
-             CALL tcm_box_filter_2d( vc*wc, vwt )
+             CALL tcm_box_filter_2d_single( uc, uct )
+             CALL tcm_box_filter_2d_single( vc, vct )
+             CALL tcm_box_filter_2d_single( wc, wct )
+             CALL tcm_box_filter_2d_single( uc**2, u2t )
+             CALL tcm_box_filter_2d_single( vc**2, v2t )
+             CALL tcm_box_filter_2d_single( wc**2, w2t )
+             CALL tcm_box_filter_2d_single( uc*vc, uvt )
+             CALL tcm_box_filter_2d_single( uc*wc, uwt )
+             CALL tcm_box_filter_2d_single( vc*wc, vwt )
 
              ld11 = u2t - uct*uct
