Index: /palm/trunk/SOURCE/Makefile
===================================================================
--- /palm/trunk/SOURCE/Makefile	(revision 3273)
+++ /palm/trunk/SOURCE/Makefile	(revision 3274)
@@ -461,7 +461,7 @@
 	advec_w_up.f90 \
 	average_3d_data.f90 \
+	basic_constants_and_equations_mod.f90 \
 	boundary_conds.f90 \
 	buoyancy.f90 \
-	calc_liquid_water_content.f90 \
 	calc_mean_profile.f90 \
 	calc_radiation.f90 \
@@ -488,5 +488,4 @@
 	data_output_tseries.f90 \
 	date_and_time_mod.f90 \
-	diagnostic_quantities_mod.f90 \
 	diffusion_s.f90 \
 	diffusion_u.f90 \
@@ -506,5 +505,4 @@
 	init_3d_model.f90 \
 	init_advec.f90 \
-	init_cloud_physics.f90 \
 	init_coupling.f90 \
 	init_dvrp.f90 \
@@ -542,5 +540,5 @@
 	lpm_write_restart_file.f90 \
 	message.f90 \
-	microphysics_mod.f90 \
+	bulk_cloud_model_mod.f90 \
 	model_1d_mod.f90 \
 	mod_kinds.f90 \
@@ -691,4 +689,5 @@
 	modules.o
 advec_ws.o: \
+	bulk_cloud_model_mod.o \
 	mod_kinds.o \
 	modules.o
@@ -700,4 +699,5 @@
 	modules.o
 average_3d_data.o: \
+	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	cpulog_mod.o \
@@ -710,5 +710,9 @@
 	turbulence_closure_mod.o \
 	urban_surface_mod.o
+basic_constants_and_equations_mod.o: \
+	mod_kinds.o
 boundary_conds.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	mod_kinds.o \
@@ -717,5 +721,12 @@
 	surface_mod.o \
 	turbulence_closure_mod.o
+bulk_cloud_model_mod.o: \
+	basic_constants_and_equations_mod.o \
+	cpulog_mod.o \
+	mod_kinds.o \
+	modules.o \
+	surface_mod.o
 buoyancy.o: \
+	basic_constants_and_equations_mod.o \
 	mod_kinds.o \
 	modules.o
@@ -723,9 +734,6 @@
 	mod_kinds.o \
 	modules.o
-calc_liquid_water_content.o: \
-	diagnostic_quantities_mod.o \
-	mod_kinds.o \
-	modules.o
 calc_radiation.o: \
+	basic_constants_and_equations_mod.o \
 	mod_kinds.o \
 	modules.o
@@ -741,9 +749,10 @@
 	posix_calls_from_fortran.o
 check_parameters.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	gust_mod.o \
 	land_surface_model_mod.o \
 	large_scale_forcing_nudging_mod.o \
-	microphysics_mod.o \
 	model_1d_mod.o \
 	mod_kinds.o \
@@ -778,4 +787,5 @@
 	modules.o
 chem_photolysis_mod.o: \
+	basic_constants_and_equations_mod.o \
 	chem_gasphase_mod.o \
 	chemistry_model_mod.o \
@@ -788,4 +798,6 @@
 	netcdf_interface_mod.o
 compute_vpt.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	mod_kinds.o \
 	modules.o
@@ -803,8 +815,12 @@
 	modules.o
 data_output_dvrp.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	cpulog_mod.o \
 	mod_kinds.o \
 	modules.o
 data_output_mask.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	cpulog_mod.o \
 	mod_kinds.o \
@@ -824,4 +840,5 @@
 	netcdf_interface_mod.o
 data_output_spectra.o: \
+	basic_constants_and_equations_mod.o \
 	cpulog_mod.o \
 	mod_kinds.o \
@@ -841,4 +858,6 @@
 	virtual_flight_mod.o
 data_output_2d.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	cpulog_mod.o \
 	gust_mod.o \
@@ -853,4 +872,6 @@
 	uv_exposure_model_mod.o
 data_output_3d.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	cpulog_mod.o \
@@ -866,7 +887,4 @@
 	mod_kinds.o \
 	modules.o
-diagnostic_quantities_mod.o: \
-	mod_kinds.o \
-	modules.o
 diffusion_s.o: \
 	mod_kinds.o \
@@ -916,4 +934,6 @@
 	temperton_fft_mod.o
 flow_statistics.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	cpulog_mod.o \
 	gust_mod.o \
@@ -932,4 +952,6 @@
 	modules.o
 header.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	cpulog_mod.o \
 	date_and_time_mod.o \
@@ -937,5 +959,4 @@
 	land_surface_model_mod.o \
 	large_scale_forcing_nudging_mod.o \
-	microphysics_mod.o \
 	model_1d_mod.o \
 	mod_kinds.o \
@@ -956,4 +977,6 @@
 init_3d_model.o: \
 	advec_ws.o \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	cpulog_mod.o \
@@ -963,5 +986,4 @@
 	large_scale_forcing_nudging_mod.o \
 	lpm_init.o \
-	microphysics_mod.o \
 	model_1d_mod.o \
 	mod_kinds.o \
@@ -987,7 +1009,4 @@
 	mod_kinds.o \
 	modules.o
-init_cloud_physics.o: \
-	mod_kinds.o \
-	modules.o
 init_coupling.o: \
 	mod_kinds.o \
@@ -1007,8 +1026,10 @@
 	vertical_nesting_mod.o
 init_masks.o: \
+	bulk_cloud_model_mod.o \
 	mod_kinds.o \
 	modules.o \
 	netcdf_interface_mod.o
 init_ocean.o: \
+	basic_constants_and_equations_mod.o \
 	eqn_state_seawater.o \
 	mod_kinds.o \
@@ -1024,15 +1045,19 @@
 	modules.o
 init_rankine.o: \
+	basic_constants_and_equations_mod.o \
 	mod_kinds.o \
 	modules.o
 init_slope.o: \
+	basic_constants_and_equations_mod.o \
 	mod_kinds.o \
 	modules.o
 interaction_droplets_ptq.o: \
+	basic_constants_and_equations_mod.o \
 	mod_kinds.o \
 	modules.o
 land_surface_model_mod.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	calc_mean_profile.o \
-	diagnostic_quantities_mod.o \
 	mod_kinds.o \
 	modules.o \
@@ -1073,4 +1098,5 @@
 	pmc_particle_interface.o
 lpm_advec.o: \
+	basic_constants_and_equations_mod.o \
 	cpulog_mod.o \
 	mod_kinds.o \
@@ -1085,4 +1111,5 @@
 	surface_mod.o
 lpm_calc_liquid_water_content.o: \
+	basic_constants_and_equations_mod.o \
 	cpulog_mod.o \
 	mod_kinds.o \
@@ -1090,4 +1117,5 @@
 	modules.o
 lpm_collision_kernels.o: \
+	basic_constants_and_equations_mod.o \
 	cpulog_mod.o \
 	mod_kinds.o \
@@ -1102,4 +1130,5 @@
 	netcdf_interface_mod.o
 lpm_droplet_collision.o: \
+	basic_constants_and_equations_mod.o \
 	cpulog_mod.o \
 	lpm_collision_kernels.o \
@@ -1108,6 +1137,6 @@
 	modules.o
 lpm_droplet_condensation.o: \
-	cpulog_mod.o \
-	diagnostic_quantities_mod.o \
+	basic_constants_and_equations_mod.o \
+	cpulog_mod.o \
 	lpm_collision_kernels.o \
 	mod_kinds.o \
@@ -1122,5 +1151,5 @@
 	netcdf_interface_mod.o
 lpm_init.o: \
-	diagnostic_quantities_mod.o \
+	basic_constants_and_equations_mod.o \
 	lpm_collision_kernels.o \
 	lpm_exchange_horiz.o \
@@ -1160,4 +1189,5 @@
 	modules.o
 lpm_splitting.o: \
+	basic_constants_and_equations_mod.o \
 	cpulog_mod.o \
 	lpm_exchange_horiz.o \
@@ -1178,11 +1208,6 @@
 	modules.o \
 	pmc_interface_mod.o
-microphysics_mod.o: \
-	cpulog_mod.o \
-	diagnostic_quantities_mod.o \
-	mod_kinds.o \
-	modules.o \
-	surface_mod.o
 model_1d_mod.o: \
+	basic_constants_and_equations_mod.o \
 	mod_kinds.o \
 	modules.o
@@ -1190,4 +1215,5 @@
 	mod_kinds.o
 multi_agent_system_mod.o: \
+	basic_constants_and_equations_mod.o \
 	chemistry_model_mod.o \
 	cpulog_mod.o \
@@ -1206,4 +1232,5 @@
 	surface_mod.o
 netcdf_interface_mod.o: \
+	basic_constants_and_equations_mod.o \
 	chemistry_model_mod.o \
 	gust_mod.o \
@@ -1225,4 +1252,5 @@
 	modules.o
 palm.o: \
+	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	chem_photolysis_mod.o \
@@ -1238,4 +1266,5 @@
 	write_restart_data_mod.o
 parin.o: \
+	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	chem_modules.o \
@@ -1244,5 +1273,4 @@
 	gust_mod.o \
 	land_surface_model_mod.o \
-	microphysics_mod.o \
 	model_1d_mod.o \
 	mod_kinds.o \
@@ -1263,4 +1291,5 @@
 	wind_turbine_model_mod.o
 plant_canopy_model_mod.o: \
+	bulk_cloud_model_mod.o \
 	mod_kinds.o \
 	modules.o \
@@ -1276,4 +1305,5 @@
 	pmc_parent_mod.o
 pmc_interface_mod.o: \
+	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	chem_modules.o \
@@ -1344,4 +1374,5 @@
 	advec_ws.o \
 	advec_w_up.o \
+	bulk_cloud_model_mod.o \
 	buoyancy.o \
 	calc_radiation.o \
@@ -1358,5 +1389,4 @@
 	eqn_state_seawater.o \
 	large_scale_forcing_nudging_mod.o \
-	microphysics_mod.o \
 	mod_kinds.o \
 	mod_kinds.o \
@@ -1375,7 +1405,8 @@
 	modules.o
 radiation_model_mod.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	calc_mean_profile.o \
 	date_and_time_mod.o \
-	microphysics_mod.o \
 	mod_particle_attributes.o \
 	modules.o \
@@ -1393,4 +1424,5 @@
 	modules.o
 read_restart_data_mod.o: \
+	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	cpulog_mod.o \
@@ -1398,5 +1430,4 @@
 	gust_mod.o \
 	land_surface_model_mod.o \
-	microphysics_mod.o \
 	modules.o \
 	mod_kinds.o \
@@ -1435,4 +1466,6 @@
 	modules.o
 sum_up_3d_data.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	cpulog_mod.o \
@@ -1447,4 +1480,5 @@
 	uv_exposure_model_mod.o
 surface_coupler.o: \
+	basic_constants_and_equations_mod.o \
 	cpulog_mod.o \
 	mod_kinds.o \
@@ -1452,4 +1486,6 @@
 	surface_mod.o
 surface_layer_fluxes_mod.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	chem_modules.o \
 	exchange_horiz_2d.o \
@@ -1465,4 +1501,5 @@
 	modules.o
 swap_timelevel.o: \
+	bulk_cloud_model_mod.o \
 	chemistry_model_mod.o \
 	cpulog_mod.o \
@@ -1475,4 +1512,5 @@
 	urban_surface_mod.o
 synthetic_turbulence_generator_mod.o: \
+	basic_constants_and_equations_mod.o \
 	cpulog_mod.o \
 	mod_kinds.o \
@@ -1484,4 +1522,5 @@
 time_integration.o: \
 	advec_ws.o \
+	bulk_cloud_model_mod.o \
 	buoyancy.o \
 	calc_mean_profile.o \
@@ -1496,5 +1535,4 @@
 	large_scale_forcing_nudging_mod.o \
 	lpm.o \
-	microphysics_mod.o \
 	mod_kinds.o \
 	modules.o \
@@ -1516,4 +1554,5 @@
 	wind_turbine_model_mod.o
 time_integration_spinup.o: \
+	basic_constants_and_equations_mod.o \
 	cpulog_mod.o \
 	date_and_time_mod.o \
@@ -1528,6 +1567,6 @@
 	mod_kinds.o
 timestep.o: \
-	cpulog_mod.o \
-	microphysics_mod.o \
+	bulk_cloud_model_mod.o \
+	cpulog_mod.o \
 	mod_kinds.o \
 	modules.o \
@@ -1542,4 +1581,5 @@
 	modules.o
 tridia_solver_mod.o: \
+	basic_constants_and_equations_mod.o \
 	mod_kinds.o \
 	modules.o
@@ -1549,6 +1589,7 @@
 	advec_s_up.o \
 	advec_ws.o \
-	cpulog_mod.o \
-	microphysics_mod.o \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
+	cpulog_mod.o \
 	mod_kinds.o \
 	mod_particle_attributes.o \
@@ -1560,4 +1601,5 @@
 	user_actions.o
 urban_surface_mod.o: \
+	basic_constants_and_equations_mod.o \
 	date_and_time_mod.o \
 	mod_kinds.o \
@@ -1706,4 +1748,5 @@
 	user_module.o
 uv_exposure_model_mod.o: \
+	basic_constants_and_equations_mod.o \
 	date_and_time_mod.o \
 	mod_kinds.o \
@@ -1716,4 +1759,6 @@
 	turbulence_closure_mod.o
 virtual_flight_mod.o: \
+	basic_constants_and_equations_mod.o \
+	bulk_cloud_model_mod.o \
 	cpulog_mod.o \
 	mod_kinds.o \
@@ -1723,4 +1768,5 @@
 	user_init_flight.o
 wind_turbine_model_mod.o: \
+	basic_constants_and_equations_mod.o \
 	cpulog_mod.o \
 	mod_kinds.o \
@@ -1729,9 +1775,9 @@
 	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 \
-	microphysics_mod.o \
 	mod_kinds.o \
 	mod_particle_attributes.o \
Index: /palm/trunk/SOURCE/advec_ws.f90
===================================================================
--- /palm/trunk/SOURCE/advec_ws.f90	(revision 3273)
+++ /palm/trunk/SOURCE/advec_ws.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -219,5 +222,14 @@
  MODULE advec_ws
 
- 
+    USE kinds
+
+    IMPLICIT NONE
+
+    REAL(wp) ::  adv_mom_1            !< 1/4 - constant used in 5th-order advection scheme for momentum advection (1st-order part)
+    REAL(wp) ::  adv_mom_3            !< 1/24 - constant used in 5th-order advection scheme for momentum advection (3rd-order part)
+    REAL(wp) ::  adv_mom_5            !< 1/120 - constant used in 5th-order advection scheme for momentum advection (5th-order part)
+    REAL(wp) ::  adv_sca_1            !< 1/2 - constant used in 5th-order advection scheme for scalar advection (1st-order part)
+    REAL(wp) ::  adv_sca_3            !< 1/12 - constant used in 5th-order advection scheme for scalar advection (3rd-order part)
+    REAL(wp) ::  adv_sca_5            !< 1/60 - constant used in 5th-order advection scheme for scalar advection (5th-order part)
 
     PRIVATE
@@ -280,12 +292,7 @@
                   flux_s_v, flux_s_w
 
-       USE constants,                                                          &
-           ONLY:  adv_mom_1, adv_mom_3, adv_mom_5, adv_sca_1, adv_sca_3,       &
-                  adv_sca_5
-
        USE control_parameters,                                                 &
-           ONLY:  cloud_physics, humidity, loop_optimization,                  &
-                  passive_scalar, microphysics_morrison, microphysics_seifert, &
-                  ocean, rans_tke_e, ws_scheme_mom, ws_scheme_sca
+           ONLY:  humidity, loop_optimization, passive_scalar, ocean,          &
+                  rans_tke_e, ws_scheme_mom, ws_scheme_sca
 
        USE indices,                                                            &
@@ -293,5 +300,8 @@
 
        USE kinds
-       
+
+       USE bulk_cloud_model_mod,                                               &
+           ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
+
        USE pegrid
 
@@ -345,5 +355,5 @@
           ENDIF
 
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
              ALLOCATE( sums_wsqcs_ws_l(nzb:nzt+1,0:threads_per_task-1) )
              ALLOCATE( sums_wsncs_ws_l(nzb:nzt+1,0:threads_per_task-1) )
@@ -352,5 +362,5 @@
           ENDIF
 
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
              ALLOCATE( sums_wsqrs_ws_l(nzb:nzt+1,0:threads_per_task-1) )
              ALLOCATE( sums_wsnrs_ws_l(nzb:nzt+1,0:threads_per_task-1) )
@@ -422,5 +432,5 @@
              ENDIF
 
-             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+             IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
                 ALLOCATE( flux_s_qc(nzb+1:nzt,0:threads_per_task-1),           &
                           diss_s_qc(nzb+1:nzt,0:threads_per_task-1),           &
@@ -433,5 +443,5 @@
              ENDIF                  
 
-             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+             IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
                 ALLOCATE( flux_s_qr(nzb+1:nzt,0:threads_per_task-1),           &
                           diss_s_qr(nzb+1:nzt,0:threads_per_task-1),           &
@@ -1074,9 +1084,10 @@
     
        USE control_parameters,                                                 &
-           ONLY:  cloud_physics, humidity, passive_scalar, ocean,              &
-                  microphysics_morrison, microphysics_seifert, ws_scheme_mom,  & 
-                  ws_scheme_sca
+           ONLY:  humidity, passive_scalar, ocean, ws_scheme_mom, ws_scheme_sca
 
        USE kinds
+
+       USE bulk_cloud_model_mod,                                               &
+           ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
 
        USE statistics,                                                         &
@@ -1104,9 +1115,9 @@
           IF ( humidity       )  sums_wsqs_ws_l = 0.0_wp
           IF ( passive_scalar )  sums_wsss_ws_l = 0.0_wp
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
              sums_wsqcs_ws_l = 0.0_wp
              sums_wsncs_ws_l = 0.0_wp
           ENDIF
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
              sums_wsqrs_ws_l = 0.0_wp
              sums_wsnrs_ws_l = 0.0_wp
@@ -1130,7 +1141,4 @@
        USE arrays_3d,                                                          &
            ONLY:  ddzw, drho_air, tend, u, v, w, rho_air_zw
-
-       USE constants,                                                          &
-           ONLY:  adv_sca_1, adv_sca_3, adv_sca_5
 
        USE control_parameters,                                                 &
@@ -1704,7 +1712,4 @@
                   drho_air, rho_air_zw
 
-       USE constants,                                                         &
-           ONLY:  adv_mom_1, adv_mom_3, adv_mom_5
-
        USE control_parameters,                                                &
            ONLY:  intermediate_timestep_count, u_gtrans, v_gtrans
@@ -2202,7 +2207,4 @@
                   drho_air, rho_air_zw
 
-       USE constants,                                                          &
-           ONLY:  adv_mom_1, adv_mom_3, adv_mom_5
-
        USE control_parameters,                                                 &
            ONLY:  intermediate_timestep_count, u_gtrans, v_gtrans
@@ -2707,7 +2709,4 @@
                   drho_air_zw, rho_air
 
-       USE constants,                                                         &
-           ONLY:  adv_mom_1, adv_mom_3, adv_mom_5
-
        USE control_parameters,                                                &
            ONLY:  intermediate_timestep_count, u_gtrans, v_gtrans
@@ -3184,7 +3183,4 @@
        USE arrays_3d,                                                         &
            ONLY:  ddzw, drho_air, tend, u, v, w, rho_air_zw
-
-       USE constants,                                                         &
-           ONLY:  adv_sca_1, adv_sca_3, adv_sca_5
 
        USE control_parameters,                                                &
@@ -3740,7 +3736,4 @@
            ONLY:  ddzw, drho_air, tend, u, v, w, rho_air_zw
 
-       USE constants,                                                          &
-           ONLY:  adv_mom_1, adv_mom_3, adv_mom_5
-
        USE control_parameters,                                                 &
            ONLY:  intermediate_timestep_count, u_gtrans, v_gtrans
@@ -4234,7 +4227,4 @@
            ONLY:  ddzw, drho_air, tend, u, v, w, rho_air_zw
 
-       USE constants,                                                          &
-           ONLY:  adv_mom_1, adv_mom_3, adv_mom_5
-
        USE control_parameters,                                                 &
            ONLY:  intermediate_timestep_count, u_gtrans, v_gtrans
@@ -4738,7 +4728,4 @@
        USE arrays_3d,                                                          &
            ONLY:  ddzu, drho_air_zw, tend, u, v, w, rho_air
-
-       USE constants,                                                          &
-           ONLY:  adv_mom_1, adv_mom_3, adv_mom_5
 
        USE control_parameters,                                                 &
Index: /palm/trunk/SOURCE/average_3d_data.f90
===================================================================
--- /palm/trunk/SOURCE/average_3d_data.f90	(revision 3273)
+++ /palm/trunk/SOURCE/average_3d_data.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3004 2018-04-27 12:33:25Z Giersch
 ! Further allocation checks implemented, case z0q* added
 ! 
@@ -138,4 +141,7 @@
     USE averaging
 
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model, bcm_3d_data_averaging
+
     USE chemistry_model_mod,                                                   &
         ONLY:  chem_3d_data_averaging
@@ -255,26 +261,4 @@
              ENDIF
 
-          CASE ( 'nc' )
-             IF ( ALLOCATED( nc_av ) ) THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      DO  k = nzb, nzt+1
-                         nc_av(k,j,i) = nc_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDIF
-
-          CASE ( 'nr' )
-             IF ( ALLOCATED( nr_av ) ) THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      DO  k = nzb, nzt+1
-                         nr_av(k,j,i) = nr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDIF
-
          CASE ( 'ol*' )
              IF ( ALLOCATED( ol_av ) ) THEN
@@ -320,15 +304,4 @@
              ENDIF
 
-          CASE ( 'prr' )
-             IF ( ALLOCATED( prr_av ) ) THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      DO  k = nzb, nzt+1
-                         prr_av(k,j,i) = prr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDIF
-
           CASE ( 'pt' )
              IF ( ALLOCATED( pt_av ) ) THEN
@@ -353,15 +326,4 @@
              ENDIF
 
-          CASE ( 'qc' )
-             IF ( ALLOCATED( qc_av ) ) THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      DO  k = nzb, nzt+1
-                         qc_av(k,j,i) = qc_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDIF
-
           CASE ( 'ql' )
              IF ( ALLOCATED( ql_av ) ) THEN
@@ -404,15 +366,4 @@
                          ql_vp_av(k,j,i) = ql_vp_av(k,j,i) /                      &
                                            REAL( average_count_3d, KIND=wp )
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDIF
-
-          CASE ( 'qr' )
-             IF ( ALLOCATED( qr_av ) ) THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      DO  k = nzb, nzt+1
-                         qr_av(k,j,i) = qr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
                       ENDDO
                    ENDDO
@@ -607,5 +558,9 @@
 !--          Turbulence closure module
              CALL tcm_3d_data_averaging( 'average', doav(ii) )
-
+!
+!--          microphysics module quantities
+             IF ( bulk_cloud_model )  THEN
+                CALL bcm_3d_data_averaging( 'average', doav(ii) )
+             ENDIF
 !
 !--          Land surface quantity
Index: /palm/trunk/SOURCE/basic_constants_and_equations_mod.f90
===================================================================
--- /palm/trunk/SOURCE/basic_constants_and_equations_mod.f90	(revision 3274)
+++ /palm/trunk/SOURCE/basic_constants_and_equations_mod.f90	(revision 3274)
@@ -0,0 +1,357 @@
+!> @file basic_constants_and_equations_mod.f90
+!------------------------------------------------------------------------------!
+! This file is part of the PALM model system.
+!
+! PALM is free software: you can redistribute it and/or modify it under the
+! terms of the GNU General Public License as published by the Free Software
+! Foundation, either version 3 of the License, or (at your option) any later
+! version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 1997-2018 Leibniz Universitaet Hannover
+!------------------------------------------------------------------------------!
+!
+! Current revisions:
+! -----------------
+! 
+! 
+! Former revisions:
+! -----------------
+! $Id$
+! New module (introduced with modularization of bulk cloud physics model)
+!
+! 
+!
+!
+! Description:
+! ------------
+!> This module contains all basic (physical) constants
+!> and
+!> functions for the calculation of diagnostic quantities.
+!------------------------------------------------------------------------------!
+ MODULE basic_constants_and_equations_mod
+
+
+    USE kinds
+
+    IMPLICIT NONE
+
+    REAL(wp), PARAMETER ::  pi = 3.141592654_wp  !< PI
+
+    REAL(wp), PARAMETER ::  c_p = 1005.0_wp                           !< heat capacity of dry air (J kg-1 K-1)
+    REAL(wp), PARAMETER ::  g = 9.81_wp                               !< gravitational acceleration (m s-2)
+    REAL(wp), PARAMETER ::  kappa = 0.4_wp                            !< von Karman constant
+    REAL(wp), PARAMETER ::  l_m = 0.33E+06_wp                         !< latent heat of water melting (J kg-1)
+    REAL(wp), PARAMETER ::  l_v = 2.5E+06_wp                          !< latent heat of water vaporization (J kg-1)
+    REAL(wp), PARAMETER ::  l_s = l_m + l_v                           !< latent heat of water sublimation (J kg-1)
+    REAL(wp), PARAMETER ::  molecular_weight_of_nacl = 0.05844_wp     !< mol. m. NaCl (kg mol-1)
+    REAL(wp), PARAMETER ::  molecular_weight_of_c3h4o4 = 0.10406_wp   !< mol. m. malonic acid (kg mol-1)
+    REAL(wp), PARAMETER ::  molecular_weight_of_nh4no3 = 0.08004_wp   !< mol. m. ammonium sulfate (kg mol-1)
+    REAL(wp), PARAMETER ::  molecular_weight_of_water = 0.01801528_wp !< mol. m. H2O (kg mol-1)
+    REAL(wp), PARAMETER ::  rho_l = 1.0E3_wp                          !< density of water (kg m-3)
+    REAL(wp), PARAMETER ::  rho_nacl = 2165.0_wp                      !< density of NaCl (kg m-3)
+    REAL(wp), PARAMETER ::  rho_c3h4o4 = 1600.0_wp                    !< density of malonic acid (kg m-3)
+    REAL(wp), PARAMETER ::  rho_nh4no3 = 1720.0_wp                    !< density of ammonium sulfate (kg m-3)
+    REAL(wp), PARAMETER ::  r_d = 287.0_wp                            !< sp. gas const. dry air (J kg-1 K-1)
+    REAL(wp), PARAMETER ::  r_v = 461.51_wp                           !< sp. gas const. water vapor (J kg-1 K-1)
+    REAL(wp), PARAMETER ::  sigma_sb = 5.67E-08_wp                    !< Stefan-Boltzmann constant
+    REAL(wp), PARAMETER ::  solar_constant = 1368.0_wp                !< solar constant at top of atmosphere
+    REAL(wp), PARAMETER ::  vanthoff_nacl = 2.0_wp                    !< van't Hoff factor for NaCl
+    REAL(wp), PARAMETER ::  vanthoff_c3h4o4 = 1.37_wp                 !< van't Hoff factor for malonic acid
+    REAL(wp), PARAMETER ::  vanthoff_nh4no3 = 2.31_wp                 !< van't Hoff factor for ammonium sulfate
+
+    REAL(wp), PARAMETER ::  p_0 = 100000.0_wp                         !< standard pressure reference state
+
+    REAL(wp), PARAMETER ::  g_d_cp  = g   / c_p   !< precomputed g / c_p
+    REAL(wp), PARAMETER ::  lv_d_cp = l_v / c_p   !< precomputed l_v / c_p
+    REAL(wp), PARAMETER ::  lv_d_rd = l_v / r_d   !< precomputed l_v / r_d
+    REAL(wp), PARAMETER ::  rd_d_cp = 0.286_wp !r_d / c_p  !< precomputed r_d / c_p
+    REAL(wp), PARAMETER ::  cp_d_rd = 1.0_wp/0.286_wp !c_p / r_d  !< precomputed c_p / r_d
+
+    REAL(wp) ::  molecular_weight_of_solute = molecular_weight_of_nacl  !< mol. m. NaCl (kg mol-1)
+    REAL(wp) ::  rho_s = rho_nacl                                       !< density of NaCl (kg m-3)
+    REAL(wp) ::  vanthoff = vanthoff_nacl                               !< van't Hoff factor for NaCl
+
+
+    SAVE
+
+    PRIVATE magnus_0d, &
+            magnus_1d, &
+            ideal_gas_law_rho_0d, &
+            ideal_gas_law_rho_1d, &
+            ideal_gas_law_rho_pt_0d, &
+            ideal_gas_law_rho_pt_1d, &
+            exner_function_0d, &
+            exner_function_1d, &
+            exner_function_invers_0d, &
+            exner_function_invers_1d, &
+            barometric_formula_0d, &
+            barometric_formula_1d
+
+    INTERFACE magnus
+       MODULE PROCEDURE magnus_0d
+       MODULE PROCEDURE magnus_1d
+    END INTERFACE magnus
+
+    INTERFACE ideal_gas_law_rho
+       MODULE PROCEDURE ideal_gas_law_rho_0d
+       MODULE PROCEDURE ideal_gas_law_rho_1d
+    END INTERFACE ideal_gas_law_rho
+
+    INTERFACE ideal_gas_law_rho_pt
+       MODULE PROCEDURE ideal_gas_law_rho_pt_0d
+       MODULE PROCEDURE ideal_gas_law_rho_pt_1d
+    END INTERFACE ideal_gas_law_rho_pt
+
+    INTERFACE exner_function
+       MODULE PROCEDURE exner_function_0d
+       MODULE PROCEDURE exner_function_1d
+    END INTERFACE exner_function
+
+    INTERFACE exner_function_invers
+       MODULE PROCEDURE exner_function_invers_0d
+       MODULE PROCEDURE exner_function_invers_1d
+    END INTERFACE exner_function_invers
+
+    INTERFACE barometric_formula
+       MODULE PROCEDURE barometric_formula_0d
+       MODULE PROCEDURE barometric_formula_1d
+    END INTERFACE barometric_formula
+
+ CONTAINS
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This function computes the magnus formula (Press et al., 1992).
+!> The magnus formula is needed to calculate the saturation vapor pressure
+!------------------------------------------------------------------------------!
+    FUNCTION magnus_0d( t )
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN) ::  t  !< temperature (K)
+
+       REAL(wp) ::  magnus_0d
+!
+!--    Saturation vapor pressure for a specific temperature:
+       magnus_0d =  611.2_wp * EXP( 17.62_wp * ( t - 273.15_wp ) /             &
+                                                   ( t - 29.65_wp  ) )
+
+    END FUNCTION magnus_0d
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This function computes the magnus formula (Press et al., 1992).
+!> The magnus formula is needed to calculate the saturation vapor pressure
+!------------------------------------------------------------------------------!
+    FUNCTION magnus_1d( t )
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN), DIMENSION(:) ::  t  !< temperature (K)
+
+       REAL(wp), DIMENSION(size(t)) ::  magnus_1d
+!
+!--    Saturation vapor pressure for a specific temperature:
+       magnus_1d =  611.2_wp * EXP( 17.62_wp * ( t - 273.15_wp ) /             &
+                                               ( t - 29.65_wp  ) )
+
+    END FUNCTION magnus_1d
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute the ideal gas law for scalar arguments.
+!------------------------------------------------------------------------------!
+    FUNCTION ideal_gas_law_rho_0d( p, t )
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN) ::  p  !< pressure (Pa)
+       REAL(wp), INTENT(IN) ::  t  !< temperature (K)
+
+       REAL(wp) ::  ideal_gas_law_rho_0d
+!
+!--    compute density according to ideal gas law:
+       ideal_gas_law_rho_0d = p / (r_d * t)
+
+    END FUNCTION ideal_gas_law_rho_0d
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute the ideal gas law for 1-D array arguments.
+!------------------------------------------------------------------------------!
+    FUNCTION ideal_gas_law_rho_1d( p, t )
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN), DIMENSION(:) ::  p  !< pressure (Pa)
+       REAL(wp), INTENT(IN), DIMENSION(:) ::  t  !< temperature (K)
+
+       REAL(wp), DIMENSION(size(p)) ::  ideal_gas_law_rho_1d
+!
+!--    compute density according to ideal gas law:
+       ideal_gas_law_rho_1d = p / (r_d * t)
+
+    END FUNCTION ideal_gas_law_rho_1d
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute the ideal gas law for scalar arguments.
+!------------------------------------------------------------------------------!
+    FUNCTION ideal_gas_law_rho_pt_0d( p, t )
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN) ::  p  !< pressure (Pa)
+       REAL(wp), INTENT(IN) ::  t  !< temperature (K)
+
+       REAL(wp) ::  ideal_gas_law_rho_pt_0d
+!
+!--    compute density according to ideal gas law:
+       ideal_gas_law_rho_pt_0d = p / (r_d * (1.0_wp / exner_function_invers(p)) * t)
+
+    END FUNCTION ideal_gas_law_rho_pt_0d
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute the ideal gas law for 1-D array arguments.
+!------------------------------------------------------------------------------!
+    FUNCTION ideal_gas_law_rho_pt_1d( p, t )
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN), DIMENSION(:) ::  p  !< pressure (Pa)
+       REAL(wp), INTENT(IN), DIMENSION(:) ::  t  !< temperature (K)
+
+       REAL(wp), DIMENSION(size(p)) ::  ideal_gas_law_rho_pt_1d
+!
+!--    compute density according to ideal gas law:
+       ideal_gas_law_rho_pt_1d = p / (r_d * (1.0_wp / exner_function_invers(p)) * t)
+
+    END FUNCTION ideal_gas_law_rho_pt_1d
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute the exner function for scalar arguments.
+!------------------------------------------------------------------------------!
+    FUNCTION exner_function_0d( p )
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN) ::  p    !< pressure (Pa)
+
+       REAL(wp) ::  exner_function_0d
+!
+!--    compute exner function:
+       exner_function_0d = ( p / p_0 )**( rd_d_cp )
+
+    END FUNCTION exner_function_0d
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute the exner function for 1-D array arguments.
+!------------------------------------------------------------------------------!
+    FUNCTION exner_function_1d( p )
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN), DIMENSION(:) ::  p  !< pressure (Pa)
+
+       REAL(wp), DIMENSION(size(p)) ::  exner_function_1d
+!
+!--    compute exner function:
+       exner_function_1d = ( p / p_0 )**( rd_d_cp )
+
+    END FUNCTION exner_function_1d
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute the exner function for scalar arguments.
+!------------------------------------------------------------------------------!
+    FUNCTION exner_function_invers_0d( p )
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN) ::  p    !< pressure (Pa)
+
+       REAL(wp) ::  exner_function_invers_0d
+!
+!--    compute exner function:
+       exner_function_invers_0d = ( p_0 / p )**( rd_d_cp )
+
+    END FUNCTION exner_function_invers_0d
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute the exner function for 1-D array arguments.
+!------------------------------------------------------------------------------!
+    FUNCTION exner_function_invers_1d( p )
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN), DIMENSION(:) ::  p  !< pressure (Pa)
+
+       REAL(wp), DIMENSION(size(p)) ::  exner_function_invers_1d
+!
+!--    compute exner function:
+       exner_function_invers_1d = ( p_0 / p )**( rd_d_cp )
+
+    END FUNCTION exner_function_invers_1d
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute the barometric formula for scalar arguments.
+!------------------------------------------------------------------------------!
+    FUNCTION barometric_formula_0d( z, t_0, p_0)
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN) ::  z    !< height (m)
+       REAL(wp), INTENT(IN) ::  t_0  !< temperature reference state (K)
+       REAL(wp), INTENT(IN) ::  p_0  !< surface pressure (Pa)
+
+       REAL(wp) ::  barometric_formula_0d
+!
+!--    compute barometric formula:
+       barometric_formula_0d =  p_0 * ( (t_0 - g_d_cp * z) / t_0 )**( cp_d_rd )
+
+    END FUNCTION barometric_formula_0d
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Compute the barometric formula for 1-D array arguments.
+!------------------------------------------------------------------------------!
+    FUNCTION barometric_formula_1d( z, t_0, p_0)
+
+       IMPLICIT NONE
+
+       REAL(wp), INTENT(IN), DIMENSION(:) ::  z  !< height (m)
+       REAL(wp), INTENT(IN) ::  t_0              !< temperature reference state (K)
+       REAL(wp), INTENT(IN) ::  p_0              !< surface pressure (Pa)
+
+       REAL(wp), DIMENSION(size(z)) ::  barometric_formula_1d
+!
+!--    compute barometric formula:
+       barometric_formula_1d =  p_0 * ( (t_0 - g_d_cp * z) / t_0 )**( cp_d_rd )
+
+    END FUNCTION barometric_formula_1d
+
+ END MODULE basic_constants_and_equations_mod
Index: /palm/trunk/SOURCE/boundary_conds.f90
===================================================================
--- /palm/trunk/SOURCE/boundary_conds.f90	(revision 3273)
+++ /palm/trunk/SOURCE/boundary_conds.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -197,4 +200,7 @@
                w, w_p, w_m_l, w_m_n, w_m_r, w_m_s
 
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  kappa
+
     USE chemistry_model_mod,                                                   &
         ONLY:  chem_boundary_conds 
@@ -204,9 +210,8 @@
                bc_dirichlet_s, bc_radiation_l, bc_radiation_n, bc_radiation_r, &
                bc_radiation_s, bc_pt_t_val, bc_q_t_val, bc_s_t_val,            &
-               child_domain, constant_diffusion, cloud_physics, coupling_mode, &
+               child_domain, constant_diffusion, coupling_mode, &
                dt_3d, humidity, ibc_pt_b, ibc_pt_t, ibc_q_b, ibc_q_t, ibc_s_b, &
                ibc_s_t,ibc_sa_t, ibc_uv_b, ibc_uv_t,                           &
-               intermediate_timestep_count, kappa,                             &
-               microphysics_morrison, microphysics_seifert,                    &
+               intermediate_timestep_count,                                    &
                nesting_offline, nudging,                                       &
                ocean, passive_scalar, rans_mode, rans_tke_e, tsc, use_cmax
@@ -220,4 +225,7 @@
 
     USE kinds
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
 
     USE pegrid
@@ -597,5 +605,5 @@
        ENDIF
 
-       IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+       IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
 !             
 !--       Surface conditions cloud water (Dirichlet)
@@ -618,5 +626,5 @@
        ENDIF
 
-       IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+       IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
 !             
 !--       Surface conditions rain water (Dirichlet)
@@ -736,9 +744,9 @@
        IF ( humidity )  THEN
           q_p(:,nys-1,:) = q_p(:,nys,:)
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
              qc_p(:,nys-1,:) = qc_p(:,nys,:)
              nc_p(:,nys-1,:) = nc_p(:,nys,:)
           ENDIF
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
              qr_p(:,nys-1,:) = qr_p(:,nys,:)
              nr_p(:,nys-1,:) = nr_p(:,nys,:)
@@ -752,9 +760,9 @@
        IF ( humidity )  THEN
           q_p(:,nyn+1,:) = q_p(:,nyn,:)
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
              qc_p(:,nyn+1,:) = qc_p(:,nyn,:)
              nc_p(:,nyn+1,:) = nc_p(:,nyn,:)
           ENDIF
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
              qr_p(:,nyn+1,:) = qr_p(:,nyn,:)
              nr_p(:,nyn+1,:) = nr_p(:,nyn,:)
@@ -768,9 +776,9 @@
        IF ( humidity )  THEN
           q_p(:,:,nxl-1) = q_p(:,:,nxl)
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
              qc_p(:,:,nxl-1) = qc_p(:,:,nxl)
              nc_p(:,:,nxl-1) = nc_p(:,:,nxl)
           ENDIF
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
              qr_p(:,:,nxl-1) = qr_p(:,:,nxl)
              nr_p(:,:,nxl-1) = nr_p(:,:,nxl)
@@ -784,9 +792,9 @@
        IF ( humidity )  THEN
           q_p(:,:,nxr+1) = q_p(:,:,nxr)
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
              qc_p(:,:,nxr+1) = qc_p(:,:,nxr)
              nc_p(:,:,nxr+1) = nc_p(:,:,nxr)
           ENDIF
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
              qr_p(:,:,nxr+1) = qr_p(:,:,nxr)
              nr_p(:,:,nxr+1) = nr_p(:,:,nxr)
Index: /palm/trunk/SOURCE/bulk_cloud_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/bulk_cloud_model_mod.f90	(revision 3274)
+++ /palm/trunk/SOURCE/bulk_cloud_model_mod.f90	(revision 3274)
@@ -0,0 +1,4380 @@
+!> @file bulk_cloud_model_mod.f90
+!------------------------------------------------------------------------------!
+! This file is part of the PALM model system.
+!
+! PALM is free software: you can redistribute it and/or modify it under the
+! terms of the GNU General Public License as published by the Free Software
+! Foundation, either version 3 of the License, or (at your option) any later
+! version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 1997-2018 Leibniz Universitaet Hannover
+!------------------------------------------------------------------------------!
+!
+! Current revisions:
+! ------------------
+! 
+! 
+! Former revisions:
+! -----------------
+! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 
+! unused variables removed
+! 
+! 3026 2018-05-22 10:30:53Z schwenkel
+! Changed the name specific humidity to mixing ratio, since we are computing
+! mixing ratios.
+! 
+! 2718 2018-01-02 08:49:38Z maronga
+! Corrected "Former revisions" section
+! 
+! 2701 2017-12-15 15:40:50Z suehring
+! Changes from last commit documented
+! 
+! 2698 2017-12-14 18:46:24Z suehring
+! Bugfix in get_topography_top_index
+!
+! 2696 2017-12-14 17:12:51Z kanani
+! Change in file header (GPL part)
+!
+! 2608 2017-11-13 14:04:26Z schwenkel
+! Calculation of supersaturation in external module (diagnostic_quantities_mod).
+! Change: correct calculation of saturation specific humidity to saturation
+! mixing ratio (the factor of 0.378 vanishes).
+! 
+! 2522 2017-10-05 14:20:37Z schwenkel
+! Minor bugfix
+! 
+! 2375 2017-08-29 14:10:28Z schwenkel
+! Improved aerosol initilization and some minor bugfixes 
+! for droplet sedimenation
+! 
+! 2318 2017-07-20 17:27:44Z suehring
+! Get topography top index via Function call 
+!
+! 2317 2017-07-20 17:27:19Z suehring
+! s1 changed to log_sigma
+!
+! 2292 2017-06-20 09:51:42Z schwenkel
+! Implementation of new microphysic scheme: cloud_scheme = 'morrison'
+! includes two more prognostic equations for cloud drop concentration (nc)
+! and cloud water content (qc).
+! - The process of activation is parameterized with a simple Twomey
+!   activion scheme or with considering solution and curvature
+!   effects (Khvorostyanov and Curry ,2006).
+! - The saturation adjustment scheme is replaced by the parameterization
+!   of condensation rates (Khairoutdinov and Kogan, 2000, Mon. Wea. Rev.,128).
+! - All other microphysical processes of Seifert and Beheng are used.
+!   Additionally, in those processes the reduction of cloud number concentration
+!   is considered.
+!
+! 2233 2017-05-30 18:08:54Z suehring
+!
+! 2232 2017-05-30 17:47:52Z suehring
+! Adjustments to new topography and surface concept
+!
+! 2155 2017-02-21 09:57:40Z hoffmann
+! Bugfix in the calculation of microphysical quantities on ghost points.
+!
+! 2031 2016-10-21 15:11:58Z knoop
+! renamed variable rho to rho_ocean
+!
+! 2000 2016-08-20 18:09:15Z knoop
+! Forced header and separation lines into 80 columns
+!
+! 1850 2016-04-08 13:29:27Z maronga
+! Module renamed
+! Adapted for modularization of microphysics.
+!
+! 1845 2016-04-08 08:29:13Z raasch
+! nzb_2d replaced by nzb_s_inner, Kessler precipitation is stored at surface
+! point (instead of one point above surface)
+!
+! 1831 2016-04-07 13:15:51Z hoffmann
+! turbulence renamed collision_turbulence,
+! drizzle renamed cloud_water_sedimentation. cloud_water_sedimentation also
+! avaialble for microphysics_kessler.
+!
+! 1822 2016-04-07 07:49:42Z hoffmann
+! Unused variables removed.
+! Kessler scheme integrated.
+!
+! 1691 2015-10-26 16:17:44Z maronga
+! Added new routine calc_precipitation_amount. The routine now allows to account
+! for precipitation due to sedimenation of cloud (fog) droplets
+!
+! 1682 2015-10-07 23:56:08Z knoop
+! Code annotations made doxygen readable
+!
+! 1646 2015-09-02 16:00:10Z hoffmann
+! Bugfix: Wrong computation of d_mean.
+!
+! 1361 2014-04-16 15:17:48Z hoffmann
+! Bugfix in sedimentation_rain: Index corrected.
+! Vectorized version of adjust_cloud added.
+! Little reformatting of the code.
+!
+! 1353 2014-04-08 15:21:23Z heinze
+! REAL constants provided with KIND-attribute
+!
+! 1346 2014-03-27 13:18:20Z heinze
+! Bugfix: REAL constants provided with KIND-attribute especially in call of
+! intrinsic function like MAX, MIN, SIGN
+!
+! 1334 2014-03-25 12:21:40Z heinze
+! Bugfix: REAL constants provided with KIND-attribute
+!
+! 1322 2014-03-20 16:38:49Z raasch
+! REAL constants defined as wp-kind
+!
+! 1320 2014-03-20 08:40:49Z raasch
+! ONLY-attribute added to USE-statements,
+! kind-parameters added to all INTEGER and REAL declaration statements,
+! kinds are defined in new module kinds,
+! comment fields (!:) to be used for variable explanations added to
+! all variable declaration statements
+!
+! 1241 2013-10-30 11:36:58Z heinze
+! hyp and rho_ocean have to be calculated at each time step if data from external
+! file LSF_DATA are used
+!
+! 1115 2013-03-26 18:16:16Z hoffmann
+! microphyical tendencies are calculated in bcm_actions in an optimized
+! way; unrealistic values are prevented; bugfix in evaporation; some reformatting
+!
+! 1106 2013-03-04 05:31:38Z raasch
+! small changes in code formatting
+!
+! 1092 2013-02-02 11:24:22Z raasch
+! unused variables removed
+! file put under GPL
+!
+! 1065 2012-11-22 17:42:36Z hoffmann
+! Sedimentation process implemented according to Stevens and Seifert (2008).
+! Turbulence effects on autoconversion and accretion added (Seifert, Nuijens
+! and Stevens, 2010).
+!
+! 1053 2012-11-13 17:11:03Z hoffmann
+! initial revision
+!
+! Description:
+! ------------
+!> Calculate bulk cloud microphysics.
+!------------------------------------------------------------------------------!
+ MODULE bulk_cloud_model_mod
+
+    USE arrays_3d,                                                             &
+        ONLY:  ddzu, diss, dzu, dzw, hyp, hyrho,                               &
+               nc, nc_1, nc_2, nc_3, nc_p, nr, nr_1, nr_2, nr_3, nr_p,         &
+               precipitation_amount, prr, pt, d_exner, pt_init, q, ql, ql_1,   &
+               qc, qc_1, qc_2, qc_3, qc_p, qr, qr_1, qr_2, qr_3, qr_p,         &
+               exner, zu, tnc_m, tnr_m, tqc_m, tqr_m
+
+    USE averaging,                                                             &
+        ONLY:  nc_av, nr_av, prr_av, qc_av, ql_av, qr_av
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  c_p, g, lv_d_cp, lv_d_rd, l_v, magnus, molecular_weight_of_solute,&
+               molecular_weight_of_water, pi, rho_l, rho_s, r_d, r_v, vanthoff,&
+               exner_function, exner_function_invers, ideal_gas_law_rho,       &
+               ideal_gas_law_rho_pt, barometric_formula
+
+    USE control_parameters,                                                    &
+        ONLY:  dt_3d, dt_do2d_xy, intermediate_timestep_count,                 &
+               intermediate_timestep_count_max, large_scale_forcing,           &
+               lsf_surf, pt_surface, rho_surface, surface_pressure,            &
+               time_do2d_xy, message_string
+
+    USE cpulog,                                                                &
+        ONLY:  cpu_log, log_point_s
+
+    USE grid_variables,                                                        &
+        ONLY:  dx, dy
+
+    USE indices,                                                               &
+        ONLY:  nxl, nxlg, nxr, nxrg, nys, nysg, nyn, nyng, nzb, nzt,           &
+               wall_flags_0
+
+    USE  kinds
+
+    USE statistics,                                                            &
+        ONLY:  weight_pres, weight_substep
+
+    USE surface_mod,                                                           &
+        ONLY :  bc_h, get_topography_top_index_ji, surf_bulk_cloud_model,      &
+                surf_microphysics_morrison, surf_microphysics_seifert
+
+    IMPLICIT NONE
+
+    CHARACTER (LEN=20)   ::  aerosol_bulk = 'nacl'                        !< namelist parameter
+    CHARACTER (LEN=20)   ::  cloud_scheme = 'saturation_adjust'           !< namelist parameter
+
+    LOGICAL ::  aerosol_nacl =.TRUE.                             !< nacl aerosol for bulk scheme
+    LOGICAL ::  aerosol_c3h4o4 =.FALSE.                          !< malonic acid aerosol for bulk scheme
+    LOGICAL ::  aerosol_nh4no3 =.FALSE.                          !< malonic acid aerosol for bulk scheme
+
+    LOGICAL ::  bulk_cloud_model = .FALSE.                       !< namelist parameter
+
+    LOGICAL ::  cloud_water_sedimentation = .FALSE.       !< cloud water sedimentation
+    LOGICAL ::  curvature_solution_effects_bulk = .FALSE. !< flag for considering koehler theory
+    LOGICAL ::  limiter_sedimentation = .TRUE.            !< sedimentation limiter
+    LOGICAL ::  collision_turbulence = .FALSE.            !< turbulence effects
+    LOGICAL ::  ventilation_effect = .TRUE.               !< ventilation effect
+
+    LOGICAL ::  call_microphysics_at_all_substeps = .FALSE.      !< namelist parameter
+    LOGICAL ::  microphysics_sat_adjust = .FALSE.                !< use saturation adjust bulk scheme?
+    LOGICAL ::  microphysics_kessler = .FALSE.                   !< use kessler bulk scheme?
+    LOGICAL ::  microphysics_morrison = .FALSE.                  !< use 2-moment Morrison (add. prog. eq. for nc and qc)
+    LOGICAL ::  microphysics_seifert = .FALSE.                   !< use 2-moment Seifert and Beheng scheme
+    LOGICAL ::  precipitation = .FALSE.                          !< namelist parameter
+
+    REAL(wp) ::  precipitation_amount_interval = 9999999.9_wp    !< namelist parameter
+
+    REAL(wp) ::  a_1 = 8.69E-4_wp          !< coef. in turb. parametrization (cm-2 s3)
+    REAL(wp) ::  a_2 = -7.38E-5_wp         !< coef. in turb. parametrization (cm-2 s3)
+    REAL(wp) ::  a_3 = -1.40E-2_wp         !< coef. in turb. parametrization
+    REAL(wp) ::  a_term = 9.65_wp          !< coef. for terminal velocity (m s-1)
+    REAL(wp) ::  a_vent = 0.78_wp          !< coef. for ventilation effect
+    REAL(wp) ::  b_1 = 11.45E-6_wp         !< coef. in turb. parametrization (m)
+    REAL(wp) ::  b_2 = 9.68E-6_wp          !< coef. in turb. parametrization (m)
+    REAL(wp) ::  b_3 = 0.62_wp             !< coef. in turb. parametrization
+    REAL(wp) ::  b_term = 9.8_wp           !< coef. for terminal velocity (m s-1)
+    REAL(wp) ::  b_vent = 0.308_wp         !< coef. for ventilation effect
+    REAL(wp) ::  beta_cc = 3.09E-4_wp      !< coef. in turb. parametrization (cm-2 s3)
+    REAL(wp) ::  c_1 = 4.82E-6_wp          !< coef. in turb. parametrization (m)
+    REAL(wp) ::  c_2 = 4.8E-6_wp           !< coef. in turb. parametrization (m)
+    REAL(wp) ::  c_3 = 0.76_wp             !< coef. in turb. parametrization
+    REAL(wp) ::  c_const = 0.93_wp         !< const. in Taylor-microscale Reynolds number
+    REAL(wp) ::  c_evap = 0.7_wp           !< constant in evaporation
+    REAL(wp) ::  c_term = 600.0_wp         !< coef. for terminal velocity (m-1)
+    REAL(wp) ::  diff_coeff_l = 0.23E-4_wp  !< diffusivity of water vapor (m2 s-1)
+    REAL(wp) ::  eps_sb = 1.0E-10_wp       !< threshold in two-moments scheme
+    REAL(wp) ::  eps_mr = 0.0_wp           !< threshold for morrison scheme
+    REAL(wp) ::  k_cc = 9.44E09_wp         !< const. cloud-cloud kernel (m3 kg-2 s-1)
+    REAL(wp) ::  k_cr0 = 4.33_wp           !< const. cloud-rain kernel (m3 kg-1 s-1)
+    REAL(wp) ::  k_rr = 7.12_wp            !< const. rain-rain kernel (m3 kg-1 s-1)
+    REAL(wp) ::  k_br = 1000.0_wp          !< const. in breakup parametrization (m-1)
+    REAL(wp) ::  k_st = 1.2E8_wp           !< const. in drizzle parametrization (m-1 s-1)
+    REAL(wp) ::  kin_vis_air = 1.4086E-5_wp  !< kin. viscosity of air (m2 s-1)
+    REAL(wp) ::  prec_time_const = 0.001_wp  !< coef. in Kessler scheme (s-1)
+    REAL(wp) ::  ql_crit = 0.0005_wp       !< coef. in Kessler scheme (kg kg-1)
+    REAL(wp) ::  schmidt_p_1d3=0.8921121_wp  !< Schmidt number**0.33333, 0.71**0.33333
+    REAL(wp) ::  sigma_gc = 1.3_wp         !< geometric standard deviation cloud droplets
+    REAL(wp) ::  thermal_conductivity_l = 2.43E-2_wp  !< therm. cond. air (J m-1 s-1 K-1)
+    REAL(wp) ::  w_precipitation = 9.65_wp  !< maximum terminal velocity (m s-1)
+    REAL(wp) ::  x0 = 2.6E-10_wp           !< separating drop mass (kg)
+    REAL(wp) ::  xamin = 5.24E-19_wp       !< average aerosol mass (kg) (~ 0.05Âµm)
+    REAL(wp) ::  xcmin = 4.18E-15_wp       !< minimum cloud drop size (kg) (~ 1Âµm)
+    REAL(wp) ::  xrmin = 2.6E-10_wp        !< minimum rain drop size (kg)
+    REAL(wp) ::  xrmax = 5.0E-6_wp         !< maximum rain drop site (kg)
+
+    REAL(wp) ::  c_sedimentation = 2.0_wp        !< Courant number of sedimentation process
+    REAL(wp) ::  dpirho_l                        !< 6.0 / ( pi * rho_l )
+    REAL(wp) ::  dry_aerosol_radius = 0.05E-6_wp !< dry aerosol radius
+    REAL(wp) ::  dt_micro                        !< microphysics time step
+    REAL(wp) ::  sigma_bulk = 2.0_wp             !< width of aerosol spectrum
+    REAL(wp) ::  na_init = 100.0E6_wp            !< Total particle/aerosol concentration (cm-3)
+    REAL(wp) ::  nc_const = 70.0E6_wp            !< cloud droplet concentration
+    REAL(wp) ::  dt_precipitation = 100.0_wp     !< timestep precipitation (s)
+    REAL(wp) ::  sed_qc_const                    !< const. for sedimentation of cloud water
+    REAL(wp) ::  pirho_l                         !< pi * rho_l / 6.0;
+
+    REAL(wp) ::  e_s     !< saturation water vapor pressure
+    REAL(wp) ::  q_s     !< saturation mixing ratio
+    REAL(wp) ::  sat     !< supersaturation
+    REAL(wp) ::  t_l     !< actual temperature
+
+    SAVE
+
+    PRIVATE
+
+    PUBLIC bcm_parin, &
+           bcm_check_parameters, &
+           bcm_check_data_output, &
+           bcm_check_data_output_pr, &
+           bcm_header, &
+           bcm_init_arrays, &
+           bcm_init, &
+           bcm_3d_data_averaging, &
+           bcm_data_output_2d, &
+           bcm_data_output_3d, &
+           bcm_swap_timelevel, &
+           bcm_rrd_global, &
+           bcm_rrd_local, &
+           bcm_wrd_global, &
+           bcm_wrd_local, &
+           bcm_actions, &
+           calc_liquid_water_content
+
+    PUBLIC call_microphysics_at_all_substeps, &
+           cloud_water_sedimentation, &
+           bulk_cloud_model, &
+           cloud_scheme, &
+           collision_turbulence, &
+           dt_precipitation, &
+           microphysics_morrison, &
+           microphysics_sat_adjust, &
+           microphysics_seifert, &
+           na_init, &
+           nc_const, &
+           precipitation, &
+           sigma_gc
+
+
+    INTERFACE bcm_parin
+       MODULE PROCEDURE bcm_parin
+    END INTERFACE bcm_parin
+
+    INTERFACE bcm_check_parameters
+       MODULE PROCEDURE bcm_check_parameters
+    END INTERFACE bcm_check_parameters
+
+    INTERFACE bcm_check_data_output
+       MODULE PROCEDURE bcm_check_data_output
+    END INTERFACE bcm_check_data_output
+
+    INTERFACE bcm_check_data_output_pr
+       MODULE PROCEDURE bcm_check_data_output_pr
+    END INTERFACE bcm_check_data_output_pr
+
+    INTERFACE bcm_header
+       MODULE PROCEDURE bcm_header
+    END INTERFACE bcm_header
+
+    INTERFACE bcm_init_arrays
+       MODULE PROCEDURE bcm_init_arrays
+    END INTERFACE bcm_init_arrays
+
+    INTERFACE bcm_init
+       MODULE PROCEDURE bcm_init
+    END INTERFACE bcm_init
+
+    INTERFACE bcm_3d_data_averaging
+       MODULE PROCEDURE bcm_3d_data_averaging
+    END INTERFACE bcm_3d_data_averaging
+
+    INTERFACE bcm_data_output_2d
+       MODULE PROCEDURE bcm_data_output_2d
+    END INTERFACE bcm_data_output_2d
+
+    INTERFACE bcm_data_output_3d
+       MODULE PROCEDURE bcm_data_output_3d
+    END INTERFACE bcm_data_output_3d
+
+    INTERFACE bcm_swap_timelevel
+       MODULE PROCEDURE bcm_swap_timelevel
+    END INTERFACE bcm_swap_timelevel
+
+    INTERFACE bcm_rrd_global
+       MODULE PROCEDURE bcm_rrd_global
+    END INTERFACE bcm_rrd_global
+
+    INTERFACE bcm_rrd_local
+       MODULE PROCEDURE bcm_rrd_local
+    END INTERFACE bcm_rrd_local
+
+    INTERFACE bcm_wrd_global
+       MODULE PROCEDURE bcm_wrd_global
+    END INTERFACE bcm_wrd_global
+
+    INTERFACE bcm_wrd_local
+       MODULE PROCEDURE bcm_wrd_local
+    END INTERFACE bcm_wrd_local
+
+    INTERFACE bcm_actions
+       MODULE PROCEDURE bcm_actions
+       MODULE PROCEDURE bcm_actions_ij
+    END INTERFACE bcm_actions
+
+    INTERFACE adjust_cloud
+       MODULE PROCEDURE adjust_cloud
+       MODULE PROCEDURE adjust_cloud_ij
+    END INTERFACE adjust_cloud
+
+    INTERFACE activation
+       MODULE PROCEDURE activation
+       MODULE PROCEDURE activation_ij
+    END INTERFACE activation
+
+    INTERFACE condensation
+       MODULE PROCEDURE condensation
+       MODULE PROCEDURE condensation_ij
+    END INTERFACE condensation
+
+    INTERFACE autoconversion
+       MODULE PROCEDURE autoconversion
+       MODULE PROCEDURE autoconversion_ij
+    END INTERFACE autoconversion
+
+    INTERFACE autoconversion_kessler
+       MODULE PROCEDURE autoconversion_kessler
+       MODULE PROCEDURE autoconversion_kessler_ij
+    END INTERFACE autoconversion_kessler
+
+    INTERFACE accretion
+       MODULE PROCEDURE accretion
+       MODULE PROCEDURE accretion_ij
+    END INTERFACE accretion
+
+    INTERFACE selfcollection_breakup
+       MODULE PROCEDURE selfcollection_breakup
+       MODULE PROCEDURE selfcollection_breakup_ij
+    END INTERFACE selfcollection_breakup
+
+    INTERFACE evaporation_rain
+       MODULE PROCEDURE evaporation_rain
+       MODULE PROCEDURE evaporation_rain_ij
+    END INTERFACE evaporation_rain
+
+    INTERFACE sedimentation_cloud
+       MODULE PROCEDURE sedimentation_cloud
+       MODULE PROCEDURE sedimentation_cloud_ij
+    END INTERFACE sedimentation_cloud
+
+    INTERFACE sedimentation_rain
+       MODULE PROCEDURE sedimentation_rain
+       MODULE PROCEDURE sedimentation_rain_ij
+    END INTERFACE sedimentation_rain
+
+    INTERFACE calc_precipitation_amount
+       MODULE PROCEDURE calc_precipitation_amount
+       MODULE PROCEDURE calc_precipitation_amount_ij
+    END INTERFACE calc_precipitation_amount
+
+    INTERFACE supersaturation
+       MODULE PROCEDURE supersaturation
+    END INTERFACE supersaturation
+
+    INTERFACE calc_liquid_water_content
+       MODULE PROCEDURE calc_liquid_water_content
+    END INTERFACE calc_liquid_water_content
+
+ CONTAINS
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Parin for &bulk_cloud_parameters for the microphysics module
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_parin
+
+
+       IMPLICIT NONE
+
+       CHARACTER (LEN=80)  ::  line  !< dummy string that contains the current line of the parameter file
+
+       NAMELIST /bulk_cloud_parameters/  &
+          aerosol_bulk, &
+          c_sedimentation, &
+          call_microphysics_at_all_substeps, &
+          bulk_cloud_model, &
+          cloud_scheme, &
+          cloud_water_sedimentation, &
+          collision_turbulence, &
+          curvature_solution_effects_bulk, &
+          dry_aerosol_radius, &
+          limiter_sedimentation, &
+          na_init, &
+          nc_const, &
+          precipitation, &
+          precipitation_amount_interval, &
+          sigma_bulk, &
+          ventilation_effect
+
+       line = ' '
+!
+!--    Try to find microphysics module package
+       REWIND ( 11 )
+       line = ' '
+       DO   WHILE ( INDEX( line, '&bulk_cloud_parameters' ) == 0 )
+          READ ( 11, '(A)', END=10 )  line
+       ENDDO
+       BACKSPACE ( 11 )
+!
+!--    Read user-defined namelist
+       READ ( 11, bulk_cloud_parameters )
+!
+!--    Set flag that indicates that the microphysics module is switched on
+       !bulk_cloud_model = .TRUE.
+
+10     CONTINUE
+
+
+    END SUBROUTINE bcm_parin
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Check parameters routine for microphysics module
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_check_parameters
+
+
+       IMPLICIT NONE
+!
+!--    Check cloud scheme
+       IF ( cloud_scheme == 'saturation_adjust' )  THEN
+          microphysics_sat_adjust = .TRUE.
+          microphysics_seifert    = .FALSE.
+          microphysics_kessler    = .FALSE.
+          precipitation           = .FALSE.
+       ELSEIF ( cloud_scheme == 'seifert_beheng' )  THEN
+          microphysics_sat_adjust = .FALSE.
+          microphysics_seifert    = .TRUE.
+          microphysics_kessler    = .FALSE.
+          microphysics_morrison  = .FALSE.
+          precipitation           = .TRUE.
+       ELSEIF ( cloud_scheme == 'kessler' )  THEN
+          microphysics_sat_adjust = .FALSE.
+          microphysics_seifert    = .FALSE.
+          microphysics_kessler    = .TRUE.
+          microphysics_morrison   = .FALSE.
+          precipitation           = .TRUE.
+       ELSEIF ( cloud_scheme == 'morrison' )  THEN
+          microphysics_sat_adjust = .FALSE.
+          microphysics_seifert    = .TRUE.
+          microphysics_kessler    = .FALSE.
+          microphysics_morrison   = .TRUE.
+          precipitation           = .TRUE.
+       ELSE
+          message_string = 'unknown cloud microphysics scheme cloud_scheme ="' // &
+                           TRIM( cloud_scheme ) // '"'
+          CALL message( 'check_parameters', 'PA0357', 1, 2, 0, 6, 0 )
+       ENDIF
+
+
+
+!
+!--    Set the default value for the integration interval of precipitation amount
+       IF ( microphysics_seifert  .OR.  microphysics_kessler )  THEN
+          IF ( precipitation_amount_interval == 9999999.9_wp )  THEN
+             precipitation_amount_interval = dt_do2d_xy
+          ELSE
+             IF ( precipitation_amount_interval > dt_do2d_xy )  THEN
+                WRITE( message_string, * )  'precipitation_amount_interval = ',   &
+                    precipitation_amount_interval, ' must not be larger than ',   &
+                    'dt_do2d_xy = ', dt_do2d_xy
+                CALL message( 'check_parameters', 'PA0090', 1, 2, 0, 6, 0 )
+             ENDIF
+          ENDIF
+       ENDIF
+
+       ! TODO: find better sollution for circular dependency problem
+       surf_bulk_cloud_model = bulk_cloud_model
+       surf_microphysics_morrison = microphysics_morrison
+       surf_microphysics_seifert = microphysics_seifert
+
+!
+!--    Check aerosol
+       IF ( aerosol_bulk == 'nacl' )  THEN
+          aerosol_nacl   = .TRUE.
+          aerosol_c3h4o4 = .FALSE.
+          aerosol_nh4no3 = .FALSE.
+       ELSEIF ( aerosol_bulk == 'c3h4o4' )  THEN
+          aerosol_nacl   = .FALSE.
+          aerosol_c3h4o4 = .TRUE.
+          aerosol_nh4no3 = .FALSE.
+       ELSEIF ( aerosol_bulk == 'nh4no3' )  THEN
+          aerosol_nacl   = .FALSE.
+          aerosol_c3h4o4 = .FALSE.
+          aerosol_nh4no3 = .TRUE.
+       ELSE
+          message_string = 'unknown aerosol = "' // TRIM( aerosol_bulk ) // '"'
+          CALL message( 'check_parameters', 'PA0469', 1, 2, 0, 6, 0 )
+       ENDIF
+
+
+    END SUBROUTINE bcm_check_parameters
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Check data output for microphysics module
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_check_data_output( var, unit )
+
+       IMPLICIT NONE
+
+       CHARACTER (LEN=*) ::  unit  !<
+       CHARACTER (LEN=*) ::  var   !<
+
+       SELECT CASE ( TRIM( var ) )
+
+          CASE ( 'nc' )
+             IF ( .NOT.  microphysics_morrison )  THEN
+                message_string = 'output of "' // TRIM( var ) // '" ' //       &
+                                 'requires ' //                                &
+                                 'cloud_scheme = "morrison"'
+                CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
+             ENDIF
+             unit = '1/m3'
+
+          CASE ( 'nr' )
+             IF ( .NOT.  microphysics_seifert )  THEN
+                message_string = 'output of "' // TRIM( var ) // '" ' //       &
+                                 'requires ' //                                &
+                                 'cloud_scheme = "seifert_beheng"'
+                CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
+             ENDIF
+             unit = '1/m3'
+
+          CASE ( 'prr' )
+             IF ( microphysics_sat_adjust )  THEN
+                message_string = 'output of "' // TRIM( var ) // '" ' //       &
+                                 'is not available for ' //                    &
+                                 'cloud_scheme = "saturation_adjust"'
+                CALL message( 'check_parameters', 'PA0423', 1, 2, 0, 6, 0 )
+             ENDIF
+             unit = 'kg/kg m/s'
+
+          CASE ( 'qc' )
+             unit = 'kg/kg'
+
+          CASE ( 'qr' )
+             IF ( .NOT.  microphysics_seifert ) THEN
+                message_string = 'output of "' // TRIM( var ) // '" ' //       &
+                                 'requires ' //                                &
+                                 'cloud_scheme = "seifert_beheng"'
+                CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
+             ENDIF
+             unit = 'kg/kg'
+
+          CASE ( 'pra*' )
+             IF ( .NOT. microphysics_kessler  .AND.                            &
+                  .NOT. microphysics_seifert )  THEN
+                message_string = 'output of "' // TRIM( var ) // '" ' //       &
+                                 'requires ' //                                &
+                                 'cloud_scheme = "kessler" or "seifert_beheng"'
+                CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 )
+             ENDIF
+! TODO: find sollution (maybe connected to flow_statistics redesign?)
+!              IF ( j == 1 )  THEN
+!                 message_string = 'temporal averaging of precipitation ' //     &
+!                           'amount "' // TRIM( var ) // '" is not possible'
+!                 CALL message( 'check_parameters', 'PA0113', 1, 2, 0, 6, 0 )
+!              ENDIF
+             unit = 'mm'
+
+          CASE ( 'prr*' )
+             IF ( .NOT. microphysics_kessler  .AND.                            &
+                  .NOT. microphysics_seifert )  THEN
+                message_string = 'output of "' // TRIM( var ) // '"' //        &
+                         ' requires' //                                        &
+                         ' cloud_scheme = "kessler" or "seifert_beheng"'
+                CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 )
+             ENDIF
+             unit = 'mm/s'
+
+          CASE DEFAULT
+             unit = 'illegal'
+
+       END SELECT
+
+
+    END SUBROUTINE bcm_check_data_output
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Check data output of profiles for microphysics module
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_check_data_output_pr( variable, var_count, unit, dopr_unit )
+
+       USE arrays_3d,                                                          &
+           ONLY: zu
+
+       USE control_parameters,                                                 &
+           ONLY: data_output_pr
+
+       USE profil_parameter,                                                   &
+           ONLY: dopr_index
+
+       USE statistics,                                                         &
+           ONLY: hom, statistic_regions, pr_palm
+
+       IMPLICIT NONE
+
+       CHARACTER (LEN=*) ::  unit      !<
+       CHARACTER (LEN=*) ::  variable  !<
+       CHARACTER (LEN=*) ::  dopr_unit !< local value of dopr_unit
+
+       INTEGER(iwp) ::  var_count      !<
+       INTEGER(iwp) ::  pr_index       !<
+
+       SELECT CASE ( TRIM( variable ) )
+
+! TODO: make index generic: pr_index = pr_palm+1
+
+          CASE ( 'nc' )
+             IF ( .NOT.  microphysics_morrison )  THEN
+                message_string = 'data_output_pr = ' //                        &
+                                 TRIM( data_output_pr(var_count) ) //          &
+                                 ' is not implemented for' //                  &
+                                 ' cloud_scheme /= morrison'
+                CALL message( 'check_parameters', 'PA0358', 1, 2, 0, 6, 0 )
+             ENDIF
+             pr_index = 89
+             dopr_index(var_count) = pr_index
+             dopr_unit     = '1/m3'
+             unit = dopr_unit
+             hom(:,2,pr_index,:)  = SPREAD( zu, 2, statistic_regions+1 )
+
+          CASE ( 'nr' )
+             IF ( .NOT.  microphysics_seifert )  THEN
+                message_string = 'data_output_pr = ' //                        &
+                                 TRIM( data_output_pr(var_count) ) //          &
+                                 ' is not implemented for' //                  &
+                                 ' cloud_scheme /= seifert_beheng'
+                CALL message( 'check_parameters', 'PA0358', 1, 2, 0, 6, 0 )
+             ENDIF
+             pr_index = 73
+             dopr_index(var_count) = pr_index
+             dopr_unit     = '1/m3'
+             unit = dopr_unit
+             hom(:,2,pr_index,:)  = SPREAD( zu, 2, statistic_regions+1 )
+
+          CASE ( 'prr' )
+             IF ( microphysics_sat_adjust )  THEN
+                message_string = 'data_output_pr = ' //                        &
+                                 TRIM( data_output_pr(var_count) ) //          &
+                                 ' is not available for' //                    &
+                                 ' cloud_scheme = saturation_adjust'
+                CALL message( 'check_parameters', 'PA0422', 1, 2, 0, 6, 0 )
+             ENDIF
+             pr_index = 76
+             dopr_index(var_count) = pr_index
+             dopr_unit     = 'kg/kg m/s'
+             unit = dopr_unit
+             hom(:,2,pr_index,:)  = SPREAD( zu, 2, statistic_regions+1 )
+
+          CASE ( 'qc' )
+             pr_index = 75
+             dopr_index(var_count) = pr_index
+             dopr_unit     = 'kg/kg'
+             unit = dopr_unit
+             hom(:,2,pr_index,:)  = SPREAD( zu, 2, statistic_regions+1 )
+
+          CASE ( 'qr' )
+             IF ( .NOT.  microphysics_seifert )  THEN
+                message_string = 'data_output_pr = ' //                        &
+                                 TRIM( data_output_pr(var_count) ) //          &
+                                 ' is not implemented for' //                  &
+                                 ' cloud_scheme /= seifert_beheng'
+                CALL message( 'check_parameters', 'PA0358', 1, 2, 0, 6, 0 )
+             ENDIF
+             pr_index = 744
+             dopr_index(var_count) = pr_index
+             dopr_unit     = 'kg/kg'
+             unit = dopr_unit
+             hom(:,2,pr_index,:)  = SPREAD( zu, 2, statistic_regions+1 )
+
+          CASE DEFAULT
+             unit = 'illegal'
+
+       END SELECT
+
+
+    END SUBROUTINE bcm_check_data_output_pr
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Allocate microphysics module arrays and define pointers
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_init_arrays
+
+       USE indices,                                                            &
+           ONLY:  nxlg, nxrg, nysg, nyng, nzb, nzt
+
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i !<
+       INTEGER(iwp) ::  j !<
+       INTEGER(iwp) ::  k !<
+!
+!--          Liquid water content
+#if defined( __nopointer )
+       ALLOCATE ( ql(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+#else
+       ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+#endif
+
+!
+!--    3D-cloud water content
+       IF ( .NOT. microphysics_morrison )  THEN
+#if defined( __nopointer )
+          ALLOCATE( qc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+#else
+          ALLOCATE( qc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+#endif
+       ENDIF
+!
+!--    Precipitation amount and rate (only needed if output is switched)
+       ALLOCATE( precipitation_amount(nysg:nyng,nxlg:nxrg) )
+
+!
+!--    3d-precipitation rate
+       ALLOCATE( prr(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+
+       IF ( microphysics_morrison )  THEN
+!
+!--       3D-cloud drop water content, cloud drop concentration arrays
+#if defined( __nopointer )
+          ALLOCATE( nc(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
+                    nc_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    qc(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
+                    qc_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    tnc_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                   &
+                    tqc_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+#else
+          ALLOCATE( nc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    nc_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    nc_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    qc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    qc_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    qc_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+#endif
+       ENDIF
+
+       IF ( microphysics_seifert )  THEN
+!
+!--       3D-rain water content, rain drop concentration arrays
+#if defined( __nopointer )
+          ALLOCATE( nr(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
+                    nr_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    qr(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
+                    qr_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    tnr_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                   &
+                    tqr_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+#else
+          ALLOCATE( nr_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    nr_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    nr_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    qr_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    qr_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
+                    qr_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+#endif
+       ENDIF
+
+#if ! defined( __nopointer )
+!
+!--    Initial assignment of the pointers
+       ql => ql_1
+       IF ( .NOT. microphysics_morrison )  THEN
+          qc => qc_1
+       ENDIF
+       IF ( microphysics_morrison )  THEN
+          qc => qc_1;  qc_p  => qc_2;  tqc_m  => qc_3
+          nc => nc_1;  nc_p  => nc_2;  tnc_m  => nc_3
+       ENDIF
+       IF ( microphysics_seifert )  THEN
+          qr => qr_1;  qr_p  => qr_2;  tqr_m  => qr_3
+          nr => nr_1;  nr_p  => nr_2;  tnr_m  => nr_3
+       ENDIF
+#endif
+
+
+    END SUBROUTINE bcm_init_arrays
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Initialization of the microphysics module
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_init !( dots_label, dots_unit, dots_num, dots_max )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i !<
+       INTEGER(iwp) ::  j !<
+       INTEGER(iwp) ::  k !<
+
+!        INTEGER(iwp) ::  dots_num
+!        INTEGER(iwp) ::  dots_max
+!        CHARACTER (LEN=13), DIMENSION(dots_max) :: dots_unit
+!        CHARACTER (LEN=13), DIMENSION(dots_max) :: dots_label
+
+       CALL location_message( 'initializing microphysics module', .FALSE. )
+
+       IF ( bulk_cloud_model )  THEN
+
+!           dots_label(dots_num+1) = 'some_var'
+!           dots_unit(dots_num+1)  = 'm/s'
+!
+!           dots_num_palm = dots_num
+!           dots_num = dots_num + 1
+! !
+! !--       Stuff for the module
+!
+!           abs_velocity   = 0.0_wp
+
+!
+!--       Initialize the remaining quantities
+          IF ( microphysics_morrison )  THEN
+             DO  i = nxlg, nxrg
+                DO  j = nysg, nyng
+                   qc(:,j,i) = 0.0_wp
+                   nc(:,j,i) = 0.0_wp
+                ENDDO
+             ENDDO
+          ENDIF
+
+          IF ( microphysics_seifert )  THEN
+             DO  i = nxlg, nxrg
+                DO  j = nysg, nyng
+                   qr(:,j,i) = 0.0_wp
+                   nr(:,j,i) = 0.0_wp
+                ENDDO
+             ENDDO
+          ENDIF
+
+!
+!--       Liquid water content and precipitation amount
+!--       are zero at beginning of the simulation
+          IF ( bulk_cloud_model )  THEN
+             ql = 0.0_wp
+! TODO ???
+             qc = 0.0_wp
+             precipitation_amount = 0.0_wp
+          ENDIF
+
+!
+!--       Initialize old and new time levels.
+          IF ( microphysics_morrison )  THEN
+             tqc_m = 0.0_wp
+             tnc_m = 0.0_wp
+             qc_p  = qc
+             nc_p  = nc
+          ENDIF
+          IF ( microphysics_seifert )  THEN
+             tqr_m = 0.0_wp
+             tnr_m = 0.0_wp
+             qr_p  = qr
+             nr_p  = nr
+          ENDIF
+
+!
+!--       constant for the sedimentation of cloud water (2-moment cloud physics)
+          sed_qc_const = k_st * ( 3.0_wp / ( 4.0_wp * pi * rho_l )                &
+                             )**( 2.0_wp / 3.0_wp ) *                             &
+                         EXP( 5.0_wp * LOG( sigma_gc )**2 )
+
+!
+!--       Calculate timestep according to precipitation
+          IF ( microphysics_seifert )  THEN
+             dt_precipitation = c_sedimentation * MINVAL( dzu(nzb+2:nzt) ) /      &
+                                w_precipitation
+          ENDIF
+
+!
+!--       Set constants for certain aerosol type
+          IF ( microphysics_morrison )  THEN
+             IF ( aerosol_nacl ) THEN
+                molecular_weight_of_solute = 0.05844_wp
+                rho_s                      = 2165.0_wp
+                vanthoff                   = 2.0_wp
+             ELSEIF ( aerosol_c3h4o4 ) THEN
+                molecular_weight_of_solute = 0.10406_wp
+                rho_s                      = 1600.0_wp
+                vanthoff                   = 1.37_wp
+             ELSEIF ( aerosol_nh4no3 ) THEN
+                molecular_weight_of_solute = 0.08004_wp
+                rho_s                      = 1720.0_wp
+                vanthoff                   = 2.31_wp
+             ENDIF
+          ENDIF
+
+!
+!--       Pre-calculate frequently calculated fractions of pi and rho_l
+          pirho_l  = pi * rho_l / 6.0_wp
+          dpirho_l = 1.0_wp / pirho_l
+
+          CALL location_message( 'finished', .TRUE. )
+
+       ELSE
+
+          CALL location_message( 'skipped', .TRUE. )
+
+       ENDIF
+
+    END SUBROUTINE bcm_init
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Swapping of timelevels
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_swap_timelevel ( mod_count )
+
+       IMPLICIT NONE
+
+       INTEGER, INTENT(IN) :: mod_count
+
+       IF ( bulk_cloud_model )  THEN
+
+#if defined( __nopointer )
+          IF ( microphysics_morrison )  THEN
+             qc = qc_p
+             nc = nc_p
+          ENDIF
+          IF ( microphysics_seifert )  THEN
+             qr = qr_p
+             nr = nr_p
+          ENDIF
+#else
+          SELECT CASE ( mod_count )
+
+             CASE ( 0 )
+
+                IF ( microphysics_morrison )  THEN
+                   qc => qc_1;    qc_p => qc_2
+                   nc => nc_1;    nc_p => nc_2
+                ENDIF
+                IF ( microphysics_seifert )  THEN
+                   qr => qr_1;    qr_p => qr_2
+                   nr => nr_1;    nr_p => nr_2
+                ENDIF
+
+             CASE ( 1 )
+
+                IF ( microphysics_morrison )  THEN
+                   qc => qc_2;    qc_p => qc_1
+                   nc => nc_2;    nc_p => nc_1
+                ENDIF
+                IF ( microphysics_seifert )  THEN
+                   qr => qr_2;    qr_p => qr_1
+                   nr => nr_2;    nr_p => nr_1
+                ENDIF
+
+          END SELECT
+#endif
+
+       ENDIF
+
+    END SUBROUTINE bcm_swap_timelevel
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Header output for microphysics module
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_header ( io )
+
+
+       IMPLICIT NONE
+
+       INTEGER(iwp), INTENT(IN) ::  io  !< Unit of the output file
+
+!
+!--    Write microphysics module header
+       WRITE ( io, 1 )
+
+       WRITE ( io, 2 )
+       WRITE ( io, 3 )
+
+       IF ( microphysics_kessler )  THEN
+          WRITE ( io, 4 ) 'Kessler-Scheme'
+       ENDIF
+
+       IF ( microphysics_seifert )  THEN
+          WRITE ( io, 4 ) 'Seifert-Beheng-Scheme'
+          IF ( cloud_water_sedimentation )  WRITE ( io, 5 )
+          IF ( collision_turbulence )  WRITE ( io, 6 )
+          IF ( ventilation_effect )  WRITE ( io, 7 )
+          IF ( limiter_sedimentation )  WRITE ( io, 8 )
+       ENDIF
+
+       WRITE ( io, 20 )
+       WRITE ( io, 21 ) surface_pressure
+       WRITE ( io, 22 ) r_d
+       WRITE ( io, 23 ) rho_surface
+       WRITE ( io, 24 ) c_p
+       WRITE ( io, 25 ) l_v
+
+       IF ( microphysics_seifert )  THEN
+          WRITE ( io, 26 ) 1.0E-6_wp * nc_const
+          WRITE ( io, 27 ) c_sedimentation
+       ENDIF
+
+
+1   FORMAT ( //' Bulk cloud microphysics module information:'/ &
+               ' ------------------------------------------'/ )
+2   FORMAT ( '--> Bulk scheme with liquid water potential temperature and'/ &
+             '    total water content is used.' )
+3   FORMAT ( '--> Condensation is parameterized via 0% - or 100% scheme.' )
+4   FORMAT ( '--> Precipitation parameterization via ', A )
+
+5   FORMAT ( '--> Cloud water sedimentation parameterization via Stokes law' )
+6   FORMAT ( '--> Turbulence effects on precipitation process' )
+7   FORMAT ( '--> Ventilation effects on evaporation of rain drops' )
+8   FORMAT ( '--> Slope limiter used for sedimentation process' )
+
+20  FORMAT ( '--> Essential parameters:' )
+21  FORMAT ( '       Surface pressure             :   p_0   = ', F7.2, ' hPa')
+22  FORMAT ( '       Gas constant                 :   R     = ', F5.1, ' J/(kg K)')
+23  FORMAT ( '       Density of air               :   rho_0 = ', F6.3, ' kg/m**3')
+24  FORMAT ( '       Specific heat cap.           :   c_p   = ', F6.1, ' J/(kg K)')
+25  FORMAT ( '       Vapourization heat           :   L_v   = ', E9.2, ' J/kg')
+26  FORMAT ( '       Droplet density              :   N_c   = ', F6.1, ' 1/cm**3' )
+27  FORMAT ( '       Sedimentation Courant number :   C_s   = ', F4.1 )
+
+
+    END SUBROUTINE bcm_header
+
+
+!------------------------------------------------------------------------------!
+!
+! Description:
+! ------------
+!> Subroutine for averaging 3D data
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_3d_data_averaging( mode, variable )
+
+       USE control_parameters,                                                 &
+           ONLY:  average_count_3d
+
+       IMPLICIT NONE
+
+       CHARACTER (LEN=*) ::  mode     !<
+       CHARACTER (LEN=*) ::  variable !<
+
+       INTEGER(iwp) ::  i       !< local index
+       INTEGER(iwp) ::  j       !< local index
+       INTEGER(iwp) ::  k       !< local index
+
+       IF ( mode == 'allocate' )  THEN
+
+          SELECT CASE ( TRIM( variable ) )
+
+             CASE ( 'nc' )
+                IF ( .NOT. ALLOCATED( nc_av ) )  THEN
+                   ALLOCATE( nc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                ENDIF
+                nc_av = 0.0_wp
+
+             CASE ( 'nr' )
+                IF ( .NOT. ALLOCATED( nr_av ) )  THEN
+                   ALLOCATE( nr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                ENDIF
+                nr_av = 0.0_wp
+
+             CASE ( 'prr' )
+                IF ( .NOT. ALLOCATED( prr_av ) )  THEN
+                   ALLOCATE( prr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                ENDIF
+                prr_av = 0.0_wp
+
+             CASE ( 'qc' )
+                IF ( .NOT. ALLOCATED( qc_av ) )  THEN
+                   ALLOCATE( qc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                ENDIF
+                qc_av = 0.0_wp
+
+             CASE ( 'ql' )
+                IF ( .NOT. ALLOCATED( ql_av ) )  THEN
+                   ALLOCATE( ql_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                ENDIF
+                ql_av = 0.0_wp
+
+             CASE ( 'qr' )
+                IF ( .NOT. ALLOCATED( qr_av ) )  THEN
+                   ALLOCATE( qr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                ENDIF
+                qr_av = 0.0_wp
+
+             CASE DEFAULT
+                CONTINUE
+
+          END SELECT
+
+       ELSEIF ( mode == 'sum' )  THEN
+
+          SELECT CASE ( TRIM( variable ) )
+
+             CASE ( 'nc' )
+                IF ( ALLOCATED( nc_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            nc_av(k,j,i) = nc_av(k,j,i) + nc(k,j,i)
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE ( 'nr' )
+                IF ( ALLOCATED( nr_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            nr_av(k,j,i) = nr_av(k,j,i) + nr(k,j,i)
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE ( 'prr' )
+                IF ( ALLOCATED( prr_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            prr_av(k,j,i) = prr_av(k,j,i) + prr(k,j,i)
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE ( 'qc' )
+                IF ( ALLOCATED( qc_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            qc_av(k,j,i) = qc_av(k,j,i) + qc(k,j,i)
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE ( 'ql' )
+                IF ( ALLOCATED( ql_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            ql_av(k,j,i) = ql_av(k,j,i) + ql(k,j,i)
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE ( 'qr' )
+                IF ( ALLOCATED( qr_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            qr_av(k,j,i) = qr_av(k,j,i) + qr(k,j,i)
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE DEFAULT
+                CONTINUE
+
+          END SELECT
+
+       ELSEIF ( mode == 'average' )  THEN
+
+          SELECT CASE ( TRIM( variable ) )
+
+             CASE ( 'nc' )
+                IF ( ALLOCATED( nc_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            nc_av(k,j,i) = nc_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE ( 'nr' )
+                IF ( ALLOCATED( nr_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            nr_av(k,j,i) = nr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE ( 'prr' )
+                IF ( ALLOCATED( prr_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            prr_av(k,j,i) = prr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE ( 'qc' )
+                IF ( ALLOCATED( qc_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            qc_av(k,j,i) = qc_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE ( 'ql' )
+                IF ( ALLOCATED( ql_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            ql_av(k,j,i) = ql_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE ( 'qr' )
+                IF ( ALLOCATED( qr_av ) ) THEN
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
+                         DO  k = nzb, nzt+1
+                            qr_av(k,j,i) = qr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
+
+             CASE DEFAULT
+                CONTINUE
+
+          END SELECT
+
+       ENDIF
+
+    END SUBROUTINE bcm_3d_data_averaging
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Define 2D output variables.
+!------------------------------------------------------------------------------!
+ SUBROUTINE bcm_data_output_2d( av, variable, found, grid, mode, local_pf,     &
+                                two_d, nzb_do, nzt_do )
+
+
+    IMPLICIT NONE
+
+    CHARACTER (LEN=*), INTENT(INOUT) ::  grid       !< name of vertical grid
+    CHARACTER (LEN=*), INTENT(IN) ::  mode       !< either 'xy', 'xz' or 'yz'
+    CHARACTER (LEN=*), INTENT(IN) ::  variable   !< name of variable
+
+    INTEGER(iwp), INTENT(IN) ::  av        !< flag for (non-)average output
+    INTEGER(iwp), INTENT(IN) ::  nzb_do    !< vertical output index (bottom)
+    INTEGER(iwp), INTENT(IN) ::  nzt_do    !< vertical output index (top)
+
+    INTEGER(iwp) ::  flag_nr   !< number of masking flag
+
+    INTEGER(iwp) ::  i         !< loop index along x-direction
+    INTEGER(iwp) ::  j         !< loop index along y-direction
+    INTEGER(iwp) ::  k         !< loop index along z-direction
+
+    LOGICAL, INTENT(INOUT) ::  found   !< flag if output variable is found
+    LOGICAL, INTENT(INOUT) ::  two_d !< flag parameter that indicates 2D variables (horizontal cross sections)
+    LOGICAL ::  resorted  !< flag if output is already resorted
+
+    REAL(wp), PARAMETER ::  fill_value = -999.0_wp  !< value for the _FillValue attribute
+
+    REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do), INTENT(INOUT) ::  local_pf !< local
+       !< array to which output data is resorted to
+
+    REAL(wp), DIMENSION(:,:,:), POINTER ::  to_be_resorted  !< points to selected output variable
+
+    found = .TRUE.
+    resorted = .FALSE.
+!
+!-- Set masking flag for topography for not resorted arrays
+    flag_nr = 0    ! 0 = scalar, 1 = u, 2 = v, 3 = w
+
+    SELECT CASE ( TRIM( variable ) )
+
+       CASE ( 'nc_xy', 'nc_xz', 'nc_yz' )
+          IF ( av == 0 )  THEN
+             to_be_resorted => nc
+          ELSE
+             IF ( .NOT. ALLOCATED( nc_av ) ) THEN
+                ALLOCATE( nc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                nc_av = REAL( fill_value, KIND = wp )
+             ENDIF
+             to_be_resorted => nc_av
+          ENDIF
+          IF ( mode == 'xy' ) grid = 'zu'
+
+       CASE ( 'nr_xy', 'nr_xz', 'nr_yz' )
+          IF ( av == 0 )  THEN
+             to_be_resorted => nr
+          ELSE
+             IF ( .NOT. ALLOCATED( nr_av ) ) THEN
+                ALLOCATE( nr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                nr_av = REAL( fill_value, KIND = wp )
+             ENDIF
+             to_be_resorted => nr_av
+          ENDIF
+          IF ( mode == 'xy' ) grid = 'zu'
+
+       CASE ( 'pra*_xy' )        ! 2d-array / integral quantity => no av
+!                CALL exchange_horiz_2d( precipitation_amount )
+          DO  i = nxl, nxr
+             DO  j = nys, nyn
+                local_pf(i,j,nzb+1) =  precipitation_amount(j,i)
+             ENDDO
+          ENDDO
+          precipitation_amount = 0.0_wp   ! reset for next integ. interval
+          resorted = .TRUE.
+          two_d = .TRUE.
+          IF ( mode == 'xy' ) grid = 'zu1'
+
+       CASE ( 'prr_xy', 'prr_xz', 'prr_yz' )
+          IF ( av == 0 )  THEN
+!                   CALL exchange_horiz( prr, nbgp )
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = nzb, nzt+1
+                      local_pf(i,j,k) = prr(k,j,i) * hyrho(nzb+1)
+                   ENDDO
+                ENDDO
+             ENDDO
+          ELSE
+             IF ( .NOT. ALLOCATED( prr_av ) ) THEN
+                ALLOCATE( prr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                prr_av = REAL( fill_value, KIND = wp )
+             ENDIF
+!                   CALL exchange_horiz( prr_av, nbgp )
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = nzb, nzt+1
+                      local_pf(i,j,k) = prr_av(k,j,i) * hyrho(nzb+1)
+                   ENDDO
+                ENDDO
+             ENDDO
+          ENDIF
+          resorted = .TRUE.
+          IF ( mode == 'xy' ) grid = 'zu'
+
+       CASE ( 'qc_xy', 'qc_xz', 'qc_yz' )
+          IF ( av == 0 )  THEN
+             to_be_resorted => qc
+          ELSE
+             IF ( .NOT. ALLOCATED( qc_av ) ) THEN
+                ALLOCATE( qc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                qc_av = REAL( fill_value, KIND = wp )
+             ENDIF
+             to_be_resorted => qc_av
+          ENDIF
+          IF ( mode == 'xy' ) grid = 'zu'
+
+       CASE ( 'ql_xy', 'ql_xz', 'ql_yz' )
+          IF ( av == 0 )  THEN
+             to_be_resorted => ql
+          ELSE
+             IF ( .NOT. ALLOCATED( ql_av ) ) THEN
+                ALLOCATE( ql_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                ql_av = REAL( fill_value, KIND = wp )
+             ENDIF
+             to_be_resorted => ql_av
+          ENDIF
+          IF ( mode == 'xy' ) grid = 'zu'
+
+       CASE ( 'qr_xy', 'qr_xz', 'qr_yz' )
+          IF ( av == 0 )  THEN
+             to_be_resorted => qr
+          ELSE
+             IF ( .NOT. ALLOCATED( qr_av ) ) THEN
+                ALLOCATE( qr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                qr_av = REAL( fill_value, KIND = wp )
+             ENDIF
+             to_be_resorted => qr_av
+          ENDIF
+          IF ( mode == 'xy' ) grid = 'zu'
+
+       CASE DEFAULT
+          found = .FALSE.
+          grid  = 'none'
+
+    END SELECT
+
+    IF ( found .AND. .NOT. resorted )  THEN
+       DO  i = nxl, nxr
+          DO  j = nys, nyn
+             DO  k = nzb_do, nzt_do
+                local_pf(i,j,k) = MERGE( &
+                                     to_be_resorted(k,j,i),                    &
+                                     REAL( fill_value, KIND = wp ),            &
+                                     BTEST( wall_flags_0(k,j,i), flag_nr )     &
+                                  )
+             ENDDO
+          ENDDO
+       ENDDO
+    ENDIF
+
+ END SUBROUTINE bcm_data_output_2d
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Define 3D output variables.
+!------------------------------------------------------------------------------!
+ SUBROUTINE bcm_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
+
+
+    IMPLICIT NONE
+
+    CHARACTER (LEN=*), INTENT(IN) ::  variable   !< name of variable
+
+    INTEGER(iwp), INTENT(IN) ::  av        !< flag for (non-)average output
+    INTEGER(iwp), INTENT(IN) ::  nzb_do    !< lower limit of the data output (usually 0)
+    INTEGER(iwp), INTENT(IN) ::  nzt_do    !< vertical upper limit of the data output (usually nz_do3d)
+
+    INTEGER(iwp) ::  flag_nr   !< number of masking flag
+
+    INTEGER(iwp) ::  i         !< loop index along x-direction
+    INTEGER(iwp) ::  j         !< loop index along y-direction
+    INTEGER(iwp) ::  k         !< loop index along z-direction
+
+    LOGICAL, INTENT(INOUT) ::  found     !< flag if output variable is found
+    LOGICAL ::  resorted  !< flag if output is already resorted
+
+    REAL(wp) ::  fill_value = -999.0_wp  !< value for the _FillValue attribute
+
+    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do), INTENT(INOUT) ::  local_pf   !< local
+       !< array to which output data is resorted to
+
+    REAL(wp), DIMENSION(:,:,:), POINTER ::  to_be_resorted  !< points to selected output variable
+
+    found = .TRUE.
+    resorted = .FALSE.
+!
+!-- Set masking flag for topography for not resorted arrays
+    flag_nr = 0    ! 0 = scalar, 1 = u, 2 = v, 3 = w
+
+    SELECT CASE ( TRIM( variable ) )
+
+       CASE ( 'nc' )
+          IF ( av == 0 )  THEN
+             to_be_resorted => nc
+          ELSE
+             IF ( .NOT. ALLOCATED( nc_av ) ) THEN
+                ALLOCATE( nc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                nc_av = REAL( fill_value, KIND = wp )
+             ENDIF
+             to_be_resorted => nc_av
+          ENDIF
+
+       CASE ( 'nr' )
+          IF ( av == 0 )  THEN
+             to_be_resorted => nr
+          ELSE
+             IF ( .NOT. ALLOCATED( nr_av ) ) THEN
+                ALLOCATE( nr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                nr_av = REAL( fill_value, KIND = wp )
+             ENDIF
+             to_be_resorted => nr_av
+          ENDIF
+
+       CASE ( 'prr' )
+          IF ( av == 0 )  THEN
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = nzb_do, nzt_do
+                      local_pf(i,j,k) = prr(k,j,i)
+                   ENDDO
+                ENDDO
+             ENDDO
+          ELSE
+             IF ( .NOT. ALLOCATED( prr_av ) ) THEN
+                ALLOCATE( prr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                prr_av = REAL( fill_value, KIND = wp )
+             ENDIF
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = nzb_do, nzt_do
+                      local_pf(i,j,k) = prr_av(k,j,i)
+                   ENDDO
+                ENDDO
+             ENDDO
+          ENDIF
+          resorted = .TRUE.
+
+       CASE ( 'qc' )
+          IF ( av == 0 )  THEN
+             to_be_resorted => qc
+          ELSE
+             IF ( .NOT. ALLOCATED( qc_av ) ) THEN
+                ALLOCATE( qc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                qc_av = REAL( fill_value, KIND = wp )
+             ENDIF
+             to_be_resorted => qc_av
+          ENDIF
+
+       CASE ( 'ql' )
+          IF ( av == 0 )  THEN
+             to_be_resorted => ql
+          ELSE
+             IF ( .NOT. ALLOCATED( ql_av ) ) THEN
+                ALLOCATE( ql_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                ql_av = REAL( fill_value, KIND = wp )
+             ENDIF
+             to_be_resorted => ql_av
+          ENDIF
+
+       CASE ( 'qr' )
+          IF ( av == 0 )  THEN
+             to_be_resorted => qr
+          ELSE
+             IF ( .NOT. ALLOCATED( qr_av ) ) THEN
+                ALLOCATE( qr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                qr_av = REAL( fill_value, KIND = wp )
+             ENDIF
+             to_be_resorted => qr_av
+          ENDIF
+
+       CASE DEFAULT
+          found = .FALSE.
+
+    END SELECT
+
+
+    IF ( found .AND. .NOT. resorted )  THEN
+       DO  i = nxl, nxr
+          DO  j = nys, nyn
+             DO  k = nzb_do, nzt_do
+                local_pf(i,j,k) = MERGE(                                       &
+                                     to_be_resorted(k,j,i),                    &
+                                     REAL( fill_value, KIND = wp ),            &
+                                     BTEST( wall_flags_0(k,j,i), flag_nr )     &
+                                  )
+             ENDDO
+          ENDDO
+       ENDDO
+    ENDIF
+
+ END SUBROUTINE bcm_data_output_3d
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This routine reads the respective restart data for the microphysics module.
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_rrd_global( found )
+
+
+       USE control_parameters,                                                 &
+           ONLY: length, restart_string
+
+
+       IMPLICIT NONE
+
+       LOGICAL, INTENT(OUT)  ::  found
+
+
+       found = .TRUE.
+
+       SELECT CASE ( restart_string(1:length) )
+
+          CASE ( 'c_sedimentation' )
+             READ ( 13 )  c_sedimentation
+
+          CASE ( 'bulk_cloud_model' )
+             READ ( 13 )  bulk_cloud_model
+
+          CASE ( 'cloud_scheme' )
+             READ ( 13 )  cloud_scheme
+
+          CASE ( 'cloud_water_sedimentation' )
+             READ ( 13 )  cloud_water_sedimentation
+
+          CASE ( 'collision_turbulence' )
+             READ ( 13 )  collision_turbulence
+
+          CASE ( 'limiter_sedimentation' )
+             READ ( 13 )  limiter_sedimentation
+
+          CASE ( 'nc_const' )
+             READ ( 13 )  nc_const
+
+          CASE ( 'precipitation' )
+             READ ( 13 ) precipitation
+
+          CASE ( 'ventilation_effect' )
+             READ ( 13 )  ventilation_effect
+
+!          CASE ( 'global_paramter' )
+!             READ ( 13 )  global_parameter
+!          CASE ( 'global_array' )
+!             IF ( .NOT. ALLOCATED( global_array ) )  ALLOCATE( global_array(1:10) )
+!             READ ( 13 )  global_array
+
+          CASE DEFAULT
+
+             found = .FALSE.
+
+       END SELECT
+
+
+    END SUBROUTINE bcm_rrd_global
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This routine reads the respective restart data for the microphysics module.
+!------------------------------------------------------------------------------!
+    SUBROUTINE 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 )
+
+
+       USE control_parameters
+
+       USE indices
+
+       USE pegrid
+
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i               !<
+       INTEGER(iwp) ::  k               !<
+       INTEGER(iwp) ::  nxlc            !<
+       INTEGER(iwp) ::  nxlf            !<
+       INTEGER(iwp) ::  nxl_on_file     !<
+       INTEGER(iwp) ::  nxrc            !<
+       INTEGER(iwp) ::  nxrf            !<
+       INTEGER(iwp) ::  nxr_on_file     !<
+       INTEGER(iwp) ::  nync            !<
+       INTEGER(iwp) ::  nynf            !<
+       INTEGER(iwp) ::  nyn_on_file     !<
+       INTEGER(iwp) ::  nysc            !<
+       INTEGER(iwp) ::  nysf            !<
+       INTEGER(iwp) ::  nys_on_file     !<
+
+       LOGICAL, INTENT(OUT)  ::  found
+
+       REAL(wp), DIMENSION(nys_on_file-nbgp:nyn_on_file+nbgp,nxl_on_file-nbgp:nxr_on_file+nbgp) :: tmp_2d   !<
+       REAL(wp), DIMENSION(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp,nxl_on_file-nbgp:nxr_on_file+nbgp) :: tmp_3d   !<
+
+!
+!-- Here the reading of user-defined restart data follows:
+!-- Sample for user-defined output
+
+
+       found = .TRUE.
+
+       SELECT CASE ( restart_string(1:length) )
+
+          CASE ( 'nc' )
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             nc(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =             &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'nc_av' )
+             IF ( .NOT. ALLOCATED( nc_av ) )  THEN
+                ALLOCATE( nc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+             ENDIF
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             nc_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'nr' )
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             nr(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =             &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'nr_av' )
+             IF ( .NOT. ALLOCATED( nr_av ) )  THEN
+                ALLOCATE( nr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+             ENDIF
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             nr_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'precipitation_amount' )
+             IF ( k == 1 )  READ ( 13 )  tmp_2d
+             precipitation_amount(nysc-nbgp:nync+nbgp,                   &
+                                  nxlc-nbgp:nxrc+nbgp)  =                &
+                   tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'prr' )
+             IF ( .NOT. ALLOCATED( prr ) )  THEN
+                ALLOCATE( prr(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+             ENDIF
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             prr(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =            &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'prr_av' )
+             IF ( .NOT. ALLOCATED( prr_av ) )  THEN
+                ALLOCATE( prr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+             ENDIF
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             prr_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =         &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'qc' )
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             qc(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =             &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'qc_av' )
+             IF ( .NOT. ALLOCATED( qc_av ) )  THEN
+                ALLOCATE( qc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+             ENDIF
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             qc_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'ql' )
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             ql(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =             &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'ql_av' )
+             IF ( .NOT. ALLOCATED( ql_av ) )  THEN
+                ALLOCATE( ql_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+             ENDIF
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             ql_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'qr' )
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             qr(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =             &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'qr_av' )
+             IF ( .NOT. ALLOCATED( qr_av ) )  THEN
+                ALLOCATE( qr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+             ENDIF
+             IF ( k == 1 )  READ ( 13 )  tmp_3d
+             qr_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
+                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+!
+          CASE DEFAULT
+
+             found = .FALSE.
+
+          END SELECT
+
+
+    END SUBROUTINE bcm_rrd_local
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This routine writes the respective restart data for the microphysics module.
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_wrd_global
+
+
+       IMPLICIT NONE
+
+       CALL wrd_write_string( 'c_sedimentation' )
+       WRITE ( 14 )  c_sedimentation
+
+       CALL wrd_write_string( 'bulk_cloud_model' )
+       WRITE ( 14 )  bulk_cloud_model
+
+       CALL wrd_write_string( 'cloud_scheme' )
+       WRITE ( 14 )  cloud_scheme
+
+       CALL wrd_write_string( 'cloud_water_sedimentation' )
+       WRITE ( 14 )  cloud_water_sedimentation
+
+       CALL wrd_write_string( 'collision_turbulence' )
+       WRITE ( 14 )  collision_turbulence
+
+       CALL wrd_write_string( 'limiter_sedimentation' )
+       WRITE ( 14 )  limiter_sedimentation
+
+       CALL wrd_write_string( 'nc_const' )
+       WRITE ( 14 )  nc_const
+
+       CALL wrd_write_string( 'precipitation' )
+       WRITE ( 14 )  precipitation
+
+       CALL wrd_write_string( 'ventilation_effect' )
+       WRITE ( 14 )  ventilation_effect
+
+! needs preceeding allocation if array
+!       CALL wrd_write_string( 'global_parameter' )
+!       WRITE ( 14 )  global_parameter
+
+!       IF ( ALLOCATED( inflow_damping_factor ) )  THEN
+!          CALL wrd_write_string( 'inflow_damping_factor' )
+!          WRITE ( 14 )  inflow_damping_factor
+!       ENDIF
+
+
+    END SUBROUTINE bcm_wrd_global
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This routine writes the respective restart data for the microphysics module.
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_wrd_local
+
+
+       IMPLICIT NONE
+
+       IF ( ALLOCATED( prr ) )  THEN
+          CALL wrd_write_string( 'prr' )
+          WRITE ( 14 )  prr
+       ENDIF
+
+       IF ( ALLOCATED( prr_av ) )  THEN
+          CALL wrd_write_string( 'prr_av' )
+          WRITE ( 14 )  prr_av
+       ENDIF
+
+       IF ( ALLOCATED( precipitation_amount ) )  THEN
+          CALL wrd_write_string( 'precipitation_amount' )
+          WRITE ( 14 )  precipitation_amount
+       ENDIF
+
+       CALL wrd_write_string( 'ql' )
+       WRITE ( 14 )  ql
+
+       IF ( ALLOCATED( ql_av ) )  THEN
+          CALL wrd_write_string( 'ql_av' )
+          WRITE ( 14 )  ql_av
+       ENDIF
+
+       CALL wrd_write_string( 'qc' )
+       WRITE ( 14 )  qc
+
+       IF ( ALLOCATED( qc_av ) )  THEN
+          CALL wrd_write_string( 'qc_av' )
+          WRITE ( 14 )  qc_av
+       ENDIF
+
+       IF ( microphysics_morrison )  THEN
+
+          CALL wrd_write_string( 'nc' )
+          WRITE ( 14 )  nc
+
+          IF ( ALLOCATED( nc_av ) )  THEN
+             CALL wrd_write_string( 'nc_av' )
+             WRITE ( 14 )  nc_av
+          ENDIF
+
+       ENDIF
+
+       IF ( microphysics_seifert )  THEN
+
+          CALL wrd_write_string( 'nr' )
+          WRITE ( 14 )  nr
+
+          IF ( ALLOCATED( nr_av ) )  THEN
+             CALL wrd_write_string( 'nr_av' )
+             WRITE ( 14 )  nr_av
+          ENDIF
+
+          CALL wrd_write_string( 'qr' )
+          WRITE ( 14 )  qr
+
+          IF ( ALLOCATED( qr_av ) )  THEN
+             CALL wrd_write_string( 'qr_av' )
+             WRITE ( 14 )  qr_av
+          ENDIF
+
+       ENDIF
+
+
+    END SUBROUTINE bcm_wrd_local
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Control of microphysics for all grid points
+!------------------------------------------------------------------------------!
+    SUBROUTINE bcm_actions
+
+       IMPLICIT NONE
+
+       IF ( large_scale_forcing  .AND.  lsf_surf ) THEN
+!
+!--       Calculate vertical profile of the hydrostatic pressure (hyp)
+          hyp    = barometric_formula(zu, pt_surface * exner_function(surface_pressure * 100.0_wp), surface_pressure * 100.0_wp)
+          d_exner = exner_function_invers(hyp)
+          exner = 1.0_wp / exner_function_invers(hyp)
+          hyrho  = ideal_gas_law_rho_pt(hyp, pt_init)
+!
+!--       Compute reference density
+          rho_surface = ideal_gas_law_rho(surface_pressure * 100.0_wp, pt_surface * exner_function(surface_pressure * 100.0_wp))
+       ENDIF
+
+!
+!--    Compute length of time step
+       IF ( call_microphysics_at_all_substeps )  THEN
+          dt_micro = dt_3d * weight_pres(intermediate_timestep_count)
+       ELSE
+          dt_micro = dt_3d
+       ENDIF
+
+!
+!--    Reset precipitation rate
+       IF ( intermediate_timestep_count == 1 )  prr = 0.0_wp
+
+!
+!--    Compute cloud physics
+       IF ( microphysics_kessler )  THEN
+
+          CALL autoconversion_kessler
+          IF ( cloud_water_sedimentation )  CALL sedimentation_cloud
+
+       ELSEIF ( microphysics_seifert )  THEN
+
+          CALL adjust_cloud
+          IF ( microphysics_morrison )  CALL activation
+          IF ( microphysics_morrison )  CALL condensation
+          CALL autoconversion
+          CALL accretion
+          CALL selfcollection_breakup
+          CALL evaporation_rain
+          CALL sedimentation_rain
+          IF ( cloud_water_sedimentation )  CALL sedimentation_cloud
+
+       ENDIF
+
+       CALL calc_precipitation_amount
+
+    END SUBROUTINE bcm_actions
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Adjust number of raindrops to avoid nonlinear effects in sedimentation and
+!> evaporation of rain drops due to too small or too big weights
+!> of rain drops (Stevens and Seifert, 2008).
+!------------------------------------------------------------------------------!
+    SUBROUTINE adjust_cloud
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp) ::  flag                  !< flag to indicate first grid level above
+
+       CALL cpu_log( log_point_s(54), 'adjust_cloud', 'start' )
+
+       DO  i = nxlg, nxrg
+          DO  j = nysg, nyng
+             DO  k = nzb+1, nzt
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+                IF ( qr(k,j,i) <= eps_sb )  THEN
+                   qr(k,j,i) = 0.0_wp
+                   nr(k,j,i) = 0.0_wp
+                ELSE
+                   IF ( nr(k,j,i) * xrmin > qr(k,j,i) * hyrho(k) )  THEN
+                      nr(k,j,i) = qr(k,j,i) * hyrho(k) / xrmin * flag
+                   ELSEIF ( nr(k,j,i) * xrmax < qr(k,j,i) * hyrho(k) )  THEN
+                      nr(k,j,i) = qr(k,j,i) * hyrho(k) / xrmax * flag
+                   ENDIF
+                ENDIF
+
+                IF ( microphysics_morrison ) THEN
+                   IF ( qc(k,j,i) <= eps_sb )  THEN
+                      qc(k,j,i) = 0.0_wp
+                      nc(k,j,i) = 0.0_wp
+                   ELSE
+                      IF ( nc(k,j,i) * xcmin > qc(k,j,i) * hyrho(k) )  THEN
+                         nc(k,j,i) = qc(k,j,i) * hyrho(k) / xcmin * flag
+                      ENDIF
+                   ENDIF
+                ENDIF
+
+             ENDDO
+          ENDDO
+       ENDDO
+
+       CALL cpu_log( log_point_s(54), 'adjust_cloud', 'stop' )
+
+    END SUBROUTINE adjust_cloud
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Calculate number of activated condensation nucleii after simple activation
+!> scheme of Twomey, 1959.
+!------------------------------------------------------------------------------!
+    SUBROUTINE activation
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  activ             !<
+       REAL(wp)     ::  afactor           !<
+       REAL(wp)     ::  beta_act          !<
+       REAL(wp)     ::  bfactor           !<
+       REAL(wp)     ::  k_act             !<
+       REAL(wp)     ::  n_act             !<
+       REAL(wp)     ::  n_ccn             !<
+       REAL(wp)     ::  s_0               !<
+       REAL(wp)     ::  sat_max           !<
+       REAL(wp)     ::  sigma             !<
+       REAL(wp)     ::  sigma_act         !<
+
+       REAL(wp) ::  flag                  !< flag to indicate first grid level above
+
+       CALL cpu_log( log_point_s(65), 'activation', 'start' )
+
+       DO  i = nxlg, nxrg
+          DO  j = nysg, nyng
+             DO  k = nzb+1, nzt
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+!
+!--             Call calculation of supersaturation located 
+!--             in diagnostic_quantities_mod
+                CALL supersaturation ( i, j, k )
+!
+!--             Prescribe parameters for activation
+!--             (see: Bott + Trautmann, 2002, Atm. Res., 64)
+                k_act  = 0.7_wp
+                activ  = 0.0_wp
+
+
+                IF ( sat > 0.0 .AND. .NOT. curvature_solution_effects_bulk ) THEN
+!
+!--                Compute the number of activated Aerosols
+!--                (see: Twomey, 1959, Pure and applied Geophysics, 43)
+                   n_act     = na_init * sat**k_act
+!
+!--                Compute the number of cloud droplets
+!--                (see: Morrison + Grabowski, 2007, JAS, 64)
+!                  activ = MAX( n_act - nc(k,j,i), 0.0_wp) / dt_micro
+
+!
+!--                Compute activation rate after Khairoutdinov and Kogan
+!--                (see: Khairoutdinov + Kogan, 2000, Mon. Wea. Rev., 128)
+                   sat_max = 1.0_wp / 100.0_wp
+                   activ   = MAX( 0.0_wp, ( (na_init + nc(k,j,i) ) * MIN       &
+                      ( 1.0_wp, ( sat / sat_max )**k_act) - nc(k,j,i) ) ) /    &
+                       dt_micro
+                ELSEIF ( sat > 0.0 .AND. curvature_solution_effects_bulk ) THEN
+!
+!--                Curvature effect (afactor) with surface tension
+!--                parameterization by Straka (2009)
+                   sigma = 0.0761_wp - 0.000155_wp * ( t_l - 273.15_wp )
+                   afactor = 2.0_wp * sigma / ( rho_l * r_v * t_l )
+!
+!--                Solute effect (bfactor)
+                   bfactor = vanthoff * molecular_weight_of_water *            &
+                       rho_s / ( molecular_weight_of_solute * rho_l )
+
+!
+!--                Prescribe power index that describes the soluble fraction
+!--                of an aerosol particle (beta) 
+!--                (see: Morrison + Grabowski, 2007, JAS, 64)
+                   beta_act  = 0.5_wp
+                   sigma_act = sigma_bulk**( 1.0_wp + beta_act )
+!
+!--                Calculate mean geometric supersaturation (s_0) with
+!--                parameterization by Khvorostyanov and Curry (2006)
+                   s_0   = dry_aerosol_radius **(- ( 1.0_wp + beta_act ) ) *    &
+                       ( 4.0_wp * afactor**3 / ( 27.0_wp * bfactor ) )**0.5_wp
+
+!
+!--                Calculate number of activated CCN as a function of
+!--                supersaturation and taking Koehler theory into account
+!--                (see: Khvorostyanov + Curry, 2006, J. Geo. Res., 111)
+                   n_ccn = ( na_init / 2.0_wp ) * ( 1.0_wp - ERF(              &
+                      LOG( s_0 / sat ) / ( SQRT(2.0_wp) * LOG(sigma_act) ) ) )
+                   activ = MAX( ( n_ccn - nc(k,j,i) ) / dt_micro, 0.0_wp )
+                ENDIF
+
+                nc(k,j,i) = MIN( (nc(k,j,i) + activ * dt_micro * flag), na_init)
+
+             ENDDO
+          ENDDO
+       ENDDO
+
+       CALL cpu_log( log_point_s(65), 'activation', 'stop' )
+
+    END SUBROUTINE activation
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Calculate condensation rate for cloud water content (after Khairoutdinov and
+!> Kogan, 2000).
+!------------------------------------------------------------------------------!
+    SUBROUTINE condensation
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  cond              !<
+       REAL(wp)     ::  cond_max          !<
+       REAL(wp)     ::  dc                !<
+       REAL(wp)     ::  evap              !<
+       REAL(wp)     ::  g_fac             !<
+       REAL(wp)     ::  nc_0              !<
+       REAL(wp)     ::  temp              !<
+       REAL(wp)     ::  xc                !<
+
+       REAL(wp) ::  flag                  !< flag to indicate first grid level above
+
+       CALL cpu_log( log_point_s(66), 'condensation', 'start' )
+
+       DO  i = nxlg, nxrg
+          DO  j = nysg, nyng
+             DO  k = nzb+1, nzt
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+!
+!--             Call calculation of supersaturation located 
+!--             in diagnostic_quantities_mod
+                CALL supersaturation ( i, j, k )
+!
+!--             Actual temperature:
+                temp = t_l + lv_d_cp * ( qc(k,j,i) + qr(k,j,i) )
+
+                g_fac  = 1.0_wp / ( ( l_v / ( r_v * temp ) - 1.0_wp ) *        &
+                                    l_v / ( thermal_conductivity_l * temp )    &
+                                    + r_v * temp / ( diff_coeff_l * e_s )      &
+                                    )
+!
+!--             Mean weight of cloud drops
+                IF ( nc(k,j,i) <= 0.0_wp) CYCLE
+                xc = MAX( (hyrho(k) * qc(k,j,i) / nc(k,j,i)), xcmin)
+!
+!--             Weight averaged diameter of cloud drops:
+                dc   = ( xc * dpirho_l )**( 1.0_wp / 3.0_wp )
+!
+!--             Integral diameter of cloud drops
+                nc_0 = nc(k,j,i) * dc
+!
+!--             Condensation needs only to be calculated in supersaturated regions
+                IF ( sat > 0.0_wp )  THEN
+!
+!--                Condensation rate of cloud water content
+!--                after KK scheme.
+!--                (see: Khairoutdinov + Kogan, 2000, Mon. Wea. Rev.,128)
+                   cond      = 2.0_wp * pi * nc_0 * g_fac * sat / hyrho(k)
+                   cond_max  = q(k,j,i) - q_s - qc(k,j,i) - qr(k,j,i)
+                   cond      = MIN( cond, cond_max / dt_micro )
+
+                   qc(k,j,i) = qc(k,j,i) + cond * dt_micro * flag
+                ELSEIF ( sat < 0.0_wp ) THEN
+                   evap      = 2.0_wp * pi * nc_0 * g_fac * sat / hyrho(k)
+                   evap      = MAX( evap, -qc(k,j,i) / dt_micro )
+
+                   qc(k,j,i) = qc(k,j,i) + evap * dt_micro * flag
+                ENDIF
+                IF ( nc(k,j,i) * xcmin > qc(k,j,i) * hyrho(k) )  THEN
+                   nc(k,j,i) = qc(k,j,i) * hyrho(k) / xcmin
+                ENDIF
+             ENDDO
+          ENDDO
+       ENDDO
+
+       CALL cpu_log( log_point_s(66), 'condensation', 'stop' )
+
+    END SUBROUTINE condensation
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Autoconversion rate (Seifert and Beheng, 2006).
+!------------------------------------------------------------------------------!
+    SUBROUTINE autoconversion
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  alpha_cc          !<
+       REAL(wp)     ::  autocon           !<
+       REAL(wp)     ::  dissipation       !<
+       REAL(wp)     ::  flag              !< flag to mask topography grid points
+       REAL(wp)     ::  k_au              !<
+       REAL(wp)     ::  l_mix             !<
+       REAL(wp)     ::  nc_auto           !<
+       REAL(wp)     ::  nu_c              !<
+       REAL(wp)     ::  phi_au            !<
+       REAL(wp)     ::  r_cc              !<
+       REAL(wp)     ::  rc                !<
+       REAL(wp)     ::  re_lambda         !<
+       REAL(wp)     ::  sigma_cc          !<
+       REAL(wp)     ::  tau_cloud         !<
+       REAL(wp)     ::  xc                !<
+
+       CALL cpu_log( log_point_s(55), 'autoconversion', 'start' )
+
+       DO  i = nxlg, nxrg
+          DO  j = nysg, nyng
+             DO  k = nzb+1, nzt
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+                IF ( microphysics_morrison ) THEN
+                   nc_auto = nc(k,j,i)
+                ELSE
+                   nc_auto = nc_const
+                ENDIF
+
+                IF ( qc(k,j,i) > eps_sb  .AND.  nc_auto > eps_mr )  THEN
+
+                   k_au = k_cc / ( 20.0_wp * x0 )
+!
+!--                Intern time scale of coagulation (Seifert and Beheng, 2006):
+!--                (1.0_wp - qc(k,j,i) / ( qc(k,j,i) + qr(k,j,i) ))
+                   tau_cloud = MAX( 1.0_wp - qc(k,j,i) / ( qr(k,j,i) +         &
+                                    qc(k,j,i) ), 0.0_wp )
+!
+!--                Universal function for autoconversion process
+!--                (Seifert and Beheng, 2006):
+                   phi_au = 600.0_wp * tau_cloud**0.68_wp *                    &
+                            ( 1.0_wp - tau_cloud**0.68_wp )**3
+!
+!--                Shape parameter of gamma distribution (Geoffroy et al., 2010):
+!--                (Use constant nu_c = 1.0_wp instead?)
+                   nu_c = 1.0_wp !MAX( 0.0_wp, 1580.0_wp * hyrho(k) * qc(k,j,i) - 0.28_wp )
+!
+!--                Mean weight of cloud droplets:
+                   xc = MAX( hyrho(k) * qc(k,j,i) / nc_auto, xcmin) 
+!
+!--                Parameterized turbulence effects on autoconversion (Seifert,
+!--                Nuijens and Stevens, 2010)
+                   IF ( collision_turbulence )  THEN
+!
+!--                   Weight averaged radius of cloud droplets:
+                      rc = 0.5_wp * ( xc * dpirho_l )**( 1.0_wp / 3.0_wp )
+
+                      alpha_cc = ( a_1 + a_2 * nu_c ) / ( 1.0_wp + a_3 * nu_c )
+                      r_cc     = ( b_1 + b_2 * nu_c ) / ( 1.0_wp + b_3 * nu_c )
+                      sigma_cc = ( c_1 + c_2 * nu_c ) / ( 1.0_wp + c_3 * nu_c )
+!
+!--                   Mixing length (neglecting distance to ground and
+!--                   stratification)
+                      l_mix = ( dx * dy * dzu(k) )**( 1.0_wp / 3.0_wp )
+!
+!--                   Limit dissipation rate according to Seifert, Nuijens and
+!--                   Stevens (2010)
+                      dissipation = MIN( 0.06_wp, diss(k,j,i) )
+!
+!--                   Compute Taylor-microscale Reynolds number:
+                      re_lambda = 6.0_wp / 11.0_wp *                           &
+                                  ( l_mix / c_const )**( 2.0_wp / 3.0_wp ) *   &
+                                  SQRT( 15.0_wp / kin_vis_air ) *              &
+                                  dissipation**( 1.0_wp / 6.0_wp )
+!
+!--                   The factor of 1.0E4 is needed to convert the dissipation
+!--                   rate from m2 s-3 to cm2 s-3.
+                      k_au = k_au * ( 1.0_wp +                                 &
+                                      dissipation * 1.0E4_wp *                 &
+                                      ( re_lambda * 1.0E-3_wp )**0.25_wp *     &
+                                      ( alpha_cc * EXP( -1.0_wp * ( ( rc -     &
+                                                                      r_cc ) / &
+                                                        sigma_cc )**2          &
+                                                      ) + beta_cc              &
+                                      )                                        &
+                                    )
+                   ENDIF
+!
+!--                Autoconversion rate (Seifert and Beheng, 2006):
+                   autocon = k_au * ( nu_c + 2.0_wp ) * ( nu_c + 4.0_wp ) /    &
+                             ( nu_c + 1.0_wp )**2 * qc(k,j,i)**2 * xc**2 *     &
+                             ( 1.0_wp + phi_au / ( 1.0_wp - tau_cloud )**2 ) * &
+                             rho_surface
+                   autocon = MIN( autocon, qc(k,j,i) / dt_micro )
+
+                   qr(k,j,i) = qr(k,j,i) + autocon * dt_micro * flag
+                   qc(k,j,i) = qc(k,j,i) - autocon * dt_micro * flag
+                   nr(k,j,i) = nr(k,j,i) + autocon / x0 * hyrho(k) * dt_micro  &
+                                                              * flag
+                   IF ( microphysics_morrison ) THEN
+                      nc(k,j,i) = nc(k,j,i) - MIN( nc(k,j,i), 2.0_wp *         &
+                                    autocon / x0 * hyrho(k) * dt_micro * flag )
+                   ENDIF
+
+                ENDIF
+
+             ENDDO
+          ENDDO
+       ENDDO
+
+       CALL cpu_log( log_point_s(55), 'autoconversion', 'stop' )
+
+    END SUBROUTINE autoconversion
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Autoconversion process (Kessler, 1969).
+!------------------------------------------------------------------------------!
+    SUBROUTINE autoconversion_kessler
+
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i      !<
+       INTEGER(iwp) ::  j      !<
+       INTEGER(iwp) ::  k      !<
+       INTEGER(iwp) ::  k_wall !< topgraphy top index
+
+       REAL(wp)    ::  dqdt_precip !<
+       REAL(wp)    ::  flag        !< flag to mask topography grid points
+
+       DO  i = nxlg, nxrg
+          DO  j = nysg, nyng
+!
+!--          Determine vertical index of topography top
+             k_wall = get_topography_top_index_ji( j, i, 's' )
+             DO  k = nzb+1, nzt
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+                IF ( qc(k,j,i) > ql_crit )  THEN
+                   dqdt_precip = prec_time_const * ( qc(k,j,i) - ql_crit )
+                ELSE
+                   dqdt_precip = 0.0_wp
+                ENDIF
+
+                qc(k,j,i) = qc(k,j,i) - dqdt_precip * dt_micro * flag
+                q(k,j,i)  = q(k,j,i)  - dqdt_precip * dt_micro * flag
+                pt(k,j,i) = pt(k,j,i) + dqdt_precip * dt_micro * lv_d_cp *     &
+                                        d_exner(k)              * flag
+
+!
+!--             Compute the rain rate (stored on surface grid point)
+                prr(k_wall,j,i) = prr(k_wall,j,i) + dqdt_precip * dzw(k) * flag
+
+             ENDDO
+          ENDDO
+       ENDDO
+
+   END SUBROUTINE autoconversion_kessler
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Accretion rate (Seifert and Beheng, 2006).
+!------------------------------------------------------------------------------!
+    SUBROUTINE accretion
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  accr              !<
+       REAL(wp)     ::  flag              !< flag to mask topography grid points
+       REAL(wp)     ::  k_cr              !<
+       REAL(wp)     ::  nc_accr           !<
+       REAL(wp)     ::  phi_ac            !<
+       REAL(wp)     ::  tau_cloud         !<
+       REAL(wp)     ::  xc                !<
+
+
+       CALL cpu_log( log_point_s(56), 'accretion', 'start' )
+
+       DO  i = nxlg, nxrg
+          DO  j = nysg, nyng
+             DO  k = nzb+1, nzt
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+                IF ( microphysics_morrison ) THEN
+                   nc_accr = nc(k,j,i)
+                ELSE
+                   nc_accr = nc_const
+                ENDIF
+
+                IF ( ( qc(k,j,i) > eps_sb )  .AND.  ( qr(k,j,i) > eps_sb )    &
+                                             .AND.  ( nc_accr > eps_mr ) ) THEN
+!
+!--                Intern time scale of coagulation (Seifert and Beheng, 2006):
+                   tau_cloud = 1.0_wp - qc(k,j,i) / ( qc(k,j,i) + qr(k,j,i) )
+!
+!--                Universal function for accretion process (Seifert and
+!--                Beheng, 2001):
+                   phi_ac = ( tau_cloud / ( tau_cloud + 5.0E-5_wp ) )**4
+
+!
+!--                Mean weight of cloud drops
+                   xc = MAX( (hyrho(k) * qc(k,j,i) / nc_accr), xcmin)
+!
+!--                Parameterized turbulence effects on autoconversion (Seifert,
+!--                Nuijens and Stevens, 2010). The factor of 1.0E4 is needed to
+!--                convert the dissipation rate (diss) from m2 s-3 to cm2 s-3.
+                   IF ( collision_turbulence )  THEN
+                      k_cr = k_cr0 * ( 1.0_wp + 0.05_wp *                      &
+                                       MIN( 600.0_wp,                          &
+                                            diss(k,j,i) * 1.0E4_wp )**0.25_wp  &
+                                     )
+                   ELSE
+                      k_cr = k_cr0
+                   ENDIF
+!
+!--                Accretion rate (Seifert and Beheng, 2006):
+                   accr = k_cr * qc(k,j,i) * qr(k,j,i) * phi_ac *              &
+                          SQRT( rho_surface * hyrho(k) )
+                   accr = MIN( accr, qc(k,j,i) / dt_micro )
+
+                   qr(k,j,i) = qr(k,j,i) + accr * dt_micro * flag
+                   qc(k,j,i) = qc(k,j,i) - accr * dt_micro * flag
+                   IF ( microphysics_morrison )  THEN
+                      nc(k,j,i) = nc(k,j,i) - MIN( nc(k,j,i),                  &
+                                         accr / xc * hyrho(k) * dt_micro * flag)
+                   ENDIF
+
+                ENDIF
+
+             ENDDO
+          ENDDO
+       ENDDO
+
+       CALL cpu_log( log_point_s(56), 'accretion', 'stop' )
+
+    END SUBROUTINE accretion
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Collisional breakup rate (Seifert, 2008).
+!------------------------------------------------------------------------------!
+    SUBROUTINE selfcollection_breakup
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  breakup           !<
+       REAL(wp)     ::  dr                !<
+       REAL(wp)     ::  flag              !< flag to mask topography grid points
+       REAL(wp)     ::  phi_br            !<
+       REAL(wp)     ::  selfcoll          !<
+
+       CALL cpu_log( log_point_s(57), 'selfcollection', 'start' )
+
+       DO  i = nxlg, nxrg
+          DO  j = nysg, nyng
+             DO  k = nzb+1, nzt
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+                IF ( qr(k,j,i) > eps_sb )  THEN
+!
+!--                Selfcollection rate (Seifert and Beheng, 2001):
+                   selfcoll = k_rr * nr(k,j,i) * qr(k,j,i) *                   &
+                              SQRT( hyrho(k) * rho_surface )
+!
+!--                Weight averaged diameter of rain drops:
+                   dr = ( hyrho(k) * qr(k,j,i) /                               &
+                          nr(k,j,i) * dpirho_l )**( 1.0_wp / 3.0_wp )
+!
+!--                Collisional breakup rate (Seifert, 2008):
+                   IF ( dr >= 0.3E-3_wp )  THEN
+                      phi_br  = k_br * ( dr - 1.1E-3_wp )
+                      breakup = selfcoll * ( phi_br + 1.0_wp )
+                   ELSE
+                      breakup = 0.0_wp
+                   ENDIF
+
+                   selfcoll = MAX( breakup - selfcoll, -nr(k,j,i) / dt_micro )
+                   nr(k,j,i) = nr(k,j,i) + selfcoll * dt_micro * flag
+
+                ENDIF
+             ENDDO
+          ENDDO
+       ENDDO
+
+       CALL cpu_log( log_point_s(57), 'selfcollection', 'stop' )
+
+    END SUBROUTINE selfcollection_breakup
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Evaporation of precipitable water. Condensation is neglected for
+!> precipitable water.
+!------------------------------------------------------------------------------!
+    SUBROUTINE evaporation_rain
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  dr                !<
+       REAL(wp)     ::  evap              !<
+       REAL(wp)     ::  evap_nr           !<
+       REAL(wp)     ::  f_vent            !<
+       REAL(wp)     ::  flag              !< flag to mask topography grid points
+       REAL(wp)     ::  g_evap            !<
+       REAL(wp)     ::  lambda_r          !<
+       REAL(wp)     ::  mu_r              !<
+       REAL(wp)     ::  mu_r_2            !<
+       REAL(wp)     ::  mu_r_5d2          !<
+       REAL(wp)     ::  nr_0              !<
+       REAL(wp)     ::  temp              !<
+       REAL(wp)     ::  xr                !<
+
+       CALL cpu_log( log_point_s(58), 'evaporation', 'start' )
+
+       DO  i = nxlg, nxrg
+          DO  j = nysg, nyng
+             DO  k = nzb+1, nzt
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+                IF ( qr(k,j,i) > eps_sb )  THEN
+
+!
+!--                Call calculation of supersaturation located 
+!--                in diagnostic_quantities_mod
+                   CALL supersaturation ( i, j, k )
+!
+!--                Evaporation needs only to be calculated in subsaturated regions
+                   IF ( sat < 0.0_wp )  THEN
+!
+!--                   Actual temperature:
+                      temp = t_l + lv_d_cp * ( qc(k,j,i) + qr(k,j,i) )
+
+                      g_evap = 1.0_wp / ( ( l_v / ( r_v * temp ) - 1.0_wp ) *     &
+                                          l_v / ( thermal_conductivity_l * temp ) &
+                                          + r_v * temp / ( diff_coeff_l * e_s )   &
+                                        )
+!
+!--                   Mean weight of rain drops
+                      xr = hyrho(k) * qr(k,j,i) / nr(k,j,i)
+!
+!--                   Weight averaged diameter of rain drops:
+                      dr = ( xr * dpirho_l )**( 1.0_wp / 3.0_wp )
+!
+!--                   Compute ventilation factor and intercept parameter
+!--                   (Seifert and Beheng, 2006; Seifert, 2008):
+                      IF ( ventilation_effect )  THEN
+!
+!--                      Shape parameter of gamma distribution (Milbrandt and Yau,
+!--                      2005; Stevens and Seifert, 2008):
+                         mu_r = 10.0_wp * ( 1.0_wp + TANH( 1.2E3_wp *          &
+                                                          ( dr - 1.4E-3_wp ) ) )
+!
+!--                      Slope parameter of gamma distribution (Seifert, 2008):
+                         lambda_r = ( ( mu_r + 3.0_wp ) * ( mu_r + 2.0_wp ) *  &
+                                      ( mu_r + 1.0_wp )                        &
+                                    )**( 1.0_wp / 3.0_wp ) / dr
+
+                         mu_r_2   = mu_r + 2.0_wp
+                         mu_r_5d2 = mu_r + 2.5_wp
+
+                         f_vent = a_vent * gamm( mu_r_2 ) *                     &
+                                  lambda_r**( -mu_r_2 ) + b_vent *              &
+                                  schmidt_p_1d3 * SQRT( a_term / kin_vis_air ) *&
+                                  gamm( mu_r_5d2 ) * lambda_r**( -mu_r_5d2 ) *  &
+                                  ( 1.0_wp -                                    &
+                                    0.5_wp * ( b_term / a_term ) *              &
+                                    ( lambda_r / ( c_term + lambda_r )          &
+                                    )**mu_r_5d2 -                               &
+                                    0.125_wp * ( b_term / a_term )**2 *         &
+                                    ( lambda_r / ( 2.0_wp * c_term + lambda_r ) &
+                                    )**mu_r_5d2 -                               &
+                                    0.0625_wp * ( b_term / a_term )**3 *        &
+                                    ( lambda_r / ( 3.0_wp * c_term + lambda_r ) &
+                                    )**mu_r_5d2 -                               &
+                                    0.0390625_wp * ( b_term / a_term )**4 *     &
+                                    ( lambda_r / ( 4.0_wp * c_term + lambda_r ) &
+                                    )**mu_r_5d2                                 &
+                                  )
+
+                         nr_0   = nr(k,j,i) * lambda_r**( mu_r + 1.0_wp ) /    &
+                                  gamm( mu_r + 1.0_wp )
+                      ELSE
+                         f_vent = 1.0_wp
+                         nr_0   = nr(k,j,i) * dr
+                      ENDIF
+   !
+   !--                Evaporation rate of rain water content (Seifert and
+   !--                Beheng, 2006):
+                      evap    = 2.0_wp * pi * nr_0 * g_evap * f_vent * sat /   &
+                                hyrho(k)
+                      evap    = MAX( evap, -qr(k,j,i) / dt_micro )
+                      evap_nr = MAX( c_evap * evap / xr * hyrho(k),            &
+                                     -nr(k,j,i) / dt_micro )
+
+                      qr(k,j,i) = qr(k,j,i) + evap    * dt_micro * flag
+                      nr(k,j,i) = nr(k,j,i) + evap_nr * dt_micro * flag
+
+                   ENDIF
+                ENDIF
+
+             ENDDO
+          ENDDO
+       ENDDO
+
+       CALL cpu_log( log_point_s(58), 'evaporation', 'stop' )
+
+    END SUBROUTINE evaporation_rain
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Sedimentation of cloud droplets (Ackermann et al., 2009, MWR).
+!------------------------------------------------------------------------------!
+    SUBROUTINE sedimentation_cloud
+
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i             !<
+       INTEGER(iwp) ::  j             !<
+       INTEGER(iwp) ::  k             !<
+
+       REAL(wp) ::  flag              !< flag to mask topography grid points
+       REAL(wp) ::  nc_sedi           !<
+
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_qc !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_nc !<
+
+
+       CALL cpu_log( log_point_s(59), 'sed_cloud', 'start' )
+
+       sed_qc(nzt+1) = 0.0_wp
+       sed_nc(nzt+1) = 0.0_wp
+
+       DO  i = nxlg, nxrg
+          DO  j = nysg, nyng
+             DO  k = nzt, nzb+1, -1
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+                IF ( microphysics_morrison ) THEN
+                   nc_sedi = nc(k,j,i)
+                ELSE
+                   nc_sedi = nc_const
+                ENDIF
+
+!
+!--             Sedimentation fluxes for number concentration are only calculated
+!--             for cloud_scheme = 'morrison'
+                IF ( microphysics_morrison ) THEN
+                   IF ( qc(k,j,i) > eps_sb  .AND.  nc(k,j,i) > eps_mr )  THEN
+                      sed_nc(k) = sed_qc_const *                               &
+                              ( qc(k,j,i) * hyrho(k) )**( 2.0_wp / 3.0_wp ) *  &
+                              ( nc(k,j,i) )**( 1.0_wp / 3.0_wp )
+                   ELSE
+                      sed_nc(k) = 0.0_wp
+                   ENDIF
+
+                   sed_nc(k) = MIN( sed_nc(k), hyrho(k) * dzu(k+1) *           &
+                                    nc(k,j,i) / dt_micro + sed_nc(k+1)         &
+                                  ) * flag
+
+                   nc(k,j,i) = nc(k,j,i) + ( sed_nc(k+1) - sed_nc(k) ) *       &
+                                         ddzu(k+1) / hyrho(k) * dt_micro * flag
+                ENDIF
+
+                IF ( qc(k,j,i) > eps_sb .AND.  nc_sedi > eps_mr )  THEN
+                   sed_qc(k) = sed_qc_const * nc_sedi**( -2.0_wp / 3.0_wp ) *  &
+                               ( qc(k,j,i) * hyrho(k) )**( 5.0_wp / 3.0_wp ) * &
+                                                                           flag
+                ELSE
+                   sed_qc(k) = 0.0_wp
+                ENDIF
+
+                sed_qc(k) = MIN( sed_qc(k), hyrho(k) * dzu(k+1) * q(k,j,i) /   &
+                                            dt_micro + sed_qc(k+1)             &
+                               ) * flag
+
+                q(k,j,i)  = q(k,j,i)  + ( sed_qc(k+1) - sed_qc(k) ) *          &
+                                        ddzu(k+1) / hyrho(k) * dt_micro * flag
+                qc(k,j,i) = qc(k,j,i) + ( sed_qc(k+1) - sed_qc(k) ) *          &
+                                        ddzu(k+1) / hyrho(k) * dt_micro * flag
+                pt(k,j,i) = pt(k,j,i) - ( sed_qc(k+1) - sed_qc(k) ) *          &
+                                        ddzu(k+1) / hyrho(k) * lv_d_cp *       &
+                                        d_exner(k) * dt_micro            * flag
+
+!
+!--             Compute the precipitation rate due to cloud (fog) droplets
+                IF ( call_microphysics_at_all_substeps )  THEN
+                   prr(k,j,i) = prr(k,j,i) +  sed_qc(k) / hyrho(k)             &
+                                * weight_substep(intermediate_timestep_count)  &
+                                * flag
+                ELSE
+                   prr(k,j,i) = prr(k,j,i) + sed_qc(k) / hyrho(k) * flag
+                ENDIF
+
+             ENDDO
+          ENDDO
+       ENDDO
+
+       CALL cpu_log( log_point_s(59), 'sed_cloud', 'stop' )
+
+    END SUBROUTINE sedimentation_cloud
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Computation of sedimentation flux. Implementation according to Stevens
+!> and Seifert (2008). Code is based on UCLA-LES.
+!------------------------------------------------------------------------------!
+    SUBROUTINE sedimentation_rain
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i             !< running index x direction
+       INTEGER(iwp) ::  j             !< running index y direction
+       INTEGER(iwp) ::  k             !< running index z direction
+       INTEGER(iwp) ::  k_run         !<
+       INTEGER(iwp) ::  m             !< running index surface elements
+       INTEGER(iwp) ::  surf_e        !< End index of surface elements at (j,i)-gridpoint
+       INTEGER(iwp) ::  surf_s        !< Start index of surface elements at (j,i)-gridpoint
+
+       REAL(wp)     ::  c_run                      !<
+       REAL(wp)     ::  d_max                      !<
+       REAL(wp)     ::  d_mean                     !<
+       REAL(wp)     ::  d_min                      !<
+       REAL(wp)     ::  dr                         !<
+       REAL(wp)     ::  flux                       !<
+       REAL(wp)     ::  flag                       !< flag to mask topography grid points
+       REAL(wp)     ::  lambda_r                   !<
+       REAL(wp)     ::  mu_r                       !<
+       REAL(wp)     ::  z_run                      !<
+
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  c_nr     !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  c_qr     !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  nr_slope !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  qr_slope !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_nr   !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_qr   !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  w_nr     !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  w_qr     !<
+
+       CALL cpu_log( log_point_s(60), 'sed_rain', 'start' )
+
+!
+!--    Compute velocities
+       DO  i = nxlg, nxrg
+          DO  j = nysg, nyng
+             DO  k = nzb+1, nzt
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+                IF ( qr(k,j,i) > eps_sb )  THEN
+!
+!--                Weight averaged diameter of rain drops:
+                   dr = ( hyrho(k) * qr(k,j,i) /                               &
+                          nr(k,j,i) * dpirho_l )**( 1.0_wp / 3.0_wp )
+!
+!--                Shape parameter of gamma distribution (Milbrandt and Yau, 2005;
+!--                Stevens and Seifert, 2008):
+                   mu_r = 10.0_wp * ( 1.0_wp + TANH( 1.2E3_wp *                &
+                                                     ( dr - 1.4E-3_wp ) ) )
+!
+!--                Slope parameter of gamma distribution (Seifert, 2008):
+                   lambda_r = ( ( mu_r + 3.0_wp ) * ( mu_r + 2.0_wp ) *        &
+                                ( mu_r + 1.0_wp ) )**( 1.0_wp / 3.0_wp ) / dr
+
+                   w_nr(k) = MAX( 0.1_wp, MIN( 20.0_wp,                        &
+                                               a_term - b_term * ( 1.0_wp +    &
+                                                  c_term /                     &
+                                                  lambda_r )**( -1.0_wp *      &
+                                                  ( mu_r + 1.0_wp ) )          &
+                                              )                                &
+                                ) * flag
+
+                   w_qr(k) = MAX( 0.1_wp, MIN( 20.0_wp,                        &
+                                               a_term - b_term * ( 1.0_wp +    &
+                                                  c_term /                     &
+                                                  lambda_r )**( -1.0_wp *      &
+                                                  ( mu_r + 4.0_wp ) )          &
+                                             )                                 &
+                                ) * flag
+                ELSE
+                   w_nr(k) = 0.0_wp
+                   w_qr(k) = 0.0_wp
+                ENDIF
+             ENDDO
+!
+!--          Adjust boundary values using surface data type.
+!--          Upward-facing
+             surf_s = bc_h(0)%start_index(j,i)
+             surf_e = bc_h(0)%end_index(j,i)
+             DO  m = surf_s, surf_e
+                k         = bc_h(0)%k(m)
+                w_nr(k-1) = w_nr(k)
+                w_qr(k-1) = w_qr(k)
+             ENDDO
+!
+!--          Downward-facing
+             surf_s = bc_h(1)%start_index(j,i)
+             surf_e = bc_h(1)%end_index(j,i)
+             DO  m = surf_s, surf_e
+                k         = bc_h(1)%k(m)
+                w_nr(k+1) = w_nr(k)
+                w_qr(k+1) = w_qr(k)
+             ENDDO
+!
+!--          Model top boundary value
+             w_nr(nzt+1) = 0.0_wp
+             w_qr(nzt+1) = 0.0_wp
+!
+!--          Compute Courant number
+             DO  k = nzb+1, nzt
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+                c_nr(k) = 0.25_wp * ( w_nr(k-1) +                              &
+                                      2.0_wp * w_nr(k) + w_nr(k+1) ) *         &
+                          dt_micro * ddzu(k) * flag
+                c_qr(k) = 0.25_wp * ( w_qr(k-1) +                              &
+                                      2.0_wp * w_qr(k) + w_qr(k+1) ) *         &
+                          dt_micro * ddzu(k) * flag
+             ENDDO
+!
+!--          Limit slopes with monotonized centered (MC) limiter (van Leer, 1977):
+             IF ( limiter_sedimentation )  THEN
+
+                DO k = nzb+1, nzt
+!
+!--                Predetermine flag to mask topography
+                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+                   d_mean = 0.5_wp * ( qr(k+1,j,i) - qr(k-1,j,i) )
+                   d_min  = qr(k,j,i) - MIN( qr(k+1,j,i), qr(k,j,i), qr(k-1,j,i) )
+                   d_max  = MAX( qr(k+1,j,i), qr(k,j,i), qr(k-1,j,i) ) - qr(k,j,i)
+
+                   qr_slope(k) = SIGN(1.0_wp, d_mean) * MIN ( 2.0_wp * d_min,  &
+                                                              2.0_wp * d_max,  &
+                                                              ABS( d_mean ) )  &
+                                                      * flag
+
+                   d_mean = 0.5_wp * ( nr(k+1,j,i) - nr(k-1,j,i) )
+                   d_min  = nr(k,j,i) - MIN( nr(k+1,j,i), nr(k,j,i), nr(k-1,j,i) )
+                   d_max  = MAX( nr(k+1,j,i), nr(k,j,i), nr(k-1,j,i) ) - nr(k,j,i)
+
+                   nr_slope(k) = SIGN(1.0_wp, d_mean) * MIN ( 2.0_wp * d_min,  &
+                                                              2.0_wp * d_max,  &
+                                                              ABS( d_mean ) )
+                ENDDO
+
+             ELSE
+
+                nr_slope = 0.0_wp
+                qr_slope = 0.0_wp
+
+             ENDIF
+
+             sed_nr(nzt+1) = 0.0_wp
+             sed_qr(nzt+1) = 0.0_wp
+!
+!--          Compute sedimentation flux
+             DO  k = nzt, nzb+1, -1
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+!
+!--             Sum up all rain drop number densities which contribute to the flux
+!--             through k-1/2
+                flux  = 0.0_wp
+                z_run = 0.0_wp ! height above z(k)
+                k_run = k
+                c_run = MIN( 1.0_wp, c_nr(k) )
+                DO WHILE ( c_run > 0.0_wp  .AND.  k_run <= nzt )
+                   flux  = flux + hyrho(k_run) *                               &
+                           ( nr(k_run,j,i) + nr_slope(k_run) *                 &
+                           ( 1.0_wp - c_run ) * 0.5_wp ) * c_run * dzu(k_run)  &
+                                              * flag
+                   z_run = z_run + dzu(k_run) * flag
+                   k_run = k_run + 1          * flag
+                   c_run = MIN( 1.0_wp, c_nr(k_run) - z_run * ddzu(k_run) )    &
+                                              * flag
+                ENDDO
+!
+!--             It is not allowed to sediment more rain drop number density than
+!--             available
+                flux = MIN( flux,                                              &
+                            hyrho(k) * dzu(k+1) * nr(k,j,i) + sed_nr(k+1) *    &
+                            dt_micro                                           &
+                          )
+
+                sed_nr(k) = flux / dt_micro * flag
+                nr(k,j,i) = nr(k,j,i) + ( sed_nr(k+1) - sed_nr(k) ) *          &
+                                        ddzu(k+1) / hyrho(k) * dt_micro * flag
+!
+!--             Sum up all rain water content which contributes to the flux
+!--             through k-1/2
+                flux  = 0.0_wp
+                z_run = 0.0_wp ! height above z(k)
+                k_run = k
+                c_run = MIN( 1.0_wp, c_qr(k) )
+
+                DO WHILE ( c_run > 0.0_wp  .AND.  k_run <= nzt )
+
+                   flux  = flux + hyrho(k_run) * ( qr(k_run,j,i) +             &
+                                  qr_slope(k_run) * ( 1.0_wp - c_run ) *       &
+                                  0.5_wp ) * c_run * dzu(k_run) * flag
+                   z_run = z_run + dzu(k_run)                   * flag
+                   k_run = k_run + 1                            * flag
+                   c_run = MIN( 1.0_wp, c_qr(k_run) - z_run * ddzu(k_run) )    &
+                                                                * flag
+
+                ENDDO
+!
+!--             It is not allowed to sediment more rain water content than
+!--             available
+                flux = MIN( flux,                                              &
+                            hyrho(k) * dzu(k) * qr(k,j,i) + sed_qr(k+1) *      &
+                            dt_micro                                           &
+                          )
+
+                sed_qr(k) = flux / dt_micro * flag
+
+                qr(k,j,i) = qr(k,j,i) + ( sed_qr(k+1) - sed_qr(k) ) *          &
+                                        ddzu(k+1) / hyrho(k) * dt_micro * flag
+                q(k,j,i)  = q(k,j,i)  + ( sed_qr(k+1) - sed_qr(k) ) *          &
+                                        ddzu(k+1) / hyrho(k) * dt_micro * flag
+                pt(k,j,i) = pt(k,j,i) - ( sed_qr(k+1) - sed_qr(k) ) *          &
+                                        ddzu(k+1) / hyrho(k) * lv_d_cp *       &
+                                        d_exner(k) * dt_micro            * flag
+!
+!--             Compute the rain rate
+                IF ( call_microphysics_at_all_substeps )  THEN
+                   prr(k,j,i) = prr(k,j,i) + sed_qr(k) / hyrho(k)             &
+                                * weight_substep(intermediate_timestep_count) &
+                                * flag
+                ELSE
+                   prr(k,j,i) = prr(k,j,i) + sed_qr(k) / hyrho(k) * flag
+                ENDIF
+
+             ENDDO
+          ENDDO
+       ENDDO
+
+       CALL cpu_log( log_point_s(60), 'sed_rain', 'stop' )
+
+    END SUBROUTINE sedimentation_rain
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Computation of the precipitation amount due to gravitational settling of
+!> rain and cloud (fog) droplets
+!------------------------------------------------------------------------------!
+    SUBROUTINE calc_precipitation_amount
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i             !< running index x direction
+       INTEGER(iwp) ::  j             !< running index y direction
+       INTEGER(iwp) ::  k             !< running index y direction
+       INTEGER(iwp) ::  m             !< running index surface elements
+
+       IF ( ( dt_do2d_xy - time_do2d_xy ) < precipitation_amount_interval .AND.&
+            ( .NOT. call_microphysics_at_all_substeps .OR.                     &
+            intermediate_timestep_count == intermediate_timestep_count_max ) ) &
+       THEN
+!
+!--       Run over all upward-facing surface elements, i.e. non-natural,
+!--       natural and urban
+          DO  m = 1, bc_h(0)%ns
+             i = bc_h(0)%i(m)
+             j = bc_h(0)%j(m)
+             k = bc_h(0)%k(m)
+             precipitation_amount(j,i) = precipitation_amount(j,i) +           &
+                                               prr(k,j,i) * hyrho(k) * dt_3d
+          ENDDO
+
+       ENDIF
+
+    END SUBROUTINE calc_precipitation_amount
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Control of microphysics for grid points i,j
+!------------------------------------------------------------------------------!
+
+    SUBROUTINE bcm_actions_ij( i, j )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+
+       IF ( large_scale_forcing  .AND.  lsf_surf ) THEN
+!
+!--       Calculate vertical profile of the hydrostatic pressure (hyp)
+          hyp    = barometric_formula(zu, pt_surface * exner_function(surface_pressure * 100.0_wp), surface_pressure * 100.0_wp)
+          d_exner = exner_function_invers(hyp)
+          exner = 1.0_wp / exner_function_invers(hyp)
+          hyrho  = ideal_gas_law_rho_pt(hyp, pt_init)
+!
+!--       Compute reference density
+          rho_surface = ideal_gas_law_rho(surface_pressure * 100.0_wp, pt_surface * exner_function(surface_pressure * 100.0_wp))
+       ENDIF
+
+!
+!--    Compute length of time step
+       IF ( call_microphysics_at_all_substeps )  THEN
+          dt_micro = dt_3d * weight_pres(intermediate_timestep_count)
+       ELSE
+          dt_micro = dt_3d
+       ENDIF
+!
+!--    Reset precipitation rate
+       IF ( intermediate_timestep_count == 1 )  prr(:,j,i) = 0.0_wp
+
+!
+!--    Compute cloud physics
+       IF( microphysics_kessler )  THEN
+
+          CALL autoconversion_kessler( i,j )
+          IF ( cloud_water_sedimentation )  CALL sedimentation_cloud( i,j )
+
+       ELSEIF ( microphysics_seifert )  THEN
+
+          CALL adjust_cloud( i,j )
+          IF ( microphysics_morrison ) CALL activation( i,j )
+          IF ( microphysics_morrison ) CALL condensation( i,j )
+          CALL autoconversion( i,j )
+          CALL accretion( i,j )
+          CALL selfcollection_breakup( i,j )
+          CALL evaporation_rain( i,j )
+          CALL sedimentation_rain( i,j )
+          IF ( cloud_water_sedimentation )  CALL sedimentation_cloud( i,j )
+
+       ENDIF
+
+       CALL calc_precipitation_amount( i,j )
+
+    END SUBROUTINE bcm_actions_ij
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Adjust number of raindrops to avoid nonlinear effects in
+!> sedimentation and evaporation of rain drops due to too small or
+!> too big weights of rain drops (Stevens and Seifert, 2008).
+!> The same procedure is applied to cloud droplets if they are determined
+!> prognostically. Call for grid point i,j
+!------------------------------------------------------------------------------!
+    SUBROUTINE adjust_cloud_ij( i, j )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp) ::  flag                  !< flag to indicate first grid level above surface
+
+       DO  k = nzb+1, nzt
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+          IF ( qr(k,j,i) <= eps_sb )  THEN
+             qr(k,j,i) = 0.0_wp
+             nr(k,j,i) = 0.0_wp
+          ELSE
+!
+!--          Adjust number of raindrops to avoid nonlinear effects in
+!--          sedimentation and evaporation of rain drops due to too small or
+!--          too big weights of rain drops (Stevens and Seifert, 2008).
+             IF ( nr(k,j,i) * xrmin > qr(k,j,i) * hyrho(k) )  THEN
+                nr(k,j,i) = qr(k,j,i) * hyrho(k) / xrmin * flag
+             ELSEIF ( nr(k,j,i) * xrmax < qr(k,j,i) * hyrho(k) )  THEN
+                nr(k,j,i) = qr(k,j,i) * hyrho(k) / xrmax * flag
+             ENDIF
+
+          ENDIF
+
+          IF ( microphysics_morrison ) THEN
+             IF ( qc(k,j,i) <= eps_sb )  THEN
+                qc(k,j,i) = 0.0_wp
+                nc(k,j,i) = 0.0_wp
+             ELSE
+                IF ( nc(k,j,i) * xcmin > qc(k,j,i) * hyrho(k) )  THEN
+                   nc(k,j,i) = qc(k,j,i) * hyrho(k) / xamin * flag
+                ENDIF
+             ENDIF
+          ENDIF
+
+       ENDDO
+
+    END SUBROUTINE adjust_cloud_ij
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Calculate number of activated condensation nucleii after simple activation
+!> scheme of Twomey, 1959.
+!------------------------------------------------------------------------------!
+    SUBROUTINE activation_ij( i, j )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  activ             !<
+       REAL(wp)     ::  afactor           !<
+       REAL(wp)     ::  alpha             !<
+       REAL(wp)     ::  beta_act          !<
+       REAL(wp)     ::  bfactor           !<
+       REAL(wp)     ::  e_s               !<
+       REAL(wp)     ::  flag              !< flag to indicate first grid level above surface
+       REAL(wp)     ::  k_act             !<
+       REAL(wp)     ::  n_act             !<
+       REAL(wp)     ::  n_ccn             !<
+       REAL(wp)     ::  q_s               !<
+       REAL(wp)     ::  s_0               !<
+       REAL(wp)     ::  sat               !<
+       REAL(wp)     ::  sat_max           !<
+       REAL(wp)     ::  sigma             !<
+       REAL(wp)     ::  sigma_act         !<
+       REAL(wp)     ::  t_int             !<
+       REAL(wp)     ::  t_l               !<
+
+       DO  k = nzb+1, nzt
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+!
+!--       Actual liquid water temperature:
+          t_l = exner(k) * pt(k,j,i)
+
+!
+!--       Calculate actual temperature
+          t_int = pt(k,j,i) * exner_function( hyp(k) )
+!
+!--             Saturation vapor pressure at t_l:
+          e_s = 610.78_wp * EXP( 17.269_wp * ( t_l - 273.16_wp ) /             &
+                                 ( t_l - 35.86_wp )                            &
+                                 )
+!
+!--       Computation of saturation mixing ratio:
+          q_s   = 0.622_wp * e_s / ( hyp(k) -  e_s )
+          alpha = 0.622_wp * lv_d_rd * lv_d_cp / ( t_l * t_l )
+          q_s   = q_s * ( 1.0_wp + alpha * q(k,j,i) ) /                        &
+                        ( 1.0_wp + alpha * q_s )
+
+!--       Supersaturation:
+          sat   = ( q(k,j,i) - qr(k,j,i) - qc(k,j,i) ) / q_s - 1.0_wp
+
+!
+!--       Prescribe parameters for activation
+!--       (see: Bott + Trautmann, 2002, Atm. Res., 64)
+          k_act  = 0.7_wp
+          activ  = 0.0_wp
+
+          IF ( sat >= 0.0 .AND. .NOT. curvature_solution_effects_bulk )  THEN
+!
+!--          Compute the number of activated Aerosols
+!--          (see: Twomey, 1959, Pure and applied Geophysics, 43)
+             n_act     = na_init * sat**k_act
+!
+!--          Compute the number of cloud droplets
+!--          (see: Morrison + Grabowski, 2007, JAS, 64)
+!            activ = MAX( n_act - nc_d1(k), 0.0_wp) / dt_micro
+
+!
+!--          Compute activation rate after Khairoutdinov and Kogan
+!--          (see: Khairoutdinov + Kogan, 2000, Mon. Wea. Rev., 128)
+             sat_max = 0.8_wp / 100.0_wp
+             activ   = MAX( 0.0_wp, ( (na_init + nc(k,j,i) ) * MIN             &
+                 ( 1.0_wp, ( sat / sat_max )**k_act) - nc(k,j,i) ) ) /         &
+                  dt_micro
+
+             nc(k,j,i) = MIN( (nc(k,j,i) + activ * dt_micro), na_init)
+          ELSEIF ( sat >= 0.0 .AND. curvature_solution_effects_bulk )  THEN
+!
+!--          Curvature effect (afactor) with surface tension
+!--          parameterization by Straka (2009)
+             sigma = 0.0761_wp - 0.000155_wp * ( t_int - 273.15_wp )
+             afactor = 2.0_wp * sigma / ( rho_l * r_v * t_int )
+!
+!--          Solute effect (bfactor)
+             bfactor = vanthoff * molecular_weight_of_water *                  &
+                  rho_s / ( molecular_weight_of_solute * rho_l )
+
+!
+!--          Prescribe power index that describes the soluble fraction
+!--          of an aerosol particle (beta).
+!--          (see: Morrison + Grabowski, 2007, JAS, 64)
+             beta_act  = 0.5_wp
+             sigma_act = sigma_bulk**( 1.0_wp + beta_act )
+!
+!--          Calculate mean geometric supersaturation (s_0) with
+!--          parameterization by Khvorostyanov and Curry (2006)
+             s_0   = dry_aerosol_radius **(- ( 1.0_wp + beta_act ) ) *         &
+               ( 4.0_wp * afactor**3 / ( 27.0_wp * bfactor ) )**0.5_wp
+
+!
+!--          Calculate number of activated CCN as a function of
+!--          supersaturation and taking Koehler theory into account
+!--          (see: Khvorostyanov + Curry, 2006, J. Geo. Res., 111)
+             n_ccn = ( na_init / 2.0_wp ) * ( 1.0_wp - ERF(                    &
+                LOG( s_0 / sat ) / ( SQRT(2.0_wp) * LOG(sigma_act) ) ) )
+             activ = MAX( ( n_ccn ) / dt_micro, 0.0_wp )
+
+             nc(k,j,i) = MIN( (nc(k,j,i) + activ * dt_micro * flag), na_init)
+          ENDIF
+
+       ENDDO
+
+    END SUBROUTINE activation_ij
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Calculate condensation rate for cloud water content (after Khairoutdinov and
+!> Kogan, 2000).
+!------------------------------------------------------------------------------!
+    SUBROUTINE condensation_ij( i, j )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  alpha             !<
+       REAL(wp)     ::  cond              !<
+       REAL(wp)     ::  cond_max          !<
+       REAL(wp)     ::  dc                !<
+       REAL(wp)     ::  e_s               !<
+       REAL(wp)     ::  evap              !<
+       REAL(wp)     ::  flag              !< flag to indicate first grid level above surface
+       REAL(wp)     ::  g_fac             !<
+       REAL(wp)     ::  nc_0              !<
+       REAL(wp)     ::  q_s               !<
+       REAL(wp)     ::  sat               !<
+       REAL(wp)     ::  t_l               !<
+       REAL(wp)     ::  temp              !<
+       REAL(wp)     ::  xc                !<
+
+
+       DO  k = nzb+1, nzt
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+!
+!--       Actual liquid water temperature:
+          t_l = exner(k) * pt(k,j,i)
+!
+!--             Saturation vapor pressure at t_l:
+          e_s = 610.78_wp * EXP( 17.269_wp * ( t_l - 273.16_wp ) /    &
+                                 ( t_l - 35.86_wp )                   &
+                                 )
+!
+!--       Computation of saturation mixing ratio:
+          q_s   = 0.622_wp * e_s / ( hyp(k) - e_s )
+          alpha = 0.622_wp * lv_d_rd * lv_d_cp / ( t_l * t_l )
+          q_s   = q_s * ( 1.0_wp + alpha * q(k,j,i) ) /               &
+                        ( 1.0_wp + alpha * q_s )
+
+!--       Supersaturation:
+          sat   = ( q(k,j,i) - qr(k,j,i) - qc(k,j,i) ) / q_s - 1.0_wp
+
+
+!
+!--       Actual temperature:
+          temp = t_l + lv_d_cp * ( qc(k,j,i) + qr(k,j,i) )
+
+          g_fac  = 1.0_wp / ( ( l_v / ( r_v * temp ) - 1.0_wp ) *        &
+                              l_v / ( thermal_conductivity_l * temp )    &
+                              + r_v * temp / ( diff_coeff_l * e_s )      &
+                            )
+!
+!--       Mean weight of cloud drops
+          IF ( nc(k,j,i) <= 0.0_wp) CYCLE
+          xc = MAX( (hyrho(k) * qc(k,j,i) / nc(k,j,i)), xcmin)
+!
+!--       Weight averaged diameter of cloud drops:
+          dc   = ( xc * dpirho_l )**( 1.0_wp / 3.0_wp )
+!
+!--       Integral diameter of cloud drops
+          nc_0 = nc(k,j,i) * dc
+!
+!--       Condensation needs only to be calculated in supersaturated regions
+          IF ( sat > 0.0_wp )  THEN
+!
+!--          Condensation rate of cloud water content
+!--          after KK scheme.
+!--          (see: Khairoutdinov + Kogan, 2000, Mon. Wea. Rev.,128)
+             cond      = 2.0_wp * pi * nc_0 * g_fac * sat / hyrho(k)
+             cond_max  = q(k,j,i) - q_s - qc(k,j,i) - qr(k,j,i)
+             cond      = MIN( cond, cond_max / dt_micro )
+
+             qc(k,j,i) = qc(k,j,i) + cond * dt_micro * flag
+          ELSEIF ( sat < 0.0_wp ) THEN
+             evap      = 2.0_wp * pi * nc_0 * g_fac * sat / hyrho(k)
+             evap      = MAX( evap, -qc(k,j,i) / dt_micro )
+
+             qc(k,j,i) = qc(k,j,i) + evap * dt_micro * flag
+          ENDIF
+       ENDDO
+
+    END SUBROUTINE condensation_ij
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Autoconversion rate (Seifert and Beheng, 2006). Call for grid point i,j
+!------------------------------------------------------------------------------!
+    SUBROUTINE autoconversion_ij( i, j )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  alpha_cc          !<
+       REAL(wp)     ::  autocon           !<
+       REAL(wp)     ::  dissipation       !<
+       REAL(wp)     ::  flag              !< flag to indicate first grid level above surface
+       REAL(wp)     ::  k_au              !<
+       REAL(wp)     ::  l_mix             !<
+       REAL(wp)     ::  nc_auto           !<
+       REAL(wp)     ::  nu_c              !<
+       REAL(wp)     ::  phi_au            !<
+       REAL(wp)     ::  r_cc              !<
+       REAL(wp)     ::  rc                !<
+       REAL(wp)     ::  re_lambda         !<
+       REAL(wp)     ::  sigma_cc          !<
+       REAL(wp)     ::  tau_cloud         !<
+       REAL(wp)     ::  xc                !<
+
+       DO  k = nzb+1, nzt
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+          nc_auto = MERGE ( nc(k,j,i), nc_const, microphysics_morrison )
+
+          IF ( qc(k,j,i) > eps_sb  .AND.  nc_auto > eps_mr )  THEN
+
+             k_au = k_cc / ( 20.0_wp * x0 )
+!
+!--          Intern time scale of coagulation (Seifert and Beheng, 2006):
+!--          (1.0_wp - qc(k,j,i) / ( qc(k,j,i) + qr(k,j,i) ))
+             tau_cloud = MAX( 1.0_wp - qc(k,j,i) / ( qr(k,j,i) + qc(k,j,i) ),     &
+                              0.0_wp )
+!
+!--          Universal function for autoconversion process
+!--          (Seifert and Beheng, 2006):
+             phi_au = 600.0_wp * tau_cloud**0.68_wp * ( 1.0_wp - tau_cloud**0.68_wp )**3
+!
+!--          Shape parameter of gamma distribution (Geoffroy et al., 2010):
+!--          (Use constant nu_c = 1.0_wp instead?)
+             nu_c = 1.0_wp !MAX( 0.0_wp, 1580.0_wp * hyrho(k) * qc(k,j,i) - 0.28_wp )
+!
+!--          Mean weight of cloud droplets:
+             xc = hyrho(k) * qc(k,j,i) / nc_auto
+!
+!--          Parameterized turbulence effects on autoconversion (Seifert,
+!--          Nuijens and Stevens, 2010)
+             IF ( collision_turbulence )  THEN
+!
+!--             Weight averaged radius of cloud droplets:
+                rc = 0.5_wp * ( xc * dpirho_l )**( 1.0_wp / 3.0_wp )
+
+                alpha_cc = ( a_1 + a_2 * nu_c ) / ( 1.0_wp + a_3 * nu_c )
+                r_cc     = ( b_1 + b_2 * nu_c ) / ( 1.0_wp + b_3 * nu_c )
+                sigma_cc = ( c_1 + c_2 * nu_c ) / ( 1.0_wp + c_3 * nu_c )
+!
+!--             Mixing length (neglecting distance to ground and stratification)
+                l_mix = ( dx * dy * dzu(k) )**( 1.0_wp / 3.0_wp )
+!
+!--             Limit dissipation rate according to Seifert, Nuijens and
+!--             Stevens (2010)
+                dissipation = MIN( 0.06_wp, diss(k,j,i) )
+!
+!--             Compute Taylor-microscale Reynolds number:
+                re_lambda = 6.0_wp / 11.0_wp *                                 &
+                            ( l_mix / c_const )**( 2.0_wp / 3.0_wp ) *         &
+                            SQRT( 15.0_wp / kin_vis_air ) *                    &
+                            dissipation**( 1.0_wp / 6.0_wp )
+!
+!--             The factor of 1.0E4 is needed to convert the dissipation rate
+!--             from m2 s-3 to cm2 s-3.
+                k_au = k_au * ( 1.0_wp +                                       &
+                                dissipation * 1.0E4_wp *                       &
+                                ( re_lambda * 1.0E-3_wp )**0.25_wp *           &
+                                ( alpha_cc * EXP( -1.0_wp * ( ( rc - r_cc ) /  &
+                                                  sigma_cc )**2                &
+                                                ) + beta_cc                    &
+                                )                                              &
+                              )
+             ENDIF
+!
+!--          Autoconversion rate (Seifert and Beheng, 2006):
+             autocon = k_au * ( nu_c + 2.0_wp ) * ( nu_c + 4.0_wp ) /          &
+                       ( nu_c + 1.0_wp )**2 * qc(k,j,i)**2 * xc**2 *            &
+                       ( 1.0_wp + phi_au / ( 1.0_wp - tau_cloud )**2 ) *       &
+                       rho_surface
+             autocon = MIN( autocon, qc(k,j,i) / dt_micro )
+
+             qr(k,j,i) = qr(k,j,i) + autocon * dt_micro                 * flag
+             qc(k,j,i) = qc(k,j,i) - autocon * dt_micro                 * flag
+             nr(k,j,i) = nr(k,j,i) + autocon / x0 * hyrho(k) * dt_micro * flag
+             IF ( microphysics_morrison ) THEN
+                nc(k,j,i) = nc(k,j,i) - MIN( nc(k,j,i), 2.0_wp *                &
+                                    autocon / x0 * hyrho(k) * dt_micro * flag )
+             ENDIF
+
+          ENDIF
+
+       ENDDO
+
+    END SUBROUTINE autoconversion_ij
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Autoconversion process (Kessler, 1969).
+!------------------------------------------------------------------------------!
+    SUBROUTINE autoconversion_kessler_ij( i, j )
+
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i      !<
+       INTEGER(iwp) ::  j      !<
+       INTEGER(iwp) ::  k      !<
+       INTEGER(iwp) ::  k_wall !< topography top index
+
+       REAL(wp)    ::  dqdt_precip !<
+       REAL(wp)    ::  flag              !< flag to indicate first grid level above surface
+
+!
+!--    Determine vertical index of topography top
+       k_wall = get_topography_top_index_ji( j, i, 's' )
+       DO  k = nzb+1, nzt
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+          IF ( qc(k,j,i) > ql_crit )  THEN
+             dqdt_precip = prec_time_const * ( qc(k,j,i) - ql_crit )
+          ELSE
+             dqdt_precip = 0.0_wp
+          ENDIF
+
+          qc(k,j,i) = qc(k,j,i) - dqdt_precip * dt_micro * flag
+          q(k,j,i)  = q(k,j,i)  - dqdt_precip * dt_micro * flag
+          pt(k,j,i) = pt(k,j,i) + dqdt_precip * dt_micro * lv_d_cp * d_exner(k)  &
+                                                                 * flag
+
+!
+!--       Compute the rain rate (stored on surface grid point)
+          prr(k_wall,j,i) = prr(k_wall,j,i) + dqdt_precip * dzw(k) * flag
+
+       ENDDO
+
+    END SUBROUTINE autoconversion_kessler_ij
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Accretion rate (Seifert and Beheng, 2006). Call for grid point i,j
+!------------------------------------------------------------------------------!
+    SUBROUTINE accretion_ij( i, j )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  accr              !<
+       REAL(wp)     ::  flag              !< flag to indicate first grid level above surface
+       REAL(wp)     ::  k_cr              !<
+       REAL(wp)     ::  nc_accr           !<
+       REAL(wp)     ::  phi_ac            !<
+       REAL(wp)     ::  tau_cloud         !<
+       REAL(wp)     ::  xc                !<
+
+
+       DO  k = nzb+1, nzt
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+          nc_accr = MERGE ( nc(k,j,i), nc_const, microphysics_morrison )
+
+          IF ( ( qc(k,j,i) > eps_sb )  .AND.  ( qr(k,j,i) > eps_sb )  .AND.  &
+               ( nc_accr > eps_mr ) )  THEN
+!
+!--          Intern time scale of coagulation (Seifert and Beheng, 2006):
+             tau_cloud = 1.0_wp - qc(k,j,i) / ( qc(k,j,i) + qr(k,j,i) )
+!
+!--          Universal function for accretion process
+!--          (Seifert and Beheng, 2001):
+             phi_ac = ( tau_cloud / ( tau_cloud + 5.0E-5_wp ) )**4
+
+!
+!--          Mean weight of cloud drops
+             xc = MAX( (hyrho(k) * qc(k,j,i) / nc_accr), xcmin)
+!
+!--          Parameterized turbulence effects on autoconversion (Seifert,
+!--          Nuijens and Stevens, 2010). The factor of 1.0E4 is needed to
+!--          convert the dissipation rate (diss) from m2 s-3 to cm2 s-3.
+             IF ( collision_turbulence )  THEN
+                k_cr = k_cr0 * ( 1.0_wp + 0.05_wp *                            &
+                                 MIN( 600.0_wp,                                &
+                                      diss(k,j,i) * 1.0E4_wp )**0.25_wp        &
+                               )
+             ELSE
+                k_cr = k_cr0
+             ENDIF
+!
+!--          Accretion rate (Seifert and Beheng, 2006):
+             accr = k_cr * qc(k,j,i) * qr(k,j,i) * phi_ac *                      &
+                    SQRT( rho_surface * hyrho(k) )
+             accr = MIN( accr, qc(k,j,i) / dt_micro )
+
+             qr(k,j,i) = qr(k,j,i) + accr * dt_micro * flag
+             qc(k,j,i) = qc(k,j,i) - accr * dt_micro * flag
+             IF ( microphysics_morrison )  THEN
+                nc(k,j,i) = nc(k,j,i) - MIN( nc(k,j,i), accr / xc *               &
+                                             hyrho(k) * dt_micro * flag        &
+                                         )
+             ENDIF
+
+
+          ENDIF
+
+       ENDDO
+
+    END SUBROUTINE accretion_ij
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Collisional breakup rate (Seifert, 2008). Call for grid point i,j
+!------------------------------------------------------------------------------!
+    SUBROUTINE selfcollection_breakup_ij( i, j )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  breakup           !<
+       REAL(wp)     ::  dr                !<
+       REAL(wp)     ::  flag              !< flag to indicate first grid level above surface
+       REAL(wp)     ::  phi_br            !<
+       REAL(wp)     ::  selfcoll          !<
+
+       DO  k = nzb+1, nzt
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+          IF ( qr(k,j,i) > eps_sb )  THEN
+!
+!--          Selfcollection rate (Seifert and Beheng, 2001):
+             selfcoll = k_rr * nr(k,j,i) * qr(k,j,i) * SQRT( hyrho(k) * rho_surface )
+!
+!--          Weight averaged diameter of rain drops:
+             dr = ( hyrho(k) * qr(k,j,i) / nr(k,j,i) * dpirho_l )**( 1.0_wp / 3.0_wp )
+!
+!--          Collisional breakup rate (Seifert, 2008):
+             IF ( dr >= 0.3E-3_wp )  THEN
+                phi_br  = k_br * ( dr - 1.1E-3_wp )
+                breakup = selfcoll * ( phi_br + 1.0_wp )
+             ELSE
+                breakup = 0.0_wp
+             ENDIF
+
+             selfcoll = MAX( breakup - selfcoll, -nr(k,j,i) / dt_micro )
+             nr(k,j,i) = nr(k,j,i) + selfcoll * dt_micro * flag
+
+          ENDIF
+       ENDDO
+
+    END SUBROUTINE selfcollection_breakup_ij
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Evaporation of precipitable water. Condensation is neglected for
+!> precipitable water. Call for grid point i,j
+!------------------------------------------------------------------------------!
+    SUBROUTINE evaporation_rain_ij( i, j )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i                 !<
+       INTEGER(iwp) ::  j                 !<
+       INTEGER(iwp) ::  k                 !<
+
+       REAL(wp)     ::  alpha             !<
+       REAL(wp)     ::  dr                !<
+       REAL(wp)     ::  e_s               !<
+       REAL(wp)     ::  evap              !<
+       REAL(wp)     ::  evap_nr           !<
+       REAL(wp)     ::  f_vent            !<
+       REAL(wp)     ::  flag              !< flag to indicate first grid level above surface
+       REAL(wp)     ::  g_evap            !<
+       REAL(wp)     ::  lambda_r          !<
+       REAL(wp)     ::  mu_r              !<
+       REAL(wp)     ::  mu_r_2            !<
+       REAL(wp)     ::  mu_r_5d2          !<
+       REAL(wp)     ::  nr_0              !<
+       REAL(wp)     ::  q_s               !<
+       REAL(wp)     ::  sat               !<
+       REAL(wp)     ::  t_l               !<
+       REAL(wp)     ::  temp              !<
+       REAL(wp)     ::  xr                !<
+
+       DO  k = nzb+1, nzt
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+          IF ( qr(k,j,i) > eps_sb )  THEN
+!
+!--          Actual liquid water temperature:
+             t_l = exner(k) * pt(k,j,i)
+!
+!--          Saturation vapor pressure at t_l:
+             e_s = 610.78_wp * EXP( 17.269_wp * ( t_l - 273.16_wp ) /          &
+                                    ( t_l - 35.86_wp )                         &
+                                  )
+!
+!--          Computation of saturation mixing ratio:
+             q_s   = 0.622_wp * e_s / ( hyp(k) - e_s )
+             alpha = 0.622_wp * lv_d_rd * lv_d_cp / ( t_l * t_l )
+             q_s   = q_s * ( 1.0_wp + alpha * q(k,j,i) ) / ( 1.0_wp + alpha * q_s )
+!
+!--          Supersaturation:
+             sat   = ( q(k,j,i) - qr(k,j,i) - qc(k,j,i) ) / q_s - 1.0_wp
+!
+!--          Evaporation needs only to be calculated in subsaturated regions
+             IF ( sat < 0.0_wp )  THEN
+!
+!--             Actual temperature:
+                temp = t_l + lv_d_cp * ( qc(k,j,i) + qr(k,j,i) )
+
+                g_evap = 1.0_wp / ( ( l_v / ( r_v * temp ) - 1.0_wp ) * l_v /  &
+                                    ( thermal_conductivity_l * temp ) +        &
+                                    r_v * temp / ( diff_coeff_l * e_s )        &
+                                  )
+!
+!--             Mean weight of rain drops
+                xr = hyrho(k) * qr(k,j,i) / nr(k,j,i)
+!
+!--             Weight averaged diameter of rain drops:
+                dr = ( xr * dpirho_l )**( 1.0_wp / 3.0_wp )
+!
+!--             Compute ventilation factor and intercept parameter
+!--             (Seifert and Beheng, 2006; Seifert, 2008):
+                IF ( ventilation_effect )  THEN
+!
+!--                Shape parameter of gamma distribution (Milbrandt and Yau, 2005;
+!--                Stevens and Seifert, 2008):
+                   mu_r = 10.0_wp * ( 1.0_wp + TANH( 1.2E3_wp * ( dr - 1.4E-3_wp ) ) )
+!
+!--                Slope parameter of gamma distribution (Seifert, 2008):
+                   lambda_r = ( ( mu_r + 3.0_wp ) * ( mu_r + 2.0_wp ) *        &
+                                ( mu_r + 1.0_wp )                              &
+                              )**( 1.0_wp / 3.0_wp ) / dr
+
+                   mu_r_2   = mu_r + 2.0_wp
+                   mu_r_5d2 = mu_r + 2.5_wp
+
+                   f_vent = a_vent * gamm( mu_r_2 ) * lambda_r**( -mu_r_2 ) +  &
+                            b_vent * schmidt_p_1d3 *                           &
+                            SQRT( a_term / kin_vis_air ) * gamm( mu_r_5d2 ) *  &
+                            lambda_r**( -mu_r_5d2 ) *                          &
+                            ( 1.0_wp -                                         &
+                              0.5_wp * ( b_term / a_term ) *                   &
+                              ( lambda_r / ( c_term + lambda_r )               &
+                              )**mu_r_5d2 -                                    &
+                              0.125_wp * ( b_term / a_term )**2 *              &
+                              ( lambda_r / ( 2.0_wp * c_term + lambda_r )      &
+                              )**mu_r_5d2 -                                    &
+                              0.0625_wp * ( b_term / a_term )**3 *             &
+                              ( lambda_r / ( 3.0_wp * c_term + lambda_r )      &
+                              )**mu_r_5d2 -                                    &
+                              0.0390625_wp * ( b_term / a_term )**4 *          &
+                              ( lambda_r / ( 4.0_wp * c_term + lambda_r )      &
+                              )**mu_r_5d2                                      &
+                            )
+
+                   nr_0   = nr(k,j,i) * lambda_r**( mu_r + 1.0_wp ) /           &
+                            gamm( mu_r + 1.0_wp )
+                ELSE
+                   f_vent = 1.0_wp
+                   nr_0   = nr(k,j,i) * dr
+                ENDIF
+!
+!--             Evaporation rate of rain water content (Seifert and Beheng, 2006):
+                evap    = 2.0_wp * pi * nr_0 * g_evap * f_vent * sat / hyrho(k)
+                evap    = MAX( evap, -qr(k,j,i) / dt_micro )
+                evap_nr = MAX( c_evap * evap / xr * hyrho(k),                  &
+                               -nr(k,j,i) / dt_micro )
+
+                qr(k,j,i) = qr(k,j,i) + evap    * dt_micro * flag
+                nr(k,j,i) = nr(k,j,i) + evap_nr * dt_micro * flag
+
+             ENDIF
+          ENDIF
+
+       ENDDO
+
+    END SUBROUTINE evaporation_rain_ij
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Sedimentation of cloud droplets (Ackermann et al., 2009, MWR).
+!> Call for grid point i,j
+!------------------------------------------------------------------------------!
+    SUBROUTINE sedimentation_cloud_ij( i, j )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i             !<
+       INTEGER(iwp) ::  j             !<
+       INTEGER(iwp) ::  k             !<
+
+       REAL(wp)     ::  flag    !< flag to indicate first grid level above surface
+       REAL(wp)     ::  nc_sedi !<
+
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_nc  !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_qc  !<
+
+       sed_qc(nzt+1) = 0.0_wp
+       sed_nc(nzt+1) = 0.0_wp
+
+
+       DO  k = nzt, nzb+1, -1
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+          nc_sedi = MERGE( nc(k,j,i), nc_const, microphysics_morrison )
+!
+!--       Sedimentation fluxes for number concentration are only calculated
+!--       for cloud_scheme = 'morrison'
+          IF ( microphysics_morrison ) THEN
+             IF ( qc(k,j,i) > eps_sb  .AND.  nc(k,j,i) > eps_mr )  THEN
+                sed_nc(k) = sed_qc_const *                                     &
+                            ( qc(k,j,i) * hyrho(k) )**( 2.0_wp / 3.0_wp ) *     &
+                            ( nc(k,j,i) )**( 1.0_wp / 3.0_wp )
+             ELSE
+                sed_nc(k) = 0.0_wp
+             ENDIF
+
+             sed_nc(k) = MIN( sed_nc(k), hyrho(k) * dzu(k+1) *                 &
+                              nc(k,j,i) / dt_micro + sed_nc(k+1)                &
+                            ) * flag
+
+             nc(k,j,i) = nc(k,j,i) + ( sed_nc(k+1) - sed_nc(k) ) *               &
+                                         ddzu(k+1) / hyrho(k) * dt_micro * flag
+          ENDIF
+
+          IF ( qc(k,j,i) > eps_sb  .AND.  nc_sedi > eps_mr )  THEN
+             sed_qc(k) = sed_qc_const * nc_sedi**( -2.0_wp / 3.0_wp ) *        &
+                         ( qc(k,j,i) * hyrho(k) )**( 5.0_wp / 3.0_wp )  * flag
+          ELSE
+             sed_qc(k) = 0.0_wp
+          ENDIF
+
+          sed_qc(k) = MIN( sed_qc(k), hyrho(k) * dzu(k+1) * q(k,j,i) /          &
+                                      dt_micro + sed_qc(k+1)                   &
+                         ) * flag
+
+          q(k,j,i)  = q(k,j,i)  + ( sed_qc(k+1) - sed_qc(k) ) * ddzu(k+1) /      &
+                                hyrho(k) * dt_micro * flag
+          qc(k,j,i) = qc(k,j,i) + ( sed_qc(k+1) - sed_qc(k) ) * ddzu(k+1) /      &
+                                hyrho(k) * dt_micro * flag
+          pt(k,j,i) = pt(k,j,i) - ( sed_qc(k+1) - sed_qc(k) ) * ddzu(k+1) /      &
+                                hyrho(k) * lv_d_cp * d_exner(k) * dt_micro     &
+                                                                * flag
+
+!
+!--       Compute the precipitation rate of cloud (fog) droplets
+          IF ( call_microphysics_at_all_substeps )  THEN
+             prr(k,j,i) = prr(k,j,i) + sed_qc(k) / hyrho(k) *                  &
+                              weight_substep(intermediate_timestep_count) * flag
+          ELSE
+             prr(k,j,i) = prr(k,j,i) + sed_qc(k) / hyrho(k) * flag
+          ENDIF
+
+       ENDDO
+
+    END SUBROUTINE sedimentation_cloud_ij
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Computation of sedimentation flux. Implementation according to Stevens
+!> and Seifert (2008). Code is based on UCLA-LES. Call for grid point i,j
+!------------------------------------------------------------------------------!
+    SUBROUTINE sedimentation_rain_ij( i, j )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i             !< running index x direction
+       INTEGER(iwp) ::  j             !< running index y direction
+       INTEGER(iwp) ::  k             !< running index z direction
+       INTEGER(iwp) ::  k_run         !<
+       INTEGER(iwp) ::  m             !< running index surface elements
+       INTEGER(iwp) ::  surf_e        !< End index of surface elements at (j,i)-gridpoint
+       INTEGER(iwp) ::  surf_s        !< Start index of surface elements at (j,i)-gridpoint
+
+       REAL(wp)     ::  c_run                      !<
+       REAL(wp)     ::  d_max                      !<
+       REAL(wp)     ::  d_mean                     !<
+       REAL(wp)     ::  d_min                      !<
+       REAL(wp)     ::  dr                         !<
+       REAL(wp)     ::  flux                       !<
+       REAL(wp)     ::  flag                       !< flag to indicate first grid level above surface
+       REAL(wp)     ::  lambda_r                   !<
+       REAL(wp)     ::  mu_r                       !<
+       REAL(wp)     ::  z_run                      !<
+
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  c_nr     !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  c_qr     !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  nr_slope !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  qr_slope !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_nr   !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_qr   !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  w_nr     !<
+       REAL(wp), DIMENSION(nzb:nzt+1) ::  w_qr     !<
+
+!
+!--    Compute velocities
+       DO  k = nzb+1, nzt
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+          IF ( qr(k,j,i) > eps_sb )  THEN
+!
+!--          Weight averaged diameter of rain drops:
+             dr = ( hyrho(k) * qr(k,j,i) / nr(k,j,i) * dpirho_l )**( 1.0_wp / 3.0_wp )
+!
+!--          Shape parameter of gamma distribution (Milbrandt and Yau, 2005;
+!--          Stevens and Seifert, 2008):
+             mu_r = 10.0_wp * ( 1.0_wp + TANH( 1.2E3_wp * ( dr - 1.4E-3_wp ) ) )
+!
+!--          Slope parameter of gamma distribution (Seifert, 2008):
+             lambda_r = ( ( mu_r + 3.0_wp ) * ( mu_r + 2.0_wp ) *              &
+                          ( mu_r + 1.0_wp ) )**( 1.0_wp / 3.0_wp ) / dr
+
+             w_nr(k) = MAX( 0.1_wp, MIN( 20.0_wp,                              &
+                                         a_term - b_term * ( 1.0_wp +          &
+                                            c_term / lambda_r )**( -1.0_wp *   &
+                                            ( mu_r + 1.0_wp ) )                &
+                                        )                                      &
+                          ) * flag
+             w_qr(k) = MAX( 0.1_wp, MIN( 20.0_wp,                              &
+                                         a_term - b_term * ( 1.0_wp +          &
+                                            c_term / lambda_r )**( -1.0_wp *   &
+                                            ( mu_r + 4.0_wp ) )                &
+                                       )                                       &
+                          ) * flag
+          ELSE
+             w_nr(k) = 0.0_wp
+             w_qr(k) = 0.0_wp
+          ENDIF
+       ENDDO
+!
+!--    Adjust boundary values using surface data type.
+!--    Upward facing non-natural
+       surf_s = bc_h(0)%start_index(j,i)
+       surf_e = bc_h(0)%end_index(j,i)
+       DO  m = surf_s, surf_e
+          k         = bc_h(0)%k(m)
+          w_nr(k-1) = w_nr(k)
+          w_qr(k-1) = w_qr(k)
+       ENDDO
+!
+!--    Downward facing non-natural
+       surf_s = bc_h(1)%start_index(j,i)
+       surf_e = bc_h(1)%end_index(j,i)
+       DO  m = surf_s, surf_e
+          k         = bc_h(1)%k(m)
+          w_nr(k+1) = w_nr(k)
+          w_qr(k+1) = w_qr(k)
+       ENDDO
+!
+!--    Neumann boundary condition at model top
+       w_nr(nzt+1) = 0.0_wp
+       w_qr(nzt+1) = 0.0_wp
+!
+!--    Compute Courant number
+       DO  k = nzb+1, nzt
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+          c_nr(k) = 0.25_wp * ( w_nr(k-1) + 2.0_wp * w_nr(k) + w_nr(k+1) ) *   &
+                    dt_micro * ddzu(k) * flag
+          c_qr(k) = 0.25_wp * ( w_qr(k-1) + 2.0_wp * w_qr(k) + w_qr(k+1) ) *   &
+                    dt_micro * ddzu(k) * flag
+       ENDDO
+!
+!--    Limit slopes with monotonized centered (MC) limiter (van Leer, 1977):
+       IF ( limiter_sedimentation )  THEN
+
+          DO k = nzb+1, nzt
+!
+!--          Predetermine flag to mask topography
+             flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+             d_mean = 0.5_wp * ( qr(k+1,j,i) - qr(k-1,j,i) )
+             d_min  = qr(k,j,i) - MIN( qr(k+1,j,i), qr(k,j,i), qr(k-1,j,i) )
+             d_max  = MAX( qr(k+1,j,i), qr(k,j,i), qr(k-1,j,i) ) - qr(k,j,i)
+
+             qr_slope(k) = SIGN(1.0_wp, d_mean) * MIN ( 2.0_wp * d_min,        &
+                                                        2.0_wp * d_max,        &
+                                                        ABS( d_mean ) ) * flag
+
+             d_mean = 0.5_wp * ( nr(k+1,j,i) - nr(k-1,j,i) )
+             d_min  = nr(k,j,i) - MIN( nr(k+1,j,i), nr(k,j,i), nr(k-1,j,i) )
+             d_max  = MAX( nr(k+1,j,i), nr(k,j,i), nr(k-1,j,i) ) - nr(k,j,i)
+
+             nr_slope(k) = SIGN(1.0_wp, d_mean) * MIN ( 2.0_wp * d_min,        &
+                                                        2.0_wp * d_max,        &
+                                                        ABS( d_mean ) ) * flag
+          ENDDO
+
+       ELSE
+
+          nr_slope = 0.0_wp
+          qr_slope = 0.0_wp
+
+       ENDIF
+
+       sed_nr(nzt+1) = 0.0_wp
+       sed_qr(nzt+1) = 0.0_wp
+!
+!--    Compute sedimentation flux
+       DO  k = nzt, nzb+1, -1
+!
+!--       Predetermine flag to mask topography
+          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+!
+!--       Sum up all rain drop number densities which contribute to the flux
+!--       through k-1/2
+          flux  = 0.0_wp
+          z_run = 0.0_wp ! height above z(k)
+          k_run = k
+          c_run = MIN( 1.0_wp, c_nr(k) )
+          DO WHILE ( c_run > 0.0_wp  .AND.  k_run <= nzt )
+             flux  = flux + hyrho(k_run) *                                     &
+                     ( nr(k_run,j,i) + nr_slope(k_run) * ( 1.0_wp - c_run ) *  &
+                     0.5_wp ) * c_run * dzu(k_run) * flag
+             z_run = z_run + dzu(k_run)            * flag
+             k_run = k_run + 1                     * flag
+             c_run = MIN( 1.0_wp, c_nr(k_run) - z_run * ddzu(k_run) ) * flag
+          ENDDO
+!
+!--       It is not allowed to sediment more rain drop number density than
+!--       available
+          flux = MIN( flux,                                                    &
+                      hyrho(k) * dzu(k+1) * nr(k,j,i) + sed_nr(k+1) * dt_micro )
+
+          sed_nr(k) = flux / dt_micro * flag
+          nr(k,j,i)  = nr(k,j,i) + ( sed_nr(k+1) - sed_nr(k) ) * ddzu(k+1) /     &
+                                    hyrho(k) * dt_micro * flag
+!
+!--       Sum up all rain water content which contributes to the flux
+!--       through k-1/2
+          flux  = 0.0_wp
+          z_run = 0.0_wp ! height above z(k)
+          k_run = k
+          c_run = MIN( 1.0_wp, c_qr(k) )
+
+          DO WHILE ( c_run > 0.0_wp  .AND.  k_run <= nzt )
+
+             flux  = flux + hyrho(k_run) *                                     &
+                     ( qr(k_run,j,i) + qr_slope(k_run) * ( 1.0_wp - c_run ) *  &
+                     0.5_wp ) * c_run * dzu(k_run) * flag
+             z_run = z_run + dzu(k_run)            * flag
+             k_run = k_run + 1                     * flag
+             c_run = MIN( 1.0_wp, c_qr(k_run) - z_run * ddzu(k_run) ) * flag
+
+          ENDDO
+!
+!--       It is not allowed to sediment more rain water content than available
+          flux = MIN( flux,                                                    &
+                      hyrho(k) * dzu(k) * qr(k,j,i) + sed_qr(k+1) * dt_micro )
+
+          sed_qr(k) = flux / dt_micro * flag
+
+          qr(k,j,i) = qr(k,j,i) + ( sed_qr(k+1) - sed_qr(k) ) * ddzu(k+1) /      &
+                                hyrho(k) * dt_micro * flag
+          q(k,j,i)  = q(k,j,i)  + ( sed_qr(k+1) - sed_qr(k) ) * ddzu(k+1) /      &
+                                hyrho(k) * dt_micro * flag
+          pt(k,j,i) = pt(k,j,i) - ( sed_qr(k+1) - sed_qr(k) ) * ddzu(k+1) /      &
+                                hyrho(k) * lv_d_cp * d_exner(k) * dt_micro     &
+                                                                * flag
+!
+!--       Compute the rain rate
+          IF ( call_microphysics_at_all_substeps )  THEN
+             prr(k,j,i) = prr(k,j,i) + sed_qr(k) / hyrho(k)                    &
+                          * weight_substep(intermediate_timestep_count) * flag
+          ELSE
+             prr(k,j,i) = prr(k,j,i) + sed_qr(k) / hyrho(k) * flag
+          ENDIF
+
+       ENDDO
+
+    END SUBROUTINE sedimentation_rain_ij
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This subroutine computes the precipitation amount due to gravitational
+!> settling of rain and cloud (fog) droplets
+!------------------------------------------------------------------------------!
+    SUBROUTINE calc_precipitation_amount_ij( i, j )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i             !< running index x direction
+       INTEGER(iwp) ::  j             !< running index y direction
+       INTEGER(iwp) ::  k             !< running index z direction
+       INTEGER(iwp) ::  m             !< running index surface elements
+       INTEGER(iwp) ::  surf_e        !< End index of surface elements at (j,i)-gridpoint
+       INTEGER(iwp) ::  surf_s        !< Start index of surface elements at (j,i)-gridpoint
+
+       IF ( ( dt_do2d_xy - time_do2d_xy ) < precipitation_amount_interval .AND.&
+            ( .NOT. call_microphysics_at_all_substeps .OR.                     &
+            intermediate_timestep_count == intermediate_timestep_count_max ) ) &
+       THEN
+
+          surf_s = bc_h(0)%start_index(j,i)
+          surf_e = bc_h(0)%end_index(j,i)
+          DO  m = surf_s, surf_e
+             k                         = bc_h(0)%k(m)
+             precipitation_amount(j,i) = precipitation_amount(j,i) +           &
+                                               prr(k,j,i) * hyrho(k) * dt_3d
+          ENDDO
+
+       ENDIF
+
+    END SUBROUTINE calc_precipitation_amount_ij
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Computation of the diagnostic supersaturation sat, actual liquid water
+!< temperature t_l and saturation water vapor mixing ratio q_s
+!------------------------------------------------------------------------------!
+    SUBROUTINE supersaturation ( i,j,k )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i   !< running index
+       INTEGER(iwp) ::  j   !< running index
+       INTEGER(iwp) ::  k   !< running index
+
+       REAL(wp) ::  alpha   !< correction factor
+!
+!--    Actual liquid water temperature:
+       t_l = exner(k) * pt(k,j,i)
+!
+!--    Calculate water vapor saturation pressure
+       e_s = magnus( t_l )
+!
+!--    Computation of saturation mixing ratio:
+       q_s   = 0.622_wp * e_s / ( hyp(k) - e_s )
+!
+!--    Correction factor
+       alpha = 0.622_wp * lv_d_rd * lv_d_cp / ( t_l * t_l )
+!
+!--    Correction of the approximated value
+!--    (see: Cuijpers + Duynkerke, 1993, JAS, 23)
+       q_s   = q_s * ( 1.0_wp + alpha * q(k,j,i) ) / ( 1.0_wp + alpha * q_s )
+!
+!--    Supersaturation:
+!--    Not in case of microphysics_kessler or microphysics_sat_adjust
+!--    since qr is unallocated
+       IF ( .NOT. microphysics_kessler  .AND.                                  &
+            .NOT.  microphysics_sat_adjust )  THEN
+          sat   = ( q(k,j,i) - qr(k,j,i) - qc(k,j,i) ) / q_s - 1.0_wp
+       ENDIF
+
+    END SUBROUTINE supersaturation
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Calculation of the liquid water content (0%-or-100%-scheme). This scheme is
+!> used by the one and the two moment cloud physics scheme. Using the two moment
+!> scheme, this calculation results in the cloud water content.
+!------------------------------------------------------------------------------!
+    SUBROUTINE calc_liquid_water_content
+
+
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  i !<
+       INTEGER(iwp) ::  j !<
+       INTEGER(iwp) ::  k !<
+
+       REAL(wp)     ::  flag !< flag to indicate first grid level above surface
+
+
+       DO  i = nxlg, nxrg
+          DO  j = nysg, nyng
+             DO  k = nzb+1, nzt
+!
+!--             Predetermine flag to mask topography
+                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
+
+   !
+   !--          Call calculation of supersaturation located
+   !--          in diagnostic_quantities_mod
+                CALL supersaturation( i, j, k )
+
+   !
+   !--          Compute the liquid water content
+                IF ( microphysics_seifert  .AND. .NOT. microphysics_morrison ) &
+                THEN
+                   IF ( ( q(k,j,i) - q_s - qr(k,j,i) ) > 0.0_wp )  THEN
+                      qc(k,j,i) = ( q(k,j,i) - q_s - qr(k,j,i) ) * flag
+                      ql(k,j,i) = ( qc(k,j,i) + qr(k,j,i) ) * flag
+                   ELSE
+                      IF ( q(k,j,i) < qr(k,j,i) )  q(k,j,i) = qr(k,j,i)
+                      qc(k,j,i) = 0.0_wp
+                      ql(k,j,i) = qr(k,j,i) * flag
+                   ENDIF
+                ELSEIF ( microphysics_morrison )  THEN
+                   ql(k,j,i) = qc(k,j,i) + qr(k,j,i) * flag
+                ELSE
+                   IF ( ( q(k,j,i) - q_s ) > 0.0_wp )  THEN
+                      qc(k,j,i) = ( q(k,j,i) - q_s ) * flag
+                      ql(k,j,i) = qc(k,j,i) * flag
+                   ELSE
+                      qc(k,j,i) = 0.0_wp
+                      ql(k,j,i) = 0.0_wp
+                   ENDIF
+                ENDIF
+             ENDDO
+          ENDDO
+       ENDDO
+
+    END SUBROUTINE calc_liquid_water_content
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> This function computes the gamma function (Press et al., 1992).
+!> The gamma function is needed for the calculation of the evaporation
+!> of rain drops.
+!------------------------------------------------------------------------------!
+    FUNCTION gamm( xx )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  j            !<
+
+       REAL(wp)     ::  gamm         !<
+       REAL(wp)     ::  ser          !<
+       REAL(wp)     ::  tmp          !<
+       REAL(wp)     ::  x_gamm       !<
+       REAL(wp)     ::  xx           !<
+       REAL(wp)     ::  y_gamm       !<
+
+
+       REAL(wp), PARAMETER  ::  stp = 2.5066282746310005_wp               !<
+       REAL(wp), PARAMETER  ::  cof(6) = (/ 76.18009172947146_wp,      &
+                                           -86.50532032941677_wp,      &
+                                            24.01409824083091_wp,      &
+                                            -1.231739572450155_wp,     &
+                                             0.1208650973866179E-2_wp, &
+                                            -0.5395239384953E-5_wp /)     !<
+
+       x_gamm = xx
+       y_gamm = x_gamm
+       tmp = x_gamm + 5.5_wp
+       tmp = ( x_gamm + 0.5_wp ) * LOG( tmp ) - tmp
+       ser = 1.000000000190015_wp
+
+       DO  j = 1, 6
+          y_gamm = y_gamm + 1.0_wp
+          ser    = ser + cof( j ) / y_gamm
+       ENDDO
+
+!
+!--    Until this point the algorithm computes the logarithm of the gamma
+!--    function. Hence, the exponential function is used.
+!       gamm = EXP( tmp + LOG( stp * ser / x_gamm ) )
+       gamm = EXP( tmp ) * stp * ser / x_gamm
+
+       RETURN
+
+    END FUNCTION gamm
+
+ END MODULE bulk_cloud_model_mod
Index: /palm/trunk/SOURCE/buoyancy.f90
===================================================================
--- /palm/trunk/SOURCE/buoyancy.f90	(revision 3273)
+++ /palm/trunk/SOURCE/buoyancy.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused Variable removed
 !
@@ -114,5 +117,7 @@
 !------------------------------------------------------------------------------!
  MODULE buoyancy_mod
- 
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  g
 
     PRIVATE
@@ -138,5 +143,5 @@
 
        USE control_parameters,                                                 &
-           ONLY:  atmos_ocean_sign, cos_alpha_surface, g, message_string,      &
+           ONLY:  atmos_ocean_sign, cos_alpha_surface, message_string,         &
                   pt_surface, sin_alpha_surface, sloping_surface
 
@@ -244,5 +249,5 @@
 
        USE control_parameters,                                                 &
-           ONLY:  atmos_ocean_sign, cos_alpha_surface, g, message_string,      &
+           ONLY:  atmos_ocean_sign, cos_alpha_surface, message_string,         &
                   pt_surface, sin_alpha_surface, sloping_surface
 
Index: lm/trunk/SOURCE/calc_liquid_water_content.f90
===================================================================
--- /palm/trunk/SOURCE/calc_liquid_water_content.f90	(revision 3273)
+++ 	(revision )
@@ -1,170 +1,0 @@
-!> @file calc_liquid_water_content.f90
-!------------------------------------------------------------------------------!
-! This file is part of the PALM model system.
-!
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
-!
-! Copyright 1997-2018 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
-!
-! Current revisions:
-! -----------------
-! 
-! 
-! Former revisions:
-! -----------------
-! $Id$
-! unused variables removed
-! 
-! 2719 2018-01-02 09:02:06Z maronga
-! Bugfix for last change.
-! 
-! 2718 2018-01-02 08:49:38Z maronga
-! Corrected "Former revisions" section
-! 
-! 2696 2017-12-14 17:12:51Z kanani
-! Change in file header (GPL part)
-!
-! 2608 2017-11-13 14:04:26Z schwenkel
-! Calculation of supersaturation in external module (diagnostic_quantities_mod).
-! Change: correct calculation of saturation specific humidity to saturation
-! mixing ratio (the factor of 0.378 vanishes).
-! 
-! 2292 2017-06-20 09:51:42Z schwenkel
-! Implementation of new microphysic scheme: cloud_scheme = 'morrison' 
-! includes two more prognostic equations for cloud drop concentration (nc)  
-! and cloud water content (qc). 
-! 
-! 2233 2017-05-30 18:08:54Z suehring
-!
-! 2232 2017-05-30 17:47:52Z suehring
-! Adjustments to new topography concept
-! 
-! 2000 2016-08-20 18:09:15Z knoop
-! Forced header and separation lines into 80 columns
-! 
-! 1822 2016-04-07 07:49:42Z hoffmann
-! icloud_scheme removed. microphysics_seifert added.
-!
-! 1682 2015-10-07 23:56:08Z knoop
-! Code annotations made doxygen readable 
-! 
-! 1353 2014-04-08 15:21:23Z heinze
-! REAL constants provided with KIND-attribute
-!
-! 1320 2014-03-20 08:40:49Z raasch
-! ONLY-attribute added to USE-statements,
-! kind-parameters added to all INTEGER and REAL declaration statements,
-! kinds are defined in new module kinds,
-! revision history before 2012 removed,
-! comment fields (!:) to be used for variable explanations added to
-! all variable declaration statements
-!
-! 1253 2013-11-07 10:48:12Z fricke
-! Bugfix: q is set to qr in case that q is smaller than qr
-!
-! 1115 2013-03-26 18:16:16Z hoffmann
-! drizzle can be used independently from precipitation
-!
-! 1053 2012-11-13 17:11:03Z hoffmann
-! description expanded to the two-moment cloud scheme
-!
-! 1036 2012-10-22 13:43:42Z raasch
-! code put under GPL (PALM 3.9)
-!
-! Revision 1.1  2000/04/13 14:50:45  schroeter
-! Initial revision
-!
-!
-! Description:
-! ------------
-!> Calculation of the liquid water content (0%-or-100%-scheme). This scheme is 
-!> used by the one and the two moment cloud physics scheme. Using the two moment 
-!> scheme, this calculation results in the cloud water content.
-!------------------------------------------------------------------------------!
- SUBROUTINE calc_liquid_water_content
- 
-
-    USE arrays_3d,                                                             &
-        ONLY:  q, qc, ql, qr
-
-    USE control_parameters,                                                    &
-        ONLY:  microphysics_morrison, microphysics_seifert
-
-    USE diagnostic_quantities_mod,                                             &
-        ONLY:  magnus, q_s, supersaturation
-
-    USE indices,                                                               &
-        ONLY:  nxlg, nxrg, nyng, nysg, nzb, nzt, wall_flags_0
-
-    USE kinds
-
-    USE pegrid
-
-
-    IMPLICIT NONE
-
-    INTEGER(iwp) ::  i !<
-    INTEGER(iwp) ::  j !<
-    INTEGER(iwp) ::  k !<
-
-
-    DO  i = nxlg, nxrg
-       DO  j = nysg, nyng
-          DO  k = nzb+1, nzt
-
-!
-!--          Call calculation of supersaturation located 
-!--          in diagnostic_quantities_mod
-             CALL supersaturation( i, j, k )
-
-!
-!--          Compute the liquid water content
-             IF ( microphysics_seifert  .AND.  .NOT. microphysics_morrison )   &
-             THEN
-                IF ( ( q(k,j,i) - q_s - qr(k,j,i) ) > 0.0_wp )  THEN
-                   qc(k,j,i) = ( q(k,j,i) - q_s - qr(k,j,i) )                  &
-                                      * MERGE( 1.0_wp, 0.0_wp,                 &
-                                               BTEST( wall_flags_0(k,j,i), 0 ) )
-                   ql(k,j,i) = ( qc(k,j,i) + qr(k,j,i) )                       &
-                                      * MERGE( 1.0_wp, 0.0_wp,                 &
-                                               BTEST( wall_flags_0(k,j,i), 0 ) )
-                ELSE
-                   IF ( q(k,j,i) < qr(k,j,i) )  q(k,j,i) = qr(k,j,i)
-                   qc(k,j,i) = 0.0_wp 
-                   ql(k,j,i) = qr(k,j,i)                                       &
-                                      * MERGE( 1.0_wp, 0.0_wp,                 &
-                                               BTEST( wall_flags_0(k,j,i), 0 ) )
-                ENDIF
-             ELSEIF ( microphysics_morrison )  THEN
-                ql(k,j,i) = qc(k,j,i) + qr(k,j,i)                              &
-                                      * MERGE( 1.0_wp, 0.0_wp,                 &
-                                               BTEST( wall_flags_0(k,j,i), 0 ) )
-             ELSE
-                IF ( ( q(k,j,i) - q_s ) > 0.0_wp )  THEN
-                   qc(k,j,i) = ( q(k,j,i) - q_s )                              &
-                                      * MERGE( 1.0_wp, 0.0_wp,                 &
-                                               BTEST( wall_flags_0(k,j,i), 0 ) )
-                   ql(k,j,i) = qc(k,j,i)                                       &
-                                      * MERGE( 1.0_wp, 0.0_wp,                 &
-                                               BTEST( wall_flags_0(k,j,i), 0 ) )
-                ELSE
-                   qc(k,j,i) = 0.0_wp
-                   ql(k,j,i) = 0.0_wp
-                ENDIF
-             ENDIF
-          ENDDO
-       ENDDO
-    ENDDO
-    
- END SUBROUTINE calc_liquid_water_content
Index: /palm/trunk/SOURCE/calc_radiation.f90
===================================================================
--- /palm/trunk/SOURCE/calc_radiation.f90	(revision 3273)
+++ /palm/trunk/SOURCE/calc_radiation.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -77,11 +80,25 @@
  MODULE calc_radiation_mod
  
+
+    USE arrays_3d,                                                             &
+        ONLY:  dzw, pt, ql, tend, d_exner, exner
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  c_p, lv_d_cp, sigma_sb
+
+    USE control_parameters,                                                    &
+        ONLY:  rho_surface
+
+    USE indices,                                                               &
+        ONLY:  nxl, nxr, nyn, nys, nzb, nzt, wall_flags_0
+
     USE kinds
-    
+
+    USE pegrid
+
     PRIVATE
     PUBLIC calc_radiation
-    
+
     LOGICAL, SAVE ::  first_call = .TRUE. !<
-    REAL(wp), SAVE ::  sigma = 5.67E-08_wp   !<
 
     REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE ::  lwp_ground         !<
@@ -103,21 +120,4 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE calc_radiation
-
-       USE arrays_3d,                                                          &
-           ONLY:  dzw, pt, ql, tend
-
-       USE cloud_parameters,                                                   &
-           ONLY:  cp, l_d_cp, pt_d_t, t_d_pt
-
-       USE control_parameters,                                                 &
-           ONLY:  rho_surface
-
-       USE indices,                                                            &
-           ONLY:  nxl, nxr, nyn, nys, nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       USE pegrid
-
 
        IMPLICIT NONE
@@ -159,6 +159,6 @@
              lwp_top(nzt+1)  = rho_surface * ql(nzt+1,j,i) * dzw(nzt+1)
 
-             temperature     = pt(nzb,j,i) * t_d_pt(nzb) + l_d_cp * ql(nzb,j,i)
-             blackbody_emission(nzb) = sigma * temperature**4
+             temperature     = pt(nzb,j,i) * exner(nzb) + lv_d_cp * ql(nzb,j,i)
+             blackbody_emission(nzb) = sigma_sb * temperature**4
 
              DO  k = nzb+1, nzt
@@ -171,6 +171,6 @@
                                   rho_surface * ql(k_help,j,i) * dzw(k_help)
 
-                temperature     = pt(k,j,i) * t_d_pt(k) + l_d_cp * ql(k,j,i)
-                blackbody_emission(k) = sigma * temperature**4                 &
+                temperature     = pt(k,j,i) * exner(k) + lv_d_cp * ql(k,j,i)
+                blackbody_emission(k) = sigma_sb * temperature**4              &
                                       * MERGE( 1.0_wp, 0.0_wp,                 &
                                                BTEST( wall_flags_0(k,j,i), 0 ) )
@@ -182,7 +182,7 @@
              lwp_top(nzb)      = lwp_top(nzb+1)
 
-             temperature       = pt(nzt+1,j,i) * t_d_pt(nzt+1) + l_d_cp *      &
+             temperature       = pt(nzt+1,j,i) * exner(nzt+1) + lv_d_cp *      &
                                  ql(nzt+1,j,i)
-             blackbody_emission(nzt+1) = sigma * temperature**4
+             blackbody_emission(nzt+1) = sigma_sb * temperature**4
 
 !
@@ -232,5 +232,5 @@
 !--                Compute tendency term         
                    tend(k,j,i) = tend(k,j,i) -                                 &
-                                ( pt_d_t(k) / ( rho_surface * cp ) *           &
+                                ( d_exner(k) / ( rho_surface * c_p ) *         &
                                   ( df_p - df_m ) / dzw(k) )                   &
                                       * MERGE( 1.0_wp, 0.0_wp,                 &
@@ -253,21 +253,4 @@
     SUBROUTINE calc_radiation_ij( i, j )
 
-       USE arrays_3d,                                                          &
-           ONLY:  dzw, pt, ql, tend
-
-       USE cloud_parameters,                                                   &
-           ONLY:  cp, l_d_cp, pt_d_t, t_d_pt
-
-       USE control_parameters,                                                 &
-           ONLY:  rho_surface
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       USE pegrid
-
-   
        IMPLICIT NONE
 
@@ -305,6 +288,6 @@
        lwp_top(nzt+1)  = rho_surface * ql(nzt+1,j,i) * dzw(nzt+1)
 
-       temperature     = pt(nzb,j,i) * t_d_pt(nzb) + l_d_cp * ql(nzb,j,i)
-       blackbody_emission(nzb) = sigma * temperature**4
+       temperature     = pt(nzb,j,i) * exner(nzb) + lv_d_cp * ql(nzb,j,i)
+       blackbody_emission(nzb) = sigma_sb * temperature**4
 
        DO  k = nzb+1, nzt
@@ -315,6 +298,6 @@
                             rho_surface * ql(k_help,j,i) * dzw(k_help)
 
-          temperature     = pt(k,j,i) * t_d_pt(k) + l_d_cp * ql(k,j,i)
-          blackbody_emission(k) = sigma * temperature**4                       &
+          temperature     = pt(k,j,i) * exner(k) + lv_d_cp * ql(k,j,i)
+          blackbody_emission(k) = sigma_sb * temperature**4                    &
                                       * MERGE( 1.0_wp, 0.0_wp,                 &
                                                BTEST( wall_flags_0(k,j,i), 0 ) )
@@ -325,7 +308,7 @@
        lwp_top(nzb)      = lwp_top(nzb+1)
 
-       temperature       = pt(nzt+1,j,i) * t_d_pt(nzt+1) + l_d_cp *            &
+       temperature       = pt(nzt+1,j,i) * exner(nzt+1) + lv_d_cp *            &
                            ql(nzt+1,j,i)
-       blackbody_emission(nzt+1) = sigma * temperature**4
+       blackbody_emission(nzt+1) = sigma_sb * temperature**4
 
 !
@@ -370,6 +353,6 @@
 !
 !--          Compute tendency term         
-             tend(k,j,i) = tend(k,j,i) - ( pt_d_t(k) / ( rho_surface * cp ) *  &
-                                         ( df_p - df_m ) / dzw(k) )            &
+             tend(k,j,i) = tend(k,j,i) - ( d_exner(k) / ( rho_surface * c_p )  &
+                                      *  ( df_p - df_m ) / dzw(k) )            &
                                       * MERGE( 1.0_wp, 0.0_wp,                 &
                                                BTEST( wall_flags_0(k,j,i), 0 ) )
Index: /palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- /palm/trunk/SOURCE/check_parameters.f90	(revision 3273)
+++ /palm/trunk/SOURCE/check_parameters.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id: check_parameters.f90 2520 2017-10-05 13:50:26Z gronemeier &
+! Modularization of all bulk cloud physics code components
+! 
+! 2520 2017-10-05 13:50:26Z gronemeier
 ! unused variables removed
 ! 
@@ -298,5 +301,5 @@
 !
 ! 1994 2016-08-15 09:52:21Z suehring
-! Add missing check for cloud_physics and cloud_droplets
+! Add missing check for bulk_cloud_model and cloud_droplets
 !
 ! 1992 2016-08-12 15:14:59Z suehring
@@ -665,10 +668,14 @@
 
     USE arrays_3d
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model, bcm_check_parameters, bcm_check_data_output,  &
+               bcm_check_data_output_pr
+
     USE chemistry_model_mod,                                                   &
         ONLY:  chem_boundary_conds, chem_check_data_output,                    &
-               chem_check_data_output_pr, chem_species                 
+               chem_check_data_output_pr, chem_species
     USE chem_modules
-    USE cloud_parameters
-    USE constants
+    USE basic_constants_and_equations_mod
     USE control_parameters
     USE dvrp_variables
@@ -1058,6 +1065,6 @@
           WRITE( action, '(A)' )  'galilei_transformation = .TRUE.'
        ENDIF
-       IF ( cloud_physics )  THEN
-          WRITE( action, '(A)' )  'cloud_physics = .TRUE.'
+       IF ( bulk_cloud_model )  THEN
+          WRITE( action, '(A)' )  'bulk_cloud_model = .TRUE.'
        ENDIF
        IF ( cloud_droplets )  THEN
@@ -1186,52 +1193,4 @@
 
     ENDIF
-!
-!-- Check cloud scheme
-    IF ( cloud_scheme == 'saturation_adjust' )  THEN
-       microphysics_sat_adjust = .TRUE.
-       microphysics_seifert    = .FALSE.
-       microphysics_kessler    = .FALSE.
-       precipitation           = .FALSE.
-    ELSEIF ( cloud_scheme == 'seifert_beheng' )  THEN
-       microphysics_sat_adjust = .FALSE.
-       microphysics_seifert    = .TRUE.
-       microphysics_kessler    = .FALSE.
-       microphysics_morrison  = .FALSE.
-       precipitation           = .TRUE.
-    ELSEIF ( cloud_scheme == 'kessler' )  THEN
-       microphysics_sat_adjust = .FALSE.
-       microphysics_seifert    = .FALSE.
-       microphysics_kessler    = .TRUE.
-       microphysics_morrison   = .FALSE.
-       precipitation           = .TRUE.
-    ELSEIF ( cloud_scheme == 'morrison' )  THEN
-       microphysics_sat_adjust = .FALSE.
-       microphysics_seifert    = .TRUE.
-       microphysics_kessler    = .FALSE.
-       microphysics_morrison   = .TRUE.
-       precipitation           = .TRUE.
-    ELSE
-       message_string = 'unknown cloud microphysics scheme cloud_scheme ="' // &
-                        TRIM( cloud_scheme ) // '"'
-       CALL message( 'check_parameters', 'PA0357', 1, 2, 0, 6, 0 )
-    ENDIF
-!
-!-- Check aerosol
-    IF ( aerosol_bulk == 'nacl' )  THEN
-       aerosol_nacl   = .TRUE.
-       aerosol_c3h4o4 = .FALSE.
-       aerosol_nh4no3 = .FALSE.
-    ELSEIF ( aerosol_bulk == 'c3h4o4' )  THEN
-       aerosol_nacl   = .FALSE.
-       aerosol_c3h4o4 = .TRUE.
-       aerosol_nh4no3 = .FALSE.
-    ELSEIF ( aerosol_bulk == 'nh4no3' )  THEN
-       aerosol_nacl   = .FALSE.
-       aerosol_c3h4o4 = .FALSE.
-       aerosol_nh4no3 = .TRUE.
-    ELSE
-       message_string = 'unknown aerosol = "' // TRIM( aerosol_bulk ) // '"'
-       CALL message( 'check_parameters', 'PA0469', 1, 2, 0, 6, 0 )
-    ENDIF
 
 !
@@ -1352,6 +1311,6 @@
 !
 !-- Check for proper settings for microphysics
-    IF ( cloud_physics  .AND.  cloud_droplets )  THEN
-       message_string = 'cloud_physics = .TRUE. is not allowed with ' //       &
+    IF ( bulk_cloud_model  .AND.  cloud_droplets )  THEN
+       message_string = 'bulk_cloud_model = .TRUE. is not allowed with ' //    &
                         'cloud_droplets = .TRUE.'
        CALL message( 'check_parameters', 'PA0442', 1, 2, 0, 6, 0 )
@@ -1458,7 +1417,7 @@
     ENDIF
 
-    IF ( cloud_physics  .AND.  .NOT.  humidity )  THEN
-       WRITE( message_string, * ) 'cloud_physics = ', cloud_physics, ' is ',   &
-              'not allowed with humidity = ', humidity
+    IF ( bulk_cloud_model  .AND.  .NOT.  humidity )  THEN
+       WRITE( message_string, * ) 'bulk_cloud_model = ', bulk_cloud_model,     &
+              ' is not allowed with humidity = ', humidity
        CALL message( 'check_parameters', 'PA0034', 1, 2, 0, 6, 0 )
     ENDIF
@@ -1483,4 +1442,7 @@
 !-- When land surface model is used, perform additional checks
     IF ( land_surface )  CALL lsm_check_parameters
+!
+!-- When microphysics module is used, perform additional checks
+    IF ( bulk_cloud_model )  CALL bcm_check_parameters
 
 !
@@ -2394,19 +2356,4 @@
 
 !
-!-- Set the default value for the integration interval of precipitation amount
-    IF ( microphysics_seifert  .OR.  microphysics_kessler )  THEN
-       IF ( precipitation_amount_interval == 9999999.9_wp )  THEN
-          precipitation_amount_interval = dt_do2d_xy
-       ELSE
-          IF ( precipitation_amount_interval > dt_do2d_xy )  THEN
-             WRITE( message_string, * )  'precipitation_amount_interval = ',   &
-                 precipitation_amount_interval, ' must not be larger than ',   &
-                 'dt_do2d_xy = ', dt_do2d_xy
-             CALL message( 'check_parameters', 'PA0090', 1, 2, 0, 6, 0 )
-          ENDIF
-       ENDIF
-    ENDIF
-
-!
 !-- Determine the number of output profiles and check whether they are
 !-- permissible
@@ -2447,5 +2394,5 @@
 
           CASE ( 'pt', '#pt' )
-             IF ( .NOT. cloud_physics ) THEN
+             IF ( .NOT. bulk_cloud_model ) THEN
                 dopr_index(i) = 4
                 dopr_unit(i)  = 'K'
@@ -2682,5 +2629,5 @@
 
           CASE ( 'qv', '#qv' )
-             IF ( .NOT. cloud_physics ) THEN
+             IF ( .NOT. bulk_cloud_model ) THEN
                 dopr_index(i) = 41
                 dopr_unit(i)  = 'kg/kg'
@@ -2705,8 +2652,8 @@
 
           CASE ( 'lpt', '#lpt' )
-             IF ( .NOT. cloud_physics ) THEN
+             IF ( .NOT. bulk_cloud_model ) THEN
                 message_string = 'data_output_pr = ' //                        &
                                  TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_physics = .FALSE.'
+                                 'lemented for bulk_cloud_model = .FALSE.'
                 CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
              ELSE
@@ -2821,9 +2768,9 @@
 
           CASE ( 'w"qv"' )
-             IF ( humidity  .AND.  .NOT.  cloud_physics )  THEN
+             IF ( humidity  .AND.  .NOT.  bulk_cloud_model )  THEN
                 dopr_index(i) = 48
                 dopr_unit(i)  = TRIM ( waterflux_output_unit )
                 hom(:,2,48,:) = SPREAD( zw, 2, statistic_regions+1 )
-             ELSEIF ( humidity  .AND.  cloud_physics )  THEN
+             ELSEIF ( humidity  .AND.  bulk_cloud_model )  THEN
                 dopr_index(i) = 51
                 dopr_unit(i)  = TRIM ( waterflux_output_unit )
@@ -2832,16 +2779,15 @@
                 message_string = 'data_output_pr = ' //                        &
                                  TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_physics = .FALSE. an'  // &
-                                 'd humidity = .FALSE.'
+                                 'lemented for bulk_cloud_model = .FALSE. ' // &
+                                 'and humidity = .FALSE.'
                 CALL message( 'check_parameters', 'PA0095', 1, 2, 0, 6, 0 )
              ENDIF
 
           CASE ( 'w*qv*' )
-             IF ( humidity  .AND.  .NOT. cloud_physics )                       &
-             THEN
+             IF ( humidity  .AND.  .NOT. bulk_cloud_model )  THEN
                 dopr_index(i) = 49
                 dopr_unit(i)  = TRIM ( waterflux_output_unit )
                 hom(:,2,49,:) = SPREAD( zw, 2, statistic_regions+1 )
-             ELSEIF( humidity .AND. cloud_physics ) THEN
+             ELSEIF( humidity .AND. bulk_cloud_model ) THEN
                 dopr_index(i) = 52
                 dopr_unit(i)  = TRIM ( waterflux_output_unit )
@@ -2850,15 +2796,15 @@
                 message_string = 'data_output_pr = ' //                        &
                                  TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_physics = .FALSE. an'  // &
-                                 'd humidity = .FALSE.'
+                                 'lemented for bulk_cloud_model = .FALSE. ' // &
+                                 'and humidity = .FALSE.'
                 CALL message( 'check_parameters', 'PA0095', 1, 2, 0, 6, 0 )
              ENDIF
 
           CASE ( 'wqv' )
-             IF ( humidity  .AND.  .NOT.  cloud_physics )  THEN
+             IF ( humidity  .AND.  .NOT.  bulk_cloud_model )  THEN
                 dopr_index(i) = 50
                 dopr_unit(i)  = TRIM ( waterflux_output_unit )
                 hom(:,2,50,:) = SPREAD( zw, 2, statistic_regions+1 )
-             ELSEIF ( humidity  .AND.  cloud_physics )  THEN
+             ELSEIF ( humidity  .AND.  bulk_cloud_model )  THEN
                 dopr_index(i) = 53
                 dopr_unit(i)  = TRIM ( waterflux_output_unit )
@@ -2867,15 +2813,15 @@
                 message_string = 'data_output_pr = ' //                        &
                                  TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_physics = .FALSE. an'  // &
-                                 'd humidity = .FALSE.'
+                                 'lemented for bulk_cloud_model = .FALSE. ' // &
+                                 'and humidity = .FALSE.'
                 CALL message( 'check_parameters', 'PA0095', 1, 2, 0, 6, 0 )
              ENDIF
 
           CASE ( 'ql' )
-             IF (  .NOT.  cloud_physics  .AND.  .NOT.  cloud_droplets )  THEN
+             IF (  .NOT.  bulk_cloud_model  .AND.  .NOT.  cloud_droplets )  THEN
                 message_string = 'data_output_pr = ' //                        &
                                  TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_physics = .FALSE. and' // &
-                                 'cloud_droplets = .FALSE.'
+                                 'lemented for bulk_cloud_model = .FALSE. ' // &
+                                 'and cloud_droplets = .FALSE.'
                 CALL message( 'check_parameters', 'PA0096', 1, 2, 0, 6, 0 )
              ELSE
@@ -3034,84 +2980,4 @@
              hom(:,2,120,:) = SPREAD( zw, 2, statistic_regions+1 )
 
-          CASE ( 'nc' )
-             IF (  .NOT.  cloud_physics )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_physics = .FALSE.'
-                CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
-             ELSEIF ( .NOT.  microphysics_morrison )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_scheme /= morrison'
-                CALL message( 'check_parameters', 'PA0358', 1, 2, 0, 6, 0 )
-             ELSE
-                dopr_index(i) = 89
-                dopr_unit(i)  = '1/m3'
-                hom(:,2,89,:)  = SPREAD( zu, 2, statistic_regions+1 )
-             ENDIF
-
-          CASE ( 'nr' )
-             IF (  .NOT.  cloud_physics )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_physics = .FALSE.'
-                CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
-             ELSEIF ( .NOT.  microphysics_seifert )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_scheme /= seifert_beheng'
-                CALL message( 'check_parameters', 'PA0358', 1, 2, 0, 6, 0 )
-             ELSE
-                dopr_index(i) = 73
-                dopr_unit(i)  = '1/m3'
-                hom(:,2,73,:)  = SPREAD( zu, 2, statistic_regions+1 )
-             ENDIF
-
-          CASE ( 'qr' )
-             IF (  .NOT.  cloud_physics )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_physics = .FALSE.'
-                CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
-             ELSEIF ( .NOT.  microphysics_seifert )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_scheme /= seifert_beheng'
-                CALL message( 'check_parameters', 'PA0358', 1, 2, 0, 6, 0 )
-             ELSE
-                dopr_index(i) = 74
-                dopr_unit(i)  = 'kg/kg'
-                hom(:,2,74,:)  = SPREAD( zu, 2, statistic_regions+1 )
-             ENDIF
-
-          CASE ( 'qc' )
-             IF (  .NOT.  cloud_physics )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_physics = .FALSE.'
-                CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
-             ELSE
-                dopr_index(i) = 75
-                dopr_unit(i)  = 'kg/kg'
-                hom(:,2,75,:)  = SPREAD( zu, 2, statistic_regions+1 )
-             ENDIF
-
-          CASE ( 'prr' )
-             IF (  .NOT.  cloud_physics )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(i) ) // ' is not imp' // &
-                                 'lemented for cloud_physics = .FALSE.'
-                CALL message( 'check_parameters', 'PA0094', 1, 2, 0, 6, 0 )
-             ELSEIF ( microphysics_sat_adjust )  THEN
-                message_string = 'data_output_pr = ' //                        &
-                                 TRIM( data_output_pr(i) ) // ' is not ava' // &
-                                 'ilable for cloud_scheme = saturation_adjust'
-                CALL message( 'check_parameters', 'PA0422', 1, 2, 0, 6, 0 )
-             ELSE
-                dopr_index(i) = 76
-                dopr_unit(i)  = 'kg/kg m/s'
-                hom(:,2,76,:)  = SPREAD( zu, 2, statistic_regions+1 )
-             ENDIF
-
           CASE ( 'ug' )
              dopr_index(i) = 78
@@ -3154,4 +3020,10 @@
              CALL lsm_check_data_output_pr( data_output_pr(i), i, unit,        &
                                             dopr_unit(i) )
+!
+!--          Block of microphysics module profile outputs
+             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' )  THEN
@@ -3260,34 +3132,10 @@
 
           CASE ( 'lpt' )
-             IF (  .NOT.  cloud_physics )  THEN
+             IF (  .NOT.  bulk_cloud_model )  THEN
                 message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                         'res cloud_physics = .TRUE.'
+                         'res bulk_cloud_model = .TRUE.'
                 CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
              ENDIF
              unit = 'K'
-
-          CASE ( 'nc' )
-             IF (  .NOT.  cloud_physics )  THEN
-                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                         'res cloud_physics = .TRUE.'
-                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
-             ELSEIF ( .NOT.  microphysics_morrison )  THEN
-                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                         'res = morrison '
-                CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
-             ENDIF
-             unit = '1/m3'
-
-          CASE ( 'nr' )
-             IF (  .NOT.  cloud_physics )  THEN
-                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                         'res cloud_physics = .TRUE.'
-                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
-             ELSEIF ( .NOT.  microphysics_seifert )  THEN
-                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                         'res cloud_scheme = seifert_beheng'
-                CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
-             ENDIF
-             unit = '1/m3'
 
           CASE ( 'pc', 'pr' )
@@ -3301,16 +3149,4 @@
              IF ( TRIM( var ) == 'pr' )  unit = 'm'
 
-          CASE ( 'prr' )
-             IF (  .NOT.  cloud_physics )  THEN
-                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                         'res cloud_physics = .TRUE.'
-                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
-             ELSEIF ( microphysics_sat_adjust )  THEN
-                message_string = 'output of "' // TRIM( var ) // '" is ' //    &
-                         'not available for cloud_scheme = saturation_adjust'
-                CALL message( 'check_parameters', 'PA0423', 1, 2, 0, 6, 0 )
-             ENDIF
-             unit = 'kg/kg m/s'
-
           CASE ( 'q', 'vpt' )
              IF (  .NOT.  humidity )  THEN
@@ -3322,16 +3158,8 @@
              IF ( TRIM( var ) == 'vpt' )  unit = 'K'
 
-          CASE ( 'qc' )
-             IF (  .NOT.  cloud_physics )  THEN
+          CASE ( 'ql' )
+             IF ( .NOT.  ( bulk_cloud_model  .OR.  cloud_droplets ) )  THEN
                 message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                         'res cloud_physics = .TRUE.'
-                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
-             ENDIF
-             unit = 'kg/kg'
-
-          CASE ( 'ql' )
-             IF ( .NOT.  ( cloud_physics  .OR.  cloud_droplets ) )  THEN
-                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                         'res cloud_physics = .TRUE. or cloud_droplets = .TRUE.'
+                      'res bulk_cloud_model = .TRUE. or cloud_droplets = .TRUE.'
                 CALL message( 'check_parameters', 'PA0106', 1, 2, 0, 6, 0 )
              ENDIF
@@ -3348,20 +3176,8 @@
              IF ( TRIM( var ) == 'ql_vp' )  unit = 'none'
 
-          CASE ( 'qr' )
-             IF (  .NOT.  cloud_physics )  THEN
+          CASE ( 'qv' )
+             IF (  .NOT.  bulk_cloud_model )  THEN
                 message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                         'res cloud_physics = .TRUE.'
-                CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
-             ELSEIF ( .NOT.  microphysics_seifert ) THEN
-                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                         'res cloud_scheme = seifert_beheng'
-                CALL message( 'check_parameters', 'PA0359', 1, 2, 0, 6, 0 )
-             ENDIF
-             unit = 'kg/kg'
-
-          CASE ( 'qv' )
-             IF (  .NOT.  cloud_physics )  THEN
-                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                                 'res cloud_physics = .TRUE.'
+                                 'res bulk_cloud_model = .TRUE.'
                 CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
              ENDIF
@@ -3400,5 +3216,5 @@
              CONTINUE
 
-          CASE ( 'ghf*', 'lwp*', 'ol*', 'pra*', 'prr*', 'qsws*', 'r_a*',       &
+          CASE ( 'ghf*', 'lwp*', 'ol*', 'qsws*', 'r_a*',                       &
                  'shf*', 'ssws*', 't*', 'tsurf*', 'u*', 'z0*', 'z0h*', 'z0q*' )
              IF ( k == 0  .OR.  data_output(i)(ilen-2:ilen) /= '_xy' )  THEN
@@ -3409,25 +3225,8 @@
              ENDIF
 
-             IF ( TRIM( var ) == 'lwp*'  .AND.  .NOT. cloud_physics )  THEN
+             IF ( TRIM( var ) == 'lwp*'  .AND.  .NOT. bulk_cloud_model )  THEN
                 message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                                 'res cloud_physics = .TRUE.'
+                                 'res bulk_cloud_model = .TRUE.'
                 CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
-             ENDIF
-             IF ( TRIM( var ) == 'pra*'  .AND.                                 &
-                  .NOT. ( microphysics_kessler .OR. microphysics_seifert ) )  THEN
-                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                                 'res cloud_scheme = kessler or seifert_beheng'
-                CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 )
-             ENDIF
-             IF ( TRIM( var ) == 'pra*'  .AND.  j == 1 )  THEN
-                message_string = 'temporal averaging of precipitation ' //     &
-                          'amount "' // TRIM( var ) // '" is not possible'
-                CALL message( 'check_parameters', 'PA0113', 1, 2, 0, 6, 0 )
-             ENDIF
-             IF ( TRIM( var ) == 'prr*'  .AND.                                 &
-                  .NOT. ( microphysics_kessler .OR. microphysics_seifert ) )  THEN
-                message_string = 'output of "' // TRIM( var ) // '" requi' //  &
-                                 'res cloud_scheme = kessler or seifert_beheng'
-                CALL message( 'check_parameters', 'PA0112', 1, 2, 0, 6, 0 )
              ENDIF
              IF ( TRIM( var ) == 'qsws*'  .AND.  .NOT.  humidity )  THEN
@@ -3460,6 +3259,4 @@
              IF ( TRIM( var ) == 'lwp*'   )  unit = 'kg/m2'
              IF ( TRIM( var ) == 'ol*'    )  unit = 'm'
-             IF ( TRIM( var ) == 'pra*'   )  unit = 'mm'
-             IF ( TRIM( var ) == 'prr*'   )  unit = 'mm/s'
              IF ( TRIM( var ) == 'qsws*'  )  unit = 'kgm/kgs'
              IF ( TRIM( var ) == 'r_a*'   )  unit = 's/m'     
@@ -3483,4 +3280,10 @@
 
              CALL tcm_check_data_output ( var, unit )
+
+!
+!--          Block of microphysics module outputs
+             IF ( unit == 'illegal'  .AND.  bulk_cloud_model  )  THEN
+                CALL bcm_check_data_output ( var, unit )
+             ENDIF
 
              IF ( unit == 'illegal' )  THEN
Index: /palm/trunk/SOURCE/chem_photolysis_mod.f90
===================================================================
--- /palm/trunk/SOURCE/chem_photolysis_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/chem_photolysis_mod.f90	(revision 3274)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables commented
 ! 
@@ -50,5 +53,5 @@
         ONLY:  dzw, hyp, pt, q, ql, zu, zw
 
-    USE constants,                                                             &
+    USE basic_constants_and_equations_mod,                                     &
         ONLY:  pi
 
@@ -68,5 +71,5 @@
     USE control_parameters,                                                    &
         ONLY:  initializing_actions           
-!       ONLY:  cloud_droplets, cloud_physics, g, initializing_actions,         &
+!       ONLY:  cloud_droplets, initializing_actions,                           &
 !              large_scale_forcing, lsf_surf, phi, pt_surface, rho_surface,    &
 !              surface_pressure, time_since_reference_point
@@ -271,5 +274,5 @@
 !      INTEGER(iwp) :: i, j, k   !< loop indices
        INTEGER(iwp) :: iphot,iav !< loop indix for photolysis reaction
-!      REAL(wp)     :: exn,   &  !< Exner functions at surface
+!      REAL(wp)     :: exn,   &  !< Exner functions at surface (better use palms own exner array in arrays_3d)
 !                      pt1       !< potential temperature at first grid level
 
@@ -304,5 +307,5 @@
 !      INTEGER(iwp) :: i, j, k   !< loop indices
        INTEGER(iwp) :: iphot,iav !< loop indix for photolysis reaction
-!      REAL(wp)     :: exn,   &  !< Exner functions at surface
+!      REAL(wp)     :: exn,   &  !< Exner functions at surface (better use palms own exner array in arrays_3d)
 !                      pt1       !< potential temperature at first grid level
        REAL(wp)     :: coszi     !< 1./cosine of zenith angle
Index: /palm/trunk/SOURCE/chemistry_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3274)
@@ -27,4 +27,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3248 2018-09-14 09:42:06Z sward
 ! Minor formating changes
 ! 
@@ -144,5 +147,5 @@
                                  intermediate_timestep_count_max,              &
                                  timestep_scheme, use_prescribed_profile_data  
-   USE arrays_3d,          ONLY: hyp, pt, rdf_sc, tend, zu                     
+   USE arrays_3d,          ONLY: hyp, pt, rdf_sc, tend, zu, exner
    USE chem_gasphase_mod,  ONLY: nspec, spc_names, nkppctrl, nmaxfixsteps,     &
                                  t_steps, fill_temp, chem_gasphase_integrate,  &
@@ -939,5 +942,5 @@
     IF (chem_gasphase_on) THEN
 
-       tmp_temp(:) = pt(:,j,i) * ( hyp(nzb+1:nzt) / 100000.0_wp )**0.286_wp
+       tmp_temp(:) = pt(:,j,i) * exner(nzb+1:nzt)
 ! ppm to molecules/cm**3
 !      tmp_fact = 1.e-6_wp*6.022e23_wp/(22.414_wp*1000._wp) * 273.15_wp * hyp(nzb+1:nzt)/( 101300.0_wp * tmp_temp )
Index: /palm/trunk/SOURCE/compute_vpt.f90
===================================================================
--- /palm/trunk/SOURCE/compute_vpt.f90	(revision 3273)
+++ /palm/trunk/SOURCE/compute_vpt.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -67,16 +70,19 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  pt, q, ql, vpt
-        
+        ONLY:  pt, q, ql, vpt, d_exner
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  lv_d_cp
+
+    USE control_parameters,                                                    &
+        ONLY:  cloud_droplets
+
     USE indices,                                                               &
         ONLY:  nzb, nzt
-        
-    USE cloud_parameters,                                                      &
-        ONLY:  l_d_cp, pt_d_t
-        
-    USE control_parameters,                                                    &
-        ONLY:  cloud_droplets, cloud_physics
-        
+
     USE kinds
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model
 
     IMPLICIT NONE
@@ -84,9 +90,9 @@
     INTEGER(iwp) :: k   !< 
 
-    IF ( .NOT. cloud_physics  .AND.  .NOT. cloud_droplets )  THEN
+    IF ( .NOT. bulk_cloud_model  .AND.  .NOT. cloud_droplets )  THEN
        vpt = pt * ( 1.0_wp + 0.61_wp * q )
-    ELSE IF (cloud_physics)  THEN
+    ELSE IF (bulk_cloud_model)  THEN
        DO  k = nzb, nzt+1
-          vpt(k,:,:) = ( pt(k,:,:) + pt_d_t(k) * l_d_cp * ql(k,:,:) ) *        &
+          vpt(k,:,:) = ( pt(k,:,:) + d_exner(k) * lv_d_cp * ql(k,:,:) ) *      &
                        ( 1.0_wp + 0.61_wp * q(k,:,:) - 1.61_wp * ql(k,:,:) ) 
        ENDDO
Index: /palm/trunk/SOURCE/data_output_2d.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_2d.f90	(revision 3273)
+++ /palm/trunk/SOURCE/data_output_2d.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -237,13 +240,16 @@
                precipitation_amount, prr, q, qc, ql, ql_c, ql_v, qr,           &
                rho_ocean, s, sa, tend, u, v, vpt, w, zu, zw,                   &
-               waterflux_output_conversion
-        
+               waterflux_output_conversion, hyrho, d_exner
+
     USE averaging
-        
-    USE cloud_parameters,                                                      &
-        ONLY:  cp, hyrho, l_d_cp, l_v, pt_d_t
-               
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  c_p, lv_d_cp, l_v
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model, bcm_data_output_2d
+
     USE control_parameters,                                                    &
-        ONLY:  cloud_physics, data_output_2d_on_each_pe, data_output_xy,       &
+        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,                          &
@@ -254,20 +260,20 @@
                psolver, section, simulated_time,                               &
                time_since_reference_point, uv_exposure
-        
+
     USE cpulog,                                                                &
         ONLY:  cpu_log, log_point 
-        
+
     USE gust_mod,                                                              &
         ONLY:  gust_data_output_2d, gust_module_enabled
-        
+
     USE indices,                                                               &
         ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg,       &
                nzb, nzt, wall_flags_0
-               
+
     USE kinds
-    
+
     USE land_surface_model_mod,                                                &
         ONLY:  lsm_data_output_2d, zs
-    
+
 #if defined( __netcdf )
     USE NETCDF
@@ -579,28 +585,4 @@
                 level_z(nzb+1) = zu(nzb+1)
 
-             CASE ( 'nc_xy', 'nc_xz', 'nc_yz' )
-                IF ( av == 0 )  THEN
-                   to_be_resorted => nc
-                ELSE
-                   IF ( .NOT. ALLOCATED( nc_av ) ) THEN
-                      ALLOCATE( nc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                      nc_av = REAL( fill_value, KIND = wp )
-                   ENDIF
-                   to_be_resorted => nc_av
-                ENDIF
-                IF ( mode == 'xy' )  level_z = zu
-
-             CASE ( 'nr_xy', 'nr_xz', 'nr_yz' )
-                IF ( av == 0 )  THEN
-                   to_be_resorted => nr
-                ELSE
-                   IF ( .NOT. ALLOCATED( nr_av ) ) THEN
-                      ALLOCATE( nr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                      nr_av = REAL( fill_value, KIND = wp )
-                   ENDIF
-                   to_be_resorted => nr_av
-                ENDIF
-                IF ( mode == 'xy' )  level_z = zu
-
              CASE ( 'ghf*_xy' )        ! 2d-array
                 IF ( av == 0 )  THEN
@@ -756,46 +738,7 @@
                 ENDIF
 
-             CASE ( 'pra*_xy' )        ! 2d-array / integral quantity => no av
-!                CALL exchange_horiz_2d( precipitation_amount )
-                   DO  i = nxl, nxr
-                      DO  j = nys, nyn
-                      local_pf(i,j,nzb+1) =  precipitation_amount(j,i)
-                   ENDDO
-                ENDDO
-                precipitation_amount = 0.0_wp   ! reset for next integ. interval
-                resorted = .TRUE.
-                two_d = .TRUE.
-                level_z(nzb+1) = zu(nzb+1)
-
-             CASE ( 'prr_xy', 'prr_xz', 'prr_yz' )
-                IF ( av == 0 )  THEN
-!                   CALL exchange_horiz( prr, nbgp )
-                   DO  i = nxl, nxr
-                      DO  j = nys, nyn
-                         DO  k = nzb, nzt+1
-                            local_pf(i,j,k) = prr(k,j,i) * hyrho(nzb+1)
-                         ENDDO
-                      ENDDO
-                   ENDDO
-                ELSE
-                   IF ( .NOT. ALLOCATED( prr_av ) ) THEN
-                      ALLOCATE( prr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                      prr_av = REAL( fill_value, KIND = wp )
-                   ENDIF
-!                   CALL exchange_horiz( prr_av, nbgp )
-                   DO  i = nxl, nxr
-                      DO  j = nys, nyn
-                         DO  k = nzb, nzt+1
-                            local_pf(i,j,k) = prr_av(k,j,i) * hyrho(nzb+1)
-                         ENDDO
-                      ENDDO
-                   ENDDO
-                ENDIF
-                resorted = .TRUE.
-                IF ( mode == 'xy' )  level_z = zu
-
              CASE ( 'pt_xy', 'pt_xz', 'pt_yz' )
                 IF ( av == 0 )  THEN
-                   IF ( .NOT. cloud_physics ) THEN
+                   IF ( .NOT. bulk_cloud_model ) THEN
                       to_be_resorted => pt
                    ELSE
@@ -803,6 +746,6 @@
                       DO  j = nys, nyn
                             DO  k = nzb, nzt+1
-                               local_pf(i,j,k) = pt(k,j,i) + l_d_cp *          &
-                                                             pt_d_t(k) *       &
+                               local_pf(i,j,k) = pt(k,j,i) + lv_d_cp *         &
+                                                             d_exner(k) *      &
                                                              ql(k,j,i)
                             ENDDO
@@ -829,16 +772,4 @@
                    ENDIF
                    to_be_resorted => q_av
-                ENDIF
-                IF ( mode == 'xy' )  level_z = zu
-
-             CASE ( 'qc_xy', 'qc_xz', 'qc_yz' )
-                IF ( av == 0 )  THEN
-                   to_be_resorted => qc
-                ELSE
-                   IF ( .NOT. ALLOCATED( qc_av ) ) THEN
-                      ALLOCATE( qc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                      qc_av = REAL( fill_value, KIND = wp )
-                   ENDIF
-                   to_be_resorted => qc_av
                 ENDIF
                 IF ( mode == 'xy' )  level_z = zu
@@ -921,16 +852,4 @@
                 IF ( mode == 'xy' )  level_z = zu
 
-             CASE ( 'qr_xy', 'qr_xz', 'qr_yz' )
-                IF ( av == 0 )  THEN
-                   to_be_resorted => qr
-                ELSE
-                   IF ( .NOT. ALLOCATED( qr_av ) ) THEN
-                      ALLOCATE( qr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                      qr_av = REAL( fill_value, KIND = wp )
-                   ENDIF
-                   to_be_resorted => qr_av
-                ENDIF
-                IF ( mode == 'xy' )  level_z = zu
-
              CASE ( 'qsws*_xy' )        ! 2d-array
                 IF ( av == 0 ) THEN
@@ -1071,5 +990,5 @@
                       j = surf_lsm_h%j(m)
                       k = surf_lsm_h%k(m)
-                      local_pf(i,j,nzb+1) = surf_lsm_h%shf(m) * cp
+                      local_pf(i,j,nzb+1) = surf_lsm_h%shf(m) * c_p
                    ENDDO
                    DO  m = 1, surf_usm_h%ns
@@ -1077,5 +996,5 @@
                       j = surf_usm_h%j(m)
                       k = surf_usm_h%k(m)
-                      local_pf(i,j,nzb+1) = surf_usm_h%shf(m) * cp
+                      local_pf(i,j,nzb+1) = surf_usm_h%shf(m) * c_p
                    ENDDO
                 ELSE
@@ -1387,15 +1306,22 @@
 
 !
-!--             Land surface model quantity
-                IF ( land_surface )  THEN
-                   CALL lsm_data_output_2d( av, do2d(av,if), found, grid, mode,&
-                                            local_pf, two_d, nzb_do, nzt_do )
-                ENDIF
-
-!
 !--             Turbulence closure variables
                 IF ( .NOT. found )  THEN
                    CALL tcm_data_output_2d( av, do2d(av,if), found, grid, mode,&
                                              local_pf, nzb_do, nzt_do )
+                ENDIF
+
+!
+!--             Microphysics module quantities
+                IF ( .NOT. found  .AND.  bulk_cloud_model )  THEN
+                   CALL bcm_data_output_2d( av, do2d(av,if), found, grid, mode,&
+                                            local_pf, two_d, nzb_do, nzt_do )
+                ENDIF
+
+!
+!--             Land surface model quantity
+                IF ( .NOT. found  .AND.  land_surface )  THEN
+                   CALL lsm_data_output_2d( av, do2d(av,if), found, grid, mode,&
+                                            local_pf, two_d, nzb_do, nzt_do )
                 ENDIF
 
@@ -1417,5 +1343,5 @@
 !
 !--             UV exposure model quantity
-                IF ( uv_exposure )  THEN
+                IF ( .NOT. found  .AND.  uv_exposure )  THEN
                    CALL uvem_data_output_2d( av, do2d(av,if), found, grid,     &
                                              local_pf, two_d, nzb_do, nzt_do )
Index: /palm/trunk/SOURCE/data_output_3d.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_3d.f90	(revision 3273)
+++ /palm/trunk/SOURCE/data_output_3d.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables and format statements removed
 ! 
@@ -206,21 +209,24 @@
     USE arrays_3d,                                                             &
         ONLY:  e, nc, nr, p, pt, prr, q, qc, ql, ql_c, ql_v, qr, rho_ocean, s, &
-               sa, tend, u, v, vpt, w
-        
+               sa, tend, u, v, vpt, w, d_exner
+
     USE averaging
-        
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  lv_d_cp
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model, bcm_data_output_3d
+
     USE chemistry_model_mod,                                                   &
         ONLY:  chem_data_output_3d
 
-    USE cloud_parameters,                                                      &
-        ONLY:  l_d_cp, pt_d_t
-        
     USE control_parameters,                                                    &
-        ONLY:  air_chemistry, cloud_physics, do3d, do3d_no, do3d_time_count,   &
+        ONLY:  air_chemistry, do3d, do3d_no, do3d_time_count,                  &
                io_blocks, io_group, land_surface, message_string,              &
                ntdim_3d, nz_do3d,  plant_canopy,                               &
                psolver, simulated_time, time_since_reference_point,            &
                urban_surface, varnamelength
-        
+
     USE cpulog,                                                                &
         ONLY:  log_point, cpu_log
@@ -228,11 +234,11 @@
     USE gust_mod,                                                              &
         ONLY: gust_data_output_3d, gust_module_enabled
-        
+
     USE indices,                                                               &
         ONLY:  nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt,     &
                wall_flags_0
-        
+
     USE kinds
-    
+
     USE land_surface_model_mod,                                                &
         ONLY: lsm_data_output_3d, nzb_soil, nzt_soil
@@ -399,26 +405,4 @@
                 ENDIF
                 to_be_resorted => lpt_av
-             ENDIF
-
-          CASE ( 'nc' )
-             IF ( av == 0 )  THEN
-                to_be_resorted => nc
-             ELSE
-                IF ( .NOT. ALLOCATED( nc_av ) ) THEN
-                   ALLOCATE( nc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                   nc_av = REAL( fill_value, KIND = wp )
-                ENDIF
-                to_be_resorted => nc_av
-             ENDIF
-
-          CASE ( 'nr' )
-             IF ( av == 0 )  THEN
-                to_be_resorted => nr
-             ELSE
-                IF ( .NOT. ALLOCATED( nr_av ) ) THEN
-                   ALLOCATE( nr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                   nr_av = REAL( fill_value, KIND = wp )
-                ENDIF
-                to_be_resorted => nr_av
              ENDIF
 
@@ -506,31 +490,7 @@
              ENDIF
 
-          CASE ( 'prr' )
-             IF ( av == 0 )  THEN
-                DO  i = nxl, nxr
-                   DO  j = nys, nyn
-                      DO  k = nzb_do, nzt_do
-                         local_pf(i,j,k) = prr(k,j,i)
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ELSE
-                IF ( .NOT. ALLOCATED( prr_av ) ) THEN
-                   ALLOCATE( prr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                   prr_av = REAL( fill_value, KIND = wp )
-                ENDIF
-                DO  i = nxl, nxr
-                   DO  j = nys, nyn
-                      DO  k = nzb_do, nzt_do
-                         local_pf(i,j,k) = prr_av(k,j,i)
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDIF
-             resorted = .TRUE.
-
           CASE ( 'pt' )
              IF ( av == 0 )  THEN
-                IF ( .NOT. cloud_physics ) THEN
+                IF ( .NOT. bulk_cloud_model ) THEN
                    to_be_resorted => pt
                 ELSE
@@ -538,6 +498,6 @@
                       DO  j = nys, nyn
                          DO  k = nzb_do, nzt_do
-                            local_pf(i,j,k) = pt(k,j,i) + l_d_cp *             &
-                                                          pt_d_t(k) *          &
+                            local_pf(i,j,k) = pt(k,j,i) + lv_d_cp *            &
+                                                          d_exner(k) *         &
                                                           ql(k,j,i)
                          ENDDO
@@ -563,15 +523,4 @@
                 ENDIF
                 to_be_resorted => q_av
-             ENDIF
-
-          CASE ( 'qc' )
-             IF ( av == 0 )  THEN
-                to_be_resorted => qc
-             ELSE
-                IF ( .NOT. ALLOCATED( qc_av ) ) THEN
-                   ALLOCATE( qc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                   qc_av = REAL( fill_value, KIND = wp )
-                ENDIF
-                to_be_resorted => qc_av
              ENDIF
 
@@ -647,15 +596,4 @@
              ENDIF
 
-          CASE ( 'qr' )
-             IF ( av == 0 )  THEN
-                to_be_resorted => qr
-             ELSE
-                IF ( .NOT. ALLOCATED( qr_av ) ) THEN
-                   ALLOCATE( qr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                   qr_av = REAL( fill_value, KIND = wp )
-                ENDIF
-                to_be_resorted => qr_av
-             ENDIF
-
           CASE ( 'qv' )
              IF ( av == 0 )  THEN
@@ -758,12 +696,26 @@
 !--       Block of urban surface model outputs   
           CASE ( 'usm_output' )
-             CALL usm_data_output_3d( av, do3d(av,if), found, local_pf,     &
+             CALL usm_data_output_3d( av, do3d(av,if), found, local_pf,        &
                                          nzb_do, nzt_do )
 
           CASE DEFAULT
 
+             IF ( .NOT. found )  THEN
+                CALL tcm_data_output_3d( av, do3d(av,if), found, local_pf,     &
+                                         nzb_do, nzt_do )
+                resorted = .TRUE.
+             ENDIF
+
+!
+!--          Microphysic module quantities
+             IF ( .NOT. found  .AND.  bulk_cloud_model )  THEN
+                CALL bcm_data_output_3d( av, do3d(av,if), found, local_pf,     &
+                                         nzb_do, nzt_do )
+                resorted = .TRUE.
+             ENDIF
+
 !
 !--          Land surface quantity
-             IF ( land_surface )  THEN
+             IF ( .NOT. found  .AND.  land_surface )  THEN
 !
 !--             For soil model quantities, it is required to re-allocate local_pf
@@ -788,10 +740,4 @@
                 ENDIF
 
-             ENDIF
-
-             IF ( .NOT. found )  THEN
-                CALL tcm_data_output_3d( av, do3d(av,if), found, local_pf,     &
-                                         nzb_do, nzt_do )
-                resorted = .TRUE.
              ENDIF
 
Index: /palm/trunk/SOURCE/data_output_dvrp.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_dvrp.f90	(revision 3273)
+++ /palm/trunk/SOURCE/data_output_dvrp.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3045 2018-05-28 07:55:41Z Giersch
 ! Code adjusted according to PALM coding standards
 ! 
@@ -131,14 +134,11 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  p, pt, q, ql, s, ts, u, us, v, w, zu
-        
-    USE cloud_parameters,                                                      &
-        ONLY:  l_d_cp, pt_d_t
-        
-    USE constants,                                                             &
-        ONLY:  pi
-        
+        ONLY:  p, pt, q, ql, s, ts, u, us, v, w, zu, d_exner
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  pi, lv_d_cp
+
     USE control_parameters,                                                    &
-        ONLY:  cloud_droplets, cloud_physics, do2d, do3d, humidity, ibc_uv_b,  &
+        ONLY:  cloud_droplets, do2d, do3d, humidity, ibc_uv_b,                 &
                message_string, nz_do3d, passive_scalar, simulated_time,        &
                threshold
@@ -160,4 +160,7 @@
         
     USE kinds
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model
 
     USE pegrid
@@ -335,5 +338,5 @@
 
                 CASE ( 'pt', 'pt_xy', 'pt_xz', 'pt_yz' )
-                   IF ( .NOT. cloud_physics ) THEN
+                   IF ( .NOT. bulk_cloud_model ) THEN
                       DO  i = nxl_dvrp, nxr_dvrp+1
                          DO  j = nys_dvrp, nyn_dvrp+1
@@ -347,6 +350,6 @@
                          DO  j = nys_dvrp, nyn_dvrp+1
                             DO  k = nzb, nz_do3d
-                               local_pf(i,j,k) = pt(k,j,i) + l_d_cp *          &
-                                                 pt_d_t(k) * ql(k,j,i)
+                               local_pf(i,j,k) = pt(k,j,i) + lv_d_cp *         &
+                                                 d_exner(k) * ql(k,j,i)
                             ENDDO
                          ENDDO
@@ -372,5 +375,5 @@
              
                 CASE ( 'ql', 'ql_xy', 'ql_xz', 'ql_yz' )
-                   IF ( cloud_physics  .OR.  cloud_droplets )  THEN
+                   IF ( bulk_cloud_model  .OR.  cloud_droplets )  THEN
                       DO  i = nxl_dvrp, nxr_dvrp+1
                          DO  j = nys_dvrp, nyn_dvrp+1
@@ -381,5 +384,5 @@
                       ENDDO
                    ELSE                     
-                      message_string = 'if cloud_physics = .FALSE. and ' //    & 
+                      message_string = 'if bulk_cloud_model = .FALSE. and ' // &
                                   'cloud_droplets = .FALSE. '
                                   'output of ' // TRIM( output_variable) //    &
Index: /palm/trunk/SOURCE/data_output_mask.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_mask.f90	(revision 3273)
+++ /palm/trunk/SOURCE/data_output_mask.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variable removed
 ! 
@@ -129,5 +132,5 @@
     USE arrays_3d,                                                             &
         ONLY:  e, nc, nr, p, pt, q, qc, ql, ql_c, ql_v, qr, rho_ocean, s, sa,  &
-               tend, u, v, vpt, w
+               tend, u, v, vpt, w, d_exner
     
     USE averaging,                                                             &
@@ -135,10 +138,10 @@
                qc_av, ql_av, ql_c_av, ql_v_av, ql_vp_av, qv_av, qr_av,         &
                rho_ocean_av, s_av, sa_av, u_av, v_av, vpt_av, w_av 
-    
-    USE cloud_parameters,                                                      &
-        ONLY:  l_d_cp, pt_d_t
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  lv_d_cp
     
     USE control_parameters,                                                    &
-        ONLY:  cloud_physics, domask, domask_no, domask_time_count, mask_i,    &
+        ONLY:  domask, domask_no, domask_time_count, mask_i,                   &
                mask_j, mask_k, mask_size, mask_size_l, mask_start_l,           &
                max_masks, message_string, mid, nz_do3d, simulated_time
@@ -150,4 +153,7 @@
         
     USE kinds
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model
     
     USE NETCDF
@@ -354,5 +360,5 @@
           CASE ( 'pt' )
              IF ( av == 0 )  THEN
-                IF ( .NOT. cloud_physics ) THEN
+                IF ( .NOT. bulk_cloud_model ) THEN
                    to_be_resorted => pt
                 ELSE
@@ -362,5 +368,5 @@
                             local_pf(i,j,k) =  &
                                  pt(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i)) &
-                                 + l_d_cp * pt_d_t(mask_k(mid,k)) * &
+                                 + lv_d_cp * d_exner(mask_k(mid,k)) *          &
                                    ql(mask_k(mid,k),mask_j(mid,j),mask_i(mid,i))
                          ENDDO
Index: /palm/trunk/SOURCE/data_output_spectra.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_spectra.f90	(revision 3273)
+++ /palm/trunk/SOURCE/data_output_spectra.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -238,5 +241,5 @@
 #if defined( __netcdf )
 
-    USE constants,                                                             &
+    USE basic_constants_and_equations_mod,                                     &
         ONLY:  pi
 
Index: lm/trunk/SOURCE/diagnostic_quantities_mod.f90
===================================================================
--- /palm/trunk/SOURCE/diagnostic_quantities_mod.f90	(revision 3273)
+++ 	(revision )
@@ -1,150 +1,0 @@
-!> @file diagnostic_quantities_mod.f90
-!------------------------------------------------------------------------------!
-! This file is part of the PALM model system.
-!
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
-!
-! Copyright 1997-2018 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
-!
-! Current revisions:
-! -----------------
-! 
-! 
-! Former revisions:
-! ----------------- 
-! $Id$
-! Bugfix for microphysic scheme = 'saturation_adjustment'
-! 
-! 3026 2018-05-22 10:30:53Z schwenkel
-! Changed the name specific humidity to mixing ratio, since we are computing
-! mixing ratios.
-! 
-! 2839 2018-02-27 09:49:06Z schwenkel
-! Bugfix for Kessler microphysics
-! 
-! 2718 2018-01-02 08:49:38Z maronga
-! Corrected "Former revisions" section
-! 
-! 2696 2017-12-14 17:12:51Z kanani
-! Change in file header (GPL part)
-!
-! 2608 2017-11-13 14:04:26Z schwenkel
-! Initial revision
-! 
-! 
-! Description:
-! ------------
-!> This module contains subroutines and functions for the calculation of 
-!> diagnostic quantities. Especially moisture quantities such as the saturation
-!> mixining ratio is calculated
-!------------------------------------------------------------------------------!
-MODULE diagnostic_quantities_mod
- 
-
-   USE kinds
-   
-   IMPLICIT NONE
-
-   REAL(wp) ::  alpha   !< correction factor 
-   REAL(wp) ::  e_s     !< saturation water vapor pressure
-   REAL(wp) ::  q_s     !< saturation mixing ratio
-   REAL(wp) ::  sat     !< supersaturation
-   REAL(wp) ::  t_l     !< actual temperature
-
-   PRIVATE
-   PUBLIC  e_s, magnus, q_s, sat, supersaturation, t_l
-
-    INTERFACE supersaturation
-       MODULE PROCEDURE supersaturation
-    END INTERFACE supersaturation
-
- CONTAINS
- 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Computation of the diagnostic supersaturation sat, actual liquid water 
-!< temperature t_l and saturation water vapor mixing ratio q_s
-!------------------------------------------------------------------------------!
-    SUBROUTINE supersaturation ( i,j,k )
-
-       USE arrays_3d,                                                          &
-           ONLY:  hyp, pt, q, qc, qr
-
-       USE cloud_parameters,                                                   &
-           ONLY:  l_d_cp, l_d_r, t_d_pt       
-
-       USE control_parameters,                                                 &
-           ONLY:  microphysics_kessler, microphysics_sat_adjust                                       
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-!
-!--    Actual liquid water temperature:
-       t_l = t_d_pt(k) * pt(k,j,i)
-!
-!--    Calculate water vapor saturation pressure
-       e_s = magnus( t_l )
-!
-!--    Computation of saturation mixing ratio:
-       q_s   = 0.622_wp * e_s / ( hyp(k) - e_s )
-!
-!--    Correction factor
-       alpha = 0.622_wp * l_d_r * l_d_cp / ( t_l * t_l )
-!
-!--    Correction of the approximated value
-!--    (see: Cuijpers + Duynkerke, 1993, JAS, 23)
-       q_s   = q_s * ( 1.0_wp + alpha * q(k,j,i) ) / ( 1.0_wp + alpha * q_s )
-!
-!--    Supersaturation:
-!--    Not in case of microphysics_kessler or microphysics_sat_adjust 
-!--    since qr is unallocated
-       IF ( .NOT. microphysics_kessler  .AND.                                  & 
-            .NOT.  microphysics_sat_adjust )                                THEN
-          sat   = ( q(k,j,i) - qr(k,j,i) - qc(k,j,i) ) / q_s - 1.0_wp
-       ENDIF
-
-    END SUBROUTINE supersaturation
-
- 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> This function computes the magnus function (Press et al., 1992).
-!> The magnus formula is needed to calculate the saturation vapor pressure
-!------------------------------------------------------------------------------!
-
-    FUNCTION magnus( temperature )
-
-       IMPLICIT NONE
-
-       REAL(wp)     ::  magnus            !<
-       REAL(wp)     ::  temperature       !<
-
-!
-!--    Saturation vapor pressure at t_l:
-       magnus =  611.2_wp * EXP( 17.62_wp * ( temperature - 273.15_wp ) /      & 
-                                            ( temperature - 29.65_wp  ) )
-
-!        magnus = 610.78_wp * EXP( 17.269_wp * ( temperature - 273.16_wp ) /     &
-!                                              ( temperature - 35.86_wp )        &
-!                                )
-
-    END FUNCTION magnus
-
-
-END MODULE diagnostic_quantities_mod
Index: /palm/trunk/SOURCE/flow_statistics.f90
===================================================================
--- /palm/trunk/SOURCE/flow_statistics.f90	(revision 3273)
+++ /palm/trunk/SOURCE/flow_statistics.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -283,16 +286,16 @@
                momentumflux_output_conversion, nc, nr, p, prho, prr, pt, q,    &
                qc, ql, qr, rho_air, rho_air_zw, rho_ocean, s,                  &
-               sa, u, ug, v, vg, vpt, w, w_subs, waterflux_output_conversion, zw
+               sa, u, ug, v, vg, vpt, w, w_subs, waterflux_output_conversion,  &
+               zw, d_exner
         
-    USE cloud_parameters,                                                      &
-        ONLY:   l_d_cp, pt_d_t
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:   g, lv_d_cp
         
     USE control_parameters,                                                    &
-        ONLY:   average_count_pr, cloud_droplets, cloud_physics, do_sum,       &
-                dt_3d, g, humidity, initializing_actions, land_surface,        &
+        ONLY:   average_count_pr, cloud_droplets, do_sum,                      &
+                dt_3d, humidity, initializing_actions, land_surface,           &
                 large_scale_forcing, large_scale_subsidence, max_pr_user,      &
-                message_string, neutral, microphysics_morrison,                &
-                microphysics_seifert, ocean, passive_scalar, simulated_time,   &
-                simulated_time_at_begin, use_subsidence_tendencies,            & 
+                message_string, neutral, ocean, passive_scalar, simulated_time,&
+                simulated_time_at_begin, use_subsidence_tendencies,            &
                 use_surface_fluxes, use_top_fluxes, ws_scheme_mom,             &
                 ws_scheme_sca
@@ -313,4 +316,7 @@
         
     USE kinds
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
     
     USE land_surface_model_mod,                                                &
@@ -515,5 +521,5 @@
              ENDDO
           ENDDO
-          IF ( cloud_physics )  THEN
+          IF ( bulk_cloud_model )  THEN
              !$OMP DO
              DO  i = nxl, nxr
@@ -525,5 +531,5 @@
                                                                * flag
                       sums_l(k,43,tn) = sums_l(k,43,tn) + (                    &
-                                      pt(k,j,i) + l_d_cp*pt_d_t(k) * ql(k,j,i) &
+                                      pt(k,j,i) + lv_d_cp * d_exner(k) * ql(k,j,i) &
                                                           ) * rmask(j,i,sr)    &
                                                             * flag
@@ -563,5 +569,5 @@
                 sums_l(:,41,0) = sums_l(:,41,0) + sums_l(:,41,i)
                 sums_l(:,44,0) = sums_l(:,44,0) + sums_l(:,44,i)
-                IF ( cloud_physics )  THEN
+                IF ( bulk_cloud_model )  THEN
                    sums_l(:,42,0) = sums_l(:,42,0) + sums_l(:,42,i)
                    sums_l(:,43,0) = sums_l(:,43,0) + sums_l(:,43,i)
@@ -598,5 +604,5 @@
           CALL MPI_ALLREDUCE( sums_l(nzb,41,0), sums(nzb,41), nzt+2-nzb,       &
                               MPI_REAL, MPI_SUM, comm2d, ierr )
-          IF ( cloud_physics ) THEN
+          IF ( bulk_cloud_model ) THEN
              IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
              CALL MPI_ALLREDUCE( sums_l(nzb,42,0), sums(nzb,42), nzt+2-nzb,    &
@@ -621,5 +627,5 @@
           sums(:,44) = sums_l(:,44,0)
           sums(:,41) = sums_l(:,41,0)
-          IF ( cloud_physics ) THEN
+          IF ( bulk_cloud_model ) THEN
              sums(:,42) = sums_l(:,42,0)
              sums(:,43) = sums_l(:,43,0)
@@ -654,5 +660,5 @@
           hom(:,1,44,sr) = sums(:,44)             ! vpt
           hom(:,1,41,sr) = sums(:,41)             ! qv (q)
-          IF ( cloud_physics ) THEN
+          IF ( bulk_cloud_model ) THEN
              sums(:,42) = sums(:,42) / ngp_2dh_s_inner(:,sr)
              sums(:,43) = sums(:,43) / ngp_2dh_s_inner(:,sr)
@@ -948,5 +954,5 @@
                                                * ddzu(k+1) * rmask(j,i,sr) * flag
 
-                   IF ( cloud_physics ) THEN
+                   IF ( bulk_cloud_model ) THEN
                       sums_l(k,51,tn) = sums_l(k,51,tn)                        &
                                          - 0.5_wp * ( kh(k,j,i) + kh(k+1,j,i) )&
@@ -1014,5 +1020,5 @@
                                           * heatflux_output_conversion(k+ki)
                             ENDIF
-                            IF ( cloud_physics )  THEN
+                            IF ( bulk_cloud_model )  THEN
 !
 !--                            Formula does not work if ql(k+ki) /= 0.0
@@ -1067,5 +1073,5 @@
                                           * heatflux_output_conversion(nzb)
                       ENDIF
-                      IF ( cloud_physics )  THEN
+                      IF ( bulk_cloud_model )  THEN
 !
 !--                      Formula does not work if ql(nzb) /= 0.0
@@ -1118,5 +1124,5 @@
                                           * heatflux_output_conversion(nzb)
                       ENDIF
-                      IF ( cloud_physics )  THEN
+                      IF ( bulk_cloud_model )  THEN
 !
 !--                      Formula does not work if ql(nzb) /= 0.0
@@ -1293,5 +1299,5 @@
                                            * heatflux_output_conversion(nzt)
                    ENDIF
-                   IF ( cloud_physics )  THEN
+                   IF ( bulk_cloud_model )  THEN
 !
 !--                   Formula does not work if ql(nzb) /= 0.0
@@ -1347,5 +1353,5 @@
 !--             content, rain drop concentration and rain water content
                 IF ( humidity )  THEN
-                   IF ( cloud_physics .OR. cloud_droplets )  THEN
+                   IF ( bulk_cloud_model .OR. cloud_droplets )  THEN
                       pts = 0.5_wp * ( vpt(k,j,i)   - hom(k,1,44,sr) +         &
                                     vpt(k+1,j,i) - hom(k+1,1,44,sr) )
Index: /palm/trunk/SOURCE/header.f90
===================================================================
--- /palm/trunk/SOURCE/header.f90	(revision 3273)
+++ /palm/trunk/SOURCE/header.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -378,9 +381,12 @@
     USE arrays_3d,                                                             &
         ONLY:  pt_init, q_init, s_init, sa_init, ug, vg, w_subs, zu, zw
-        
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  g, kappa, l_v, r_d
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model, bcm_header
+
     USE control_parameters
-        
-    USE cloud_parameters,                                                      &
-        ONLY:  cp, l_v, r_d
 
     USE cpulog,                                                                &
@@ -413,9 +419,4 @@
     USE lsf_nudging_mod,                                                       &
         ONLY:  lsf_nudging_header
-
-    USE microphysics_mod,                                                      &
-        ONLY:  cloud_water_sedimentation, collision_turbulence,                &
-               c_sedimentation, limiter_sedimentation, nc_const,               &
-               ventilation_effect
 
     USE model_1d_mod,                                                          &
@@ -742,5 +743,5 @@
     IF ( neutral )  WRITE ( io, 131 )  pt_surface
     IF ( humidity )  THEN
-       IF ( .NOT. cloud_physics )  THEN
+       IF ( .NOT. bulk_cloud_model )  THEN
           WRITE ( io, 129 )
        ELSE
@@ -1902,32 +1903,15 @@
 
 !
-!-- Cloud physics parameters
-    IF ( cloud_physics )  THEN
-       WRITE ( io, 415 )
-       WRITE ( io, 416 ) surface_pressure, r_d, rho_surface, cp, l_v
-       IF ( microphysics_seifert )  THEN
-          WRITE ( io, 510 ) 1.0E-6_wp * nc_const
-          WRITE ( io, 511 ) c_sedimentation
-       ENDIF
-    ENDIF
+!-- Output of microphysics information
+    IF ( bulk_cloud_model )  CALL bcm_header( io )
 
 !
 !-- Cloud physcis parameters / quantities / numerical methods
     WRITE ( io, 430 )
-    IF ( humidity .AND. .NOT. cloud_physics .AND. .NOT. cloud_droplets)  THEN
+    IF ( humidity .AND. .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets)  THEN
        WRITE ( io, 431 )
-    ELSEIF ( humidity  .AND.  cloud_physics )  THEN
-       WRITE ( io, 432 )
-       IF ( cloud_top_radiation )  WRITE ( io, 132 )
-       IF ( microphysics_kessler )  THEN
-          WRITE ( io, 133 )
-       ELSEIF ( microphysics_seifert )  THEN
-          IF ( cloud_water_sedimentation )  WRITE ( io, 506 )
-          WRITE ( io, 505 )
-          IF ( collision_turbulence )  WRITE ( io, 507 )
-          IF ( ventilation_effect )  WRITE ( io, 508 )
-          IF ( limiter_sedimentation )  WRITE ( io, 509 )
-       ENDIF
-    ELSEIF ( humidity  .AND.  cloud_droplets )  THEN
+    ENDIF
+    IF ( cloud_top_radiation )  WRITE ( io, 132 )
+    IF ( humidity  .AND.  cloud_droplets )  THEN
        WRITE ( io, 433 )
        IF ( curvature_solution_effects )  WRITE ( io, 434 )
@@ -2105,5 +2089,4 @@
 132 FORMAT ('     Parameterization of long-wave radiation processes via'/ &
             '     effective emissivity scheme')
-133 FORMAT ('     Precipitation parameterization via Kessler-Scheme')
 134 FORMAT (' --> Additional prognostic equation for a passive scalar')
 135 FORMAT (' --> Solve perturbation pressure via ',A,' method (', &
@@ -2327,11 +2310,4 @@
 413 FORMAT ('       Reference density in buoyancy terms: ',F8.3,' kg/m**3')
 414 FORMAT ('       Reference temperature in buoyancy terms: ',F8.4,' K')
-415 FORMAT (/' Cloud physics parameters:'/ &
-             ' ------------------------'/)
-416 FORMAT ('    Surface pressure   :   p_0   = ',F7.2,' hPa'/      &
-            '    Gas constant       :   R     = ',F5.1,' J/(kg K)'/ &
-            '    Density of air     :   rho_0 =',F6.3,' kg/m**3'/  &
-            '    Specific heat cap. :   c_p   = ',F6.1,' J/(kg K)'/ &
-            '    Vapourization heat :   L_v   =',E9.2,' J/kg')
 420 FORMAT (/'    Characteristic levels of the initial temperature profile:'// &
             '       Height:        ',A,'  m'/ &
@@ -2376,7 +2352,4 @@
               ' ----------------------------------'/)
 431 FORMAT ('    Humidity is considered, bu no condensation')
-432 FORMAT ('    Bulk scheme with liquid water potential temperature and'/ &
-            '    total water content is used.'/ &
-            '    Condensation is parameterized via 0% - or 100% scheme.')
 433 FORMAT ('    Cloud droplets treated explicitly using the Lagrangian part', &
                  'icle model')
@@ -2473,12 +2446,4 @@
 503 FORMAT (' --> Momentum advection via Wicker-Skamarock-Scheme 5th order')
 504 FORMAT (' --> Scalar advection via Wicker-Skamarock-Scheme 5th order')
-505 FORMAT ('    Precipitation parameterization via Seifert-Beheng-Scheme')
-506 FORMAT ('    Cloud water sedimentation parameterization via Stokes law')
-507 FORMAT ('    Turbulence effects on precipitation process')
-508 FORMAT ('    Ventilation effects on evaporation of rain drops')
-509 FORMAT ('    Slope limiter used for sedimentation process')
-510 FORMAT ('    Droplet density    :   N_c   = ',F6.1,' 1/cm**3')
-511 FORMAT ('    Sedimentation Courant number:                  '/&
-            '                               C_s   =',F4.1,'        ')
 512 FORMAT (/' Date:                 ',A8,6X,'Run:       ',A34/      &
             ' Time:                 ',A8,6X,'Run-No.:   ',I2.2/     &
Index: /palm/trunk/SOURCE/init_3d_model.f90
===================================================================
--- /palm/trunk/SOURCE/init_3d_model.f90	(revision 3273)
+++ /palm/trunk/SOURCE/init_3d_model.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -255,5 +258,5 @@
 ! precipitation_amount, precipitation_rate, prr moved to arrays_3d.
 ! Initialization of nc_1d, nr_1d, pt_1d, qc_1d, qr_1d, q_1d moved to
-! microphysics_init.
+! bcm_init.
 !
 ! 1845 2016-04-08 08:29:13Z raasch
@@ -498,13 +501,14 @@
     USE arrays_3d
 
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  c_p, g, l_v, pi, r_d, exner_function, exner_function_invers,    &
+               ideal_gas_law_rho, ideal_gas_law_rho_pt, barometric_formula
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model, bcm_init, bcm_init_arrays
+
     USE chemistry_model_mod,                                                   &
         ONLY:  chem_emissions
 
-    USE cloud_parameters,                                                      &
-        ONLY:  cp, l_v, r_d
-
-    USE constants,                                                             &
-        ONLY:  pi
-    
     USE control_parameters
     
@@ -530,7 +534,4 @@
     USE lsf_nudging_mod,                                                       &
         ONLY:  lsf_init, ls_forcing_surf, nudge_init
-
-    USE microphysics_mod,                                                      &
-        ONLY:  microphysics_init
 
     USE model_1d_mod,                                                          &
@@ -738,72 +739,4 @@
 #endif
 
-       IF ( cloud_physics )  THEN
-!
-!--          Liquid water content
-#if defined( __nopointer )
-          ALLOCATE ( ql(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-#else
-          ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-#endif
-
-!
-!--       3D-cloud water content
-          IF ( .NOT. microphysics_morrison )  THEN
-#if defined( __nopointer )
-             ALLOCATE( qc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-#else
-             ALLOCATE( qc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-#endif
-          ENDIF
-!
-!--       Precipitation amount and rate (only needed if output is switched)
-          ALLOCATE( precipitation_amount(nysg:nyng,nxlg:nxrg) )
-
-!
-!--       3d-precipitation rate
-          ALLOCATE( prr(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-
-          IF ( microphysics_morrison )  THEN
-!
-!--          3D-cloud drop water content, cloud drop concentration arrays
-#if defined( __nopointer )
-             ALLOCATE( nc(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
-                       nc_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       qc(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
-                       qc_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       tnc_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                   & 
-                       tqc_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-#else
-             ALLOCATE( nc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       nc_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       nc_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       qc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       qc_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       qc_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-#endif
-          ENDIF
-
-          IF ( microphysics_seifert )  THEN
-!
-!--          3D-rain water content, rain drop concentration arrays
-#if defined( __nopointer )
-             ALLOCATE( nr(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
-                       nr_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       qr(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
-                       qr_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       tnr_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                   &
-                       tqr_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-#else
-             ALLOCATE( nr_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       nr_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       nr_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       qr_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       qr_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
-                       qr_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-#endif
-          ENDIF
-
-       ENDIF
-
        IF ( cloud_droplets )  THEN
 !
@@ -868,13 +801,13 @@
 !
 !-- Density profile calculation for anelastic approximation
-    t_surface = pt_surface * ( surface_pressure / 1000.0_wp )**( r_d / cp )
+    t_surface = pt_surface * ( surface_pressure / 1000.0_wp )**( r_d / c_p )
     IF ( TRIM( approximation ) == 'anelastic' ) THEN
        DO  k = nzb, nzt+1
           p_hydrostatic(k)    = surface_pressure * 100.0_wp *                  &
-                                ( 1 - ( g * zu(k) ) / ( cp * t_surface )       &
-                                )**( cp / r_d )
+                                ( 1 - ( g * zu(k) ) / ( c_p * t_surface )      &
+                                )**( c_p / r_d )
           rho_air(k)          = ( p_hydrostatic(k) *                           &
                                   ( 100000.0_wp / p_hydrostatic(k)             &
-                                  )**( r_d / cp )                              &
+                                  )**( r_d / c_p )                             &
                                 ) / ( r_d * pt_init(k) )
        ENDDO
@@ -887,9 +820,9 @@
        DO  k = nzb, nzt+1
           p_hydrostatic(k)    = surface_pressure * 100.0_wp *                  &
-                                ( 1 - ( g * zu(nzb) ) / ( cp * t_surface )       &
-                                )**( cp / r_d )
+                                ( 1 - ( g * zu(nzb) ) / ( c_p * t_surface )    &
+                                )**( c_p / r_d )
           rho_air(k)          = ( p_hydrostatic(k) *                           &
                                   ( 100000.0_wp / p_hydrostatic(k)             &
-                                  )**( r_d / cp )                              &
+                                  )**( r_d / c_p )                             &
                                 ) / ( r_d * pt_init(nzb) )
        ENDDO
@@ -923,5 +856,5 @@
             momentumflux_input_conversion(k)  = rho_air_zw(k)
         ELSEIF ( TRIM( flux_input_mode ) == 'dynamic' ) THEN
-            heatflux_input_conversion(k)      = 1.0_wp / cp
+            heatflux_input_conversion(k)      = 1.0_wp / c_p
             waterflux_input_conversion(k)     = 1.0_wp / l_v
             momentumflux_input_conversion(k)  = 1.0_wp
@@ -933,5 +866,5 @@
             momentumflux_output_conversion(k) = drho_air_zw(k)
         ELSEIF ( TRIM( flux_output_mode ) == 'dynamic' ) THEN
-            heatflux_output_conversion(k)     = cp
+            heatflux_output_conversion(k)     = c_p
             waterflux_output_conversion(k)    = l_v
             momentumflux_output_conversion(k) = 1.0_wp
@@ -1065,21 +998,5 @@
     IF ( humidity )  THEN
        q => q_1;  q_p => q_2;  tq_m => q_3
-       IF ( humidity )  THEN
-          vpt  => vpt_1    
-          IF ( cloud_physics )  THEN
-             ql => ql_1
-             IF ( .NOT. microphysics_morrison )  THEN
-                qc => qc_1
-             ENDIF
-             IF ( microphysics_morrison )  THEN
-                qc => qc_1;  qc_p  => qc_2;  tqc_m  => qc_3
-                nc => nc_1;  nc_p  => nc_2;  tnc_m  => nc_3
-             ENDIF
-             IF ( microphysics_seifert )  THEN
-                qr => qr_1;  qr_p  => qr_2;  tqr_m  => qr_3
-                nr => nr_1;  nr_p  => nr_2;  tnr_m  => nr_3
-             ENDIF
-          ENDIF
-       ENDIF
+       vpt  => vpt_1
        IF ( cloud_droplets )  THEN
           ql   => ql_1
@@ -1102,4 +1019,9 @@
 !-- Initialize surface arrays
     CALL init_surface_arrays
+!
+!-- Allocate microphysics module arrays
+    IF ( bulk_cloud_model )  THEN
+       CALL bcm_init_arrays
+    ENDIF
 !
 !-- Allocate land surface model arrays
@@ -1297,26 +1219,4 @@
 !--       Set inital w to 0
           w = 0.0_wp
-!
-!--       Initialize the remaining quantities
-          IF ( humidity )  THEN
-             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      qc(:,j,i) = 0.0_wp
-                      nc(:,j,i) = 0.0_wp
-                   ENDDO
-                ENDDO
-             ENDIF
-
-             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      qr(:,j,i) = 0.0_wp
-                      nr(:,j,i) = 0.0_wp
-                   ENDDO
-                ENDDO
-             ENDIF
-
-          ENDIF
 
           IF ( passive_scalar )  THEN
@@ -1376,20 +1276,4 @@
                 ENDDO
              ENDDO
-             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      qc(:,j,i) = 0.0_wp
-                      nc(:,j,i) = 0.0_wp
-                   ENDDO
-                ENDDO
-             ENDIF
-             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      qr(:,j,i) = 0.0_wp
-                      nr(:,j,i) = 0.0_wp
-                   ENDDO
-                ENDDO
-             ENDIF
           ENDIF
 
@@ -1485,22 +1369,4 @@
                 ENDDO
              ENDDO
-             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      qc(:,j,i) = 0.0_wp
-                      nc(:,j,i) = 0.0_wp
-                   ENDDO
-                ENDDO
-             ENDIF
-
-             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      qr(:,j,i) = 0.0_wp
-                      nr(:,j,i) = 0.0_wp
-                   ENDDO
-                ENDDO
-             ENDIF
-
           ENDIF
           
@@ -1598,5 +1464,5 @@
 !--       Store initial profile of mixing ratio and potential
 !--       temperature
-          IF ( cloud_physics  .OR.  cloud_droplets ) THEN
+          IF ( bulk_cloud_model  .OR.  cloud_droplets ) THEN
              hom(:,1,27,:) = SPREAD(  q(:,nys,nxl), 2, statistic_regions+1 )
              hom(:,1,28,:) = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
@@ -1645,14 +1511,4 @@
 !--    In case of iterative solvers, p must get an initial value
        IF ( psolver(1:9) == 'multigrid'  .OR.  psolver == 'sor' )  p = 0.0_wp
-
-!
-!--    Treating cloud physics, liquid water content and precipitation amount
-!--    are zero at beginning of the simulation
-       IF ( cloud_physics )  THEN
-          ql = 0.0_wp
-          qc = 0.0_wp
-
-          precipitation_amount = 0.0_wp
-       ENDIF
 !
 !--    Impose vortex with vertical axis on the initial velocity profile
@@ -1693,16 +1549,4 @@
           tq_m = 0.0_wp
           q_p = q
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
-             tqc_m = 0.0_wp
-             qc_p  = qc
-             tnc_m = 0.0_wp
-             nc_p  = nc
-          ENDIF
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
-             tqr_m = 0.0_wp
-             qr_p  = qr
-             tnr_m = 0.0_wp
-             nr_p  = nr
-          ENDIF
        ENDIF
        
@@ -1963,12 +1807,4 @@
        IF ( humidity )  THEN
           q_p = q
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
-             qc_p = qc
-             nc_p = nc
-          ENDIF
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
-             qr_p = qr
-             nr_p = nr
-          ENDIF
        ENDIF
        IF ( passive_scalar )  s_p  = s
@@ -1982,12 +1818,4 @@
        IF ( humidity )  THEN
           tq_m = 0.0_wp
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
-             tqc_m = 0.0_wp
-             tnc_m = 0.0_wp
-          ENDIF
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
-             tqr_m = 0.0_wp
-             tnr_m = 0.0_wp
-          ENDIF
        ENDIF
        IF ( passive_scalar )  ts_m  = 0.0_wp
@@ -2417,14 +2245,41 @@
        CALL init_ocean
 
-    ELSE
+    ENDIF
 !
 !--    Initialize quantities for handling cloud physics
 !--    This routine must be called before lpm_init, because
-!--    otherwise, array pt_d_t, needed in data_output_dvrp (called by
+!--    otherwise, array d_exner, needed in data_output_dvrp (called by
 !--    lpm_init) is not defined.
-       CALL init_cloud_physics
-!
-!--    Initialize bulk cloud microphysics
-       CALL microphysics_init
+    IF ( .NOT. ocean )  THEN
+
+       ALLOCATE( hyp(nzb:nzt+1) )
+       ALLOCATE( d_exner(nzb:nzt+1) )
+       ALLOCATE( exner(nzb:nzt+1) )
+       ALLOCATE( hyrho(nzb:nzt+1) )
+!
+!--    Check temperature in case of too large domain height
+       DO  k = nzb, nzt+1
+          IF ( ( pt_surface * exner_function(surface_pressure * 100.0_wp) - g/c_p * zu(k) ) < 0.0_wp )  THEN
+             WRITE( message_string, * )  'absolute temperature < 0.0 at zu(', k, &
+                                         ') = ', zu(k)
+             CALL message( 'init_bulk_cloud_model', 'PA0142', 1, 2, 0, 6, 0 )
+          ENDIF
+       ENDDO
+
+!
+!--    Calculate vertical profile of the hydrostatic pressure (hyp)
+       hyp    = barometric_formula(zu, pt_surface * exner_function(surface_pressure * 100.0_wp), surface_pressure * 100.0_wp)
+       d_exner = exner_function_invers(hyp)
+       exner = 1.0_wp / exner_function_invers(hyp)
+       hyrho  = ideal_gas_law_rho_pt(hyp, pt_init)
+!
+!--    Compute reference density
+       rho_surface = ideal_gas_law_rho(surface_pressure * 100.0_wp, pt_surface * exner_function(surface_pressure * 100.0_wp))
+
+    ENDIF
+!
+!-- If required, initialize quantities needed for the microphysics module
+    IF ( bulk_cloud_model )  THEN
+       CALL bcm_init
     ENDIF
 
Index: lm/trunk/SOURCE/init_cloud_physics.f90
===================================================================
--- /palm/trunk/SOURCE/init_cloud_physics.f90	(revision 3273)
+++ 	(revision )
@@ -1,154 +1,0 @@
-!> @file init_cloud_physics.f90
-!------------------------------------------------------------------------------!
-! This file is part of the PALM model system.
-!
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
-!
-! Copyright 1997-2018 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
-!
-! Current revisions:
-! -----------------
-! 
-! 
-! Former revisions:
-! ------------------
-! $Id$
-! unused variables removed
-! 
-! 2718 2018-01-02 08:49:38Z maronga
-! Corrected "Former revisions" section
-! 
-! 2696 2017-12-14 17:12:51Z kanani
-! Change in file header (GPL part)
-!
-! 2101 2017-01-05 16:42:31Z suehring
-!
-! 2000 2016-08-20 18:09:15Z knoop
-! Forced header and separation lines into 80 columns
-! 
-! 1849 2016-04-08 11:33:18Z hoffmann
-! bfactor removed and microphysics constants moved microphysics_mod
-!
-! 1822 2016-04-07 07:49:42Z hoffmann
-! icloud_scheme replaced by microphysics_*
-!
-! 1691 2015-10-26 16:17:44Z maronga
-! Removed typo
-! 
-! 1682 2015-10-07 23:56:08Z knoop
-! Code annotations made doxygen readable 
-! 
-! 1361 2014-04-16 15:17:48Z hoffmann
-! sed_qc_const is now calculated here (2-moment microphysics)
-! 
-! 1353 2014-04-08 15:21:23Z heinze
-! REAL constants provided with KIND-attribute
-! 
-! 1334 2014-03-25 12:21:40Z heinze
-! Bugfix: REAL constants provided with KIND-attribute
-!
-! 1322 2014-03-20 16:38:49Z raasch
-! REAL constants defined as wp-kind
-! 
-! 1320 2014-03-20 08:40:49Z raasch
-! ONLY-attribute added to USE-statements,
-! kind-parameters added to all INTEGER and REAL declaration statements, 
-! kinds are defined in new module mod_kinds, 
-! revision history before 2012 removed,
-! comment fields (!:) to be used for variable explanations added to
-! all variable declaration statements 
-!
-! 1065 2012-11-22 17:42:36Z hoffmann
-! The Courant number of sedimentation can be controlled with c_sedimentation. 
-!
-! 1053 2012-11-13 17:11:03Z hoffmann
-! calculation of the maximum timestep according to the terminal velocity of rain 
-! drops in the two moment cloud scheme
-!
-! calculation of frequently used constants (pirho_l, dpirho_l, schmidt_p_1d3, 
-! hyrho) 
-!
-! 1036 2012-10-22 13:43:42Z raasch
-! code put under GPL (PALM 3.9)
-!
-! 824 2012-02-17 09:09:57Z raasch
-! calculation of b_cond replaced by calculation of bfactor
-!
-! Revision 1.1  2000/04/13 14:37:22  schroeter
-! Initial revision
-!
-!
-! Description:
-! ------------
-!> Initialization of parameters for handling cloud-physics
-!------------------------------------------------------------------------------!
- SUBROUTINE init_cloud_physics
- 
-
-    USE arrays_3d,                                                             &
-        ONLY:  hyp, pt_init, zu
-        
-    USE cloud_parameters,                                                      &
-        ONLY:  cp, hyrho, l_d_cp, l_d_r, l_d_rv, l_v, pt_d_t, r_d, r_v, t_d_pt
-                
-    USE control_parameters,                                                    &
-        ONLY:  g, message_string, pt_surface, rho_surface, surface_pressure
-    
-    USE indices,                                                               &
-        ONLY:  nzb, nzt
-    
-    USE kinds
-
-    IMPLICIT NONE
-
-    INTEGER(iwp) ::  k      !<
-    
-    REAL(wp) ::  t_surface  !<
-
-    ALLOCATE( hyp(nzb:nzt+1), pt_d_t(nzb:nzt+1), t_d_pt(nzb:nzt+1),            &
-              hyrho(nzb:nzt+1) )
-
-!
-!-- Calculate frequently used parameters
-    l_d_cp = l_v / cp
-    l_d_r  = l_v / r_d
-    l_d_rv = l_v / r_v
-
-!
-!-- Calculate:
-!-- pt / t : ratio of potential and actual temperature (pt_d_t)
-!-- t / pt : ratio of actual and potential temperature (t_d_pt)
-!-- p_0(z) : vertical profile of the hydrostatic pressure (hyp)
-    t_surface = pt_surface * ( surface_pressure / 1000.0_wp )**0.286_wp
-    DO  k = nzb, nzt+1
-!
-!--    Check temperature in case of too large domain height
-       IF ( ( t_surface - g/cp * zu(k) ) < 0.0_wp )  THEN
-          WRITE( message_string, * )  'absolute temperature < 0.0 at zu(', k, &
-                                      ') = ', zu(k)
-          CALL message( 'init_cloud_physics', 'PA0142', 1, 2, 0, 6, 0 )
-       ENDIF
-       hyp(k)    = surface_pressure * 100.0_wp * &
-                   ( (t_surface - g/cp * zu(k)) / t_surface )**(1.0_wp/0.286_wp)
-       pt_d_t(k) = ( 100000.0_wp / hyp(k) )**0.286_wp
-       t_d_pt(k) = 1.0_wp / pt_d_t(k)
-       hyrho(k)  = hyp(k) / ( r_d * t_d_pt(k) * pt_init(k) )       
-    ENDDO
-
-!
-!-- Compute reference density
-    rho_surface = surface_pressure * 100.0_wp / ( r_d * t_surface )
-
-
- END SUBROUTINE init_cloud_physics
Index: /palm/trunk/SOURCE/init_masks.f90
===================================================================
--- /palm/trunk/SOURCE/init_masks.f90	(revision 3273)
+++ /palm/trunk/SOURCE/init_masks.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3065 2018-06-12 07:03:02Z Giersch
 ! dz_stretch_level was replaced by dz_stretch_level_start
 ! 
@@ -134,5 +137,5 @@
 
     USE control_parameters,                                                    &
-        ONLY:  constant_diffusion, cloud_droplets, cloud_physics,              &
+        ONLY:  constant_diffusion, cloud_droplets,                             &
                data_output_masks, data_output_masks_user,                      &
                doav, doav_n, domask, domask_no, dz, dz_stretch_level_start,    &
@@ -142,7 +145,6 @@
                mask_x_loop, mask_xyz_dimension, mask_y, mask_y_loop, mask_z,   &
                mask_z_loop, max_masks,  message_string, mid,                   &
-               microphysics_morrison, microphysics_seifert, passive_scalar,    &
-               ocean, varnamelength
-               
+               passive_scalar, ocean, varnamelength
+
 
     USE grid_variables,                                                        &
@@ -153,4 +155,7 @@
 
     USE kinds
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
 
     USE netcdf_interface,                                                      &
@@ -309,7 +314,7 @@
 
              CASE ( 'lpt' )
-                IF ( .NOT. cloud_physics )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires cloud_physics = .TRUE.'
+                IF ( .NOT. bulk_cloud_model )  THEN
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
+                        '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -317,7 +322,7 @@
 
              CASE ( 'nc' )
-                IF ( .NOT. cloud_physics )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires cloud_physics = .TRUE.'
+                IF ( .NOT. bulk_cloud_model )  THEN
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
+                        '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
                  ELSEIF ( .NOT. microphysics_morrison ) THEN
@@ -329,7 +334,7 @@
 
              CASE ( 'nr' )
-                IF ( .NOT. cloud_physics )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires cloud_physics = .TRUE.'
+                IF ( .NOT. bulk_cloud_model )  THEN
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
+                        '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
                  ELSEIF ( .NOT. microphysics_seifert ) THEN
@@ -360,7 +365,7 @@
 
              CASE ( 'qc' )
-                IF ( .NOT. cloud_physics )  THEN
+                IF ( .NOT. bulk_cloud_model )  THEN
                    message_string = 'output of "' // TRIM( var ) // '"' //     &
-                            'requires cloud_physics = .TRUE.'
+                            'requires bulk_cloud_model = .TRUE.'
                    CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -368,8 +373,8 @@
 
              CASE ( 'ql' )
-                IF ( .NOT. ( cloud_physics  .OR.  cloud_droplets ) )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires cloud_physics = .TRUE. or cloud_droplets', &
-                        ' = .TRUE.'
+                IF ( .NOT. ( bulk_cloud_model  .OR.  cloud_droplets ) )  THEN
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
+                        '" requires bulk_cloud_model = .TRUE. or ',            &
+                        'cloud_droplets = .TRUE.'
                    CALL message( 'init_masks', 'PA0106', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -387,7 +392,7 @@
 
              CASE ( 'qv' )
-                IF ( .NOT. cloud_physics )  THEN
-                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
-                        '" requires cloud_physics = .TRUE.'
+                IF ( .NOT. bulk_cloud_model )  THEN
+                   WRITE ( message_string, * ) 'output of "', TRIM( var ),     &
+                        '" requires bulk_cloud_model = .TRUE.'
                    CALL message( 'init_masks', 'PA0108', 1, 2, 0, 6, 0 )
                 ENDIF
@@ -395,7 +400,7 @@
 
              CASE ( 'qr' )
-                IF ( .NOT. cloud_physics )  THEN
+                IF ( .NOT. bulk_cloud_model )  THEN
                    message_string = 'output of "' // TRIM( var ) // '" ' //    &
-                            'requires cloud_physics = .TRUE.'
+                            'requires bulk_cloud_model = .TRUE.'
                    CALL message( 'check_parameters', 'PA0108', 1, 2, 0, 6, 0 )
                 ELSEIF ( .NOT. microphysics_seifert ) THEN
Index: /palm/trunk/SOURCE/init_ocean.f90
===================================================================
--- /palm/trunk/SOURCE/init_ocean.f90	(revision 3273)
+++ /palm/trunk/SOURCE/init_ocean.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! ------------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3270 2018-09-24 06:28:20Z raasch
 ! bugfix for r2502: wrong calculation of hyp(nzt) in second iterative step
 ! 
@@ -90,6 +93,9 @@
         ONLY:  dzu, hyp, pt_init, ref_state, sa_init, zu, zw
 
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  g
+
     USE control_parameters,                                                    &
-        ONLY:  g, molecular_viscosity, prho_reference, rho_surface,            &
+        ONLY:  molecular_viscosity, prho_reference, rho_surface,               &
                rho_reference, surface_pressure, use_single_reference_value
 
Index: /palm/trunk/SOURCE/init_rankine.f90
===================================================================
--- /palm/trunk/SOURCE/init_rankine.f90	(revision 3273)
+++ /palm/trunk/SOURCE/init_rankine.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -73,5 +76,5 @@
         ONLY:  initializing_actions, n_sor, nsor, nsor_ini   
 
-    USE constants,                                                             &
+    USE basic_constants_and_equations_mod,                                     &
         ONLY:  pi
 
Index: /palm/trunk/SOURCE/init_slope.f90
===================================================================
--- /palm/trunk/SOURCE/init_slope.f90	(revision 3273)
+++ /palm/trunk/SOURCE/init_slope.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -72,5 +75,5 @@
         ONLY:  pt, pt_init, pt_slope_ref, zu
         
-    USE constants,                                                             &
+    USE basic_constants_and_equations_mod,                                     &
         ONLY:  pi
                     
Index: /palm/trunk/SOURCE/interaction_droplets_ptq.f90
===================================================================
--- /palm/trunk/SOURCE/interaction_droplets_ptq.f90	(revision 3273)
+++ /palm/trunk/SOURCE/interaction_droplets_ptq.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3040 2018-05-25 10:22:08Z schwenkel
 ! Changed the name specific humidity to mixing ratio
 ! 
@@ -74,5 +77,5 @@
 !
 ! 799 2011-12-21 17:48:03Z franke
-! Bugfix: pt_d_t(k) was missing in calculation of pt_p
+! Bugfix: d_exner(k) was missing in calculation of pt_p
 !
 ! RCS Log replace by Id keyword, revision history cleaned up
@@ -89,4 +92,17 @@
  MODULE interaction_droplets_ptq_mod
  
+
+    USE arrays_3d,                                                             &
+        ONLY:  pt_p, ql_c, q_p, d_exner
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  lv_d_cp
+
+    USE indices,                                                               &
+        ONLY:  nxl, nxr, nyn, nys, nzb, nzt, wall_flags_0
+
+    USE kinds
+
+    USE pegrid
 
     PRIVATE
@@ -111,17 +127,4 @@
     SUBROUTINE i_droplets_ptq
 
-       USE arrays_3d,                                                          &
-           ONLY:  pt_p, ql_c, q_p
-           
-       USE cloud_parameters,                                                   &
-           ONLY:  l_d_cp, pt_d_t
-           
-       USE indices,                                                            &
-           ONLY:  nxl, nxr, nyn, nys, nzb, nzt, wall_flags_0
-           
-       USE kinds
-
-       USE pegrid
-
        IMPLICIT NONE
 
@@ -140,5 +143,5 @@
 
                 q_p(k,j,i)  = q_p(k,j,i)  - ql_c(k,j,i) * flag
-                pt_p(k,j,i) = pt_p(k,j,i) + l_d_cp * ql_c(k,j,i) * pt_d_t(k)   &
+                pt_p(k,j,i) = pt_p(k,j,i) + lv_d_cp * ql_c(k,j,i) * d_exner(k) &
                                                         * flag
              ENDDO
@@ -155,18 +158,4 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE i_droplets_ptq_ij( i, j )
-
-       USE arrays_3d,                                                          &
-           ONLY:  pt_p, ql_c, q_p
-
-       USE cloud_parameters,                                                   &
-           ONLY:  l_d_cp, pt_d_t
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt, wall_flags_0
-
-       USE kinds,                                                              &
-           ONLY:  iwp, wp
-
-       USE pegrid
 
        IMPLICIT NONE
@@ -185,5 +174,5 @@
 
           q_p(k,j,i)  = q_p(k,j,i)  - ql_c(k,j,i) * flag
-          pt_p(k,j,i) = pt_p(k,j,i) + l_d_cp * ql_c(k,j,i) * pt_d_t(k) * flag
+          pt_p(k,j,i) = pt_p(k,j,i) + lv_d_cp * ql_c(k,j,i) * d_exner(k) * flag
        ENDDO
 
Index: /palm/trunk/SOURCE/land_surface_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3271 2018-09-24 08:20:34Z suehring
 ! Several bugfixes:
 ! - Initialization of pt_surface array with soil temperature in the uppermost
@@ -474,17 +477,17 @@
  
     USE arrays_3d,                                                             &
-        ONLY:  hyp, pt, prr, q, q_p, ql, vpt, u, v, w
+        ONLY:  hyp, pt, prr, q, q_p, ql, vpt, u, v, w, hyrho, exner, d_exner
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  c_p, g, lv_d_cp, l_v, magnus, rho_l, r_d, r_v
 
     USE calc_mean_profile_mod,                                                 &
         ONLY:  calc_mean_profile
 
-    USE cloud_parameters,                                                      &
-        ONLY:  cp, hyrho, l_d_cp, l_d_r, l_v, pt_d_t, rho_l, r_d, r_v
-
     USE control_parameters,                                                    &
-        ONLY:  cloud_droplets, cloud_physics, coupling_start_time, dt_3d,      &
+        ONLY:  cloud_droplets, coupling_start_time, dt_3d,      &
                end_time, humidity, intermediate_timestep_count,                &
                initializing_actions, intermediate_timestep_count_max,          &
-               land_surface, max_masks, precipitation, pt_surface,             &
+               land_surface, max_masks, pt_surface,             &
                rho_surface, spinup, spinup_pt_mean, spinup_time,               &
                surface_pressure, timestep_scheme, tsc,                         &
@@ -493,4 +496,7 @@
     USE indices,                                                               &
         ONLY:  nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY: bulk_cloud_model, precipitation
 
     USE netcdf_data_input_mod,                                                 &
@@ -584,5 +590,4 @@
                 deep_soil_temperature =  9999999.9_wp,  & !< Deep soil temperature (bottom boundary condition)
                 drho_l_lv,                              & !< (rho_l * l_v)**-1
-                exn,                                    & !< value of the Exner function
                 field_capacity = 9999999.9_wp,          & !< NAMELIST m_fc
                 f_shortwave_incoming = 9999999.9_wp,    & !< NAMELIST f_sw_in
@@ -604,5 +609,4 @@
                 rho_cp,                                 & !< rho_surface * cp
                 rho_lv,                                 & !< rho_ocean * l_v
-                rd_d_rv,                                & !< r_d / r_v
                 saturation_moisture = 9999999.9_wp,     & !< NAMELIST m_sat
                 skip_time_do_lsm = 0.0_wp,              & !< LSM is not called before this time
@@ -1734,7 +1738,4 @@
  SUBROUTINE lsm_energy_balance( horizontal, l )
 
-    USE diagnostic_quantities_mod,                                             &
-        ONLY:  magnus 
-
     USE pegrid
 
@@ -1816,8 +1817,4 @@
     j_off = surf%joff
     i_off = surf%ioff
-    
-!
-!-- Calculate the exner function for the current time step
-    exn = ( surface_pressure / 1000.0_wp )**0.286_wp
 
     DO  m = 1, surf%ns
@@ -1889,9 +1886,9 @@
 !--    time step is used here. Note that this formulation is the
 !--    equivalent to the ECMWF formulation using drag coefficients
-!        IF ( cloud_physics )  THEN
-!           pt1 = pt(k,j,i) + l_d_cp * pt_d_t(k) * ql(k,j,i)
+!        IF ( bulk_cloud_model )  THEN
+!           pt1 = pt(k,j,i) + lv_d_cp * d_exner(k) * ql(k,j,i)
 !           qv1 = q(k,j,i) - ql(k,j,i)
 !        ELSEIF ( cloud_droplets ) THEN
-!           pt1 = pt(k,j,i) + l_d_cp * pt_d_t(k) * ql(k,j,i)
+!           pt1 = pt(k,j,i) + lv_d_cp * d_exner(k) * ql(k,j,i)
 !           qv1 = q(k,j,i) 
 !        ELSE
@@ -2097,5 +2094,5 @@
 !--       Denominator of the prognostic equation
           coef_2 = surf%rad_lw_out_change_0(m) + f_qsws * dq_s_dt              &
-                   + lambda_surface + f_shf / exn
+                   + lambda_surface + f_shf / exner(nzb)
        ELSE
 !
@@ -2107,5 +2104,5 @@
 !
 !--       Denominator of the prognostic equation
-          coef_2 = surf%rad_lw_out_change_0(m) + lambda_surface + f_shf / exn
+          coef_2 = surf%rad_lw_out_change_0(m) + lambda_surface + f_shf / exner(nzb)
 
        ENDIF
@@ -2160,6 +2157,6 @@
 
 
-!        pt(k+k_off,j+j_off,i+i_off) = surf_t_surface_p%var_1d(m) / exn  !is actually no air temperature
-       surf%pt_surface(m)          = surf_t_surface_p%var_1d(m) / exn
+!        pt(k+k_off,j+j_off,i+i_off) = surf_t_surface_p%var_1d(m) / exner(nzb)  !is actually no air temperature
+       surf%pt_surface(m)          = surf_t_surface_p%var_1d(m) / exner(nzb)
 
 !
@@ -2177,5 +2174,5 @@
                                              - surf_t_soil%var_2d(nzb_soil,m) )
 
-       surf%shf(m) = - f_shf * ( surf%pt1(m) - surf%pt_surface(m) ) / cp
+       surf%shf(m) = - f_shf * ( surf%pt1(m) - surf%pt_surface(m) ) / c_p
 
        IF ( humidity )  THEN
@@ -2330,9 +2327,9 @@
     SUBROUTINE calc_q_surface
 
-       USE diagnostic_quantities_mod
-
        IMPLICIT NONE
 
-       REAL(wp) :: resistance    !< aerodynamic and soil resistance term
+       REAL(wp) ::  e_s           !< saturation water vapor pressure
+       REAL(wp) ::  q_s           !< saturation mixing ratio
+       REAL(wp) ::  resistance    !< aerodynamic and soil resistance term
 
        DO  m = 1, surf%ns
@@ -2353,5 +2350,5 @@
 !
 !--       Calculate mixing ratio at surface
-          IF ( cloud_physics )  THEN
+          IF ( bulk_cloud_model )  THEN
              q(k+k_off,j+j_off,i+i_off) = resistance * q_s +                   &
                                         ( 1.0_wp - resistance ) *              &
@@ -2471,5 +2468,5 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE lsm_init
-    
+
        USE control_parameters,                                                 &
            ONLY:  message_string
@@ -2501,19 +2498,14 @@
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  bound, bound_root_fr  !< temporary arrays for storing index bounds
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  pr_soil_init !< temporary array used for averaging soil profiles
-
-!
-!--    Calculate Exner function
-       exn = ( surface_pressure / 1000.0_wp )**0.286_wp
 !
 !--    If no cloud physics is used, rho_surface has not been calculated before
-       IF (  .NOT.  cloud_physics  .AND.  .NOT.  cloud_droplets )  THEN
+       IF (  .NOT.  bulk_cloud_model  .AND.  .NOT.  cloud_droplets )  THEN
           CALL calc_mean_profile( pt, 4 )
-          rho_surface = surface_pressure * 100.0_wp / ( r_d * hom(topo_min_level+1,1,4,0) * exn )
+          rho_surface = hyp(nzb) / ( r_d * hom(topo_min_level+1,1,4,0) * exner(nzb) )
        ENDIF
 
 !
 !--    Calculate frequently used parameters
-       rho_cp    = cp * rho_surface
-       rd_d_rv   = r_d / r_v
+       rho_cp    = c_p * rho_surface
        rho_lv    = rho_surface * l_v
        drho_l_lv = 1.0_wp / (rho_l * l_v)
@@ -4451,8 +4443,8 @@
 !--          uppermost layer
              t_surface_h%var_1d(m)    = t_soil_h%var_2d(nzb_soil,m)
-             surf_lsm_h%pt_surface(m) = t_soil_h%var_2d(nzb_soil,m) / exn
+             surf_lsm_h%pt_surface(m) = t_soil_h%var_2d(nzb_soil,m) / exner(nzb)
              
-             IF ( cloud_physics  .OR. cloud_droplets ) THEN
-                surf_lsm_h%pt1(m) = pt(k,j,i) + l_d_cp * pt_d_t(k) * ql(k,j,i)
+             IF ( bulk_cloud_model  .OR. cloud_droplets ) THEN
+                surf_lsm_h%pt1(m) = pt(k,j,i) + lv_d_cp * d_exner(k) * ql(k,j,i)
              ELSE
                 surf_lsm_h%pt1(m) = pt(k,j,i)
@@ -4480,8 +4472,8 @@
 !--             uppermost layer
                 t_surface_v(l)%var_1d(m)      = t_soil_v(l)%var_2d(nzb_soil,m)
-                surf_lsm_v(l)%pt_surface(m)   = t_soil_v(l)%var_2d(nzb_soil,m) / exn
-
-                IF ( cloud_physics  .OR. cloud_droplets ) THEN
-                   surf_lsm_v(l)%pt1(m) = pt(k,j,i) + l_d_cp * pt_d_t(k) * ql(k,j,i)
+                surf_lsm_v(l)%pt_surface(m)   = t_soil_v(l)%var_2d(nzb_soil,m) / exner(nzb)
+
+                IF ( bulk_cloud_model  .OR. cloud_droplets ) THEN
+                   surf_lsm_v(l)%pt1(m) = pt(k,j,i) + lv_d_cp * d_exner(k) * ql(k,j,i)
                 ELSE
                    surf_lsm_v(l)%pt1(m) = pt(k,j,i)
@@ -7078,5 +7070,5 @@
 
        USE control_parameters,                                                 &
-           ONLY: g, message_string, molecular_viscosity
+           ONLY: message_string, molecular_viscosity
 
        IMPLICIT NONE
Index: /palm/trunk/SOURCE/lpm_advec.f90
===================================================================
--- /palm/trunk/SOURCE/lpm_advec.f90	(revision 3273)
+++ /palm/trunk/SOURCE/lpm_advec.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -173,4 +176,7 @@
         ONLY:  de_dx, de_dy, de_dz, diss, dzw, e, km, u, v, w, zu, zw
 
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  g, kappa
+
     USE cpulog
 
@@ -179,5 +185,5 @@
     USE control_parameters,                                                    &
         ONLY:  cloud_droplets, constant_flux_layer, dt_3d, dt_3d_reached_l,    &
-               dz, g, kappa, topography, u_gtrans, v_gtrans
+               dz, topography, u_gtrans, v_gtrans
 
     USE grid_variables,                                                        &
Index: /palm/trunk/SOURCE/lpm_calc_liquid_water_content.f90
===================================================================
--- /palm/trunk/SOURCE/lpm_calc_liquid_water_content.f90	(revision 3273)
+++ /palm/trunk/SOURCE/lpm_calc_liquid_water_content.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -75,9 +78,6 @@
         ONLY:  dzw, ql, ql_v, ql_vp
 
-    USE cloud_parameters,                                                      &
-        ONLY:  rho_l
-
-    USE constants,                                                             &
-        ONLY:  pi
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  pi, rho_l
 
     USE control_parameters,                                                    &
Index: /palm/trunk/SOURCE/lpm_collision_kernels.f90
===================================================================
--- /palm/trunk/SOURCE/lpm_collision_kernels.f90	(revision 3273)
+++ /palm/trunk/SOURCE/lpm_collision_kernels.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -135,6 +138,6 @@
  
 
-    USE constants,                                                             &
-        ONLY:  pi
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  g, pi
         
     USE kinds
@@ -404,5 +407,5 @@
 
        USE control_parameters,                                                 &
-           ONLY:  g, molecular_viscosity
+           ONLY:  molecular_viscosity
     
        USE particle_attributes,                                                &
Index: /palm/trunk/SOURCE/lpm_droplet_collision.f90
===================================================================
--- /palm/trunk/SOURCE/lpm_droplet_collision.f90	(revision 3273)
+++ /palm/trunk/SOURCE/lpm_droplet_collision.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -122,9 +125,6 @@
         ONLY:  diss, dzw, ql_v, ql_vp
 
-    USE cloud_parameters,                                                      &
-        ONLY:  rho_l, rho_s
-
-    USE constants,                                                             &
-        ONLY:  pi
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  pi, rho_l, rho_s
 
     USE control_parameters,                                                    &
Index: /palm/trunk/SOURCE/lpm_droplet_condensation.f90
===================================================================
--- /palm/trunk/SOURCE/lpm_droplet_condensation.f90	(revision 3273)
+++ /palm/trunk/SOURCE/lpm_droplet_condensation.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -136,12 +139,9 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  dzw, hyp, pt, q, ql_c, ql_v
-
-    USE cloud_parameters,                                                      &
-        ONLY:  l_v, molecular_weight_of_solute,                        &
-               molecular_weight_of_water, rho_l, rho_s, r_v, vanthoff
-
-    USE constants,                                                             &
-        ONLY:  pi
+        ONLY:  dzw, hyp, pt, q, ql_c, ql_v, exner
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  l_v, molecular_weight_of_solute, molecular_weight_of_water,     &
+               magnus, pi, rho_l, rho_s, r_v, vanthoff
 
     USE control_parameters,                                                    &
@@ -150,7 +150,4 @@
     USE cpulog,                                                                &
         ONLY:  cpu_log, log_point_s
-
-    USE diagnostic_quantities_mod,                                             &
-        ONLY:  magnus
 
     USE grid_variables,                                                        &
@@ -220,5 +217,5 @@
 !
 !-- Absolute temperature
-    t_int = pt(kp,jp,ip) * ( hyp(kp) / 100000.0_wp )**0.286_wp
+    t_int = pt(kp,jp,ip) * exner(kp)
 !
 !-- Saturation vapor pressure (Eq. 10 in Bolton, 1980)
Index: /palm/trunk/SOURCE/lpm_init.f90
===================================================================
--- /palm/trunk/SOURCE/lpm_init.f90	(revision 3273)
+++ /palm/trunk/SOURCE/lpm_init.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -1051,16 +1054,9 @@
 
     USE arrays_3d,                                                             &
-        ONLY: hyp, pt, q
-
-    USE cloud_parameters,                                                      &
-        ONLY: molecular_weight_of_solute, molecular_weight_of_water, rho_l,    &
-              r_v, rho_s, vanthoff
-
-    USE constants,                                                             &
-        ONLY: pi
-
-    USE diagnostic_quantities_mod,                                             &
-        ONLY:  magnus
-
+        ONLY: hyp, pt, q, exner
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY: molecular_weight_of_solute, molecular_weight_of_water, magnus,   &
+              pi, rho_l, r_v, rho_s, vanthoff
 
     USE kinds
@@ -1199,5 +1195,5 @@
 !--          the sometimes lengthy growth toward their equilibrium radius within
 !--          the simulation.
-             t_int  = pt(kp,jp,ip) * ( hyp(kp) / 100000.0_wp )**0.286_wp
+             t_int  = pt(kp,jp,ip) * exner(kp)
 
              e_s = magnus( t_int )
Index: /palm/trunk/SOURCE/lpm_splitting.f90
===================================================================
--- /palm/trunk/SOURCE/lpm_splitting.f90	(revision 3273)
+++ /palm/trunk/SOURCE/lpm_splitting.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -61,9 +64,6 @@
         ONLY:  ql
 
-    USE cloud_parameters,                                                      &
-        ONLY:  rho_l
-
-    USE constants,                                                             &
-        ONLY:  pi
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  pi, rho_l
 
     USE cpulog,                                                                &
Index: lm/trunk/SOURCE/microphysics_mod.f90
===================================================================
--- /palm/trunk/SOURCE/microphysics_mod.f90	(revision 3273)
+++ 	(revision )
@@ -1,3086 +1,0 @@
-!> @file microphysics_mod.f90
-!------------------------------------------------------------------------------!
-! This file is part of the PALM model system.
-!
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
-!
-! Copyright 1997-2018 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
-!
-! Current revisions:
-! ------------------
-! 
-! 
-! Former revisions:
-! -----------------
-! $Id$
-! unused variables removed
-! 
-! 3026 2018-05-22 10:30:53Z schwenkel
-! Changed the name specific humidity to mixing ratio, since we are computing
-! mixing ratios.
-! 
-! 2718 2018-01-02 08:49:38Z maronga
-! Corrected "Former revisions" section
-! 
-! 2701 2017-12-15 15:40:50Z suehring
-! Changes from last commit documented
-! 
-! 2698 2017-12-14 18:46:24Z suehring
-! Bugfix in get_topography_top_index
-!
-! 2696 2017-12-14 17:12:51Z kanani
-! Change in file header (GPL part)
-!
-! 2608 2017-11-13 14:04:26Z schwenkel
-! Calculation of supersaturation in external module (diagnostic_quantities_mod).
-! Change: correct calculation of saturation specific humidity to saturation
-! mixing ratio (the factor of 0.378 vanishes).
-! 
-! 2522 2017-10-05 14:20:37Z schwenkel
-! Minor bugfix
-! 
-! 2375 2017-08-29 14:10:28Z schwenkel
-! Improved aerosol initilization and some minor bugfixes 
-! for droplet sedimenation
-! 
-! 2318 2017-07-20 17:27:44Z suehring
-! Get topography top index via Function call 
-!
-! 2317 2017-07-20 17:27:19Z suehring
-! s1 changed to log_sigma
-!
-! 2292 2017-06-20 09:51:42Z schwenkel
-! Implementation of new microphysic scheme: cloud_scheme = 'morrison'
-! includes two more prognostic equations for cloud drop concentration (nc)
-! and cloud water content (qc).
-! - The process of activation is parameterized with a simple Twomey
-!   activion scheme or with considering solution and curvature
-!   effects (Khvorostyanov and Curry ,2006).
-! - The saturation adjustment scheme is replaced by the parameterization
-!   of condensation rates (Khairoutdinov and Kogan, 2000, Mon. Wea. Rev.,128).
-! - All other microphysical processes of Seifert and Beheng are used.
-!   Additionally, in those processes the reduction of cloud number concentration
-!   is considered.
-!
-! 2233 2017-05-30 18:08:54Z suehring
-!
-! 2232 2017-05-30 17:47:52Z suehring
-! Adjustments to new topography and surface concept
-!
-! 2155 2017-02-21 09:57:40Z hoffmann
-! Bugfix in the calculation of microphysical quantities on ghost points.
-!
-! 2031 2016-10-21 15:11:58Z knoop
-! renamed variable rho to rho_ocean
-!
-! 2000 2016-08-20 18:09:15Z knoop
-! Forced header and separation lines into 80 columns
-!
-! 1850 2016-04-08 13:29:27Z maronga
-! Module renamed
-! Adapted for modularization of microphysics.
-!
-! 1845 2016-04-08 08:29:13Z raasch
-! nzb_2d replaced by nzb_s_inner, Kessler precipitation is stored at surface
-! point (instead of one point above surface)
-!
-! 1831 2016-04-07 13:15:51Z hoffmann
-! turbulence renamed collision_turbulence,
-! drizzle renamed cloud_water_sedimentation. cloud_water_sedimentation also
-! avaialble for microphysics_kessler.
-!
-! 1822 2016-04-07 07:49:42Z hoffmann
-! Unused variables removed.
-! Kessler scheme integrated.
-!
-! 1691 2015-10-26 16:17:44Z maronga
-! Added new routine calc_precipitation_amount. The routine now allows to account
-! for precipitation due to sedimenation of cloud (fog) droplets
-!
-! 1682 2015-10-07 23:56:08Z knoop
-! Code annotations made doxygen readable
-!
-! 1646 2015-09-02 16:00:10Z hoffmann
-! Bugfix: Wrong computation of d_mean.
-!
-! 1361 2014-04-16 15:17:48Z hoffmann
-! Bugfix in sedimentation_rain: Index corrected.
-! Vectorized version of adjust_cloud added.
-! Little reformatting of the code.
-!
-! 1353 2014-04-08 15:21:23Z heinze
-! REAL constants provided with KIND-attribute
-!
-! 1346 2014-03-27 13:18:20Z heinze
-! Bugfix: REAL constants provided with KIND-attribute especially in call of
-! intrinsic function like MAX, MIN, SIGN
-!
-! 1334 2014-03-25 12:21:40Z heinze
-! Bugfix: REAL constants provided with KIND-attribute
-!
-! 1322 2014-03-20 16:38:49Z raasch
-! REAL constants defined as wp-kind
-!
-! 1320 2014-03-20 08:40:49Z raasch
-! ONLY-attribute added to USE-statements,
-! kind-parameters added to all INTEGER and REAL declaration statements,
-! kinds are defined in new module kinds,
-! comment fields (!:) to be used for variable explanations added to
-! all variable declaration statements
-!
-! 1241 2013-10-30 11:36:58Z heinze
-! hyp and rho_ocean have to be calculated at each time step if data from external
-! file LSF_DATA are used
-!
-! 1115 2013-03-26 18:16:16Z hoffmann
-! microphyical tendencies are calculated in microphysics_control in an optimized
-! way; unrealistic values are prevented; bugfix in evaporation; some reformatting
-!
-! 1106 2013-03-04 05:31:38Z raasch
-! small changes in code formatting
-!
-! 1092 2013-02-02 11:24:22Z raasch
-! unused variables removed
-! file put under GPL
-!
-! 1065 2012-11-22 17:42:36Z hoffmann
-! Sedimentation process implemented according to Stevens and Seifert (2008).
-! Turbulence effects on autoconversion and accretion added (Seifert, Nuijens
-! and Stevens, 2010).
-!
-! 1053 2012-11-13 17:11:03Z hoffmann
-! initial revision
-!
-! Description:
-! ------------
-!> Calculate bilk cloud microphysics.
-!------------------------------------------------------------------------------!
- MODULE microphysics_mod
-
-    USE  kinds
-
-    IMPLICIT NONE
-
-    LOGICAL ::  cloud_water_sedimentation = .FALSE.       !< cloud water sedimentation
-    LOGICAL ::  curvature_solution_effects_bulk = .FALSE. !< flag for considering koehler theory
-    LOGICAL ::  limiter_sedimentation = .TRUE.            !< sedimentation limiter
-    LOGICAL ::  collision_turbulence = .FALSE.            !< turbulence effects
-    LOGICAL ::  ventilation_effect = .TRUE.               !< ventilation effect
-
-    REAL(wp) ::  a_1 = 8.69E-4_wp          !< coef. in turb. parametrization (cm-2 s3)
-    REAL(wp) ::  a_2 = -7.38E-5_wp         !< coef. in turb. parametrization (cm-2 s3)
-    REAL(wp) ::  a_3 = -1.40E-2_wp         !< coef. in turb. parametrization
-    REAL(wp) ::  a_term = 9.65_wp          !< coef. for terminal velocity (m s-1)
-    REAL(wp) ::  a_vent = 0.78_wp          !< coef. for ventilation effect
-    REAL(wp) ::  b_1 = 11.45E-6_wp         !< coef. in turb. parametrization (m)
-    REAL(wp) ::  b_2 = 9.68E-6_wp          !< coef. in turb. parametrization (m)
-    REAL(wp) ::  b_3 = 0.62_wp             !< coef. in turb. parametrization
-    REAL(wp) ::  b_term = 9.8_wp           !< coef. for terminal velocity (m s-1)
-    REAL(wp) ::  b_vent = 0.308_wp         !< coef. for ventilation effect
-    REAL(wp) ::  beta_cc = 3.09E-4_wp      !< coef. in turb. parametrization (cm-2 s3)
-    REAL(wp) ::  c_1 = 4.82E-6_wp          !< coef. in turb. parametrization (m)
-    REAL(wp) ::  c_2 = 4.8E-6_wp           !< coef. in turb. parametrization (m)
-    REAL(wp) ::  c_3 = 0.76_wp             !< coef. in turb. parametrization
-    REAL(wp) ::  c_const = 0.93_wp         !< const. in Taylor-microscale Reynolds number
-    REAL(wp) ::  c_evap = 0.7_wp           !< constant in evaporation
-    REAL(wp) ::  c_term = 600.0_wp         !< coef. for terminal velocity (m-1)
-    REAL(wp) ::  diff_coeff_l = 0.23E-4_wp  !< diffusivity of water vapor (m2 s-1)
-    REAL(wp) ::  eps_sb = 1.0E-10_wp       !< threshold in two-moments scheme
-    REAL(wp) ::  eps_mr = 0.0_wp           !< threshold for morrison scheme
-    REAL(wp) ::  k_cc = 9.44E09_wp         !< const. cloud-cloud kernel (m3 kg-2 s-1)
-    REAL(wp) ::  k_cr0 = 4.33_wp           !< const. cloud-rain kernel (m3 kg-1 s-1)
-    REAL(wp) ::  k_rr = 7.12_wp            !< const. rain-rain kernel (m3 kg-1 s-1)
-    REAL(wp) ::  k_br = 1000.0_wp          !< const. in breakup parametrization (m-1)
-    REAL(wp) ::  k_st = 1.2E8_wp           !< const. in drizzle parametrization (m-1 s-1)
-    REAL(wp) ::  kin_vis_air = 1.4086E-5_wp  !< kin. viscosity of air (m2 s-1)
-    REAL(wp) ::  prec_time_const = 0.001_wp  !< coef. in Kessler scheme (s-1)
-    REAL(wp) ::  ql_crit = 0.0005_wp       !< coef. in Kessler scheme (kg kg-1)
-    REAL(wp) ::  schmidt_p_1d3=0.8921121_wp  !< Schmidt number**0.33333, 0.71**0.33333
-    REAL(wp) ::  sigma_gc = 1.3_wp         !< geometric standard deviation cloud droplets
-    REAL(wp) ::  thermal_conductivity_l = 2.43E-2_wp  !< therm. cond. air (J m-1 s-1 K-1)
-    REAL(wp) ::  w_precipitation = 9.65_wp  !< maximum terminal velocity (m s-1)
-    REAL(wp) ::  x0 = 2.6E-10_wp           !< separating drop mass (kg)
-    REAL(wp) ::  xamin = 5.24E-19_wp       !< average aerosol mass (kg) (~ 0.05Âµm)
-    REAL(wp) ::  xcmin = 4.18E-15_wp       !< minimum cloud drop size (kg) (~ 1Âµm)
-    REAL(wp) ::  xrmin = 2.6E-10_wp        !< minimum rain drop size (kg)
-    REAL(wp) ::  xrmax = 5.0E-6_wp         !< maximum rain drop site (kg)
-
-    REAL(wp) ::  c_sedimentation = 2.0_wp        !< Courant number of sedimentation process
-    REAL(wp) ::  dpirho_l                        !< 6.0 / ( pi * rho_l )
-    REAL(wp) ::  dry_aerosol_radius = 0.05E-6_wp !< dry aerosol radius
-    REAL(wp) ::  dt_micro                        !< microphysics time step
-    REAL(wp) ::  sigma_bulk = 2.0_wp             !< width of aerosol spectrum
-    REAL(wp) ::  na_init = 100.0E6_wp            !< Total particle/aerosol concentration (cm-3)
-    REAL(wp) ::  nc_const = 70.0E6_wp            !< cloud droplet concentration
-    REAL(wp) ::  dt_precipitation = 100.0_wp     !< timestep precipitation (s)
-    REAL(wp) ::  sed_qc_const                    !< const. for sedimentation of cloud water
-    REAL(wp) ::  pirho_l                         !< pi * rho_l / 6.0;
-
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  nc_1d  !<
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  nr_1d  !<
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  pt_1d  !<
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  qc_1d  !<
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  qr_1d  !<
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  q_1d   !<
-
-    SAVE
-
-    PRIVATE
-    PUBLIC microphysics_control, microphysics_init
-
-    PUBLIC cloud_water_sedimentation, collision_turbulence,                    &
-           curvature_solution_effects_bulk, c_sedimentation,                   &
-           dry_aerosol_radius, dt_precipitation,                               &
-           limiter_sedimentation, na_init, nc_const, sigma_gc, sigma_bulk,     &
-           ventilation_effect
-
-
-    INTERFACE microphysics_control
-       MODULE PROCEDURE microphysics_control
-       MODULE PROCEDURE microphysics_control_ij
-    END INTERFACE microphysics_control
-
-    INTERFACE adjust_cloud
-       MODULE PROCEDURE adjust_cloud
-       MODULE PROCEDURE adjust_cloud_ij
-    END INTERFACE adjust_cloud
-
-    INTERFACE activation
-       MODULE PROCEDURE activation
-       MODULE PROCEDURE activation_ij
-    END INTERFACE activation
-
-    INTERFACE condensation
-       MODULE PROCEDURE condensation
-       MODULE PROCEDURE condensation_ij
-    END INTERFACE condensation
-
-    INTERFACE autoconversion
-       MODULE PROCEDURE autoconversion
-       MODULE PROCEDURE autoconversion_ij
-    END INTERFACE autoconversion
-
-    INTERFACE autoconversion_kessler
-       MODULE PROCEDURE autoconversion_kessler
-       MODULE PROCEDURE autoconversion_kessler_ij
-    END INTERFACE autoconversion_kessler
-
-    INTERFACE accretion
-       MODULE PROCEDURE accretion
-       MODULE PROCEDURE accretion_ij
-    END INTERFACE accretion
-
-    INTERFACE selfcollection_breakup
-       MODULE PROCEDURE selfcollection_breakup
-       MODULE PROCEDURE selfcollection_breakup_ij
-    END INTERFACE selfcollection_breakup
-
-    INTERFACE evaporation_rain
-       MODULE PROCEDURE evaporation_rain
-       MODULE PROCEDURE evaporation_rain_ij
-    END INTERFACE evaporation_rain
-
-    INTERFACE sedimentation_cloud
-       MODULE PROCEDURE sedimentation_cloud
-       MODULE PROCEDURE sedimentation_cloud_ij
-    END INTERFACE sedimentation_cloud
-
-    INTERFACE sedimentation_rain
-       MODULE PROCEDURE sedimentation_rain
-       MODULE PROCEDURE sedimentation_rain_ij
-    END INTERFACE sedimentation_rain
-
-    INTERFACE calc_precipitation_amount
-       MODULE PROCEDURE calc_precipitation_amount
-       MODULE PROCEDURE calc_precipitation_amount_ij
-    END INTERFACE calc_precipitation_amount
-
- CONTAINS
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Initialization of bulk microphysics
-!------------------------------------------------------------------------------!
-    SUBROUTINE microphysics_init
-
-       USE arrays_3d,                                                          &
-           ONLY:  dzu
-
-       USE constants,                                                          &
-           ONLY:  pi
-
-       USE cloud_parameters,                                                   &
-           ONLY:  molecular_weight_of_solute, rho_l, rho_s, vanthoff
-
-       USE control_parameters,                                                 &
-           ONLY:  aerosol_nacl, aerosol_c3h4o4 , aerosol_nh4no3,               &
-                  microphysics_morrison, microphysics_seifert
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt
-
-       IMPLICIT NONE
-
-!
-!--    constant for the sedimentation of cloud water (2-moment cloud physics)
-       sed_qc_const = k_st * ( 3.0_wp / ( 4.0_wp * pi * rho_l )                &
-                          )**( 2.0_wp / 3.0_wp ) *                             &
-                      EXP( 5.0_wp * LOG( sigma_gc )**2 )
-
-!
-!--    Calculate timestep according to precipitation
-       IF ( microphysics_seifert )  THEN
-          dt_precipitation = c_sedimentation * MINVAL( dzu(nzb+2:nzt) ) /      &
-                             w_precipitation
-       ENDIF
-
-!
-!--    Set constants for certain aerosol type
-       IF ( microphysics_morrison )  THEN
-          IF ( aerosol_nacl ) THEN
-             molecular_weight_of_solute = 0.05844_wp 
-             rho_s                      = 2165.0_wp
-             vanthoff                   = 2.0_wp
-          ELSEIF ( aerosol_c3h4o4 ) THEN
-             molecular_weight_of_solute = 0.10406_wp 
-             rho_s                      = 1600.0_wp
-             vanthoff                   = 1.37_wp
-          ELSEIF ( aerosol_nh4no3 ) THEN
-             molecular_weight_of_solute = 0.08004_wp 
-             rho_s                      = 1720.0_wp
-             vanthoff                   = 2.31_wp
-          ENDIF
-       ENDIF
- 
-!
-!--    Pre-calculate frequently calculated fractions of pi and rho_l
-       pirho_l  = pi * rho_l / 6.0_wp
-       dpirho_l = 1.0_wp / pirho_l
-
-!
-!--    Allocate 1D microphysics arrays
-       ALLOCATE ( pt_1d(nzb:nzt+1), q_1d(nzb:nzt+1),         &
-                  qc_1d(nzb:nzt+1) )
-
-       IF ( microphysics_morrison .OR. microphysics_seifert ) THEN
-          ALLOCATE ( nc_1d(nzb:nzt+1) )
-       ENDIF
-
-       IF ( microphysics_seifert )  THEN
-          ALLOCATE ( nr_1d(nzb:nzt+1), qr_1d(nzb:nzt+1) )
-       ENDIF
-
-    END SUBROUTINE microphysics_init
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Control of microphysics for all grid points
-!------------------------------------------------------------------------------!
-    SUBROUTINE microphysics_control
-
-       USE arrays_3d,                                                          &
-           ONLY:  hyp, pt_init, prr, zu
-
-       USE cloud_parameters,                                                   &
-           ONLY:  cp, hyrho, pt_d_t, r_d, t_d_pt
-
-       USE control_parameters,                                                 &
-           ONLY:  call_microphysics_at_all_substeps, dt_3d, g,                 &
-                  intermediate_timestep_count, large_scale_forcing,            &
-                  lsf_surf, microphysics_kessler, microphysics_morrison,       &
-                  microphysics_seifert, pt_surface,                            &
-                  rho_surface,surface_pressure
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt
-
-       USE kinds
-
-       USE statistics,                                                         &
-           ONLY:  weight_pres
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  t_surface         !<
-
-       IF ( large_scale_forcing  .AND.  lsf_surf ) THEN
-!
-!--       Calculate:
-!--       pt / t : ratio of potential and actual temperature (pt_d_t)
-!--       t / pt : ratio of actual and potential temperature (t_d_pt)
-!--       p_0(z) : vertical profile of the hydrostatic pressure (hyp)
-          t_surface = pt_surface * ( surface_pressure / 1000.0_wp )**0.286_wp
-          DO  k = nzb, nzt+1
-             hyp(k)    = surface_pressure * 100.0_wp * &
-                         ( ( t_surface - g / cp * zu(k) ) /                    &
-                         t_surface )**(1.0_wp / 0.286_wp)
-             pt_d_t(k) = ( 100000.0_wp / hyp(k) )**0.286_wp
-             t_d_pt(k) = 1.0_wp / pt_d_t(k)
-             hyrho(k)  = hyp(k) / ( r_d * t_d_pt(k) * pt_init(k) )
-          ENDDO
-
-!
-!--       Compute reference density
-          rho_surface = surface_pressure * 100.0_wp / ( r_d * t_surface )
-       ENDIF
-
-!
-!--    Compute length of time step
-       IF ( call_microphysics_at_all_substeps )  THEN
-          dt_micro = dt_3d * weight_pres(intermediate_timestep_count)
-       ELSE
-          dt_micro = dt_3d
-       ENDIF
-
-!
-!--    Reset precipitation rate
-       IF ( intermediate_timestep_count == 1 )  prr = 0.0_wp
-
-!
-!--    Compute cloud physics
-       IF ( microphysics_kessler )  THEN
-
-          CALL autoconversion_kessler
-          IF ( cloud_water_sedimentation )  CALL sedimentation_cloud
-
-       ELSEIF ( microphysics_seifert )  THEN
-
-          CALL adjust_cloud
-          IF ( microphysics_morrison )  CALL activation
-          IF ( microphysics_morrison )  CALL condensation
-          CALL autoconversion
-          CALL accretion
-          CALL selfcollection_breakup
-          CALL evaporation_rain
-          CALL sedimentation_rain
-          IF ( cloud_water_sedimentation )  CALL sedimentation_cloud
-
-       ENDIF
-
-       CALL calc_precipitation_amount
-
-    END SUBROUTINE microphysics_control
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Adjust number of raindrops to avoid nonlinear effects in sedimentation and
-!> evaporation of rain drops due to too small or too big weights
-!> of rain drops (Stevens and Seifert, 2008).
-!------------------------------------------------------------------------------!
-    SUBROUTINE adjust_cloud
-
-       USE arrays_3d,                                                          &
-           ONLY:  qc, nc, qr, nr
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho
-
-       USE control_parameters,                                                 &
-           ONLY:  microphysics_morrison
-
-       USE cpulog,                                                             &
-           ONLY:  cpu_log, log_point_s
-
-       USE indices,                                                            &
-           ONLY:  nxlg, nxrg, nyng, nysg, nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       CALL cpu_log( log_point_s(54), 'adjust_cloud', 'start' )
-
-       DO  i = nxlg, nxrg
-          DO  j = nysg, nyng
-             DO  k = nzb+1, nzt
-                IF ( qr(k,j,i) <= eps_sb )  THEN
-                   qr(k,j,i) = 0.0_wp
-                   nr(k,j,i) = 0.0_wp
-                ELSE
-                   IF ( nr(k,j,i) * xrmin > qr(k,j,i) * hyrho(k) )  THEN
-                      nr(k,j,i) = qr(k,j,i) * hyrho(k) / xrmin *               &
-                                       MERGE( 1.0_wp, 0.0_wp,                  &
-                                              BTEST( wall_flags_0(k,j,i), 0 ) )
-                   ELSEIF ( nr(k,j,i) * xrmax < qr(k,j,i) * hyrho(k) )  THEN
-                      nr(k,j,i) = qr(k,j,i) * hyrho(k) / xrmax *               &
-                                       MERGE( 1.0_wp, 0.0_wp,                  &
-                                              BTEST( wall_flags_0(k,j,i), 0 ) )
-                   ENDIF
-                ENDIF
-                IF ( microphysics_morrison ) THEN
-                   IF ( qc(k,j,i) <= eps_sb )  THEN
-                      qc(k,j,i) = 0.0_wp
-                      nc(k,j,i) = 0.0_wp
-                   ELSE
-                      IF ( nc(k,j,i) * xcmin > qc(k,j,i) * hyrho(k) )  THEN
-                         nc(k,j,i) = qc(k,j,i) * hyrho(k) / xcmin *            &
-                                          MERGE( 1.0_wp, 0.0_wp,               &
-                                              BTEST( wall_flags_0(k,j,i), 0 ) )
-                      ENDIF
-                   ENDIF
-                ENDIF
-             ENDDO
-          ENDDO
-       ENDDO
-
-       CALL cpu_log( log_point_s(54), 'adjust_cloud', 'stop' )
-
-    END SUBROUTINE adjust_cloud
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Calculate number of activated condensation nucleii after simple activation
-!> scheme of Twomey, 1959.
-!------------------------------------------------------------------------------!
-    SUBROUTINE activation
-
-       USE arrays_3d,                                                          &
-           ONLY:  nc
-
-       USE cloud_parameters,                                                   &
-           ONLY:  molecular_weight_of_solute,       &
-                  molecular_weight_of_water, rho_l, rho_s, r_v, vanthoff
-
-       USE cpulog,                                                             &
-           ONLY:  cpu_log, log_point_s
-
-       USE diagnostic_quantities_mod,                                          &
-           ONLY:  magnus, sat, supersaturation, t_l
-
-       USE indices,                                                            &
-           ONLY:  nxlg, nxrg, nysg, nyng, nzb, nzt
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  activ             !<
-       REAL(wp)     ::  afactor           !<
-       REAL(wp)     ::  beta_act          !<
-       REAL(wp)     ::  bfactor           !<
-       REAL(wp)     ::  k_act             !<
-       REAL(wp)     ::  n_act             !<
-       REAL(wp)     ::  n_ccn             !<
-       REAL(wp)     ::  s_0               !<
-       REAL(wp)     ::  sat_max           !<
-       REAL(wp)     ::  sigma             !<
-       REAL(wp)     ::  sigma_act         !<
-
-       CALL cpu_log( log_point_s(65), 'activation', 'start' )
-
-       DO  i = nxlg, nxrg
-          DO  j = nysg, nyng
-             DO  k = nzb+1, nzt
-
-!
-!--             Call calculation of supersaturation located 
-!--             in diagnostic_quantities_mod
-                CALL supersaturation ( i, j, k )
-!
-!--             Prescribe parameters for activation
-!--             (see: Bott + Trautmann, 2002, Atm. Res., 64)
-                k_act  = 0.7_wp
-                activ  = 0.0_wp
-
-
-                IF ( sat > 0.0 .AND. .NOT. curvature_solution_effects_bulk ) THEN
-!
-!--                Compute the number of activated Aerosols
-!--                (see: Twomey, 1959, Pure and applied Geophysics, 43)
-                   n_act     = na_init * sat**k_act
-!
-!--                Compute the number of cloud droplets
-!--                (see: Morrison + Grabowski, 2007, JAS, 64)
-!                  activ = MAX( n_act - nc(k,j,i), 0.0_wp) / dt_micro
-
-!
-!--                Compute activation rate after Khairoutdinov and Kogan
-!--                (see: Khairoutdinov + Kogan, 2000, Mon. Wea. Rev., 128)
-                   sat_max = 1.0_wp / 100.0_wp
-                   activ   = MAX( 0.0_wp, ( (na_init + nc(k,j,i) ) * MIN       &
-                      ( 1.0_wp, ( sat / sat_max )**k_act) - nc(k,j,i) ) ) /    &
-                       dt_micro
-                ELSEIF ( sat > 0.0 .AND. curvature_solution_effects_bulk ) THEN
-!
-!--                Curvature effect (afactor) with surface tension
-!--                parameterization by Straka (2009)
-                   sigma = 0.0761_wp - 0.000155_wp * ( t_l - 273.15_wp )
-                   afactor = 2.0_wp * sigma / ( rho_l * r_v * t_l )
-!
-!--                Solute effect (bfactor)
-                   bfactor = vanthoff * molecular_weight_of_water *            &
-                       rho_s / ( molecular_weight_of_solute * rho_l )
-
-!
-!--                Prescribe power index that describes the soluble fraction
-!--                of an aerosol particle (beta) 
-!--                (see: Morrison + Grabowski, 2007, JAS, 64)
-                   beta_act  = 0.5_wp
-                   sigma_act = sigma_bulk**( 1.0_wp + beta_act )
-!
-!--                Calculate mean geometric supersaturation (s_0) with
-!--                parameterization by Khvorostyanov and Curry (2006)
-                   s_0   = dry_aerosol_radius **(- ( 1.0_wp + beta_act ) ) *    &
-                       ( 4.0_wp * afactor**3 / ( 27.0_wp * bfactor ) )**0.5_wp
-
-!
-!--                Calculate number of activated CCN as a function of
-!--                supersaturation and taking Koehler theory into account
-!--                (see: Khvorostyanov + Curry, 2006, J. Geo. Res., 111)
-                   n_ccn = ( na_init / 2.0_wp ) * ( 1.0_wp - ERF(              &
-                      LOG( s_0 / sat ) / ( SQRT(2.0_wp) * LOG(sigma_act) ) ) )
-                   activ = MAX( ( n_ccn - nc(k,j,i) ) / dt_micro, 0.0_wp )
-                ENDIF
-
-                nc(k,j,i) = MIN( (nc(k,j,i) + activ * dt_micro), na_init)
-
-             ENDDO
-          ENDDO
-       ENDDO
-
-       CALL cpu_log( log_point_s(65), 'activation', 'stop' )
-
-    END SUBROUTINE activation
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Calculate condensation rate for cloud water content (after Khairoutdinov and
-!> Kogan, 2000).
-!------------------------------------------------------------------------------!
-    SUBROUTINE condensation
-
-       USE arrays_3d,                                                          &
-           ONLY:  q,  qc, qr, nc
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho, l_d_cp, l_v, r_v
-
-       USE constants,                                                          &
-           ONLY:  pi
-
-       USE cpulog,                                                             &
-           ONLY:  cpu_log, log_point_s
-
-       USE diagnostic_quantities_mod,                                          &
-           ONLY: e_s, magnus, q_s, sat, supersaturation, t_l
-
-       USE indices,                                                            &
-           ONLY:  nxlg, nxrg, nysg, nyng, nzb, nzt
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  cond              !<
-       REAL(wp)     ::  cond_max          !<
-       REAL(wp)     ::  dc                !<
-       REAL(wp)     ::  evap              !<
-       REAL(wp)     ::  g_fac             !<
-       REAL(wp)     ::  nc_0              !<
-       REAL(wp)     ::  temp              !<
-       REAL(wp)     ::  xc                !<
-
-       CALL cpu_log( log_point_s(66), 'condensation', 'start' )
-
-       DO  i = nxlg, nxrg
-          DO  j = nysg, nyng
-             DO  k = nzb+1, nzt
-!
-!--             Call calculation of supersaturation located 
-!--             in diagnostic_quantities_mod
-                CALL supersaturation ( i, j, k )
-!
-!--             Actual temperature:
-                temp = t_l + l_d_cp * ( qc(k,j,i) + qr(k,j,i) )
-
-                g_fac  = 1.0_wp / ( ( l_v / ( r_v * temp ) - 1.0_wp ) *        &
-                                    l_v / ( thermal_conductivity_l * temp )    &
-                                    + r_v * temp / ( diff_coeff_l * e_s )      &
-                                    )
-!
-!--             Mean weight of cloud drops
-                IF ( nc(k,j,i) <= 0.0_wp) CYCLE
-                xc = MAX( (hyrho(k) * qc(k,j,i) / nc(k,j,i)), xcmin)
-!
-!--             Weight averaged diameter of cloud drops:
-                dc   = ( xc * dpirho_l )**( 1.0_wp / 3.0_wp )
-!
-!--             Integral diameter of cloud drops
-                nc_0 = nc(k,j,i) * dc
-!
-!--             Condensation needs only to be calculated in supersaturated regions
-                IF ( sat > 0.0_wp )  THEN
-!
-!--                Condensation rate of cloud water content
-!--                after KK scheme.
-!--                (see: Khairoutdinov + Kogan, 2000, Mon. Wea. Rev.,128)
-                   cond      = 2.0_wp * pi * nc_0 * g_fac * sat / hyrho(k)
-                   cond_max  = q(k,j,i) - q_s - qc(k,j,i) - qr(k,j,i)
-                   cond      = MIN( cond, cond_max / dt_micro )
-
-                   qc(k,j,i) = qc(k,j,i) + cond * dt_micro
-                ELSEIF ( sat < 0.0_wp ) THEN
-                   evap      = 2.0_wp * pi * nc_0 * g_fac * sat / hyrho(k)
-                   evap      = MAX( evap, -qc(k,j,i) / dt_micro )
-
-                   qc(k,j,i) = qc(k,j,i) + evap * dt_micro
-                ENDIF
-                IF ( nc(k,j,i) * xcmin > qc(k,j,i) * hyrho(k) )  THEN
-                   nc(k,j,i) = qc(k,j,i) * hyrho(k) / xcmin
-                ENDIF
-             ENDDO
-          ENDDO
-       ENDDO
-
-       CALL cpu_log( log_point_s(66), 'condensation', 'stop' )
-
-    END SUBROUTINE condensation
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Autoconversion rate (Seifert and Beheng, 2006).
-!------------------------------------------------------------------------------!
-    SUBROUTINE autoconversion
-
-       USE arrays_3d,                                                          &
-           ONLY:  diss, dzu, nc, nr, qc, qr
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho
-
-       USE control_parameters,                                                 &
-           ONLY:  microphysics_morrison, rho_surface
-
-       USE cpulog,                                                             &
-           ONLY:  cpu_log, log_point_s
-
-       USE grid_variables,                                                     &
-           ONLY:  dx, dy
-
-       USE indices,                                                            &
-           ONLY:  nxlg, nxrg, nyng, nysg, nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  alpha_cc          !<
-       REAL(wp)     ::  autocon           !<
-       REAL(wp)     ::  dissipation       !<
-       REAL(wp)     ::  flag              !< flag to mask topography grid points
-       REAL(wp)     ::  k_au              !<
-       REAL(wp)     ::  l_mix             !<
-       REAL(wp)     ::  nc_auto           !<
-       REAL(wp)     ::  nu_c              !<
-       REAL(wp)     ::  phi_au            !<
-       REAL(wp)     ::  r_cc              !<
-       REAL(wp)     ::  rc                !<
-       REAL(wp)     ::  re_lambda         !<
-       REAL(wp)     ::  sigma_cc          !<
-       REAL(wp)     ::  tau_cloud         !<
-       REAL(wp)     ::  xc                !<
-
-       CALL cpu_log( log_point_s(55), 'autoconversion', 'start' )
-
-       DO  i = nxlg, nxrg
-          DO  j = nysg, nyng
-             DO  k = nzb+1, nzt
-!
-!--             Predetermine flag to mask topography
-                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-                nc_auto = MERGE( nc(k,j,i), nc_const, microphysics_morrison )
-
-                IF ( qc(k,j,i) > eps_sb  .AND.  nc_auto > eps_mr )  THEN
-
-                   k_au = k_cc / ( 20.0_wp * x0 )
-!
-!--                Intern time scale of coagulation (Seifert and Beheng, 2006):
-!--                (1.0_wp - qc(k,j,i) / ( qc(k,j,i) + qr(k,j,i) ))
-                   tau_cloud = MAX( 1.0_wp - qc(k,j,i) / ( qr(k,j,i) +         &
-                                    qc(k,j,i) ), 0.0_wp )
-!
-!--                Universal function for autoconversion process
-!--                (Seifert and Beheng, 2006):
-                   phi_au = 600.0_wp * tau_cloud**0.68_wp *                    &
-                            ( 1.0_wp - tau_cloud**0.68_wp )**3
-!
-!--                Shape parameter of gamma distribution (Geoffroy et al., 2010):
-!--                (Use constant nu_c = 1.0_wp instead?)
-                   nu_c = 1.0_wp !MAX( 0.0_wp, 1580.0_wp * hyrho(k) * qc(k,j,i) - 0.28_wp )
-!
-!--                Mean weight of cloud droplets:
-                   xc = MAX( hyrho(k) * qc(k,j,i) / nc_auto, xcmin) 
-!
-!--                Parameterized turbulence effects on autoconversion (Seifert,
-!--                Nuijens and Stevens, 2010)
-                   IF ( collision_turbulence )  THEN
-!
-!--                   Weight averaged radius of cloud droplets:
-                      rc = 0.5_wp * ( xc * dpirho_l )**( 1.0_wp / 3.0_wp )
-
-                      alpha_cc = ( a_1 + a_2 * nu_c ) / ( 1.0_wp + a_3 * nu_c )
-                      r_cc     = ( b_1 + b_2 * nu_c ) / ( 1.0_wp + b_3 * nu_c )
-                      sigma_cc = ( c_1 + c_2 * nu_c ) / ( 1.0_wp + c_3 * nu_c )
-!
-!--                   Mixing length (neglecting distance to ground and
-!--                   stratification)
-                      l_mix = ( dx * dy * dzu(k) )**( 1.0_wp / 3.0_wp )
-!
-!--                   Limit dissipation rate according to Seifert, Nuijens and
-!--                   Stevens (2010)
-                      dissipation = MIN( 0.06_wp, diss(k,j,i) )
-!
-!--                   Compute Taylor-microscale Reynolds number:
-                      re_lambda = 6.0_wp / 11.0_wp *                           &
-                                  ( l_mix / c_const )**( 2.0_wp / 3.0_wp ) *   &
-                                  SQRT( 15.0_wp / kin_vis_air ) *              &
-                                  dissipation**( 1.0_wp / 6.0_wp )
-!
-!--                   The factor of 1.0E4 is needed to convert the dissipation
-!--                   rate from m2 s-3 to cm2 s-3.
-                      k_au = k_au * ( 1.0_wp +                                 &
-                                      dissipation * 1.0E4_wp *                 &
-                                      ( re_lambda * 1.0E-3_wp )**0.25_wp *     &
-                                      ( alpha_cc * EXP( -1.0_wp * ( ( rc -     &
-                                                                      r_cc ) / &
-                                                        sigma_cc )**2          &
-                                                      ) + beta_cc              &
-                                      )                                        &
-                                    )
-                   ENDIF
-!
-!--                Autoconversion rate (Seifert and Beheng, 2006):
-                   autocon = k_au * ( nu_c + 2.0_wp ) * ( nu_c + 4.0_wp ) /    &
-                             ( nu_c + 1.0_wp )**2 * qc(k,j,i)**2 * xc**2 *     &
-                             ( 1.0_wp + phi_au / ( 1.0_wp - tau_cloud )**2 ) * &
-                             rho_surface
-                   autocon = MIN( autocon, qc(k,j,i) / dt_micro )
-
-                   qr(k,j,i) = qr(k,j,i) + autocon * dt_micro * flag
-                   qc(k,j,i) = qc(k,j,i) - autocon * dt_micro * flag
-                   nr(k,j,i) = nr(k,j,i) + autocon / x0 * hyrho(k) * dt_micro  &
-                                                              * flag
-                   IF ( microphysics_morrison ) THEN
-                      nc(k,j,i) = nc(k,j,i) - MIN( nc(k,j,i), 2.0_wp *         &
-                                    autocon / x0 * hyrho(k) * dt_micro * flag )
-                   ENDIF
-
-                ENDIF
-
-             ENDDO
-          ENDDO
-       ENDDO
-
-       CALL cpu_log( log_point_s(55), 'autoconversion', 'stop' )
-
-    END SUBROUTINE autoconversion
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Autoconversion process (Kessler, 1969).
-!------------------------------------------------------------------------------!
-    SUBROUTINE autoconversion_kessler
-
-       USE arrays_3d,                                                          &
-           ONLY:  dzw, pt, prr, q, qc
-
-       USE cloud_parameters,                                                   &
-           ONLY:  l_d_cp, pt_d_t
-
-       USE indices,                                                            &
-           ONLY:  nxlg, nxrg, nyng, nysg, nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       USE surface_mod,                                                        &
-           ONLY:  get_topography_top_index_ji
-
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i      !<
-       INTEGER(iwp) ::  j      !<
-       INTEGER(iwp) ::  k      !<
-       INTEGER(iwp) ::  k_wall !< topgraphy top index
-
-       REAL(wp)    ::  dqdt_precip !<
-       REAL(wp)    ::  flag        !< flag to mask topography grid points
-
-       DO  i = nxlg, nxrg
-          DO  j = nysg, nyng
-!
-!--          Determine vertical index of topography top
-             k_wall = get_topography_top_index_ji( j, i, 's' )
-             DO  k = nzb+1, nzt
-!
-!--             Predetermine flag to mask topography
-                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-                IF ( qc(k,j,i) > ql_crit )  THEN
-                   dqdt_precip = prec_time_const * ( qc(k,j,i) - ql_crit )
-                ELSE
-                   dqdt_precip = 0.0_wp
-                ENDIF
-
-                qc(k,j,i) = qc(k,j,i) - dqdt_precip * dt_micro * flag
-                q(k,j,i)  = q(k,j,i)  - dqdt_precip * dt_micro * flag
-                pt(k,j,i) = pt(k,j,i) + dqdt_precip * dt_micro * l_d_cp *      &
-                                        pt_d_t(k)              * flag
-
-!
-!--             Compute the rain rate (stored on surface grid point)
-                prr(k_wall,j,i) = prr(k_wall,j,i) + dqdt_precip * dzw(k) * flag
-
-             ENDDO
-          ENDDO
-       ENDDO
-
-   END SUBROUTINE autoconversion_kessler
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Accretion rate (Seifert and Beheng, 2006).
-!------------------------------------------------------------------------------!
-    SUBROUTINE accretion
-
-       USE arrays_3d,                                                          &
-           ONLY:  diss, qc, qr, nc
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho
-
-       USE control_parameters,                                                 &
-           ONLY:  microphysics_morrison, rho_surface
-
-       USE cpulog,                                                             &
-           ONLY:  cpu_log, log_point_s
-
-       USE indices,                                                            &
-           ONLY:  nxlg, nxrg, nyng, nysg, nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  accr              !<
-       REAL(wp)     ::  flag              !< flag to mask topography grid points
-       REAL(wp)     ::  k_cr              !<
-       REAL(wp)     ::  nc_accr           !<
-       REAL(wp)     ::  phi_ac            !<
-       REAL(wp)     ::  tau_cloud         !<
-       REAL(wp)     ::  xc                !<
-
-
-       CALL cpu_log( log_point_s(56), 'accretion', 'start' )
-
-       DO  i = nxlg, nxrg
-          DO  j = nysg, nyng
-             DO  k = nzb+1, nzt
-!
-!--             Predetermine flag to mask topography
-                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-                nc_accr = MERGE( nc(k,j,i), nc_const, microphysics_morrison )
-
-                IF ( ( qc(k,j,i) > eps_sb )  .AND.  ( qr(k,j,i) > eps_sb )    &
-                                             .AND.  ( nc_accr > eps_mr ) ) THEN
-!
-!--                Intern time scale of coagulation (Seifert and Beheng, 2006):
-                   tau_cloud = 1.0_wp - qc(k,j,i) / ( qc(k,j,i) + qr(k,j,i) )
-!
-!--                Universal function for accretion process (Seifert and
-!--                Beheng, 2001):
-                   phi_ac = ( tau_cloud / ( tau_cloud + 5.0E-5_wp ) )**4
-
-!
-!--                Mean weight of cloud drops
-                   xc = MAX( (hyrho(k) * qc(k,j,i) / nc_accr), xcmin)
-!
-!--                Parameterized turbulence effects on autoconversion (Seifert,
-!--                Nuijens and Stevens, 2010). The factor of 1.0E4 is needed to
-!--                convert the dissipation rate (diss) from m2 s-3 to cm2 s-3.
-                   IF ( collision_turbulence )  THEN
-                      k_cr = k_cr0 * ( 1.0_wp + 0.05_wp *                      &
-                                       MIN( 600.0_wp,                          &
-                                            diss(k,j,i) * 1.0E4_wp )**0.25_wp  &
-                                     )
-                   ELSE
-                      k_cr = k_cr0
-                   ENDIF
-!
-!--                Accretion rate (Seifert and Beheng, 2006):
-                   accr = k_cr * qc(k,j,i) * qr(k,j,i) * phi_ac *              &
-                          SQRT( rho_surface * hyrho(k) )
-                   accr = MIN( accr, qc(k,j,i) / dt_micro )
-
-                   qr(k,j,i) = qr(k,j,i) + accr * dt_micro * flag
-                   qc(k,j,i) = qc(k,j,i) - accr * dt_micro * flag
-                   IF ( microphysics_morrison )  THEN
-                      nc(k,j,i) = nc(k,j,i) - MIN( nc(k,j,i),                  &
-                                         accr / xc * hyrho(k) * dt_micro * flag)
-                   ENDIF
-
-                ENDIF
-
-             ENDDO
-          ENDDO
-       ENDDO
-
-       CALL cpu_log( log_point_s(56), 'accretion', 'stop' )
-
-    END SUBROUTINE accretion
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Collisional breakup rate (Seifert, 2008).
-!------------------------------------------------------------------------------!
-    SUBROUTINE selfcollection_breakup
-
-       USE arrays_3d,                                                          &
-           ONLY:  nr, qr
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho
-
-       USE control_parameters,                                                 &
-           ONLY:  rho_surface
-
-       USE cpulog,                                                             &
-           ONLY:  cpu_log, log_point_s
-
-       USE indices,                                                            &
-           ONLY:  nxlg, nxrg, nyng, nysg, nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  breakup           !<
-       REAL(wp)     ::  dr                !<
-       REAL(wp)     ::  flag              !< flag to mask topography grid points
-       REAL(wp)     ::  phi_br            !<
-       REAL(wp)     ::  selfcoll          !<
-
-       CALL cpu_log( log_point_s(57), 'selfcollection', 'start' )
-
-       DO  i = nxlg, nxrg
-          DO  j = nysg, nyng
-             DO  k = nzb+1, nzt
-!
-!--             Predetermine flag to mask topography
-                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-                IF ( qr(k,j,i) > eps_sb )  THEN
-!
-!--                Selfcollection rate (Seifert and Beheng, 2001):
-                   selfcoll = k_rr * nr(k,j,i) * qr(k,j,i) *                   &
-                              SQRT( hyrho(k) * rho_surface )
-!
-!--                Weight averaged diameter of rain drops:
-                   dr = ( hyrho(k) * qr(k,j,i) /                               &
-                          nr(k,j,i) * dpirho_l )**( 1.0_wp / 3.0_wp )
-!
-!--                Collisional breakup rate (Seifert, 2008):
-                   IF ( dr >= 0.3E-3_wp )  THEN
-                      phi_br  = k_br * ( dr - 1.1E-3_wp )
-                      breakup = selfcoll * ( phi_br + 1.0_wp )
-                   ELSE
-                      breakup = 0.0_wp
-                   ENDIF
-
-                   selfcoll = MAX( breakup - selfcoll, -nr(k,j,i) / dt_micro )
-                   nr(k,j,i) = nr(k,j,i) + selfcoll * dt_micro * flag
-
-                ENDIF
-             ENDDO
-          ENDDO
-       ENDDO
-
-       CALL cpu_log( log_point_s(57), 'selfcollection', 'stop' )
-
-    END SUBROUTINE selfcollection_breakup
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Evaporation of precipitable water. Condensation is neglected for
-!> precipitable water.
-!------------------------------------------------------------------------------!
-    SUBROUTINE evaporation_rain
-
-       USE arrays_3d,                                                          &
-           ONLY:  nr, qc, qr
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho, l_d_cp, l_v, r_v
-
-       USE constants,                                                          &
-           ONLY:  pi
-
-       USE cpulog,                                                             &
-           ONLY:  cpu_log, log_point_s
-
-       USE diagnostic_quantities_mod,                                          &
-           ONLY: e_s, magnus, sat, supersaturation, t_l
-
-       USE indices,                                                            &
-           ONLY:  nxlg, nxrg, nyng, nysg, nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  dr                !<
-       REAL(wp)     ::  evap              !<
-       REAL(wp)     ::  evap_nr           !<
-       REAL(wp)     ::  f_vent            !<
-       REAL(wp)     ::  flag              !< flag to mask topography grid points
-       REAL(wp)     ::  g_evap            !<
-       REAL(wp)     ::  lambda_r          !<
-       REAL(wp)     ::  mu_r              !<
-       REAL(wp)     ::  mu_r_2            !<
-       REAL(wp)     ::  mu_r_5d2          !<
-       REAL(wp)     ::  nr_0              !<
-       REAL(wp)     ::  temp              !<
-       REAL(wp)     ::  xr                !<
-
-       CALL cpu_log( log_point_s(58), 'evaporation', 'start' )
-
-       DO  i = nxlg, nxrg
-          DO  j = nysg, nyng
-             DO  k = nzb+1, nzt
-!
-!--             Predetermine flag to mask topography
-                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-                IF ( qr(k,j,i) > eps_sb )  THEN
-
-!
-!--                Call calculation of supersaturation located 
-!--                in diagnostic_quantities_mod
-                   CALL supersaturation ( i, j, k )
-!
-!--                Evaporation needs only to be calculated in subsaturated regions
-                   IF ( sat < 0.0_wp )  THEN
-!
-!--                   Actual temperature:
-                      temp = t_l + l_d_cp * ( qc(k,j,i) + qr(k,j,i) )
-
-                      g_evap = 1.0_wp / ( ( l_v / ( r_v * temp ) - 1.0_wp ) *     &
-                                          l_v / ( thermal_conductivity_l * temp ) &
-                                          + r_v * temp / ( diff_coeff_l * e_s )   &
-                                        )
-!
-!--                   Mean weight of rain drops
-                      xr = hyrho(k) * qr(k,j,i) / nr(k,j,i)
-!
-!--                   Weight averaged diameter of rain drops:
-                      dr = ( xr * dpirho_l )**( 1.0_wp / 3.0_wp )
-!
-!--                   Compute ventilation factor and intercept parameter
-!--                   (Seifert and Beheng, 2006; Seifert, 2008):
-                      IF ( ventilation_effect )  THEN
-!
-!--                      Shape parameter of gamma distribution (Milbrandt and Yau,
-!--                      2005; Stevens and Seifert, 2008):
-                         mu_r = 10.0_wp * ( 1.0_wp + TANH( 1.2E3_wp *          &
-                                                          ( dr - 1.4E-3_wp ) ) )
-!
-!--                      Slope parameter of gamma distribution (Seifert, 2008):
-                         lambda_r = ( ( mu_r + 3.0_wp ) * ( mu_r + 2.0_wp ) *  &
-                                      ( mu_r + 1.0_wp )                        &
-                                    )**( 1.0_wp / 3.0_wp ) / dr
-
-                         mu_r_2   = mu_r + 2.0_wp
-                         mu_r_5d2 = mu_r + 2.5_wp
-
-                         f_vent = a_vent * gamm( mu_r_2 ) *                     &
-                                  lambda_r**( -mu_r_2 ) + b_vent *              &
-                                  schmidt_p_1d3 * SQRT( a_term / kin_vis_air ) *&
-                                  gamm( mu_r_5d2 ) * lambda_r**( -mu_r_5d2 ) *  &
-                                  ( 1.0_wp -                                    &
-                                    0.5_wp * ( b_term / a_term ) *              &
-                                    ( lambda_r / ( c_term + lambda_r )          &
-                                    )**mu_r_5d2 -                               &
-                                    0.125_wp * ( b_term / a_term )**2 *         &
-                                    ( lambda_r / ( 2.0_wp * c_term + lambda_r ) &
-                                    )**mu_r_5d2 -                               &
-                                    0.0625_wp * ( b_term / a_term )**3 *        &
-                                    ( lambda_r / ( 3.0_wp * c_term + lambda_r ) &
-                                    )**mu_r_5d2 -                               &
-                                    0.0390625_wp * ( b_term / a_term )**4 *     &
-                                    ( lambda_r / ( 4.0_wp * c_term + lambda_r ) &
-                                    )**mu_r_5d2                                 &
-                                  )
-
-                         nr_0   = nr(k,j,i) * lambda_r**( mu_r + 1.0_wp ) /    &
-                                  gamm( mu_r + 1.0_wp )
-                      ELSE
-                         f_vent = 1.0_wp
-                         nr_0   = nr(k,j,i) * dr
-                      ENDIF
-   !
-   !--                Evaporation rate of rain water content (Seifert and
-   !--                Beheng, 2006):
-                      evap    = 2.0_wp * pi * nr_0 * g_evap * f_vent * sat /   &
-                                hyrho(k)
-                      evap    = MAX( evap, -qr(k,j,i) / dt_micro )
-                      evap_nr = MAX( c_evap * evap / xr * hyrho(k),            &
-                                     -nr(k,j,i) / dt_micro )
-
-                      qr(k,j,i) = qr(k,j,i) + evap    * dt_micro * flag
-                      nr(k,j,i) = nr(k,j,i) + evap_nr * dt_micro * flag
-
-                   ENDIF
-                ENDIF
-
-             ENDDO
-          ENDDO
-       ENDDO
-
-       CALL cpu_log( log_point_s(58), 'evaporation', 'stop' )
-
-    END SUBROUTINE evaporation_rain
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Sedimentation of cloud droplets (Ackermann et al., 2009, MWR).
-!------------------------------------------------------------------------------!
-    SUBROUTINE sedimentation_cloud
-
-       USE arrays_3d,                                                          &
-           ONLY:  ddzu, dzu, nc, pt, prr, q, qc
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho, l_d_cp, pt_d_t
-
-       USE control_parameters,                                                 &
-           ONLY:  call_microphysics_at_all_substeps,                           &
-                  intermediate_timestep_count, microphysics_morrison
-
-       USE cpulog,                                                             &
-           ONLY:  cpu_log, log_point_s
-
-       USE indices,                                                            &
-           ONLY:  nxlg, nxrg, nyng, nysg, nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       USE statistics,                                                         &
-           ONLY:  weight_substep
-
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i             !<
-       INTEGER(iwp) ::  j             !<
-       INTEGER(iwp) ::  k             !<
-
-       REAL(wp) ::  flag              !< flag to mask topography grid points
-       REAL(wp) ::  nc_sedi           !<
-
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_qc !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_nc !<
-
-
-       CALL cpu_log( log_point_s(59), 'sed_cloud', 'start' )
-
-       sed_qc(nzt+1) = 0.0_wp
-       sed_nc(nzt+1) = 0.0_wp
-
-       DO  i = nxlg, nxrg
-          DO  j = nysg, nyng
-             DO  k = nzt, nzb+1, -1
-!
-!--             Predetermine flag to mask topography
-                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-                nc_sedi = MERGE ( nc(k,j,i), nc_const, microphysics_morrison )
-
-!
-!--             Sedimentation fluxes for number concentration are only calculated
-!--             for cloud_scheme = 'morrison'
-                IF ( microphysics_morrison ) THEN
-                   IF ( qc(k,j,i) > eps_sb  .AND.  nc(k,j,i) > eps_mr )  THEN
-                      sed_nc(k) = sed_qc_const *                               &
-                              ( qc(k,j,i) * hyrho(k) )**( 2.0_wp / 3.0_wp ) *  &
-                              ( nc(k,j,i) )**( 1.0_wp / 3.0_wp )
-                   ELSE
-                      sed_nc(k) = 0.0_wp
-                   ENDIF
-
-                   sed_nc(k) = MIN( sed_nc(k), hyrho(k) * dzu(k+1) *           &
-                                    nc(k,j,i) / dt_micro + sed_nc(k+1)         &
-                                  ) * flag
-
-                   nc(k,j,i) = nc(k,j,i) + ( sed_nc(k+1) - sed_nc(k) ) *       &
-                                         ddzu(k+1) / hyrho(k) * dt_micro * flag
-                ENDIF
-
-                IF ( qc(k,j,i) > eps_sb .AND.  nc_sedi > eps_mr )  THEN
-                   sed_qc(k) = sed_qc_const * nc_sedi**( -2.0_wp / 3.0_wp ) *  &
-                               ( qc(k,j,i) * hyrho(k) )**( 5.0_wp / 3.0_wp ) * &
-                                                                           flag
-                ELSE
-                   sed_qc(k) = 0.0_wp
-                ENDIF
-
-                sed_qc(k) = MIN( sed_qc(k), hyrho(k) * dzu(k+1) * q(k,j,i) /   &
-                                            dt_micro + sed_qc(k+1)             &
-                               ) * flag
-
-                q(k,j,i)  = q(k,j,i)  + ( sed_qc(k+1) - sed_qc(k) ) *          &
-                                        ddzu(k+1) / hyrho(k) * dt_micro * flag
-                qc(k,j,i) = qc(k,j,i) + ( sed_qc(k+1) - sed_qc(k) ) *          &
-                                        ddzu(k+1) / hyrho(k) * dt_micro * flag
-                pt(k,j,i) = pt(k,j,i) - ( sed_qc(k+1) - sed_qc(k) ) *          &
-                                        ddzu(k+1) / hyrho(k) * l_d_cp *        &
-                                        pt_d_t(k) * dt_micro            * flag
-
-!
-!--             Compute the precipitation rate due to cloud (fog) droplets
-                IF ( call_microphysics_at_all_substeps )  THEN
-                   prr(k,j,i) = prr(k,j,i) +  sed_qc(k) / hyrho(k)             &
-                                * weight_substep(intermediate_timestep_count)  &
-                                * flag
-                ELSE
-                   prr(k,j,i) = prr(k,j,i) + sed_qc(k) / hyrho(k) * flag
-                ENDIF
-
-             ENDDO
-          ENDDO
-       ENDDO
-
-       CALL cpu_log( log_point_s(59), 'sed_cloud', 'stop' )
-
-    END SUBROUTINE sedimentation_cloud
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Computation of sedimentation flux. Implementation according to Stevens
-!> and Seifert (2008). Code is based on UCLA-LES.
-!------------------------------------------------------------------------------!
-    SUBROUTINE sedimentation_rain
-
-       USE arrays_3d,                                                          &
-           ONLY:  ddzu, dzu, nr, pt, prr, q, qr
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho, l_d_cp, pt_d_t
-
-       USE control_parameters,                                                 &
-           ONLY:  call_microphysics_at_all_substeps, intermediate_timestep_count
-       USE cpulog,                                                             &
-           ONLY:  cpu_log, log_point_s
-
-       USE indices,                                                            &
-           ONLY:  nxlg, nxrg, nyng, nysg, nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       USE statistics,                                                         &
-           ONLY:  weight_substep
-
-       USE surface_mod,                                                        &
-           ONLY :  bc_h
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i             !< running index x direction
-       INTEGER(iwp) ::  j             !< running index y direction
-       INTEGER(iwp) ::  k             !< running index z direction
-       INTEGER(iwp) ::  k_run         !<
-       INTEGER(iwp) ::  m             !< running index surface elements
-       INTEGER(iwp) ::  surf_e        !< End index of surface elements at (j,i)-gridpoint
-       INTEGER(iwp) ::  surf_s        !< Start index of surface elements at (j,i)-gridpoint
-
-       REAL(wp)     ::  c_run                      !<
-       REAL(wp)     ::  d_max                      !<
-       REAL(wp)     ::  d_mean                     !<
-       REAL(wp)     ::  d_min                      !<
-       REAL(wp)     ::  dr                         !<
-       REAL(wp)     ::  flux                       !<
-       REAL(wp)     ::  flag                       !< flag to mask topography grid points
-       REAL(wp)     ::  lambda_r                   !<
-       REAL(wp)     ::  mu_r                       !<
-       REAL(wp)     ::  z_run                      !<
-
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  c_nr     !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  c_qr     !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  nr_slope !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  qr_slope !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_nr   !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_qr   !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  w_nr     !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  w_qr     !<
-
-       CALL cpu_log( log_point_s(60), 'sed_rain', 'start' )
-
-!
-!--    Compute velocities
-       DO  i = nxlg, nxrg
-          DO  j = nysg, nyng
-             DO  k = nzb+1, nzt
-!
-!--             Predetermine flag to mask topography
-                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-                IF ( qr(k,j,i) > eps_sb )  THEN
-!
-!--                Weight averaged diameter of rain drops:
-                   dr = ( hyrho(k) * qr(k,j,i) /                               &
-                          nr(k,j,i) * dpirho_l )**( 1.0_wp / 3.0_wp )
-!
-!--                Shape parameter of gamma distribution (Milbrandt and Yau, 2005;
-!--                Stevens and Seifert, 2008):
-                   mu_r = 10.0_wp * ( 1.0_wp + TANH( 1.2E3_wp *                &
-                                                     ( dr - 1.4E-3_wp ) ) )
-!
-!--                Slope parameter of gamma distribution (Seifert, 2008):
-                   lambda_r = ( ( mu_r + 3.0_wp ) * ( mu_r + 2.0_wp ) *        &
-                                ( mu_r + 1.0_wp ) )**( 1.0_wp / 3.0_wp ) / dr
-
-                   w_nr(k) = MAX( 0.1_wp, MIN( 20.0_wp,                        &
-                                               a_term - b_term * ( 1.0_wp +    &
-                                                  c_term /                     &
-                                                  lambda_r )**( -1.0_wp *      &
-                                                  ( mu_r + 1.0_wp ) )          &
-                                              )                                &
-                                ) * flag
-
-                   w_qr(k) = MAX( 0.1_wp, MIN( 20.0_wp,                        &
-                                               a_term - b_term * ( 1.0_wp +    &
-                                                  c_term /                     &
-                                                  lambda_r )**( -1.0_wp *      &
-                                                  ( mu_r + 4.0_wp ) )          &
-                                             )                                 &
-                                ) * flag
-                ELSE
-                   w_nr(k) = 0.0_wp
-                   w_qr(k) = 0.0_wp
-                ENDIF
-             ENDDO
-!
-!--          Adjust boundary values using surface data type.
-!--          Upward-facing
-             surf_s = bc_h(0)%start_index(j,i)
-             surf_e = bc_h(0)%end_index(j,i)
-             DO  m = surf_s, surf_e
-                k         = bc_h(0)%k(m)
-                w_nr(k-1) = w_nr(k)
-                w_qr(k-1) = w_qr(k)
-             ENDDO
-!
-!--          Downward-facing
-             surf_s = bc_h(1)%start_index(j,i)
-             surf_e = bc_h(1)%end_index(j,i)
-             DO  m = surf_s, surf_e
-                k         = bc_h(1)%k(m)
-                w_nr(k+1) = w_nr(k)
-                w_qr(k+1) = w_qr(k)
-             ENDDO
-!
-!--          Model top boundary value
-             w_nr(nzt+1) = 0.0_wp
-             w_qr(nzt+1) = 0.0_wp
-!
-!--          Compute Courant number
-             DO  k = nzb+1, nzt
-!
-!--             Predetermine flag to mask topography
-                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-                c_nr(k) = 0.25_wp * ( w_nr(k-1) +                              &
-                                      2.0_wp * w_nr(k) + w_nr(k+1) ) *         &
-                          dt_micro * ddzu(k) * flag
-                c_qr(k) = 0.25_wp * ( w_qr(k-1) +                              &
-                                      2.0_wp * w_qr(k) + w_qr(k+1) ) *         &
-                          dt_micro * ddzu(k) * flag
-             ENDDO
-!
-!--          Limit slopes with monotonized centered (MC) limiter (van Leer, 1977):
-             IF ( limiter_sedimentation )  THEN
-
-                DO k = nzb+1, nzt
-!
-!--                Predetermine flag to mask topography
-                   flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-                   d_mean = 0.5_wp * ( qr(k+1,j,i) - qr(k-1,j,i) )
-                   d_min  = qr(k,j,i) - MIN( qr(k+1,j,i), qr(k,j,i), qr(k-1,j,i) )
-                   d_max  = MAX( qr(k+1,j,i), qr(k,j,i), qr(k-1,j,i) ) - qr(k,j,i)
-
-                   qr_slope(k) = SIGN(1.0_wp, d_mean) * MIN ( 2.0_wp * d_min,  &
-                                                              2.0_wp * d_max,  &
-                                                              ABS( d_mean ) )  &
-                                                      * flag
-
-                   d_mean = 0.5_wp * ( nr(k+1,j,i) - nr(k-1,j,i) )
-                   d_min  = nr(k,j,i) - MIN( nr(k+1,j,i), nr(k,j,i), nr(k-1,j,i) )
-                   d_max  = MAX( nr(k+1,j,i), nr(k,j,i), nr(k-1,j,i) ) - nr(k,j,i)
-
-                   nr_slope(k) = SIGN(1.0_wp, d_mean) * MIN ( 2.0_wp * d_min,  &
-                                                              2.0_wp * d_max,  &
-                                                              ABS( d_mean ) )
-                ENDDO
-
-             ELSE
-
-                nr_slope = 0.0_wp
-                qr_slope = 0.0_wp
-
-             ENDIF
-
-             sed_nr(nzt+1) = 0.0_wp
-             sed_qr(nzt+1) = 0.0_wp
-!
-!--          Compute sedimentation flux
-             DO  k = nzt, nzb+1, -1
-!
-!--             Predetermine flag to mask topography
-                flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-!
-!--             Sum up all rain drop number densities which contribute to the flux
-!--             through k-1/2
-                flux  = 0.0_wp
-                z_run = 0.0_wp ! height above z(k)
-                k_run = k
-                c_run = MIN( 1.0_wp, c_nr(k) )
-                DO WHILE ( c_run > 0.0_wp  .AND.  k_run <= nzt )
-                   flux  = flux + hyrho(k_run) *                               &
-                           ( nr(k_run,j,i) + nr_slope(k_run) *                 &
-                           ( 1.0_wp - c_run ) * 0.5_wp ) * c_run * dzu(k_run)  &
-                                              * flag
-                   z_run = z_run + dzu(k_run) * flag
-                   k_run = k_run + 1          * flag
-                   c_run = MIN( 1.0_wp, c_nr(k_run) - z_run * ddzu(k_run) )    &
-                                              * flag
-                ENDDO
-!
-!--             It is not allowed to sediment more rain drop number density than
-!--             available
-                flux = MIN( flux,                                              &
-                            hyrho(k) * dzu(k+1) * nr(k,j,i) + sed_nr(k+1) *    &
-                            dt_micro                                           &
-                          )
-
-                sed_nr(k) = flux / dt_micro * flag
-                nr(k,j,i) = nr(k,j,i) + ( sed_nr(k+1) - sed_nr(k) ) *          &
-                                        ddzu(k+1) / hyrho(k) * dt_micro * flag
-!
-!--             Sum up all rain water content which contributes to the flux
-!--             through k-1/2
-                flux  = 0.0_wp
-                z_run = 0.0_wp ! height above z(k)
-                k_run = k
-                c_run = MIN( 1.0_wp, c_qr(k) )
-
-                DO WHILE ( c_run > 0.0_wp  .AND.  k_run <= nzt )
-
-                   flux  = flux + hyrho(k_run) * ( qr(k_run,j,i) +             &
-                                  qr_slope(k_run) * ( 1.0_wp - c_run ) *       &
-                                  0.5_wp ) * c_run * dzu(k_run) * flag
-                   z_run = z_run + dzu(k_run)                   * flag
-                   k_run = k_run + 1                            * flag
-                   c_run = MIN( 1.0_wp, c_qr(k_run) - z_run * ddzu(k_run) )    &
-                                                                * flag
-
-                ENDDO
-!
-!--             It is not allowed to sediment more rain water content than
-!--             available
-                flux = MIN( flux,                                              &
-                            hyrho(k) * dzu(k) * qr(k,j,i) + sed_qr(k+1) *      &
-                            dt_micro                                           &
-                          )
-
-                sed_qr(k) = flux / dt_micro * flag
-
-                qr(k,j,i) = qr(k,j,i) + ( sed_qr(k+1) - sed_qr(k) ) *          &
-                                        ddzu(k+1) / hyrho(k) * dt_micro * flag
-                q(k,j,i)  = q(k,j,i)  + ( sed_qr(k+1) - sed_qr(k) ) *          &
-                                        ddzu(k+1) / hyrho(k) * dt_micro * flag
-                pt(k,j,i) = pt(k,j,i) - ( sed_qr(k+1) - sed_qr(k) ) *          &
-                                        ddzu(k+1) / hyrho(k) * l_d_cp *        &
-                                        pt_d_t(k) * dt_micro            * flag
-!
-!--             Compute the rain rate
-                IF ( call_microphysics_at_all_substeps )  THEN
-                   prr(k,j,i) = prr(k,j,i) + sed_qr(k) / hyrho(k)             &
-                                * weight_substep(intermediate_timestep_count) &
-                                * flag
-                ELSE
-                   prr(k,j,i) = prr(k,j,i) + sed_qr(k) / hyrho(k) * flag
-                ENDIF
-
-             ENDDO
-          ENDDO
-       ENDDO
-
-       CALL cpu_log( log_point_s(60), 'sed_rain', 'stop' )
-
-    END SUBROUTINE sedimentation_rain
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Computation of the precipitation amount due to gravitational settling of
-!> rain and cloud (fog) droplets
-!------------------------------------------------------------------------------!
-    SUBROUTINE calc_precipitation_amount
-
-       USE arrays_3d,                                                          &
-           ONLY:  precipitation_amount, prr
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho
-
-       USE control_parameters,                                                 &
-           ONLY:  call_microphysics_at_all_substeps, dt_do2d_xy, dt_3d,        &
-                  intermediate_timestep_count, intermediate_timestep_count_max,&
-                  precipitation_amount_interval, time_do2d_xy
-
-       USE kinds
-
-       USE surface_mod,                                                        &
-           ONLY :  bc_h
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i             !< running index x direction
-       INTEGER(iwp) ::  j             !< running index y direction
-       INTEGER(iwp) ::  k             !< running index y direction
-       INTEGER(iwp) ::  m             !< running index surface elements
-
-       IF ( ( dt_do2d_xy - time_do2d_xy ) < precipitation_amount_interval .AND.&
-            ( .NOT. call_microphysics_at_all_substeps .OR.                     &
-            intermediate_timestep_count == intermediate_timestep_count_max ) ) &
-       THEN
-!
-!--       Run over all upward-facing surface elements, i.e. non-natural,
-!--       natural and urban
-          DO  m = 1, bc_h(0)%ns
-             i = bc_h(0)%i(m)
-             j = bc_h(0)%j(m)
-             k = bc_h(0)%k(m)
-             precipitation_amount(j,i) = precipitation_amount(j,i) +           &
-                                               prr(k,j,i) * hyrho(k) * dt_3d
-          ENDDO
-
-       ENDIF
-
-    END SUBROUTINE calc_precipitation_amount
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Control of microphysics for grid points i,j
-!------------------------------------------------------------------------------!
-
-    SUBROUTINE microphysics_control_ij( i, j )
-
-       USE arrays_3d,                                                          &
-           ONLY:  hyp, nc, nr, pt, pt_init, prr, q, qc, qr, zu
-
-       USE cloud_parameters,                                                   &
-           ONLY:  cp, hyrho, pt_d_t, r_d, t_d_pt
-
-       USE control_parameters,                                                 &
-           ONLY:  call_microphysics_at_all_substeps, dt_3d, g,                 &
-                  intermediate_timestep_count, large_scale_forcing,            &
-                  lsf_surf, microphysics_morrison, microphysics_seifert,       &
-                  microphysics_kessler, pt_surface, rho_surface,               &
-                  surface_pressure
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt
-
-       USE kinds
-
-       USE statistics,                                                         &
-           ONLY:  weight_pres
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  t_surface         !<
-
-       IF ( large_scale_forcing  .AND.  lsf_surf ) THEN
-!
-!--       Calculate:
-!--       pt / t : ratio of potential and actual temperature (pt_d_t)
-!--       t / pt : ratio of actual and potential temperature (t_d_pt)
-!--       p_0(z) : vertical profile of the hydrostatic pressure (hyp)
-          t_surface = pt_surface * ( surface_pressure / 1000.0_wp )**0.286_wp
-          DO  k = nzb, nzt+1
-             hyp(k)    = surface_pressure * 100.0_wp * &
-                         ( ( t_surface - g / cp * zu(k) ) / t_surface )**(1.0_wp / 0.286_wp)
-             pt_d_t(k) = ( 100000.0_wp / hyp(k) )**0.286_wp
-             t_d_pt(k) = 1.0_wp / pt_d_t(k)
-             hyrho(k)  = hyp(k) / ( r_d * t_d_pt(k) * pt_init(k) )
-          ENDDO
-!
-!--       Compute reference density
-          rho_surface = surface_pressure * 100.0_wp / ( r_d * t_surface )
-       ENDIF
-
-!
-!--    Compute length of time step
-       IF ( call_microphysics_at_all_substeps )  THEN
-          dt_micro = dt_3d * weight_pres(intermediate_timestep_count)
-       ELSE
-          dt_micro = dt_3d
-       ENDIF
-
-!
-!--    Use 1d arrays
-       q_1d(:)  = q(:,j,i)
-       pt_1d(:) = pt(:,j,i)
-       qc_1d(:) = qc(:,j,i)
-       IF ( microphysics_seifert )  THEN
-          qr_1d(:) = qr(:,j,i)
-          nr_1d(:) = nr(:,j,i)
-       ENDIF
-       IF ( microphysics_morrison )  THEN
-          nc_1d(:) = nc(:,j,i)
-       ENDIF
-
-
-!
-!--    Reset precipitation rate
-       IF ( intermediate_timestep_count == 1 )  prr(:,j,i) = 0.0_wp
-
-!
-!--    Compute cloud physics
-       IF( microphysics_kessler )  THEN
-
-          CALL autoconversion_kessler( i,j )
-          IF ( cloud_water_sedimentation )  CALL sedimentation_cloud( i,j )
-
-       ELSEIF ( microphysics_seifert )  THEN
-
-          CALL adjust_cloud( i,j )
-          IF ( microphysics_morrison ) CALL activation( i,j )
-          IF ( microphysics_morrison ) CALL condensation( i,j )
-          CALL autoconversion( i,j )
-          CALL accretion( i,j )
-          CALL selfcollection_breakup( i,j )
-          CALL evaporation_rain( i,j )
-          CALL sedimentation_rain( i,j )
-          IF ( cloud_water_sedimentation )  CALL sedimentation_cloud( i,j )
-
-       ENDIF
-
-       CALL calc_precipitation_amount( i,j )
-
-!
-!--    Store results on the 3d arrays
-       q(:,j,i)  = q_1d(:)
-       pt(:,j,i) = pt_1d(:)
-       IF ( microphysics_morrison ) THEN
-          qc(:,j,i) = qc_1d(:)
-          nc(:,j,i) = nc_1d(:)
-       ENDIF
-       IF ( microphysics_seifert )  THEN
-          qr(:,j,i) = qr_1d(:)
-          nr(:,j,i) = nr_1d(:)
-       ENDIF
-
-    END SUBROUTINE microphysics_control_ij
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Adjust number of raindrops to avoid nonlinear effects in
-!> sedimentation and evaporation of rain drops due to too small or
-!> too big weights of rain drops (Stevens and Seifert, 2008).
-!> The same procedure is applied to cloud droplets if they are determined
-!> prognostically. Call for grid point i,j
-!------------------------------------------------------------------------------!
-    SUBROUTINE adjust_cloud_ij( i, j )
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho
-
-       USE control_parameters,                                                 &
-           ONLY: microphysics_morrison
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp) ::  flag                  !< flag to indicate first grid level above surface
-
-       DO  k = nzb+1, nzt
-!
-!--       Predetermine flag to mask topography
-          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-          IF ( qr_1d(k) <= eps_sb )  THEN
-             qr_1d(k) = 0.0_wp
-             nr_1d(k) = 0.0_wp
-          ELSE
-!
-!--          Adjust number of raindrops to avoid nonlinear effects in
-!--          sedimentation and evaporation of rain drops due to too small or
-!--          too big weights of rain drops (Stevens and Seifert, 2008).
-             IF ( nr_1d(k) * xrmin > qr_1d(k) * hyrho(k) )  THEN
-                nr_1d(k) = qr_1d(k) * hyrho(k) / xrmin * flag
-             ELSEIF ( nr_1d(k) * xrmax < qr_1d(k) * hyrho(k) )  THEN
-                nr_1d(k) = qr_1d(k) * hyrho(k) / xrmax * flag
-             ENDIF
-
-          ENDIF
-
-          IF ( microphysics_morrison ) THEN
-             IF ( qc_1d(k) <= eps_sb )  THEN
-                qc_1d(k) = 0.0_wp
-                nc_1d(k) = 0.0_wp
-             ELSE
-                IF ( nc_1d(k) * xcmin > qc_1d(k) * hyrho(k) )  THEN
-                   nc_1d(k) = qc_1d(k) * hyrho(k) / xamin * flag
-                ENDIF
-             ENDIF
-          ENDIF
-
-       ENDDO
-
-    END SUBROUTINE adjust_cloud_ij
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Calculate number of activated condensation nucleii after simple activation
-!> scheme of Twomey, 1959.
-!------------------------------------------------------------------------------!
-    SUBROUTINE activation_ij( i, j )
-
-       USE arrays_3d,                                                          &
-           ONLY:  hyp
-
-       USE cloud_parameters,                                                   &
-           ONLY:  l_d_cp, l_d_r, molecular_weight_of_solute,                   &
-                  molecular_weight_of_water, rho_l, rho_s, r_v, t_d_pt,        &
-                  vanthoff
-
-       USE cpulog,                                                             &
-           ONLY:  cpu_log
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  activ             !<
-       REAL(wp)     ::  afactor           !<
-       REAL(wp)     ::  alpha             !<
-       REAL(wp)     ::  beta_act          !<
-       REAL(wp)     ::  bfactor           !<
-       REAL(wp)     ::  e_s               !<
-       REAL(wp)     ::  k_act             !<
-       REAL(wp)     ::  n_act             !<
-       REAL(wp)     ::  n_ccn             !<
-       REAL(wp)     ::  q_s               !<
-       REAL(wp)     ::  s_0               !<
-       REAL(wp)     ::  sat               !<
-       REAL(wp)     ::  sat_max           !<
-       REAL(wp)     ::  sigma             !<
-       REAL(wp)     ::  sigma_act         !<
-       REAL(wp)     ::  t_int             !<
-       REAL(wp)     ::  t_l               !<
-
-       DO  k = nzb+1, nzt
-!
-!--       Actual liquid water temperature:
-          t_l = t_d_pt(k) * pt_1d(k)
-
-!
-!--       Calculate actual temperature
-          t_int = pt_1d(k) * ( hyp(k) / 100000.0_wp )**0.286_wp
-!
-!--             Saturation vapor pressure at t_l:
-          e_s = 610.78_wp * EXP( 17.269_wp * ( t_l - 273.16_wp ) /             &
-                                 ( t_l - 35.86_wp )                            &
-                                 )
-!
-!--       Computation of saturation mixing ratio:
-          q_s   = 0.622_wp * e_s / ( hyp(k) -  e_s )
-          alpha = 0.622_wp * l_d_r * l_d_cp / ( t_l * t_l )
-          q_s   = q_s * ( 1.0_wp + alpha * q_1d(k) ) /                         &
-                        ( 1.0_wp + alpha * q_s )
-
-!--       Supersaturation:
-          sat   = ( q_1d(k) - qr_1d(k) - qc_1d(k) ) / q_s - 1.0_wp
-
-!
-!--       Prescribe parameters for activation
-!--       (see: Bott + Trautmann, 2002, Atm. Res., 64)
-          k_act  = 0.7_wp
-          activ  = 0.0_wp
-
-          IF ( sat >= 0.0 .AND. .NOT. curvature_solution_effects_bulk )  THEN
-!
-!--          Compute the number of activated Aerosols
-!--          (see: Twomey, 1959, Pure and applied Geophysics, 43)
-             n_act     = na_init * sat**k_act
-!
-!--          Compute the number of cloud droplets
-!--          (see: Morrison + Grabowski, 2007, JAS, 64)
-!            activ = MAX( n_act - nc_d1(k), 0.0_wp) / dt_micro
-
-!
-!--          Compute activation rate after Khairoutdinov and Kogan
-!--          (see: Khairoutdinov + Kogan, 2000, Mon. Wea. Rev., 128)
-             sat_max = 0.8_wp / 100.0_wp
-             activ   = MAX( 0.0_wp, ( (na_init + nc_1d(k) ) * MIN              &
-                 ( 1.0_wp, ( sat / sat_max )**k_act) - nc_1d(k) ) ) /          &
-                  dt_micro
-
-             nc_1d(k) = MIN( (nc_1d(k) + activ * dt_micro), na_init)
-          ELSEIF ( sat >= 0.0 .AND. curvature_solution_effects_bulk )  THEN
-!
-!--          Curvature effect (afactor) with surface tension
-!--          parameterization by Straka (2009)
-             sigma = 0.0761_wp - 0.000155_wp * ( t_int - 273.15_wp )
-             afactor = 2.0_wp * sigma / ( rho_l * r_v * t_int )
-!
-!--          Solute effect (bfactor)
-             bfactor = vanthoff * molecular_weight_of_water *                  &
-                  rho_s / ( molecular_weight_of_solute * rho_l )
-
-!
-!--          Prescribe power index that describes the soluble fraction
-!--          of an aerosol particle (beta).
-!--          (see: Morrison + Grabowski, 2007, JAS, 64)
-             beta_act  = 0.5_wp
-             sigma_act = sigma_bulk**( 1.0_wp + beta_act )
-!
-!--          Calculate mean geometric supersaturation (s_0) with
-!--          parameterization by Khvorostyanov and Curry (2006)
-             s_0   = dry_aerosol_radius **(- ( 1.0_wp + beta_act ) ) *         &
-               ( 4.0_wp * afactor**3 / ( 27.0_wp * bfactor ) )**0.5_wp
-
-!
-!--          Calculate number of activated CCN as a function of
-!--          supersaturation and taking Koehler theory into account
-!--          (see: Khvorostyanov + Curry, 2006, J. Geo. Res., 111)
-             n_ccn = ( na_init / 2.0_wp ) * ( 1.0_wp - ERF(                    &
-                LOG( s_0 / sat ) / ( SQRT(2.0_wp) * LOG(sigma_act) ) ) )
-             activ = MAX( ( n_ccn ) / dt_micro, 0.0_wp )
-
-             nc_1d(k) = MIN( (nc_1d(k) + activ * dt_micro), na_init)
-          ENDIF
-
-       ENDDO
-
-    END SUBROUTINE activation_ij
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Calculate condensation rate for cloud water content (after Khairoutdinov and
-!> Kogan, 2000).
-!------------------------------------------------------------------------------!
-    SUBROUTINE condensation_ij( i, j )
-
-       USE arrays_3d,                                                          &
-           ONLY:  hyp
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho, l_d_cp, l_d_r, l_v, r_v, t_d_pt
-
-       USE constants,                                                          &
-           ONLY:  pi
-
-       USE cpulog,                                                             &
-           ONLY:  cpu_log
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  alpha             !<
-       REAL(wp)     ::  cond              !<
-       REAL(wp)     ::  cond_max          !<
-       REAL(wp)     ::  dc                !<
-       REAL(wp)     ::  e_s               !<
-       REAL(wp)     ::  evap              !<
-       REAL(wp)     ::  g_fac             !<
-       REAL(wp)     ::  nc_0              !<
-       REAL(wp)     ::  q_s               !<
-       REAL(wp)     ::  sat               !<
-       REAL(wp)     ::  t_l               !<
-       REAL(wp)     ::  temp              !<
-       REAL(wp)     ::  xc                !<
-
-
-       DO  k = nzb+1, nzt
-!
-!--       Actual liquid water temperature:
-          t_l = t_d_pt(k) * pt_1d(k)
-!
-!--             Saturation vapor pressure at t_l:
-          e_s = 610.78_wp * EXP( 17.269_wp * ( t_l - 273.16_wp ) /    &
-                                 ( t_l - 35.86_wp )                   &
-                                 )
-!
-!--       Computation of saturation mixing ratio:
-          q_s   = 0.622_wp * e_s / ( hyp(k) - e_s )
-          alpha = 0.622_wp * l_d_r * l_d_cp / ( t_l * t_l )
-          q_s   = q_s * ( 1.0_wp + alpha * q_1d(k) ) /               &
-                        ( 1.0_wp + alpha * q_s )
-
-!--       Supersaturation:
-          sat   = ( q_1d(k) - qr_1d(k) - qc_1d(k) ) / q_s - 1.0_wp
-
-
-!
-!--       Actual temperature:
-          temp = t_l + l_d_cp * ( qc_1d(k) + qr_1d(k) )
-
-          g_fac  = 1.0_wp / ( ( l_v / ( r_v * temp ) - 1.0_wp ) *        &
-                              l_v / ( thermal_conductivity_l * temp )    &
-                              + r_v * temp / ( diff_coeff_l * e_s )      &
-                            )
-!
-!--       Mean weight of cloud drops
-          IF ( nc_1d(k) <= 0.0_wp) CYCLE
-          xc = MAX( (hyrho(k) * qc_1d(k) / nc_1d(k)), xcmin)
-!
-!--       Weight averaged diameter of cloud drops:
-          dc   = ( xc * dpirho_l )**( 1.0_wp / 3.0_wp )
-!
-!--       Integral diameter of cloud drops
-          nc_0 = nc_1d(k) * dc
-!
-!--       Condensation needs only to be calculated in supersaturated regions
-          IF ( sat > 0.0_wp )  THEN
-!
-!--          Condensation rate of cloud water content
-!--          after KK scheme.
-!--          (see: Khairoutdinov + Kogan, 2000, Mon. Wea. Rev.,128)
-             cond      = 2.0_wp * pi * nc_0 * g_fac * sat / hyrho(k)
-             cond_max  = q_1d(k) - q_s - qc_1d(k) - qr_1d(k)
-             cond      = MIN( cond, cond_max / dt_micro )
-
-             qc_1d(k) = qc_1d(k) + cond * dt_micro
-          ELSEIF ( sat < 0.0_wp ) THEN
-             evap      = 2.0_wp * pi * nc_0 * g_fac * sat / hyrho(k)
-             evap      = MAX( evap, -qc_1d(k) / dt_micro )
-
-             qc_1d(k) = qc_1d(k) + evap * dt_micro
-          ENDIF
-       ENDDO
-
-    END SUBROUTINE condensation_ij
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Autoconversion rate (Seifert and Beheng, 2006). Call for grid point i,j
-!------------------------------------------------------------------------------!
-    SUBROUTINE autoconversion_ij( i, j )
-
-       USE arrays_3d,                                                          &
-           ONLY:  diss, dzu
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho
-
-       USE control_parameters,                                                 &
-           ONLY:  microphysics_morrison, rho_surface
-
-       USE grid_variables,                                                     &
-           ONLY:  dx, dy
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  alpha_cc          !<
-       REAL(wp)     ::  autocon           !<
-       REAL(wp)     ::  dissipation       !<
-       REAL(wp)     ::  flag              !< flag to indicate first grid level above surface
-       REAL(wp)     ::  k_au              !<
-       REAL(wp)     ::  l_mix             !<
-       REAL(wp)     ::  nc_auto           !<
-       REAL(wp)     ::  nu_c              !<
-       REAL(wp)     ::  phi_au            !<
-       REAL(wp)     ::  r_cc              !<
-       REAL(wp)     ::  rc                !<
-       REAL(wp)     ::  re_lambda         !<
-       REAL(wp)     ::  sigma_cc          !<
-       REAL(wp)     ::  tau_cloud         !<
-       REAL(wp)     ::  xc                !<
-
-       DO  k = nzb+1, nzt
-!
-!--       Predetermine flag to mask topography
-          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-          nc_auto = MERGE ( nc_1d(k), nc_const, microphysics_morrison )
-
-          IF ( qc_1d(k) > eps_sb  .AND.  nc_auto > eps_mr )  THEN
-
-             k_au = k_cc / ( 20.0_wp * x0 )
-!
-!--          Intern time scale of coagulation (Seifert and Beheng, 2006):
-!--          (1.0_wp - qc(k,j,i) / ( qc(k,j,i) + qr_1d(k) ))
-             tau_cloud = MAX( 1.0_wp - qc_1d(k) / ( qr_1d(k) + qc_1d(k) ),     & 
-                              0.0_wp )
-!
-!--          Universal function for autoconversion process
-!--          (Seifert and Beheng, 2006):
-             phi_au = 600.0_wp * tau_cloud**0.68_wp * ( 1.0_wp - tau_cloud**0.68_wp )**3
-!
-!--          Shape parameter of gamma distribution (Geoffroy et al., 2010):
-!--          (Use constant nu_c = 1.0_wp instead?)
-             nu_c = 1.0_wp !MAX( 0.0_wp, 1580.0_wp * hyrho(k) * qc_1d(k) - 0.28_wp )
-!
-!--          Mean weight of cloud droplets:
-             xc = hyrho(k) * qc_1d(k) / nc_auto
-!
-!--          Parameterized turbulence effects on autoconversion (Seifert,
-!--          Nuijens and Stevens, 2010)
-             IF ( collision_turbulence )  THEN
-!
-!--             Weight averaged radius of cloud droplets:
-                rc = 0.5_wp * ( xc * dpirho_l )**( 1.0_wp / 3.0_wp )
-
-                alpha_cc = ( a_1 + a_2 * nu_c ) / ( 1.0_wp + a_3 * nu_c )
-                r_cc     = ( b_1 + b_2 * nu_c ) / ( 1.0_wp + b_3 * nu_c )
-                sigma_cc = ( c_1 + c_2 * nu_c ) / ( 1.0_wp + c_3 * nu_c )
-!
-!--             Mixing length (neglecting distance to ground and stratification)
-                l_mix = ( dx * dy * dzu(k) )**( 1.0_wp / 3.0_wp )
-!
-!--             Limit dissipation rate according to Seifert, Nuijens and
-!--             Stevens (2010)
-                dissipation = MIN( 0.06_wp, diss(k,j,i) )
-!
-!--             Compute Taylor-microscale Reynolds number:
-                re_lambda = 6.0_wp / 11.0_wp *                                 &
-                            ( l_mix / c_const )**( 2.0_wp / 3.0_wp ) *         &
-                            SQRT( 15.0_wp / kin_vis_air ) *                    &
-                            dissipation**( 1.0_wp / 6.0_wp )
-!
-!--             The factor of 1.0E4 is needed to convert the dissipation rate
-!--             from m2 s-3 to cm2 s-3.
-                k_au = k_au * ( 1.0_wp +                                       &
-                                dissipation * 1.0E4_wp *                       &
-                                ( re_lambda * 1.0E-3_wp )**0.25_wp *           &
-                                ( alpha_cc * EXP( -1.0_wp * ( ( rc - r_cc ) /  &
-                                                  sigma_cc )**2                &
-                                                ) + beta_cc                    &
-                                )                                              &
-                              )
-             ENDIF
-!
-!--          Autoconversion rate (Seifert and Beheng, 2006):
-             autocon = k_au * ( nu_c + 2.0_wp ) * ( nu_c + 4.0_wp ) /          &
-                       ( nu_c + 1.0_wp )**2 * qc_1d(k)**2 * xc**2 *            &
-                       ( 1.0_wp + phi_au / ( 1.0_wp - tau_cloud )**2 ) *       &
-                       rho_surface
-             autocon = MIN( autocon, qc_1d(k) / dt_micro )
-
-             qr_1d(k) = qr_1d(k) + autocon * dt_micro                 * flag
-             qc_1d(k) = qc_1d(k) - autocon * dt_micro                 * flag
-             nr_1d(k) = nr_1d(k) + autocon / x0 * hyrho(k) * dt_micro * flag
-             IF ( microphysics_morrison ) THEN
-                nc_1d(k) = nc_1d(k) - MIN( nc_1d(k), 2.0_wp *                &
-                                    autocon / x0 * hyrho(k) * dt_micro * flag )
-             ENDIF
-
-          ENDIF
-
-       ENDDO
-
-    END SUBROUTINE autoconversion_ij
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Autoconversion process (Kessler, 1969).
-!------------------------------------------------------------------------------!
-    SUBROUTINE autoconversion_kessler_ij( i, j )
-
-       USE arrays_3d,                                                          &
-           ONLY:  dzw, prr
-
-       USE cloud_parameters,                                                   &
-           ONLY:  l_d_cp, pt_d_t
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       USE surface_mod,                                                        &
-           ONLY:  get_topography_top_index_ji
-
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i      !<
-       INTEGER(iwp) ::  j      !<
-       INTEGER(iwp) ::  k      !<
-       INTEGER(iwp) ::  k_wall !< topography top index
-
-       REAL(wp)    ::  dqdt_precip !<
-       REAL(wp)    ::  flag              !< flag to indicate first grid level above surface
-
-!
-!--    Determine vertical index of topography top
-       k_wall = get_topography_top_index_ji( j, i, 's' )
-       DO  k = nzb+1, nzt
-!
-!--       Predetermine flag to mask topography
-          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-          IF ( qc_1d(k) > ql_crit )  THEN
-             dqdt_precip = prec_time_const * ( qc_1d(k) - ql_crit )
-          ELSE
-             dqdt_precip = 0.0_wp
-          ENDIF
-
-          qc_1d(k) = qc_1d(k) - dqdt_precip * dt_micro * flag
-          q_1d(k)  = q_1d(k)  - dqdt_precip * dt_micro * flag
-          pt_1d(k) = pt_1d(k) + dqdt_precip * dt_micro * l_d_cp * pt_d_t(k) * flag
-
-!
-!--       Compute the rain rate (stored on surface grid point)
-          prr(k_wall,j,i) = prr(k_wall,j,i) + dqdt_precip * dzw(k) * flag
-
-       ENDDO
-
-    END SUBROUTINE autoconversion_kessler_ij
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Accretion rate (Seifert and Beheng, 2006). Call for grid point i,j
-!------------------------------------------------------------------------------!
-    SUBROUTINE accretion_ij( i, j )
-
-       USE arrays_3d,                                                          &
-           ONLY:  diss
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho
-
-       USE control_parameters,                                                 &
-           ONLY:  microphysics_morrison, rho_surface
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  accr              !<
-       REAL(wp)     ::  flag              !< flag to indicate first grid level above surface
-       REAL(wp)     ::  k_cr              !<
-       REAL(wp)     ::  nc_accr           !<
-       REAL(wp)     ::  phi_ac            !<
-       REAL(wp)     ::  tau_cloud         !<
-       REAL(wp)     ::  xc                !<
-
-
-       DO  k = nzb+1, nzt
-!
-!--       Predetermine flag to mask topography
-          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-          nc_accr = MERGE ( nc_1d(k), nc_const, microphysics_morrison )
-
-          IF ( ( qc_1d(k) > eps_sb )  .AND.  ( qr_1d(k) > eps_sb )  .AND.  &
-               ( nc_accr > eps_mr ) )  THEN
-!
-!--          Intern time scale of coagulation (Seifert and Beheng, 2006):
-             tau_cloud = 1.0_wp - qc_1d(k) / ( qc_1d(k) + qr_1d(k) )
-!
-!--          Universal function for accretion process
-!--          (Seifert and Beheng, 2001):
-             phi_ac = ( tau_cloud / ( tau_cloud + 5.0E-5_wp ) )**4
-
-!
-!--          Mean weight of cloud drops
-             xc = MAX( (hyrho(k) * qc_1d(k) / nc_accr), xcmin)
-!
-!--          Parameterized turbulence effects on autoconversion (Seifert,
-!--          Nuijens and Stevens, 2010). The factor of 1.0E4 is needed to
-!--          convert the dissipation rate (diss) from m2 s-3 to cm2 s-3.
-             IF ( collision_turbulence )  THEN
-                k_cr = k_cr0 * ( 1.0_wp + 0.05_wp *                            &
-                                 MIN( 600.0_wp,                                &
-                                      diss(k,j,i) * 1.0E4_wp )**0.25_wp        &
-                               )
-             ELSE
-                k_cr = k_cr0
-             ENDIF
-!
-!--          Accretion rate (Seifert and Beheng, 2006):
-             accr = k_cr * qc_1d(k) * qr_1d(k) * phi_ac *                      &
-                    SQRT( rho_surface * hyrho(k) )
-             accr = MIN( accr, qc_1d(k) / dt_micro )
-
-             qr_1d(k) = qr_1d(k) + accr * dt_micro * flag
-             qc_1d(k) = qc_1d(k) - accr * dt_micro * flag
-             IF ( microphysics_morrison )  THEN
-                nc_1d(k) = nc_1d(k) - MIN( nc_1d(k), accr / xc *               &
-                                             hyrho(k) * dt_micro * flag        &
-                                         )
-             ENDIF
-
-
-          ENDIF
-
-       ENDDO
-
-    END SUBROUTINE accretion_ij
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Collisional breakup rate (Seifert, 2008). Call for grid point i,j
-!------------------------------------------------------------------------------!
-    SUBROUTINE selfcollection_breakup_ij( i, j )
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho
-
-       USE control_parameters,                                                 &
-           ONLY:  rho_surface
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  breakup           !<
-       REAL(wp)     ::  dr                !<
-       REAL(wp)     ::  flag              !< flag to indicate first grid level above surface
-       REAL(wp)     ::  phi_br            !<
-       REAL(wp)     ::  selfcoll          !<
-
-       DO  k = nzb+1, nzt
-!
-!--       Predetermine flag to mask topography
-          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-          IF ( qr_1d(k) > eps_sb )  THEN
-!
-!--          Selfcollection rate (Seifert and Beheng, 2001):
-             selfcoll = k_rr * nr_1d(k) * qr_1d(k) * SQRT( hyrho(k) * rho_surface )
-!
-!--          Weight averaged diameter of rain drops:
-             dr = ( hyrho(k) * qr_1d(k) / nr_1d(k) * dpirho_l )**( 1.0_wp / 3.0_wp )
-!
-!--          Collisional breakup rate (Seifert, 2008):
-             IF ( dr >= 0.3E-3_wp )  THEN
-                phi_br  = k_br * ( dr - 1.1E-3_wp )
-                breakup = selfcoll * ( phi_br + 1.0_wp )
-             ELSE
-                breakup = 0.0_wp
-             ENDIF
-
-             selfcoll = MAX( breakup - selfcoll, -nr_1d(k) / dt_micro )
-             nr_1d(k) = nr_1d(k) + selfcoll * dt_micro * flag
-
-          ENDIF
-       ENDDO
-
-    END SUBROUTINE selfcollection_breakup_ij
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Evaporation of precipitable water. Condensation is neglected for
-!> precipitable water. Call for grid point i,j
-!------------------------------------------------------------------------------!
-    SUBROUTINE evaporation_rain_ij( i, j )
-
-       USE arrays_3d,                                                          &
-           ONLY:  hyp
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho, l_d_cp, l_d_r, l_v, r_v, t_d_pt
-
-       USE constants,                                                          &
-           ONLY:  pi
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i                 !<
-       INTEGER(iwp) ::  j                 !<
-       INTEGER(iwp) ::  k                 !<
-
-       REAL(wp)     ::  alpha             !<
-       REAL(wp)     ::  dr                !<
-       REAL(wp)     ::  e_s               !<
-       REAL(wp)     ::  evap              !<
-       REAL(wp)     ::  evap_nr           !<
-       REAL(wp)     ::  f_vent            !<
-       REAL(wp)     ::  flag              !< flag to indicate first grid level above surface
-       REAL(wp)     ::  g_evap            !<
-       REAL(wp)     ::  lambda_r          !<
-       REAL(wp)     ::  mu_r              !<
-       REAL(wp)     ::  mu_r_2            !<
-       REAL(wp)     ::  mu_r_5d2          !<
-       REAL(wp)     ::  nr_0              !<
-       REAL(wp)     ::  q_s               !<
-       REAL(wp)     ::  sat               !<
-       REAL(wp)     ::  t_l               !<
-       REAL(wp)     ::  temp              !<
-       REAL(wp)     ::  xr                !<
-
-       DO  k = nzb+1, nzt
-!
-!--       Predetermine flag to mask topography
-          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-          IF ( qr_1d(k) > eps_sb )  THEN
-!
-!--          Actual liquid water temperature:
-             t_l = t_d_pt(k) * pt_1d(k)
-!
-!--          Saturation vapor pressure at t_l:
-             e_s = 610.78_wp * EXP( 17.269_wp * ( t_l - 273.16_wp ) /          &
-                                    ( t_l - 35.86_wp )                         &
-                                  )
-!
-!--          Computation of saturation mixing ratio:
-             q_s   = 0.622_wp * e_s / ( hyp(k) - e_s )
-             alpha = 0.622_wp * l_d_r * l_d_cp / ( t_l * t_l )
-             q_s   = q_s * ( 1.0_wp + alpha * q_1d(k) ) / ( 1.0_wp + alpha * q_s )
-!
-!--          Supersaturation:
-             sat   = ( q_1d(k) - qr_1d(k) - qc_1d(k) ) / q_s - 1.0_wp
-!
-!--          Evaporation needs only to be calculated in subsaturated regions
-             IF ( sat < 0.0_wp )  THEN
-!
-!--             Actual temperature:
-                temp = t_l + l_d_cp * ( qc_1d(k) + qr_1d(k) )
-
-                g_evap = 1.0_wp / ( ( l_v / ( r_v * temp ) - 1.0_wp ) * l_v /  &
-                                    ( thermal_conductivity_l * temp ) +        &
-                                    r_v * temp / ( diff_coeff_l * e_s )        &
-                                  )
-!
-!--             Mean weight of rain drops
-                xr = hyrho(k) * qr_1d(k) / nr_1d(k)
-!
-!--             Weight averaged diameter of rain drops:
-                dr = ( xr * dpirho_l )**( 1.0_wp / 3.0_wp )
-!
-!--             Compute ventilation factor and intercept parameter
-!--             (Seifert and Beheng, 2006; Seifert, 2008):
-                IF ( ventilation_effect )  THEN
-!
-!--                Shape parameter of gamma distribution (Milbrandt and Yau, 2005;
-!--                Stevens and Seifert, 2008):
-                   mu_r = 10.0_wp * ( 1.0_wp + TANH( 1.2E3_wp * ( dr - 1.4E-3_wp ) ) )
-!
-!--                Slope parameter of gamma distribution (Seifert, 2008):
-                   lambda_r = ( ( mu_r + 3.0_wp ) * ( mu_r + 2.0_wp ) *        &
-                                ( mu_r + 1.0_wp )                              &
-                              )**( 1.0_wp / 3.0_wp ) / dr
-
-                   mu_r_2   = mu_r + 2.0_wp
-                   mu_r_5d2 = mu_r + 2.5_wp
-
-                   f_vent = a_vent * gamm( mu_r_2 ) * lambda_r**( -mu_r_2 ) +  &
-                            b_vent * schmidt_p_1d3 *                           &
-                            SQRT( a_term / kin_vis_air ) * gamm( mu_r_5d2 ) *  &
-                            lambda_r**( -mu_r_5d2 ) *                          &
-                            ( 1.0_wp -                                         &
-                              0.5_wp * ( b_term / a_term ) *                   &
-                              ( lambda_r / ( c_term + lambda_r )               &
-                              )**mu_r_5d2 -                                    &
-                              0.125_wp * ( b_term / a_term )**2 *              &
-                              ( lambda_r / ( 2.0_wp * c_term + lambda_r )      &
-                              )**mu_r_5d2 -                                    &
-                              0.0625_wp * ( b_term / a_term )**3 *             &
-                              ( lambda_r / ( 3.0_wp * c_term + lambda_r )      &
-                              )**mu_r_5d2 -                                    &
-                              0.0390625_wp * ( b_term / a_term )**4 *          &
-                              ( lambda_r / ( 4.0_wp * c_term + lambda_r )      &
-                              )**mu_r_5d2                                      &
-                            )
-
-                   nr_0   = nr_1d(k) * lambda_r**( mu_r + 1.0_wp ) /           &
-                            gamm( mu_r + 1.0_wp )
-                ELSE
-                   f_vent = 1.0_wp
-                   nr_0   = nr_1d(k) * dr
-                ENDIF
-!
-!--             Evaporation rate of rain water content (Seifert and Beheng, 2006):
-                evap    = 2.0_wp * pi * nr_0 * g_evap * f_vent * sat / hyrho(k)
-                evap    = MAX( evap, -qr_1d(k) / dt_micro )
-                evap_nr = MAX( c_evap * evap / xr * hyrho(k),                  &
-                               -nr_1d(k) / dt_micro )
-
-                qr_1d(k) = qr_1d(k) + evap    * dt_micro * flag
-                nr_1d(k) = nr_1d(k) + evap_nr * dt_micro * flag
-
-             ENDIF
-          ENDIF
-
-       ENDDO
-
-    END SUBROUTINE evaporation_rain_ij
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Sedimentation of cloud droplets (Ackermann et al., 2009, MWR).
-!> Call for grid point i,j
-!------------------------------------------------------------------------------!
-    SUBROUTINE sedimentation_cloud_ij( i, j )
-
-       USE arrays_3d,                                                          &
-           ONLY:  ddzu, dzu, prr
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho, l_d_cp, pt_d_t
-
-       USE control_parameters,                                                 &
-           ONLY:  call_microphysics_at_all_substeps,                           &
-                  intermediate_timestep_count, microphysics_morrison
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       USE statistics,                                                         &
-           ONLY:  weight_substep
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i             !<
-       INTEGER(iwp) ::  j             !<
-       INTEGER(iwp) ::  k             !<
-
-       REAL(wp)     ::  flag    !< flag to indicate first grid level above surface
-       REAL(wp)     ::  nc_sedi !<
-
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_nc  !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_qc  !<
-
-       sed_qc(nzt+1) = 0.0_wp
-       sed_nc(nzt+1) = 0.0_wp
-
-
-       DO  k = nzt, nzb+1, -1
-!
-!--       Predetermine flag to mask topography
-          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-          nc_sedi = MERGE( nc_1d(k), nc_const, microphysics_morrison )
-!
-!--       Sedimentation fluxes for number concentration are only calculated
-!--       for cloud_scheme = 'morrison'
-          IF ( microphysics_morrison ) THEN
-             IF ( qc_1d(k) > eps_sb  .AND.  nc_1d(k) > eps_mr )  THEN
-                sed_nc(k) = sed_qc_const *                                     &
-                            ( qc_1d(k) * hyrho(k) )**( 2.0_wp / 3.0_wp ) *     &
-                            ( nc_1d(k) )**( 1.0_wp / 3.0_wp )
-             ELSE
-                sed_nc(k) = 0.0_wp
-             ENDIF
-
-             sed_nc(k) = MIN( sed_nc(k), hyrho(k) * dzu(k+1) *                 &
-                              nc_1d(k) / dt_micro + sed_nc(k+1)                &
-                            ) * flag
-
-             nc_1d(k) = nc_1d(k) + ( sed_nc(k+1) - sed_nc(k) ) *               &
-                                         ddzu(k+1) / hyrho(k) * dt_micro * flag
-          ENDIF
-
-          IF ( qc_1d(k) > eps_sb  .AND.  nc_sedi > eps_mr )  THEN
-             sed_qc(k) = sed_qc_const * nc_sedi**( -2.0_wp / 3.0_wp ) *        &
-                         ( qc_1d(k) * hyrho(k) )**( 5.0_wp / 3.0_wp )  * flag
-          ELSE
-             sed_qc(k) = 0.0_wp
-          ENDIF
-
-          sed_qc(k) = MIN( sed_qc(k), hyrho(k) * dzu(k+1) * q_1d(k) /          &
-                                      dt_micro + sed_qc(k+1)                   &
-                         ) * flag
-
-          q_1d(k)  = q_1d(k)  + ( sed_qc(k+1) - sed_qc(k) ) * ddzu(k+1) /      &
-                                hyrho(k) * dt_micro * flag
-          qc_1d(k) = qc_1d(k) + ( sed_qc(k+1) - sed_qc(k) ) * ddzu(k+1) /      &
-                                hyrho(k) * dt_micro * flag
-          pt_1d(k) = pt_1d(k) - ( sed_qc(k+1) - sed_qc(k) ) * ddzu(k+1) /      &
-                                hyrho(k) * l_d_cp * pt_d_t(k) * dt_micro * flag
-
-!
-!--       Compute the precipitation rate of cloud (fog) droplets
-          IF ( call_microphysics_at_all_substeps )  THEN
-             prr(k,j,i) = prr(k,j,i) + sed_qc(k) / hyrho(k) *                  &
-                              weight_substep(intermediate_timestep_count) * flag
-          ELSE
-             prr(k,j,i) = prr(k,j,i) + sed_qc(k) / hyrho(k) * flag
-          ENDIF
-
-       ENDDO
-
-    END SUBROUTINE sedimentation_cloud_ij
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Computation of sedimentation flux. Implementation according to Stevens
-!> and Seifert (2008). Code is based on UCLA-LES. Call for grid point i,j
-!------------------------------------------------------------------------------!
-    SUBROUTINE sedimentation_rain_ij( i, j )
-
-       USE arrays_3d,                                                          &
-           ONLY:  ddzu, dzu, prr
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho, l_d_cp, pt_d_t
-
-       USE control_parameters,                                                 &
-           ONLY:  call_microphysics_at_all_substeps, intermediate_timestep_count
-
-       USE indices,                                                            &
-           ONLY:  nzb, nzb, nzt, wall_flags_0
-
-       USE kinds
-
-       USE statistics,                                                         &
-           ONLY:  weight_substep
-
-       USE surface_mod,                                                        &
-           ONLY :  bc_h
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i             !< running index x direction
-       INTEGER(iwp) ::  j             !< running index y direction
-       INTEGER(iwp) ::  k             !< running index z direction
-       INTEGER(iwp) ::  k_run         !<
-       INTEGER(iwp) ::  m             !< running index surface elements
-       INTEGER(iwp) ::  surf_e        !< End index of surface elements at (j,i)-gridpoint
-       INTEGER(iwp) ::  surf_s        !< Start index of surface elements at (j,i)-gridpoint
-
-       REAL(wp)     ::  c_run                      !<
-       REAL(wp)     ::  d_max                      !<
-       REAL(wp)     ::  d_mean                     !<
-       REAL(wp)     ::  d_min                      !<
-       REAL(wp)     ::  dr                         !<
-       REAL(wp)     ::  flux                       !<
-       REAL(wp)     ::  flag                       !< flag to indicate first grid level above surface
-       REAL(wp)     ::  lambda_r                   !<
-       REAL(wp)     ::  mu_r                       !<
-       REAL(wp)     ::  z_run                      !<
-
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  c_nr     !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  c_qr     !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  nr_slope !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  qr_slope !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_nr   !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  sed_qr   !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  w_nr     !<
-       REAL(wp), DIMENSION(nzb:nzt+1) ::  w_qr     !<
-
-!
-!--    Compute velocities
-       DO  k = nzb+1, nzt
-!
-!--       Predetermine flag to mask topography
-          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-          IF ( qr_1d(k) > eps_sb )  THEN
-!
-!--          Weight averaged diameter of rain drops:
-             dr = ( hyrho(k) * qr_1d(k) / nr_1d(k) * dpirho_l )**( 1.0_wp / 3.0_wp )
-!
-!--          Shape parameter of gamma distribution (Milbrandt and Yau, 2005;
-!--          Stevens and Seifert, 2008):
-             mu_r = 10.0_wp * ( 1.0_wp + TANH( 1.2E3_wp * ( dr - 1.4E-3_wp ) ) )
-!
-!--          Slope parameter of gamma distribution (Seifert, 2008):
-             lambda_r = ( ( mu_r + 3.0_wp ) * ( mu_r + 2.0_wp ) *              &
-                          ( mu_r + 1.0_wp ) )**( 1.0_wp / 3.0_wp ) / dr
-
-             w_nr(k) = MAX( 0.1_wp, MIN( 20.0_wp,                              &
-                                         a_term - b_term * ( 1.0_wp +          &
-                                            c_term / lambda_r )**( -1.0_wp *   &
-                                            ( mu_r + 1.0_wp ) )                &
-                                        )                                      &
-                          ) * flag
-             w_qr(k) = MAX( 0.1_wp, MIN( 20.0_wp,                              &
-                                         a_term - b_term * ( 1.0_wp +          &
-                                            c_term / lambda_r )**( -1.0_wp *   &
-                                            ( mu_r + 4.0_wp ) )                &
-                                       )                                       &
-                          ) * flag
-          ELSE
-             w_nr(k) = 0.0_wp
-             w_qr(k) = 0.0_wp
-          ENDIF
-       ENDDO
-!
-!--    Adjust boundary values using surface data type.
-!--    Upward facing non-natural
-       surf_s = bc_h(0)%start_index(j,i)
-       surf_e = bc_h(0)%end_index(j,i)
-       DO  m = surf_s, surf_e
-          k         = bc_h(0)%k(m)
-          w_nr(k-1) = w_nr(k)
-          w_qr(k-1) = w_qr(k)
-       ENDDO
-!
-!--    Downward facing non-natural
-       surf_s = bc_h(1)%start_index(j,i)
-       surf_e = bc_h(1)%end_index(j,i)
-       DO  m = surf_s, surf_e
-          k         = bc_h(1)%k(m)
-          w_nr(k+1) = w_nr(k)
-          w_qr(k+1) = w_qr(k)
-       ENDDO
-!
-!--    Neumann boundary condition at model top
-       w_nr(nzt+1) = 0.0_wp
-       w_qr(nzt+1) = 0.0_wp
-!
-!--    Compute Courant number
-       DO  k = nzb+1, nzt
-!
-!--       Predetermine flag to mask topography
-          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-          c_nr(k) = 0.25_wp * ( w_nr(k-1) + 2.0_wp * w_nr(k) + w_nr(k+1) ) *   &
-                    dt_micro * ddzu(k) * flag
-          c_qr(k) = 0.25_wp * ( w_qr(k-1) + 2.0_wp * w_qr(k) + w_qr(k+1) ) *   &
-                    dt_micro * ddzu(k) * flag
-       ENDDO
-!
-!--    Limit slopes with monotonized centered (MC) limiter (van Leer, 1977):
-       IF ( limiter_sedimentation )  THEN
-
-          DO k = nzb+1, nzt
-!
-!--          Predetermine flag to mask topography
-             flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-
-             d_mean = 0.5_wp * ( qr_1d(k+1) - qr_1d(k-1) )
-             d_min  = qr_1d(k) - MIN( qr_1d(k+1), qr_1d(k), qr_1d(k-1) )
-             d_max  = MAX( qr_1d(k+1), qr_1d(k), qr_1d(k-1) ) - qr_1d(k)
-
-             qr_slope(k) = SIGN(1.0_wp, d_mean) * MIN ( 2.0_wp * d_min,        &
-                                                        2.0_wp * d_max,        &
-                                                        ABS( d_mean ) ) * flag
-
-             d_mean = 0.5_wp * ( nr_1d(k+1) - nr_1d(k-1) )
-             d_min  = nr_1d(k) - MIN( nr_1d(k+1), nr_1d(k), nr_1d(k-1) )
-             d_max  = MAX( nr_1d(k+1), nr_1d(k), nr_1d(k-1) ) - nr_1d(k)
-
-             nr_slope(k) = SIGN(1.0_wp, d_mean) * MIN ( 2.0_wp * d_min,        &
-                                                        2.0_wp * d_max,        &
-                                                        ABS( d_mean ) ) * flag
-          ENDDO
-
-       ELSE
-
-          nr_slope = 0.0_wp
-          qr_slope = 0.0_wp
-
-       ENDIF
-
-       sed_nr(nzt+1) = 0.0_wp
-       sed_qr(nzt+1) = 0.0_wp
-!
-!--    Compute sedimentation flux
-       DO  k = nzt, nzb+1, -1
-!
-!--       Predetermine flag to mask topography
-          flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) )
-!
-!--       Sum up all rain drop number densities which contribute to the flux
-!--       through k-1/2
-          flux  = 0.0_wp
-          z_run = 0.0_wp ! height above z(k)
-          k_run = k
-          c_run = MIN( 1.0_wp, c_nr(k) )
-          DO WHILE ( c_run > 0.0_wp  .AND.  k_run <= nzt )
-             flux  = flux + hyrho(k_run) *                                     &
-                     ( nr_1d(k_run) + nr_slope(k_run) * ( 1.0_wp - c_run ) *   &
-                     0.5_wp ) * c_run * dzu(k_run) * flag
-             z_run = z_run + dzu(k_run)            * flag
-             k_run = k_run + 1                     * flag
-             c_run = MIN( 1.0_wp, c_nr(k_run) - z_run * ddzu(k_run) ) * flag
-          ENDDO
-!
-!--       It is not allowed to sediment more rain drop number density than
-!--       available
-          flux = MIN( flux,                                                    &
-                      hyrho(k) * dzu(k+1) * nr_1d(k) + sed_nr(k+1) * dt_micro )
-
-          sed_nr(k) = flux / dt_micro * flag
-          nr_1d(k)  = nr_1d(k) + ( sed_nr(k+1) - sed_nr(k) ) * ddzu(k+1) /     &
-                                    hyrho(k) * dt_micro * flag
-!
-!--       Sum up all rain water content which contributes to the flux
-!--       through k-1/2
-          flux  = 0.0_wp
-          z_run = 0.0_wp ! height above z(k)
-          k_run = k
-          c_run = MIN( 1.0_wp, c_qr(k) )
-
-          DO WHILE ( c_run > 0.0_wp  .AND.  k_run <= nzt )
-
-             flux  = flux + hyrho(k_run) *                                     &
-                     ( qr_1d(k_run) + qr_slope(k_run) * ( 1.0_wp - c_run ) *   &
-                     0.5_wp ) * c_run * dzu(k_run) * flag
-             z_run = z_run + dzu(k_run)            * flag
-             k_run = k_run + 1                     * flag
-             c_run = MIN( 1.0_wp, c_qr(k_run) - z_run * ddzu(k_run) ) * flag
-
-          ENDDO
-!
-!--       It is not allowed to sediment more rain water content than available
-          flux = MIN( flux,                                                    &
-                      hyrho(k) * dzu(k) * qr_1d(k) + sed_qr(k+1) * dt_micro )
-
-          sed_qr(k) = flux / dt_micro * flag
-
-          qr_1d(k) = qr_1d(k) + ( sed_qr(k+1) - sed_qr(k) ) * ddzu(k+1) /      &
-                                hyrho(k) * dt_micro * flag
-          q_1d(k)  = q_1d(k)  + ( sed_qr(k+1) - sed_qr(k) ) * ddzu(k+1) /      &
-                                hyrho(k) * dt_micro * flag
-          pt_1d(k) = pt_1d(k) - ( sed_qr(k+1) - sed_qr(k) ) * ddzu(k+1) /      &
-                                hyrho(k) * l_d_cp * pt_d_t(k) * dt_micro * flag
-!
-!--       Compute the rain rate
-          IF ( call_microphysics_at_all_substeps )  THEN
-             prr(k,j,i) = prr(k,j,i) + sed_qr(k) / hyrho(k)                    &
-                          * weight_substep(intermediate_timestep_count) * flag
-          ELSE
-             prr(k,j,i) = prr(k,j,i) + sed_qr(k) / hyrho(k) * flag
-          ENDIF
-
-       ENDDO
-
-    END SUBROUTINE sedimentation_rain_ij
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> This subroutine computes the precipitation amount due to gravitational
-!> settling of rain and cloud (fog) droplets
-!------------------------------------------------------------------------------!
-    SUBROUTINE calc_precipitation_amount_ij( i, j )
-
-       USE arrays_3d,                                                          &
-           ONLY:  precipitation_amount, prr
-
-       USE cloud_parameters,                                                   &
-           ONLY:  hyrho
-
-       USE control_parameters,                                                 &
-           ONLY:  call_microphysics_at_all_substeps, dt_do2d_xy, dt_3d,        &
-                  intermediate_timestep_count, intermediate_timestep_count_max,&
-                  precipitation_amount_interval, time_do2d_xy
-
-       USE kinds
-
-       USE surface_mod,                                                        &
-           ONLY :  bc_h
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i             !< running index x direction
-       INTEGER(iwp) ::  j             !< running index y direction
-       INTEGER(iwp) ::  k             !< running index z direction
-       INTEGER(iwp) ::  m             !< running index surface elements
-       INTEGER(iwp) ::  surf_e        !< End index of surface elements at (j,i)-gridpoint
-       INTEGER(iwp) ::  surf_s        !< Start index of surface elements at (j,i)-gridpoint
-
-       IF ( ( dt_do2d_xy - time_do2d_xy ) < precipitation_amount_interval .AND.&
-            ( .NOT. call_microphysics_at_all_substeps .OR.                     &
-            intermediate_timestep_count == intermediate_timestep_count_max ) ) &
-       THEN
-
-          surf_s = bc_h(0)%start_index(j,i)
-          surf_e = bc_h(0)%end_index(j,i)
-          DO  m = surf_s, surf_e
-             k                         = bc_h(0)%k(m)
-             precipitation_amount(j,i) = precipitation_amount(j,i) +           &
-                                               prr(k,j,i) * hyrho(k) * dt_3d
-          ENDDO
-
-       ENDIF
-
-    END SUBROUTINE calc_precipitation_amount_ij
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> This function computes the gamma function (Press et al., 1992).
-!> The gamma function is needed for the calculation of the evaporation
-!> of rain drops.
-!------------------------------------------------------------------------------!
-    FUNCTION gamm( xx )
-
-       USE kinds
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  j            !<
-
-       REAL(wp)     ::  gamm         !<
-       REAL(wp)     ::  ser          !<
-       REAL(wp)     ::  tmp          !<
-       REAL(wp)     ::  x_gamm       !<
-       REAL(wp)     ::  xx           !<
-       REAL(wp)     ::  y_gamm       !<
-
-
-       REAL(wp), PARAMETER  ::  stp = 2.5066282746310005_wp               !<
-       REAL(wp), PARAMETER  ::  cof(6) = (/ 76.18009172947146_wp,      &
-                                           -86.50532032941677_wp,      &
-                                            24.01409824083091_wp,      &
-                                            -1.231739572450155_wp,     &
-                                             0.1208650973866179E-2_wp, &
-                                            -0.5395239384953E-5_wp /)     !<
-
-       x_gamm = xx
-       y_gamm = x_gamm
-       tmp = x_gamm + 5.5_wp
-       tmp = ( x_gamm + 0.5_wp ) * LOG( tmp ) - tmp
-       ser = 1.000000000190015_wp
-
-       DO  j = 1, 6
-          y_gamm = y_gamm + 1.0_wp
-          ser    = ser + cof( j ) / y_gamm
-       ENDDO
-
-!
-!--    Until this point the algorithm computes the logarithm of the gamma
-!--    function. Hence, the exponential function is used.
-!       gamm = EXP( tmp + LOG( stp * ser / x_gamm ) )
-       gamm = EXP( tmp ) * stp * ser / x_gamm
-
-       RETURN
-
-    END FUNCTION gamm
-
- END MODULE microphysics_mod
Index: /palm/trunk/SOURCE/model_1d_mod.f90
===================================================================
--- /palm/trunk/SOURCE/model_1d_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/model_1d_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3135 2018-07-16 14:43:04Z gronemeier
 ! Bugfix: add +1 to c_3 according to Sogachev et al. (2012)
 ! 
@@ -173,9 +176,12 @@
         ONLY:  dd2zu, ddzu, ddzw, dzu, dzw, pt_init, q_init, ug, u_init,       &
                vg, v_init, zu
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  g, kappa, pi
     
     USE control_parameters,                                                    &
-        ONLY:  constant_diffusion, constant_flux_layer, dissipation_1d, f, g,  &
+        ONLY:  constant_diffusion, constant_flux_layer, dissipation_1d, f,     &
                humidity, ibc_e_b, intermediate_timestep_count,                 &
-               intermediate_timestep_count_max, kappa, km_constant,            &
+               intermediate_timestep_count_max, km_constant,                   &
                message_string, mixing_length_1d, prandtl_number,               &
                roughness_length, run_description_header, simulated_time_chr,   &
@@ -989,7 +995,4 @@
 
 
-    USE constants,                                                             &
-        ONLY:  pi
-
     IMPLICIT NONE
 
Index: /palm/trunk/SOURCE/modules.f90
===================================================================
--- /palm/trunk/SOURCE/modules.f90	(revision 3273)
+++ /palm/trunk/SOURCE/modules.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3240 2018-09-12 12:04:40Z Giersch
 ! max_pr_user_tmp has been defined as a control variable because it is not 
 ! local anymore
@@ -985,4 +988,8 @@
     REAL(wp), DIMENSION(:), ALLOCATABLE ::  momentumflux_output_conversion  !< conversion factor array for momentumflux output
 
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  hyrho   !< density of air calculated with hydrostatic pressure
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  exner   !< ratio of actual and potential temperature
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  d_exner !< ratio of potential and actual temperature
+
     SAVE
 
@@ -1044,59 +1051,4 @@
   
  END MODULE averaging
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Definition of variables and constants for cloud physics.
-!------------------------------------------------------------------------------!
- MODULE cloud_parameters
- 
-    USE kinds
-
-    REAL(wp) ::  cp = 1005.0_wp                            !< heat capacity of dry air (J kg-1 K-1)
-    REAL(wp) ::  l_v = 2.5E+06_wp                          !< latent heat of vaporization (J kg-1)
-    REAL(wp) ::  l_d_cp                                    !< l_v / cp
-    REAL(wp) ::  l_d_r                                     !< l_v / r_d
-    REAL(wp) ::  l_d_rv                                    !< l_v / r_v    
-    REAL(wp) ::  molecular_weight_of_solute = 0.05844_wp   !< mol. m. NaCl (kg mol-1)
-    REAL(wp) ::  molecular_weight_of_water = 0.01801528_wp !< mol. m. H2O (kg mol-1)
-    REAL(wp) ::  rho_l = 1.0E3_wp                          !< density of water (kg m-3)
-    REAL(wp) ::  rho_s = 2165.0_wp                         !< density of NaCl (kg m-3)
-    REAL(wp) ::  r_d = 287.0_wp                            !< sp. gas const. dry air (J kg-1 K-1)
-    REAL(wp) ::  r_v = 461.51_wp                           !< sp. gas const. water vapor (J kg-1 K-1)
-    REAL(wp) ::  vanthoff = 2.0_wp                         !< van't Hoff factor for NaCl
-
-
-
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  hyrho   !< density of air calculated with hydrostatic pressure 
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  pt_d_t  !< ratio of potential and actual temperature
-    REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_d_pt  !< ratio of actual and potential temperature
-
-    SAVE
-
- END MODULE cloud_parameters
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Definition of general constants.
-!------------------------------------------------------------------------------!
- MODULE constants
- 
-    USE kinds
-
-    REAL(wp) ::  pi = 3.141592654_wp  !< PI
-    REAL(wp) ::  adv_mom_1            !< 1/4 - constant used in 5th-order advection scheme for momentum advection (1st-order part)
-    REAL(wp) ::  adv_mom_3            !< 1/24 - constant used in 5th-order advection scheme for momentum advection (3rd-order part)
-    REAL(wp) ::  adv_mom_5            !< 1/120 - constant used in 5th-order advection scheme for momentum advection (5th-order part)
-    REAL(wp) ::  adv_sca_1            !< 1/2 - constant used in 5th-order advection scheme for scalar advection (1st-order part)
-    REAL(wp) ::  adv_sca_3            !< 1/12 - constant used in 5th-order advection scheme for scalar advection (3rd-order part)
-    REAL(wp) ::  adv_sca_5            !< 1/60 - constant used in 5th-order advection scheme for scalar advection (5th-order part)
-    
-    SAVE
-
- END MODULE constants
 
  
@@ -1157,6 +1109,4 @@
     CHARACTER (LEN=20)   ::  bc_uv_b = 'dirichlet'                        !< namelist parameter
     CHARACTER (LEN=20)   ::  bc_uv_t = 'dirichlet'                        !< namelist parameter
-    CHARACTER (LEN=20)   ::  aerosol_bulk = 'nacl'                        !< namelist parameter
-    CHARACTER (LEN=20)   ::  cloud_scheme = 'saturation_adjust'           !< namelist parameter
     CHARACTER (LEN=20)   ::  coupling_mode = 'uncoupled'                  !< coupling mode for atmosphere-ocean coupling  
     CHARACTER (LEN=20)   ::  coupling_mode_remote = 'uncoupled'           !< coupling mode of the remote process in case of coupled atmosphere-ocean runs
@@ -1311,7 +1261,4 @@
     INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  mask_k_global  !< global grid index of masked output point on z-dimension
 
-    LOGICAL ::  aerosol_nacl =.TRUE.                             !< nacl aerosol for bulk scheme
-    LOGICAL ::  aerosol_c3h4o4 =.FALSE.                          !< malonic acid aerosol for bulk scheme
-    LOGICAL ::  aerosol_nh4no3 =.FALSE.                          !< malonic acid aerosol for bulk scheme
     LOGICAL ::  agent_time_unlimited = .FALSE.                   !< namelist parameter
     LOGICAL ::  air_chemistry = .FALSE.                          !< chemistry model switch
@@ -1331,9 +1278,7 @@
     LOGICAL ::  bc_radiation_s = .FALSE.                         !< radiation boundary condition for outflow at south domain boundary
     LOGICAL ::  calc_soil_moisture_during_spinup = .FALSE.       !< namelist parameter
-    LOGICAL ::  call_microphysics_at_all_substeps = .FALSE.      !< namelist parameter
     LOGICAL ::  call_psolver_at_all_substeps = .TRUE.            !< namelist parameter
     LOGICAL ::  child_domain  = .FALSE.                          !< flag indicating that model is nested in a parent domain
     LOGICAL ::  cloud_droplets = .FALSE.                         !< namelist parameter
-    LOGICAL ::  cloud_physics = .FALSE.                          !< namelist parameter
     LOGICAL ::  cloud_top_radiation = .FALSE.                    !< namelist parameter
     LOGICAL ::  complex_terrain = .FALSE.                        !< namelist parameter
@@ -1375,8 +1320,4 @@
     LOGICAL ::  lsf_vert = .TRUE.                                !< use atmospheric forcing (large scale forcing)?
     LOGICAL ::  masking_method = .FALSE.                         !< namelist parameter
-    LOGICAL ::  microphysics_sat_adjust = .FALSE.                !< use saturation adjust bulk scheme?
-    LOGICAL ::  microphysics_kessler = .FALSE.                   !< use kessler bulk scheme?
-    LOGICAL ::  microphysics_morrison = .FALSE.                  !< use 2-moment Morrison (add. prog. eq. for nc and qc)
-    LOGICAL ::  microphysics_seifert = .FALSE.                   !< use 2-moment Seifert and Beheng scheme
     LOGICAL ::  mg_switch_to_pe0 = .FALSE.                       !< internal multigrid switch for steering the ghost point exchange in case that data has been collected on PE0
     LOGICAL ::  nesting_offline = .FALSE.                        !< flag controlling offline nesting in COSMO model  
@@ -1386,5 +1327,4 @@
     LOGICAL ::  passive_scalar = .FALSE.                         !< namelist parameter
     LOGICAL ::  plant_canopy = .FALSE.                           !< switch for use of plant canopy model
-    LOGICAL ::  precipitation = .FALSE.                          !< namelist parameter
     LOGICAL ::  random_heatflux = .FALSE.                        !< namelist parameter
     LOGICAL ::  rans_mode = .FALSE.                              !< switch between RANS and LES mode
@@ -1492,8 +1432,6 @@
     REAL(wp) ::  f = 0.0_wp                                    !< Coriolis parameter
     REAL(wp) ::  fs = 0.0_wp                                   !< Coriolis parameter
-    REAL(wp) ::  g = 9.81_wp                                   !< gravitational acceleration
     REAL(wp) ::  inflow_damping_height = 9999999.9_wp          !< namelist parameter
     REAL(wp) ::  inflow_damping_width = 9999999.9_wp           !< namelist parameter
-    REAL(wp) ::  kappa = 0.4_wp                                !< von Karman constant
     REAL(wp) ::  km_constant = -1.0_wp                         !< namelist parameter
     REAL(wp) ::  latitude = 55.0_wp                            !< namelist parameter
@@ -1512,5 +1450,4 @@
     REAL(wp) ::  particle_maximum_age = 9999999.9_wp           !< namelist parameter
     REAL(wp) ::  prandtl_number = 1.0_wp                       !< namelist parameter
-    REAL(wp) ::  precipitation_amount_interval = 9999999.9_wp  !< namelist parameter
     REAL(wp) ::  prho_reference                                !< reference state of potential density
     REAL(wp) ::  pt_damping_factor = 0.0_wp                    !< namelist parameter
Index: /palm/trunk/SOURCE/multi_agent_system_mod.f90
===================================================================
--- /palm/trunk/SOURCE/multi_agent_system_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/multi_agent_system_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3268 2018-09-21 13:45:37Z sward
 ! Cleaned up agent pointer assignment in output routine
 ! 
@@ -77,5 +80,5 @@
     USE, INTRINSIC ::  ISO_C_BINDING
 
-    USE constants,                                                             &
+    USE basic_constants_and_equations_mod,                                     &
         ONLY:  pi
 
@@ -2689,5 +2692,5 @@
 
        USE arrays_3d,                                                          &
-           ONLY:  u, v, pt, hyp
+           ONLY:  u, v, pt, hyp, exner
 
 !       USE chemistry_model_mod,                                                &
@@ -2761,6 +2764,5 @@
 !
 !--                Calculate temperature at agent position
-                   agents(nl)%t = pt(kl,jl,il) *                               &
-                                  ( hyp(kl) / 100000.0_wp )**0.286_wp
+                   agents(nl)%t = pt(kl,jl,il) * exner(kl)
 ! !
 ! !--                Get PM10 concentration at agent position, if possible
@@ -4107,7 +4109,4 @@
     SUBROUTINE mas_timestep_social_forces ( mode, nl, ip, jp )
 
-!       USE constants,                                                          &
-!           ONLY:  pi
-
        IMPLICIT NONE
 
Index: /palm/trunk/SOURCE/netcdf_interface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -552,5 +555,5 @@
         ONLY:  chem_define_netcdf_grid 
 
-    USE constants,                                                             &
+    USE basic_constants_and_equations_mod,                                     &
         ONLY:  pi
 
Index: /palm/trunk/SOURCE/palm.f90
===================================================================
--- /palm/trunk/SOURCE/palm.f90	(revision 3273)
+++ /palm/trunk/SOURCE/palm.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3258 2018-09-18 07:23:31Z Giersch
 ! current revision for user interface has been changed to 3240
 ! 
@@ -245,8 +248,8 @@
 
     USE control_parameters,                                                    &
-        ONLY:  air_chemistry, cloud_physics, constant_diffusion, child_domain, &
+        ONLY:  air_chemistry, constant_diffusion, child_domain,                &
                coupling_char, coupling_mode, do2d_at_begin, do3d_at_begin,     &
                humidity, initializing_actions, io_blocks, io_group,            &
-               message_string, microphysics_morrison, microphysics_seifert,    &
+               message_string,                                                 &
                neutral, passive_scalar, runnr, simulated_time_chr, spinup,     &
                time_since_reference_point, user_interface_current_revision,    &
@@ -259,4 +262,9 @@
         ONLY:  nbgp
 
+    USE kinds
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
+
     USE multi_agent_system_mod,                                                &
         ONLY:  agents_active, mas_last_actions
@@ -265,6 +273,4 @@
         ONLY:  netcdf_data_input_inquire_file, netcdf_data_input_init,         &
                netcdf_data_input_surface_data, netcdf_data_input_topo
-
-    USE kinds
 
     USE particle_attributes,                                                   &
@@ -442,9 +448,9 @@
              IF ( humidity )  THEN
                 CALL exchange_horiz( q, nbgp )
-                IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
                   CALL exchange_horiz( qc, nbgp )
                   CALL exchange_horiz( nc, nbgp )
                 ENDIF
-                IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
                    CALL exchange_horiz( qr, nbgp ) 
                    CALL exchange_horiz( nr, nbgp )
Index: /palm/trunk/SOURCE/parin.f90
===================================================================
--- /palm/trunk/SOURCE/parin.f90	(revision 3273)
+++ /palm/trunk/SOURCE/parin.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3248 2018-09-14 09:42:06Z sward
 ! Minor formating changes
 ! 
@@ -420,10 +423,13 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  pt_init, q_init, ref_state, s_init, sa_init,                    &     
+        ONLY:  pt_init, q_init, ref_state, s_init, sa_init,                    &
                ug, u_init, v_init, vg
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bcm_parin
 
     USE chemistry_model_mod,                                                   &
         ONLY:  chem_parin
-        
+
     USE chem_modules
 
@@ -455,10 +461,4 @@
     USE land_surface_model_mod,                                                &
         ONLY: lsm_parin
-
-    USE microphysics_mod,                                                      &
-        ONLY:  c_sedimentation, cloud_water_sedimentation,                     &
-               collision_turbulence, curvature_solution_effects_bulk,          &
-               dry_aerosol_radius, limiter_sedimentation, na_init, nc_const,   &
-               sigma_bulk, ventilation_effect
 
     USE model_1d_mod,                                                          &
@@ -525,5 +525,5 @@
     INTEGER(iwp) ::  ioerr          !< error flag for open/read/write
 
-    NAMELIST /inipar/  aerosol_bulk, alpha_surface, approximation, bc_e_b,     &
+    NAMELIST /inipar/  alpha_surface, approximation, bc_e_b,     &
                        bc_lr, bc_ns, bc_p_b, bc_p_t, bc_pt_b, bc_pt_t, bc_q_b, &
              bc_q_t,bc_s_b, bc_s_t, bc_sa_t, bc_uv_b, bc_uv_t,                 &
@@ -531,19 +531,18 @@
              building_length_y, building_wall_left, building_wall_south,       &
              calc_soil_moisture_during_spinup,                                 &
-             call_psolver_at_all_substeps, call_microphysics_at_all_substeps,  &
+             call_psolver_at_all_substeps,  &
              canyon_height,                                                    &
              canyon_width_x, canyon_width_y, canyon_wall_left,                 &
-             canyon_wall_south, c_sedimentation, cfl_factor, cloud_droplets,   &
-             cloud_physics, cloud_scheme, cloud_top_radiation,                 &
-             cloud_water_sedimentation,                                        &
-             collective_wait, collision_turbulence, complex_terrain,           &
+             canyon_wall_south, cfl_factor, cloud_droplets,   &
+             cloud_top_radiation,                 &
+             collective_wait, complex_terrain,           &
              conserve_volume_flow,                                             &
              conserve_volume_flow_mode, constant_flux_layer,                   &
-             coupling_start_time, curvature_solution_effects_bulk,             &
+             coupling_start_time,             &
              cycle_mg, damp_level_1d,                                          &
              data_output_during_spinup,                                        &
              day_of_year_init,                                                 &
              dissipation_1d,                                                   &
-             dp_external, dp_level_b, dp_smooth, dpdxy, dry_aerosol_radius,    &
+             dp_external, dp_level_b, dp_smooth, dpdxy,    &
              dt, dt_pr_1d, dt_run_control_1d, dt_spinup, dx, dy, dz, dz_max,   &
              dz_stretch_factor, dz_stretch_level, dz_stretch_level_start,      &
@@ -555,12 +554,12 @@
              initializing_actions, km_constant,                                &
              large_scale_forcing, large_scale_subsidence, latitude,            &
-             limiter_sedimentation, longitude,                                 &
+             longitude,                                 &
              loop_optimization, lsf_exception, masking_method, mg_cycles,      &
              mg_switch_to_pe0_level, mixing_length_1d, momentum_advec,         &
-             most_method, na_init, nc_const, nesting_offline,                  &
+             most_method, nesting_offline,                  &
              netcdf_precision, neutral, ngsrb,                                 &
              nsor, nsor_ini, nudging, nx, ny, nz, ocean, omega, omega_sor,     &
              outflow_source_plane, passive_scalar,                             &
-             prandtl_number, precipitation, psolver, pt_damping_factor,        &
+             prandtl_number, psolver, pt_damping_factor,        &
              pt_damping_width, pt_reference, pt_surface,                       &
              pt_surface_initial_change, pt_vertical_gradient,                  &
@@ -574,5 +573,5 @@
              roughness_length, sa_surface,                                     &
              sa_vertical_gradient, sa_vertical_gradient_level, scalar_advec,   &
-             scalar_rayleigh_damping, sigma_bulk,                              &
+             scalar_rayleigh_damping,                              &
              spinup_time, spinup_pt_amplitude, spinup_pt_mean,                 &
              statistic_regions, subs_vertical_gradient,                        &
@@ -592,10 +591,10 @@
              use_top_fluxes, use_ug_for_galilei_tr, use_upstream_for_tke,      &
              uv_heights, u_bulk, u_profile, vg_surface, vg_vertical_gradient,  &
-             vg_vertical_gradient_level, v_bulk, v_profile, ventilation_effect,&
+             vg_vertical_gradient_level, v_bulk, v_profile,&
              wall_adjustment, wall_heatflux, wall_humidityflux,                &
              wall_salinityflux, wall_scalarflux, y_shift, zeta_max, zeta_min,  &
              z0h_factor
 
-    NAMELIST /initialization_parameters/  aerosol_bulk, alpha_surface,         &
+    NAMELIST /initialization_parameters/  alpha_surface,         &
              approximation, bc_e_b,                                            &
              bc_lr, bc_ns, bc_p_b, bc_p_t, bc_pt_b, bc_pt_t, bc_q_b,           &
@@ -604,19 +603,18 @@
              building_length_y, building_wall_left, building_wall_south,       &
              calc_soil_moisture_during_spinup,                                 &
-             call_psolver_at_all_substeps, call_microphysics_at_all_substeps,  &
+             call_psolver_at_all_substeps,  &
              canyon_height,                                                    &
              canyon_width_x, canyon_width_y, canyon_wall_left,                 &
-             canyon_wall_south, c_sedimentation, cfl_factor, cloud_droplets,   &
-             cloud_physics, cloud_scheme, cloud_top_radiation,                 &
-             cloud_water_sedimentation,                                        &
-             collective_wait, collision_turbulence, complex_terrain,           &
+             canyon_wall_south, cfl_factor, cloud_droplets,   &
+             cloud_top_radiation,                 &
+             collective_wait, complex_terrain,           &
              conserve_volume_flow,                                             &
              conserve_volume_flow_mode, constant_flux_layer,                   &
-             coupling_start_time, curvature_solution_effects_bulk,             &
+             coupling_start_time,             &
              cycle_mg, damp_level_1d,                                          &
              data_output_during_spinup,                                        &
              day_of_year_init,                                                 &
              dissipation_1d,                                                   &
-             dp_external, dp_level_b, dp_smooth, dpdxy, dry_aerosol_radius,    &
+             dp_external, dp_level_b, dp_smooth, dpdxy,    &
              dt, dt_pr_1d, dt_run_control_1d, dt_spinup, dx, dy, dz, dz_max,   &
              dz_stretch_factor, dz_stretch_level, dz_stretch_level_start,      &
@@ -628,12 +626,12 @@
              initializing_actions, km_constant,                                &
              large_scale_forcing, large_scale_subsidence, latitude,            &
-             limiter_sedimentation, longitude,                                 &
+             longitude,                                 &
              loop_optimization, lsf_exception, masking_method, mg_cycles,      &
              mg_switch_to_pe0_level, mixing_length_1d, momentum_advec,         &
-             most_method, na_init, nc_const, nesting_offline,                  &
+             most_method, nesting_offline,                  &
              netcdf_precision, neutral, ngsrb,                                 &
              nsor, nsor_ini, nudging, nx, ny, nz, ocean, omega, omega_sor,     &
              outflow_source_plane, passive_scalar,                             &
-             prandtl_number, precipitation, psolver, pt_damping_factor,        &
+             prandtl_number, psolver, pt_damping_factor,        &
              pt_damping_width, pt_reference, pt_surface,                       &
              pt_surface_initial_change, pt_vertical_gradient,                  &
@@ -647,5 +645,5 @@
              roughness_length, sa_surface,                                     &
              sa_vertical_gradient, sa_vertical_gradient_level, scalar_advec,   &
-             scalar_rayleigh_damping, sigma_bulk,                              &
+             scalar_rayleigh_damping,                              &
              spinup_time, spinup_pt_amplitude, spinup_pt_mean,                 &
              statistic_regions, subs_vertical_gradient,                        &
@@ -665,5 +663,5 @@
              use_free_convection_scaling,                                      &
              uv_heights, u_bulk, u_profile, vg_surface, vg_vertical_gradient,  &
-             vg_vertical_gradient_level, v_bulk, v_profile, ventilation_effect,&
+             vg_vertical_gradient_level, v_bulk, v_profile,&
              wall_adjustment, wall_heatflux, wall_humidityflux,                &
              wall_salinityflux, wall_scalarflux, y_shift, zeta_max, zeta_min,  &
@@ -684,5 +682,5 @@
              mask_y_loop, mask_z_loop, netcdf_data_format, netcdf_deflate,     &
              normalizing_region, npex, npey, nz_do3d,                          &
-             precipitation_amount_interval, profile_columns, profile_rows,     &
+             profile_columns, profile_rows,     &
              restart_time, section_xy, section_xz, section_yz,                 &
              skip_time_data_output, skip_time_data_output_av, skip_time_dopr,  &
@@ -705,5 +703,5 @@
              mask_y_loop, mask_z_loop, netcdf_data_format, netcdf_deflate,     &
              normalizing_region, npex, npey, nz_do3d,                          &
-             precipitation_amount_interval, profile_columns, profile_rows,     &
+             profile_columns, profile_rows,     &
              restart_time, section_xy, section_xz, section_yz,                 &
              skip_time_data_output, skip_time_data_output_av, skip_time_dopr,  &
@@ -864,4 +862,8 @@
 
 !
+!--       Check if gust module is used and read &gust_par if required
+          CALL bcm_parin
+
+!
 !--       Check if urban surface model is used and read &urban_surface_par if required
           CALL usm_parin
Index: /palm/trunk/SOURCE/plant_canopy_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3248 2018-09-14 09:42:06Z sward
 ! Minor formating changes
 ! 
@@ -365,6 +368,8 @@
 
        USE control_parameters,                                                 &
-           ONLY: cloud_physics, coupling_char, message_string,                 &
-                 microphysics_seifert
+           ONLY: coupling_char, message_string
+
+       USE bulk_cloud_model_mod,                                               &
+           ONLY: bulk_cloud_model, microphysics_seifert
 
        USE netcdf_data_input_mod,                                              &
@@ -407,5 +412,5 @@
        ENDIF 
 
-       IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+       IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
           message_string = 'plant_canopy = .TRUE. requires cloud_scheme /=' // &
                           ' seifert_beheng'
Index: /palm/trunk/SOURCE/pmc_interface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/pmc_interface_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/pmc_interface_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -326,8 +329,7 @@
     USE control_parameters,                                                    &
         ONLY:  air_chemistry, bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r,  &
-               bc_dirichlet_s, cloud_physics, child_domain,                    &
+               bc_dirichlet_s, child_domain,                                   &
                constant_diffusion, constant_flux_layer,                        &
                coupling_char, dt_3d, dz, humidity, message_string,             &
-               microphysics_morrison, microphysics_seifert,                    &
                neutral, passive_scalar, rans_mode, rans_tke_e,                 &
                roughness_length, simulated_time, topography, volume_flow
@@ -348,4 +350,7 @@
         ONLY:  nbgp, nx, nxl, nxlg, nxlu, nxr, nxrg, ny, nyn, nyng, nys, nysg, &
                nysv, nz, nzb, nzt, wall_flags_0
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
 
     USE particle_attributes,                                                   &
@@ -1269,10 +1274,10 @@
           CALL pmc_set_dataarray_name( 'coarse', 'q'  ,'fine', 'q',  ierr )
 
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
             CALL pmc_set_dataarray_name( 'coarse', 'qc'  ,'fine', 'qc',  ierr )  
             CALL pmc_set_dataarray_name( 'coarse', 'nc'  ,'fine', 'nc',  ierr ) 
           ENDIF
 
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
              CALL pmc_set_dataarray_name( 'coarse', 'qr'  ,'fine', 'qr',  ierr )
              CALL pmc_set_dataarray_name( 'coarse', 'nr'  ,'fine', 'nr',  ierr ) 
@@ -3842,5 +3847,5 @@
                                       r2yo, r1zo, r2zo, 's' )
 
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
              CALL pmci_interp_tril_all ( qc, qcc, ico, jco, kco, r1xo, r2xo,   &
                                           r1yo, r2yo, r1zo, r2zo, 's' ) 
@@ -3849,5 +3854,5 @@
           ENDIF
 
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
              CALL pmci_interp_tril_all ( qr, qrc, ico, jco, kco, r1xo, r2xo,   &
                                          r1yo, r2yo, r1zo, r2zo, 's' )
@@ -4575,5 +4580,5 @@
                                           nzt_topo_nestbc_l, 'l', 's' )
 
-                IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
                    CALL pmci_interp_tril_lr( qc, qcc, ico, jco, kco, r1xo,     &
                                              r2xo, r1yo, r2yo, r1zo, r2zo,     &
@@ -4589,5 +4594,5 @@
                 ENDIF
 
-                IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
                    CALL pmci_interp_tril_lr( qr, qrc, ico, jco, kco, r1xo,     &
                                              r2xo, r1yo, r2yo, r1zo, r2zo,     &
@@ -4683,5 +4688,5 @@
                                           nzt_topo_nestbc_r, 'r', 's' )
 
-                IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
 
                    CALL pmci_interp_tril_lr( qc, qcc, ico, jco, kco, r1xo,     &
@@ -4700,5 +4705,5 @@
                 ENDIF
 
-                IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
 
      
@@ -4796,5 +4801,5 @@
                                           nzt_topo_nestbc_s, 's', 's' )
 
-                IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
 
                    CALL pmci_interp_tril_sn( qc, qcc, ico, jco, kco, r1xo,     &
@@ -4812,5 +4817,5 @@
                 ENDIF
 
-                IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
 
                    CALL pmci_interp_tril_sn( qr, qrc, ico, jco, kco, r1xo,     &
@@ -4907,5 +4912,5 @@
                                           nzt_topo_nestbc_n, 'n', 's' )
 
-                IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
 
                    CALL pmci_interp_tril_sn( qc, qcc, ico, jco, kco, r1xo,     &
@@ -4923,5 +4928,5 @@
                 ENDIF
 
-                IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
 
                    CALL pmci_interp_tril_sn( qr, qrc, ico, jco, kco, r1xo,     &
@@ -4994,5 +4999,5 @@
                                    r2yo, r1zo, r2zo, 's' )
 
-          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
 
              CALL pmci_interp_tril_t( qc, qcc, ico, jco, kco, r1xo, r2xo, r1yo,&
@@ -5004,5 +5009,5 @@
           ENDIF
 
-          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+          IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
 
 
@@ -5078,5 +5083,5 @@
                                   kfuo, ijkfc_s, 'q' )
 
-         IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+         IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
 
             CALL pmci_anterp_tophat( qc, qcc, kctu, iflo, ifuo, jflo, jfuo,    &
@@ -5088,5 +5093,5 @@
          ENDIF
 
-         IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+         IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
 
             CALL pmci_anterp_tophat( qr, qrc, kctu, iflo, ifuo, jflo, jfuo,    &
@@ -5902,5 +5907,5 @@
           ENDDO  
        ENDIF
-       IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+       IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
           DO  m = 1, bc_h(0)%ns
              i = bc_h(0)%i(m)            
@@ -5920,5 +5925,5 @@
        ENDIF
 
-       IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+       IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
           DO  m = 1, bc_h(0)%ns
              i = bc_h(0)%i(m)            
Index: /palm/trunk/SOURCE/prognostic_equations.f90
===================================================================
--- /palm/trunk/SOURCE/prognostic_equations.f90	(revision 3273)
+++ /palm/trunk/SOURCE/prognostic_equations.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! omp_get_thread_num now declared in omp directive
 ! 
@@ -289,4 +292,9 @@
                w, w_p
 
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  call_microphysics_at_all_substeps, bulk_cloud_model,            &
+               bcm_actions, microphysics_sat_adjust,                           &
+               microphysics_morrison, microphysics_seifert
+
     USE chemistry_model_mod,                                                   &
         ONLY:  chem_integrate, chem_prognostic_equations,                      &
@@ -300,11 +308,11 @@
 
     USE control_parameters,                                                    &
-        ONLY:  air_chemistry, call_microphysics_at_all_substeps,               &
-               cloud_physics, cloud_top_radiation, constant_diffusion,         &
+        ONLY:  air_chemistry,                                                  &
+               cloud_top_radiation, constant_diffusion,                        &
                dp_external, dp_level_ind_b, dp_smooth_factor, dpdxy, dt_3d,    &
                humidity, intermediate_timestep_count,                          &
                intermediate_timestep_count_max, large_scale_forcing,           &
-               large_scale_subsidence, microphysics_morrison,                  &
-               microphysics_seifert, microphysics_sat_adjust, neutral, nudging,&
+               large_scale_subsidence,                  &
+               neutral, nudging, &
                ocean, passive_scalar, plant_canopy,                            &
                prho_reference, prho_reference,                                 &
@@ -381,7 +389,4 @@
     USE lsf_nudging_mod,                                                       &
         ONLY:  ls_advec, nudge
-
-    USE microphysics_mod,                                                      &
-        ONLY:  microphysics_control
 
     USE plant_canopy_model_mod,                                                &
@@ -500,5 +505,5 @@
 !
 !-- If required, calculate cloud microphysics
-    IF ( cloud_physics  .AND.  .NOT. microphysics_sat_adjust  .AND.            &
+    IF ( bulk_cloud_model  .AND.  .NOT. microphysics_sat_adjust  .AND.         &
          ( intermediate_timestep_count == 1  .OR.                              &
            call_microphysics_at_all_substeps ) )                               &
@@ -508,5 +513,5 @@
        DO  i = nxlg, nxrg
           DO  j = nysg, nyng
-             CALL microphysics_control( i, j )
+             CALL bcm_actions( i, j )
            ENDDO
        ENDDO
@@ -995,5 +1000,5 @@
 !--          If required, calculate prognostic equations for cloud water content
 !--          and cloud drop concentration
-             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+             IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
 !
 !--             Calculate prognostic equation for cloud water content
@@ -1111,5 +1116,5 @@
 !--          If required, calculate prognostic equations for rain water content
 !--          and rain drop concentration
-             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+             IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
 !
 !--             Calculate prognostic equation for rain water content
@@ -1371,10 +1376,10 @@
 !
 !-- If required, calculate cloud microphysical impacts
-    IF ( cloud_physics  .AND.  .NOT. microphysics_sat_adjust  .AND.            &
+    IF ( bulk_cloud_model  .AND.  .NOT. microphysics_sat_adjust  .AND.         &
          ( intermediate_timestep_count == 1  .OR.                              &
            call_microphysics_at_all_substeps )                                 &
        )  THEN
        CALL cpu_log( log_point(51), 'microphysics', 'start' )
-       CALL microphysics_control
+       CALL bcm_actions
        CALL cpu_log( log_point(51), 'microphysics', 'stop' )
     ENDIF
@@ -1981,5 +1986,5 @@
 !--    If required, calculate prognostic equations for cloud water content
 !--    and cloud drop concentration
-       IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+       IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
 
           CALL cpu_log( log_point(67), 'qc-equation', 'start' )
@@ -2160,5 +2165,5 @@
 !--    If required, calculate prognostic equations for rain water content
 !--    and rain drop concentration
-       IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+       IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
 
           CALL cpu_log( log_point(52), 'qr-equation', 'start' )
Index: /palm/trunk/SOURCE/radiation_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3274)
@@ -28,4 +28,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3272 2018-09-24 10:16:32Z suehring
 ! - split direct and diffusion shortwave radiation using RRTMG rather than using
 !   calc_diffusion_radiation, in case of RRTMG
@@ -103,5 +106,5 @@
 ! 
 ! 3117 2018-07-11 09:59:11Z maronga
-! Bugfix: water vapor was not transfered to RRTMG when cloud_physics = .F.
+! Bugfix: water vapor was not transfered to RRTMG when bulk_cloud_model = .F.
 ! Bugfix: changed the calculation of RRTMG boundary conditions (Mohamed Salim)
 ! Bugfix: dry residual atmosphere is replaced by standard RRTMG atmosphere
@@ -437,21 +440,19 @@
  
     USE arrays_3d,                                                             &
-        ONLY:  dzw, hyp, nc, pt, q, ql, zu, zw
+        ONLY:  dzw, hyp, nc, pt, q, ql, zu, zw, exner, d_exner
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  c_p, g, lv_d_cp, l_v, pi, r_d, rho_l, solar_constant,           &
+               barometric_formula
 
     USE calc_mean_profile_mod,                                                 &
         ONLY:  calc_mean_profile
 
-    USE cloud_parameters,                                                      &
-        ONLY:  cp, l_d_cp, l_v, r_d, rho_l
-
-    USE constants,                                                             &
-        ONLY:  pi
-
     USE control_parameters,                                                    &
-        ONLY:  cloud_droplets, cloud_physics, coupling_char, dz, g,            &
+        ONLY:  cloud_droplets, coupling_char, dz,                              &
                humidity,                                                       &
                initializing_actions, io_blocks, io_group,                      &
                latitude, longitude, large_scale_forcing, lsf_surf,             &
-               message_string, microphysics_morrison, plant_canopy, pt_surface,&
+               message_string, plant_canopy, pt_surface,&
                rho_surface, surface_pressure, time_since_reference_point,      &
                urban_surface, land_surface, end_time, spinup_time, dt_spinup
@@ -475,6 +476,6 @@
     USE kinds
 
-    USE microphysics_mod,                                                      &
-        ONLY:  na_init, nc_const, sigma_gc
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model, microphysics_morrison, na_init, nc_const, sigma_gc
 
 #if defined ( __netcdf )
@@ -561,4 +562,6 @@
                                                          /)
 
+    REAL(wp), PARAMETER :: sigma_sb       = 5.67037321E-8_wp !< Stefan-Boltzmann constant
+
     INTEGER(iwp) :: albedo_type  = 9999999, & !< Albedo surface type
                     dots_rad     = 0          !< starting index for timeseries output 
@@ -578,8 +581,4 @@
                                                         !< will be considered. However fewer SVFs are expected.
                 radiation_interactions_on = .TRUE.      !< namelist flag to force RTM activiation regardless to vertical urban/land surface and trees
-
-
-    REAL(wp), PARAMETER :: sigma_sb       = 5.67037321E-8_wp,       & !< Stefan-Boltzmann constant
-                           solar_constant = 1368.0_wp                 !< solar constant at top of atmosphere
 
     REAL(wp) :: albedo = 9999999.9_wp,           & !< NAMELIST alpha
@@ -2274,6 +2273,6 @@
 !
 !--       Initialize RRTMG
-          IF ( lw_radiation )  CALL rrtmg_lw_ini ( cp )
-          IF ( sw_radiation )  CALL rrtmg_sw_ini ( cp )
+          IF ( lw_radiation )  CALL rrtmg_lw_ini ( c_p )
+          IF ( sw_radiation )  CALL rrtmg_sw_ini ( c_p )
 
 !
@@ -2335,7 +2334,4 @@
 
        INTEGER(iwp) ::  l         !< running index for surface orientation
-
-       REAL(wp)     ::  exn       !< Exner functions at surface
-       REAL(wp)     ::  exn1      !< Exner functions at first grid level or at urban layer top 
        REAL(wp)     ::  pt1       !< potential temperature at first grid level or mean value at urban layer top 
        REAL(wp)     ::  pt1_l     !< potential temperature at first grid level or mean value at urban layer top at local subdomain 
@@ -2355,5 +2351,4 @@
 !
 !--    Calculate value of the Exner function at model surface
-       exn = (surface_pressure / 1000.0_wp )**0.286_wp
 !
 !--    In case averaged radiation is used, calculate mean temperature and 
@@ -2361,21 +2356,20 @@
        IF ( average_radiation ) THEN   
           pt1   = 0.0_wp
-          IF ( cloud_physics  .OR.  cloud_droplets )  ql1   = 0.0_wp
+          IF ( bulk_cloud_model  .OR.  cloud_droplets )  ql1   = 0.0_wp
 
           pt1_l = SUM( pt(nzut,nys:nyn,nxl:nxr) )
-          IF ( cloud_physics  .OR.  cloud_droplets  )  ql1_l = SUM( ql(nzut,nys:nyn,nxl:nxr) )
+          IF ( bulk_cloud_model  .OR.  cloud_droplets  )  ql1_l = SUM( ql(nzut,nys:nyn,nxl:nxr) )
 
 #if defined( __parallel )      
           IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
           CALL MPI_ALLREDUCE( pt1_l, pt1, 1, MPI_REAL, MPI_SUM, comm2d, ierr )
-          IF ( cloud_physics  .OR.  cloud_droplets )                            &
+          IF ( bulk_cloud_model  .OR.  cloud_droplets )                            &
              CALL MPI_ALLREDUCE( ql1_l, ql1, 1, MPI_REAL, MPI_SUM, comm2d, ierr )
 #else
           pt1 = pt1_l 
-          IF ( cloud_physics  .OR.  cloud_droplets )  ql1 = ql1_l
+          IF ( bulk_cloud_model  .OR.  cloud_droplets )  ql1 = ql1_l
 #endif
- 
-          exn1 = ( hyp(nzut) / 100000.0_wp )**0.286_wp
-          IF ( cloud_physics  .OR.  cloud_droplets  )  pt1 = pt1 + l_d_cp / exn1 * ql1
+
+          IF ( bulk_cloud_model  .OR.  cloud_droplets  )  pt1 = pt1 + lv_d_cp / exner(nzut) * ql1
 !
 !--       Finally, divide by number of grid points
@@ -2418,10 +2412,8 @@
                 k = nzut
 
-                exn1 = ( hyp(k+1) / 100000.0_wp )**0.286_wp
-
                 surf%rad_sw_in  = solar_constant * sky_trans * zenith(0)
                 surf%rad_sw_out = albedo_urb * surf%rad_sw_in
                 
-                surf%rad_lw_in  = 0.8_wp * sigma_sb * (pt1 * exn1)**4
+                surf%rad_lw_in  = 0.8_wp * sigma_sb * (pt1 * exner(k+1))**4
 
                 surf%rad_lw_out = emissivity_urb * sigma_sb * (t_rad_urb)**4   &
@@ -2443,6 +2435,4 @@
                    j = surf%j(m)
                    k = surf%k(m)
-
-                   exn1 = (hyp(k) / 100000.0_wp )**0.286_wp
 
                    surf%rad_sw_in(m) = solar_constant * sky_trans * zenith(0)
@@ -2469,5 +2459,5 @@
                                         )                                      &
                                         * sigma_sb                             &
-                                        * ( surf%pt_surface(m) * exn )**4
+                                        * ( surf%pt_surface(m) * exner(nzb) )**4
 
                    surf%rad_lw_out_change_0(m) =                               &
@@ -2479,12 +2469,12 @@
                                         surf%emissivity(ind_wat_win,m)         &
                                       ) * 3.0_wp * sigma_sb                    &
-                                      * ( surf%pt_surface(m) * exn )** 3
-
-
-                   IF ( cloud_physics  .OR.  cloud_droplets  )  THEN
-                      pt1 = pt(k,j,i) + l_d_cp / exn1 * ql(k,j,i)
-                      surf%rad_lw_in(m)  = 0.8_wp * sigma_sb * (pt1 * exn1)**4
+                                      * ( surf%pt_surface(m) * exner(nzb) )** 3
+
+
+                   IF ( bulk_cloud_model  .OR.  cloud_droplets  )  THEN
+                      pt1 = pt(k,j,i) + lv_d_cp / exner(k) * ql(k,j,i)
+                      surf%rad_lw_in(m)  = 0.8_wp * sigma_sb * (pt1 * exner(k))**4
                    ELSE
-                      surf%rad_lw_in(m)  = 0.8_wp * sigma_sb * (pt(k,j,i) * exn1)**4
+                      surf%rad_lw_in(m)  = 0.8_wp * sigma_sb * (pt(k,j,i) * exner(k))**4
                    ENDIF
 
@@ -2524,6 +2514,4 @@
        INTEGER(iwp) ::  l         !< running index for surface orientation
 
-       REAL(wp)     ::  exn       !< Exner functions at surface
-       REAL(wp)     ::  exn1      !< Exner functions at first grid level
        REAL(wp)     ::  pt1       !< potential temperature at first grid level or mean value at urban layer top 
        REAL(wp)     ::  pt1_l     !< potential temperature at first grid level or mean value at urban layer top at local subdomain 
@@ -2531,9 +2519,6 @@
        REAL(wp)     ::  ql1_l     !< liquid water mixing ratio at first grid level or mean value at urban layer top at local subdomain 
 
-       TYPE(surf_type), POINTER ::  surf !< pointer on respective surface type, used to generalize routine   
-
-!
-!--    Calculate value of the Exner function
-       exn = (surface_pressure / 1000.0_wp )**0.286_wp
+       TYPE(surf_type), POINTER ::  surf !< pointer on respective surface type, used to generalize routine
+
 !
 !--    In case averaged radiation is used, calculate mean temperature and 
@@ -2541,19 +2526,19 @@
        IF ( average_radiation ) THEN   
           pt1   = 0.0_wp
-          IF ( cloud_physics  .OR.  cloud_droplets )  ql1   = 0.0_wp
+          IF ( bulk_cloud_model  .OR.  cloud_droplets )  ql1   = 0.0_wp
 
           pt1_l = SUM( pt(nzut,nys:nyn,nxl:nxr) )
-          IF ( cloud_physics  .OR.  cloud_droplets )  ql1_l = SUM( ql(nzut,nys:nyn,nxl:nxr) )
+          IF ( bulk_cloud_model  .OR.  cloud_droplets )  ql1_l = SUM( ql(nzut,nys:nyn,nxl:nxr) )
 
 #if defined( __parallel )      
           IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
           CALL MPI_ALLREDUCE( pt1_l, pt1, 1, MPI_REAL, MPI_SUM, comm2d, ierr )
-          IF ( cloud_physics  .OR.  cloud_droplets )                             &
+          IF ( bulk_cloud_model  .OR.  cloud_droplets )                             &
              CALL MPI_ALLREDUCE( ql1_l, ql1, 1, MPI_REAL, MPI_SUM, comm2d, ierr )
 #else
           pt1 = pt1_l
-          IF ( cloud_physics  .OR.  cloud_droplets )  ql1 = ql1_l
+          IF ( bulk_cloud_model  .OR.  cloud_droplets )  ql1 = ql1_l
 #endif
-          IF ( cloud_physics  .OR.  cloud_droplets )  pt1 = pt1 + l_d_cp / exn1 * ql1
+          IF ( bulk_cloud_model  .OR.  cloud_droplets )  pt1 = pt1 + lv_d_cp / exner(nzut+1) * ql1
 !
 !--       Finally, divide by number of grid points
@@ -2595,12 +2580,7 @@
              IF ( average_radiation ) THEN
 
-                ! set height above canopy
-                k = nzut
-
                 surf%rad_net = net_radiation
-! MS: Wyh k + 1 ?
-                exn1 = (hyp(k+1) / 100000.0_wp )**0.286_wp
-
-                surf%rad_lw_in  = 0.8_wp * sigma_sb * (pt1 * exn1)**4
+
+                surf%rad_lw_in  = 0.8_wp * sigma_sb * (pt1 * exner(nzut+1))**4
 
                 surf%rad_lw_out = emissivity_urb * sigma_sb * (t_rad_urb)**4   &
@@ -2636,12 +2616,10 @@
                    surf%rad_net(m) = net_radiation
 
-                   exn1 = (hyp(k) / 100000.0_wp )**0.286_wp
-
-                   IF ( cloud_physics  .OR.  cloud_droplets )  THEN
-                      pt1 = pt(k,j,i) + l_d_cp / exn1 * ql(k,j,i)
-                      surf%rad_lw_in(m)  = 0.8_wp * sigma_sb * (pt1 * exn1)**4
+                   IF ( bulk_cloud_model  .OR.  cloud_droplets )  THEN
+                      pt1 = pt(k,j,i) + lv_d_cp / exner(k) * ql(k,j,i)
+                      surf%rad_lw_in(m)  = 0.8_wp * sigma_sb * (pt1 * exner(k))**4
                    ELSE
                       surf%rad_lw_in(m)  = 0.8_wp * sigma_sb *                 &
-                                             ( pt(k,j,i) * exn1 )**4
+                                             ( pt(k,j,i) * exner(k) )**4
                    ENDIF
 
@@ -2656,5 +2634,5 @@
                                         )                                      &
                                       * sigma_sb                               &
-                                      * ( surf%pt_surface(m) * exn )**4
+                                      * ( surf%pt_surface(m) * exner(nzb) )**4
 
                    surf%rad_sw_in(m) = ( surf%rad_net(m) - surf%rad_lw_in(m)   &
@@ -2954,5 +2932,5 @@
           rrtm_tlev(0,nzb+1) = t_rad_urb
 
-          IF ( cloud_physics )  THEN
+          IF ( bulk_cloud_model )  THEN
 
              CALL calc_mean_profile( ql, 54 )
@@ -2962,5 +2940,5 @@
              DO k = nzb+1, nzt+1
                 rrtm_tlay(0,k) = pt_av(k) * ( (hyp(k) ) / 100000._wp       &
-                                 )**.286_wp + l_d_cp * ql_av(k)
+                                 )**.286_wp + lv_d_cp * ql_av(k)
                 rrtm_h2ovmr(0,k) = mol_mass_air_d_wv * (q_av(k) - ql_av(k))
              ENDDO
@@ -3013,5 +2991,5 @@
           rrtm_icld   = 0
 
-          IF ( cloud_physics )  THEN
+          IF ( bulk_cloud_model )  THEN
              DO k = nzb+1, nzt+1
                 rrtm_cliqwp(0,k) =  ql_av(k) * 1000._wp *                   &
@@ -3133,29 +3111,26 @@
 !--             Prepare profiles of temperature and H2O volume mixing ratio
                 DO  m = surf_lsm_h%start_index(j,i), surf_lsm_h%end_index(j,i)
-                   rrtm_tlev(0,nzb+1) = surf_lsm_h%pt_surface(m) * &
-                                    ( surface_pressure / 1000.0_wp )**0.286_wp
+                   rrtm_tlev(0,nzb+1) = surf_lsm_h%pt_surface(m) * exner(nzb)
                 ENDDO
                 DO  m = surf_usm_h%start_index(j,i), surf_usm_h%end_index(j,i)
-                   rrtm_tlev(0,nzb+1) = surf_usm_h%pt_surface(m) * &
-                                    ( surface_pressure / 1000.0_wp )**0.286_wp
+                   rrtm_tlev(0,nzb+1) = surf_usm_h%pt_surface(m) * exner(nzb)
                 ENDDO
 
 
-                IF ( cloud_physics )  THEN
+                IF ( bulk_cloud_model )  THEN
                    DO k = nzb+1, nzt+1
-                      rrtm_tlay(0,k) = pt(k,j,i) * ( (hyp(k) ) / 100000.0_wp   &
-                                       )**0.286_wp + l_d_cp * ql(k,j,i)
+                      rrtm_tlay(0,k) = pt(k,j,i) * exner(k)                    &
+                                        + lv_d_cp * ql(k,j,i)
                       rrtm_h2ovmr(0,k) = mol_mass_air_d_wv * (q(k,j,i) - ql(k,j,i))
                    ENDDO
                 ELSEIF ( cloud_droplets )  THEN
                    DO k = nzb+1, nzt+1
-                      rrtm_tlay(0,k) = pt(k,j,i) * ( (hyp(k) ) / 100000.0_wp   &
-                                       )**0.286_wp + l_d_cp * ql(k,j,i)
+                      rrtm_tlay(0,k) = pt(k,j,i) * exner(k)                     &
+                                        + lv_d_cp * ql(k,j,i)
                       rrtm_h2ovmr(0,k) = mol_mass_air_d_wv * q(k,j,i) 
                    ENDDO
                 ELSE
                    DO k = nzb+1, nzt+1
-                      rrtm_tlay(0,k) = pt(k,j,i) * ( (hyp(k) ) / 100000.0_wp   &
-                                       )**0.286_wp
+                      rrtm_tlay(0,k) = pt(k,j,i) * exner(k)
                    ENDDO
 
@@ -3202,5 +3177,5 @@
                 rrtm_icld   = 0
 
-                IF ( cloud_physics  .OR.  cloud_droplets )  THEN
+                IF ( bulk_cloud_model  .OR.  cloud_droplets )  THEN
                    DO k = nzb+1, nzt+1
                       rrtm_cliqwp(0,k) =  ql(k,j,i) * 1000.0_wp *              &
@@ -3214,5 +3189,5 @@
 !
 !--                      Calculate cloud droplet effective radius
-                         IF ( cloud_physics )  THEN
+                         IF ( bulk_cloud_model )  THEN
 !
 !--                         Calculete effective droplet radius. In case of using 
@@ -3285,6 +3260,5 @@
                                surf_lsm_h%frac(ind_wat_win,m)   *              &
                                surf_lsm_h%emissivity(ind_wat_win,m)
-                   rrtm_tsfc = surf_lsm_h%pt_surface(m) *                      &
-                                       (surface_pressure / 1000.0_wp )**0.286_wp
+                   rrtm_tsfc = surf_lsm_h%pt_surface(m) * exner(nzb)
                 ENDDO             
                 DO  m = surf_usm_h%start_index(j,i), surf_usm_h%end_index(j,i)
@@ -3295,6 +3269,5 @@
                                surf_usm_h%frac(ind_wat_win,m)   *              &
                                surf_usm_h%emissivity(ind_wat_win,m)
-                   rrtm_tsfc = surf_usm_h%pt_surface(m) *                      &
-                                       (surface_pressure / 1000.0_wp )**0.286_wp
+                   rrtm_tsfc = surf_usm_h%pt_surface(m) * exner(nzb)
                 ENDDO
 !
@@ -3985,9 +3958,10 @@
        ALLOCATE ( rrtm_plev(0:0,nzb+1:nzt_rad+2)   )
 
-       t_surface = pt_surface * ( surface_pressure / 1000.0_wp )**0.286_wp
+       t_surface = pt_surface * exner(nzb)
        DO k = nzb+1, nzt+1
           rrtm_play(0,k) = hyp(k) * 0.01_wp
-          rrtm_plev(0,k) = surface_pressure * ( (t_surface - g/cp * zw(k-1)) / &
-                         t_surface )**(1.0_wp/0.286_wp)
+          rrtm_plev(0,k) = barometric_formula(zw(k-1),                         &
+                              pt_surface * exner(nzb), &
+                              surface_pressure )
        ENDDO
 
@@ -4406,7 +4380,4 @@
  SUBROUTINE radiation_tendency_ij ( i, j, tend )
 
-    USE cloud_parameters,                                                      &
-        ONLY:  pt_d_t
-
     IMPLICIT NONE
 
@@ -4421,5 +4392,5 @@
        DO k = nzb+1, nzt+1
           tend(k,j,i) = tend(k,j,i) + (rad_lw_hr(k,j,i) + rad_sw_hr(k,j,i))    &
-                                         * pt_d_t(k) * d_seconds_hour
+                                         * d_exner(k) * d_seconds_hour
        ENDDO
 #endif
@@ -4437,7 +4408,4 @@
  SUBROUTINE radiation_tendency ( tend )
 
-    USE cloud_parameters,                                                      &
-        ONLY:  pt_d_t
-
     USE indices,                                                               &
         ONLY:  nxl, nxr, nyn, nys
@@ -4457,5 +4425,5 @@
              DO k = nzb+1, nzt+1
                 tend(k,j,i) = tend(k,j,i) + ( rad_lw_hr(k,j,i)                 &
-                                          +  rad_sw_hr(k,j,i) ) * pt_d_t(k)    &
+                                          +  rad_sw_hr(k,j,i) ) * d_exner(k)   &
                                           * d_seconds_hour
              ENDDO
@@ -4525,7 +4493,7 @@
 #if ! defined( __nopointer )
      IF ( plant_canopy )  THEN
-         pchf_prep(:) = r_d * (hyp(nzub:nzut) / 100000.0_wp)**0.286_wp &
-                     / (cp * hyp(nzub:nzut) * dx*dy*dz(1)) !< equals to 1 / (rho * c_p * Vbox * T)
-         pctf_prep(:) = r_d * (hyp(nzub:nzut) / 100000.0_wp)**0.286_wp &
+         pchf_prep(:) = r_d * exner(nzub:nzut)                                 &
+                     / (c_p * hyp(nzub:nzut) * dx*dy*dz(1)) !< equals to 1 / (rho * c_p * Vbox * T)
+         pctf_prep(:) = r_d * exner(nzub:nzut)                                 &
                      / (l_v * hyp(nzub:nzut) * dx*dy*dz(1))
      ENDIF
@@ -5032,5 +5000,5 @@
 !         k                = surf_lsm_h%k(m)
 !         pt_surf_urb_l    = pt_surf_urb_l + surf_lsm_h%pt_surface(m)            &
-!                            * ( hyp(k) / 100000.0_wp )**0.286_wp
+!                            * exner(k)
 !         count_surfaces_l = count_surfaces_l + 1.0_wp
 !      ENDDO
@@ -5038,5 +5006,5 @@
 !         k                = surf_usm_h%k(m)
 !         pt_surf_urb_l    = pt_surf_urb_l + surf_usm_h%pt_surface(m)            &
-!                            * ( hyp(k) / 100000.0_wp )**0.286_wp
+!                            * exner(k)
 !         count_surfaces_l = count_surfaces_l + 1.0_wp
 !      ENDDO
@@ -5045,11 +5013,10 @@
 !            k                = surf_lsm_v(l)%k(m)
 !            pt_surf_urb_l    = pt_surf_urb_l + surf_lsm_v(l)%pt_surface(m)      &
-!                            * ( hyp(k) / 100000.0_wp )**0.286_wp
+!                            * exner(k)
 !            count_surfaces_l = count_surfaces_l + 1.0_wp
 !         ENDDO
 !         DO  m = 1, surf_usm_v(l)%ns
 !            k                = surf_usm_v(l)%k(m)
-!            pt_surf_urb_l    = pt_surf_urb_l + surf_usm_v(l)%pt_surface(m)      &
-!                            * ( hyp(k) / 100000.0_wp )**0.286_wp
+!            pt_surf_urb_l    = pt_surf_urb_l + surf_usm_v(l)%pt_surface(m) * exner(k)
 !            count_surfaces_l = count_surfaces_l + 1.0_wp
 !         ENDDO
Index: /palm/trunk/SOURCE/read_restart_data_mod.f90
===================================================================
--- /palm/trunk/SOURCE/read_restart_data_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/read_restart_data_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -111,4 +114,7 @@
                   q_init, ref_state, s_init, sa_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
@@ -125,9 +131,4 @@
        USE indices,                                                            &
            ONLY:  nz, nx, nx_on_file, ny, ny_on_file
-
-       USE microphysics_mod,                                                   &
-           ONLY:  c_sedimentation, collision_turbulence,                       &
-                  cloud_water_sedimentation, limiter_sedimentation,            &
-                  nc_const, ventilation_effect
 
        USE model_1d_mod,                                                       &
@@ -332,6 +333,4 @@
              CASE ( 'building_wall_south' )
                 READ ( 13 )  building_wall_south
-             CASE ( 'c_sedimentation' )
-                READ ( 13 )  c_sedimentation
              CASE ( 'call_psolver_at_all_substeps' )
                 READ ( 13 )  call_psolver_at_all_substeps
@@ -350,16 +349,8 @@
              CASE ( 'cloud_droplets' )
                 READ ( 13 )  cloud_droplets
-             CASE ( 'cloud_physics' )
-                READ ( 13 )  cloud_physics
-             CASE ( 'cloud_scheme' )
-                READ ( 13 )  cloud_scheme
              CASE ( 'cloud_top_radiation' )
                 READ ( 13 )  cloud_top_radiation
-             CASE ( 'cloud_water_sedimentation' )
-                READ ( 13 )  cloud_water_sedimentation
              CASE ( 'collective_wait' )
                 READ ( 13 )  collective_wait
-             CASE ( 'collision_turbulence' )
-                READ ( 13 )  collision_turbulence
              CASE ( 'conserve_volume_flow' )
                 READ ( 13 )  conserve_volume_flow
@@ -461,6 +452,4 @@
              CASE ( 'latitude' )
                 READ ( 13 )  latitude
-             CASE ( 'limiter_sedimentation' )
-                READ ( 13 )  limiter_sedimentation
              CASE ( 'longitude' )
                 READ ( 13 )  longitude
@@ -484,6 +473,4 @@
              CASE ( 'most_method' )
                 READ ( 13 )  most_method
-             CASE ( 'nc_const' )
-                READ ( 13 )  nc_const
              CASE ( 'netcdf_precision' )
                 READ ( 13 )  netcdf_precision
@@ -520,6 +507,4 @@
              CASE ( 'prandtl_number' )
                 READ ( 13 )  prandtl_number
-             CASE ( 'precipitation' )
-                READ ( 13 ) precipitation
              CASE ( 'psolver' )
                 READ ( 13 )  psolver
@@ -732,6 +717,4 @@
              CASE ( 'v_max_ijk' )
                 READ ( 13 )  v_max_ijk
-             CASE ( 'ventilation_effect' )
-                READ ( 13 )  ventilation_effect
              CASE ( 'vg' )
                 READ ( 13 )  vg
@@ -786,4 +769,6 @@
              CASE DEFAULT
 
+                IF ( .NOT. found ) CALL bcm_rrd_global( found )
+
                 IF ( .NOT. found ) CALL wtm_rrd_global( found )
 
@@ -1061,6 +1046,6 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  e, kh, km, p, pt, q, ql, qc, nc, nr, prr, precipitation_amount, &
-               qr, s, sa, u, u_m_l, u_m_n, u_m_r, u_m_s, v, v_m_l, v_m_n,      &
+        ONLY:  e, kh, km, p, pt, q, ql, &
+               s, sa, 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
 
@@ -1073,5 +1058,5 @@
         ONLY:  cpu_log, log_point_s
 
-    USE gust_mod,                                                           &
+    USE gust_mod,                                                              &
         ONLY :  gust_rrd_local
 
@@ -1084,4 +1069,7 @@
     USE land_surface_model_mod,                                                &
         ONLY:  lsm_rrd_local
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY :  bcm_rrd_local
 
     USE particle_attributes,                                                   &
@@ -1469,31 +1457,4 @@
                       tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
-                CASE ( 'nc' )
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   nc(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =             &
-                      tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
-                CASE ( 'nc_av' )
-                   IF ( .NOT. ALLOCATED( nc_av ) )  THEN
-                      ALLOCATE( nc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   nc_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
-                      tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
-
-                CASE ( 'nr' )
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   nr(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =             &
-                      tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
-                CASE ( 'nr_av' )
-                   IF ( .NOT. ALLOCATED( nr_av ) )  THEN
-                      ALLOCATE( nr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   nr_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
-                      tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
                 CASE ( 'p' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
@@ -1525,26 +1486,4 @@
                       tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
-                CASE ( 'prr' )
-                   IF ( .NOT. ALLOCATED( prr ) )  THEN
-                      ALLOCATE( prr(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   prr(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =            &
-                      tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
-                CASE ( 'prr_av' )
-                   IF ( .NOT. ALLOCATED( prr_av ) )  THEN
-                      ALLOCATE( prr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   prr_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =         &
-                      tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
-                CASE ( 'precipitation_amount' )
-                   IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   precipitation_amount(nysc-nbgp:nync+nbgp,                   &
-                                        nxlc-nbgp:nxrc+nbgp)  =                &
-                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
                 CASE ( 'pt' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
@@ -1573,17 +1512,4 @@
                       tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
-                CASE ( 'qc' )
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   qc(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =             &
-                      tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
-                CASE ( 'qc_av' )
-                   IF ( .NOT. ALLOCATED( qc_av ) )  THEN
-                      ALLOCATE( qc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   qc_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
-                      tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
                 CASE ( 'ql' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
@@ -1597,17 +1523,4 @@
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
                    ql_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
-                      tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
-                CASE ( 'qr' )
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   qr(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =             &
-                      tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
-
-                CASE ( 'qr_av' )
-                   IF ( .NOT. ALLOCATED( qr_av ) )  THEN
-                      ALLOCATE( qr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   qr_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =          &
                       tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
@@ -1968,4 +1881,12 @@
 
 !
+!--                Read microphysics module restart data
+                   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 )
+
+!
 !--                Read surface related variables
                    IF ( .NOT. found ) CALL surface_rrd_local( i, k, nxlf,      &
Index: /palm/trunk/SOURCE/sum_up_3d_data.f90
===================================================================
--- /palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3273)
+++ /palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -204,22 +207,24 @@
         ONLY:  dzw, e, heatflux_output_conversion, nc, nr, p, prr, pt,         &
                q, qc, ql, ql_c, ql_v, qr, rho_ocean, s, sa, u, v, vpt, w,      &
-               waterflux_output_conversion
+               waterflux_output_conversion, d_exner
 
     USE averaging,                                                             &
-        ONLY:  e_av, ghf_av, lpt_av, lwp_av, nc_av,     &
-               nr_av,                                                          &
-               ol_av, p_av, pc_av, pr_av, prr_av, pt_av, q_av, qc_av, ql_av,   &
-               ql_c_av, ql_v_av, ql_vp_av, qr_av, qsws_av, qv_av, r_a_av,      &
+        ONLY:  e_av, ghf_av, lpt_av, lwp_av,                                   &
+               ol_av, p_av, pc_av, pr_av, pt_av, q_av, ql_av,                  &
+               ql_c_av, ql_v_av, ql_vp_av, qsws_av, qv_av, r_a_av,             &
                rho_ocean_av, s_av, sa_av, shf_av, ssws_av, ts_av, tsurf_av,    &
                u_av, us_av, v_av, vpt_av, w_av, z0_av, z0h_av, z0q_av
 
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  c_p, lv_d_cp, l_v
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model, bcm_3d_data_averaging
+
     USE chemistry_model_mod,                                                   &
         ONLY:  chem_3d_data_averaging
 
-    USE cloud_parameters,                                                      &
-        ONLY:  cp, l_d_cp, l_v, pt_d_t
-
     USE control_parameters,                                                    &
-        ONLY:  air_chemistry, average_count_3d, cloud_physics, doav, doav_n,   &
+        ONLY:  air_chemistry, average_count_3d, doav, doav_n,                  &
                land_surface, rho_surface, urban_surface, uv_exposure,          &
                varnamelength
@@ -323,16 +328,4 @@
                 lwp_av = 0.0_wp
 
-             CASE ( 'nc' )
-                IF ( .NOT. ALLOCATED( nc_av ) )  THEN
-                   ALLOCATE( nc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                ENDIF
-                nc_av = 0.0_wp
-
-             CASE ( 'nr' )
-                IF ( .NOT. ALLOCATED( nr_av ) )  THEN
-                   ALLOCATE( nr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                ENDIF
-                nr_av = 0.0_wp
-
              CASE ( 'ol*' )
                 IF ( .NOT. ALLOCATED( ol_av ) )  THEN
@@ -359,10 +352,4 @@
                 pr_av = 0.0_wp
 
-             CASE ( 'prr' )
-                IF ( .NOT. ALLOCATED( prr_av ) )  THEN
-                   ALLOCATE( prr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                ENDIF
-                prr_av = 0.0_wp
-
              CASE ( 'pt' )
                 IF ( .NOT. ALLOCATED( pt_av ) )  THEN
@@ -377,10 +364,4 @@
                 q_av = 0.0_wp
 
-             CASE ( 'qc' )
-                IF ( .NOT. ALLOCATED( qc_av ) )  THEN
-                   ALLOCATE( qc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                ENDIF
-                qc_av = 0.0_wp
-
              CASE ( 'ql' )
                 IF ( .NOT. ALLOCATED( ql_av ) )  THEN
@@ -406,10 +387,4 @@
                 ENDIF
                 ql_vp_av = 0.0_wp
-
-             CASE ( 'qr' )
-                IF ( .NOT. ALLOCATED( qr_av ) )  THEN
-                   ALLOCATE( qr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-                ENDIF
-                qr_av = 0.0_wp
 
              CASE ( 'qsws*' )
@@ -532,4 +507,10 @@
 !--             Turbulence closure module
                 CALL tcm_3d_data_averaging( 'allocate', doav(ii) )
+
+!
+!--             Microphysics module quantities
+                IF ( bulk_cloud_model )  THEN
+                   CALL bcm_3d_data_averaging( 'allocate', doav(ii) )
+                ENDIF
 
 !
@@ -654,26 +635,4 @@
              ENDIF
 
-          CASE ( 'nc' )
-             IF ( ALLOCATED( nc_av ) ) THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      DO  k = nzb, nzt+1
-                         nc_av(k,j,i) = nc_av(k,j,i) + nc(k,j,i)
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDIF
-
-          CASE ( 'nr' )
-             IF ( ALLOCATED( nr_av ) ) THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      DO  k = nzb, nzt+1
-                         nr_av(k,j,i) = nr_av(k,j,i) + nr(k,j,i)
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDIF
-
           CASE ( 'ol*' )
              IF ( ALLOCATED( ol_av ) ) THEN
@@ -758,18 +717,7 @@
              ENDIF
 
-          CASE ( 'prr' )
-             IF ( ALLOCATED( prr_av ) ) THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      DO  k = nzb, nzt+1
-                         prr_av(k,j,i) = prr_av(k,j,i) + prr(k,j,i)
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDIF
-
           CASE ( 'pt' )
              IF ( ALLOCATED( pt_av ) ) THEN
-                IF ( .NOT. cloud_physics ) THEN
+                IF ( .NOT. bulk_cloud_model ) THEN
                 DO  i = nxlg, nxrg
                    DO  j = nysg, nyng
@@ -783,6 +731,6 @@
                    DO  j = nysg, nyng
                       DO  k = nzb, nzt+1
-                            pt_av(k,j,i) = pt_av(k,j,i) + pt(k,j,i) + l_d_cp * &
-                                                          pt_d_t(k) * ql(k,j,i)
+                            pt_av(k,j,i) = pt_av(k,j,i) + pt(k,j,i) + lv_d_cp * &
+                                                          d_exner(k) * ql(k,j,i)
                          ENDDO
                       ENDDO
@@ -797,15 +745,4 @@
                       DO  k = nzb, nzt+1
                          q_av(k,j,i) = q_av(k,j,i) + q(k,j,i)
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDIF
-
-          CASE ( 'qc' )
-             IF ( ALLOCATED( qc_av ) ) THEN
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      DO  k = nzb, nzt+1
-                         qc_av(k,j,i) = qc_av(k,j,i) + qc(k,j,i)
                       ENDDO
                    ENDDO
@@ -862,15 +799,4 @@
                             ENDIF
                          ENDDO
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDIF
-
-          CASE ( 'qr' )
-             IF ( ALLOCATED( qr_av ) ) THEN 
-                DO  i = nxlg, nxrg
-                   DO  j = nysg, nyng
-                      DO  k = nzb, nzt+1
-                         qr_av(k,j,i) = qr_av(k,j,i) + qr(k,j,i)
                       ENDDO
                    ENDDO
@@ -1001,9 +927,9 @@
                          m = surf_lsm_h%end_index(j,i)
                          shf_av(j,i) = shf_av(j,i) +                           &
-                                         surf_lsm_h%shf(m) * cp
+                                         surf_lsm_h%shf(m) * c_p
                       ELSEIF ( match_usm )  THEN
                          m = surf_usm_h%end_index(j,i)
                          shf_av(j,i) = shf_av(j,i) +                           &
-                                         surf_usm_h%shf(m) * cp
+                                         surf_usm_h%shf(m) * c_p
                       ENDIF
                    ENDDO
@@ -1265,4 +1191,10 @@
 
 !
+!--          Microphysics module quantities
+             IF ( bulk_cloud_model )  THEN
+                CALL bcm_3d_data_averaging( 'sum', doav(ii) )
+             ENDIF
+
+!
 !--          Land surface quantity
              IF ( land_surface )  THEN
Index: /palm/trunk/SOURCE/surface_coupler.f90
===================================================================
--- /palm/trunk/SOURCE/surface_coupler.f90	(revision 3273)
+++ /palm/trunk/SOURCE/surface_coupler.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3049 2018-05-29 13:52:36Z Giersch
 ! Error messages revised
 ! 
@@ -101,6 +104,6 @@
         ONLY:  pt, rho_ocean, sa, total_2d_a, total_2d_o, u, v
 
-    USE cloud_parameters,                                                      &
-        ONLY:  cp, l_v
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  c_p, l_v
 
     USE control_parameters,                                                    &
@@ -477,5 +480,5 @@
              
              surf_def_h(2)%shf(m) = surf_def_h(2)%shf(m) +                     &
-                                    surf_def_h(2)%qsws(m) * l_v / cp
+                                    surf_def_h(2)%qsws(m) * l_v / c_p
 !
 !--          ...and convert it to a salinity flux at the sea surface (top)
@@ -498,5 +501,5 @@
           j = surf_def_h(2)%j(m)
           surf_def_h(2)%shf(m) = surf_def_h(2)%shf(m) / rho_ocean(nzt,j,i) *   &
-                                 cp / cpw
+                                 c_p / cpw
 
           surf_def_h(2)%usws(m) = surf_def_h(2)%usws(m) / rho_ocean(nzt,j,i)
Index: /palm/trunk/SOURCE/surface_layer_fluxes_mod.f90
===================================================================
--- /palm/trunk/SOURCE/surface_layer_fluxes_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/surface_layer_fluxes_mod.f90	(revision 3274)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3271 2018-09-24 08:20:34Z suehring
 ! Comment revised
 ! 
@@ -231,25 +234,21 @@
     USE arrays_3d,                                                             &
         ONLY:  e, kh, nc, nr, pt, q, ql, qc, qr, s, u, v, vpt, w, zu, zw,      &
-               drho_air_zw, rho_air_zw
+               drho_air_zw, rho_air_zw, d_exner
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  g, kappa, lv_d_cp, pi
 
     USE chem_modules,                                                          &
         ONLY:  constant_csflux, nvar
 
-    USE cloud_parameters,                                                      &
-        ONLY:  l_d_cp, pt_d_t
-
-    USE constants,                                                             &
-        ONLY:  pi
-
     USE cpulog
 
     USE control_parameters,                                                    &
-        ONLY:  air_chemistry, cloud_droplets, cloud_physics,                   &
-               constant_heatflux, constant_scalarflux,                         &     
-               constant_waterflux, coupling_mode, g, humidity, ibc_e_b,        &
-               ibc_pt_b, initializing_actions, kappa,                          &
+        ONLY:  air_chemistry, cloud_droplets,                                  &
+               constant_heatflux, constant_scalarflux,                         &
+               constant_waterflux, coupling_mode, humidity, ibc_e_b,           &
+               ibc_pt_b, initializing_actions,                                 &
                intermediate_timestep_count, intermediate_timestep_count_max,   &
-               land_surface, large_scale_forcing, lsf_surf,                    &
-               message_string, microphysics_morrison, microphysics_seifert,    &
+               land_surface, large_scale_forcing, lsf_surf, message_string,    &
                most_method, neutral, passive_scalar, pt_surface, q_surface,    &
                run_coupled, surface_pressure, simulated_time, terminate_run,   &
@@ -264,4 +263,7 @@
 
     USE kinds
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
 
     USE pegrid
@@ -1467,5 +1469,5 @@
 
              ENDDO
-          ELSEIF ( cloud_physics  .OR.  cloud_droplets )  THEN
+          ELSEIF ( bulk_cloud_model  .OR.  cloud_droplets )  THEN
              !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo )
              DO  m = 1, surf%ns
@@ -1596,9 +1598,9 @@
           k   = surf%k(m)
 
-          IF ( cloud_physics ) THEN
-             surf%pt1(m) = pt(k,j,i) + l_d_cp * pt_d_t(k) * ql(k,j,i)
+          IF ( bulk_cloud_model ) THEN
+             surf%pt1(m) = pt(k,j,i) + lv_d_cp * d_exner(k) * ql(k,j,i)
              surf%qv1(m) = q(k,j,i) - ql(k,j,i)
           ELSEIF( cloud_droplets ) THEN
-             surf%pt1(m) = pt(k,j,i) + l_d_cp * pt_d_t(k) * ql(k,j,i)
+             surf%pt1(m) = pt(k,j,i) + lv_d_cp * d_exner(k) * ql(k,j,i)
              surf%qv1(m) = q(k,j,i) 
           ELSE
@@ -1820,5 +1822,5 @@
              ENDIF
 
-             IF ( cloud_physics  .OR.  cloud_droplets )  THEN
+             IF ( bulk_cloud_model  .OR.  cloud_droplets )  THEN
                !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo )
                 DO  m = 1, surf%ns   
@@ -1927,5 +1929,5 @@
 !
 !--    If required compute qc* and nc*
-       IF ( cloud_physics  .AND.  microphysics_morrison  .AND.                 &
+       IF ( bulk_cloud_model  .AND.  microphysics_morrison  .AND.              &
             .NOT. surf_vertical )  THEN
           !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo )
@@ -1953,5 +1955,5 @@
 !
 !--    If required compute qr* and nr*
-       IF ( cloud_physics  .AND.  microphysics_seifert  .AND.                  &
+       IF ( bulk_cloud_model  .AND.  microphysics_seifert  .AND.               &
             .NOT. surf_vertical )  THEN
           !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo )
@@ -2145,5 +2147,5 @@
 !
 !--       Compute (turbulent) fluxes of cloud water content and cloud drop conc.
-          IF ( cloud_physics  .AND.  microphysics_morrison  .AND.              &
+          IF ( bulk_cloud_model  .AND.  microphysics_morrison  .AND.           &
                .NOT. downward)  THEN
              !$OMP PARALLEL DO PRIVATE( i, j )
@@ -2159,5 +2161,5 @@
 !
 !--       Compute (turbulent) fluxes of rain water content and rain drop conc.
-          IF ( cloud_physics  .AND.  microphysics_seifert  .AND.               &
+          IF ( bulk_cloud_model  .AND.  microphysics_seifert  .AND.            &
                .NOT. downward)  THEN
              !$OMP PARALLEL DO PRIVATE( i, j )
Index: /palm/trunk/SOURCE/surface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/surface_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/surface_mod.f90	(revision 3274)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3254 2018-09-17 10:53:57Z suehring
 ! Remove redundant subroutine argument
 ! 
@@ -207,5 +210,5 @@
     USE chem_modules
 
-    USE control_parameters               
+    USE control_parameters
 
     USE indices,                                                               &
@@ -505,4 +508,8 @@
                                                     !< in the domain (required to activiate RTM)
 
+    LOGICAL ::  surf_bulk_cloud_model = .FALSE.                          !< use cloud microphysics
+    LOGICAL ::  surf_microphysics_morrison = .FALSE.                  !< use 2-moment Morrison (add. prog. eq. for nc and qc)
+    LOGICAL ::  surf_microphysics_seifert = .FALSE.                   !< use 2-moment Seifert and Beheng scheme
+
 
     SAVE
@@ -543,5 +550,6 @@
     PUBLIC bc_h, ind_pav_green, ind_veg_wall, ind_wat_win, ns_h_on_file,       &
            ns_v_on_file, surf_def_h, surf_def_v, surf_lsm_h, surf_lsm_v,       &
-           surf_usm_h, surf_usm_v, surf_type, vertical_surfaces_exist
+           surf_usm_h, surf_usm_v, surf_type, vertical_surfaces_exist,         &
+           surf_bulk_cloud_model, surf_microphysics_morrison, surf_microphysics_seifert
 !
 !-- Public subroutines and functions
@@ -1090,5 +1098,5 @@
 !
 !--       
-       IF ( cloud_physics .AND. microphysics_morrison)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_morrison)  THEN
           DEALLOCATE ( surfaces%qcs )
           DEALLOCATE ( surfaces%ncs )
@@ -1098,5 +1106,5 @@
 !
 !--       
-       IF ( cloud_physics .AND. microphysics_seifert)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_seifert)  THEN
           DEALLOCATE ( surfaces%qrs )
           DEALLOCATE ( surfaces%nrs )
@@ -1217,5 +1225,5 @@
 !
 !--       
-       IF ( cloud_physics .AND. microphysics_morrison)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_morrison)  THEN
           ALLOCATE ( surfaces%qcs(1:surfaces%ns)   )
           ALLOCATE ( surfaces%ncs(1:surfaces%ns)   )
@@ -1225,5 +1233,5 @@
 !
 !--       
-       IF ( cloud_physics .AND. microphysics_seifert)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_seifert)  THEN
           ALLOCATE ( surfaces%qrs(1:surfaces%ns)   )
           ALLOCATE ( surfaces%nrs(1:surfaces%ns)   )
@@ -1286,5 +1294,5 @@
 !
 !--       
-       IF ( cloud_physics .AND. microphysics_morrison)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_morrison)  THEN
           DEALLOCATE ( surfaces%qcsws )
           DEALLOCATE ( surfaces%ncsws )
@@ -1292,5 +1300,5 @@
 !
 !--       
-       IF ( cloud_physics .AND. microphysics_seifert)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_seifert)  THEN
           DEALLOCATE ( surfaces%qrsws )
           DEALLOCATE ( surfaces%nrsws )
@@ -1358,5 +1366,5 @@
 !
 !--       
-       IF ( cloud_physics .AND. microphysics_morrison)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_morrison)  THEN
           ALLOCATE ( surfaces%qcsws(1:surfaces%ns) )
           ALLOCATE ( surfaces%ncsws(1:surfaces%ns) )
@@ -1364,5 +1372,5 @@
 !
 !--       
-       IF ( cloud_physics .AND. microphysics_seifert)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_seifert)  THEN
           ALLOCATE ( surfaces%qrsws(1:surfaces%ns) )
           ALLOCATE ( surfaces%nrsws(1:surfaces%ns) )
@@ -1473,5 +1481,5 @@
        DEALLOCATE ( surfaces%vpt1 )
 
-       IF ( cloud_physics .AND. microphysics_seifert)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_seifert)  THEN
           DEALLOCATE ( surfaces%qcs )
           DEALLOCATE ( surfaces%ncs )
@@ -1480,5 +1488,5 @@
        ENDIF
 
-       IF ( cloud_physics .AND. microphysics_seifert)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_seifert)  THEN
           DEALLOCATE ( surfaces%qrs )
           DEALLOCATE ( surfaces%nrs )
@@ -1598,5 +1606,5 @@
        ALLOCATE ( surfaces%vpt1(1:surfaces%ns) )
 
-       IF ( cloud_physics .AND. microphysics_seifert)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_seifert)  THEN
           ALLOCATE ( surfaces%qcs(1:surfaces%ns)   )
           ALLOCATE ( surfaces%ncs(1:surfaces%ns)   )
@@ -1605,5 +1613,5 @@
        ENDIF
 
-       IF ( cloud_physics .AND. microphysics_seifert)  THEN
+       IF ( surf_bulk_cloud_model .AND. surf_microphysics_seifert)  THEN
           ALLOCATE ( surfaces%qrs(1:surfaces%ns)   )
           ALLOCATE ( surfaces%nrs(1:surfaces%ns)   )
@@ -2133,5 +2141,5 @@
              IF ( humidity )  THEN
                 surf%qs(num_h)   = 0.0_wp
-                IF ( cloud_physics .AND. microphysics_morrison)  THEN
+                IF ( surf_bulk_cloud_model .AND. surf_microphysics_morrison)  THEN
                    surf%qcs(num_h) = 0.0_wp
                    surf%ncs(num_h) = 0.0_wp
@@ -2141,5 +2149,5 @@
 
                 ENDIF
-                IF ( cloud_physics .AND. microphysics_seifert)  THEN
+                IF ( surf_bulk_cloud_model .AND. surf_microphysics_seifert)  THEN
                    surf%qrs(num_h) = 0.0_wp
                    surf%nrs(num_h) = 0.0_wp
@@ -2314,9 +2322,9 @@
              IF ( humidity )  THEN
                 surf%qsws(num_h) = 0.0_wp
-                IF ( cloud_physics  .AND.  microphysics_morrison ) THEN
+                IF ( surf_bulk_cloud_model  .AND.  surf_microphysics_morrison ) THEN
                    surf%ncsws(num_h) = 0.0_wp
                    surf%qcsws(num_h) = 0.0_wp
                 ENDIF
-                IF ( cloud_physics  .AND.  microphysics_seifert ) THEN
+                IF ( surf_bulk_cloud_model  .AND.  surf_microphysics_seifert ) THEN
                    surf%nrsws(num_h) = 0.0_wp
                    surf%qrsws(num_h) = 0.0_wp
@@ -2449,5 +2457,5 @@
 !
 !--             Following wall fluxes are assumed to be zero 
-                IF ( cloud_physics .AND. microphysics_morrison)  THEN
+                IF ( surf_bulk_cloud_model .AND. surf_microphysics_morrison)  THEN
                    surf%qcs(num_v) = 0.0_wp
                    surf%ncs(num_v) = 0.0_wp
@@ -2456,5 +2464,5 @@
                    surf%ncsws(num_v) = 0.0_wp
                 ENDIF
-                IF ( cloud_physics .AND. microphysics_seifert)  THEN
+                IF ( surf_bulk_cloud_model .AND. surf_microphysics_seifert)  THEN
                    surf%qrs(num_v) = 0.0_wp
                    surf%nrs(num_v) = 0.0_wp
Index: /palm/trunk/SOURCE/swap_timelevel.f90
===================================================================
--- /palm/trunk/SOURCE/swap_timelevel.f90	(revision 3273)
+++ /palm/trunk/SOURCE/swap_timelevel.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -138,4 +141,7 @@
 #endif
 
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model, bcm_swap_timelevel
+
     USE chemistry_model_mod,                                                   &
         ONLY:  chem_swap_timelevel 
@@ -148,7 +154,6 @@
 
     USE control_parameters,                                                    &
-        ONLY:  air_chemistry, cloud_physics, humidity, land_surface,           &
-               microphysics_morrison, microphysics_seifert, neutral, ocean,    &
-               passive_scalar, timestep_count, urban_surface
+        ONLY:  air_chemistry, humidity, land_surface,                          &
+               neutral, ocean, passive_scalar, timestep_count, urban_surface
 
     USE gust_mod,                                                              &
@@ -205,15 +210,11 @@
     IF ( humidity )  THEN
        q = q_p
-       IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
-          qc = qc_p
-          nc = nc_p
-       ENDIF             
-       IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
-          qr = qr_p
-          nr = nr_p
-       ENDIF
     ENDIF
 
     IF ( passive_scalar )  s = s_p             
+
+    IF ( humidity  .AND.  bulk_cloud_model )  THEN
+       CALL bcm_swap_timelevel ( 0 )
+    ENDIF
 
     IF ( land_surface )  THEN
@@ -249,12 +250,4 @@
           IF ( humidity )  THEN
              q => q_1;    q_p => q_2
-             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
-                qc => qc_1;    qc_p => qc_2
-                nc => nc_1;    nc_p => nc_2
-             ENDIF
-             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
-                qr => qr_1;    qr_p => qr_2
-                nr => nr_1;    nr_p => nr_2
-             ENDIF
           ENDIF
           IF ( passive_scalar )  THEN
@@ -279,12 +272,4 @@
           IF ( humidity )  THEN
              q => q_2;    q_p => q_1
-             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
-                qc => qc_2;    qc_p => qc_1
-                nc => nc_2;    nc_p => nc_1
-             ENDIF
-             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
-                qr => qr_2;    qr_p => qr_1
-                nr => nr_2;    nr_p => nr_1
-             ENDIF
           ENDIF
           IF ( passive_scalar )  THEN
@@ -300,4 +285,8 @@
     CALL tcm_swap_timelevel ( MOD( timestep_count, 2) )
 
+    IF ( humidity  .AND.  bulk_cloud_model )  THEN
+       CALL bcm_swap_timelevel ( MOD( timestep_count, 2) )
+    ENDIF
+
     IF ( land_surface )  THEN
        CALL lsm_swap_timelevel ( MOD( timestep_count, 2) )
Index: /palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90
===================================================================
--- /palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/synthetic_turbulence_generator_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3248 2018-09-14 09:42:06Z sward
 ! Minor formating changes
 ! 
@@ -145,5 +148,5 @@
         ONLY:  mean_inflow_profiles, u, v, w
 
-    USE constants,                                                             &
+    USE basic_constants_and_equations_mod,                                     &
         ONLY:  pi
 
Index: /palm/trunk/SOURCE/time_integration.f90
===================================================================
--- /palm/trunk/SOURCE/time_integration.f90	(revision 3273)
+++ /palm/trunk/SOURCE/time_integration.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -381,5 +384,5 @@
                bc_lr_cyc, bc_ns_cyc, bc_pt_t_val, bc_q_t_val,                  &
                call_psolver_at_all_substeps,  child_domain, cloud_droplets,    &
-               cloud_physics, constant_flux_layer, constant_heatflux,          &
+               constant_flux_layer, constant_heatflux,                         &
                create_disturbances, dopr_n, constant_diffusion, coupling_mode, &
                coupling_start_time, current_timestep_number,                   &
@@ -393,6 +396,5 @@
                intermediate_timestep_count_max,                                &
                land_surface, large_scale_forcing,                              &
-               loop_optimization, lsf_surf, lsf_vert, masks,                   &
-               microphysics_morrison, microphysics_seifert, mid,               &
+               loop_optimization, lsf_surf, lsf_vert, masks, mid,              &
                multi_agent_system_end, multi_agent_system_start,               &
                nesting_offline, neutral, nr_timesteps_this_run, nudging,       &
@@ -441,6 +443,7 @@
                lsf_nesting_offline, lsf_nesting_offline_mass_conservation
 
-    USE microphysics_mod,                                                      &
-        ONLY: collision_turbulence
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY: bulk_cloud_model, calc_liquid_water_content,                     &
+              collision_turbulence, microphysics_morrison, microphysics_seifert
 
     USE netcdf_data_input_mod,                                                 &
@@ -757,9 +760,9 @@
           IF ( humidity )  THEN
              CALL exchange_horiz( q_p, nbgp )
-             IF ( cloud_physics .AND. microphysics_morrison )  THEN
+             IF ( bulk_cloud_model .AND. microphysics_morrison )  THEN
                 CALL exchange_horiz( qc_p, nbgp )
                 CALL exchange_horiz( nc_p, nbgp )
              ENDIF
-             IF ( cloud_physics .AND. microphysics_seifert )  THEN
+             IF ( bulk_cloud_model .AND. microphysics_seifert )  THEN
                 CALL exchange_horiz( qr_p, nbgp )
                 CALL exchange_horiz( nr_p, nbgp )
@@ -822,9 +825,9 @@
                    CALL exchange_horiz( q, nbgp )
 
-                   IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
+                   IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
                        CALL exchange_horiz( qc, nbgp )
                        CALL exchange_horiz( nc, nbgp )
                    ENDIF
-                   IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
+                   IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
                        CALL exchange_horiz( qr, nbgp )
                        CALL exchange_horiz( nr, nbgp )
@@ -960,5 +963,5 @@
 !
 !--       If required, compute liquid water content
-          IF ( cloud_physics )  THEN
+          IF ( bulk_cloud_model )  THEN
              CALL calc_liquid_water_content
           ENDIF
Index: /palm/trunk/SOURCE/time_integration_spinup.f90
===================================================================
--- /palm/trunk/SOURCE/time_integration_spinup.f90	(revision 3273)
+++ /palm/trunk/SOURCE/time_integration_spinup.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -577,5 +580,5 @@
     FUNCTION solar_angle( local_time ) 
 
-       USE constants,                                                          &
+       USE basic_constants_and_equations_mod,                                  &
        ONLY:  pi
       
Index: /palm/trunk/SOURCE/timestep.f90
===================================================================
--- /palm/trunk/SOURCE/timestep.f90	(revision 3273)
+++ /palm/trunk/SOURCE/timestep.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -154,5 +157,5 @@
     USE kinds
 
-    USE microphysics_mod,                                                      &
+    USE bulk_cloud_model_mod,                                                  &
         ONLY:  dt_precipitation
 
Index: /palm/trunk/SOURCE/tridia_solver_mod.f90
===================================================================
--- /palm/trunk/SOURCE/tridia_solver_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/tridia_solver_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3241 2018-09-12 15:02:00Z raasch
 ! unused variables removed
 ! 
@@ -109,4 +112,7 @@
  
 
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  pi
+
     USE indices,                                                               &
         ONLY:  nx, ny, nz
@@ -145,6 +151,4 @@
        USE arrays_3d,                                                          &
            ONLY:  ddzu_pres, ddzw, rho_air_zw
-
-       USE kinds
 
        IMPLICIT NONE
@@ -186,7 +190,4 @@
               ONLY:  tric, rho_air
 
-          USE constants,                                                       &
-              ONLY:  pi
-
           USE control_parameters,                                              &
               ONLY:  ibc_p_b, ibc_p_t
@@ -195,6 +196,4 @@
               ONLY:  dx, dy
 
-
-          USE kinds
 
           IMPLICIT NONE
@@ -282,6 +281,4 @@
               ONLY:  ibc_p_b, ibc_p_t
 
-          USE kinds
-
           IMPLICIT NONE
 
@@ -358,6 +355,4 @@
               ONLY:  ibc_p_b, ibc_p_t
 
-          USE kinds
-
           IMPLICIT NONE
 
@@ -431,6 +426,4 @@
           USE arrays_3d,                                                       & 
               ONLY:  tri, tric
-
-          USE kinds
 
           IMPLICIT NONE
@@ -482,6 +475,4 @@
            ONLY:  ibc_p_b, ibc_p_t
 
-       USE kinds
-
        IMPLICIT NONE
 
@@ -533,9 +524,4 @@
 !------------------------------------------------------------------------------!
        SUBROUTINE maketri_1dd( j )
-
-          USE constants,                                                       &
-              ONLY:  pi
-
-          USE kinds
 
           IMPLICIT NONE
Index: /palm/trunk/SOURCE/turbulence_closure_mod.f90
===================================================================
--- /palm/trunk/SOURCE/turbulence_closure_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/turbulence_closure_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3245 2018-09-13 14:08:16Z knoop
 ! unused variables removed, shortest_distance has wp now
 ! 
@@ -154,8 +157,11 @@
 #endif
 
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  g, kappa, lv_d_cp, lv_d_rd
+
     USE control_parameters,                                                    &
         ONLY:  constant_diffusion, dt_3d, e_init, humidity,                    &
                initializing_actions, intermediate_timestep_count,              &
-               intermediate_timestep_count_max, kappa, km_constant,            &
+               intermediate_timestep_count_max, km_constant,                   &
                les_dynamic, les_mw, ocean, plant_canopy, prandtl_number,       &
                prho_reference, pt_reference, rans_mode, rans_tke_e, rans_tke_l,&
@@ -950,5 +956,5 @@
  SUBROUTINE tcm_init_arrays
 
-    USE microphysics_mod,                                                      &
+    USE bulk_cloud_model_mod,                                                  &
         ONLY:  collision_turbulence
 
@@ -2598,11 +2604,8 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  ddzw, dd2zu, drho_air_zw, q, ql
-
-    USE cloud_parameters,                                                      &
-        ONLY:  l_d_cp, l_d_r, pt_d_t, t_d_pt
+        ONLY:  ddzw, dd2zu, drho_air_zw, q, ql, d_exner, exner
 
     USE control_parameters,                                                    &
-        ONLY:  cloud_droplets, cloud_physics, constant_flux_layer, g, neutral, &
+        ONLY:  cloud_droplets, constant_flux_layer, neutral,                   &
                rho_reference, use_single_reference_value, use_surface_fluxes,  &
                use_top_fluxes
@@ -2610,4 +2613,7 @@
     USE grid_variables,                                                        &
         ONLY:  ddx, dx, ddy, dy
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model
 
     USE surface_mod,                                                           &
@@ -3067,5 +3073,5 @@
 !--                Flag 9 is used to mask top fluxes, flag 30 to mask
 !--                surface fluxes
-                   IF ( .NOT. cloud_physics .AND. .NOT. cloud_droplets ) THEN
+                   IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
                       k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                       k2 = 0.61_wp * pt(k,j,i)
@@ -3083,17 +3089,17 @@
                                           BTEST( wall_flags_0(k,j,i), 9 )      &
                                         )
-                   ELSE IF ( cloud_physics )  THEN
+                   ELSE IF ( bulk_cloud_model )  THEN
                       IF ( ql(k,j,i) == 0.0_wp )  THEN
                          k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                          k2 = 0.61_wp * pt(k,j,i)
                       ELSE
-                         theta = pt(k,j,i) + pt_d_t(k) * l_d_cp * ql(k,j,i)
-                         temp  = theta * t_d_pt(k)
+                         theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
+                         temp  = theta * exner(k)
                          k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *                  &
                                        ( q(k,j,i) - ql(k,j,i) ) *              &
-                              ( 1.0_wp + 0.622_wp * l_d_r / temp ) ) /         &
-                              ( 1.0_wp + 0.622_wp * l_d_r * l_d_cp *           &
+                              ( 1.0_wp + 0.622_wp * lv_d_rd / temp ) ) /       &
+                              ( 1.0_wp + 0.622_wp * lv_d_rd * lv_d_cp *        &
                               ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
-                         k2 = theta * ( l_d_cp / temp * k1 - 1.0_wp )
+                         k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                       ENDIF
                       tend(k,j,i) = tend(k,j,i) - kh(k,j,i) *                  &
@@ -3144,20 +3150,20 @@
                          k = surf_def_h(l)%k(m)
 
-                         IF ( .NOT. cloud_physics .AND. .NOT. cloud_droplets ) THEN
+                         IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
                             k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                             k2 = 0.61_wp * pt(k,j,i)
-                         ELSE IF ( cloud_physics )  THEN
+                         ELSE IF ( bulk_cloud_model )  THEN
                             IF ( ql(k,j,i) == 0.0_wp )  THEN
                                k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                                k2 = 0.61_wp * pt(k,j,i)
                             ELSE
-                               theta = pt(k,j,i) + pt_d_t(k) * l_d_cp * ql(k,j,i)
-                               temp  = theta * t_d_pt(k)
+                               theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
+                               temp  = theta * exner(k)
                                k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *            &
                                           ( q(k,j,i) - ql(k,j,i) ) *           &
-                                 ( 1.0_wp + 0.622_wp * l_d_r / temp ) ) /      &
-                                 ( 1.0_wp + 0.622_wp * l_d_r * l_d_cp *        &
+                                 ( 1.0_wp + 0.622_wp * lv_d_rd / temp ) ) /    &
+                                 ( 1.0_wp + 0.622_wp * lv_d_rd * lv_d_cp *     &
                                  ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
-                               k2 = theta * ( l_d_cp / temp * k1 - 1.0_wp )
+                               k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                             ENDIF
                          ELSE IF ( cloud_droplets )  THEN
@@ -3181,20 +3187,20 @@
                       k = surf_lsm_h%k(m)
 
-                      IF ( .NOT. cloud_physics .AND. .NOT. cloud_droplets ) THEN
+                      IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
                          k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                          k2 = 0.61_wp * pt(k,j,i)
-                      ELSE IF ( cloud_physics )  THEN
+                      ELSE IF ( bulk_cloud_model )  THEN
                          IF ( ql(k,j,i) == 0.0_wp )  THEN
                             k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                             k2 = 0.61_wp * pt(k,j,i)
                          ELSE
-                            theta = pt(k,j,i) + pt_d_t(k) * l_d_cp * ql(k,j,i)
-                            temp  = theta * t_d_pt(k)
+                            theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
+                            temp  = theta * exner(k)
                             k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *               &
                                           ( q(k,j,i) - ql(k,j,i) ) *           &
-                                 ( 1.0_wp + 0.622_wp * l_d_r / temp ) ) /      &
-                                 ( 1.0_wp + 0.622_wp * l_d_r * l_d_cp *        &
+                                 ( 1.0_wp + 0.622_wp * lv_d_rd / temp ) ) /    &
+                                 ( 1.0_wp + 0.622_wp * lv_d_rd * lv_d_cp *     &
                                  ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
-                            k2 = theta * ( l_d_cp / temp * k1 - 1.0_wp )
+                            k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                          ENDIF
                       ELSE IF ( cloud_droplets )  THEN
@@ -3217,20 +3223,20 @@
                       k = surf_usm_h%k(m)
 
-                      IF ( .NOT. cloud_physics .AND. .NOT. cloud_droplets ) THEN
+                      IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
                          k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                          k2 = 0.61_wp * pt(k,j,i)
-                      ELSE IF ( cloud_physics )  THEN
+                      ELSE IF ( bulk_cloud_model )  THEN
                          IF ( ql(k,j,i) == 0.0_wp )  THEN
                             k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                             k2 = 0.61_wp * pt(k,j,i)
                          ELSE
-                            theta = pt(k,j,i) + pt_d_t(k) * l_d_cp * ql(k,j,i)
-                            temp  = theta * t_d_pt(k)
+                            theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
+                            temp  = theta * exner(k)
                             k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *               &
                                           ( q(k,j,i) - ql(k,j,i) ) *           &
-                                 ( 1.0_wp + 0.622_wp * l_d_r / temp ) ) /      &
-                                 ( 1.0_wp + 0.622_wp * l_d_r * l_d_cp *        &
+                                 ( 1.0_wp + 0.622_wp * lv_d_rd / temp ) ) /    &
+                                 ( 1.0_wp + 0.622_wp * lv_d_rd * lv_d_cp *     &
                                  ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
-                            k2 = theta * ( l_d_cp / temp * k1 - 1.0_wp )
+                            k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                          ENDIF
                       ELSE IF ( cloud_droplets )  THEN
@@ -3260,20 +3266,20 @@
                       k = surf_def_h(2)%k(m)
 
-                      IF ( .NOT. cloud_physics .AND. .NOT. cloud_droplets ) THEN
+                      IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
                          k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                          k2 = 0.61_wp * pt(k,j,i)
-                      ELSE IF ( cloud_physics )  THEN
+                      ELSE IF ( bulk_cloud_model )  THEN
                          IF ( ql(k,j,i) == 0.0_wp )  THEN
                             k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                             k2 = 0.61_wp * pt(k,j,i)
                          ELSE
-                            theta = pt(k,j,i) + pt_d_t(k) * l_d_cp * ql(k,j,i)
-                            temp  = theta * t_d_pt(k)
+                            theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
+                            temp  = theta * exner(k)
                             k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *               &
                                        ( q(k,j,i) - ql(k,j,i) ) *              &
-                              ( 1.0_wp + 0.622_wp * l_d_r / temp ) ) /         &
-                              ( 1.0_wp + 0.622_wp * l_d_r * l_d_cp *           &
+                              ( 1.0_wp + 0.622_wp * lv_d_rd / temp ) ) /       &
+                              ( 1.0_wp + 0.622_wp * lv_d_rd * lv_d_cp *        &
                               ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
-                            k2 = theta * ( l_d_cp / temp * k1 - 1.0_wp )
+                            k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                          ENDIF
                       ELSE IF ( cloud_droplets )  THEN
@@ -3316,11 +3322,8 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  ddzw, dd2zu, drho_air_zw, q, ql
-
-    USE cloud_parameters,                                                      &
-        ONLY:  l_d_cp, l_d_r, pt_d_t, t_d_pt
+        ONLY:  ddzw, dd2zu, drho_air_zw, q, ql, d_exner, exner
 
     USE control_parameters,                                                    &
-        ONLY:  cloud_droplets, cloud_physics, constant_flux_layer, g, neutral, &
+        ONLY:  cloud_droplets, constant_flux_layer, neutral,                &
                rho_reference, use_single_reference_value, use_surface_fluxes,  &
                use_top_fluxes
@@ -3328,4 +3331,7 @@
     USE grid_variables,                                                        &
         ONLY:  ddx, dx, ddy, dy
+
+    USE bulk_cloud_model_mod,                                                  &
+        ONLY:  bulk_cloud_model
 
     USE surface_mod,                                                           &
@@ -3864,5 +3870,5 @@
 !
 !--          Flag 9 is used to mask top fluxes, flag 30 to mask surface fluxes
-             IF ( .NOT. cloud_physics .AND. .NOT. cloud_droplets )  THEN
+             IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets )  THEN
                 k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                 k2 = 0.61_wp * pt(k,j,i)
@@ -3880,17 +3886,17 @@
                                         )
 
-             ELSE IF ( cloud_physics )  THEN
+             ELSE IF ( bulk_cloud_model )  THEN
                 IF ( ql(k,j,i) == 0.0_wp )  THEN
                    k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                    k2 = 0.61_wp * pt(k,j,i)
                 ELSE
-                   theta = pt(k,j,i) + pt_d_t(k) * l_d_cp * ql(k,j,i)
-                   temp  = theta * t_d_pt(k)
+                   theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
+                   temp  = theta * exner(k)
                    k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *                        &
                                  ( q(k,j,i) - ql(k,j,i) ) *                    &
-                        ( 1.0_wp + 0.622_wp * l_d_r / temp ) ) /               &
-                        ( 1.0_wp + 0.622_wp * l_d_r * l_d_cp *                 &
+                        ( 1.0_wp + 0.622_wp * lv_d_rd / temp ) ) /             &
+                        ( 1.0_wp + 0.622_wp * lv_d_rd * lv_d_cp *              &
                         ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
-                   k2 = theta * ( l_d_cp / temp * k1 - 1.0_wp )
+                   k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                 ENDIF
                 tend(k,j,i) = tend(k,j,i) - kh(k,j,i) * g /                    &
@@ -3934,20 +3940,20 @@
                    k = surf_def_h(l)%k(m)
 
-                   IF ( .NOT. cloud_physics .AND. .NOT. cloud_droplets ) THEN
+                   IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
                       k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                       k2 = 0.61_wp * pt(k,j,i)
-                   ELSE IF ( cloud_physics )  THEN
+                   ELSE IF ( bulk_cloud_model )  THEN
                       IF ( ql(k,j,i) == 0.0_wp )  THEN
                          k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                          k2 = 0.61_wp * pt(k,j,i)
                       ELSE
-                        theta = pt(k,j,i) + pt_d_t(k) * l_d_cp * ql(k,j,i)
-                        temp  = theta * t_d_pt(k)
+                        theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
+                        temp  = theta * exner(k)
                         k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *                   &
                                    ( q(k,j,i) - ql(k,j,i) ) *                  &
-                          ( 1.0_wp + 0.622_wp * l_d_r / temp ) ) /             &
-                          ( 1.0_wp + 0.622_wp * l_d_r * l_d_cp *               & 
+                          ( 1.0_wp + 0.622_wp * lv_d_rd / temp ) ) /           &
+                          ( 1.0_wp + 0.622_wp * lv_d_rd * lv_d_cp *            &
                           ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
-                        k2 = theta * ( l_d_cp / temp * k1 - 1.0_wp )
+                        k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                       ENDIF
                    ELSE IF ( cloud_droplets )  THEN
@@ -3971,20 +3977,20 @@
                 k = surf_lsm_h%k(m)
 
-                IF ( .NOT. cloud_physics .AND. .NOT. cloud_droplets ) THEN
+                IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
                     k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                     k2 = 0.61_wp * pt(k,j,i)
-                ELSE IF ( cloud_physics )  THEN
+                ELSE IF ( bulk_cloud_model )  THEN
                     IF ( ql(k,j,i) == 0.0_wp )  THEN
                        k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                        k2 = 0.61_wp * pt(k,j,i)
                     ELSE
-                       theta = pt(k,j,i) + pt_d_t(k) * l_d_cp * ql(k,j,i)
-                       temp  = theta * t_d_pt(k)
+                       theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
+                       temp  = theta * exner(k)
                        k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *                    &
                                      ( q(k,j,i) - ql(k,j,i) ) *                &
-                            ( 1.0_wp + 0.622_wp * l_d_r / temp ) ) /           &
-                            ( 1.0_wp + 0.622_wp * l_d_r * l_d_cp *             &
+                            ( 1.0_wp + 0.622_wp * lv_d_rd / temp ) ) /         &
+                            ( 1.0_wp + 0.622_wp * lv_d_rd * lv_d_cp *          &
                             ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
-                       k2 = theta * ( l_d_cp / temp * k1 - 1.0_wp )
+                       k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                    ENDIF
                 ELSE IF ( cloud_droplets )  THEN
@@ -4007,20 +4013,20 @@
                 k = surf_usm_h%k(m)
 
-                IF ( .NOT. cloud_physics .AND. .NOT. cloud_droplets ) THEN
+                IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets ) THEN
                     k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                     k2 = 0.61_wp * pt(k,j,i)
-                ELSE IF ( cloud_physics )  THEN
+                ELSE IF ( bulk_cloud_model )  THEN
                     IF ( ql(k,j,i) == 0.0_wp )  THEN
                        k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                        k2 = 0.61_wp * pt(k,j,i)
                     ELSE
-                       theta = pt(k,j,i) + pt_d_t(k) * l_d_cp * ql(k,j,i)
-                       temp  = theta * t_d_pt(k)
+                       theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
+                       temp  = theta * exner(k)
                        k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *                    &
                                      ( q(k,j,i) - ql(k,j,i) ) *                &
-                            ( 1.0_wp + 0.622_wp * l_d_r / temp ) ) /           &
-                            ( 1.0_wp + 0.622_wp * l_d_r * l_d_cp *             &
+                            ( 1.0_wp + 0.622_wp * lv_d_rd / temp ) ) /         &
+                            ( 1.0_wp + 0.622_wp * lv_d_rd * lv_d_cp *          &
                             ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
-                       k2 = theta * ( l_d_cp / temp * k1 - 1.0_wp )
+                       k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                    ENDIF
                 ELSE IF ( cloud_droplets )  THEN
@@ -4047,20 +4053,20 @@
 
 
-                IF ( .NOT. cloud_physics .AND. .NOT. cloud_droplets )  THEN
+                IF ( .NOT. bulk_cloud_model .AND. .NOT. cloud_droplets )  THEN
                    k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                    k2 = 0.61_wp * pt(k,j,i)
-                ELSE IF ( cloud_physics )  THEN
+                ELSE IF ( bulk_cloud_model )  THEN
                    IF ( ql(k,j,i) == 0.0_wp )  THEN
                       k1 = 1.0_wp + 0.61_wp * q(k,j,i)
                       k2 = 0.61_wp * pt(k,j,i)
                    ELSE
-                      theta = pt(k,j,i) + pt_d_t(k) * l_d_cp * ql(k,j,i)
-                      temp  = theta * t_d_pt(k)
+                      theta = pt(k,j,i) + d_exner(k) * lv_d_cp * ql(k,j,i)
+                      temp  = theta * exner(k)
                       k1 = ( 1.0_wp - q(k,j,i) + 1.61_wp *                     &
                                  ( q(k,j,i) - ql(k,j,i) ) *                    &
-                        ( 1.0_wp + 0.622_wp * l_d_r / temp ) ) /               &
-                        ( 1.0_wp + 0.622_wp * l_d_r * l_d_cp *                 &
+                        ( 1.0_wp + 0.622_wp * lv_d_rd / temp ) ) /             &
+                        ( 1.0_wp + 0.622_wp * lv_d_rd * lv_d_cp *              &
                         ( q(k,j,i) - ql(k,j,i) ) / ( temp * temp ) )
-                      k2 = theta * ( l_d_cp / temp * k1 - 1.0_wp )
+                      k2 = theta * ( lv_d_cp / temp * k1 - 1.0_wp )
                    ENDIF
                 ELSE IF ( cloud_droplets )  THEN
@@ -4100,5 +4106,5 @@
         ONLY:  ddx2, ddy2
 
-    USE microphysics_mod,                                                      &
+    USE bulk_cloud_model_mod,                                                  &
         ONLY:  collision_turbulence
 
@@ -4237,5 +4243,5 @@
         ONLY:  ddx2, ddy2
         
-    USE microphysics_mod,                                                      &
+    USE bulk_cloud_model_mod,                                                  &
         ONLY:  collision_turbulence
 
@@ -4476,5 +4482,5 @@
 
     USE control_parameters,                                                    &
-        ONLY:  atmos_ocean_sign, g, use_single_reference_value,                &
+        ONLY:  atmos_ocean_sign, use_single_reference_value,                   &
                wall_adjustment, wall_adjustment_factor
 
@@ -4533,5 +4539,5 @@
 
     USE control_parameters,                                                    &
-        ONLY:  atmos_ocean_sign, g, use_single_reference_value
+        ONLY:  atmos_ocean_sign, use_single_reference_value
 
     IMPLICIT NONE
Index: /palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3274)
@@ -28,4 +28,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3248 2018-09-14 09:42:06Z sward
 ! Minor formating changes
 ! 
@@ -331,13 +334,10 @@
 #if ! defined( __nopointer )
     USE arrays_3d,                                                             &
-        ONLY:  dzu, hyp, zu, pt, pt_1, pt_2, p, u, v, w, hyp, tend
+        ONLY:  dzu, hyp, zu, pt, pt_1, pt_2, p, u, v, w, hyp, tend, exner
 #endif
 
-    USE cloud_parameters,                                                      &
-        ONLY:  cp, r_d
-
-    USE constants,                                                             &
-        ONLY:  pi
-    
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  c_p, g, kappa, pi, r_d
+
     USE control_parameters,                                                    &
         ONLY:  coupling_start_time, topography, dt_3d, humidity,               &
@@ -346,7 +346,7 @@
                timestep_scheme, tsc, coupling_char, io_blocks, io_group,       &
                message_string, time_since_reference_point, surface_pressure,   &
-               g, pt_surface, large_scale_forcing, lsf_surf, spinup,           &
+               pt_surface, large_scale_forcing, lsf_surf, spinup,              &
                spinup_pt_mean, spinup_time, time_do3d, dt_do3d,                &
-               average_count_3d, varnamelength, urban_surface, kappa,          &
+               average_count_3d, varnamelength, urban_surface,                 &
                plant_canopy
 
@@ -376,6 +376,5 @@
         ONLY:  albedo_type, radiation_interaction, calc_zenith, zenith,        &
                radiation, rad_sw_in, rad_lw_in, rad_sw_out, rad_lw_out,        &
-               sigma_sb, solar_constant, sun_direction, sun_dir_lat,           &
-               sun_dir_lon,                                                    &
+               sigma_sb, sun_direction, sun_dir_lat, sun_dir_lon,              &
                force_radiation_call, surfinsw, surfinlw, surfinswdir,          &
                surfinswdif, surfoutsw, surfoutlw, surfins,nsvfl, svf, svfsurf, &
@@ -3603,5 +3602,4 @@
         REAL(wp)     ::  ground_floor_level_l         !< local height of ground floor level
         REAL(wp)     ::  z_agl                        !< height above ground
-        REAL(wp), DIMENSION(nzb:nzt)   ::  exn        !< value of the Exner function in layers
 
 !
@@ -4690,9 +4688,4 @@
         IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.        &
              TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
-       
-!--         Calculate initial surface temperature from pt of adjacent gridbox
-#if ! defined( __nopointer )
-            exn(nzb:nzt) = (hyp(nzb:nzt) / 100000.0_wp )**0.286_wp          !< Exner function
-#endif
 
 !
@@ -4705,8 +4698,8 @@
                k = surf_usm_h%k(m)
 
-               t_surf_h(m) = pt(k,j,i) * exn(k)
-               t_surf_window_h(m) = pt(k,j,i) * exn(k)
-               t_surf_green_h(m) = pt(k,j,i) * exn(k)
-               surf_usm_h%pt_surface(m) = pt(k,j,i) * exn(k)
+               t_surf_h(m) = pt(k,j,i) * exner(k)
+               t_surf_window_h(m) = pt(k,j,i) * exner(k)
+               t_surf_green_h(m) = pt(k,j,i) * exner(k)
+               surf_usm_h%pt_surface(m) = pt(k,j,i) * exner(k)
             ENDDO
 !
@@ -4718,8 +4711,8 @@
                   k = surf_usm_v(l)%k(m)
 
-                  t_surf_v(l)%t(m) = pt(k,j,i) * exn(k)
-                  t_surf_window_v(l)%t(m) = pt(k,j,i) * exn(k)
-                  t_surf_green_v(l)%t(m) = pt(k,j,i) * exn(k)
-                  surf_usm_v(l)%pt_surface(m) = pt(k,j,i) * exn(k)
+                  t_surf_v(l)%t(m) = pt(k,j,i) * exner(k)
+                  t_surf_window_v(l)%t(m) = pt(k,j,i) * exner(k)
+                  t_surf_green_v(l)%t(m) = pt(k,j,i) * exner(k)
+                  surf_usm_v(l)%pt_surface(m) = pt(k,j,i) * exner(k)
                ENDDO
             ENDDO
@@ -7338,5 +7331,4 @@
         REAL(wp)                              :: lambda_surface_window !< current value of lambda_surface (heat conductivity between air and window)
         REAL(wp)                              :: lambda_surface_green  !< current value of lambda_surface (heat conductivity between air and greeb wall)
-        REAL(wp), DIMENSION(nzb:nzt)          :: exn                !< value of the Exner function in layers
         
         REAL(wp)                              :: dtime              !< simulated time of day (in UTC)
@@ -7345,7 +7337,4 @@
 
 
-#if ! defined( __nopointer )
-        exn(nzb:nzt) = (hyp(nzb:nzt) / 100000.0_wp )**0.286_wp          !< Exner function
-#endif
 !        
 !--     First, treat horizontal surface elements
@@ -7371,6 +7360,6 @@
 #if ! defined( __nopointer )
 !
-!--        calculate rho * cp coefficient at surface layer
-           rho_cp  = cp * hyp(k) / ( r_d * surf_usm_h%pt1(m) * exn(k) )
+!--        calculate rho * c_p coefficient at surface layer
+           rho_cp  = c_p * hyp(k) / ( r_d * surf_usm_h%pt1(m) * exner(k) )
 #endif
 !
@@ -7387,9 +7376,9 @@
            surf_usm_h%r_a_green(m)  = surf_usm_h%r_a(m)
 
-!            r_a = ( surf_usm_h%pt1(m) - t_surf_h(m) / exn(k) ) /                              &
+!            r_a = ( surf_usm_h%pt1(m) - t_surf_h(m) / exner(k) ) /                              &
 !                  ( surf_usm_h%ts(m) * surf_usm_h%us(m) + 1.0E-20_wp )
-!            r_a_window = ( surf_usm_h%pt1(m) - t_surf_window_h(m) / exn(k) ) /                &
+!            r_a_window = ( surf_usm_h%pt1(m) - t_surf_window_h(m) / exner(k) ) /                &
 !                  ( surf_usm_h%ts(m) * surf_usm_h%us(m) + 1.0E-20_wp )
-!            r_a_green = ( surf_usm_h%pt1(m) - t_surf_green_h(m) / exn(k) ) /                  &
+!            r_a_green = ( surf_usm_h%pt1(m) - t_surf_green_h(m) / exner(k) ) /                  &
 !                  ( surf_usm_h%ts(m) * surf_usm_h%us(m) + 1.0E-20_wp )
                 
@@ -7446,11 +7435,11 @@
            coef_2 = 4.0_wp * surf_usm_h%emissivity(ind_veg_wall,m) *           &
                              sigma_sb * t_surf_h(m) ** 3                       &
-                           + lambda_surface + f_shf / exn(k)
+                           + lambda_surface + f_shf / exner(k)
            coef_window_2 = 4.0_wp * surf_usm_h%emissivity(ind_wat_win,m) *     &
                              sigma_sb * t_surf_window_h(m) ** 3                &
-                           + lambda_surface_window + f_shf_window / exn(k)
+                           + lambda_surface_window + f_shf_window / exner(k)
            coef_green_2 = 4.0_wp * surf_usm_h%emissivity(ind_pav_green,m) *    &
                              sigma_sb * t_surf_green_h(m) ** 3                 &
-                           + lambda_surface_green + f_shf_green / exn(k)
+                           + lambda_surface_green + f_shf_green / exner(k)
 
 !--        implicit solution when the surface layer has no heat capacity,
@@ -7480,5 +7469,5 @@
                                + surf_usm_h%frac(ind_wat_win,m) * t_surf_window_h_p(m)   &
                                + surf_usm_h%frac(ind_pav_green,m) * t_surf_green_h_p(m) )  &
-                               / exn(k)
+                               / exner(k)
                                
            IF ( humidity )  surf_usm_h%vpt_surface(m) =                        &
@@ -7540,14 +7529,14 @@
 !
 !--        ground/wall/roof surface heat flux
-           surf_usm_h%wshf_eb(m)   = - f_shf  * ( surf_usm_h%pt1(m) - t_surf_h_p(m) / exn(k) ) *               &
+           surf_usm_h%wshf_eb(m)   = - f_shf  * ( surf_usm_h%pt1(m) - t_surf_h_p(m) / exner(k) ) *               &
                                        surf_usm_h%frac(ind_veg_wall,m)         &
-                                     - f_shf_window  * ( surf_usm_h%pt1(m) - t_surf_window_h_p(m) / exn(k) ) * &
+                                     - f_shf_window  * ( surf_usm_h%pt1(m) - t_surf_window_h_p(m) / exner(k) ) * &
                                        surf_usm_h%frac(ind_wat_win,m)          &
-                                     - f_shf_green  * ( surf_usm_h%pt1(m) - t_surf_green_h_p(m) / exn(k) ) *   &
+                                     - f_shf_green  * ( surf_usm_h%pt1(m) - t_surf_green_h_p(m) / exner(k) ) *   &
                                        surf_usm_h%frac(ind_pav_green,m)
 !           
 !--        store kinematic surface heat fluxes for utilization in other processes
 !--        diffusion_s, surface_layer_fluxes,...
-           surf_usm_h%shf(m) = surf_usm_h%wshf_eb(m) / cp
+           surf_usm_h%shf(m) = surf_usm_h%wshf_eb(m) / c_p
 
        ENDDO
@@ -7573,6 +7562,6 @@
 #if ! defined( __nopointer )          
 !
-!--          calculate rho * cp coefficient at surface layer
-             rho_cp  = cp * hyp(k) / ( r_d * surf_usm_v(l)%pt1(m) * exn(k) )
+!--          calculate rho * c_p coefficient at surface layer
+             rho_cp  = c_p * hyp(k) / ( r_d * surf_usm_v(l)%pt1(m) * exner(k) )
 #endif
 
@@ -7647,11 +7636,11 @@
               coef_2 = 4.0_wp * surf_usm_v(l)%emissivity(ind_veg_wall,m) *     &
                                 sigma_sb * t_surf_v(l)%t(m) ** 3               &
-                              + lambda_surface + f_shf / exn(k)
+                              + lambda_surface + f_shf / exner(k)
               coef_window_2 = 4.0_wp * surf_usm_v(l)%emissivity(ind_wat_win,m) *&
                                 sigma_sb * t_surf_window_v(l)%t(m) ** 3        &
-                              + lambda_surface_window + f_shf / exn(k)
+                              + lambda_surface_window + f_shf / exner(k)
               coef_green_2 = 4.0_wp * surf_usm_v(l)%emissivity(ind_pav_green,m) *&
                                 sigma_sb * t_surf_green_v(l)%t(m) ** 3         &
-                              + lambda_surface_green + f_shf / exn(k)
+                              + lambda_surface_green + f_shf / exner(k)
 
 !--           implicit solution when the surface layer has no heat capacity,
@@ -7684,5 +7673,5 @@
                                       + surf_usm_v(l)%frac(ind_wat_win,m) * t_surf_window_v_p(l)%t(m)  &
                                       + surf_usm_v(l)%frac(ind_pav_green,m) * t_surf_green_v_p(l)%t(m) ) &
-                                      / exn(k) 
+                                      / exner(k)
                                       
               IF ( humidity )  surf_usm_v(l)%vpt_surface(m) =                  &
@@ -7751,14 +7740,14 @@
               surf_usm_v(l)%wshf_eb(m)   =                                     &
                  - f_shf  * ( surf_usm_v(l)%pt1(m) -                           &
-                 t_surf_v_p(l)%t(m) / exn(k) ) * surf_usm_v(l)%frac(ind_veg_wall,m)       &
+                 t_surf_v_p(l)%t(m) / exner(k) ) * surf_usm_v(l)%frac(ind_veg_wall,m)       &
                  - f_shf_window  * ( surf_usm_v(l)%pt1(m) -                    &
-                 t_surf_window_v_p(l)%t(m) / exn(k) ) * surf_usm_v(l)%frac(ind_wat_win,m)&
+                 t_surf_window_v_p(l)%t(m) / exner(k) ) * surf_usm_v(l)%frac(ind_wat_win,m)&
                  - f_shf_green  * ( surf_usm_v(l)%pt1(m) -                     &
-                 t_surf_green_v_p(l)%t(m) / exn(k) ) * surf_usm_v(l)%frac(ind_pav_green,m)
+                 t_surf_green_v_p(l)%t(m) / exner(k) ) * surf_usm_v(l)%frac(ind_pav_green,m)
 
 !           
 !--           store kinematic surface heat fluxes for utilization in other processes
 !--           diffusion_s, surface_layer_fluxes,...
-              surf_usm_v(l)%shf(m) = surf_usm_v(l)%wshf_eb(m) / cp
+              surf_usm_v(l)%shf(m) = surf_usm_v(l)%wshf_eb(m) / c_p
 
            ENDDO
@@ -7790,5 +7779,5 @@
                          (dtime/3600.0_wp-REAL(dhour,wp))*aheatprof(k,dhour+1)
                  IF ( aheat(k,j,i) > 0.0_wp )  THEN
-                    pt(k,j,i) = pt(k,j,i) + aheat(k,j,i)*acoef*dt_3d/(exn(k)*rho_cp*dzu(k))
+                    pt(k,j,i) = pt(k,j,i) + aheat(k,j,i)*acoef*dt_3d/(exner(k)*rho_cp*dzu(k))
                  ENDIF
               ENDIF
Index: /palm/trunk/SOURCE/uv_exposure_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/uv_exposure_model_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/uv_exposure_model_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3248 2018-09-14 09:42:06Z sward
 ! Minor formating changes
 ! 
@@ -77,5 +80,8 @@
 !------------------------------------------------------------------------------!
  MODULE uv_exposure_model_mod
- 
+
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  pi
 
     USE kinds
@@ -640,8 +646,5 @@
 !> Module-specific routine for new module
 !------------------------------------------------------------------------------!
- SUBROUTINE uvem_solar_position 
-
-    USE constants,                                                             &
-       ONLY:  pi
+ SUBROUTINE uvem_solar_position
     
     USE date_and_time_mod,                                                     &
@@ -713,7 +716,4 @@
 !------------------------------------------------------------------------------!
  SUBROUTINE uvem_calc_exposure
-    
-    USE constants,                                                             &
-        ONLY:  pi
 
     USE indices,                                                               &
Index: /palm/trunk/SOURCE/virtual_flight_mod.f90
===================================================================
--- /palm/trunk/SOURCE/virtual_flight_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/virtual_flight_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3248 2018-09-14 09:42:06Z sward
 ! Minor formating changes
 ! 
@@ -311,5 +314,5 @@
     SUBROUTINE flight_init
  
-       USE constants,                                                          &
+       USE basic_constants_and_equations_mod,                                  &
            ONLY:  pi
     
@@ -410,7 +413,9 @@
     
        USE control_parameters,                                                 &
-          ONLY:  cloud_droplets, cloud_physics, humidity, neutral,             &
-                 passive_scalar
-          
+          ONLY:  cloud_droplets, humidity, neutral, passive_scalar
+
+       USE bulk_cloud_model_mod,                                               &
+           ONLY:  bulk_cloud_model
+
        USE netcdf_interface
     
@@ -441,5 +446,5 @@
           id_q       = num_var_fl
        ENDIF
-       IF ( cloud_physics .OR. cloud_droplets )  THEN
+       IF ( bulk_cloud_model .OR. cloud_droplets )  THEN
           num_var_fl = num_var_fl + 1  
           id_ql      = num_var_fl
@@ -533,5 +538,5 @@
 
        USE control_parameters,                                                 &
-           ONLY:  cloud_droplets, cloud_physics, dt_3d, humidity, neutral,     &
+           ONLY:  cloud_droplets, dt_3d, humidity, neutral,                    &
                   passive_scalar, simulated_time
                   
@@ -544,4 +549,7 @@
        USE indices,                                                            &
            ONLY:  nx, nxl, nxr, ny, nys, nyn
+
+       USE bulk_cloud_model_mod,                                               &
+           ONLY:  bulk_cloud_model
 
        USE pegrid
@@ -712,5 +720,5 @@
 !
 !--             Liquid water content
-                IF ( cloud_physics .OR. cloud_droplets )  THEN
+                IF ( bulk_cloud_model .OR. cloud_droplets )  THEN
                    CALL interpolate_xyz( ql, zu, ddzu, 1.0_wp, x, y, var_index, j, i )
                    var_index = var_index + 1
Index: /palm/trunk/SOURCE/wind_turbine_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/wind_turbine_model_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/wind_turbine_model_mod.f90	(revision 3274)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3248 2018-09-14 09:42:06Z sward
 ! Minor formating changes
 ! 
@@ -175,5 +178,5 @@
         ONLY:  tend, u, v, w, zu, zw
 
-    USE constants,                                                             &
+    USE basic_constants_and_equations_mod,                                     &
         ONLY:  pi
 
Index: /palm/trunk/SOURCE/write_restart_data_mod.f90
===================================================================
--- /palm/trunk/SOURCE/write_restart_data_mod.f90	(revision 3273)
+++ /palm/trunk/SOURCE/write_restart_data_mod.f90	(revision 3274)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Modularization of all bulk cloud physics code components
+! 
+! 3065 2018-06-12 07:03:02Z Giersch
 ! New parameters concerning vertical grid stretching have been added
 ! 
@@ -109,8 +112,6 @@
            ONLY:  nx, ny, nz
 
-       USE microphysics_mod,                                                   &
-           ONLY:  c_sedimentation, cloud_water_sedimentation,                  &
-                  collision_turbulence, limiter_sedimentation, nc_const,       &
-                  ventilation_effect
+       USE bulk_cloud_model_mod,                                               &
+           ONLY:  bulk_cloud_model, bcm_wrd_global
 
        USE model_1d_mod,                                                       &
@@ -264,7 +265,4 @@
        WRITE ( 14 )  building_wall_south
 
-       CALL wrd_write_string( 'c_sedimentation' ) 
-       WRITE ( 14 )  c_sedimentation
-
        CALL wrd_write_string( 'call_psolver_at_all_substeps' ) 
        WRITE ( 14 )  call_psolver_at_all_substeps
@@ -291,21 +289,9 @@
        WRITE ( 14 )  cloud_droplets
 
-       CALL wrd_write_string( 'cloud_physics' ) 
-       WRITE ( 14 )  cloud_physics
-
-       CALL wrd_write_string( 'cloud_scheme' ) 
-       WRITE ( 14 )  cloud_scheme
-
        CALL wrd_write_string( 'cloud_top_radiation' ) 
        WRITE ( 14 )  cloud_top_radiation
 
-       CALL wrd_write_string( 'cloud_water_sedimentation' ) 
-       WRITE ( 14 )  cloud_water_sedimentation
-
        CALL wrd_write_string( 'collective_wait' ) 
        WRITE ( 14 )  collective_wait
-
-       CALL wrd_write_string( 'collision_turbulence' ) 
-       WRITE ( 14 )  collision_turbulence
 
        CALL wrd_write_string( 'conserve_volume_flow' ) 
@@ -455,7 +441,4 @@
        WRITE ( 14 )  latitude
 
-       CALL wrd_write_string( 'limiter_sedimentation' ) 
-       WRITE ( 14 )  limiter_sedimentation
-
        CALL wrd_write_string( 'longitude' )
        WRITE ( 14 )  longitude 
@@ -487,7 +470,4 @@
        WRITE ( 14 )  most_method
 
-       CALL wrd_write_string( 'nc_const' ) 
-       WRITE ( 14 )  nc_const
-
        CALL wrd_write_string( 'netcdf_precision' ) 
        WRITE ( 14 )  netcdf_precision
@@ -537,7 +517,4 @@
        CALL wrd_write_string( 'prandtl_number' ) 
        WRITE ( 14 )  prandtl_number
-
-       CALL wrd_write_string( 'precipitation' ) 
-       WRITE ( 14 )  precipitation
 
        CALL wrd_write_string( 'psolver' )
@@ -848,7 +825,4 @@
        WRITE ( 14 )  v_max_ijk
 
-       CALL wrd_write_string( 'ventilation_effect' ) 
-       WRITE ( 14 )  ventilation_effect
-
        CALL wrd_write_string( 'vg' ) 
        WRITE ( 14 )  vg
@@ -927,4 +901,8 @@
 !-- The order of the calls can be different as in read_restart_data_mod where
 !-- the restart data will be read 
+
+!
+!-- If required, write restart data for gust module.
+       IF ( bulk_cloud_model )  CALL bcm_wrd_global
 !
 !-- If required, write restart data for wind turbine model.
@@ -962,10 +940,12 @@
 
        USE arrays_3d,                                                          &
-           ONLY:  e, kh, km, p, pt, q, ql, qc, nc, nr, prr,                    &
-                  precipitation_amount, qr, s, sa, u, u_m_l, u_m_n, u_m_r,     &
+           ONLY:  e, kh, km, p, pt, q, ql, s, sa, 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,                                                &
@@ -980,5 +960,5 @@
        USE land_surface_model_mod,                                             &
            ONLY:  lsm_wrd_local
-        
+
        USE particle_attributes,                                                &
            ONLY:  iran_part
@@ -1078,19 +1058,4 @@
        ENDIF
 
-       IF ( ALLOCATED( prr ) )  THEN
-          CALL wrd_write_string( 'prr' ) 
-          WRITE ( 14 )  prr
-       ENDIF
-
-       IF ( ALLOCATED( prr_av ) )  THEN
-          CALL wrd_write_string( 'prr_av' ) 
-          WRITE ( 14 )  prr_av
-       ENDIF
-
-       IF ( ALLOCATED( precipitation_amount ) )  THEN
-          CALL wrd_write_string( 'precipitation_amount' ) 
-          WRITE ( 14 )  precipitation_amount
-       ENDIF
-
        CALL wrd_write_string( 'pt' ) 
        WRITE ( 14 )  pt
@@ -1111,56 +1076,14 @@
           ENDIF
 
-          IF ( cloud_physics  .OR.  cloud_droplets )  THEN
-
-             CALL wrd_write_string( 'ql' ) 
+          IF ( cloud_droplets )  THEN
+
+             CALL wrd_write_string( 'ql' )
              WRITE ( 14 )  ql
 
              IF ( ALLOCATED( ql_av ) )  THEN
-                CALL wrd_write_string( 'ql_av' ) 
+                CALL wrd_write_string( 'ql_av' )
                 WRITE ( 14 )  ql_av
              ENDIF
 
-             IF ( .NOT. cloud_droplets )  THEN
-
-                CALL wrd_write_string( 'qc' ) 
-                WRITE ( 14 )  qc
-
-                IF ( ALLOCATED( qc_av ) )  THEN
-                   CALL wrd_write_string( 'qc_av' ) 
-                   WRITE ( 14 )  qc_av
-                ENDIF
-
-                IF ( microphysics_morrison )  THEN
-
-                   CALL wrd_write_string( 'nc' ) 
-                   WRITE ( 14 )  nc
-
-                   IF ( ALLOCATED( nc_av ) )  THEN
-                      CALL wrd_write_string( 'nc_av' ) 
-                      WRITE ( 14 )  nc_av
-                   ENDIF
-
-                ENDIF
-
-                IF ( microphysics_seifert )  THEN
-
-                   CALL wrd_write_string( 'nr' ) 
-                   WRITE ( 14 )  nr
-
-                   IF ( ALLOCATED( nr_av ) )  THEN
-                      CALL wrd_write_string( 'nr_av' ) 
-                      WRITE ( 14 )  nr_av
-                   ENDIF
-
-                   CALL wrd_write_string( 'qr' ) 
-                   WRITE ( 14 )  qr
-
-                   IF ( ALLOCATED( qr_av ) )  THEN
-                      CALL wrd_write_string( 'qr_av' ) 
-                      WRITE ( 14 )  qr_av
-                   ENDIF
-
-                ENDIF
-             ENDIF
           ENDIF
 
@@ -1387,4 +1310,10 @@
 
 !
+!-- If required, write restart data for microphysics module.
+       IF ( bulk_cloud_model )  THEN
+          CALL bcm_wrd_local
+       ENDIF
+
+!
 !-- Write surface-related restart data.
        CALL surface_wrd_local
