Index: palm/trunk/SOURCE/module_interface.f90
===================================================================
--- palm/trunk/SOURCE/module_interface.f90	(revision 3956)
+++ palm/trunk/SOURCE/module_interface.f90	(revision 3987)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Introduce switchable DEBUG file output via debug_message routine
+! 
+! 3956 2019-05-07 12:32:52Z monakurppa
 ! - Added calls for salsa_non_advective_processes and 
 !   salsa_exchange_horiz_bounds
@@ -122,6 +125,8 @@
 !-- ToDo: move all of them to respective module or a dedicated central module
     USE control_parameters,                                                    &
-        ONLY:  biometeorology,                                                 &
-               air_chemistry,                                                  &
+        ONLY:  air_chemistry,                                                  &
+               biometeorology,                                                 &
+               debug_output,                                                   &
+               debug_output_timestep,                                          &
                indoor_model,                                                   &
                land_surface,                                                   &
@@ -539,4 +544,6 @@
 
 
+    IF ( debug_output )  CALL debug_message( 'reading module-specific parameters', 'start' )
+
     CALL bio_parin
     CALL bcm_parin
@@ -563,4 +570,6 @@
     CALL package_parin ! ToDo: deprecated, needs to be dissolved
 
+    IF ( debug_output )  CALL debug_message( 'reading module-specific parameters', 'end' )
+
 
  END SUBROUTINE module_interface_parin
@@ -574,4 +583,6 @@
  SUBROUTINE module_interface_check_parameters
 
+
+    IF ( debug_output )  CALL debug_message( 'checking module-specific parameters', 'start' )
 
     IF ( bulk_cloud_model )     CALL bcm_check_parameters
@@ -594,4 +605,6 @@
     IF ( user_module_enabled )  CALL user_check_parameters
 
+    IF ( debug_output )  CALL debug_message( 'checking module-specific parameters', 'end' )
+
 
  END SUBROUTINE module_interface_check_parameters
@@ -612,4 +625,6 @@
 
 
+    IF ( debug_output )  CALL debug_message( 'checking module-specific data output ts', 'start' )
+
     IF ( radiation )  THEN
        CALL radiation_check_data_output_ts( dots_max, dots_num )
@@ -619,4 +634,6 @@
        CALL user_check_data_output_ts( dots_max, dots_num, dots_label, dots_unit )
     ENDIF
+
+    IF ( debug_output )  CALL debug_message( 'checking module-specific data output ts', 'end' )
 
 
@@ -638,4 +655,7 @@
     CHARACTER (LEN=*), INTENT(OUT)   ::  dopr_unit !< local value of dopr_unit
 
+
+    IF ( debug_output )  CALL debug_message( 'checking module-specific data output pr', 'start' )
+
     IF ( unit == 'illegal' .AND.  bulk_cloud_model )  THEN
        CALL bcm_check_data_output_pr( variable, var_count, unit, dopr_unit )
@@ -670,4 +690,6 @@
        CALL user_check_data_output_pr( variable, var_count, unit, dopr_unit )
     ENDIF
+
+    IF ( debug_output )  CALL debug_message( 'checking module-specific data output pr', 'end' )
 
 
@@ -690,4 +712,7 @@
     INTEGER(iwp),      INTENT(IN)    :: k         !< ToDo: remove dummy argument, instead pass string from data_output
 
+
+    IF ( debug_output )  CALL debug_message( 'checking module-specific data output 2d/3d', 'start' )
+
     IF ( unit == 'illegal'  .AND.  biometeorology )  THEN
        CALL bio_check_data_output( variable, unit, i, j, ilen, k )
@@ -742,4 +767,6 @@
     ENDIF
 
+    IF ( debug_output )  CALL debug_message( 'checking module-specific data output 2d/3d', 'end' )
+
 
  END SUBROUTINE module_interface_check_data_output
@@ -757,4 +784,7 @@
     CHARACTER (LEN=*), INTENT(IN)    ::  variable !< variable name
     CHARACTER (LEN=*), INTENT(INOUT) ::  unit     !< physical unit of variable
+
+
+    IF ( debug_output )  CALL debug_message( 'initializing module-specific masks', 'start' )
 
     IF ( unit == 'illegal'  .AND.  air_chemistry                               &
@@ -775,4 +805,6 @@
        CALL user_check_data_output( variable, unit )
     ENDIF
+
+    IF ( debug_output )  CALL debug_message( 'initializing module-specific masks', 'end' )
 
 
@@ -795,4 +827,7 @@
     CHARACTER (LEN=*), INTENT(OUT) ::  grid_y !< netcdf dimension in y-direction
     CHARACTER (LEN=*), INTENT(OUT) ::  grid_z !< netcdf dimension in z-direction
+
+
+    IF ( debug_output )  CALL debug_message( 'defining module-specific netcdf grids', 'start' )
 !
 !-- As long as no action is done in this subroutine, initialize strings with
@@ -806,4 +841,7 @@
     IF ( var == ' ' )  RETURN
 
+    IF ( debug_output )  CALL debug_message( 'defining module-specific netcdf grids', 'end' )
+
+
  END SUBROUTINE module_interface_define_netcdf_grid
 
@@ -817,5 +855,5 @@
 
 
-    CALL location_message( 'initializing module-specific arrays', 'start' )
+    IF ( debug_output )  CALL debug_message( 'initializing module-specific arrays', 'start' )
 
     IF ( bulk_cloud_model    )  CALL bcm_init_arrays
@@ -830,5 +868,5 @@
     IF ( user_module_enabled )  CALL user_init_arrays
 
-    CALL location_message( 'initializing module-specific arrays', 'finished' )
+    IF ( debug_output )  CALL debug_message( 'initializing module-specific arrays', 'end' )
 
 
@@ -844,5 +882,5 @@
 
 
-    CALL location_message( 'initializing module features', 'start' )
+    IF ( debug_output )  CALL debug_message( 'module-specific initialization', 'start' )
 
     IF ( biometeorology      )  CALL bio_init
@@ -864,5 +902,5 @@
     IF ( user_module_enabled )  CALL user_init
 
-    CALL location_message( 'initializing module features', 'finished' )
+    IF ( debug_output )  CALL debug_message( 'module-specific initialization', 'end' )
 
 
@@ -878,6 +916,10 @@
 
 
+    IF ( debug_output )  CALL debug_message( 'module-specific post-initialization checks', 'start' )
+
     IF ( biometeorology      )  CALL bio_init_checks
 
+    IF ( debug_output )  CALL debug_message( 'module-specific post-initialization checks', 'end' )
+
 
  END SUBROUTINE module_interface_init_checks
@@ -894,4 +936,6 @@
     INTEGER(iwp), INTENT(IN) ::  io  !< unit of the output file
 
+
+    IF ( debug_output )  CALL debug_message( 'module-specific header output', 'start' )
 
     IF ( biometeorology      )  CALL bio_header ( io )
@@ -911,4 +955,6 @@
     IF ( user_module_enabled )  CALL user_header( io )
 
+    IF ( debug_output )  CALL debug_message( 'module-specific header output', 'end' )
+
 
  END SUBROUTINE module_interface_header
@@ -966,5 +1012,5 @@
 ! Description:
 ! ------------
-!> Compute module-specificc non_advective_processes (vector-optimized)
+!> Compute module-specific non_advective_processes (vector-optimized)
 !------------------------------------------------------------------------------!
  SUBROUTINE module_interface_non_advective_processes()
@@ -1006,7 +1052,12 @@
 
 
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific exchange_horiz', 'start' )
+
     IF ( bulk_cloud_model    )  CALL bcm_exchange_horiz()
     IF ( air_chemistry       )  CALL chem_exchange_horiz_bounds()
     IF ( salsa               )  CALL salsa_exchange_horiz_bounds()
+
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific exchange_horiz', 'end' )
+
 
  END SUBROUTINE module_interface_exchange_horiz
@@ -1064,4 +1115,7 @@
 
     INTEGER(iwp), INTENT(IN) :: swap_mode !< determines procedure of pointer swap
+
+
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific swap timelevel', 'start' )
 
     IF ( bulk_cloud_model    )  CALL bcm_swap_timelevel( swap_mode )
@@ -1073,4 +1127,6 @@
     IF ( urban_surface       )  CALL usm_swap_timelevel( swap_mode )
 
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific swap timelevel', 'end' )
+
 
  END SUBROUTINE module_interface_swap_timelevel
@@ -1088,4 +1144,7 @@
     CHARACTER (LEN=*), INTENT(IN) ::  mode     !< averaging interface mode
     CHARACTER (LEN=*), INTENT(IN) ::  variable !< variable name
+
+
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific 3d data averaging', 'start' )
 
     IF ( biometeorology      )  CALL bio_3d_data_averaging( mode, variable )
@@ -1100,4 +1159,6 @@
     IF ( user_module_enabled )  CALL user_3d_data_averaging( mode, variable )
 
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific 3d data averaging', 'end' )
+
 
  END SUBROUTINE module_interface_3d_data_averaging
@@ -1126,4 +1187,6 @@
 
 
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific 2d data output', 'start' )
+
     IF ( .NOT. found  .AND.  biometeorology )  THEN
        CALL bio_data_output_2d(                                                &
@@ -1179,4 +1242,7 @@
             )
     ENDIF
+
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific 2d data output', 'end' )
+
 
  END SUBROUTINE module_interface_data_output_2d
@@ -1204,4 +1270,6 @@
 
 
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific 3d data output', 'start' )
+
     IF ( .NOT. found  .AND.  biometeorology )  THEN
        CALL bio_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
@@ -1254,4 +1322,6 @@
     ENDIF
 
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific 3d data output', 'end' )
+
 
  END SUBROUTINE module_interface_data_output_3d
@@ -1271,8 +1341,13 @@
     INTEGER(iwp),      INTENT(IN) ::  dots_max !< maximum number of timeseries
 
+
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific statistics', 'start' )
+
     IF ( gust_module_enabled )  CALL gust_statistics( mode, sr, tn, dots_max )
     IF ( air_chemistry       )  CALL chem_statistics( mode, sr, tn )
     IF ( user_module_enabled )  CALL user_statistics( mode, sr, tn )
 
+    IF ( debug_output_timestep )  CALL debug_message( 'module-specific statistics', 'end' )
+
 
  END SUBROUTINE module_interface_statistics
@@ -1288,4 +1363,7 @@
 
     LOGICAL, INTENT(INOUT) ::  found    !< flag if variable was found
+
+
+    IF ( debug_output )  CALL debug_message( 'module-specific read global restart data', 'start' )
 
     IF ( .NOT. found )  CALL bio_rrd_global( found ) ! ToDo: change interface to pass variable
@@ -1299,4 +1377,6 @@
     IF ( .NOT. found )  CALL user_rrd_global( found ) ! ToDo: change interface to pass variable
 
+    IF ( debug_output )  CALL debug_message( 'module-specific read global restart data', 'end' )
+
 
  END SUBROUTINE module_interface_rrd_global
@@ -1310,4 +1390,6 @@
  SUBROUTINE module_interface_wrd_global
 
+
+    IF ( debug_output )  CALL debug_message( 'module-specific write global restart data', 'start' )
 
     IF ( biometeorology )       CALL bio_wrd_global
@@ -1320,4 +1402,6 @@
     IF ( surface_output )       CALL surface_data_output_wrd_global
     IF ( user_module_enabled )  CALL user_wrd_global
+
+    IF ( debug_output )  CALL debug_message( 'module-specific write global restart data', 'end' )
 
 
@@ -1357,4 +1441,6 @@
 
 
+    IF ( debug_output )  CALL debug_message( 'module-specific read local restart data', 'start' )
+
     IF ( .NOT. found ) CALL bio_rrd_local(                                     &
                                found                                           &
@@ -1445,4 +1531,6 @@
                             ) ! ToDo: change interface to pass variable
 
+    IF ( debug_output )  CALL debug_message( 'module-specific read local restart data', 'end' )
+
 
  END SUBROUTINE module_interface_rrd_local
@@ -1456,4 +1544,6 @@
  SUBROUTINE module_interface_wrd_local
 
+
+    IF ( debug_output )  CALL debug_message( 'module-specific write local restart data', 'start' )
 
     IF ( biometeorology )       CALL bio_wrd_local
@@ -1469,4 +1559,6 @@
     IF ( user_module_enabled )  CALL user_wrd_local
 
+    IF ( debug_output )  CALL debug_message( 'module-specific write local restart data', 'end' )
+
 
  END SUBROUTINE module_interface_wrd_local
@@ -1480,8 +1572,12 @@
  SUBROUTINE module_interface_last_actions
 
+
+    IF ( debug_output )  CALL debug_message( 'module-specific last actions', 'start' )
 
     IF ( virtual_measurement )  CALL vm_last_actions
     IF ( user_module_enabled )  CALL user_last_actions
 
+    IF ( debug_output )  CALL debug_message( 'module-specific last actions', 'end' )
+
 
  END SUBROUTINE module_interface_last_actions
