Index: palm/trunk/SOURCE/data_output_module.f90
===================================================================
--- palm/trunk/SOURCE/data_output_module.f90	(revision 4115)
+++ palm/trunk/SOURCE/data_output_module.f90	(revision 4116)
@@ -142,5 +142,5 @@
 
    INTEGER(iwp) ::  debug_output_unit  !< Fortran Unit Number of the debug-output file
-   INTEGER(iwp) ::  nf                 !< number of files
+   INTEGER      ::  nf = 0             !< number of files
    INTEGER      ::  master_rank = 0    !< master rank for tasks to be executed by single PE only
    INTEGER      ::  output_group_comm  !< MPI communicator addressing all MPI ranks which participate in output
@@ -282,5 +282,5 @@
    WRITE( debug_output_unit, '(A)' ) REPEAT( separation_string // ' ', 4 )
 
-   IF ( .NOT. ALLOCATED( files) )  THEN
+   IF ( .NOT. ALLOCATED( files ) .OR. nf == 0 )  THEN
 
       WRITE( debug_output_unit, '(A)' ) 'database is empty'
@@ -293,5 +293,4 @@
                                         ',(": ")'
 
-      nf = SIZE( files )
       DO  f = 1, nf
 
@@ -679,4 +678,6 @@
    return_value = 0
 
+   CALL internal_message( 'debug', routine_name // ': define file "' // TRIM( filename ) // '"' )
+
    !-- Allocate file list or extend it by 1
    IF ( .NOT. ALLOCATED( files ) ) THEN
@@ -768,4 +769,8 @@
    return_value = 0
 
+   CALL internal_message( 'debug', routine_name //                  &
+                          ': define dimension "' // TRIM( name ) // &
+                          '" in file "' // TRIM( filename ) // '"' )
+
    dimension%name      = TRIM( name )
    dimension%data_type = TRIM( output_type )
@@ -782,7 +787,7 @@
       IF ( PRESENT( mask ) )  THEN
          return_value = 1
-         CALL internal_message( 'error', routine_name //                            &
-                                         ': unlimited dimension' // TRIM( name ) // &
-                                         ' in file ' // TRIM( filename ) // ' cannot be masked' )
+         CALL internal_message( 'error', routine_name //                              &
+                                         ': unlimited dimension "' // TRIM( name ) // &
+                                         '" in file "' // TRIM( filename ) // '" cannot be masked' )
       ENDIF
 
@@ -982,7 +987,9 @@
 
       return_value = 1
-      CALL internal_message( 'error', routine_name //          &
-                             ': dimension ' // TRIM( name ) // &
-                             ': At least one but no more than two bounds must be given' )
+      CALL internal_message( 'error', routine_name //                                       &
+                             ': at least one but no more than two bounds must be given ' // &
+                             '(dimension "' // TRIM( name ) //                              &
+                             '", file "' // TRIM( filename ) //                             &
+                             '")!' )
 
    ENDIF
@@ -1065,6 +1072,7 @@
       IF ( f > nf )  THEN
          return_value = 1
-         CALL internal_message( 'error', routine_name // &
-                                         ': file "' // TRIM( filename ) // '" not found' )
+         CALL internal_message( 'error', routine_name //                           &
+                                ': file not found (dimension "' // TRIM( name ) // &
+                                '", file "' // TRIM( filename ) // '")!' )
       ENDIF
 
@@ -1104,4 +1112,8 @@
 
    return_value = 0
+
+   CALL internal_message( 'debug', routine_name //                  &
+                          ': define variable "' // TRIM( name ) // &
+                          '" in file "' // TRIM( filename ) // '"' )
 
    variable%name = TRIM( name )
@@ -1158,11 +1170,11 @@
                   IF ( .NOT. found )  THEN
                      return_value = 1
-                     CALL internal_message( 'error',                               &
-                                            routine_name //                        &
-                                            ': variable "' // TRIM( name ) //      &
-                                            '" in file "' // TRIM( filename ) //   &
-                                            '": required dimension "' //           &
-                                            TRIM( variable%dimension_names(i) ) // &
-                                            '" not defined' )
+                     CALL internal_message( 'error',                                            &
+                                            routine_name //                                     &
+                                            ': required dimension "' //                         &
+                                            TRIM( variable%dimension_names(i) ) //              &
+                                            '" for variable "' // TRIM( name ) //               &
+                                            '" is not defined in file "' // TRIM( filename ) // &
+                                            '"!' )
                      EXIT
                   ENDIF
@@ -1173,7 +1185,8 @@
 
             return_value = 1
-            CALL internal_message( 'error', routine_name //                   &
-                                            ': file "' // TRIM( filename ) // &
-                                            '" has no dimensions defined' )
+            CALL internal_message( 'error', routine_name //                        &
+                                   ': cannot define variable "' // TRIM( name ) // &
+                                   '" in file "' // TRIM( filename ) //            &
+                                   '" because no dimensions defined in file.' )
 
          ENDIF
@@ -1193,8 +1206,8 @@
                   IF ( files(f)%variables(i)%name == variable%name )  THEN
                      return_value = 1
-                     CALL internal_message( 'error', routine_name //                      &
-                                                     ': variable "' // TRIM( name ) //    &
-                                                     '" in file "' // TRIM( filename ) // &
-                                                     '": variable already exists' )
+                     CALL internal_message( 'error', routine_name //          &
+                                            ': variable "' // TRIM( name ) // &
+                                            '" already exists in file "' //   &
+                                            TRIM( filename ) // '"!' )
                      EXIT
                   ENDIF
@@ -1227,8 +1240,7 @@
    IF ( f > nf )  THEN
       return_value = 1
-      CALL internal_message( 'error', routine_name //                    &
-                                      ': variable "' // TRIM( name ) //  &
-                                      '": file "' // TRIM( filename ) // &
-                                      '" not found' )
+      CALL internal_message( 'error', routine_name //                           &
+                             ': file not found (variable "' // TRIM( name ) //  &
+                             '", file "' // TRIM( filename ) // '")!' )
    ENDIF
 
@@ -1271,8 +1283,8 @@
    IF ( PRESENT( variable ) )  THEN
       return_value = dom_def_att_save( TRIM( filename ), TRIM( variable ), &
-                                           attribute=attribute, append=append_internal )
+                                       attribute=attribute, append=append_internal )
    ELSE
       return_value = dom_def_att_save( TRIM( filename ), &
-                                           attribute=attribute, append=append_internal )
+                                       attribute=attribute, append=append_internal )
    ENDIF
 
@@ -1574,4 +1586,15 @@
    return_value = 0
    found = .FALSE.
+
+   IF ( PRESENT( variable_name ) )  THEN
+      CALL internal_message( 'debug', routine_name //                            &
+                             ': define attribute "' // TRIM( attribute%name ) // &
+                             '" of variable "' // TRIM( variable_name ) //       &
+                             '" in file "' // TRIM( filename ) // '"' )
+   ELSE
+      CALL internal_message( 'debug', routine_name //                            &
+                             ': define attribute "' // TRIM( attribute%name ) // &
+                             '" in file "' // TRIM( filename ) // '"' )
+   ENDIF
 
    DO  f = 1, nf
@@ -1772,5 +1795,5 @@
       CALL internal_message( 'error',                                         &
                              routine_name //                                  &
-                             ': requested file "' // TRIM( variable_name ) // &
+                             ': requested file "' // TRIM( filename ) //      &
                              '" for attribute "' // TRIM( attribute%name ) // &
                              '" does not exist' )
@@ -1815,6 +1838,9 @@
 
 
+   return_value = 0
+   CALL internal_message( 'debug', routine_name // ': start' )
+
    !-- Clear database from empty files and unused dimensions
-   return_value = cleanup_database()
+   IF ( nf > 0 )  return_value = cleanup_database()
 
    IF ( return_value == 0 )  THEN
