Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 3636)
+++ palm/trunk/SOURCE/Makefile	(revision 3637)
@@ -25,4 +25,7 @@
 # -----------------
 # $Id$
+# Implementation of the PALM module interface
+# 
+# 3634 2018-12-18 12:31:28Z knoop
 # OpenACC port for SPEC
 # 
@@ -623,4 +626,5 @@
 	bulk_cloud_model_mod.f90 \
 	model_1d_mod.f90 \
+	module_interface.f90 \
 	mod_kinds.f90 \
 	mod_particle_attributes.f90 \
@@ -785,18 +789,10 @@
 	modules.o
 average_3d_data.o: \
-	biometeorology_mod.o \
-	bulk_cloud_model_mod.o \
-	chemistry_model_mod.o \
 	cpulog_mod.o \
 	exchange_horiz_2d.o \
-	gust_mod.o \
-	land_surface_model_mod.o \
-	mod_kinds.o \
-	modules.o \
-	ocean_mod.o \
-	radiation_model_mod.o \
-	salsa_mod.o \
-	turbulence_closure_mod.o \
-	urban_surface_mod.o
+	mod_kinds.o \
+	module_interface.o \
+	modules.o \
+	turbulence_closure_mod.o
 basic_constants_and_equations_mod.o: \
 	mod_kinds.o
@@ -843,31 +839,17 @@
 check_parameters.o: \
 	basic_constants_and_equations_mod.o \
-	biometeorology_mod.o \
-	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	chem_emissions_mod.o \
-	gust_mod.o \
 	init_vertical_profiles.o \
-	land_surface_model_mod.o \
-	large_scale_forcing_nudging_mod.o \
 	model_1d_mod.o \
-	mod_kinds.o \
-	modules.o \
-	nesting_offl_mod.o \
+	module_interface.o \
+	mod_kinds.o \
+	modules.o \
 	netcdf_data_input_mod.o \
 	netcdf_interface_mod.o \
-	ocean_mod.o \
-	plant_canopy_model_mod.o \
 	pmc_interface_mod.o \
-	radiation_model_mod.o \
-	salsa_mod.o \
-	spectra_mod.o \
 	subsidence_mod.o \
-	surface_output_mod.o \
-	synthetic_turbulence_generator_mod.o \
 	turbulence_closure_mod.o \
-	urban_surface_mod.o \
-	vertical_nesting_mod.o \
-	wind_turbine_model_mod.o
+	vertical_nesting_mod.o
 chem_emissions_mod.o: \
 	chem_gasphase_mod.o \
@@ -978,33 +960,25 @@
 data_output_2d.o: \
 	basic_constants_and_equations_mod.o \
-	biometeorology_mod.o \
-	bulk_cloud_model_mod.o \
-	chemistry_model_mod.o\
-	cpulog_mod.o \
-	gust_mod.o \
+	bulk_cloud_model_mod.o \
+	cpulog_mod.o \
 	land_surface_model_mod.o \
 	mod_kinds.o \
 	mod_particle_attributes.o \
-	modules.o \
-	netcdf_interface_mod.o \
-	ocean_mod.o \
-	radiation_model_mod.o \
-	salsa_mod.o \
+	module_interface.o \
+	modules.o \
+	netcdf_interface_mod.o \
 	surface_mod.o \
 	urban_surface_mod.o
 data_output_3d.o: \
 	basic_constants_and_equations_mod.o \
-	biometeorology_mod.o \
-	bulk_cloud_model_mod.o \
-	chemistry_model_mod.o \
-	cpulog_mod.o \
-	gust_mod.o \
+	bulk_cloud_model_mod.o \
+	cpulog_mod.o \
 	land_surface_model_mod.o \
 	mod_kinds.o \
 	mod_particle_attributes.o \
-	modules.o \
-	netcdf_interface_mod.o \
-	ocean_mod.o \
-	salsa_mod.o \
+	module_interface.o \
+	modules.o \
+	netcdf_interface_mod.o \
+	radiation_model_mod.o \
 	turbulence_closure_mod.o \
 	urban_surface_mod.o
@@ -1058,10 +1032,10 @@
 	basic_constants_and_equations_mod.o \
 	bulk_cloud_model_mod.o \
-	chemistry_model_mod.o \
-	cpulog_mod.o \
-	gust_mod.o \
+	chem_modules.o \
+	cpulog_mod.o \
 	land_surface_model_mod.o \
 	large_scale_forcing_nudging_mod.o \
 	mod_kinds.o \
+	module_interface.o \
 	modules.o \
 	netcdf_interface_mod.o \
@@ -1076,27 +1050,18 @@
 header.o: \
 	basic_constants_and_equations_mod.o \
-	biometeorology_mod.o \
-	bulk_cloud_model_mod.o \
-	chemistry_model_mod.o \
+	bulk_cloud_model_mod.o \
 	cpulog_mod.o \
 	date_and_time_mod.o \
-	gust_mod.o \
-	land_surface_model_mod.o \
-	large_scale_forcing_nudging_mod.o \
 	model_1d_mod.o \
-	mod_kinds.o \
-	modules.o \
-	netcdf_interface_mod.o \
-	nesting_offl_mod.o \
+	module_interface.o \
+	mod_kinds.o \
+	modules.o \
+	netcdf_interface_mod.o \
 	ocean_mod.o \
 	plant_canopy_model_mod.o \
 	pmc_handle_communicator_mod.o \
 	pmc_interface_mod.o \
-	radiation_model_mod.o \
-	salsa_mod.o \
-	spectra_mod.o \
 	subsidence_mod.o \
-	surface_mod.o \
-	virtual_flight_mod.o
+	surface_mod.o
 indoor_model_mod.o: \
 	cpulog_mod.o \
@@ -1355,4 +1320,29 @@
 	modules.o \
 	time_to_string.o
+module_interface.o: \
+	mod_kinds.o \
+	modules.o \
+	biometeorology_mod.o \
+	bulk_cloud_model_mod.o \
+	chemistry_model_mod.o \
+	gust_mod.o \
+	indoor_model_mod.o \
+	land_surface_model_mod.o \
+	large_scale_forcing_nudging_mod.o \
+	multi_agent_system_mod.o \
+	nesting_offl_mod.o \
+	ocean_mod.o \
+	plant_canopy_model_mod.o \
+	radiation_model_mod.o \
+	salsa_mod.o \
+	spectra_mod.o \
+	surface_output_mod.o \
+	synthetic_turbulence_generator_mod.o \
+	urban_surface_mod.o \
+	user_read_restart_data_mod.o \
+	user_write_restart_data_mod.o \
+	virtual_flight_mod.o \
+	virtual_measurement_mod.o \
+	wind_turbine_model_mod.o
 modules.o: \
 	mod_kinds.o
@@ -1436,34 +1426,16 @@
 	write_restart_data_mod.o
 parin.o: \
-	biometeorology_mod.o \
-	bulk_cloud_model_mod.o \
-	chemistry_model_mod.o \
 	chem_modules.o \
 	cpulog_mod.o \
 	date_and_time_mod.o \
-	gust_mod.o \
-	indoor_model_mod.o \
-	land_surface_model_mod.o \
 	model_1d_mod.o \
 	mod_kinds.o \
 	modules.o \
-	multi_agent_system_mod.o \
-	nesting_offl_mod.o \
-	netcdf_interface_mod.o \
-	ocean_mod.o \
-	plant_canopy_model_mod.o \
+	netcdf_interface_mod.o \
 	pmc_interface_mod.o \
 	progress_bar_mod.o \
-	radiation_model_mod.o \
 	read_restart_data_mod.o \
-	salsa_mod.o \
-	spectra_mod.o \
-	surface_output_mod.o \
-	synthetic_turbulence_generator_mod.o \
 	turbulence_closure_mod.o \
-	vertical_nesting_mod.o \
-	virtual_flight_mod.o \
-	virtual_measurement_mod.o \
-	wind_turbine_model_mod.o
+	vertical_nesting_mod.o
 plant_canopy_model_mod.o: \
 	bulk_cloud_model_mod.o \
@@ -1601,26 +1573,18 @@
 	modules.o
 read_restart_data_mod.o: \
-	bulk_cloud_model_mod.o \
-	chemistry_model_mod.o \
+	chem_modules.o \
 	cpulog_mod.o \
 	date_and_time_mod.o \
-	gust_mod.o \
-	land_surface_model_mod.o \
-	modules.o \
 	mod_kinds.o \
 	model_1d_mod.o \
+	module_interface.o \
+	modules.o \
 	netcdf_interface_mod.o \
 	radiation_model_mod.o \
 	random_function_mod.o\
 	random_generator_parallel_mod.o \
-	salsa_mod.o \
 	spectra_mod.o \
 	surface_mod.o \
-	synthetic_turbulence_generator_mod.o \
-	urban_surface_mod.o \
-	user_read_restart_data_mod.o \
-	vertical_nesting_mod.o \
-	virtual_flight_mod.o \
-	wind_turbine_model_mod.o
+	vertical_nesting_mod.o
 run_control.o: \
 	cpulog_mod.o \
@@ -1661,14 +1625,9 @@
 sum_up_3d_data.o: \
 	basic_constants_and_equations_mod.o \
-	biometeorology_mod.o \
-	bulk_cloud_model_mod.o \
-	chemistry_model_mod.o \
-	cpulog_mod.o \
-	gust_mod.o \
-	land_surface_model_mod.o \
-	mod_kinds.o \
-	modules.o \
-	radiation_model_mod.o \
-	salsa_mod.o \
+	bulk_cloud_model_mod.o \
+	cpulog_mod.o \
+	mod_kinds.o \
+	module_interface.o \
+	modules.o \
 	surface_mod.o \
 	turbulence_closure_mod.o \
@@ -1700,16 +1659,10 @@
 	surface_mod.o
 swap_timelevel.o: \
-	bulk_cloud_model_mod.o \
-	chemistry_model_mod.o \
-	cpulog_mod.o \
-	gust_mod.o \
-	land_surface_model_mod.o \
-	mod_kinds.o \
-	modules.o \
-	ocean_mod.o \
+	cpulog_mod.o \
+	mod_kinds.o \
+	module_interface.o \
+	modules.o \
 	pmc_interface_mod.o \
-	salsa_mod.o \
-	turbulence_closure_mod.o \
-	urban_surface_mod.o
+	turbulence_closure_mod.o
 synthetic_turbulence_generator_mod.o: \
 	basic_constants_and_equations_mod.o \
@@ -1992,23 +1945,15 @@
 	mod_kinds.o
 write_restart_data_mod.o: \
-	bulk_cloud_model_mod.o \
-	chemistry_model_mod.o \
 	date_and_time_mod.o \
-	gust_mod.o \
-	land_surface_model_mod.o \
 	mod_kinds.o \
 	mod_particle_attributes.o \
 	model_1d_mod.o \
-	modules.o \
-	netcdf_interface_mod.o \
-	ocean_mod.o \
+	module_interface.o \
+	modules.o \
+	netcdf_interface_mod.o \
 	radiation_model_mod.o \
 	random_function_mod.o \
 	random_generator_parallel_mod.o \
-	spectra_mod.o surface_mod.o \
-	synthetic_turbulence_generator_mod.o \
-	urban_surface_mod.o \
-	user_write_restart_data_mod.o \
-	vertical_nesting_mod.o \
-	virtual_flight_mod.o \
-	wind_turbine_model_mod.o
+	spectra_mod.o \
+	surface_mod.o \
+	vertical_nesting_mod.o
Index: palm/trunk/SOURCE/average_3d_data.f90
===================================================================
--- palm/trunk/SOURCE/average_3d_data.f90	(revision 3636)
+++ palm/trunk/SOURCE/average_3d_data.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3597 2018-12-04 08:40:18Z maronga
 ! Added theta_2m
 ! 
@@ -173,23 +176,10 @@
     USE averaging
 
-    USE biometeorology_mod,                                                    &
-        ONLY:  bio_3d_data_averaging
-
-    USE bulk_cloud_model_mod,                                                  &
-        ONLY:  bulk_cloud_model, bcm_3d_data_averaging
-
-    USE chemistry_model_mod,                                                   &
-        ONLY:  chem_3d_data_averaging
-
     USE control_parameters,                                                    &
-        ONLY:  air_chemistry, average_count_3d, biometeorology, doav, doav_n,  &
-               land_surface, ocean_mode, salsa, urban_surface, varnamelength
+        ONLY:  average_count_3d, doav, doav_n, varnamelength
 
     USE cpulog,                                                                &
         ONLY:  cpu_log, log_point
 
-    USE gust_mod,                                                              &
-        ONLY:  gust_3d_data_averaging, gust_module_enabled
-
     USE indices,                                                               &
         ONLY:  nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt
@@ -197,21 +187,9 @@
     USE kinds
 
-    USE land_surface_model_mod,                                                &
-        ONLY:  lsm_3d_data_averaging
-
-    USE ocean_mod,                                                             &
-        ONLY:  ocean_3d_data_averaging
-
-    USE radiation_model_mod,                                                   &
-        ONLY:  radiation, radiation_3d_data_averaging
-           
-    USE salsa_mod,                                                             &
-        ONLY:  salsa_3d_data_averaging 
+    USE module_interface,                                                      &
+        ONLY:  module_interface_3d_data_averaging
 
     USE turbulence_closure_mod,                                                &
         ONLY:  tcm_3d_data_averaging
-
-    USE urban_surface_mod,                                                     &
-        ONLY:  usm_average_3d_data
 
 
@@ -573,48 +551,11 @@
 
           CASE DEFAULT
-!
-!--          Averaging of data from other modules
-             IF ( air_chemistry .AND. &
-                  (trimvar(1:3) == 'kc_' .OR. trimvar(1:3) == 'em_')  )  THEN
-                CALL chem_3d_data_averaging( 'average', doav(ii) )
-             ENDIF
-
-             IF ( bulk_cloud_model )  THEN
-                CALL bcm_3d_data_averaging( 'average', doav(ii) )
-             ENDIF
-
-             IF ( gust_module_enabled )  THEN
-                CALL gust_3d_data_averaging( 'average', doav(ii) )
-             ENDIF
-
-             IF ( land_surface )  THEN
-                CALL lsm_3d_data_averaging( 'average', doav(ii) )
-             ENDIF
-
-             IF ( ocean_mode )  THEN
-                CALL ocean_3d_data_averaging( 'average', doav(ii) )
-             ENDIF
-
-             IF ( radiation )  THEN
-                CALL radiation_3d_data_averaging( 'average', doav(ii) )
-             ENDIF
-             
-             IF ( salsa )  THEN
-                CALL salsa_3d_data_averaging( 'average', doav(ii) )
-             ENDIF             
-
-             IF ( biometeorology )  THEN
-                CALL bio_3d_data_averaging( 'average', doav(ii) )
-             ENDIF
-
-             CALL tcm_3d_data_averaging( 'average', doav(ii) )
-
-             IF ( urban_surface  .AND.  trimvar(1:4) == 'usm_' )  THEN
-                CALL usm_average_3d_data( 'average', doav(ii) )
-             ENDIF
-
-!
-!--          User-defined quantities
-             CALL user_3d_data_averaging( 'average', doav(ii) )
+
+!
+!--          Averaging of data from turbulence closure module
+             CALL tcm_3d_data_averaging( 'average', trimvar )
+!
+!--          Averaging of data from all other modules
+             CALL module_interface_3d_data_averaging( 'average', trimvar )
 
        END SELECT
Index: palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- palm/trunk/SOURCE/check_parameters.f90	(revision 3636)
+++ palm/trunk/SOURCE/check_parameters.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3597 2018-12-04 08:40:18Z maronga
 ! Added checks for theta_2m
 ! 
@@ -748,19 +751,11 @@
     USE basic_constants_and_equations_mod
 
-    USE biometeorology_mod,                                                    &
-        ONLY:  bio_check_data_output, bio_check_parameters
-
     USE bulk_cloud_model_mod,                                                  &
-        ONLY:  bulk_cloud_model, bcm_check_parameters, bcm_check_data_output,  &
-               bcm_check_data_output_pr
-
-    USE chem_emissions_mod,                                                    &
-        ONLY:  chem_emissions_check_parameters
+        ONLY:  bulk_cloud_model
 
     USE chem_modules
 
     USE chemistry_model_mod,                                                   &
-        ONLY:  chem_boundary_conds, chem_check_data_output,                    &
-               chem_check_data_output_pr, chem_check_parameters, chem_species
+        ONLY:  chem_boundary_conds
 
     USE control_parameters
@@ -770,25 +765,16 @@
     USE grid_variables
 
-    USE gust_mod,                                                              &
-        ONLY: gust_check_data_output, gust_check_data_output_pr,               &
-              gust_check_parameters, gust_module_enabled
-
     USE kinds
 
     USE indices
-
-    USE land_surface_model_mod,                                                &
-        ONLY: lsm_check_data_output, lsm_check_data_output_pr,                 &
-              lsm_check_parameters
-
-    USE lsf_nudging_mod,                                                       &
-        ONLY:  lsf_nudging_check_parameters, lsf_nudging_check_data_output_pr
 
     USE model_1d_mod,                                                          &
         ONLY:  damp_level_1d, damp_level_ind_1d
 
-    USE nesting_offl_mod,                                                      &
-        ONLY:  nesting_offl_check_parameters
-        
+    USE module_interface,                                                      &
+        ONLY:  module_interface_check_parameters,                              &
+               module_interface_check_data_output_pr,                          &
+               module_interface_check_data_output
+
     USE netcdf_data_input_mod,                                                 &
         ONLY:  init_model, input_pids_static, netcdf_data_input_check_dynamic, &
@@ -800,14 +786,7 @@
                waterflux_output_unit, momentumflux_output_unit
 
-    USE ocean_mod,                                                             &
-        ONLY:  ocean_check_data_output, ocean_check_data_output_pr,            &
-               ocean_check_parameters
-
     USE particle_attributes
 
     USE pegrid
-
-    USE plant_canopy_model_mod,                                                &
-        ONLY:  pcm_check_data_output, pcm_check_parameters
 
     USE pmc_interface,                                                         &
@@ -816,37 +795,17 @@
     USE profil_parameter
 
-    USE radiation_model_mod,                                                   &
-        ONLY:  radiation, radiation_check_data_output,                         &
-               radiation_check_data_output_pr, radiation_check_parameters
-                            
-    USE salsa_mod,                                                             &
-        ONLY:  salsa_check_data_output, salsa_check_parameters        
-
-    USE spectra_mod,                                                           &
-        ONLY:  calculate_spectra, spectra_check_parameters
-
     USE statistics
 
     USE subsidence_mod
 
-    USE surface_output_mod,                                                    &
-        ONLY:  surface_output_check_parameters
-
-    USE synthetic_turbulence_generator_mod,                                    &
-        ONLY:  stg_check_parameters
-
     USE transpose_indices
 
     USE turbulence_closure_mod,                                                &
-        ONLY:  tcm_check_data_output, tcm_check_parameters
-
-    USE urban_surface_mod,                                                     &
-        ONLY:  usm_check_data_output, usm_check_parameters
-
-    USE wind_turbine_model_mod,                                                &
-        ONLY:  wtm_check_parameters
+        ONLY:  tcm_check_parameters,                                           &
+               tcm_check_data_output
 
     USE vertical_nesting_mod,                                                  &
-        ONLY:  vnested, vnest_check_parameters
+        ONLY:  vnested,                                                        &
+               vnest_check_parameters
 
 
@@ -1525,30 +1484,9 @@
 
 !
-!-- Check the module settings:
-!-- tcm_check_parameters must be called at first
+!-- tcm_check_parameters must be called before all other module calls
     CALL tcm_check_parameters
 
-    IF ( biometeorology )       CALL bio_check_parameters
-    IF ( bulk_cloud_model )     CALL bcm_check_parameters
-    IF ( air_chemistry )        CALL chem_check_parameters
-!   IF ( air_chemistry )        CALL chem_emissions_check_parameters   ! forkel preliminary
-    IF ( gust_module_enabled )  CALL gust_check_parameters
-    IF ( large_scale_forcing  .OR.  nudging )                                  &
-                                CALL lsf_nudging_check_parameters
-    IF ( land_surface )         CALL lsm_check_parameters
-    IF ( nesting_offline )      CALL nesting_offl_check_parameters    
-    IF ( ocean_mode )           CALL ocean_check_parameters
-    IF ( plant_canopy )         CALL pcm_check_parameters
-    IF ( radiation )            CALL radiation_check_parameters
-    IF ( calculate_spectra )    CALL spectra_check_parameters
-                                CALL stg_check_parameters
-    IF ( urban_surface )        CALL usm_check_parameters
-    IF ( wind_turbine )         CALL wtm_check_parameters
-!
-!-- Checks for surface data output
-    IF ( surface_data_output )  CALL surface_output_check_parameters
-!    
-!-- When SALSA is used, perform additional checks 
-    IF ( salsa )  CALL salsa_check_parameters     
+!-- Check the module settings
+    CALL module_interface_check_parameters
 
 !
@@ -1562,14 +1500,5 @@
        IF ( humidity       )  q_init  = q_surface
        IF ( passive_scalar )  s_init  = s_surface
-!
-!--    TODO
-!--    Russo: Is done in chem_init and would overwrite what is done there
-!--    --> kanani: Revise
-!      IF ( air_chemistry )  THEN
-!        DO lsp = 1, nvar
-!           chem_species(lsp)%conc_pr_init = cs_surface(lsp)      
-!        ENDDO
-!      ENDIF
-!
+
 !--
 !--    If required, compute initial profile of the geostrophic wind
@@ -2960,44 +2889,6 @@
 !
 !--          Check for other modules
-             IF ( unit == 'illegal' .AND.  bulk_cloud_model )  THEN
-                CALL bcm_check_data_output_pr( data_output_pr(i), i, unit,     &
-                                               dopr_unit(i) )
-             ENDIF
-
-             IF ( unit == 'illegal' .AND.  air_chemistry )  THEN
-                CALL chem_check_data_output_pr( data_output_pr(i), i, unit,    &
-                                                dopr_unit(i) )
-             ENDIF
-
-             IF ( unit == 'illegal'  .AND.  gust_module_enabled  )  THEN
-                CALL gust_check_data_output_pr( data_output_pr(i), i, unit,    &
-                                                dopr_unit(i) )
-             ENDIF
-
-             IF ( unit == 'illegal' )  THEN
-                CALL lsf_nudging_check_data_output_pr( data_output_pr(i), i,   &
-                                                       unit, dopr_unit(i) )
-             ENDIF
-
-             IF ( unit == 'illegal' )  THEN
-                CALL lsm_check_data_output_pr( data_output_pr(i), i, unit,        &
-                                            dopr_unit(i) )
-             ENDIF
-             IF ( unit == 'illegal' )  THEN
-                CALL ocean_check_data_output_pr( data_output_pr(i), i, unit,   &
-                                                 dopr_unit(i) )
-             ENDIF
-
-             IF ( unit == 'illegal' )  THEN
-                CALL radiation_check_data_output_pr( data_output_pr(i), i,     &
-                                                     unit, dopr_unit(i) )
-             ENDIF
-
-!
-!--          Finally, check for user defined quantities
-             IF ( unit == 'illegal' )  THEN
-                unit = ''
-                CALL user_check_data_output_pr( data_output_pr(i), i, unit )
-             ENDIF
+             CALL module_interface_check_data_output_pr( data_output_pr(i), i, &
+                                                         unit, dopr_unit(i) )
 
 !
@@ -3224,55 +3115,7 @@
 
              CALL tcm_check_data_output( var, unit )
-
 !
 !--          Check for other modules
-             IF ( unit == 'illegal'  .AND.  bulk_cloud_model  )  THEN
-                CALL bcm_check_data_output( var, unit )
-             ENDIF
-
-             IF ( unit == 'illegal'  .AND.  air_chemistry                      &
-                  .AND.  (var(1:3) == 'kc_' .OR. var(1:3) == 'em_') )  THEN
-                CALL chem_check_data_output( var, unit, i, ilen, k )
-             ENDIF
-
-             IF ( unit == 'illegal' )  THEN
-                CALL lsm_check_data_output ( var, unit, i, ilen, k )
-             ENDIF
-
-             IF ( unit == 'illegal'  .AND.  gust_module_enabled  )  THEN
-                CALL gust_check_data_output ( var, unit )
-             ENDIF
-
-             IF ( unit == 'illegal'  .AND.  biometeorology )  THEN
-                CALL bio_check_data_output( var, unit, i, ilen, k )
-             ENDIF
-
-             IF ( unit == 'illegal'  .AND.  ocean_mode )  THEN
-                CALL ocean_check_data_output( var, unit )
-             ENDIF
-
-             IF ( unit == 'illegal'  .AND.  plant_canopy                       &
-                                     .AND.  var(1:4) == 'pcm_' )  THEN
-                CALL pcm_check_data_output( var, unit )
-             ENDIF
-
-             IF ( unit == 'illegal' )  THEN
-                CALL radiation_check_data_output( var, unit, i, ilen, k )
-             ENDIF
-
-             IF ( unit == 'illegal' .AND. salsa ) THEN
-                 CALL salsa_check_data_output( var, unit )
-             ENDIF   
-
-             IF ( unit == 'illegal'  .AND.  urban_surface                      &
-                                     .AND.  var(1:4) == 'usm_' )  THEN
-                 CALL usm_check_data_output( var, unit )
-             ENDIF
-!
-!--          Finally, check for user-defined quantities
-             IF ( unit == 'illegal' )  THEN
-                unit = ''
-                CALL user_check_data_output( var, unit )
-             ENDIF
+             CALL module_interface_check_data_output( var, unit, i, ilen, k )
 
              IF ( unit == 'illegal' )  THEN
@@ -3986,7 +3829,4 @@
 
     CALL location_message( 'finished', .TRUE. )
-!
-!-- Check &userpar parameters
-    CALL user_check_parameters
 
  CONTAINS
Index: palm/trunk/SOURCE/chemistry_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3636)
+++ palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3637)
@@ -27,4 +27,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3636 2018-12-19 13:48:34Z raasch
 ! nopointer option removed
 !
@@ -588,4 +591,5 @@
     INTEGER(iwp) :: lsp                 !< running index for chem spcs
 
+    IF ( (variable(1:3) == 'kc_' .OR. variable(1:3) == 'em_')  )  THEN
 
     IF ( mode == 'allocate' )  THEN
@@ -662,4 +666,6 @@
           ENDIF
        ENDDO
+
+    ENDIF
 
     ENDIF
Index: palm/trunk/SOURCE/data_output_2d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_2d.f90	(revision 3636)
+++ palm/trunk/SOURCE/data_output_2d.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3597 2018-12-04 08:40:18Z maronga
 ! Added theta_2m
 ! 
@@ -284,29 +287,20 @@
         ONLY:  c_p, lv_d_cp, l_v
 
-    USE biometeorology_mod,                                                    &
-        ONLY:  bio_data_output_2d
-
     USE bulk_cloud_model_mod,                                                  &
-        ONLY:  bulk_cloud_model, bcm_data_output_2d
-
-    USE chemistry_model_mod,                                                   &
-        ONLY:  chem_data_output_2d
+        ONLY:  bulk_cloud_model
 
     USE control_parameters,                                                    &
-        ONLY:  air_chemistry, biometeorology, data_output_2d_on_each_pe,       &
+        ONLY:  data_output_2d_on_each_pe,                                      &
                data_output_xy, data_output_xz, data_output_yz, do2d,           &
                do2d_xy_last_time, do2d_xy_time_count,                          &
                do2d_xz_last_time, do2d_xz_time_count,                          &
                do2d_yz_last_time, do2d_yz_time_count,                          &
-               ibc_uv_b, io_blocks, io_group, land_surface, message_string,    &
+               ibc_uv_b, io_blocks, io_group, message_string,                  &
                ntdim_2d_xy, ntdim_2d_xz, ntdim_2d_yz,                          &
-               ocean_mode, psolver, salsa, section, simulated_time,            &
+               psolver, section, simulated_time,                               &
                time_since_reference_point
 
     USE cpulog,                                                                &
-        ONLY:  cpu_log, log_point 
-        
-    USE gust_mod,                                                              &
-        ONLY:  gust_data_output_2d, gust_module_enabled
+        ONLY:  cpu_log, log_point
 
     USE indices,                                                               &
@@ -317,5 +311,8 @@
 
     USE land_surface_model_mod,                                                &
-        ONLY:  lsm_data_output_2d, zs
+        ONLY:  zs
+
+    USE module_interface,                                                      &
+        ONLY:  module_interface_data_output_2d
 
 #if defined( __netcdf )
@@ -327,7 +324,4 @@
                id_var_time_xy, id_var_time_xz, id_var_time_yz, nc_stat,        &
                netcdf_data_format, netcdf_handle_error
-
-    USE ocean_mod,                                                             &
-        ONLY:  ocean_data_output_2d
 
     USE particle_attributes,                                                   &
@@ -336,10 +330,4 @@
     
     USE pegrid
-
-    USE radiation_model_mod,                                                   &
-        ONLY:  radiation, radiation_data_output_2d
-   
-    USE salsa_mod,                                                             &
-        ONLY:  salsa_data_output_2d    
 
     USE surface_mod,                                                           &
@@ -1362,50 +1350,10 @@
 !
 !--             Quantities of other modules
-                IF ( .NOT. found  .AND.  bulk_cloud_model )  THEN
-                   CALL bcm_data_output_2d( av, do2d(av,ivar), found, grid, mode,&
-                                            local_pf, two_d, nzb_do, nzt_do )
-                ENDIF
-
-                IF ( .NOT. found  .AND.  gust_module_enabled )  THEN
-                   CALL gust_data_output_2d( av, do2d(av,ivar), found, grid,     &
-                                             local_pf, two_d, nzb_do, nzt_do )
-                ENDIF
-
-                IF ( .NOT. found  .AND.  biometeorology )  THEN
-                   CALL bio_data_output_2d( av, do2d(av,ivar), found, grid,      &
-                                            local_pf, two_d, nzb_do, nzt_do )
-                ENDIF
-
-                IF ( .NOT. found  .AND.  land_surface )  THEN
-                   CALL lsm_data_output_2d( av, do2d(av,ivar), found, grid, mode,&
-                                            local_pf, two_d, nzb_do, nzt_do )
-                ENDIF
-
-                IF ( .NOT. found  .AND.  ocean_mode )  THEN
-                   CALL ocean_data_output_2d( av, do2d(av,ivar), found, grid,    &
-                                              mode, local_pf, nzb_do, nzt_do )
-                ENDIF
-
-                IF ( .NOT. found  .AND.  radiation )  THEN
-                   CALL radiation_data_output_2d( av, do2d(av,ivar), found, grid,&
-                                                  mode, local_pf, two_d,       &
-                                                  nzb_do, nzt_do  )
-                ENDIF
-                
-                IF ( .NOT. found  .AND.  salsa )  THEN
-                   CALL salsa_data_output_2d( av, do2d(av,ivar), found, grid,  &
-                                              mode, local_pf, two_d, nzb_do,   &
-                                              nzt_do)
-                ENDIF                 
-
-                IF ( .NOT. found  .AND.  air_chemistry )  THEN
-                   CALL chem_data_output_2d( av, do2d(av,ivar), found, grid, mode, &
-                                             local_pf, two_d, nzb_do, nzt_do, fill_value )
-                ENDIF
-!
-!--             User defined quantities
                 IF ( .NOT. found )  THEN
-                   CALL user_data_output_2d( av, do2d(av,ivar), found, grid,     &
-                                             local_pf, two_d, nzb_do, nzt_do )
+                   CALL module_interface_data_output_2d(                       &
+                           av, do2d(av,ivar), found, grid, mode,               &
+                           local_pf, two_d, nzb_do, nzt_do,                    &
+                           fill_value                                          &
+                        )
                 ENDIF
 
Index: palm/trunk/SOURCE/data_output_3d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_3d.f90	(revision 3636)
+++ palm/trunk/SOURCE/data_output_3d.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3589 2018-11-30 15:09:51Z suehring
 ! Move the control parameter "salsa" from salsa_mod to control_parameters 
 ! (M. Kurppa)
@@ -245,12 +248,6 @@
         ONLY:  lv_d_cp
 
-    USE biometeorology_mod,                                                    &
-        ONLY:  bio_data_output_3d
-
     USE bulk_cloud_model_mod,                                                  &
-        ONLY:  bulk_cloud_model, bcm_data_output_3d
-
-    USE chemistry_model_mod,                                                   &
-        ONLY:  chem_data_output_3d
+        ONLY:  bulk_cloud_model
 
     USE control_parameters,                                                    &
@@ -263,7 +260,4 @@
     USE cpulog,                                                                &
         ONLY:  log_point, cpu_log
-
-    USE gust_mod,                                                              &
-        ONLY: gust_data_output_3d, gust_module_enabled
 
 #if defined( __parallel )
@@ -282,4 +276,7 @@
         ONLY: lsm_data_output_3d, nzb_soil, nzt_soil
 
+    USE module_interface,                                                      &
+        ONLY:  module_interface_data_output_3d
+
 #if defined( __netcdf )
     USE NETCDF
@@ -289,22 +286,13 @@
         ONLY:  fill_value, id_set_3d, id_var_do3d, id_var_time_3d, nc_stat,    &
                netcdf_data_format, netcdf_handle_error
-        
-    USE ocean_mod,                                                             &
-        ONLY:  ocean_data_output_3d
 
     USE particle_attributes,                                                   &
         ONLY:  grid_particles, number_of_particles, particles,                 &
                particle_advection_start, prt_count
-        
+
     USE pegrid
 
-    USE plant_canopy_model_mod,                                                &
-        ONLY:  pcm_data_output_3d
-        
     USE radiation_model_mod,                                                   &
-        ONLY:  nzub, nzut, radiation, radiation_data_output_3d
-               
-    USE salsa_mod,                                                             &
-        ONLY:  salsa_data_output_3d     
+        ONLY:  nzub, nzut
 
     USE turbulence_closure_mod,                                                &
@@ -399,22 +387,15 @@
 
 !
-!--    Temporary solution to account for data output within the new urban 
+!--    Initiate found flag and resorting flag
+       found = .FALSE.
+       resorted = .FALSE.
+!
+!--    Temporary solution to account for data output within the new urban
 !--    surface model (urban_surface_mod.f90), see also SELECT CASE ( trimvar ).
 !--    Store the array chosen on the temporary array.
+       nzb_do   = nzb
+       nzt_do   = nz_do3d
+
        trimvar = TRIM( do3d(av,ivar) )
-       IF ( urban_surface  .AND.  trimvar(1:4) == 'usm_' )  THEN
-          trimvar = 'usm_output'
-          resorted = .TRUE.
-          nzb_do   = nzub
-          nzt_do   = nzut
-       ELSE
-          resorted = .FALSE.
-          nzb_do   = nzb
-          nzt_do   = nz_do3d
-       ENDIF
-!
-!--    Set flag to steer output of radiation, land-surface, or user-defined
-!--    quantities
-       found = .FALSE.
 !
 !--    Allocate a temporary array with the desired output dimensions.
@@ -715,37 +696,29 @@
                 to_be_resorted => w_av
              ENDIF
-!             
-!--       Block of urban surface model outputs   
-          CASE ( 'usm_output' )
-             CALL usm_data_output_3d( av, do3d(av,ivar), found, local_pf,        &
-                                         nzb_do, nzt_do )
 
           CASE DEFAULT
 
-!
-!--          Quantities of other modules
-             IF ( .NOT. found  .AND.  bulk_cloud_model )  THEN
-                CALL bcm_data_output_3d( av, do3d(av,ivar), found, local_pf,     &
+             IF ( .NOT. found )  THEN
+                CALL tcm_data_output_3d( av, trimvar, found, local_pf,   &
                                          nzb_do, nzt_do )
                 resorted = .TRUE.
              ENDIF
 
-             IF ( .NOT. found  .AND.  air_chemistry )  THEN
-                CALL chem_data_output_3d( av, do3d(av,ivar), 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, do3d(av,ivar), found, local_pf,    &
-                                          nzb_do, nzt_do )
-                resorted = .TRUE.
-             ENDIF
-
-             IF ( .NOT. found  .AND.  land_surface )  THEN
-!
-!--             For soil model quantities, it is required to re-allocate local_pf
-                nzb_do = nzb_soil
-                nzt_do = nzt_soil
+!
+!--          Quantities of other modules
+             IF ( .NOT. found )  THEN
+                CALL module_interface_data_output_3d(                          &
+                        av, trimvar, found, local_pf,                          &
+                        fill_value, resorted, nzb_do, nzt_do                   &
+                     )
+             ENDIF
+
+!
+!--          Temporary workaround: ToDo: refactor local_pf allocation
+             IF ( .NOT. found  .AND.  urban_surface  .AND.  trimvar(1:4) == 'usm_' )  THEN
+!
+!--             For urban model quantities, it is required to re-allocate local_pf
+                nzb_do = nzub
+                nzt_do = nzut
 
                 DEALLOCATE ( local_pf )
@@ -753,5 +726,6 @@
                 local_pf = fill_value
 
-                CALL lsm_data_output_3d( av, do3d(av,ivar), found, local_pf )
+                CALL usm_data_output_3d( av, trimvar, found, local_pf,         &
+                                         nzb_do, nzt_do )
                 resorted = .TRUE.
 
@@ -763,52 +737,34 @@
 
                    DEALLOCATE ( local_pf )
-                   ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )                 
-                ENDIF
-
-             ENDIF
-
-             IF ( .NOT. found  .AND.  ocean_mode )  THEN
-                CALL ocean_data_output_3d( av, do3d(av,ivar), found, local_pf,   &
-                                           nzb_do, nzt_do )
+                   ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
+                ENDIF
+
+             ENDIF
+
+!
+!--          Temporary workaround: ToDo: refactor local_pf allocation
+             IF ( .NOT. found  .AND.  land_surface )  THEN
+!
+!--             For soil model quantities, it is required to re-allocate local_pf
+                nzb_do = nzb_soil
+                nzt_do = nzt_soil
+
+                DEALLOCATE ( local_pf )
+                ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
+                local_pf = fill_value
+
+                CALL lsm_data_output_3d( av, trimvar, found, local_pf )
                 resorted = .TRUE.
-             ENDIF
-
-             IF ( .NOT. found  .AND.  plant_canopy )  THEN
-                CALL pcm_data_output_3d( av, do3d(av,ivar), found, local_pf,     &
-                                         fill_value, nzb_do, nzt_do )
-                resorted = .TRUE.
-             ENDIF
-
-             IF ( .NOT. found  .AND.  radiation )  THEN
-                CALL radiation_data_output_3d( av, do3d(av,ivar), found,         &
-                                               local_pf, nzb_do, nzt_do )
-                resorted = .TRUE.
-             ENDIF
-
-             IF ( .NOT. found )  THEN
-                CALL tcm_data_output_3d( av, do3d(av,ivar), found, local_pf,     &
-                                         nzb_do, nzt_do )
-                resorted = .TRUE.
-             ENDIF
-             
-!
-!--          SALSA output
-             IF ( .NOT. found  .AND.  salsa )  THEN
-                CALL salsa_data_output_3d( av, do3d(av,ivar), found, local_pf, &
-                                           nzb_do, nzt_do )
-                resorted = .TRUE.
-             ENDIF                  
-
-             IF ( .NOT. found  .AND.  biometeorology )  THEN
-                 CALL bio_data_output_3d( av, do3d(av,ivar), found, local_pf,    &
-                                          nzb_do, nzt_do )
-             ENDIF
-
-!
-!--          User defined quantities
-             IF ( .NOT. found )  THEN
-                CALL user_data_output_3d( av, do3d(av,ivar), found, local_pf,    &
-                                          nzb_do, nzt_do )
-                resorted = .TRUE.
+
+!
+!--             If no soil model variable was found, re-allocate local_pf
+                IF ( .NOT. found )  THEN
+                   nzb_do = nzb
+                   nzt_do = nz_do3d
+
+                   DEALLOCATE ( local_pf )
+                   ALLOCATE( local_pf(nxl:nxr,nys:nyn,nzb_do:nzt_do) )
+                ENDIF
+
              ENDIF
 
Index: palm/trunk/SOURCE/flow_statistics.f90
===================================================================
--- palm/trunk/SOURCE/flow_statistics.f90	(revision 3636)
+++ palm/trunk/SOURCE/flow_statistics.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3458 2018-10-30 14:51:23Z kanani
 ! from chemistry branch r3443, basit:
 ! bug fixed in chemistry profiles
@@ -309,10 +312,9 @@
         ONLY:  g, lv_d_cp
 
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
 
     USE chem_modules,                                                          &
         ONLY:  max_pr_cs
-
-    USE chemistry_model_mod,                                                   &
-        ONLY:  chem_species, chem_statistics
 
     USE control_parameters,                                                    &
@@ -330,7 +332,4 @@
     USE grid_variables,                                                        &
         ONLY:   ddx, ddy
-
-    USE gust_mod,                                                              &
-        ONLY:  gust_module_enabled, gust_statistics
         
     USE indices,                                                               &
@@ -340,7 +339,4 @@
         
     USE kinds
-
-    USE bulk_cloud_model_mod,                                                  &
-        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
     
     USE land_surface_model_mod,                                                &
@@ -349,4 +345,7 @@
     USE lsf_nudging_mod,                                                       &
         ONLY:   td_lsa_lpt, td_lsa_q, td_sub_lpt, td_sub_q, time_vert
+
+    USE module_interface,                                                      &
+        ONLY:  module_interface_statistics
 
     USE netcdf_interface,                                                      &
@@ -1795,18 +1794,8 @@
           ENDDO
        ENDIF
-!
-!--    Calculate the gust module profiles
-       IF ( gust_module_enabled )  THEN
-          CALL gust_statistics( 'profiles', sr, tn, dots_max )
-       ENDIF
-!
-!--    Calculate the chemistry module profiles
-       IF ( air_chemistry ) THEN
-          CALL chem_statistics( 'profiles', sr, tn )
-       ENDIF
-!
-!--    Calculate the user-defined profiles
-       CALL user_statistics( 'profiles', sr, tn )
-       !$OMP END PARALLEL
+
+!
+!--    Calculate the profiles for all other modules
+       CALL module_interface_statistics( 'profiles', sr, tn, dots_max )
 
 !
@@ -2268,12 +2257,6 @@
 
 !
-!--    Calculate additional statistics provided by the gust module
-       IF ( gust_module_enabled )  THEN
-          CALL gust_statistics( 'time_series', sr, 0, dots_max )
-       ENDIF
-
-!
-!--    Calculate additional statistics provided by the user interface
-       CALL user_statistics( 'time_series', sr, 0 )
+!--    Calculate additional statistics provided by other modules
+       CALL module_interface_statistics( 'time_series', sr, 0, dots_max )
 
     ENDDO    ! loop of the subregions
Index: palm/trunk/SOURCE/header.f90
===================================================================
--- palm/trunk/SOURCE/header.f90	(revision 3636)
+++ palm/trunk/SOURCE/header.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3589 2018-11-30 15:09:51Z suehring
 ! Move the control parameter "salsa" from salsa_mod to control_parameters 
 ! (M. Kurppa)
@@ -420,12 +423,6 @@
         ONLY:  g, kappa, l_v
 
-    USE biometeorology_mod,                                                    &
-        ONLY:  bio_header
-
     USE bulk_cloud_model_mod,                                                  &
-        ONLY:  bulk_cloud_model, bcm_header
-
-    USE chemistry_model_mod,                                                   &
-        ONLY:  chem_header
+        ONLY:  bulk_cloud_model
 
     USE control_parameters
@@ -439,37 +436,25 @@
     USE dvrp_variables,                                                        &
         ONLY:  use_seperate_pe_for_dvrp_output
-        
-    USE flight_mod,                                                            &
-        ONLY:  flight_header
-        
+
     USE grid_variables,                                                        &
         ONLY:  dx, dy
-
-    USE gust_mod,                                                              &
-        ONLY: gust_header, gust_module_enabled
 
     USE indices,                                                               &
         ONLY:  mg_loc_ind, nnx, nny, nnz, nx, ny, nxl_mg, nxr_mg, nyn_mg,      &
                nys_mg, nzt, nzt_mg
-        
+
     USE kinds
- 
-    USE land_surface_model_mod,                                                &
-        ONLY: lsm_header
-
-    USE lsf_nudging_mod,                                                       &
-        ONLY:  lsf_nudging_header
 
     USE model_1d_mod,                                                          &
         ONLY:  damp_level_ind_1d, dt_pr_1d, dt_run_control_1d, end_time_1d
 
+    USE module_interface,                                                      &
+        ONLY:  module_interface_header
+
     USE netcdf_interface,                                                      &
         ONLY:  netcdf_data_format, netcdf_data_format_string, netcdf_deflate
 
-    USE nesting_offl_mod,                                                      &
-        ONLY:  nesting_offl_header
-
     USE ocean_mod,                                                             &
-        ONLY:  ibc_sa_t, ocean_header, prho_reference, sa_surface,             &
+        ONLY:  ibc_sa_t, prho_reference, sa_surface,                           &
                sa_vertical_gradient, sa_vertical_gradient_level,               &
                sa_vertical_gradient_level_ind
@@ -487,9 +472,6 @@
                total_number_of_particles, use_sgs_for_particles,               &
                vertical_particle_advection, write_particle_statistics
-        
+
     USE pegrid
-
-    USE plant_canopy_model_mod,                                                &
-        ONLY:  pcm_header
 
 #if defined( __parallel )
@@ -501,18 +483,6 @@
         ONLY:  nested_run, nesting_datatransfer_mode, nesting_mode
 
-    USE radiation_model_mod,                                                   &
-        ONLY:  radiation, radiation_header
-               
-    USE salsa_mod,                                                             &
-        ONLY:  salsa_header        
-    
-    USE spectra_mod,                                                           &
-        ONLY:  calculate_spectra, spectra_header
-
     USE surface_mod,                                                           &
         ONLY:  surf_def_h, get_topography_top_index_ji
-
-    USE synthetic_turbulence_generator_mod,                                    &
-        ONLY:  stg_header
 
     USE turbulence_closure_mod,                                                &
@@ -935,12 +905,4 @@
 
 !
-!-- Large scale forcing and nudging
-    IF ( large_scale_forcing )  CALL lsf_nudging_header( io )
-
-!
-!-- Offline nesting 
-    IF ( nesting_offline )  CALL nesting_offl_header( io )
-
-!
 !-- Profile for the large scale vertial velocity
 !-- Building output strings, starting with surface value
@@ -1161,16 +1123,4 @@
        ENDIF
     ENDIF
-
-!
-!-- Header information from other modules
-    IF ( biometeorology      )  CALL bio_header ( io )
-    IF ( gust_module_enabled )  CALL gust_header( io )
-    IF ( land_surface        )  CALL lsm_header( io )
-    IF ( ocean_mode          )  CALL ocean_header( io )
-    IF ( plant_canopy        )  CALL pcm_header( io )
-    IF ( radiation           )  CALL radiation_header( io )
-    IF ( syn_turb_gen        )  CALL stg_header( io )
-
-    IF ( air_chemistry )  CALL chem_header ( io )
 !
 !-- Boundary conditions
@@ -1924,11 +1874,5 @@
     ENDIF
 #endif
-!
-!-- Output of virtual flight information
-    IF ( virtual_flight )  CALL flight_header( io )
-
-!
-!-- Output of spectra related quantities
-    IF ( calculate_spectra )  CALL spectra_header( io )
+
 
     WRITE ( io, 99 )
@@ -1958,8 +1902,4 @@
        ENDIF
     ENDIF
-
-!
-!-- Output of microphysics information
-    IF ( bulk_cloud_model )  CALL bcm_header( io )
 
 !
@@ -2083,12 +2023,9 @@
        ENDIF
     ENDIF
-    
-!
-!-- SALSA information
-    IF ( salsa )  CALL salsa_header( io ) 
-
-!
-!-- User-defined information
-    CALL user_header( io )
+
+!
+!-- Header information from other modules
+    CALL module_interface_header( io )
+
 
     WRITE ( io, 99 )
Index: palm/trunk/SOURCE/module_interface.f90
===================================================================
--- palm/trunk/SOURCE/module_interface.f90	(revision 3637)
+++ palm/trunk/SOURCE/module_interface.f90	(revision 3637)
@@ -0,0 +1,1043 @@
+!> @file module_interface.f90
+!------------------------------------------------------------------------------!
+! This file is part of PALM.
+!
+! 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-2018 Leibniz Universitaet Hannover
+!------------------------------------------------------------------------------!
+!
+! Current revisions:
+! -----------------
+! 
+! 
+! Former revisions:
+! -----------------
+! $Id$
+! Initial implementation of the PALM module interface
+!
+! 
+! Description:
+! ------------
+!> This is the interface between the PALM model core and all its modules.
+!>
+!------------------------------------------------------------------------------!
+MODULE module_interface
+
+   USE indices,                                                                &
+       ONLY:  nbgp, nxl, nxlg, nxr, nxrg, nys, nysg, nyn, nyng, nzb, nzt
+
+   USE kinds
+
+!- load module-specific control parameters.
+!- ToDo: move all of them to respective module or a dedicated central module
+
+   USE control_parameters,                                                     &
+       ONLY:  biometeorology,                                                  &
+              air_chemistry,                                                   &
+              land_surface,                                                    &
+              large_scale_forcing,                                             &
+              nesting_offline,                                                 &
+              nudging,                                                         &
+              ocean_mode,                                                      &
+              plant_canopy,                                                    &
+              salsa,                                                           &
+              surface_data_output,                                             &
+              syn_turb_gen,                                                    &
+              urban_surface,                                                   &
+              virtual_flight,                                                  &
+              wind_turbine
+
+!- load interface routines of all PALM modules
+
+   USE biometeorology_mod,                                                     &
+       ONLY:  bio_parin,                                                       &
+              bio_check_parameters,                                            &
+              bio_check_data_output,                                           &
+              bio_header,                                                      &
+              bio_3d_data_averaging,                                           &
+              bio_data_output_2d,                                              &
+              bio_data_output_3d
+
+   USE bulk_cloud_model_mod,                                                   &
+       ONLY:  bulk_cloud_model,                                                &
+              bcm_parin,                                                       &
+              bcm_check_parameters,                                            &
+              bcm_check_data_output_pr,                                        &
+              bcm_check_data_output,                                           &
+              bcm_header,                                                      &
+              bcm_swap_timelevel,                                              &
+              bcm_3d_data_averaging,                                           &
+              bcm_data_output_2d,                                              &
+              bcm_data_output_3d,                                              &
+              bcm_rrd_global,                                                  &
+              bcm_wrd_global,                                                  &
+              bcm_rrd_local,                                                   &
+              bcm_wrd_local
+
+   USE chemistry_model_mod,                                                    &
+       ONLY:  chem_parin,                                                      &
+              chem_check_parameters,                                           &
+              chem_check_data_output_pr,                                       &
+              chem_check_data_output,                                          &
+              chem_header,                                                     &
+              chem_swap_timelevel,                                             &
+              chem_3d_data_averaging,                                          &
+              chem_data_output_2d,                                             &
+              chem_data_output_3d,                                             &
+              chem_statistics,                                                 &
+              chem_rrd_local,                                                  &
+              chem_wrd_local
+
+   USE flight_mod,                                                             &
+       ONLY:  flight_parin,                                                    &
+              flight_header,                                                   &
+              flight_rrd_global,                                               &
+              flight_wrd_global
+
+   USE gust_mod,                                                               &
+       ONLY:  gust_module_enabled,                                             &
+              gust_parin,                                                      &
+              gust_check_parameters,                                           &
+              gust_check_data_output_pr,                                       &
+              gust_check_data_output,                                          &
+              gust_header,                                                     &
+              gust_swap_timelevel,                                             &
+              gust_3d_data_averaging,                                          &
+              gust_data_output_2d,                                             &
+              gust_data_output_3d,                                             &
+              gust_statistics,                                                 &
+              gust_rrd_global,                                                 &
+              gust_wrd_global,                                                 &
+              gust_rrd_local,                                                  &
+              gust_wrd_local
+
+   USE indoor_model_mod,                                                       &
+       ONLY:  im_parin
+
+   USE land_surface_model_mod,                                                 &
+       ONLY:  lsm_parin,                                                       &
+              lsm_check_parameters,                                            &
+              lsm_check_data_output_pr,                                        &
+              lsm_check_data_output,                                           &
+              lsm_header,                                                      &
+              lsm_swap_timelevel,                                              &
+              lsm_3d_data_averaging,                                           &
+              lsm_data_output_2d,                                              &
+              lsm_rrd_local,                                                   &
+              lsm_wrd_local
+
+   USE lsf_nudging_mod,                                                        &
+       ONLY:  lsf_nudging_check_parameters,                                    &
+              lsf_nudging_check_data_output_pr,                                &
+              lsf_nudging_header
+
+   USE multi_agent_system_mod,                                                 &
+       ONLY:  mas_parin
+
+   USE nesting_offl_mod,                                                       &
+       ONLY:  nesting_offl_parin,                                              &
+              nesting_offl_check_parameters,                                   &
+              nesting_offl_header
+
+   USE ocean_mod,                                                              &
+       ONLY:  ocean_parin,                                                     &
+              ocean_check_parameters,                                          &
+              ocean_check_data_output_pr,                                      &
+              ocean_check_data_output,                                         &
+              ocean_header,                                                    &
+              ocean_swap_timelevel,                                            &
+              ocean_3d_data_averaging,                                         &
+              ocean_data_output_2d,                                            &
+              ocean_data_output_3d,                                            &
+              ocean_rrd_global,                                                &
+              ocean_wrd_global,                                                &
+              ocean_rrd_local,                                                 &
+              ocean_wrd_local
+
+   USE plant_canopy_model_mod,                                                 &
+        ONLY: pcm_parin,                                                       &
+              pcm_check_parameters,                                            &
+              pcm_check_data_output,                                           &
+              pcm_header,                                                      &
+              pcm_data_output_3d
+
+   USE radiation_model_mod,                                                    &
+       ONLY:  radiation,                                                       &
+              radiation_parin,                                                 &
+              radiation_check_parameters,                                      &
+              radiation_check_data_output_pr,                                  &
+              radiation_check_data_output,                                     &
+              radiation_header,                                                &
+              radiation_3d_data_averaging,                                     &
+              radiation_data_output_2d,                                        &
+              radiation_data_output_3d,                                        &
+              radiation_rrd_local,                                             &
+              radiation_wrd_local
+
+   USE salsa_mod,                                                              &
+       ONLY:  salsa_parin,                                                     &
+              salsa_check_parameters,                                          &
+              salsa_check_data_output,                                         &
+              salsa_header,                                                    &
+              salsa_swap_timelevel,                                            &
+              salsa_3d_data_averaging,                                         &
+              salsa_data_output_2d,                                            &
+              salsa_data_output_3d,                                            &
+              salsa_rrd_local,                                                 &
+              salsa_wrd_local
+
+   USE spectra_mod,                                                            &
+       ONLY:  calculate_spectra,                                               &
+              spectra_parin,                                                   &
+              spectra_check_parameters,                                        &
+              spectra_header
+
+   USE surface_output_mod,                                                     &
+       ONLY:  surface_output_parin,                                            &
+              surface_output_check_parameters
+
+   USE synthetic_turbulence_generator_mod,                                     &
+       ONLY:  stg_parin,                                                       &
+              stg_check_parameters,                                            &
+              stg_header,                                                      &
+              stg_rrd_global,                                                  &
+              stg_wrd_global
+
+   USE urban_surface_mod,                                                      &
+       ONLY:  usm_parin,                                                       &
+              usm_check_parameters,                                            &
+              usm_check_data_output,                                           &
+              usm_swap_timelevel,                                              &
+              usm_3d_data_averaging,                                           &
+              usm_rrd_local,                                                   &
+              usm_wrd_local
+
+   USE user_read_restart_data_mod,                                             &
+       ONLY:  user_rrd_global,                                                 &
+              user_rrd_local
+
+   USE user_write_restart_data_mod,                                            &
+       ONLY:  user_wrd_global,                                                 &
+              user_wrd_local
+
+   USE virtual_measurement_mod,                                                &
+       ONLY:  vm_parin
+
+   USE wind_turbine_model_mod,                                                 &
+       ONLY:  wtm_parin,                                                       &
+              wtm_check_parameters,                                            &
+              wtm_rrd_global,                                                  &
+              wtm_wrd_global
+
+   IMPLICIT NONE
+
+   PRIVATE
+
+!
+!- Public functions
+   PUBLIC                                                                      &
+      module_interface_parin,                                                  &
+      module_interface_check_parameters,                                       &
+      module_interface_check_data_output_pr,                                   &
+      module_interface_check_data_output,                                      &
+      module_interface_define_netcdf_grid,                                     &
+      module_interface_init_arrays,                                            &
+      module_interface_init,                                                   &
+      module_interface_header,                                                 &
+      module_interface_actions,                                                &
+      module_interface_swap_timelevel,                                         &
+      module_interface_3d_data_averaging,                                      &
+      module_interface_data_output_2d,                                         &
+      module_interface_data_output_3d,                                         &
+      module_interface_statistics,                                             &
+      module_interface_rrd_global,                                             &
+      module_interface_wrd_global,                                             &
+      module_interface_rrd_local,                                              &
+      module_interface_wrd_local
+
+
+   INTERFACE module_interface_parin
+      MODULE PROCEDURE module_interface_parin
+   END INTERFACE module_interface_parin
+
+   INTERFACE module_interface_check_parameters
+      MODULE PROCEDURE module_interface_check_parameters
+   END INTERFACE module_interface_check_parameters
+
+   INTERFACE module_interface_check_data_output_pr
+      MODULE PROCEDURE module_interface_check_data_output_pr
+   END INTERFACE module_interface_check_data_output_pr
+
+   INTERFACE module_interface_check_data_output
+      MODULE PROCEDURE module_interface_check_data_output
+   END INTERFACE module_interface_check_data_output
+
+   INTERFACE module_interface_define_netcdf_grid
+      MODULE PROCEDURE module_interface_define_netcdf_grid
+   END INTERFACE module_interface_define_netcdf_grid
+
+   INTERFACE module_interface_init_arrays
+      MODULE PROCEDURE module_interface_init_arrays
+   END INTERFACE module_interface_init_arrays
+
+   INTERFACE module_interface_init
+      MODULE PROCEDURE module_interface_init
+   END INTERFACE module_interface_init
+
+   INTERFACE module_interface_header
+      MODULE PROCEDURE module_interface_header
+   END INTERFACE module_interface_header
+
+   INTERFACE module_interface_actions
+      MODULE PROCEDURE module_interface_actions
+      MODULE PROCEDURE module_interface_actions_ij
+   END INTERFACE module_interface_actions
+
+   INTERFACE module_interface_swap_timelevel
+      MODULE PROCEDURE module_interface_swap_timelevel
+   END INTERFACE module_interface_swap_timelevel
+
+   INTERFACE module_interface_3d_data_averaging
+      MODULE PROCEDURE module_interface_3d_data_averaging
+   END INTERFACE module_interface_3d_data_averaging
+
+   INTERFACE module_interface_data_output_2d
+      MODULE PROCEDURE module_interface_data_output_2d
+   END INTERFACE module_interface_data_output_2d
+
+   INTERFACE module_interface_data_output_3d
+      MODULE PROCEDURE module_interface_data_output_3d
+   END INTERFACE module_interface_data_output_3d
+
+   INTERFACE module_interface_statistics
+      MODULE PROCEDURE module_interface_statistics
+   END INTERFACE module_interface_statistics
+
+   INTERFACE module_interface_rrd_global
+      MODULE PROCEDURE module_interface_rrd_global
+   END INTERFACE module_interface_rrd_global
+
+   INTERFACE module_interface_wrd_global
+      MODULE PROCEDURE module_interface_wrd_global
+   END INTERFACE module_interface_wrd_global
+
+   INTERFACE module_interface_rrd_local
+      MODULE PROCEDURE module_interface_rrd_local
+   END INTERFACE module_interface_rrd_local
+
+   INTERFACE module_interface_wrd_local
+      MODULE PROCEDURE module_interface_wrd_local
+   END INTERFACE module_interface_wrd_local
+
+
+CONTAINS
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Read module-specific parameter namelists
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_parin
+
+
+   CALL bio_parin
+   CALL bcm_parin
+   CALL chem_parin
+   CALL flight_parin ! ToDo: rename module to match filename
+   CALL gust_parin
+   CALL im_parin
+   CALL lsm_parin
+   ! ToDo: create parin routine for large_scale_forcing and nudging (should be seperate modules or new module switch)
+   CALL mas_parin
+   CALL nesting_offl_parin
+   CALL ocean_parin
+   CALL pcm_parin
+   CALL radiation_parin
+   CALL salsa_parin
+   CALL spectra_parin
+   CALL surface_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 package_parin ! ToDo: deprecated, needs to be dissolved
+
+
+END SUBROUTINE module_interface_parin
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Perform module-specific initialization checks
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_check_parameters
+
+
+   IF ( biometeorology )       CALL bio_check_parameters
+   IF ( bulk_cloud_model )     CALL bcm_check_parameters
+   IF ( air_chemistry )        CALL chem_check_parameters
+   IF ( gust_module_enabled )  CALL gust_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
+   IF ( nesting_offline )      CALL nesting_offl_check_parameters
+   IF ( ocean_mode )           CALL ocean_check_parameters
+   IF ( plant_canopy )         CALL pcm_check_parameters
+   IF ( radiation )            CALL radiation_check_parameters
+   IF ( salsa )                CALL salsa_check_parameters
+   IF ( calculate_spectra )    CALL spectra_check_parameters
+   IF ( surface_data_output )  CALL surface_output_check_parameters
+   IF ( syn_turb_gen )         CALL stg_check_parameters
+   IF ( urban_surface )        CALL usm_check_parameters
+   IF ( wind_turbine )         CALL wtm_check_parameters
+                               CALL user_check_parameters
+
+
+END SUBROUTINE module_interface_check_parameters
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Check module-specific data output of profiles
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_check_data_output_pr( variable, var_count, unit,   &
+                                                dopr_unit )
+
+
+   CHARACTER (LEN=*), INTENT(IN)    ::  variable  !< variable name
+   INTEGER(iwp),      INTENT(IN)    ::  var_count !< variable output array index
+   CHARACTER (LEN=*), INTENT(INOUT) ::  unit      !< physical unit of variable
+   CHARACTER (LEN=*), INTENT(OUT)   ::  dopr_unit !< local value of dopr_unit
+
+   IF ( unit == 'illegal' .AND.  bulk_cloud_model )  THEN
+      CALL bcm_check_data_output_pr( variable, var_count, unit, dopr_unit )
+   ENDIF
+
+   IF ( unit == 'illegal' .AND.  air_chemistry )  THEN
+      CALL chem_check_data_output_pr( variable, var_count, unit, dopr_unit )
+   ENDIF
+
+   IF ( unit == 'illegal'  .AND.  gust_module_enabled  )  THEN
+      CALL gust_check_data_output_pr( variable, var_count, unit, dopr_unit )
+   ENDIF
+
+   IF ( unit == 'illegal' )  THEN ! ToDo: add module switch if possible
+      CALL lsm_check_data_output_pr( variable, var_count, unit, dopr_unit )
+   ENDIF
+
+   IF ( unit == 'illegal' )  THEN ! ToDo: add module switch if possible
+      CALL lsf_nudging_check_data_output_pr( variable, var_count, unit, dopr_unit )
+   ENDIF
+
+   IF ( unit == 'illegal'  .AND.  ocean_mode )  THEN
+      CALL ocean_check_data_output_pr( variable, var_count, unit, dopr_unit )
+   ENDIF
+
+   IF ( unit == 'illegal' )  THEN
+      CALL radiation_check_data_output_pr( variable, var_count, unit, dopr_unit )
+   ENDIF
+
+   IF ( unit == 'illegal' )  THEN
+      unit = '' ! ToDo: Seems like a hack. Find a general soultion!
+      CALL user_check_data_output_pr( variable, var_count, unit )
+   ENDIF
+
+
+
+END SUBROUTINE module_interface_check_data_output_pr
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Check module-specific 2D and 3D data output
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_check_data_output( variable, unit, i, ilen, k )
+
+
+   CHARACTER (LEN=*), INTENT(IN)  ::  variable !< variable name
+   CHARACTER (LEN=*), INTENT(OUT) ::  unit     !< physical unit of variable
+
+   INTEGER(iwp),      INTENT(IN)  :: i         !< ToDo: remove dummy argument, instead pass string from data_output
+   INTEGER(iwp),      INTENT(IN)  :: ilen      !< ToDo: remove dummy argument, instead pass string from data_output
+   INTEGER(iwp),      INTENT(IN)  :: k         !< ToDo: remove dummy argument, instead pass string from data_output
+
+   IF ( unit == 'illegal'  .AND.  biometeorology )  THEN
+      CALL bio_check_data_output( variable, unit, i, ilen, k )
+   ENDIF
+
+   IF ( unit == 'illegal'  .AND.  bulk_cloud_model  )  THEN
+      CALL bcm_check_data_output( variable, unit )
+   ENDIF
+
+   IF ( unit == 'illegal'  .AND.  air_chemistry                                &
+        .AND.  (variable(1:3) == 'kc_' .OR. variable(1:3) == 'em_') )  THEN  ! ToDo: remove aditional conditions
+      CALL chem_check_data_output( variable, unit, i, ilen, k )
+   ENDIF
+
+   IF ( unit == 'illegal'  .AND.  gust_module_enabled  )  THEN
+      CALL gust_check_data_output( variable, unit )
+   ENDIF
+
+   IF ( unit == 'illegal' )  THEN  ! ToDo: add module switch if possible
+      CALL lsm_check_data_output( variable, unit, i, ilen, k )
+   ENDIF
+
+   IF ( unit == 'illegal'  .AND.  ocean_mode )  THEN
+      CALL ocean_check_data_output( variable, unit )
+   ENDIF
+
+   IF ( unit == 'illegal'  .AND.  plant_canopy                                 &
+        .AND.  variable(1:4) == 'pcm_' )  THEN  ! ToDo: remove aditional conditions
+      CALL pcm_check_data_output( variable, unit )
+   ENDIF
+
+   IF ( unit == 'illegal' )  THEN
+      CALL radiation_check_data_output( variable, unit, i, ilen, k )
+   ENDIF
+
+   IF ( unit == 'illegal' .AND. salsa ) THEN
+       CALL salsa_check_data_output( variable, unit )
+   ENDIF
+
+   IF ( unit == 'illegal'  .AND.  urban_surface                      &
+        .AND.  variable(1:4) == 'usm_' )  THEN  ! ToDo: remove aditional conditions
+       CALL usm_check_data_output( variable, unit )
+   ENDIF
+
+   IF ( unit == 'illegal' )  THEN
+      unit = ''
+      CALL user_check_data_output( variable, unit )
+   ENDIF
+
+
+END SUBROUTINE module_interface_check_data_output
+
+
+!------------------------------------------------------------------------------!
+!
+! Description:
+! ------------
+!> Define appropriate grid for module-specific netcdf output variables.
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_define_netcdf_grid( var, found,                    &
+                                                grid_x, grid_y, grid_z )
+
+
+   CHARACTER (LEN=*), INTENT(IN)  ::  var    !< variable name
+   LOGICAL,           INTENT(OUT) ::  found  !< indicates if variable was found
+   CHARACTER (LEN=*), INTENT(OUT) ::  grid_x !< netcdf dimension in x-direction
+   CHARACTER (LEN=*), INTENT(OUT) ::  grid_y !< netcdf dimension in y-direction
+   CHARACTER (LEN=*), INTENT(OUT) ::  grid_z !< netcdf dimension in z-direction
+
+
+END SUBROUTINE module_interface_define_netcdf_grid
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Allocate module-specific arrays and pointers
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_init_arrays
+
+
+END SUBROUTINE module_interface_init_arrays
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Perform module-specific initialization
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_init
+
+
+END SUBROUTINE module_interface_init
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Gather module-specific header output
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_header( io )
+
+
+   INTEGER(iwp), INTENT(IN) ::  io  !< unit of the output file
+
+
+   IF ( biometeorology      )  CALL bio_header ( io )
+   IF ( bulk_cloud_model    )  CALL bcm_header( io )
+   IF ( air_chemistry       )  CALL chem_header ( io )
+   IF ( virtual_flight      )  CALL flight_header( io )
+   IF ( gust_module_enabled )  CALL gust_header( io )
+   IF ( land_surface        )  CALL lsm_header( io )
+   IF ( large_scale_forcing )  CALL lsf_nudging_header( io )
+   IF ( nesting_offline     )  CALL nesting_offl_header( io )
+   IF ( ocean_mode          )  CALL ocean_header( io )
+   IF ( plant_canopy        )  CALL pcm_header( io )
+   IF ( radiation           )  CALL radiation_header( io )
+   IF ( salsa               )  CALL salsa_header( io )
+   IF ( calculate_spectra   )  CALL spectra_header( io )
+   IF ( syn_turb_gen        )  CALL stg_header( io )
+
+   CALL user_header( io ) ! ToDo: make user module switch
+
+
+END SUBROUTINE module_interface_header
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Perform module-specific actions while in time-integration (cache-optimized)
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_actions( location )
+
+
+   CHARACTER (LEN=*), INTENT(IN) ::  location !< call location string
+
+
+END SUBROUTINE module_interface_actions
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Perform module-specific actions while in time-integration (vector-optimized)
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_actions_ij( i, j, location )
+
+
+   INTEGER(iwp),      INTENT(IN) ::  i         !< grid index in x-direction
+   INTEGER(iwp),      INTENT(IN) ::  j         !< grid index in y-direction
+   CHARACTER (LEN=*), INTENT(IN) ::  location  !< call location string
+
+
+END SUBROUTINE module_interface_actions_ij
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Swap the timelevel pointers for module-specific arrays
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_swap_timelevel ( swap_mode )
+
+
+   INTEGER(iwp), INTENT(IN) :: swap_mode !< determines procedure of pointer swap
+
+   IF ( bulk_cloud_model    )  CALL bcm_swap_timelevel( swap_mode )
+   IF ( air_chemistry       )  CALL chem_swap_timelevel( swap_mode )
+   IF ( gust_module_enabled )  CALL gust_swap_timelevel( swap_mode )
+   IF ( land_surface        )  CALL lsm_swap_timelevel( swap_mode )
+   IF ( ocean_mode          )  CALL ocean_swap_timelevel( swap_mode )
+   IF ( salsa               )  CALL salsa_swap_timelevel( swap_mode )
+   IF ( urban_surface       )  CALL usm_swap_timelevel( swap_mode )
+
+
+END SUBROUTINE module_interface_swap_timelevel
+
+
+!------------------------------------------------------------------------------!
+!
+! Description:
+! ------------
+!> Perform module-specific averaging of 3D data
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_3d_data_averaging( mode, variable )
+
+
+   CHARACTER (LEN=*), INTENT(IN) ::  mode     !< averaging interface mode
+   CHARACTER (LEN=*), INTENT(IN) ::  variable !< variable name
+
+   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 )
+   IF ( gust_module_enabled )  CALL gust_3d_data_averaging( mode, variable )
+   IF ( land_surface        )  CALL lsm_3d_data_averaging( mode, variable )
+   IF ( ocean_mode          )  CALL ocean_3d_data_averaging( mode, variable )
+   IF ( radiation           )  CALL radiation_3d_data_averaging( mode, variable )
+   IF ( salsa               )  CALL salsa_3d_data_averaging( mode, variable )
+   IF ( urban_surface       )  CALL usm_3d_data_averaging( mode, variable )
+
+   CALL user_3d_data_averaging( mode, variable ) ! ToDo: make user module switch
+
+
+END SUBROUTINE module_interface_3d_data_averaging
+
+!------------------------------------------------------------------------------!
+!
+! Description:
+! ------------
+!> Define module-specific 2D output variables
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_data_output_2d( av, variable, found, grid, mode,   &
+                                            local_pf, two_d, nzb_do, nzt_do,   &
+                                            fill_value )
+
+   INTEGER(iwp),      INTENT(IN)  ::  av       !< flag for (non-)average output
+   CHARACTER (LEN=*), INTENT(IN)  ::  variable !< variable name
+   LOGICAL,           INTENT(OUT) ::  found    !< flag if output variable is found
+   CHARACTER (LEN=*), INTENT(OUT) ::  grid     !< name of vertical grid
+   CHARACTER (LEN=*), INTENT(IN)  ::  mode     !< either 'xy', 'xz' or 'yz'
+   LOGICAL,           INTENT(OUT) ::  two_d    !< flag for 2D variables
+   INTEGER(iwp),      INTENT(IN)  ::  nzb_do   !< vertical output index (bottom) (usually 0)
+   INTEGER(iwp),      INTENT(IN)  ::  nzt_do   !< vertical output index (top) (usually nz_do3d)
+   REAL(wp),          INTENT(IN)  ::  fill_value !< to be removed
+
+   REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do), INTENT(OUT) ::  local_pf !< ToDo: can also be kind=sp
+
+
+   IF ( .NOT. found  .AND.  biometeorology )  THEN
+      CALL bio_data_output_2d(                                                 &
+              av, variable, found, grid, local_pf, two_d, nzb_do, nzt_do       &
+           )
+   ENDIF
+
+   IF ( .NOT. found  .AND.  bulk_cloud_model )  THEN
+      CALL bcm_data_output_2d(                                                 &
+              av, variable, found, grid, mode, local_pf, two_d, nzb_do, nzt_do &
+           )
+   ENDIF
+
+   IF ( .NOT. found  .AND.  air_chemistry )  THEN
+      CALL chem_data_output_2d(                                                &
+              av, variable, found, grid, mode, local_pf, two_d, nzb_do, nzt_do, fill_value &
+           )
+   ENDIF
+
+   IF ( .NOT. found  .AND.  gust_module_enabled )  THEN
+      CALL gust_data_output_2d(                                                &
+              av, variable, found, grid, local_pf, two_d, nzb_do, nzt_do       &
+           )
+   ENDIF
+
+   IF ( .NOT. found  .AND.  land_surface )  THEN
+      CALL lsm_data_output_2d(                                                 &
+              av, variable, found, grid, mode, local_pf, two_d, nzb_do, nzt_do &
+           )
+   ENDIF
+
+   IF ( .NOT. found  .AND.  ocean_mode )  THEN
+      CALL ocean_data_output_2d(                                               &
+              av, variable, found, grid, mode, local_pf, nzb_do, nzt_do        &
+           )
+   ENDIF
+
+   IF ( .NOT. found  .AND.  radiation )  THEN
+      CALL radiation_data_output_2d(                                           &
+              av, variable, found, grid, mode, local_pf, two_d, nzb_do, nzt_do &
+           )
+   ENDIF
+
+   IF ( .NOT. found  .AND.  salsa )  THEN
+      CALL salsa_data_output_2d(                                               &
+              av, variable, found, grid, mode, local_pf, two_d, nzb_do, nzt_do &
+           )
+   ENDIF
+
+   IF ( .NOT. found )  THEN  ! ToDo: make user module switch
+      CALL user_data_output_2d(                                                &
+              av, variable, found, grid, local_pf, two_d, nzb_do, nzt_do       &
+           )
+   ENDIF
+
+END SUBROUTINE module_interface_data_output_2d
+
+
+!------------------------------------------------------------------------------!
+!
+! Description:
+! ------------
+!> Define module-specific 3D output variables
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_data_output_3d( av, variable, found, local_pf,     &
+                                            fill_value, resorted, nzb_do, nzt_do )
+
+
+   INTEGER(iwp),      INTENT(IN)  ::  av         !< flag for (non-)average output
+   CHARACTER (LEN=*), INTENT(IN)  ::  variable   !< variable name
+   LOGICAL,           INTENT(OUT) ::  found      !< flag if output variable is found
+   REAL(wp),          INTENT(IN)  ::  fill_value !< ToDo: refactor
+   LOGICAL,           INTENT(OUT) ::  resorted   !< flag if output has been resorted
+   INTEGER(iwp),      INTENT(IN)  ::  nzb_do     !< vertical output index (bottom) (usually 0)
+   INTEGER(iwp),      INTENT(IN)  ::  nzt_do     !< vertical output index (top) (usually nz_do3d)
+
+   REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do), INTENT(OUT) ::  local_pf
+
+
+   IF ( .NOT. found  .AND.  biometeorology )  THEN
+      CALL bio_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
+      resorted = .FALSE.
+   ENDIF
+
+   IF ( .NOT. found  .AND.  bulk_cloud_model )  THEN
+      CALL bcm_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
+      resorted = .TRUE.
+   ENDIF
+
+   IF ( .NOT. found  .AND.  air_chemistry )  THEN
+      CALL chem_data_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, nzb_do, nzt_do )
+      resorted = .TRUE.
+   ENDIF
+
+   IF ( .NOT. found  .AND.  ocean_mode )  THEN
+      CALL ocean_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
+      resorted = .TRUE.
+   ENDIF
+
+   IF ( .NOT. found  .AND.  plant_canopy )  THEN
+      CALL pcm_data_output_3d( av, variable, found, local_pf, fill_value, nzb_do, nzt_do )
+      resorted = .TRUE.
+   ENDIF
+
+   IF ( .NOT. found  .AND.  radiation )  THEN
+      CALL radiation_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
+      resorted = .TRUE.
+   ENDIF
+
+   IF ( .NOT. found  .AND.  salsa )  THEN
+      CALL salsa_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
+      resorted = .TRUE.
+   ENDIF
+
+   IF ( .NOT. found )  THEN  ! ToDo: make user module switch
+      CALL user_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
+      resorted = .TRUE.
+   ENDIF
+
+
+END SUBROUTINE module_interface_data_output_3d
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute module-specific profile and timeseries data
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_statistics( mode, sr, tn, dots_max )
+
+
+   CHARACTER (LEN=*), INTENT(IN) ::  mode     !< statistical analysis mode
+   INTEGER(iwp),      INTENT(IN) ::  sr       !<
+   INTEGER(iwp),      INTENT(IN) ::  tn       !<
+   INTEGER(iwp),      INTENT(IN) ::  dots_max !< maximum number of timeseries
+
+   IF ( gust_module_enabled )  CALL gust_statistics( mode, sr, tn, dots_max )
+   IF ( air_chemistry       )  CALL chem_statistics( mode, sr, tn )
+
+   CALL user_statistics( mode, sr, tn ) ! ToDo: make user module switch
+
+
+END SUBROUTINE module_interface_statistics
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Read module-specific restart data globaly shared by all MPI ranks
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_rrd_global( variable, found )
+
+
+   CHARACTER (LEN=*), INTENT(IN)  ::  variable !< name of global variable
+   LOGICAL,           INTENT(OUT) ::  found    !< flag if variable was found
+
+   IF ( .NOT. found )  CALL bcm_rrd_global( found ) ! ToDo: change interface to pass variable
+   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 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 user_rrd_global( found ) ! ToDo: change interface to pass variable
+
+
+END SUBROUTINE module_interface_rrd_global
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Write module-specific restart data globaly shared by all MPI ranks
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_wrd_global
+
+
+   IF ( bulk_cloud_model )     CALL bcm_wrd_global
+   IF ( virtual_flight )       CALL flight_wrd_global
+   IF ( gust_module_enabled )  CALL gust_wrd_global
+   IF ( ocean_mode )           CALL ocean_wrd_global
+   IF ( syn_turb_gen )         CALL stg_wrd_global
+   IF ( wind_turbine )         CALL wtm_wrd_global
+
+   CALL user_wrd_global ! ToDo: make user module switch
+
+
+END SUBROUTINE module_interface_wrd_global
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Read module-specific restart data specific to local MPI ranks
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_rrd_local( variable, file_index, 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 )
+
+
+   CHARACTER (LEN=*), INTENT(IN)  ::  variable     !< name of global variable
+   INTEGER(iwp),      INTENT(IN)  ::  file_index   !<
+   INTEGER(iwp),      INTENT(IN)  ::  map_index    !<
+   INTEGER(iwp),      INTENT(IN)  ::  nxlc         !<
+   INTEGER(iwp),      INTENT(IN)  ::  nxlf         !<
+   INTEGER(iwp),      INTENT(IN)  ::  nxl_on_file  !<
+   INTEGER(iwp),      INTENT(IN)  ::  nxrc         !<
+   INTEGER(iwp),      INTENT(IN)  ::  nxrf         !<
+   INTEGER(iwp),      INTENT(IN)  ::  nxr_on_file  !<
+   INTEGER(iwp),      INTENT(IN)  ::  nync         !<
+   INTEGER(iwp),      INTENT(IN)  ::  nynf         !<
+   INTEGER(iwp),      INTENT(IN)  ::  nyn_on_file  !<
+   INTEGER(iwp),      INTENT(IN)  ::  nysc         !<
+   INTEGER(iwp),      INTENT(IN)  ::  nysf         !<
+   INTEGER(iwp),      INTENT(IN)  ::  nys_on_file  !<
+   LOGICAL,           INTENT(OUT) ::  found        !< flag if variable was found
+
+   REAL(wp), DIMENSION(nys_on_file-nbgp:nyn_on_file+nbgp,nxl_on_file-nbgp:nxr_on_file+nbgp), INTENT(OUT) :: tmp_2d   !<
+   REAL(wp), DIMENSION(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp,nxl_on_file-nbgp:nxr_on_file+nbgp), INTENT(OUT) :: tmp_3d   !<
+
+
+   IF ( .NOT. found ) CALL bcm_rrd_local(                                      &
+                              file_index, 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 chem_rrd_local(                                     &
+                              file_index, map_index,                           &
+                              nxlf, nxlc, nxl_on_file,                         &
+                              nxrf, nxrc, nxr_on_file,                         &
+                              nynf, nync, nyn_on_file,                         &
+                              nysf, nysc, nys_on_file,                         &
+                              tmp_3d, found                                    &
+                           ) ! ToDo: change interface to pass variable
+
+   IF ( .NOT. found ) CALL gust_rrd_local(                                     &
+                              file_index, 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 lsm_rrd_local(                                      &
+                              file_index, map_index,                           &
+                              nxlf, nxlc, nxl_on_file,                         &
+                              nxrf, nxrc, nxr_on_file,                         &
+                              nynf, nync, nyn_on_file,                         &
+                              nysf, nysc, nys_on_file,                         &
+                              tmp_2d, found                                    &
+                           ) ! ToDo: change interface to pass variable
+
+   IF ( .NOT. found ) CALL ocean_rrd_local(                                    &
+                              file_index, 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 radiation_rrd_local(                                &
+                              file_index, 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 salsa_rrd_local(                                    &
+                              file_index, map_index,                           &
+                              nxlf, nxlc, nxl_on_file,                         &
+                              nxrf, nxrc, nxr_on_file,                         &
+                              nynf, nync, nyn_on_file,                         &
+                              nysf, nysc, nys_on_file,                         &
+                              tmp_3d, found                                    &
+                           ) ! ToDo: change interface to pass variable
+
+   IF ( .NOT. found ) CALL usm_rrd_local(                                      &
+                              file_index, map_index,                           &
+                              nxlf, nxlc, nxl_on_file,                         &
+                              nxrf, nxrc, nxr_on_file,                         &
+                              nynf, nync, nyn_on_file,                         &
+                              nysf, nysc, nys_on_file,                         &
+                              found                                            &
+                           ) ! ToDo: change interface to pass variable
+
+   IF ( .NOT. found ) CALL user_rrd_local(                                     &
+                              file_index, map_index,                           &
+                              nxlf, nxlc, nxl_on_file,                         &
+                              nxrf, nxrc, nxr_on_file,                         &
+                              nynf, nync, nyn_on_file,                         &
+                              nysf, nysc, nys_on_file,                         &
+                              tmp_3d, found                                    &
+                           ) ! ToDo: change interface to pass variable
+
+
+END SUBROUTINE module_interface_rrd_local
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Write module-specific restart data specific to local MPI ranks
+!------------------------------------------------------------------------------!
+SUBROUTINE module_interface_wrd_local
+
+
+   IF ( bulk_cloud_model )     CALL bcm_wrd_local
+   IF ( air_chemistry )        CALL chem_wrd_local
+   IF ( gust_module_enabled )  CALL gust_wrd_local
+   IF ( land_surface )         CALL lsm_wrd_local
+   IF ( ocean_mode )           CALL ocean_wrd_local
+   IF ( radiation )            CALL radiation_wrd_local
+   IF ( salsa )                CALL salsa_wrd_local
+   IF ( urban_surface )        CALL usm_wrd_local
+
+   CALL user_wrd_local ! ToDo: make user module switch
+
+
+END SUBROUTINE module_interface_wrd_local
+
+
+END MODULE module_interface
Index: palm/trunk/SOURCE/parin.f90
===================================================================
--- palm/trunk/SOURCE/parin.f90	(revision 3636)
+++ palm/trunk/SOURCE/parin.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3569 2018-11-27 17:03:40Z kanani
 ! dom_dwd_user, Schrempf:
 ! Remove uv exposure model code, this is now part of biometeorology_mod.
@@ -468,13 +471,4 @@
                ug, u_init, v_init, vg
 
-    USE biometeorology_mod,                                                    &
-        ONLY:  bio_parin
-
-    USE bulk_cloud_model_mod,                                                  &
-        ONLY:  bcm_parin
-
-    USE chemistry_model_mod,                                                   &
-        ONLY:  chem_parin
-
     USE chem_modules
 
@@ -490,43 +484,22 @@
         ONLY:  local_dvrserver_running
 
-    USE flight_mod,                                                            &
-        ONLY:  flight_parin
-
     USE grid_variables,                                                        &
         ONLY:  dx, dy
 
-    USE gust_mod,                                                              &
-        ONLY: gust_parin
-
     USE indices,                                                               &
         ONLY:  nx, ny, nz
 
-    USE indoor_model_mod,                                                      &
-        ONLY:  im_parin
-
     USE kinds
-
-    USE land_surface_model_mod,                                                &
-        ONLY: lsm_parin
 
     USE model_1d_mod,                                                          &
         ONLY:  damp_level_1d, dt_pr_1d, dt_run_control_1d, end_time_1d
 
-    USE multi_agent_system_mod,                                                &
-        ONLY:  mas_parin
-
-    USE nesting_offl_mod,                                                      &
-        ONLY:  nesting_offl_parin
-        
+    USE module_interface,                                                      &
+        ONLY:  module_interface_parin
+
     USE netcdf_interface,                                                      &
         ONLY:  netcdf_data_format, netcdf_deflate, netcdf_precision
 
-    USE ocean_mod,                                                             &
-        ONLY:  ocean_parin
-
     USE pegrid
-
-    USE plant_canopy_model_mod,                                                &
-         ONLY: pcm_parin
 
     USE pmc_interface,                                                         &
@@ -539,39 +512,15 @@
         ONLY :  progress_bar_disabled
 
-    USE radiation_model_mod,                                                   &
-        ONLY: radiation_parin
-
     USE read_restart_data_mod,                                                 &
-        ONLY:  rrd_global  
-             
-    USE salsa_mod,                                                             &
-        ONLY: salsa_parin          
-
-    USE spectra_mod,                                                           &
-        ONLY :  spectra_parin
+        ONLY:  rrd_global
 
     USE statistics,                                                            &
         ONLY:  hom, hom_sum, pr_palm, region, statistic_regions
 
-    USE surface_output_mod,                                                    &
-        ONLY:  surface_output_parin
-
-    USE synthetic_turbulence_generator_mod,                                    &
-        ONLY:  stg_parin
-
     USE turbulence_closure_mod,                                                &
         ONLY:  rans_const_c, rans_const_sigma
 
-    USE urban_surface_mod,                                                     &
-        ONLY: usm_parin
-
     USE vertical_nesting_mod,                                                  &
         ONLY:  vnest_start_time
-        
-    USE virtual_measurement_mod,                                               &
-        ONLY:  vm_parin
-
-    USE wind_turbine_model_mod,                                                &
-        ONLY:  wtm_parin
 
 
@@ -917,27 +866,5 @@
 !
 !--       Check for module namelists and read them
-          CALL bio_parin
-          CALL lsm_parin
-          CALL bcm_parin
-          CALL surface_output_parin
-          CALL usm_parin
-          CALL spectra_parin
-          CALL radiation_parin
-          CALL gust_parin
-          CALL mas_parin
-          CALL nesting_offl_parin
-          CALL ocean_parin
-          CALL pcm_parin
-          CALL package_parin
-          CALL wtm_parin
-          CALL flight_parin
-          CALL stg_parin
-          CALL chem_parin
-          CALL im_parin
-          CALL salsa_parin
-          CALL vm_parin
-!
-!--       Read user-defined variables
-          CALL user_parin
+          CALL module_interface_parin
 
 !
Index: palm/trunk/SOURCE/read_restart_data_mod.f90
===================================================================
--- palm/trunk/SOURCE/read_restart_data_mod.f90	(revision 3636)
+++ palm/trunk/SOURCE/read_restart_data_mod.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3589 2018-11-30 15:09:51Z suehring
 ! Move the control parameter "salsa" from salsa_mod to control_parameters 
 ! (M. Kurppa)
@@ -88,8 +91,68 @@
 
 
-    USE control_parameters
+    USE arrays_3d,                                                             &
+        ONLY:  inflow_damping_factor, mean_inflow_profiles, pt_init,           &
+               q_init, ref_state, sa_init, s_init, u_init, ug, v_init, vg,     &
+               e, kh, km, p, pt, q, ql, s, u, u_m_l, u_m_n, u_m_r, u_m_s,      &
+               v, v_m_l, v_m_n, v_m_r, v_m_s, vpt, w, w_m_l, w_m_n, w_m_r, w_m_s
+
+    USE averaging
 
     USE chem_modules,                                                                              &
        ONLY: max_pr_cs
+
+    USE control_parameters
+
+    USE cpulog,                                                                &
+        ONLY:  cpu_log, log_point_s
+
+    USE date_and_time_mod,                                                     &
+        ONLY:  day_of_year_init, time_utc_init
+
+    USE grid_variables,                                                        &
+        ONLY:  dx, dy
+
+    USE indices,                                                               &
+        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, nx_on_file, ny, nys, nysg, nyn, &
+               nyng, ny_on_file, nz, nzb, nzt
+
+    USE kinds
+
+    USE model_1d_mod,                                                          &
+        ONLY:  damp_level_1d, dt_pr_1d, dt_run_control_1d, end_time_1d
+
+    USE module_interface,                                                      &
+        ONLY:  module_interface_rrd_global,                                    &
+               module_interface_rrd_local
+
+    USE netcdf_interface,                                                      &
+        ONLY:  netcdf_precision, output_for_t0
+
+    USE particle_attributes,                                                   &
+        ONLY:  curvature_solution_effects, iran_part
+
+    USE pegrid
+
+    USE radiation_model_mod,                                                   &
+        ONLY:  time_radiation
+
+    USE random_function_mod,                                                   &
+        ONLY:  random_iv, random_iy
+
+    USE random_generator_parallel,                                             &
+        ONLY:  id_random_array, seq_random_array
+
+    USE spectra_mod,                                                           &
+        ONLY:  average_count_sp, spectrum_x, spectrum_y
+
+    USE surface_mod,                                                           &
+        ONLY :  surface_rrd_local
+
+    USE statistics,                                                            &
+        ONLY:  statistic_regions, hom, hom_sum, pr_palm, u_max, u_max_ijk,     &
+               v_max, v_max_ijk, w_max, w_max_ijk, z_i
+
+    USE vertical_nesting_mod,                                                  &
+        ONLY:  vnest_init
 
 
@@ -127,65 +190,4 @@
     SUBROUTINE rrd_global
 
-
-       USE arrays_3d,                                                          &
-           ONLY:  inflow_damping_factor, mean_inflow_profiles, pt_init,        &
-                  q_init, ref_state, sa_init, s_init, u_init, ug, v_init, vg
-
-       USE bulk_cloud_model_mod,                                               &
-           ONLY:  bcm_rrd_global
-
-       USE date_and_time_mod,                                                  &
-           ONLY:  day_of_year_init, time_utc_init
-
-       USE flight_mod,                                                         &
-           ONLY: flight_rrd_global
-
-       USE grid_variables,                                                     &
-           ONLY:  dx, dy
-
-       USE gust_mod,                                                           &
-           ONLY :  gust_rrd_global
-
-       USE indices,                                                            &
-           ONLY:  nz, nx, nx_on_file, ny, ny_on_file
-
-       USE model_1d_mod,                                                       &
-           ONLY:  damp_level_1d, dt_pr_1d, dt_run_control_1d, end_time_1d
-
-       USE netcdf_interface,                                                   &
-           ONLY:  netcdf_precision, output_for_t0
-
-       USE ocean_mod,                                                          &
-           ONLY:  ocean_rrd_global
-
-       USE particle_attributes,                                                &
-           ONLY:  curvature_solution_effects
-
-       USE pegrid
-
-       USE radiation_model_mod,                                                &
-           ONLY:  time_radiation
-
-       USE spectra_mod,                                                        &
-           ONLY:  average_count_sp, spectrum_x, spectrum_y
-
-       USE statistics,                                                         &
-           ONLY:  statistic_regions, hom, hom_sum, pr_palm, u_max, u_max_ijk,  &
-                  v_max, v_max_ijk, w_max, w_max_ijk, z_i
-
-       USE synthetic_turbulence_generator_mod,                                 &
-           ONLY: stg_rrd_global
-
-       USE user_read_restart_data_mod,                                         &
-           ONLY:  user_rrd_global 
-
-       USE vertical_nesting_mod,                                               &
-           ONLY:  vnest_init
-
-       USE wind_turbine_model_mod,                                             &
-           ONLY: wtm_rrd_global
-
-
-       IMPLICIT NONE
 
        CHARACTER (LEN=10) ::  binary_version_global, version_on_file
@@ -772,13 +774,5 @@
 !
 !--             Read global variables from of other modules
-                IF ( .NOT. found )  CALL bcm_rrd_global( found )
-                IF ( .NOT. found )  CALL flight_rrd_global( found )
-                IF ( .NOT. found )  CALL gust_rrd_global( found )
-                IF ( .NOT. found )  CALL ocean_rrd_global( found )
-                IF ( .NOT. found )  CALL stg_rrd_global ( found )
-                IF ( .NOT. found )  CALL wtm_rrd_global( found )
-!
-!--             Read user-defined global variables
-                IF ( .NOT. found )  CALL user_rrd_global( found )
+                CALL module_interface_rrd_global( restart_string(1:length), found )
 
                 IF ( .NOT. found )  THEN
@@ -818,19 +812,4 @@
     SUBROUTINE rrd_read_parts_of_global
 
-
-       USE arrays_3d,                                                          &
-           ONLY:  ref_state
-
-       USE indices,                                                            &
-           ONLY:  nz, nx_on_file, ny_on_file
-
-       USE kinds
-
-       USE pegrid
-
-       USE statistics,                                                         &
-           ONLY:  statistic_regions, hom, hom_sum, pr_palm
-
-       IMPLICIT NONE
 
        CHARACTER (LEN=10) ::  version_on_file
@@ -959,5 +938,5 @@
                    WRITE( message_string, * ) 'inflow profiles not ',          &
                                   'temporally averaged. &Averaging will be ',  &
-                                  'done now using', average_count_pr,          & 
+                                  'done now using', average_count_pr,          &
                                   ' samples.'
                    CALL message( 'rrd_read_parts_of_global', 'PA0309',         &
@@ -1043,65 +1022,6 @@
 !> (binary format).
 !------------------------------------------------------------------------------!
- SUBROUTINE rrd_local 
- 
-
-    USE arrays_3d,                                                             &
-        ONLY:  e, kh, km, p, pt, q, ql, s, u, u_m_l, u_m_n, u_m_r, u_m_s,      &
-               v, v_m_l, v_m_n, v_m_r, v_m_s, vpt, w, w_m_l, w_m_n, w_m_r, w_m_s
-
-    USE bulk_cloud_model_mod,                                                  &
-        ONLY :  bcm_rrd_local
-
-    USE averaging
-
-    USE chemistry_model_mod,                                                   &
-        ONLY:  chem_rrd_local
-
-    USE cpulog,                                                                &
-        ONLY:  cpu_log, log_point_s
-
-    USE gust_mod,                                                              &
-        ONLY :  gust_rrd_local
-
-    USE indices,                                                               &
-        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, nx_on_file, ny, nys, nysg, nyn, &
-               nyng, ny_on_file, nzb, nzt
-
-    USE kinds
-
-    USE land_surface_model_mod,                                                &
-        ONLY:  lsm_rrd_local
-
-    USE ocean_mod,                                                             &
-        ONLY:  ocean_rrd_local
-
-    USE particle_attributes,                                                   &
-        ONLY:  iran_part
-
-    USE pegrid
-
-    USE radiation_model_mod,                                                   &
-        ONLY: radiation_rrd_local
-
-    USE random_function_mod,                                                   &
-        ONLY:  random_iv, random_iy
-
-    USE random_generator_parallel,                                             &
-        ONLY:  id_random_array, seq_random_array
-    
-    USE salsa_mod,                                                             &
-        ONLY:  salsa_rrd_local
-
-    USE surface_mod,                                                           &
-        ONLY :  surface_rrd_local
-        
-    USE urban_surface_mod,                                                     &
-        ONLY:  usm_rrd_local
-
-    USE user_read_restart_data_mod,                                            &
-        ONLY:  user_rrd_local 
- 
-
-    IMPLICIT NONE
+ SUBROUTINE rrd_local
+
 
     CHARACTER (LEN=7)  ::  myid_char_save
@@ -1866,48 +1786,6 @@
 
 !
-!--                Read restart data of other modules
-                   IF ( .NOT. found ) CALL bcm_rrd_local( i, 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 )
-
-                   IF ( .NOT. found ) CALL chem_rrd_local( i, k, nxlf,         &
-                                           nxlc, nxl_on_file, nxrf, nxrc,      &
-                                           nxr_on_file, nynf, nync,            & 
-                                           nyn_on_file, nysf, nysc,            &
-                                           nys_on_file, tmp_3d, found )
-
-                   IF ( .NOT. found ) CALL gust_rrd_local( i, 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 )
-
-                   IF ( .NOT. found ) CALL lsm_rrd_local( i, k, nxlf,          & 
-                                           nxlc, nxl_on_file, nxrf, nxrc,      &
-                                           nxr_on_file, nynf, nync,            &
-                                           nyn_on_file, nysf, nysc,            &
-                                           nys_on_file, tmp_2d, found )
-
-                   IF ( .NOT. found ) CALL ocean_rrd_local( i, 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 )
-
-                   IF ( .NOT. found ) CALL radiation_rrd_local( i, 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 )
-
+!--                Read restart data of surfaces
                    IF ( .NOT. found ) CALL surface_rrd_local( i, k, nxlf,      &
-                                           nxlc, nxl_on_file, nxrf, nxrc,      &
-                                           nxr_on_file, nynf, nync,            & 
-                                           nyn_on_file, nysf, nysc,            &
-                                           nys_on_file, found )
-
-                   IF ( .NOT. found ) CALL usm_rrd_local( i, k, nxlf,          &
                                            nxlc, nxl_on_file, nxrf, nxrc,      &
                                            nxr_on_file, nynf, nync,            &
@@ -1915,17 +1793,13 @@
                                            nys_on_file, found )
 
-                   IF ( .NOT. found  .AND.  salsa )  CALL salsa_rrd_local( i,  &
-                                           k, nxlf, nxlc, nxl_on_file, nxrf,   &
-                                           nxrc, nxr_on_file, nynf, nync,      & 
-                                           nyn_on_file, nysf, nysc,            &
-                                           nys_on_file, tmp_3d, found )                                        
-
-!
-!--                Read user-defined restart data
-                   IF ( .NOT. found ) CALL user_rrd_local( i, k, nxlf,         &
-                                           nxlc, nxl_on_file, nxrf, nxrc,      &
-                                           nxr_on_file, nynf, nync,            &
-                                           nyn_on_file, nysf, nysc,            &
-                                           nys_on_file, tmp_3d, found )
+!
+!--                Read restart data of other modules
+                   IF ( .NOT. found ) CALL module_interface_rrd_local(         &
+                                           restart_string(1:length), i, 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 )
 
 
@@ -1994,6 +1868,4 @@
 
 
-       IMPLICIT NONE
-
        CHARACTER (LEN=1) ::  cdum
 
@@ -2005,5 +1877,5 @@
 
           READ ( 13 )  cdum
-          READ ( 13 )  length 
+          READ ( 13 )  length
           READ ( 13 )  restart_string(1:length)
 
Index: palm/trunk/SOURCE/salsa_mod.f90
===================================================================
--- palm/trunk/SOURCE/salsa_mod.f90	(revision 3636)
+++ palm/trunk/SOURCE/salsa_mod.f90	(revision 3637)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3636 2018-12-19 13:48:34Z raasch
 ! nopointer option removed
 ! 
@@ -91,5 +94,5 @@
 
     USE control_parameters
-        
+
     USE indices,                                                               &
         ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb,  &
@@ -1956,4 +1959,5 @@
     INTEGER(iwp) ::  g  !<
 
+    IF ( simulated_time >= time_since_reference_point )  THEN
 
     SELECT CASE ( mod_count )
@@ -2010,4 +2014,6 @@
 
     END SELECT
+
+    ENDIF
 
  END SUBROUTINE salsa_swap_timelevel
Index: palm/trunk/SOURCE/sum_up_3d_data.f90
===================================================================
--- palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3636)
+++ palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3597 2018-12-04 08:40:18Z maronga
 ! Added output of theta_2m
 ! 
@@ -259,16 +262,9 @@
         ONLY:  c_p, lv_d_cp, l_v
 
-    USE biometeorology_mod,                                                    &
-        ONLY:  bio_3d_data_averaging
-
     USE bulk_cloud_model_mod,                                                  &
-        ONLY:  bulk_cloud_model, bcm_3d_data_averaging
-
-    USE chemistry_model_mod,                                                   &
-        ONLY:  chem_3d_data_averaging
+        ONLY:  bulk_cloud_model
 
     USE control_parameters,                                                    &
-        ONLY:  air_chemistry, average_count_3d, biometeorology, doav, doav_n,  &
-               land_surface, ocean_mode, rho_surface, salsa, urban_surface,    &
+        ONLY:  average_count_3d, doav, doav_n, rho_surface, urban_surface,     &
                varnamelength
 
@@ -276,7 +272,4 @@
         ONLY:  cpu_log, log_point
 
-    USE gust_mod,                                                              &
-        ONLY:  gust_3d_data_averaging, gust_module_enabled
-
     USE indices,                                                               &
         ONLY:  nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt 
@@ -284,18 +277,9 @@
     USE kinds
 
-    USE land_surface_model_mod,                                                &
-        ONLY:  lsm_3d_data_averaging
-
-    USE ocean_mod,                                                             &
-        ONLY:  ocean_3d_data_averaging
+    USE module_interface,                                                      &
+        ONLY:  module_interface_3d_data_averaging
 
     USE particle_attributes,                                                   &
         ONLY:  grid_particles, number_of_particles, particles, prt_count
-
-    USE radiation_model_mod,                                                   &
-        ONLY:  radiation, radiation_3d_data_averaging
-         
-    USE salsa_mod,                                                             &
-        ONLY:  salsa_3d_data_averaging          
 
     USE surface_mod,                                                           &
@@ -307,5 +291,5 @@
 
     USE urban_surface_mod,                                                     &
-        ONLY:  usm_average_3d_data
+        ONLY:  usm_3d_data_averaging
 
 
@@ -535,48 +519,11 @@
 
 !
-!--             Allocating and initializing data arrays for other modules
-
-                IF ( air_chemistry  .AND. &
-                     (trimvar(1:3) == 'kc_' .OR. trimvar(1:3) == 'em_') )  THEN
-                   CALL chem_3d_data_averaging( 'allocate', doav(ii) )
-                ENDIF
-
-                IF ( bulk_cloud_model )  THEN
-                   CALL bcm_3d_data_averaging( 'allocate', doav(ii) )
-                ENDIF
-
-                IF ( gust_module_enabled )  THEN
-                   CALL gust_3d_data_averaging( 'allocate', doav(ii) )
-                ENDIF
-
-                IF ( biometeorology )  THEN
-                   CALL bio_3d_data_averaging( 'allocate', doav(ii) )
-                ENDIF
-
-                IF ( land_surface )  THEN
-                   CALL lsm_3d_data_averaging( 'allocate', doav(ii) )
-                ENDIF
-
-                IF ( ocean_mode )  THEN
-                   CALL ocean_3d_data_averaging( 'allocate', doav(ii) )
-                ENDIF
-
-                IF ( radiation )  THEN
-                   CALL radiation_3d_data_averaging( 'allocate', doav(ii) )
-                ENDIF
-
-                IF ( salsa )  THEN
-                   CALL salsa_3d_data_averaging( 'allocate', doav(ii) )
-                ENDIF                
-
-                CALL tcm_3d_data_averaging( 'allocate', doav(ii) )
-
-                IF ( urban_surface  .AND.  trimvar(1:4) == 'usm_' )  THEN
-                   CALL usm_average_3d_data( 'allocate', doav(ii) )
-                ENDIF
-
-!
-!--             User-defined quantities
-                CALL user_3d_data_averaging( 'allocate', doav(ii) )
+!--             Allocating and initializing data arrays for turbulence closure module
+                CALL tcm_3d_data_averaging( 'allocate', trimvar )
+
+!
+!--             Allocating and initializing data arrays for all other modules
+                CALL module_interface_3d_data_averaging( 'allocate', trimvar )
+
 
           END SELECT
@@ -1183,52 +1130,20 @@
 
           CASE DEFAULT
-!
-!--          Summing up data from other modules
-             IF ( bulk_cloud_model )  THEN
-                CALL bcm_3d_data_averaging( 'sum', doav(ii) )
-             ENDIF
-
-             IF ( air_chemistry  .AND. &
-                  (trimvar(1:3) == 'kc_' .OR. trimvar(1:3) == 'em_') )  THEN
-                CALL chem_3d_data_averaging( 'sum',doav(ii) )
-             ENDIF
-
-             IF ( gust_module_enabled )  THEN
-                CALL gust_3d_data_averaging( 'sum', doav(ii) )
-             ENDIF
-
-             IF ( biometeorology )  THEN
-                CALL bio_3d_data_averaging( 'sum', doav(ii) )
-             ENDIF
-
-             IF ( land_surface )  THEN
-                CALL lsm_3d_data_averaging( 'sum', doav(ii) )
-             ENDIF
-
-             IF ( ocean_mode )  THEN
-                CALL ocean_3d_data_averaging( 'sum', doav(ii) )
-             ENDIF
-
-             IF ( radiation )  THEN
-                CALL radiation_3d_data_averaging( 'sum', doav(ii) )
-             ENDIF
-
-             IF ( salsa )  THEN
-                CALL salsa_3d_data_averaging( 'sum', doav(ii) )
-             ENDIF                 
-
-             CALL tcm_3d_data_averaging( 'sum', doav(ii) )
 
 !--          In case of urban surface variables it should be always checked
 !--          if respective arrays are allocated, at least in case of a restart
 !--          run, as averaged usm arrays are not read from file at the moment.
-             IF ( urban_surface  .AND.  trimvar(1:4) == 'usm_' )  THEN
-                CALL usm_average_3d_data( 'allocate', doav(ii) )
-                CALL usm_average_3d_data( 'sum', doav(ii) )
-             ENDIF
-
-!
-!--          User-defined quantities
-             CALL user_3d_data_averaging( 'sum', doav(ii) )
+             IF ( urban_surface )  THEN
+                CALL usm_3d_data_averaging( 'allocate', trimvar )
+             ENDIF
+
+!
+!--          Summing up data from turbulence closure module
+             CALL tcm_3d_data_averaging( 'sum', trimvar )
+
+!
+!--          Summing up data from all other modules
+             CALL module_interface_3d_data_averaging( 'sum', trimvar )
+
 
        END SELECT
Index: palm/trunk/SOURCE/swap_timelevel.f90
===================================================================
--- palm/trunk/SOURCE/swap_timelevel.f90	(revision 3636)
+++ palm/trunk/SOURCE/swap_timelevel.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3636 2018-12-19 13:48:34Z raasch
 ! nopointer option removed
 ! 
@@ -151,43 +154,25 @@
                v, v_1, v_2, v_p, w, w_1, w_2, w_p
 
-    USE bulk_cloud_model_mod,                                                  &
-        ONLY:  bulk_cloud_model, bcm_swap_timelevel
-
-    USE chemistry_model_mod,                                                   &
-        ONLY:  chem_swap_timelevel 
-
     USE cpulog,                                                                &
         ONLY: cpu_log, log_point
 
     USE control_parameters,                                                    &
-        ONLY:  air_chemistry, humidity, land_surface, neutral, ocean_mode,     &
-               passive_scalar, simulated_time, timestep_count, urban_surface,  &
-               time_since_reference_point, salsa
-
-    USE gust_mod,                                                              &
-        ONLY: gust_module_enabled, gust_swap_timelevel
-
-    USE land_surface_model_mod,                                                &
-        ONLY: lsm_swap_timelevel
-
-    USE ocean_mod,                                                             &
-        ONLY:  ocean_swap_timelevel
+        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 salsa_mod,                                                             &
-        ONLY:  salsa_swap_timelevel, skip_time_do_salsa             
 
     USE turbulence_closure_mod,                                                &
         ONLY:  tcm_swap_timelevel
 
-    USE urban_surface_mod,                                                     &
-        ONLY:  usm_swap_timelevel
-
 
     IMPLICIT NONE
 
-    INTEGER ::  swap_level  !> swap_level for steering the pmc data transfer
+    INTEGER(iwp) ::  swap_level  !> swap_level for steering the pmc data transfer
 
 !
@@ -237,31 +222,11 @@
     END SELECT
 
-    IF ( humidity  .AND.  bulk_cloud_model )  THEN
-       CALL bcm_swap_timelevel( MOD( timestep_count, 2) )
-    ENDIF
-
-    IF ( air_chemistry )  CALL chem_swap_timelevel( MOD( timestep_count, 2) )
-
-    IF ( gust_module_enabled )  THEN
-       CALL gust_swap_timelevel( MOD( timestep_count, 2) )
-    ENDIF
-
-    IF ( land_surface )  THEN
-       CALL lsm_swap_timelevel( MOD( timestep_count, 2) )
-    ENDIF
-
-    IF ( ocean_mode )  THEN
-       CALL ocean_swap_timelevel( MOD( timestep_count, 2 ) )
-    ENDIF
-   
-    IF ( salsa  .AND.  simulated_time >= time_since_reference_point )  THEN
-       CALL salsa_swap_timelevel(  MOD( timestep_count, 2 ) )
-    ENDIF     
-
+!
+!-- Set the swap level the turbulence closure module
     CALL tcm_swap_timelevel( MOD( timestep_count, 2) )
 
-    IF ( urban_surface )  THEN
-       CALL usm_swap_timelevel( MOD( timestep_count, 2) )
-    ENDIF
+!
+!-- Set the swap level for all other modules
+    CALL module_interface_swap_timelevel( MOD( timestep_count, 2) )
 
 !
Index: palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3636)
+++ palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3637)
@@ -28,4 +28,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3636 2018-12-19 13:48:34Z raasch
 ! nopointer option removed
 ! 
@@ -52,5 +55,5 @@
 ! 
 ! 3449 2018-10-29 19:36:56Z suehring
-! Bugfix: Fix average arrays allocations in usm_average_3d_data (J.Resler)
+! Bugfix: Fix average arrays allocations in usm_3d_data_averaging (J.Resler)
 ! Bugfix: Fix reading wall temperatures (J.Resler)
 ! Bugfix: Fix treating of outputs for wall temperature and sky view factors (J.Resler)
@@ -182,5 +185,5 @@
 ! 2906 2018-03-19 08:56:40Z Giersch
 ! Local variable ids has to be initialized with a value of -1 in 
-! usm_average_3d_data
+! usm_3d_data_averaging
 ! 
 ! 2894 2018-03-15 09:17:58Z Giersch
@@ -1125,7 +1128,7 @@
     END INTERFACE usm_allocate_surface
 
-    INTERFACE usm_average_3d_data
-       MODULE PROCEDURE usm_average_3d_data
-    END INTERFACE usm_average_3d_data
+    INTERFACE usm_3d_data_averaging
+       MODULE PROCEDURE usm_3d_data_averaging
+    END INTERFACE usm_3d_data_averaging
 
     
@@ -1138,5 +1141,5 @@
            usm_rrd_local,                                                      & 
            usm_surface_energy_balance, usm_material_heat_model,                &
-           usm_swap_timelevel, usm_check_data_output, usm_average_3d_data,     &
+           usm_swap_timelevel, usm_check_data_output, usm_3d_data_averaging,   &
            usm_data_output_3d, usm_define_netcdf_grid, usm_parin,              &
            usm_wrd_local, usm_allocate_surface
@@ -1563,5 +1566,5 @@
 !> the array necessary for storing the average.
 !------------------------------------------------------------------------------!
-    SUBROUTINE usm_average_3d_data( mode, variable )
+    SUBROUTINE usm_3d_data_averaging( mode, variable )
 
         IMPLICIT NONE
@@ -1575,4 +1578,6 @@
         CHARACTER(LEN=6), DIMENSION(0:nd-1), PARAMETER     :: dirname = (/ '_roof ', '_south', '_north', '_west ', '_east ' /)
         INTEGER(iwp), DIMENSION(0:nd-1), PARAMETER         :: dirint = (/ iup_u, isouth_u, inorth_u, iwest_u, ieast_u /)
+
+        IF ( variable(1:4) == 'usm_' )  THEN  ! is such a check really rquired?
 
 !--     find the real name of the variable
@@ -2447,5 +2452,7 @@
         ENDIF
 
-    END SUBROUTINE usm_average_3d_data
+        ENDIF
+
+    END SUBROUTINE usm_3d_data_averaging
 
 
Index: palm/trunk/SOURCE/write_restart_data_mod.f90
===================================================================
--- palm/trunk/SOURCE/write_restart_data_mod.f90	(revision 3636)
+++ palm/trunk/SOURCE/write_restart_data_mod.f90	(revision 3637)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Implementation of the PALM module interface
+! 
+! 3589 2018-11-30 15:09:51Z suehring
 ! Move the control parameter "salsa" from salsa_mod to control_parameters 
 ! (M. Kurppa)
@@ -69,11 +72,64 @@
 
 
+    USE arrays_3d,                                                          &
+        ONLY:  inflow_damping_factor, mean_inflow_profiles, pt_init,        &
+               q_init, ref_state, s_init, u_init, ug, v_init, vg,           &
+               e, kh, km, p, pt, q, ql, s, u, u_m_l, u_m_n, u_m_r,          &
+               u_m_s, v, v_m_l, v_m_n, v_m_r, v_m_s, vpt, w, w_m_l, w_m_n,  &
+               w_m_r, w_m_s
+
+    USE averaging
+
     USE control_parameters
- 
-    USE kinds     
+
+    USE date_and_time_mod,                                                     &
+        ONLY:  day_of_year_init, time_utc_init
+
+    USE grid_variables,                                                        &
+        ONLY:  dx, dy
+
+    USE indices,                                                               &
+        ONLY:  nx, nxl, nxr, ny, nys, nyn, nz, nzb, nzt
+
+    USE kinds
+
+    USE model_1d_mod,                                                          &
+        ONLY:  damp_level_1d, dt_pr_1d, dt_run_control_1d, end_time_1d
+
+    USE module_interface,                                                      &
+        ONLY:  module_interface_wrd_global,                                    &
+               module_interface_wrd_local
+
+    USE netcdf_interface,                                                      &
+        ONLY:  netcdf_precision, output_for_t0
+
+    USE particle_attributes,                                                   &
+        ONLY:  curvature_solution_effects, iran_part
 
     USE pegrid,                                                                &
-        ONLY:  myid, numprocs
-     
+        ONLY:  collective_wait, hor_index_bounds, myid, numprocs
+
+    USE radiation_model_mod,                                                   &
+        ONLY:  time_radiation
+
+    USE random_function_mod,                                                   &
+        ONLY:  random_iv, random_iy
+
+    USE random_generator_parallel,                                             &
+        ONLY:  id_random_array, seq_random_array
+
+    USE spectra_mod,                                                           &
+        ONLY:  average_count_sp, spectrum_x, spectrum_y
+
+    USE statistics,                                                            &
+        ONLY:  statistic_regions, hom, hom_sum, u_max, u_max_ijk, v_max,       &
+               v_max_ijk, w_max, w_max_ijk, z_i
+
+    USE surface_mod,                                                           &
+        ONLY :  surface_wrd_local
+
+    USE vertical_nesting_mod,                                                  &
+        ONLY:  vnest_init
+
 
     IMPLICIT NONE
@@ -103,66 +159,4 @@
     SUBROUTINE wrd_global
 
-
-       USE arrays_3d,                                                          &
-           ONLY:  inflow_damping_factor, mean_inflow_profiles, pt_init,        &
-                  q_init, ref_state, s_init, u_init, ug, v_init, vg
-
-       USE bulk_cloud_model_mod,                                               &
-           ONLY:  bulk_cloud_model, bcm_wrd_global
-
-       USE date_and_time_mod,                                                  &
-           ONLY:  day_of_year_init, time_utc_init
-
-       USE flight_mod,                                                         &
-           ONLY:  flight_wrd_global
-
-       USE grid_variables,                                                     &
-           ONLY:  dx, dy
-
-       USE gust_mod,                                                           &
-           ONLY :  gust_module_enabled, gust_wrd_global
-
-       USE indices,                                                            &
-           ONLY:  nx, ny, nz
-
-       USE model_1d_mod,                                                       &
-           ONLY:  damp_level_1d, dt_pr_1d, dt_run_control_1d, end_time_1d
-
-       USE netcdf_interface,                                                   &
-           ONLY:  netcdf_precision, output_for_t0
-
-       USE ocean_mod,                                                          &
-           ONLY:  ocean_wrd_global
-
-       USE particle_attributes,                                                &
-           ONLY:  curvature_solution_effects
-
-       USE pegrid,                                                             &
-           ONLY:  hor_index_bounds, collective_wait                                
-
-       USE radiation_model_mod,                                                &
-           ONLY:  time_radiation
-
-       USE spectra_mod,                                                        &
-           ONLY:  average_count_sp, spectrum_x, spectrum_y
-
-       USE synthetic_turbulence_generator_mod,                                 &
-           ONLY:  stg_wrd_global
-
-       USE statistics,                                                         &
-           ONLY:  statistic_regions, hom, hom_sum, u_max, u_max_ijk, v_max,    &
-                  v_max_ijk, w_max, w_max_ijk, z_i
-
-       USE user_write_restart_data_mod,                                        &
-           ONLY:  user_wrd_global 
-
-       USE vertical_nesting_mod,                                               &
-           ONLY:  vnest_init
-
-       USE wind_turbine_model_mod,                                             &
-           ONLY:  wtm_wrd_global
-     
-
-       IMPLICIT NONE
 
        CHARACTER (LEN=10)  ::  binary_version_global   !<
@@ -886,15 +880,5 @@
 !
 !--    Write restart data of the other modules
-!--    The order of the calls can be different as in read_restart_data_mod where
-!--    the restart data will be read
-       IF ( bulk_cloud_model )     CALL bcm_wrd_global
-       IF ( virtual_flight )       CALL flight_wrd_global
-       IF ( gust_module_enabled )  CALL gust_wrd_global
-       IF ( ocean_mode )           CALL ocean_wrd_global
-       IF ( syn_turb_gen )         CALL stg_wrd_global
-       IF ( wind_turbine )         CALL wtm_wrd_global
-!
-!--    Write restart data of the user-interface
-       CALL user_wrd_global
+       CALL module_interface_wrd_global
 
 
@@ -910,60 +894,7 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE wrd_local
- 
-
-       USE arrays_3d,                                                          &
-           ONLY:  e, kh, km, p, pt, q, ql, s, u, u_m_l, u_m_n, u_m_r,          &
-                  u_m_s, v, v_m_l, v_m_n, v_m_r, v_m_s, vpt, w, w_m_l, w_m_n,  &
-                  w_m_r, w_m_s
-        
-       USE averaging
-
-       USE bulk_cloud_model_mod,                                               &
-           ONLY:  bulk_cloud_model, bcm_wrd_local
-
-       USE chemistry_model_mod,                                                &
-           ONLY:  chem_wrd_local
-
-       USE gust_mod,                                                           &
-           ONLY :  gust_module_enabled, gust_wrd_local
-                
-       USE indices,                                                            &
-           ONLY:  nxl, nxr, nys, nyn, nzb, nzt
-
-       USE land_surface_model_mod,                                             &
-           ONLY:  lsm_wrd_local
-
-       USE ocean_mod,                                                          &
-           ONLY:  ocean_wrd_local
-
-       USE particle_attributes,                                                &
-           ONLY:  iran_part
-
-       USE radiation_model_mod,                                                &
-           ONLY:  radiation, radiation_wrd_local
-    
-       USE random_function_mod,                                                &
-           ONLY:  random_iv, random_iy
-
-       USE random_generator_parallel,                                          &
-           ONLY:  id_random_array, seq_random_array
-              
-       USE salsa_mod,                                                          &
-           ONLY:  salsa_wrd_local          
-
-       USE surface_mod,                                                        &
-           ONLY :  surface_wrd_local
-
-       USE urban_surface_mod,                                                  &
-           ONLY:  usm_wrd_local    
-
-       USE user_write_restart_data_mod,                                        &
-           ONLY:  user_wrd_local 
-
-
-       IMPLICIT NONE
+
 
        CHARACTER (LEN=10) ::  binary_version_local   !< 
-
 
 !
@@ -1271,19 +1202,10 @@
        ENDIF
 
+
+       CALL surface_wrd_local
+
 !
 !--    Write restart data of other modules
-       IF ( bulk_cloud_model )     CALL bcm_wrd_local
-       IF ( air_chemistry )        CALL chem_wrd_local
-       IF ( gust_module_enabled )  CALL gust_wrd_local
-       IF ( land_surface )         CALL lsm_wrd_local
-       IF ( ocean_mode )           CALL ocean_wrd_local
-       IF ( radiation )            CALL radiation_wrd_local
-       IF ( salsa )                CALL salsa_wrd_local
-       CALL surface_wrd_local
-       IF ( urban_surface )        CALL usm_wrd_local
-
-!
-!--    Write user-defined restart data
-       CALL user_wrd_local
+       CALL module_interface_wrd_local
 
 !
