Index: /palm/trunk/SOURCE/Makefile
===================================================================
--- /palm/trunk/SOURCE/Makefile	(revision 4046)
+++ /palm/trunk/SOURCE/Makefile	(revision 4047)
@@ -25,26 +25,29 @@
 # -----------------
 # $Id$
+# Introduction of the dynamics module and dissolution of swap_timelevel
+#
+# 4043 2019-06-18 16:59:00Z schwenkel
 # Delete droplet_interactions_ptq
 #
 # 4039 2019-06-18 10:32:41Z suehring
 # add dependency for diagnostic output quantities
-# 
+#
 # 4017 2019-06-06 12:16:46Z schwenkel
 # add dependency for init_pegrid
-# 
+#
 # 3994 2019-05-22 18:08:09Z suehring
 # new module for calculation and output of diagnostic quantities added
-# 
+#
 # 3988 2019-05-22 11:32:37Z kanani
 # Add dependencies for virtual_measurement_mod
-# 
+#
 # 3880 2019-04-08 21:43:02Z knoop
 # Add Netcdf data output for indoor model
 # Remove some dependencies
-# 
+#
 # 3744 2019-02-15 18:38:58Z suehring
-# Enable mesoscale offline nesting for chemistry variables as well as 
+# Enable mesoscale offline nesting for chemistry variables as well as
 # initialization of chemistry via dynamic input file.
-# 
+#
 # 3727 2019-02-08 14:52:10Z gronemeier
 # surface_data_output_mod depends on netcdf_interface_mod
@@ -52,14 +55,14 @@
 # 3700 2019-01-26 17:03:42Z knoop
 # Rename surface_output_mod into surface_data_output_mod
-# 
+#
 # 3637 2018-12-20 01:51:36Z knoop
 # Implementation of the PALM module interface
-# 
+#
 # 3634 2018-12-18 12:31:28Z knoop
 # OpenACC port for SPEC
-# 
+#
 # 3579 2018-11-29 15:32:39Z suehring
 # Dependency for check_parameters on nesting_offl_mod added
-# 
+#
 # 3569 2018-11-27 17:03:40Z kanani
 # dom_dwd_user, Schrempf:
@@ -69,22 +72,22 @@
 # 3525 2018-11-14 16:06:14Z kanani
 # Changes related to clean-up of biometeorology (dom_dwd_user)
-# 
+#
 # 3522 2018-11-13 12:14:36Z suehring
 # Dependencies for virtual measurement module added
-# 
+#
 # 3494 2018-11-06 14:51:27Z suehring
 # Surface output revised
-# 
+#
 # 3474 2018-10-30 21:07:39Z kanani
 # Add virtual measurement module
-# 
+#
 # 3472 2018-10-30 20:43:50Z suehring
 # Add indoor model (kanani, srissman, tlang),
 # minor formatting
-# 
+#
 # 3467 2018-10-30 19:05:21Z suehring
 # Implementation of a new aerosol module salsa.
-# 
-# 
+#
+#
 # 3458 2018-10-30 14:51:23Z kanani
 # from chemistry branch r3443, banzhafs, Russo, forkel, basit:
@@ -93,23 +96,23 @@
 # Added chemistry emission module
 # chemistry_model_mod added to flow_statistics
-# 
+#
 # 3448 2018-10-29 18:14:31Z kanani
 # Adjustment of biometeorology dependencies
-# 
+#
 # 3436 2018-10-26 18:35:15Z gronemeier
 # Add surface_mod to user_data_output_mask
-# 
+#
 # 3435 2018-10-26 18:25:44Z gronemeier
 # - Add surface_mod to data_output_mask
 # - Add chemistry_model_mod and surface_mod to init_masks
-# 
+#
 # 3421 2018-10-24 18:39:32Z gronemeier
 # Add netcdf_data_input_mod to netcdf_interface_mod
 # bugfix: add dependencies to chemistry_model_mod
 # Add module for surface data output
-# 
+#
 # 3381 2018-10-19 13:09:06Z raasch
 # dependencies for ocean_mod fixed
-# 
+#
 # 3355 2018-10-16 14:03:34Z knoop
 # Add module for offline nesting;
@@ -117,13 +120,13 @@
 # Bugfix, missing dependency for turbulence generator in init_3d_model;
 # Some formatting ajdustments
-# 
+#
 # 3343 2018-10-15 10:38:52Z suehring
 # (from branch resler)
 # Add biometeorology
-# 
-# 
+#
+#
 # 3322 2018-10-09 10:02:39Z kanani
 # Formatting and cleanup
-# 
+#
 # 3298 2018-10-02 12:21:11Z kanani
 # Added missing dependencies and replaced blanks with tabs (forkel)
@@ -134,68 +137,68 @@
 # changes related to modularization of the ocean mode,
 # bugfix: dependency to advec_ws was missed in chemistry_model_mod
-# 
+#
 # 3274 2018-09-24 15:42:55Z knoop
 # Added palm dependency of multi_agent_system_mod, because of mas_last_actions
 # call at the end of palm run
-# 
+#
 # 3167 2018-07-24 18:17:30Z suehring
 # Bugfix, add missing dependencies for multi-agent system
-# 
+#
 # 3159 2018-07-20 11:20:01Z sward
 # Added multi agent system
-# 
+#
 # 3130 2018-07-16 11:08:55Z gronemeier
 # add surface_layer_fluxes_mod to turbulence_closure_mod
-# 
+#
 # 3129 2018-07-16 07:45:13Z gronemeier
 # add turbulence_closure_mod to parin
-# 
+#
 # 2963 2018-04-12 14:47:44Z suehring
-# Introduce index for vegetation/wall, pavement/green-wall and water/window 
+# Introduce index for vegetation/wall, pavement/green-wall and water/window
 # surfaces, for clearer access of surface fraction, albedo, emissivity, etc. .
-# 
+#
 # 2955 2018-04-09 15:14:01Z suehring
 # Add log-points to measure CPU time of NetCDF data input.
-# 
+#
 # 2938 2018-03-27 15:52:42Z suehring
 # No initialization of child domains via dynamic input file, except for soil
 # moisture and temperature
 # Apply turbulence generator at non-cyclic lateral boundary in nesting case
-# 
+#
 # 2936 2018-03-27 14:49:27Z suehring
 # Added dependencies for parent and child synchronization
-# 
+#
 # 2921 2018-03-22 15:05:23Z Giersch
 # date_and_time_mod dependency has been added to read/write_restart_data_mod
-# 
+#
 # 2918 2018-03-21 15:52:14Z gronemeier
-# read/write_3d_binary and read/write_var_list has been removed, 
+# read/write_3d_binary and read/write_var_list has been removed,
 # read/write_restart_data_mod, wrd_write_string and
-# user_read/write_restart_data_mod has been added, dependencies with respect to 
+# user_read/write_restart_data_mod has been added, dependencies with respect to
 # the aforementioned routines have been added/removed
 #
 # 2847 2018-03-02 21:45:58Z suehring
 # Changed format and enforced sorting
-# 
+#
 # 2817 2018-02-19 16:32:21Z knoop
 # Preliminary gust module interface implemented
-# 
+#
 # 2802 2018-02-14 16:21:39Z thiele
 # Changed lpm from subroutine to module.
 # Introduce particle transfer in nested models.
-# 
+#
 # 2773 2018-01-30 14:12:54Z suehring
 # Nesting of chemical species
-# 
+#
 # 2718 2018-01-02 08:49:38Z maronga
 # Corrected "Former revisions" section
-# 
+#
 # 2697 2017-12-14 17:57:20Z kanani
 # Bugfix, missing dependencies
-# 
+#
 # 2696 2017-12-14 17:12:51Z kanani
 # Change in file header (GPL part)
 # Implementation of uv exposure model (FK)
-# Bugfix, removed loop dependcy for vertical_nesting_mod and 
+# Bugfix, removed loop dependcy for vertical_nesting_mod and
 # turbulence_closure_mod, added depencies for vertical_nesting_mod (TG)
 # implemented turbulence_closure_mod (TG)
@@ -205,13 +208,13 @@
 # For LSM, add dependency on calc_mean_profile (??)
 # poismg_noopt modularized and renamed into poismg_noopt_mod
-# add dependencies for netcdf_data_input_mod, calc_mean_profile, 
+# add dependencies for netcdf_data_input_mod, calc_mean_profile,
 # radiation_module_mod, land_surface_model_mod (MS)
-# 
+#
 # 2608 2017-11-13 14:04:26Z schwenkel
-# Added diagnostic_quantities_mod 
-# 
+# Added diagnostic_quantities_mod
+#
 # 2600 2017-11-01 14:11:20Z raasch
 # comment line concerning bound checks removed
-# 
+#
 # 2599 2017-11-01 13:18:45Z hellstea
 # virtual_flight_mod, synthetic_turbulence_generator_mod and
@@ -220,40 +223,40 @@
 # 2563 2017-10-19 15:36:10Z Giersch
 # wind_turbine_model_mod and synthetic_turbulence_generator_mod were added to
-# write_var_list and virtual_flight_mod was deleted from read_var_list 
+# write_var_list and virtual_flight_mod was deleted from read_var_list
 #
 # 2544 2017-10-13 18:09:32Z maronga
-# Added date_and_time_mod 
-# 
+# Added date_and_time_mod
+#
 # 2371 2017-08-24 13:01:17Z kanani
 # Corrected dependencies for vertical_nesting_mod
-# 
+#
 # 2370 2017-08-23 06:11:43Z raasch
 # dependency bugfix for synthetic_turbulence_generator
-# 
+#
 # 2365 2017-08-21 14:59:59Z kanani
 # Added dependencies for vertical_nesting_mod
-# 
+#
 # 2339 2017-08-07 13:55:26Z gronemeier
 # corrected timestamp in header
-# 
+#
 # 2338 2017-08-07 12:15:38Z gronemeier
 # Modularize 1D model
-# 
+#
 # 2320 2017-07-21 12:47:43Z suehring
 # -ls_forcing nudging
 # +large_scale_forcing_nudging
-# 
+#
 # 2318 2017-07-20 17:27:44Z suehring
 # Add further dependencies on surface_mod
-# 
+#
 # 2317 2017-07-20 17:27:19Z suehring
 # Added time_integration_spinup
-# 
+#
 # 2269 2017-06-09 11:57:32Z suehring
 # Add dependency in read_3d_binary
-# 
+#
 # 2263 2017-06-08 14:59:01Z schwenkel
 # Implemented splitting and merging algorithm
-# 
+#
 # 2259 2017-06-08 09:09:11Z gronemeier
 # Implemented synthetic turbulence generator
@@ -261,12 +264,12 @@
 # 2256 2017-06-07 13:58:08Z suehring
 # Remove ring dependency in init_pegrid
-# 
+#
 # 2238 2017-05-31 16:49:16Z suehring
 # Bugfix, further missing dependency on surface_mod
-# 
+#
 # 2237 2017-05-31 10:34:53Z suehring
-# Bugfix, add dependencies on surface_mod for surface_coupler, 
-# plant_canopy_model_mod and ls_forcing_mod 
-# 
+# Bugfix, add dependencies on surface_mod for surface_coupler,
+# plant_canopy_model_mod and ls_forcing_mod
+#
 # 2233 2017-05-30 18:08:54Z suehring
 #
@@ -274,5 +277,5 @@
 # +dependencies for surface_mod
 # -wall_fluxes
-# 
+#
 # 2130 2017-01-24 16:25:39Z raasch
 # dependency for timestep updated
@@ -280,13 +283,13 @@
 # 2118 2017-01-17 16:38:49Z raasch
 # -cuda_fft_interfaces_mod
-# 
+#
 # 2050 2016-11-08 15:00:55Z gronemeier
 # Implement turbulent outflow method
-# 
+#
 # 2007 2016-08-24 15:47:17Z kanani
 # urban surface module added,
 # cleaned up some lines (compiler flags/options), which were accidentally
 # added in rev1938
-# 
+#
 # 1998 2016-08-20 18:45:34Z knoop
 # Bugfix: added netcdf_interface to dependency list for user_init_land_surface
@@ -294,8 +297,8 @@
 # 1986 2016-08-10 14:07:17Z gronemeier
 # POSIX-calls module added
-# 
+#
 # 1972 2016-07-26 07:52:02Z maronga
 # Removed some dependencies due to further modularization of land surface model
-# 
+#
 # 1957 2016-07-07 10:43:48Z suehring
 # flight module added
@@ -305,9 +308,9 @@
 #
 # 1938 2016-06-13 15:26:05Z hellstea
-# Some dependency errors corrected 
-# 
+# Some dependency errors corrected
+#
 # 1934 2016-06-13 09:46:57Z hellstea
 # poismg renamed poismg_noopt, poismg_fast_mod renamed poismg_mod
-# 
+#
 # 1914 2016-05-26 14:44:07Z witha
 # Added wind_turbine_model_mod
@@ -320,5 +323,5 @@
 #
 # 1850 2016-04-08 13:29:27Z maronga
-# Adapted for modularization of microphysics 
+# Adapted for modularization of microphysics
 # Several files renamed --> _mod
 # Bugfix for previous commit
@@ -335,16 +338,16 @@
 # 1833 2016-04-07 14:23:03Z raasch
 # spectrum renamed spectra_mod, depencies for spectra changed
-# 
+#
 # 1826 2016-04-07 12:01:39Z maronga
 # Renamed radiation_model to radiation_model_mod.
 # Renamed plant_canopy_model to plant_canopy_model_mod.
-# 
+#
 # 1822 2016-04-07 07:49:42Z hoffmann
 # Tails removed. lpm_release_set removed. calc_precipitation, impact_of_latent_heat
-# removed. 
+# removed.
 #
 # 1817 2016-04-06 15:44:20Z maronga
 # Renamed land_surface_model to land_surface_model_mod.
-# 
+#
 # 1808 2016-04-05 19:44:00Z raasch
 # -local_flush, -local_getenv
@@ -372,5 +375,5 @@
 #
 # 1762 2016-02-25 12:31:13Z hellstea
-# +pmc_interface, +pmc routines 
+# +pmc_interface, +pmc routines
 #
 # 1747 2016-02-08 12:25:53Z raasch
@@ -378,10 +381,10 @@
 #
 # 1691 2015-10-26 16:17:44Z maronga
-# Replaced prandtl_fluxes with surface_layer_fluxes. Added radiation_model to 
+# Replaced prandtl_fluxes with surface_layer_fluxes. Added radiation_model to
 # prognostic_equations
-# 
+#
 # 1585 2015-04-30 07:05:52Z maronga
 # Added user_init_radiation.f90
-# 
+#
 # 1575 2015-03-27 09:56:27Z raasch
 # +poismg_fast
@@ -389,5 +392,5 @@
 # 1551 2015-03-03 14:18:16Z maronga
 # Bugfix: further adjustments for the land surface model and radiation model
-# 
+#
 # 1517 2015-01-07 19:12:25Z hoffmann
 # advec_s_bc added to prognostic_equations
@@ -395,16 +398,16 @@
 # 1500 2014-12-03 17:42:41Z maronga
 # Bugfix: missing adjustments for land surface model and radiation model
-# 
+#
 # 1496 2014-12-02 17:25:50Z maronga
-# Added land surface model and radiation model files: land_surface_model, 
+# Added land surface model and radiation model files: land_surface_model,
 # radiation_model, user_init_land_surface
-# 
+#
 # 1484 2014-10-21 10:53:05Z kanani
 # plant_canopy_model-dependency added for check_parameters, header, init_3d_model,
 # package_parin, read_var_list, user_init_plant_canopy, write_var_list
-# 
+#
 # 1444 2014-08-02 20:10:32Z letzel
 # bugfix: cpulog added to lpm_advec
-# 
+#
 # 1404 2014-05-14 09:01:39Z keck
 # bugfix: dependencies added for progress_bar
@@ -412,11 +415,11 @@
 # 1402 2014-05-09 14:25:13Z raasch
 # progress_bar added
-# 
+#
 # 1400 2014-05-09 14:03:54Z knoop
 # Added new module random_generator_parallel
-# 
+#
 # 1380 2014-04-28 12:40:45Z heinze
 # bugfix: mod_particle_attributes  added to check_open
-# nudging added to time_integration 
+# nudging added to time_integration
 #
 # 1374 2014-04-25 12:55:07Z raasch
@@ -426,5 +429,5 @@
 # Added new module calc_mean_profile, previously in module buoyancy,
 # removed buoyancy dependency from nudging
-# 
+#
 # 1363 2014-04-17 12:28:49Z keck
 # bugfix: cpulog added to lpm_pack_arrays
@@ -432,7 +435,7 @@
 # 1361 2014-04-16 15:17:48Z hoffmann
 # cpulog added to microphysics
-# 
+#
 # 1359 2014-04-11 17:15:14Z hoffmann
-# mod_particle_attributes added, lpm_sort_arrays removed, 
+# mod_particle_attributes added, lpm_sort_arrays removed,
 # lpm_extend_particle_array removed
 #
@@ -606,4 +609,5 @@
 	disturb_field.f90 \
 	disturb_heatflux.f90 \
+	dynamics_mod.f90 \
 	exchange_horiz_2d.f90 \
 	exchange_horiz.f90 \
@@ -679,5 +683,4 @@
 	surface_mod.f90 \
 	surface_data_output_mod.f90 \
-	swap_timelevel.f90 \
 	synthetic_turbulence_generator_mod.f90 \
 	temperton_fft_mod.f90 \
@@ -715,5 +718,5 @@
 
 CC = cc
-CFLAGS = -O 
+CFLAGS = -O
 
 F90 =
@@ -736,5 +739,5 @@
 
 clean:
-	rm -f $(PROG) $(OBJS) *.mod *.smod *.i *.lst 
+	rm -f $(PROG) $(OBJS) *.mod *.smod *.i *.lst
 
 .f90.o:
@@ -994,4 +997,7 @@
 	random_generator_parallel_mod.o \
 	surface_mod.o
+dynamics_mod.o: \
+	mod_kinds.o \
+	modules.o
 exchange_horiz.o: \
 	cpulog_mod.o \
@@ -1179,4 +1185,5 @@
 	chemistry_model_mod.o \
 	diagnostic_output_quantities_mod.o \
+	dynamics_mod.o \
 	gust_mod.o \
 	indoor_model_mod.o \
@@ -1194,4 +1201,5 @@
 	surface_data_output_mod.o \
 	synthetic_turbulence_generator_mod.o \
+	turbulence_closure_mod.o \
 	urban_surface_mod.o \
 	user_module.o \
@@ -1508,11 +1516,4 @@
 	netcdf_interface_mod.o \
 	surface_mod.o
-swap_timelevel.o: \
-	cpulog_mod.o \
-	mod_kinds.o \
-	module_interface.o \
-	modules.o \
-	pmc_interface_mod.o \
-	turbulence_closure_mod.o
 synthetic_turbulence_generator_mod.o: \
 	basic_constants_and_equations_mod.o \
Index: /palm/trunk/SOURCE/dynamics_mod.f90
===================================================================
--- /palm/trunk/SOURCE/dynamics_mod.f90	(revision 4047)
+++ /palm/trunk/SOURCE/dynamics_mod.f90	(revision 4047)
@@ -0,0 +1,990 @@
+!> @file dynamics_mod.f90
+!--------------------------------------------------------------------------------------------------!
+! This file is part of the PALM model system.
+!
+! PALM is free software: you can redistribute it and/or modify it under the
+! terms of the GNU General Public License as published by the Free Software
+! Foundation, either version 3 of the License, or (at your option) any later
+! version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 1997-2019 Leibniz Universitaet Hannover
+!--------------------------------------------------------------------------------------------------!
+!
+! Current revisions:
+! -----------------
+!
+!
+! Former revisions:
+! -----------------
+! $Id$
+! Initial introduction of the dynamics module with only dynamics_swap_timelevel implemented
+!
+!
+! Description:
+! ------------
+!> This module contains the dynamics of PALM.
+!--------------------------------------------------------------------------------------------------!
+ MODULE dynamics_mod
+
+
+    USE arrays_3d, &
+        ONLY:  pt, pt_1, pt_2, pt_p, &
+               q, q_1, q_2, q_p, &
+               s, s_1, s_2, s_p, &
+               u, u_1, u_2, u_p, &
+               v, v_1, v_2, v_p, &
+               w, w_1, w_2, w_p
+
+    USE control_parameters, &
+        ONLY:  length, &
+               restart_string, &
+               humidity, &
+               neutral, &
+               passive_scalar
+
+    USE indices, &
+        ONLY:  nbgp, &
+               nxl, &
+               nxr, &
+               nys, &
+               nyn, &
+               nzb, &
+               nzt
+
+    USE kinds
+
+    IMPLICIT NONE
+
+    LOGICAL ::  dynamics_module_enabled = .FALSE.   !<
+
+    SAVE
+
+    PRIVATE
+
+!
+!-- Public functions
+    PUBLIC &
+       dynamics_parin, &
+       dynamics_check_parameters, &
+       dynamics_check_data_output_ts, &
+       dynamics_check_data_output_pr, &
+       dynamics_check_data_output, &
+       dynamics_init_masks, &
+       dynamics_define_netcdf_grid, &
+       dynamics_init_arrays, &
+       dynamics_init, &
+       dynamics_init_checks, &
+       dynamics_header, &
+       dynamics_actions, &
+       dynamics_non_advective_processes, &
+       dynamics_exchange_horiz, &
+       dynamics_prognostic_equations, &
+       dynamics_swap_timelevel, &
+       dynamics_3d_data_averaging, &
+       dynamics_data_output_2d, &
+       dynamics_data_output_3d, &
+       dynamics_statistics, &
+       dynamics_rrd_global, &
+       dynamics_rrd_local, &
+       dynamics_wrd_global, &
+       dynamics_wrd_local, &
+       dynamics_last_actions
+
+!
+!-- Public parameters, constants and initial values
+    PUBLIC &
+       dynamics_module_enabled
+
+    INTERFACE dynamics_parin
+       MODULE PROCEDURE dynamics_parin
+    END INTERFACE dynamics_parin
+
+    INTERFACE dynamics_check_parameters
+       MODULE PROCEDURE dynamics_check_parameters
+    END INTERFACE dynamics_check_parameters
+
+    INTERFACE dynamics_check_data_output_ts
+       MODULE PROCEDURE dynamics_check_data_output_ts
+    END INTERFACE dynamics_check_data_output_ts
+
+    INTERFACE dynamics_check_data_output_pr
+       MODULE PROCEDURE dynamics_check_data_output_pr
+    END INTERFACE dynamics_check_data_output_pr
+
+    INTERFACE dynamics_check_data_output
+       MODULE PROCEDURE dynamics_check_data_output
+    END INTERFACE dynamics_check_data_output
+
+    INTERFACE dynamics_init_masks
+       MODULE PROCEDURE dynamics_init_masks
+    END INTERFACE dynamics_init_masks
+
+    INTERFACE dynamics_define_netcdf_grid
+       MODULE PROCEDURE dynamics_define_netcdf_grid
+    END INTERFACE dynamics_define_netcdf_grid
+
+    INTERFACE dynamics_init_arrays
+       MODULE PROCEDURE dynamics_init_arrays
+    END INTERFACE dynamics_init_arrays
+
+    INTERFACE dynamics_init
+       MODULE PROCEDURE dynamics_init
+    END INTERFACE dynamics_init
+
+    INTERFACE dynamics_init_checks
+       MODULE PROCEDURE dynamics_init_checks
+    END INTERFACE dynamics_init_checks
+
+    INTERFACE dynamics_header
+       MODULE PROCEDURE dynamics_header
+    END INTERFACE dynamics_header
+
+    INTERFACE dynamics_actions
+       MODULE PROCEDURE dynamics_actions
+       MODULE PROCEDURE dynamics_actions_ij
+    END INTERFACE dynamics_actions
+
+    INTERFACE dynamics_non_advective_processes
+       MODULE PROCEDURE dynamics_non_advective_processes
+       MODULE PROCEDURE dynamics_non_advective_processes_ij
+    END INTERFACE dynamics_non_advective_processes
+
+    INTERFACE dynamics_exchange_horiz
+       MODULE PROCEDURE dynamics_exchange_horiz
+    END INTERFACE dynamics_exchange_horiz
+
+    INTERFACE dynamics_prognostic_equations
+       MODULE PROCEDURE dynamics_prognostic_equations
+       MODULE PROCEDURE dynamics_prognostic_equations_ij
+    END INTERFACE dynamics_prognostic_equations
+
+    INTERFACE dynamics_swap_timelevel
+       MODULE PROCEDURE dynamics_swap_timelevel
+    END INTERFACE dynamics_swap_timelevel
+
+    INTERFACE dynamics_3d_data_averaging
+       MODULE PROCEDURE dynamics_3d_data_averaging
+    END INTERFACE dynamics_3d_data_averaging
+
+    INTERFACE dynamics_data_output_2d
+       MODULE PROCEDURE dynamics_data_output_2d
+    END INTERFACE dynamics_data_output_2d
+
+    INTERFACE dynamics_data_output_3d
+       MODULE PROCEDURE dynamics_data_output_3d
+    END INTERFACE dynamics_data_output_3d
+
+    INTERFACE dynamics_statistics
+       MODULE PROCEDURE dynamics_statistics
+    END INTERFACE dynamics_statistics
+
+    INTERFACE dynamics_rrd_global
+       MODULE PROCEDURE dynamics_rrd_global
+    END INTERFACE dynamics_rrd_global
+
+    INTERFACE dynamics_rrd_local
+       MODULE PROCEDURE dynamics_rrd_local
+    END INTERFACE dynamics_rrd_local
+
+    INTERFACE dynamics_wrd_global
+       MODULE PROCEDURE dynamics_wrd_global
+    END INTERFACE dynamics_wrd_global
+
+    INTERFACE dynamics_wrd_local
+       MODULE PROCEDURE dynamics_wrd_local
+    END INTERFACE dynamics_wrd_local
+
+    INTERFACE dynamics_last_actions
+       MODULE PROCEDURE dynamics_last_actions
+    END INTERFACE dynamics_last_actions
+
+
+ CONTAINS
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Read module-specific namelist
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_parin
+
+
+    CHARACTER (LEN=80)  ::  line  !< dummy string that contains the current line of the parameter file
+
+    NAMELIST /dynamics_parameters/  &
+       dynamics_module_enabled
+
+    line = ' '
+!
+!-- Try to find module-specific namelist
+    REWIND ( 11 )
+    line = ' '
+    DO   WHILE ( INDEX( line, '&dynamics_parameters' ) == 0 )
+       READ ( 11, '(A)', END=12 )  line
+    ENDDO
+    BACKSPACE ( 11 )
+
+!-- Set default module switch to true
+    dynamics_module_enabled = .TRUE.
+
+!-- Read user-defined namelist
+    READ ( 11, dynamics_parameters, ERR = 10 )
+
+    GOTO 12
+
+10  BACKSPACE( 11 )
+    READ( 11 , '(A)') line
+    CALL parin_fail_message( 'dynamics_parameters', line )
+
+12  CONTINUE
+
+ END SUBROUTINE dynamics_parin
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Check control parameters and deduce further quantities.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_check_parameters
+
+
+ END SUBROUTINE dynamics_check_parameters
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Set module-specific timeseries units and labels
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_check_data_output_ts( dots_max, dots_num, dots_label, dots_unit )
+
+
+    INTEGER(iwp),      INTENT(IN)     ::  dots_max
+    INTEGER(iwp),      INTENT(INOUT)  ::  dots_num
+    CHARACTER (LEN=*), DIMENSION(dots_max), INTENT(INOUT)  :: dots_label
+    CHARACTER (LEN=*), DIMENSION(dots_max), INTENT(INOUT)  :: dots_unit
+
+!
+!-- Next line is to avoid compiler warning about unused variables. Please remove.
+    IF ( dots_num == 0  .OR.  dots_label(1)(1:1) == ' '  .OR.  dots_unit(1)(1:1) == ' ' )  CONTINUE
+
+
+ END SUBROUTINE dynamics_check_data_output_ts
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Set the unit of module-specific profile output quantities. For those variables not recognized,
+!> the parameter unit is set to "illegal", which tells the calling routine that the output variable
+!> is not defined and leads to a program abort.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_check_data_output_pr( variable, var_count, unit, dopr_unit )
+
+
+    CHARACTER (LEN=*) ::  unit     !<
+    CHARACTER (LEN=*) ::  variable !<
+    CHARACTER (LEN=*) ::  dopr_unit !< local value of dopr_unit
+
+    INTEGER(iwp) ::  var_count     !<
+
+!
+!-- Next line is to avoid compiler warning about unused variables. Please remove.
+    IF ( unit(1:1) == ' '  .OR.  dopr_unit(1:1) == ' '  .OR.  var_count == 0 )  CONTINUE
+
+    SELECT CASE ( TRIM( variable ) )
+
+!       CASE ( 'var_name' )
+
+       CASE DEFAULT
+          unit = 'illegal'
+
+    END SELECT
+
+
+ END SUBROUTINE dynamics_check_data_output_pr
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Set the unit of module-specific output quantities. For those variables not recognized,
+!> the parameter unit is set to "illegal", which tells the calling routine that the output variable
+!< is not defined and leads to a program abort.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_check_data_output( variable, unit )
+
+
+    CHARACTER (LEN=*) ::  unit     !<
+    CHARACTER (LEN=*) ::  variable !<
+
+    SELECT CASE ( TRIM( variable ) )
+
+!       CASE ( 'u2' )
+
+       CASE DEFAULT
+          unit = 'illegal'
+
+    END SELECT
+
+
+ END SUBROUTINE dynamics_check_data_output
+
+
+!------------------------------------------------------------------------------!
+!
+! Description:
+! ------------
+!> Initialize module-specific masked output
+!------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_init_masks( variable, unit )
+
+
+    CHARACTER (LEN=*) ::  unit     !<
+    CHARACTER (LEN=*) ::  variable !<
+
+
+    SELECT CASE ( TRIM( variable ) )
+
+!       CASE ( 'u2' )
+
+       CASE DEFAULT
+          unit = 'illegal'
+
+    END SELECT
+
+
+ END SUBROUTINE dynamics_init_masks
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Initialize module-specific arrays
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_init_arrays
+
+
+ END SUBROUTINE dynamics_init_arrays
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Execution of module-specific initializing actions
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_init
+
+
+ END SUBROUTINE dynamics_init
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Perform module-specific post-initialization checks
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_init_checks
+
+
+ END SUBROUTINE dynamics_init_checks
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Set the grids on which module-specific output quantities are defined. Allowed values for
+!> grid_x are "x" and "xu", for grid_y "y" and "yv", and for grid_z "zu" and "zw".
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_define_netcdf_grid( variable, found, grid_x, grid_y, grid_z )
+
+
+    CHARACTER (LEN=*) ::  grid_x     !<
+    CHARACTER (LEN=*) ::  grid_y     !<
+    CHARACTER (LEN=*) ::  grid_z     !<
+    CHARACTER (LEN=*) ::  variable   !<
+
+    LOGICAL ::  found   !<
+
+
+    SELECT CASE ( TRIM( variable ) )
+
+!       CASE ( 'u2' )
+
+       CASE DEFAULT
+          found  = .FALSE.
+          grid_x = 'none'
+          grid_y = 'none'
+          grid_z = 'none'
+
+    END SELECT
+
+
+ END SUBROUTINE dynamics_define_netcdf_grid
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Print a header with module-specific information.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_header( io )
+
+
+    INTEGER(iwp) ::  io   !<
+
+!
+!-- If no module-specific variables are read from the namelist-file, no information will be printed.
+    IF ( .NOT. dynamics_module_enabled )  THEN
+       WRITE ( io, 100 )
+       RETURN
+    ENDIF
+
+!
+!-- Printing the information.
+    WRITE ( io, 110 )
+
+!
+!-- Format-descriptors
+100 FORMAT (//' *** dynamic module disabled'/)
+110 FORMAT (//1X,78('#')                                                       &
+            //' User-defined variables and actions:'/                          &
+              ' -----------------------------------'//)
+
+ END SUBROUTINE dynamics_header
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Execute module-specific actions for all grid points
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_actions( location )
+
+
+    CHARACTER (LEN=*) ::  location !<
+
+!    INTEGER(iwp) ::  i !<
+!    INTEGER(iwp) ::  j !<
+!    INTEGER(iwp) ::  k !<
+
+!
+!-- Here the user-defined 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' )
+
+
+       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 dynamics_actions
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Execute module-specific actions for grid point i,j
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_actions_ij( i, j, location )
+
+
+    CHARACTER (LEN=*) ::  location
+
+    INTEGER(iwp) ::  i
+    INTEGER(iwp) ::  j
+
+!
+!-- Here the user-defined 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 dynamics_actions_ij
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute module-specific non-advective processes for all grid points
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_non_advective_processes
+
+
+
+ END SUBROUTINE dynamics_non_advective_processes
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute module-specific non-advective processes for grid points i,j
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_non_advective_processes_ij( i, j )
+
+
+    INTEGER(iwp) ::  i                 !<
+    INTEGER(iwp) ::  j                 !<
+
+!
+!--    Next line is just to avoid compiler warnings about unused variables. You may remove it.
+       IF ( i + j < 0 )  CONTINUE
+
+
+ END SUBROUTINE dynamics_non_advective_processes_ij
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Perform module-specific horizontal boundary exchange
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_exchange_horiz
+
+
+
+ END SUBROUTINE dynamics_exchange_horiz
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute module-specific prognostic equations for all grid points
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_prognostic_equations
+
+
+
+ END SUBROUTINE dynamics_prognostic_equations
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute module-specific prognostic equations for grid point i,j
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_prognostic_equations_ij( i, j, i_omp_start, tn )
+
+
+    INTEGER(iwp), INTENT(IN) ::  i            !< grid index in x-direction
+    INTEGER(iwp), INTENT(IN) ::  j            !< grid index in y-direction
+    INTEGER(iwp), INTENT(IN) ::  i_omp_start  !< first loop index of i-loop in prognostic_equations
+    INTEGER(iwp), INTENT(IN) ::  tn           !< task number of openmp task
+
+!
+!-- Next line is just to avoid compiler warnings about unused variables. You may remove it.
+    IF ( i + j + i_omp_start + tn < 0 )  CONTINUE
+
+ END SUBROUTINE dynamics_prognostic_equations_ij
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Swap timelevels of module-specific array pointers
+!------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_swap_timelevel ( mod_count )
+
+
+    INTEGER, INTENT(IN) :: mod_count
+
+
+    SELECT CASE ( mod_count )
+
+       CASE ( 0 )
+
+          u  => u_1;   u_p  => u_2
+          v  => v_1;   v_p  => v_2
+          w  => w_1;   w_p  => w_2
+          IF ( .NOT. neutral )  THEN
+             pt => pt_1;  pt_p => pt_2
+          ENDIF
+          IF ( humidity )  THEN
+             q => q_1;    q_p => q_2
+          ENDIF
+          IF ( passive_scalar )  THEN
+             s => s_1;    s_p => s_2
+          ENDIF
+
+       CASE ( 1 )
+
+          u  => u_2;   u_p  => u_1
+          v  => v_2;   v_p  => v_1
+          w  => w_2;   w_p  => w_1
+          IF ( .NOT. neutral )  THEN
+             pt => pt_2;  pt_p => pt_1
+          ENDIF
+          IF ( humidity )  THEN
+             q => q_2;    q_p => q_1
+          ENDIF
+          IF ( passive_scalar )  THEN
+             s => s_2;    s_p => s_1
+          ENDIF
+
+    END SELECT
+
+ END SUBROUTINE dynamics_swap_timelevel
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Sum up and time-average module-specific output quantities
+!> as well as allocate the array necessary for storing the average.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_3d_data_averaging( mode, variable )
+
+
+    CHARACTER (LEN=*) ::  mode    !<
+    CHARACTER (LEN=*) :: variable !<
+
+
+    IF ( mode == 'allocate' )  THEN
+
+       SELECT CASE ( TRIM( variable ) )
+
+!          CASE ( 'u2' )
+
+          CASE DEFAULT
+             CONTINUE
+
+       END SELECT
+
+    ELSEIF ( mode == 'sum' )  THEN
+
+       SELECT CASE ( TRIM( variable ) )
+
+!          CASE ( 'u2' )
+
+          CASE DEFAULT
+             CONTINUE
+
+       END SELECT
+
+    ELSEIF ( mode == 'average' )  THEN
+
+       SELECT CASE ( TRIM( variable ) )
+
+!          CASE ( 'u2' )
+
+       END SELECT
+
+    ENDIF
+
+
+ END SUBROUTINE dynamics_3d_data_averaging
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Resorts the module-specific output quantity with indices (k,j,i) to a
+!> temporary array with indices (i,j,k) and sets the grid on which it is defined.
+!> Allowed values for grid are "zu" and "zw".
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_data_output_2d( av, variable, found, grid, mode, local_pf, &
+                                     two_d, nzb_do, nzt_do, fill_value )
+
+
+    CHARACTER (LEN=*) ::  grid     !<
+    CHARACTER (LEN=*), INTENT(IN) ::  mode       !< either 'xy', 'xz' or 'yz'
+    CHARACTER (LEN=*) ::  variable !<
+
+    INTEGER(iwp) ::  av     !< flag to control data output of instantaneous or time-averaged data
+!    INTEGER(iwp) ::  i      !< grid index along x-direction
+!    INTEGER(iwp) ::  j      !< grid index along y-direction
+!    INTEGER(iwp) ::  k      !< grid index along z-direction
+!    INTEGER(iwp) ::  m      !< running index surface elements
+    INTEGER(iwp) ::  nzb_do !< lower limit of the domain (usually nzb)
+    INTEGER(iwp) ::  nzt_do !< upper limit of the domain (usually nzt+1)
+
+    LOGICAL      ::  found !<
+    LOGICAL      ::  two_d !< flag parameter that indicates 2D variables (horizontal cross sections)
+
+    REAL(wp), INTENT(IN) ::  fill_value
+
+    REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !<
+
+!
+!-- Next line is just to avoid compiler warnings about unused variables. You may remove it.
+    IF ( two_d .AND. av + LEN( mode ) + local_pf(nxl,nys,nzb_do) + fill_value < 0.0 )  CONTINUE
+
+    found = .TRUE.
+
+    SELECT CASE ( TRIM( variable ) )
+
+!       CASE ( 'u2_xy', 'u2_xz', 'u2_yz' )
+
+       CASE DEFAULT
+          found = .FALSE.
+          grid  = 'none'
+
+    END SELECT
+
+
+ END SUBROUTINE dynamics_data_output_2d
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Resorts the module-specific output quantity with indices (k,j,i)
+!> to a temporary array with indices (i,j,k).
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_data_output_3d( av, variable, found, local_pf, fill_value, nzb_do, nzt_do )
+
+
+    CHARACTER (LEN=*) ::  variable !<
+
+    INTEGER(iwp) ::  av    !<
+!    INTEGER(iwp) ::  i     !<
+!    INTEGER(iwp) ::  j     !<
+!    INTEGER(iwp) ::  k     !<
+    INTEGER(iwp) ::  nzb_do !< lower limit of the data output (usually 0)
+    INTEGER(iwp) ::  nzt_do !< vertical upper limit of the data output (usually nz_do3d)
+
+    LOGICAL      ::  found !<
+
+    REAL(wp), INTENT(IN) ::  fill_value    !< value for the _FillValue attribute
+
+    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !<
+
+!
+!-- Next line is to avoid compiler warning about unused variables. Please remove.
+    IF ( av + local_pf(nxl,nys,nzb_do) + fill_value < 0.0 )  CONTINUE
+
+
+    found = .TRUE.
+
+    SELECT CASE ( TRIM( variable ) )
+
+!       CASE ( 'u2' )
+
+       CASE DEFAULT
+          found = .FALSE.
+
+    END SELECT
+
+
+ END SUBROUTINE dynamics_data_output_3d
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Calculation of module-specific statistics, i.e. horizontally averaged profiles and time series.
+!> This is called for every statistic region sr, but at least for the region "total domain" (sr=0).
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_statistics( mode, sr, tn )
+
+
+    CHARACTER (LEN=*) ::  mode   !<
+!    INTEGER(iwp) ::  i    !<
+!    INTEGER(iwp) ::  j    !<
+!    INTEGER(iwp) ::  k    !<
+    INTEGER(iwp) ::  sr   !<
+    INTEGER(iwp) ::  tn   !<
+
+!
+!-- Next line is to avoid compiler warning about unused variables. Please remove.
+    IF ( sr == 0  .OR.  tn == 0 )  CONTINUE
+
+    IF ( mode == 'profiles' )  THEN
+
+    ELSEIF ( mode == 'time_series' )  THEN
+
+    ENDIF
+
+ END SUBROUTINE dynamics_statistics
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Read module-specific global restart data.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_rrd_global( found )
+
+
+    LOGICAL, INTENT(OUT)  ::  found
+
+
+    found = .TRUE.
+
+
+    SELECT CASE ( restart_string(1:length) )
+
+       CASE ( 'global_paramter' )
+!          READ ( 13 )  global_parameter
+
+       CASE DEFAULT
+
+          found = .FALSE.
+
+    END SELECT
+
+
+ END SUBROUTINE dynamics_rrd_global
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Read module-specific processor specific restart data from file(s).
+!> Subdomain index limits on file are given by nxl_on_file, etc.
+!> Indices nxlc, etc. indicate the range of gridpoints to be mapped from the subdomain on file (f)
+!> to the subdomain of the current PE (c). They have been calculated in routine rrd_local.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_rrd_local( k, nxlf, nxlc, nxl_on_file, nxrf, nxrc, nxr_on_file, nynf, nync,   &
+                                nyn_on_file, nysf, nysc, nys_on_file, tmp_2d, tmp_3d, found )
+
+
+    INTEGER(iwp) ::  k               !<
+    INTEGER(iwp) ::  nxlc            !<
+    INTEGER(iwp) ::  nxlf            !<
+    INTEGER(iwp) ::  nxl_on_file     !<
+    INTEGER(iwp) ::  nxrc            !<
+    INTEGER(iwp) ::  nxrf            !<
+    INTEGER(iwp) ::  nxr_on_file     !<
+    INTEGER(iwp) ::  nync            !<
+    INTEGER(iwp) ::  nynf            !<
+    INTEGER(iwp) ::  nyn_on_file     !<
+    INTEGER(iwp) ::  nysc            !<
+    INTEGER(iwp) ::  nysf            !<
+    INTEGER(iwp) ::  nys_on_file     !<
+
+    LOGICAL, INTENT(OUT)  ::  found
+
+    REAL(wp), DIMENSION(nys_on_file-nbgp:nyn_on_file+nbgp,nxl_on_file-nbgp:nxr_on_file+nbgp) :: tmp_2d   !<
+    REAL(wp), DIMENSION(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp,nxl_on_file-nbgp:nxr_on_file+nbgp) :: tmp_3d   !<
+
+!
+!-- Next line is to avoid compiler warning about unused variables. Please remove.
+    IF ( k + nxlc + nxlf + nxrc + nxrf + nync + nynf + nysc + nysf + tmp_2d(nys_on_file,nxl_on_file) + tmp_3d(nzb,nys_on_file,nxl_on_file) < 0.0 )  CONTINUE
+!
+!-- Here the reading of user-defined restart data follows:
+!-- Sample for user-defined output
+
+    found = .TRUE.
+
+    SELECT CASE ( restart_string(1:length) )
+
+!       CASE ( 'u2_av' )
+
+       CASE DEFAULT
+
+          found = .FALSE.
+
+    END SELECT
+
+ END SUBROUTINE dynamics_rrd_local
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Writes global module-specific restart data into binary file(s) for restart runs.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_wrd_global
+
+
+ END SUBROUTINE dynamics_wrd_global
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Writes processor specific and module-specific restart data into binary file(s) for restart runs.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_wrd_local
+
+
+ END SUBROUTINE dynamics_wrd_local
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Execute module-specific actions at the very end of the program.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE dynamics_last_actions
+
+
+ END SUBROUTINE dynamics_last_actions
+
+ END MODULE dynamics_mod
Index: /palm/trunk/SOURCE/module_interface.f90
===================================================================
--- /palm/trunk/SOURCE/module_interface.f90	(revision 4046)
+++ /palm/trunk/SOURCE/module_interface.f90	(revision 4047)
@@ -25,20 +25,23 @@
 ! -----------------
 ! $Id$
+! Introduction of the dynamics module
+!
+! 4039 2019-06-18 10:32:41Z suehring
 ! Introduce diagnostic output
-! 
+!
 ! 4028 2019-06-13 12:21:37Z schwenkel
 ! Further modularization of particle code components
-! 
+!
 ! 4017 2019-06-06 12:16:46Z schwenkel
-! local_pf need INTENT(INOUT) attribute rather than INTENT(OUT). This is 
+! local_pf need INTENT(INOUT) attribute rather than INTENT(OUT). This is
 ! because INTENT(OUT) sets the array to not-defined. Especially for outputs that
-! are not defined everywhere, e.g. land-surface outputs, this will be 
-! problematic as NaN will be output.   
-! 
+! are not defined everywhere, e.g. land-surface outputs, this will be
+! problematic as NaN will be output.
+!
 ! 3987 2019-05-22 09:52:13Z kanani
 ! Introduce switchable DEBUG file output via debug_message routine
-! 
+!
 ! 3956 2019-05-07 12:32:52Z monakurppa
-! - Added calls for salsa_non_advective_processes and 
+! - Added calls for salsa_non_advective_processes and
 !   salsa_exchange_horiz_bounds
 ! - Moved the call for salsa_data_output_2d/3d before that of
@@ -46,21 +49,21 @@
 !   salsa output variable and encounters a segmentation fault for "Ntot" due
 !   to the shortoutput name
-! 
+!
 ! 3931 2019-04-24 16:34:28Z schwenkel
 ! Changed non_transport_physics to non_advective_processes
-! 
+!
 ! 3930 2019-04-24 14:57:18Z forkel
 ! Correct/complete module_interface introduction for chemistry model
 !
 ! 3887 2019 -04-12 08:47:41Z schwenkel
-! Changes related to global restructuring of location messages and introduction 
+! Changes related to global restructuring of location messages and introduction
 ! of additional debug messages
-!  
+!
 ! 3880 2019 -04-08 21:43:02Z knoop
 ! Add a call for salsa_prognostic_equations
-! 
+!
 ! 3840 2019-03-29 10:35:52Z knoop
 ! bugfix: intent of dummy arguments changed to inout
-! 
+!
 ! 3770 2019-02-28 11:22:32Z moh.hefny
 ! removed unused variables in module_interface_check_data_output_ts
@@ -68,56 +71,56 @@
 ! 3767 08:18:02Z raasch
 ! unused variable file_index removed from subroutine parameter list
-! 
+!
 ! 3766 2019-02-26 16:23:41Z raasch
 ! first argument removed from module_interface_rrd_*, statement added to avoid
 ! compiler warning about unused variable, file reformatted with respect to coding
 ! standards
-! 
+!
 ! 3762 2019-02-25 16:54:16Z suehring
 ! only pass required arguments to surface_data_output_rrd_local
-! 
+!
 ! 3747 2019-02-16 15:15:23Z gronemeier
 ! Call user_init_arrays
-! 
+!
 ! 3745 2019-02-15 18:57:56Z suehring
 ! Add indoor model
-! 
+!
 ! 3744 2019-02-15 18:38:58Z suehring
 ! Removed bio_check_parameters as the method is empty.
-! 
+!
 ! 3735 2019-02-12 09:52:40Z dom_dwd_user
-! Accepting variable j from check_parameters and passing it to 
+! Accepting variable j from check_parameters and passing it to
 ! bio_check_data_output
 ! Add required restart data for surface output module
-! 
+!
 ! 3731 2019-02-11 13:06:27Z suehring
 ! Add check_parameters routine for virtual measurements
-! 
+!
 ! 3711 2019-01-31 13:44:26Z knoop
 ! Introduced module_interface_init_checks for post-init checks
-! 
+!
 ! 3705 2019-01-29 19:56:39Z suehring
 ! Add last_actions for virtual measurements
-! 
+!
 ! 3704 2019-01-29 19:51:41Z suehring
 ! Some interface calls moved to module_interface + cleanup
-! 
+!
 ! 3684 2019-01-20 20:20:58Z knoop
 ! Bugfix: made unit intend INOUT
-! 
+!
 ! 3650 2019-01-04 13:01:33Z kanani
 ! Add restart routines for biometeorology
-! 
+!
 ! 3649 2019-01-02 16:52:21Z suehring
 ! Initialize strings, in order to avoid compiler warnings for non-initialized
 ! characters with intent(out) attribute
-! 
+!
 ! 3648 2019-01-02 16:35:46Z suehring
 ! Rename subroutines for surface-data output
-! 
+!
 ! 3641 2018-12-23 22:10:01Z knoop
 ! Initial implementation of the PALM module interface
 !
-! 
+!
 ! Description:
 ! ------------
@@ -136,4 +139,35 @@
 !-- load module-specific control parameters.
 !-- ToDo: move all of them to respective module or a dedicated central module
+
+    USE dynamics_mod, &
+        ONLY:  dynamics_parin, &
+               dynamics_check_parameters, &
+               dynamics_check_data_output_ts, &
+               dynamics_check_data_output_pr, &
+               dynamics_check_data_output, &
+               dynamics_init_masks, &
+               dynamics_define_netcdf_grid, &
+               dynamics_init_arrays, &
+               dynamics_init, &
+               dynamics_init_checks, &
+               dynamics_header, &
+               dynamics_actions, &
+               dynamics_non_advective_processes, &
+               dynamics_exchange_horiz, &
+               dynamics_prognostic_equations, &
+               dynamics_swap_timelevel, &
+               dynamics_3d_data_averaging, &
+               dynamics_data_output_2d, &
+               dynamics_data_output_3d, &
+               dynamics_statistics, &
+               dynamics_rrd_global, &
+               dynamics_rrd_local, &
+               dynamics_wrd_global, &
+               dynamics_wrd_local, &
+               dynamics_last_actions
+
+    USE turbulence_closure_mod, &
+        ONLY:  tcm_swap_timelevel
+
     USE control_parameters,                                                    &
         ONLY:  air_chemistry,                                                  &
@@ -213,6 +247,6 @@
               chem_rrd_local,                                                  &
               chem_wrd_local
-     
-    USE diagnostic_output_quantities_mod,                                      & 
+
+    USE diagnostic_output_quantities_mod,                                      &
         ONLY:  doq_3d_data_averaging,                                          &
                doq_check_data_output,                                          &
@@ -257,10 +291,10 @@
                im_data_output_3d,                                              &
                im_init
-               
+
     USE lagrangian_particle_model_mod,                                         &
         ONLY:  lpm_parin,                                                      &
                lpm_header,                                                     &
                lpm_check_parameters,                                           &
-               lpm_init_arrays,                                                &                              
+               lpm_init_arrays,                                                &
                lpm_init,                                                       &
                lpm_actions,                                                    &
@@ -269,5 +303,5 @@
                lpm_wrd_local,                                                  &
                lpm_wrd_global
-               
+
     USE land_surface_model_mod,                                                &
         ONLY:  lsm_parin,                                                      &
@@ -317,7 +351,7 @@
                ocean_rrd_local,                                                &
                ocean_wrd_local
-               
+
     USE particle_attributes,                                                   &
-        ONLY:  particle_advection               
+        ONLY:  particle_advection
 
     USE plant_canopy_model_mod,                                                &
@@ -394,4 +428,19 @@
                usm_rrd_local,                                                  &
                usm_wrd_local
+
+    USE virtual_measurement_mod,                                               &
+        ONLY:  vm_check_parameters,                                            &
+               vm_init,                                                        &
+               vm_last_actions,                                                &
+               vm_parin
+
+    USE wind_turbine_model_mod,                                                &
+        ONLY:  wtm_parin,                                                      &
+               wtm_check_parameters,                                           &
+               wtm_init_arrays,                                                &
+               wtm_init,                                                       &
+               wtm_actions,                                                    &
+               wtm_rrd_global,                                                 &
+               wtm_wrd_global
 
     USE user,                                                                  &
@@ -415,19 +464,4 @@
                user_wrd_local,                                                 &
                user_last_actions
-
-    USE virtual_measurement_mod,                                               &
-        ONLY:  vm_check_parameters,                                            &
-               vm_init,                                                        &
-               vm_last_actions,                                                &
-               vm_parin
-
-    USE wind_turbine_model_mod,                                                &
-        ONLY:  wtm_parin,                                                      &
-               wtm_check_parameters,                                           &
-               wtm_init_arrays,                                                &
-               wtm_init,                                                       &
-               wtm_actions,                                                    &
-               wtm_rrd_global,                                                 &
-               wtm_wrd_global
 
     IMPLICIT NONE
@@ -518,9 +552,9 @@
        MODULE PROCEDURE module_interface_non_advective_processes_ij
     END INTERFACE module_interface_non_advective_processes
-    
+
     INTERFACE module_interface_exchange_horiz
        MODULE PROCEDURE module_interface_exchange_horiz
     END INTERFACE module_interface_exchange_horiz
-    
+
     INTERFACE module_interface_prognostic_equations
        MODULE PROCEDURE module_interface_prognostic_equations
@@ -581,4 +615,6 @@
 
     IF ( debug_output )  CALL debug_message( 'reading module-specific parameters', 'start' )
+
+    CALL dynamics_parin
 
     CALL bio_parin
@@ -588,5 +624,5 @@
     CALL gust_parin
     CALL im_parin
-    CALL lpm_parin      
+    CALL lpm_parin
     CALL lsm_parin
     ! ToDo: create parin routine for large_scale_forcing and nudging (should be seperate modules or new module switch)
@@ -600,9 +636,10 @@
     CALL surface_data_output_parin
     CALL stg_parin
-    CALL user_parin ! ToDo: make user code a single Fortran module
     CALL usm_parin
     CALL vm_parin
     CALL wtm_parin
 
+    CALL user_parin
+
     IF ( debug_output )  CALL debug_message( 'reading module-specific parameters', 'end' )
 
@@ -620,4 +657,6 @@
 
     IF ( debug_output )  CALL debug_message( 'checking module-specific parameters', 'start' )
+
+    CALL dynamics_check_parameters
 
     IF ( bulk_cloud_model )     CALL bcm_check_parameters
@@ -625,5 +664,5 @@
     IF ( gust_module_enabled )  CALL gust_check_parameters
     IF ( indoor_model )         CALL im_check_parameters
-    IF ( particle_advection )   CALL lpm_check_parameters        
+    IF ( particle_advection )   CALL lpm_check_parameters
     IF ( land_surface )         CALL lsm_check_parameters
     IF ( large_scale_forcing  .OR.  nudging )  CALL lsf_nudging_check_parameters ! ToDo: create single module switch
@@ -639,4 +678,5 @@
     IF ( virtual_measurement )  CALL vm_check_parameters
     IF ( wind_turbine )         CALL wtm_check_parameters
+
     IF ( user_module_enabled )  CALL user_check_parameters
 
@@ -663,4 +703,6 @@
     IF ( debug_output )  CALL debug_message( 'checking module-specific data output ts', 'start' )
 
+    CALL dynamics_check_data_output_ts( dots_max, dots_num, dots_label, dots_unit )
+
     IF ( radiation )  THEN
        CALL radiation_check_data_output_ts( dots_max, dots_num )
@@ -694,4 +736,6 @@
     IF ( debug_output )  CALL debug_message( 'checking module-specific data output pr', 'start' )
 
+    CALL dynamics_check_data_output_pr( variable, var_count, unit, dopr_unit )
+
     IF ( unit == 'illegal' .AND.  bulk_cloud_model )  THEN
        CALL bcm_check_data_output_pr( variable, var_count, unit, dopr_unit )
@@ -751,4 +795,6 @@
     IF ( debug_output )  CALL debug_message( 'checking module-specific data output 2d/3d', 'start' )
 
+    CALL dynamics_check_data_output( variable, unit )
+
     IF ( unit == 'illegal'  .AND.  biometeorology )  THEN
        CALL bio_check_data_output( variable, unit, i, j, ilen, k )
@@ -763,5 +809,5 @@
        CALL chem_check_data_output( variable, unit, i, ilen, k )
     ENDIF
-    
+
     IF ( unit == 'illegal' )  THEN
        CALL doq_check_data_output( variable, unit )
@@ -796,5 +842,5 @@
        CALL im_check_data_output( variable, unit )
     ENDIF
-   
+
     IF ( unit == 'illegal'  .AND.  urban_surface                      &
         .AND.  variable(1:4) == 'usm_' )  THEN  ! ToDo: remove aditional conditions
@@ -827,4 +873,6 @@
 
     IF ( debug_output )  CALL debug_message( 'initializing module-specific masks', 'start' )
+
+    CALL dynamics_init_masks( variable, unit )
 
     IF ( unit == 'illegal'  .AND.  air_chemistry                               &
@@ -897,8 +945,10 @@
     IF ( debug_output )  CALL debug_message( 'initializing module-specific arrays', 'start' )
 
+    CALL dynamics_init_arrays
+
     IF ( bulk_cloud_model    )  CALL bcm_init_arrays
     IF ( air_chemistry       )  CALL chem_init_arrays
     IF ( gust_module_enabled )  CALL gust_init_arrays
-    IF ( particle_advection  )  CALL lpm_init_arrays        
+    IF ( particle_advection  )  CALL lpm_init_arrays
     IF ( land_surface        )  CALL lsm_init_arrays
     IF ( ocean_mode          )  CALL ocean_init_arrays
@@ -907,4 +957,5 @@
     IF ( surface_output      )  CALL surface_data_output_init_arrays
     IF ( wind_turbine        )  CALL wtm_init_arrays
+
     IF ( user_module_enabled )  CALL user_init_arrays
 
@@ -924,4 +975,6 @@
 
     IF ( debug_output )  CALL debug_message( 'module-specific initialization', 'start' )
+
+    CALL dynamics_init
 
     IF ( biometeorology      )  CALL bio_init
@@ -931,5 +984,5 @@
     IF ( gust_module_enabled )  CALL gust_init
     IF ( indoor_model        )  CALL im_init
-    IF ( particle_advection  )  CALL lpm_init    
+    IF ( particle_advection  )  CALL lpm_init
     IF ( large_scale_forcing )  CALL lsf_init
     IF ( land_surface        )  CALL lsm_init
@@ -942,4 +995,5 @@
     IF ( wind_turbine        )  CALL wtm_init
     IF ( radiation           )  CALL radiation_init
+
     IF ( user_module_enabled )  CALL user_init
 
@@ -960,4 +1014,6 @@
     IF ( debug_output )  CALL debug_message( 'module-specific post-initialization checks', 'start' )
 
+    CALL dynamics_init_checks
+
     IF ( biometeorology      )  CALL bio_init_checks
 
@@ -980,4 +1036,6 @@
 
     IF ( debug_output )  CALL debug_message( 'module-specific header output', 'start' )
+
+    CALL dynamics_header( io )
 
     IF ( biometeorology      )  CALL bio_header ( io )
@@ -986,5 +1044,5 @@
     IF ( virtual_flight      )  CALL flight_header( io )
     IF ( gust_module_enabled )  CALL gust_header( io )
-    IF ( particle_advection  )  CALL lpm_header( io )    
+    IF ( particle_advection  )  CALL lpm_header( io )
     IF ( land_surface        )  CALL lsm_header( io )
     IF ( large_scale_forcing )  CALL lsf_nudging_header( io )
@@ -996,4 +1054,5 @@
     IF ( calculate_spectra   )  CALL spectra_header( io )
     IF ( syn_turb_gen        )  CALL stg_header( io )
+
     IF ( user_module_enabled )  CALL user_header( io )
 
@@ -1014,12 +1073,14 @@
     CHARACTER (LEN=*), INTENT(IN) ::  location !< call location string
 
+    CALL dynamics_actions( location )
 
     IF ( bulk_cloud_model    )  CALL bcm_actions( location )
     IF ( air_chemistry       )  CALL chem_actions( location )
     IF ( gust_module_enabled )  CALL gust_actions( location )
-    IF ( particle_advection  )  CALL lpm_actions( location )    
+    IF ( particle_advection  )  CALL lpm_actions( location )
     IF ( ocean_mode          )  CALL ocean_actions( location )
     IF ( salsa               )  CALL salsa_actions( location )
     IF ( wind_turbine        )  CALL wtm_actions( location )
+
     IF ( user_module_enabled )  CALL user_actions( location )
 
@@ -1040,4 +1101,5 @@
     CHARACTER (LEN=*), INTENT(IN) ::  location  !< call location string
 
+    CALL dynamics_actions( i, j, location )
 
     IF ( bulk_cloud_model    )  CALL bcm_actions( i, j, location )
@@ -1047,4 +1109,5 @@
     IF ( salsa               )  CALL salsa_actions( i, j, location )
     IF ( wind_turbine        )  CALL wtm_actions( i, j, location )
+
     IF ( user_module_enabled )  CALL user_actions( i, j, location )
 
@@ -1058,10 +1121,12 @@
 !> Compute module-specific non_advective_processes (vector-optimized)
 !------------------------------------------------------------------------------!
- SUBROUTINE module_interface_non_advective_processes()
-
-
-    IF ( bulk_cloud_model    )  CALL bcm_non_advective_processes()
-    IF ( air_chemistry       )  CALL chem_non_advective_processes()
-    IF ( salsa               )  CALL salsa_non_advective_processes()
+ SUBROUTINE module_interface_non_advective_processes
+
+
+    CALL dynamics_non_advective_processes
+
+    IF ( bulk_cloud_model    )  CALL bcm_non_advective_processes
+    IF ( air_chemistry       )  CALL chem_non_advective_processes
+    IF ( salsa               )  CALL salsa_non_advective_processes
 
 
@@ -1080,4 +1145,5 @@
     INTEGER(iwp), INTENT(IN) ::  j            !< grid index in y-direction
 
+    CALL dynamics_non_advective_processes( i, j )
 
     IF ( bulk_cloud_model    )  CALL bcm_non_advective_processes( i, j )
@@ -1087,18 +1153,20 @@
 
  END SUBROUTINE module_interface_non_advective_processes_ij
- 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Exchange horiz for module-specific quantities 
-!------------------------------------------------------------------------------!
- SUBROUTINE module_interface_exchange_horiz()
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Exchange horiz for module-specific quantities
+!------------------------------------------------------------------------------!
+ SUBROUTINE module_interface_exchange_horiz
 
 
     IF ( debug_output_timestep )  CALL debug_message( 'module-specific exchange_horiz', 'start' )
 
-    IF ( bulk_cloud_model    )  CALL bcm_exchange_horiz()
-    IF ( air_chemistry       )  CALL chem_exchange_horiz_bounds()
-    IF ( salsa               )  CALL salsa_exchange_horiz_bounds()
+    CALL dynamics_exchange_horiz
+
+    IF ( bulk_cloud_model    )  CALL bcm_exchange_horiz
+    IF ( air_chemistry       )  CALL chem_exchange_horiz_bounds
+    IF ( salsa               )  CALL salsa_exchange_horiz_bounds
 
     IF ( debug_output_timestep )  CALL debug_message( 'module-specific exchange_horiz', 'end' )
@@ -1113,12 +1181,14 @@
 !> Compute module-specific prognostic_equations (vector-optimized)
 !------------------------------------------------------------------------------!
- SUBROUTINE module_interface_prognostic_equations()
-
-
-    IF ( bulk_cloud_model    )  CALL bcm_prognostic_equations()
-    IF ( air_chemistry       )  CALL chem_prognostic_equations()
-    IF ( gust_module_enabled )  CALL gust_prognostic_equations()
-    IF ( ocean_mode          )  CALL ocean_prognostic_equations()
-    IF ( salsa               )  CALL salsa_prognostic_equations()
+ SUBROUTINE module_interface_prognostic_equations
+
+
+    CALL dynamics_prognostic_equations
+
+    IF ( bulk_cloud_model    )  CALL bcm_prognostic_equations
+    IF ( air_chemistry       )  CALL chem_prognostic_equations
+    IF ( gust_module_enabled )  CALL gust_prognostic_equations
+    IF ( ocean_mode          )  CALL ocean_prognostic_equations
+    IF ( salsa               )  CALL salsa_prognostic_equations
 
 
@@ -1139,4 +1209,5 @@
     INTEGER(iwp), INTENT(IN) ::  tn           !< task number of openmp task
 
+    CALL dynamics_prognostic_equations( i, j, i_omp_start, tn )
 
     IF ( bulk_cloud_model    )  CALL bcm_prognostic_equations( i, j, i_omp_start, tn )
@@ -1162,4 +1233,7 @@
 
     IF ( debug_output_timestep )  CALL debug_message( 'module-specific swap timelevel', 'start' )
+
+    CALL dynamics_swap_timelevel( swap_mode )
+    CALL tcm_swap_timelevel( swap_mode )
 
     IF ( bulk_cloud_model    )  CALL bcm_swap_timelevel( swap_mode )
@@ -1192,8 +1266,10 @@
     IF ( debug_output_timestep )  CALL debug_message( 'module-specific 3d data averaging', 'start' )
 
+    CALL dynamics_3d_data_averaging( mode, variable )
+
     IF ( biometeorology      )  CALL bio_3d_data_averaging( mode, variable )
     IF ( bulk_cloud_model    )  CALL bcm_3d_data_averaging( mode, variable )
     IF ( air_chemistry       )  CALL chem_3d_data_averaging( mode, variable )
-    CALL doq_3d_data_averaging( mode, variable )
+    CALL doq_3d_data_averaging( mode, variable )  ! ToDo: this seems to be not according to the design
     IF ( gust_module_enabled )  CALL gust_3d_data_averaging( mode, variable )
     IF ( land_surface        )  CALL lsm_3d_data_averaging( mode, variable )
@@ -1202,4 +1278,5 @@
     IF ( salsa               )  CALL salsa_3d_data_averaging( mode, variable )
     IF ( urban_surface       )  CALL usm_3d_data_averaging( mode, variable )
+
     IF ( user_module_enabled )  CALL user_3d_data_averaging( mode, variable )
 
@@ -1234,4 +1311,8 @@
     IF ( debug_output_timestep )  CALL debug_message( 'module-specific 2d data output', 'start' )
 
+    CALL dynamics_data_output_2d(                                                  &
+               av, variable, found, grid, mode, local_pf, two_d, nzb_do, nzt_do, fill_value &
+            )
+
     IF ( .NOT. found  .AND.  biometeorology )  THEN
        CALL bio_data_output_2d(                                                &
@@ -1251,5 +1332,5 @@
             )
     ENDIF
-    
+
     IF ( .NOT. found )  THEN
        CALL doq_output_2d(                                                     &
@@ -1323,4 +1404,7 @@
     IF ( debug_output_timestep )  CALL debug_message( 'module-specific 3d data output', 'start' )
 
+    CALL dynamics_data_output_3d( av, variable, found, local_pf, fill_value, nzb_do, nzt_do )
+    resorted = .FALSE.
+
     IF ( .NOT. found  .AND.  biometeorology )  THEN
        CALL bio_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
@@ -1337,15 +1421,15 @@
        resorted = .TRUE.
     ENDIF
-    
+
     IF ( .NOT. found )  THEN
        CALL doq_output_3d( av, variable, found, local_pf, fill_value, nzb_do, nzt_do )
        resorted = .TRUE.
     ENDIF
-    
+
     IF ( .NOT. found  .AND.  gust_module_enabled )  THEN
        CALL gust_data_output_3d( av, variable, found, local_pf, fill_value, nzb_do, nzt_do )
        resorted = .TRUE.
     ENDIF
-   
+
     IF ( .NOT. found  .AND.  indoor_model )  THEN
        CALL im_data_output_3d( av, variable, found, local_pf, fill_value, nzb_do, nzt_do )
@@ -1400,6 +1484,9 @@
     IF ( debug_output_timestep )  CALL debug_message( 'module-specific statistics', 'start' )
 
+    CALL dynamics_statistics( mode, sr, tn )
+
     IF ( gust_module_enabled )  CALL gust_statistics( mode, sr, tn, dots_max )
     IF ( air_chemistry       )  CALL chem_statistics( mode, sr, tn )
+
     IF ( user_module_enabled )  CALL user_statistics( mode, sr, tn )
 
@@ -1422,4 +1509,6 @@
 
     IF ( debug_output )  CALL debug_message( 'module-specific read global restart data', 'start' )
+
+    CALL dynamics_rrd_global( found ) ! ToDo: change interface to pass variable
 
     IF ( .NOT. found )  CALL bio_rrd_global( found ) ! ToDo: change interface to pass variable
@@ -1427,9 +1516,10 @@
     IF ( .NOT. found )  CALL flight_rrd_global( found ) ! ToDo: change interface to pass variable
     IF ( .NOT. found )  CALL gust_rrd_global( found ) ! ToDo: change interface to pass variable
-    IF ( .NOT. found )  CALL lpm_rrd_global( found ) ! ToDo: change interface to pass variable        
+    IF ( .NOT. found )  CALL lpm_rrd_global( found ) ! ToDo: change interface to pass variable
     IF ( .NOT. found )  CALL ocean_rrd_global( found ) ! ToDo: change interface to pass variable
     IF ( .NOT. found )  CALL stg_rrd_global ( found ) ! ToDo: change interface to pass variable
     IF ( .NOT. found )  CALL wtm_rrd_global( found ) ! ToDo: change interface to pass variable
     IF ( .NOT. found )  CALL surface_data_output_rrd_global( found )
+
     IF ( .NOT. found )  CALL user_rrd_global( found ) ! ToDo: change interface to pass variable
 
@@ -1449,4 +1539,6 @@
 
     IF ( debug_output )  CALL debug_message( 'module-specific write global restart data', 'start' )
+
+    CALL dynamics_wrd_global
 
     IF ( biometeorology )       CALL bio_wrd_global
@@ -1458,4 +1550,5 @@
     IF ( wind_turbine )         CALL wtm_wrd_global
     IF ( surface_output )       CALL surface_data_output_wrd_global
+
     IF ( user_module_enabled )  CALL user_wrd_global
 
@@ -1504,4 +1597,13 @@
     IF ( debug_output )  CALL debug_message( 'module-specific read local restart data', 'start' )
 
+    CALL dynamics_rrd_local(                                                   &
+           map_index,                                                          &
+           nxlf, nxlc, nxl_on_file,                                            &
+           nxrf, nxrc, nxr_on_file,                                            &
+           nynf, nync, nyn_on_file,                                            &
+           nysf, nysc, nys_on_file,                                            &
+           tmp_2d, tmp_3d, found                                               &
+        ) ! ToDo: change interface to pass variable
+
     IF ( .NOT. found )  CALL bio_rrd_local(                                    &
                                found                                           &
@@ -1525,5 +1627,5 @@
                                tmp_3d, found                                   &
                             ) ! ToDo: change interface to pass variable
-                            
+
 !     IF ( .NOT. found )  CALL doq_rrd_local(                                    &
 !                                map_index,                                      &
@@ -1600,5 +1702,5 @@
 !-- Surface data do not need overlap data, so do not pass these information.
     IF ( .NOT. found )  CALL surface_data_output_rrd_local( found )
-                           
+
     IF ( .NOT. found )  CALL user_rrd_local(                                   &
                                map_index,                                      &
@@ -1626,4 +1728,6 @@
     IF ( debug_output )  CALL debug_message( 'module-specific write local restart data', 'start' )
 
+    CALL dynamics_wrd_local
+
     IF ( biometeorology )       CALL bio_wrd_local
     IF ( bulk_cloud_model )     CALL bcm_wrd_local
@@ -1631,5 +1735,5 @@
     CALL doq_wrd_local
     IF ( gust_module_enabled )  CALL gust_wrd_local
-    IF ( particle_advection )   CALL lpm_wrd_local    
+    IF ( particle_advection )   CALL lpm_wrd_local
     IF ( land_surface )         CALL lsm_wrd_local
     IF ( ocean_mode )           CALL ocean_wrd_local
@@ -1638,4 +1742,5 @@
     IF ( urban_surface )        CALL usm_wrd_local
     IF ( surface_output )       CALL surface_data_output_wrd_local
+
     IF ( user_module_enabled )  CALL user_wrd_local
 
@@ -1656,5 +1761,8 @@
     IF ( debug_output )  CALL debug_message( 'module-specific last actions', 'start' )
 
+    CALL dynamics_last_actions
+
     IF ( virtual_measurement )  CALL vm_last_actions
+
     IF ( user_module_enabled )  CALL user_last_actions
 
Index: lm/trunk/SOURCE/swap_timelevel.f90
===================================================================
--- /palm/trunk/SOURCE/swap_timelevel.f90	(revision 4046)
+++ 	(revision )
@@ -1,241 +1,0 @@
-!> @file swap_timelevel.f90
-!------------------------------------------------------------------------------!
-! This file is part of the PALM model system.
-!
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
-!
-! Copyright 1997-2019 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
-!
-! Current revisions:
-! -----------------
-! 
-! 
-! Former revisions:
-! -----------------
-! $Id$
-! unused variables removed
-! 
-! 3655 2019-01-07 16:51:22Z knoop
-! Implementation of the PALM module interface
-! 
-! 3636 2018-12-19 13:48:34Z raasch
-! nopointer option removed
-! 
-! 3589 2018-11-30 15:09:51Z suehring
-! Move the control parameter "salsa" from salsa_mod to control_parameters 
-! (M. Kurppa)
-! 
-! 3582 2018-11-29 19:16:36Z suehring
-! Implementation of a new aerosol module salsa.
-! 
-! 3303 2018-10-03 12:04:15Z raasch
-! bugfix for swapping in case of ocean mode
-! 
-! 3294 2018-10-01 02:37:10Z raasch
-! changes concerning modularization of ocean option
-! 
-! 3274 2018-09-24 15:42:55Z knoop
-! Modularization of all bulk cloud physics code components
-! 
-! 3241 2018-09-12 15:02:00Z raasch
-! unused variables removed
-! 
-! 2817 2018-02-19 16:32:21Z knoop
-! Preliminary gust module interface implemented
-! 
-! 2766 2018-01-22 17:17:47Z kanani
-! Removed preprocessor directive __chem
-! 
-! 2718 2018-01-02 08:49:38Z maronga
-! Corrected "Former revisions" section
-! 
-! 2696 2017-12-14 17:12:51Z kanani
-! Change in file header (GPL part)
-! Moved TKE to turbulence_closure_mod (TG)
-! Implementation of chemistry module (FK)
-! 
-! 2350 2017-08-15 11:48:26Z kanani
-! Bugfix in nopointer version
-! 
-! 2292 2017-06-20 09:51:42Z schwenkel
-! Implementation of new microphysic scheme: cloud_scheme = 'morrison' 
-! includes two more prognostic equations for cloud drop concentration (nc)  
-! and cloud water content (qc). 
-! 
-! 2233 2017-05-30 18:08:54Z suehring
-!
-! 2232 2017-05-30 17:47:52Z suehring
-! Adjustments to new surface concept
-! 
-! 2118 2017-01-17 16:38:49Z raasch
-! OpenACC directives removed
-! 
-! 2011 2016-09-19 17:29:57Z kanani
-! Flag urban_surface is now defined in module control_parameters.
-! 
-! 2007 2016-08-24 15:47:17Z kanani
-! Added swapping of urban surface model quantities,
-! removed redundance for land surface model
-! 
-! 2000 2016-08-20 18:09:15Z knoop
-! Forced header and separation lines into 80 columns
-! 
-! 1960 2016-07-12 16:34:24Z suehring
-! Separate humidity and passive scalar
-!
-! 1822 2016-04-07 07:49:42Z hoffmann
-! icloud_scheme replaced by microphysics_*
-!
-! swap_timelevel.f90 1766 2016-02-29 08:37:15Z raasch
-! setting the swap level for pmc data transfer
-!
-! 1747 2016-02-08 12:25:53Z raasch
-! explicit loops in nopointer case to omit craypointer option of pgi compiler
-!
-! 1682 2015-10-07 23:56:08Z knoop
-! Code annotations made doxygen readable 
-! 
-! 1496 2014-12-02 17:25:50Z maronga
-! Added swapping of land surface model quantities
-! 
-! 1374 2014-04-25 12:55:07Z raasch
-! bugfix: use-statement for nopointer-case added
-! 
-! 1320 2014-03-20 08:40:49Z raasch
-! ONLY-attribute added to USE-statements,
-! revision history before 2012 removed,
-! 1318 2014-03-17 13:35:16Z raasch
-! module interfaces removed
-!
-! 1115 2013-03-26 18:16:16Z hoffmann
-! calculation of qr and nr is restricted to precipitation
-!
-! 1111 2013-03-08 23:54:10Z raasch
-! openACC directives added
-!
-! 1053 2012-11-13 17:11:03Z hoffmann
-! swap of timelevels for nr, qr added
-!
-! 1036 2012-10-22 13:43:42Z raasch
-! code put under GPL (PALM 3.9)
-!
-! 1032 2012-10-21 13:03:21Z letzel
-! save memory by not allocating pt_2 in case of neutral = .T.
-!
-! 1010 2012-09-20 07:59:54Z raasch
-! cpp switch __nopointer added for pointer free version
-!
-! 1001 2012-09-13 14:08:46Z raasch
-! all actions concerning leapfrog scheme removed
-!
-! Revision 1.1  2000/01/10  10:08:58  10:08:58  raasch (Siegfried Raasch)
-! Initial revision
-! 
-!
-! Description:
-! ------------
-!> Swap of timelevels of variables after each timestep
-!------------------------------------------------------------------------------!
- SUBROUTINE swap_timelevel
- 
-
-    USE arrays_3d,                                                                                 &
-        ONLY:  pt, pt_1, pt_2, pt_p, q, q_1, q_2, q_p, s, s_1, s_2, s_p, u, u_1, u_2, u_p, v, v_1, &
-               v_2, v_p, w, w_1, w_2, w_p
-
-    USE cpulog,                                                                                    &
-        ONLY: cpu_log, log_point
-
-    USE control_parameters,                                                                        &
-        ONLY:  humidity, neutral, passive_scalar, timestep_count
-
-    USE kinds
-
-    USE module_interface,                                                                          &
-        ONLY:  module_interface_swap_timelevel
-
-    USE pmc_interface,                                                                             &
-        ONLY: nested_run, pmci_set_swaplevel
-
-    USE turbulence_closure_mod,                                                                    &
-        ONLY:  tcm_swap_timelevel
-
-
-    IMPLICIT NONE
-
-    INTEGER(iwp) ::  swap_level  !> swap_level for steering the pmc data transfer
-
-!
-!-- Incrementing timestep counter
-    timestep_count = timestep_count + 1
-
-!
-!-- Swap of variables
-    CALL cpu_log( log_point(28), 'swap_timelevel', 'start' )
-
-    SELECT CASE ( MOD( timestep_count, 2 ) )
-
-       CASE ( 0 )
-
-          u  => u_1;   u_p  => u_2
-          v  => v_1;   v_p  => v_2
-          w  => w_1;   w_p  => w_2
-          IF ( .NOT. neutral )  THEN
-             pt => pt_1;  pt_p => pt_2
-          ENDIF
-          IF ( humidity )  THEN
-             q => q_1;    q_p => q_2
-          ENDIF
-          IF ( passive_scalar )  THEN
-             s => s_1;    s_p => s_2
-          ENDIF
-
-          swap_level = 1
-
-       CASE ( 1 )
-
-          u  => u_2;   u_p  => u_1
-          v  => v_2;   v_p  => v_1
-          w  => w_2;   w_p  => w_1
-          IF ( .NOT. neutral )  THEN
-             pt => pt_2;  pt_p => pt_1
-          ENDIF
-          IF ( humidity )  THEN
-             q => q_2;    q_p => q_1
-          ENDIF
-          IF ( passive_scalar )  THEN
-             s => s_2;    s_p => s_1
-          ENDIF
-
-          swap_level = 2
-
-    END SELECT
-
-!
-!-- Set the swap level the turbulence closure module
-    CALL tcm_swap_timelevel( MOD( timestep_count, 2) )
-
-!
-!-- Set the swap level for all other modules
-    CALL module_interface_swap_timelevel( MOD( timestep_count, 2) )
-
-!
-!-- Set the swap level for steering the pmc data transfer
-    IF ( nested_run )  CALL pmci_set_swaplevel( swap_level )
-
-    CALL cpu_log( log_point(28), 'swap_timelevel', 'stop' )
-
- END SUBROUTINE swap_timelevel
-
-
Index: /palm/trunk/SOURCE/time_integration.f90
===================================================================
--- /palm/trunk/SOURCE/time_integration.f90	(revision 4046)
+++ /palm/trunk/SOURCE/time_integration.f90	(revision 4047)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Added remainings of swap_timelevel upon its dissolution
+! 
+! 4043 2019-06-18 16:59:00Z schwenkel
 ! Further LPM modularization
 !
@@ -575,5 +578,5 @@
                turbulent_inflow, turbulent_outflow, urban_surface,                                 &
                use_initial_profile_as_reference, use_single_reference_value, u_gtrans, v_gtrans,   &
-               virtual_flight, virtual_measurement, ws_scheme_mom, ws_scheme_sca
+               virtual_flight, virtual_measurement, ws_scheme_mom, ws_scheme_sca, timestep_count
 
     USE cpulog,                                                                                    &
@@ -610,5 +613,5 @@
 
     USE module_interface,                                                                          &
-        ONLY:  module_interface_actions
+        ONLY:  module_interface_actions, module_interface_swap_timelevel
 
     USE multi_agent_system_mod,                                                                    &
@@ -631,5 +634,6 @@
     USE pmc_interface,                                                                             &
         ONLY:  nested_run, nesting_mode, pmci_boundary_conds, pmci_datatrans, pmci_synchronize,    &
-        pmci_ensure_nest_mass_conservation, pmci_ensure_nest_mass_conservation_vertical
+        pmci_ensure_nest_mass_conservation, pmci_ensure_nest_mass_conservation_vertical,           &
+        pmci_set_swaplevel
 
     USE progress_bar,                                                                              &
@@ -1135,6 +1139,16 @@
 
 !
-!--       Swap the time levels in preparation for the next time step.
-          CALL swap_timelevel
+!--       Incrementing timestep counter
+          timestep_count = timestep_count + 1
+
+          CALL cpu_log( log_point(28), 'swap_timelevel', 'start' )
+!
+!--       Set the swap level for all modules
+          CALL module_interface_swap_timelevel( MOD( timestep_count, 2) )
+!
+!--       Set the swap level for steering the pmc data transfer
+          IF ( nested_run )  CALL pmci_set_swaplevel( MOD( timestep_count, 2) + 1 )  !> @todo: why the +1 ?
+
+          CALL cpu_log( log_point(28), 'swap_timelevel', 'stop' )
 
 !
