Index: /palm/trunk/SOURCE/biometeorology_mod.f90
===================================================================
--- /palm/trunk/SOURCE/biometeorology_mod.f90	(revision 4576)
+++ /palm/trunk/SOURCE/biometeorology_mod.f90	(revision 4577)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! further re-formatting concerning Fortran parameter variables
+!
+! 4540 2020-05-18 15:23:29Z raasch
 ! file re-formatted to follow the PALM coding standard
 !
@@ -187,4 +190,8 @@
 !
 !-- Declare all global variables within the module (alphabetical order)
+    REAL(wp), PARAMETER ::  bio_fill_value = -9999.0_wp  !< set module fill value, replace by global fill value as soon as available
+    REAL(wp), PARAMETER ::  human_absorb = 0.7_wp  !< SW absorbtivity of a human body (Fanger 1972)
+    REAL(wp), PARAMETER ::  human_emiss = 0.97_wp  !< LW emissivity of a human body after (Fanger 1972)
+
     INTEGER(iwp) ::  bio_cell_level     !< cell level biom calculates for
 
@@ -209,8 +216,4 @@
 
     REAL(wp)    ::  bio_output_height  !< height output is calculated in m
-
-    REAL(wp), PARAMETER ::  bio_fill_value = -9999.0_wp  !< set module fill value, replace by global fill value as soon as available
-    REAL(wp), PARAMETER ::  human_absorb = 0.7_wp  !< SW absorbtivity of a human body (Fanger 1972)
-    REAL(wp), PARAMETER ::  human_emiss = 0.97_wp  !< LW emissivity of a human body after (Fanger 1972)
 
     REAL(wp), DIMENSION(:), ALLOCATABLE   ::  mrt_av_grid   !< time average mean
@@ -2270,10 +2273,11 @@
 !
 !-- Parameters for standard "Klima-Michel"
-    REAL(wp), PARAMETER :: actlev = 134.6862_wp  !< Workload by activity per standardized surface 
-                                                 !< (A_Du)
+    REAL(wp), PARAMETER :: actlev = 134.6862_wp  !< Workload by activity per standardized surface (A_Du)
     REAL(wp), PARAMETER :: eta = 0.0_wp          !< Mechanical work efficiency for walking on flat
                                                  !< ground (compare to Fanger (1972) pp 24f)
 !
 !-- Type of program variables
+    REAL(wp), PARAMETER :: eps = 0.0005  !< Accuracy in clothing insulation (clo) for evaluation the root of Fanger's PMV (pmva=0)
+
     INTEGER(iwp) :: ncount      !< running index
     INTEGER(iwp) :: nerr_cold   !< error number (cold conditions)
@@ -2281,7 +2285,4 @@
 
     LOGICAL :: sultrieness
-
-    REAL(wp), PARAMETER :: eps = 0.0005  !< Accuracy in clothing insulation (clo) for evaluation the
-                                         !< root of Fanger's PMV (pmva=0)
 
     REAL(wp) ::  clon           !< clo for neutral conditions   (clo)
@@ -2504,7 +2505,8 @@
 !-- Type of program variables
     INTEGER(iwp), PARAMETER  ::  max_iteration = 15_iwp       !< max number of iterations
+
+    REAL(wp),     PARAMETER  ::  guess_0       = -1.11e30_wp  !< initial guess
+
     INTEGER(iwp) ::  j       !< running index
-
-    REAL(wp),     PARAMETER  ::  guess_0       = -1.11e30_wp  !< initial guess
 
     REAL(wp) ::  clo_lower   !< lower limit of clothing insulation      (clo)
@@ -2788,5 +2790,5 @@
     REAL(wp) ::  dtmrt        !< difference mean radiation to air temperature
     REAL(wp) ::  pa           !< vapor pressure (hPa) with hard bounds
-    REAL(wp) ::  pa_p50       !< ratio actual water vapour pressure to that of relative humidity of 
+    REAL(wp) ::  pa_p50       !< ratio actual water vapour pressure to that of relative humidity of
                               !< 50 %
     REAL(wp) ::  pmv          !< temp storage og predicted mean vote
@@ -2973,5 +2975,5 @@
 !
 !-- Additional output variables of argument list:
-    REAL(wp), INTENT ( OUT ) ::  dperctm    !< Mean deviation perct (classical gt) to gt* (rational 
+    REAL(wp), INTENT ( OUT ) ::  dperctm    !< Mean deviation perct (classical gt) to gt* (rational
                                             !< gt calculated based on Gagge's rational PMV*)
     REAL(wp), INTENT ( OUT ) ::  dperctstd  !< dperctm plus its standard deviation times a factor
@@ -3039,8 +3041,8 @@
 !
 !-- Type of output argument
-    INTEGER(iwp), INTENT ( OUT ) ::  nerr !< Error indicator: 0 = o.k., +1 = denominator for 
+    INTEGER(iwp), INTENT ( OUT ) ::  nerr !< Error indicator: 0 = o.k., +1 = denominator for
                                           !< intersection = 0
 
-    REAL(wp),     INTENT ( OUT ) ::  dpmv_cold_res    !< Increment to adjust pmva according to the 
+    REAL(wp),     INTENT ( OUT ) ::  dpmv_cold_res    !< Increment to adjust pmva according to the
                                                       !< results of Gagge's 2 node model depending on the input
 !
@@ -3344,4 +3346,7 @@
 !
 !-- Internal variables
+    REAL(wp), PARAMETER :: eps = 0.0005_wp
+    REAL(wp), PARAMETER :: eta = 0.0_wp
+
     INTEGER(iwp) ::  ncount
     INTEGER(iwp) ::  nerr_cold
@@ -3349,7 +3354,4 @@
 
     LOGICAL ::  sultrieness
-
-    REAL(wp), PARAMETER :: eps = 0.0005_wp
-    REAL(wp), PARAMETER :: eta = 0.0_wp
 
 !    REAL(wp) ::  acti
@@ -3639,8 +3641,8 @@
 !
 !-- Internal variables
+    REAL(wp), PARAMETER  ::  time_equil = 7200.0_wp
+
     INTEGER(iwp) :: i         !< running index
     INTEGER(iwp) ::  niter    !< Running index
-
-    REAL(wp), PARAMETER  ::  time_equil = 7200.0_wp
 
     REAL(wp) ::  adjustrate        !< Max storage adjustment rate
@@ -3661,5 +3663,5 @@
     REAL(wp) ::  ws                !< wind speed                             (m/s)
     REAL(wp) ::  z1                !< Empiric factor for the adaption of the heat
-                                   !< ballance equation to the psycho-physical scale 
+                                   !< ballance equation to the psycho-physical scale
                                    !< (Equ. 40 in FANGER)
     REAL(wp) ::  z2                !< Water vapour diffution through the skin
@@ -4087,5 +4089,5 @@
           IF ( eswdif <= 0.0_wp )  esw = eswpot     !< Limit is evaporation
           IF ( eswdif > 0.0_wp )   esw = eswphy     !< Limit is sweat production
-          IF ( esw  > 0.0_wp )     esw = 0.0_wp     !< Sweat can't be evaporated, no more cooling 
+          IF ( esw  > 0.0_wp )     esw = 0.0_wp     !< Sweat can't be evaporated, no more cooling
                                                     !< effect
 !
Index: /palm/trunk/SOURCE/bulk_cloud_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/bulk_cloud_model_mod.f90	(revision 4576)
+++ /palm/trunk/SOURCE/bulk_cloud_model_mod.f90	(revision 4577)
@@ -24,4 +24,7 @@
 ! -----------------
 ! $Id$
+! further re-formatting concerning Fortran parameter variables
+!
+! 4542 2020-05-19 15:45:12Z raasch
 ! file re-formatted to follow the PALM coding standard
 !
@@ -2884,4 +2887,6 @@
     IMPLICIT NONE
 
+    REAL(wp), PARAMETER ::  fill_value = -999.0_wp  !< value for the _FillValue attribute
+
     CHARACTER (LEN=*), INTENT(INOUT) ::  grid       !< name of vertical grid
     CHARACTER (LEN=*), INTENT(IN)    ::  mode       !< either 'xy', 'xz' or 'yz'
@@ -2902,7 +2907,4 @@
     LOGICAL, INTENT(INOUT) ::  two_d   !< flag parameter that indicates 2D variables
                                        !<  (horizontal cross sections)
-
-
-    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
@@ -6531,12 +6533,4 @@
        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,                                  &
@@ -6547,4 +6541,12 @@
                                             -0.5395239384953E-5_wp /)     !<
 
+       REAL(wp)     ::  gamm         !<
+       REAL(wp)     ::  ser          !<
+       REAL(wp)     ::  tmp          !<
+       REAL(wp)     ::  x_gamm       !<
+       REAL(wp)     ::  xx           !<
+       REAL(wp)     ::  y_gamm       !<
+
+
        x_gamm = xx
        y_gamm = x_gamm
Index: /palm/trunk/SOURCE/check_open.f90
===================================================================
--- /palm/trunk/SOURCE/check_open.f90	(revision 4576)
+++ /palm/trunk/SOURCE/check_open.f90	(revision 4577)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! further re-formatting to follow the PALM coding standard
+!
+! 4546 2020-05-24 12:16:41Z raasch
 ! file re-formatted to follow the PALM coding standard
 !
@@ -201,5 +204,5 @@
 !--       and the run crashes. Thus, if the file is not there, PARIN_O will be read. An ocean
 !--       precursor run will be the only situation where this can happen.
-          INQUIRE( FILE = 'PARIN' // TRIM( coupling_char ), EXIST = file_exist )
+          INQUIRE( FILE='PARIN' // TRIM( coupling_char ), EXIST=file_exist )
 
           IF ( file_exist )  THEN
@@ -209,5 +212,5 @@
           ENDIF
 
-          OPEN ( 11, FILE= TRIM( filename ), FORM = 'FORMATTED', STATUS = 'OLD', IOSTAT = ioerr )
+          OPEN ( 11, FILE=TRIM( filename ), FORM='FORMATTED', STATUS='OLD', IOSTAT=ioerr )
 
           IF ( ioerr /= 0 )  THEN
@@ -222,6 +225,6 @@
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 13, FILE = 'BININ' // TRIM( coupling_char ) // myid_char, FORM = 'UNFORMATTED',&
-                        STATUS = 'OLD' )
+             OPEN ( 13, FILE='BININ' // TRIM( coupling_char ) // myid_char, FORM='UNFORMATTED',    &
+                        STATUS='OLD' )
           ELSE
 !
@@ -229,9 +232,9 @@
 !--          the global variables.
              IF ( .NOT. openfile(file_id)%opened_before )  THEN
-                OPEN ( 13, FILE = 'BININ' // TRIM( coupling_char ) // '/_000000',                  &
-                           FORM = 'UNFORMATTED', STATUS = 'OLD' )
+                OPEN ( 13, FILE='BININ' // TRIM( coupling_char ) // '/_000000', FORM='UNFORMATTED',&
+                           STATUS='OLD' )
              ELSE
-                OPEN ( 13, FILE = 'BININ' // TRIM( coupling_char ) // '/' // myid_char,            &
-                           FORM = 'UNFORMATTED', STATUS = 'OLD' )
+                OPEN ( 13, FILE='BININ' // TRIM( coupling_char ) // '/' // myid_char,              &
+                           FORM='UNFORMATTED', STATUS='OLD' )
              ENDIF
           ENDIF
@@ -240,6 +243,6 @@
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 14, FILE = 'BINOUT' // TRIM( coupling_char ) // myid_char,                     &
-                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
+             OPEN ( 14, FILE='BINOUT' // TRIM( coupling_char ) // myid_char, FORM='UNFORMATTED',   &
+                        POSITION='APPEND' )
           ELSE
              IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
@@ -254,6 +257,6 @@
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 14, FILE = 'BINOUT' // TRIM(coupling_char)// '/' // myid_char,              &
-                           FORM = 'UNFORMATTED', IOSTAT = ioerr )
+                OPEN ( 14, FILE='BINOUT' // TRIM(coupling_char)// '/' // myid_char,                &
+                           FORM='UNFORMATTED', IOSTAT=ioerr )
                 IF ( ioerr /= 0 )  THEN
                    WRITE( 9, * )  '*** could not open "BINOUT' //                                  &
@@ -268,21 +271,21 @@
        CASE ( 15 )
 
-          OPEN ( 15, FILE = 'RUN_CONTROL' // TRIM( coupling_char ), FORM = 'FORMATTED' )
+          OPEN ( 15, FILE='RUN_CONTROL' // TRIM( coupling_char ), FORM='FORMATTED' )
 
        CASE ( 16 )
 
-          OPEN ( 16, FILE = 'LIST_PROFIL' // TRIM( coupling_char ), FORM = 'FORMATTED' )
+          OPEN ( 16, FILE='LIST_PROFIL' // TRIM( coupling_char ), FORM='FORMATTED' )
 
        CASE ( 17 )
 
-          OPEN ( 17, FILE = 'LIST_PROFIL_1D' // TRIM( coupling_char ), FORM = 'FORMATTED' )
+          OPEN ( 17, FILE='LIST_PROFIL_1D' // TRIM( coupling_char ), FORM='FORMATTED' )
 
        CASE ( 18 )
 
-          OPEN ( 18, FILE = 'CPU_MEASURES' // TRIM( coupling_char ), FORM = 'FORMATTED' )
+          OPEN ( 18, FILE='CPU_MEASURES' // TRIM( coupling_char ), FORM='FORMATTED' )
 
        CASE ( 19 )
 
-          OPEN ( 19, FILE = 'HEADER' // TRIM( coupling_char ), FORM = 'FORMATTED' )
+          OPEN ( 19, FILE='HEADER' // TRIM( coupling_char ), FORM='FORMATTED' )
 
        CASE ( 20 )
@@ -292,6 +295,6 @@
           ENDIF
           IF ( myid_char == '' )  THEN
-             OPEN ( 20, FILE = 'DATA_LOG' // TRIM( coupling_char ) // '/_000000',                  &
-                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
+             OPEN ( 20, FILE='DATA_LOG' // TRIM( coupling_char ) // '/_000000', FORM='UNFORMATTED',&
+                        POSITION='APPEND' )
           ELSE
 #if defined( __parallel )
@@ -303,6 +306,6 @@
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 20, FILE = 'DATA_LOG' // TRIM( coupling_char ) // '/' // myid_char,         &
-                           FORM = 'UNFORMATTED', POSITION = 'APPEND', IOSTAT = ioerr )
+                OPEN ( 20, FILE='DATA_LOG' // TRIM( coupling_char ) // '/' // myid_char,           &
+                           FORM='UNFORMATTED', POSITION='APPEND', IOSTAT=ioerr )
                 IF ( ioerr /= 0 )  THEN
                    WRITE( 9, * )  '*** could not open "DATA_LOG' // TRIM( coupling_char ) // '/' //&
@@ -317,9 +320,9 @@
 
           IF ( data_output_2d_on_each_pe )  THEN
-             OPEN ( 21, FILE = 'PLOT2D_XY' // TRIM( coupling_char ) // myid_char,                  &
-                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
-          ELSE
-             OPEN ( 21, FILE = 'PLOT2D_XY' // TRIM( coupling_char ),                               &
-                        FORM ='UNFORMATTED', POSITION = 'APPEND' )
+             OPEN ( 21, FILE='PLOT2D_XY' // TRIM( coupling_char ) // myid_char, FORM='UNFORMATTED',&
+                        POSITION='APPEND' )
+          ELSE
+             OPEN ( 21, FILE='PLOT2D_XY' // TRIM( coupling_char ), FORM='UNFORMATTED',             &
+                        POSITION='APPEND' )
           ENDIF
 
@@ -336,9 +339,9 @@
 
           IF ( data_output_2d_on_each_pe )  THEN
-             OPEN ( 22, FILE = 'PLOT2D_XZ' // TRIM( coupling_char ) // myid_char,                  &
-                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
-          ELSE
-             OPEN ( 22, FILE = 'PLOT2D_XZ' // TRIM( coupling_char ), FORM = 'UNFORMATTED',         &
-                        POSITION = 'APPEND' )
+             OPEN ( 22, FILE='PLOT2D_XZ' // TRIM( coupling_char ) // myid_char, FORM='UNFORMATTED',&
+                        POSITION='APPEND' )
+          ELSE
+             OPEN ( 22, FILE='PLOT2D_XZ' // TRIM( coupling_char ), FORM='UNFORMATTED',             &
+                        POSITION='APPEND' )
           ENDIF
 
@@ -355,9 +358,9 @@
 
           IF ( data_output_2d_on_each_pe )  THEN
-             OPEN ( 23, FILE = 'PLOT2D_YZ' // TRIM( coupling_char ) // myid_char,                  &
-                        FORM = 'UNFORMATTED', POSITION='APPEND' )
-          ELSE
-             OPEN ( 23, FILE = 'PLOT2D_YZ' // TRIM( coupling_char ), FORM = 'UNFORMATTED',         &
-                        POSITION = 'APPEND' )
+             OPEN ( 23, FILE='PLOT2D_YZ' // TRIM( coupling_char ) // myid_char, FORM='UNFORMATTED',&
+                        POSITION='APPEND' )
+          ELSE
+             OPEN ( 23, FILE='PLOT2D_YZ' // TRIM( coupling_char ), FORM='UNFORMATTED',             &
+                        POSITION='APPEND' )
           ENDIF
 
@@ -374,10 +377,10 @@
 !
 !--       Binary files for surface data
-          ! OPEN ( 25, FILE = 'SURFACE_DATA_BIN' // TRIM( coupling_char ) // myid_char,            &
-          !            FORM = 'UNFORMATTED', POSITION = 'APPEND' )
+          ! OPEN ( 25, FILE='SURFACE_DATA_BIN' // TRIM( coupling_char ) // myid_char,               &
+          !            FORM='UNFORMATTED', POSITION='APPEND' )
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 25, FILE = 'SURFACE_DATA_BIN' // TRIM( coupling_char ) // myid_char,           &
-                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
+             OPEN ( 25, FILE='SURFACE_DATA_BIN' // TRIM( coupling_char ) // myid_char,             &
+                        FORM='UNFORMATTED', POSITION='APPEND' )
           ELSE
              IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
@@ -392,6 +395,6 @@
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 25, FILE = 'SURFACE_DATA_BIN' // TRIM(coupling_char) //  '/' // myid_char,  &
-                           FORM = 'UNFORMATTED', IOSTAT = ioerr )
+                OPEN ( 25, FILE='SURFACE_DATA_BIN' // TRIM(coupling_char) //  '/' // myid_char,    &
+                           FORM='UNFORMATTED', IOSTAT=ioerr )
                 IF ( ioerr /= 0 )  THEN
                    WRITE( 9, * )  '*** could not open "SURFACE_DATA_BIN'// TRIM(coupling_char) //  &
@@ -406,10 +409,10 @@
 !
 !--       Binary files for averaged surface data
-          ! OPEN ( 26, FILE = 'SURFACE_DATA_AV_BIN' // TRIM( coupling_char ) // myid_char,         &
-          !        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
+          ! OPEN ( 26, FILE='SURFACE_DATA_AV_BIN' // TRIM( coupling_char ) // myid_char,            &
+          !        FORM='UNFORMATTED', POSITION='APPEND' )
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 26, FILE = 'SURFACE_DATA_AV_BIN' // TRIM( coupling_char ) // myid_char,        &
-                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
+             OPEN ( 26, FILE='SURFACE_DATA_AV_BIN' // TRIM( coupling_char ) // myid_char,          &
+                        FORM='UNFORMATTED', POSITION='APPEND' )
           ELSE
              IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
@@ -424,9 +427,10 @@
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 26, FILE = 'SURFACE_DATA_AV_BIN' // TRIM(coupling_char) // '/' // myid_char,&
-                           FORM = 'UNFORMATTED', IOSTAT = ioerr )
+                OPEN ( 26, FILE='SURFACE_DATA_AV_BIN' // TRIM( coupling_char ) // '/' // myid_char,&
+                           FORM='UNFORMATTED', IOSTAT=ioerr )
                 IF ( ioerr /= 0 )  THEN
-                   WRITE( 9, * )  '*** could not open "SURFACE_DATA_AV_BIN' // TRIM(coupling_char) &
-                                  // '/' // myid_char // '"! Trying again in 1 sec.'
+                   WRITE( 9, * )  '*** could not open "SURFACE_DATA_AV_BIN' //                     &
+                                  TRIM( coupling_char ) // '/' // myid_char //                     &
+                                  '"! Trying again in 1 sec.'
                    CALL fortran_sleep( 1 )
                 ENDIF
@@ -437,6 +441,5 @@
        CASE ( 30 )
 
-          OPEN ( 30, FILE = 'PLOT3D_DATA' // TRIM( coupling_char ) // myid_char,                   &
-                     FORM = 'UNFORMATTED' )
+          OPEN ( 30, FILE='PLOT3D_DATA' // TRIM( coupling_char ) // myid_char, FORM='UNFORMATTED' )
 !
 !--       Specifications for combine_plot_fields
@@ -450,6 +453,6 @@
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 80, FILE = 'PARTICLE_INFOS'//TRIM(coupling_char)//myid_char, &
-                        FORM = 'FORMATTED', POSITION='APPEND' )
+             OPEN ( 80, FILE='PARTICLE_INFOS'//TRIM(coupling_char)//myid_char, FORM='FORMATTED',   &
+                        POSITION='APPEND' )
           ELSE
              IF ( myid == 0  .AND.  .NOT. openfile(80)%opened_before )  THEN
@@ -466,6 +469,6 @@
              ENDIF
 #endif
-             OPEN ( 80, FILE = 'PARTICLE_INFOS' // TRIM( coupling_char ) // '/' // myid_char,      &
-                        FORM = 'FORMATTED', POSITION = 'APPEND' )
+             OPEN ( 80, FILE='PARTICLE_INFOS' // TRIM( coupling_char ) // '/' // myid_char,        &
+                        FORM='FORMATTED', POSITION='APPEND' )
           ENDIF
 
@@ -477,6 +480,6 @@
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 85, FILE = 'PARTICLE_DATA' // TRIM(coupling_char) // myid_char,                &
-                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
+             OPEN ( 85, FILE='PARTICLE_DATA' // TRIM(coupling_char) // myid_char,                  &
+                        FORM='UNFORMATTED', POSITION='APPEND' )
           ELSE
              IF ( myid == 0  .AND.  .NOT. openfile(85)%opened_before )  THEN
@@ -491,6 +494,6 @@
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 85, FILE = 'PARTICLE_DATA' // TRIM( coupling_char ) // '/' // myid_char,    &
-                           FORM = 'UNFORMATTED', POSITION = 'APPEND', IOSTAT = ioerr )
+                OPEN ( 85, FILE='PARTICLE_DATA' // TRIM( coupling_char ) // '/' // myid_char,      &
+                           FORM='UNFORMATTED', POSITION='APPEND', IOSTAT=ioerr )
                 IF ( ioerr /= 0 )  THEN
                    WRITE( 9, * )  '*** could not open "PARTICLE_DATA' // TRIM( coupling_char ) //  &
@@ -519,10 +522,10 @@
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 88, FILE = 'SVFIN' // TRIM( coupling_char ) // myid_char, FORM = 'UNFORMATTED',&
-                        STATUS = 'OLD', IOSTAT = ioerr )
-          ELSE
-
-             OPEN ( 88, FILE = 'SVFIN' // TRIM( coupling_char ) // '/' // myid_char,               &
-                        FORM = 'UNFORMATTED', STATUS = 'OLD', IOSTAT = ioerr )
+             OPEN ( 88, FILE='SVFIN' // TRIM( coupling_char ) // myid_char, FORM='UNFORMATTED',    &
+                        STATUS='OLD', IOSTAT=ioerr )
+          ELSE
+
+             OPEN ( 88, FILE='SVFIN' // TRIM( coupling_char ) // '/' // myid_char,                 &
+                        FORM='UNFORMATTED', STATUS='OLD', IOSTAT=ioerr )
           ENDIF
 
@@ -532,6 +535,6 @@
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 89, FILE = 'SVFOUT' // TRIM( coupling_char ) // myid_char,                     &
-                        FORM = 'UNFORMATTED', STATUS = 'NEW' )
+             OPEN ( 89, FILE='SVFOUT' // TRIM( coupling_char ) // myid_char, FORM='UNFORMATTED',   &
+                        STATUS='NEW' )
           ELSE
              IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
@@ -546,8 +549,8 @@
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 89, FILE = 'SVFOUT' // TRIM(coupling_char) // '/' // myid_char,             &
-                           FORM = 'UNFORMATTED', STATUS = 'NEW', IOSTAT = ioerr )
+                OPEN ( 89, FILE='SVFOUT' // TRIM( coupling_char ) // '/' // myid_char,             &
+                           FORM='UNFORMATTED', STATUS='NEW', IOSTAT=ioerr )
                 IF ( ioerr /= 0 )  THEN
-                   WRITE( 9, * )  '*** could not open "SVFOUT' // TRIM(coupling_char) // '/' //    &
+                   WRITE( 9, * )  '*** could not open "SVFOUT' // TRIM( coupling_char ) // '/' //  &
                                   myid_char // '"! Trying again in 1 sec.'
                    CALL fortran_sleep( 1 )
@@ -561,6 +564,5 @@
        CASE ( 117 )
 
-          OPEN ( 117, FILE = 'PROGRESS' // TRIM( coupling_char ), STATUS = 'REPLACE',              &
-                      FORM = 'FORMATTED' )
+          OPEN ( 117, FILE='PROGRESS' // TRIM( coupling_char ), STATUS='REPLACE', FORM='FORMATTED' )
 
 #if defined( __netcdf )
@@ -578,5 +580,5 @@
 !--       Inquire, if there is a netCDF file from a previous run. This should be opened for
 !--       extension, if its dimensions and variables match the actual run.
-          INQUIRE( FILE = filename, EXIST = netcdf_extend )
+          INQUIRE( FILE=filename, EXIST=netcdf_extend )
           IF ( netcdf_extend )  THEN
 !
@@ -618,5 +620,5 @@
 !--          that nothing is to do.
              IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
-                OPEN( 99, FILE = 'NO_COMBINE_PLOT_FIELDS_XY' )
+                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XY' )
                 WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
                 CLOSE( 99 )
@@ -638,5 +640,5 @@
 !--       Inquire, if there is a netCDF file from a previous run. This should be opened for
 !--       extension, if its dimensions and variables match the actual run.
-          INQUIRE( FILE = filename, EXIST = netcdf_extend )
+          INQUIRE( FILE=filename, EXIST=netcdf_extend )
 
           IF ( netcdf_extend )  THEN
@@ -679,5 +681,5 @@
 !--          that nothing is to do.
              IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
-                OPEN( 99, FILE = 'NO_COMBINE_PLOT_FIELDS_XZ' )
+                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XZ' )
                 WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
                 CLOSE( 99 )
@@ -699,5 +701,5 @@
 !--       Inquire, if there is a netCDF file from a previous run. This should be opened for
 !--       extension, if its dimensions and variables match the actual run.
-          INQUIRE( FILE = filename, EXIST=netcdf_extend )
+          INQUIRE( FILE=filename, EXIST=netcdf_extend )
 
           IF ( netcdf_extend )  THEN
@@ -740,5 +742,5 @@
 !--          that nothing is to do.
              IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
-                OPEN( 99, FILE = 'NO_COMBINE_PLOT_FIELDS_YZ' )
+                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_YZ' )
                 WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
                 CLOSE( 99 )
@@ -755,5 +757,5 @@
 !--       Inquire, if there is a netCDF file from a previous run. This should be opened for
 !--       extension, if its variables match the actual run.
-          INQUIRE( FILE = filename, EXIST = netcdf_extend )
+          INQUIRE( FILE=filename, EXIST=netcdf_extend )
 
           IF ( netcdf_extend )  THEN
@@ -794,5 +796,5 @@
 !--       Inquire, if there is a netCDF file from a previous run. This should be opened for
 !--       extension, if its variables match the actual run.
-          INQUIRE( FILE = filename, EXIST = netcdf_extend )
+          INQUIRE( FILE=filename, EXIST=netcdf_extend )
 
           IF ( netcdf_extend )  THEN
@@ -839,5 +841,5 @@
 !--       Inquire, if there is a netCDF file from a previous run. This should be opened for
 !--       extension, if its dimensions and variables match the actual run.
-          INQUIRE( FILE = filename, EXIST = netcdf_extend )
+          INQUIRE( FILE=filename, EXIST=netcdf_extend )
           IF ( netcdf_extend )  THEN
 !
@@ -998,5 +1000,5 @@
 !--       Inquire, if there is a netCDF file from a previous run. This should be opened for
 !--       extension, if its variables match the actual run.
-          INQUIRE( FILE = filename, EXIST = netcdf_extend )
+          INQUIRE( FILE=filename, EXIST=netcdf_extend )
 
           IF ( netcdf_extend )  THEN
@@ -1098,5 +1100,5 @@
 !--       Inquire, if there is a netCDF file from a previous run. This should be opened for
 !--       extension, if its variables match the actual run.
-          INQUIRE( FILE = filename, EXIST = netcdf_extend )
+          INQUIRE( FILE=filename, EXIST=netcdf_extend )
 
           IF ( netcdf_extend )  THEN
Index: /palm/trunk/SOURCE/chem_modules.f90
===================================================================
--- /palm/trunk/SOURCE/chem_modules.f90	(revision 4576)
+++ /palm/trunk/SOURCE/chem_modules.f90	(revision 4577)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! further re-formatting concerning Fortran parameter variables
+!
+! 4559 2020-06-11 08:51:48Z raasch
 ! file re-formatted to follow the PALM coding standard
 !
@@ -95,4 +98,30 @@
 
     IMPLICIT NONE
+
+    REAL, PARAMETER ::  xm_air   =   28.964e-3             !< air      molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_C     =   12.01115e-3           !< C        molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_Ca    =   40.07800e-3           !< Ca       molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_Cd    =  112.41000e-3           !< Cd       molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_Cl    =   35.45300e-3           !< Cl       molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_dummy = 1000.0e-3               !< dummy    molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_F     =   18.99840e-3           !< F        molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_H     =    1.00790e-3           !< H        molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_K     =   39.09800e-3           !< K        molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_Mg    =   24.30500e-3           !< Mg       molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_N     =   14.00670e-3           !< N        molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_Na    =   22.98977e-3           !< Na       molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_O     =   15.99940e-3           !< O        molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_Pb    =  207.20000e-3           !< Pb       molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_Pb210 =  210.00000e-3           !< Pb (210) molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_Rn222 =  222.00000e-3           !< Rn (222) molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_S     =   32.06400e-3           !< S        molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_CO2   = xm_C + xm_O * 2         !< CO2      molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_h2o   = xm_H * 2 + xm_O         !< H2O      molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_HNO3  = xm_H + xm_N + xm_O * 3  !< HNO3     molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_o3    = xm_O * 3                !< O3       molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_N2O5  = xm_N * 2 + xm_O * 5     !< N2O5     molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_NH4   = xm_N + xm_H * 4         !< NH4      molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_NO3   = xm_N + xm_O * 3         !< NO3      molecular weight (kg/mol)
+    REAL, PARAMETER ::  xm_SO4   = xm_S + xm_O * 4         !< SO4      molecular weight (kg/mol)
 
     CHARACTER (LEN=20) ::  bc_cs_b        = 'dirichlet'         !< namelist parameter: surface
@@ -247,29 +276,4 @@
     REAL(wp), DIMENSION(:,:,:), POINTER ::  tcs_m  !< pointer: to tcs array (temp)
 
-    REAL, PARAMETER ::  xm_air   =   28.964e-3             !< air      molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_C     =   12.01115e-3           !< C        molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_Ca    =   40.07800e-3           !< Ca       molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_Cd    =  112.41000e-3           !< Cd       molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_Cl    =   35.45300e-3           !< Cl       molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_dummy = 1000.0e-3               !< dummy    molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_F     =   18.99840e-3           !< F        molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_H     =    1.00790e-3           !< H        molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_K     =   39.09800e-3           !< K        molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_Mg    =   24.30500e-3           !< Mg       molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_N     =   14.00670e-3           !< N        molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_Na    =   22.98977e-3           !< Na       molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_O     =   15.99940e-3           !< O        molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_Pb    =  207.20000e-3           !< Pb       molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_Pb210 =  210.00000e-3           !< Pb (210) molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_Rn222 =  222.00000e-3           !< Rn (222) molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_S     =   32.06400e-3           !< S        molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_CO2   = xm_C + xm_O * 2         !< CO2      molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_h2o   = xm_H * 2 + xm_O         !< H2O      molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_HNO3  = xm_H + xm_N + xm_O * 3  !< HNO3     molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_o3    = xm_O * 3                !< O3       molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_N2O5  = xm_N * 2 + xm_O * 5     !< N2O5     molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_NH4   = xm_N + xm_H * 4         !< NH4      molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_NO3   = xm_N + xm_O * 3         !< NO3      molecular weight (kg/mol)
-    REAL, PARAMETER ::  xm_SO4   = xm_S + xm_O * 4         !< SO4      molecular weight (kg/mol)
 !
 !-  Define chemical variables within chem_species
Index: /palm/trunk/SOURCE/chem_photolysis_mod.f90
===================================================================
--- /palm/trunk/SOURCE/chem_photolysis_mod.f90	(revision 4576)
+++ /palm/trunk/SOURCE/chem_photolysis_mod.f90	(revision 4577)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! further re-formatting to follow the PALM coding standard
+!
+! 4559 2020-06-11 08:51:48Z raasch
 ! file re-formatted to follow the PALM coding standard
 !
@@ -89,37 +92,34 @@
 
 
-!   LOGICAL ::  unscheduled_photolysis_calls = .TRUE., & !< flag parameter indicating whether
-!                                                        !< additional calls of the photolysis code are allowed
-!               constant_albedo = .FALSE.,             & !< flag parameter indicating whether the
-!                                                        !< albedo may change depending on zenith
-!               force_photolysis_call = .FALSE.,       & !< flag parameter for unscheduled photolysis
-!                                                        !< calls
-!               photolysis = .FALSE.,                  & !< flag parameter indicating whether the
-!                                                        !< photolysis model is used
-!               sun_up    = .TRUE.,                    & !< flag parameter indicating whether the sun
-!                                                        !< is up or down
-!               photolysis = .TRUE.,                   & !< flag parameter indicing whether
-!                                                        !< photolysis shall be calculated
-!               sun_direction = .FALSE.                  !< flag parameter indicing whether solar
-!                                                        !< direction shall be calculated
-
+!   LOGICAL ::  unscheduled_photolysis_calls = .TRUE., & !< flag parameter indicating whether additional calls of the photolysis
+!                                                        !< code are allowed
+!               constant_albedo = .FALSE.,             & !< flag parameter indicating whether the albedo may change depending on
+!                                                        !< zenith
+!               force_photolysis_call = .FALSE.,       & !< flag parameter for unscheduled photolysis calls
+!               photolysis = .FALSE.,                  & !< flag parameter indicating whether the photolysis model is used
+!               sun_up    = .TRUE.,                    & !< flag parameter indicating whether the sun is up or down
+!               photolysis = .TRUE.,                   & !< flag parameter indicing whether photolysis shall be calculated
+!               sun_direction = .FALSE.                  !< flag parameter indicing whether solar direction shall be calculated
+
+!
 !-- Parameters for constant photolysis frequencies
-    INTEGER,PARAMETER :: nconst  = 15               !< available predefined photolysis prequencies
-                                                    !< for constant
-
-! Names for predefined fixed photolysis frequencies at zenith angle 0
+    INTEGER,PARAMETER :: nconst  = 15               !< available predefined photolysis prequencies for constant
+!
+!-- Names for predefined fixed photolysis frequencies at zenith angle 0
     CHARACTER(LEN=10), PARAMETER, DIMENSION(nconst) :: names_c =  (/                               &
                      'J_O31D    ','J_O33P    ','J_NO2     ','J_HNO3    ','J_RCHO    ',             &
                      'J         ','J         ','J         ','J         ','J         ',             &
                      'J         ','J         ','J         ','J         ','J         ' /)
-! Photolysis frequency at zenith angle 0 degrees in 1/s
+!
+!-- Photolysis frequency at zenith angle 0 degrees in 1/s
     REAL(wp), PARAMETER, DIMENSION(nconst) :: phot0 =  (/                                          &
                       2.489E-05_wp, 3.556E-04_wp, 8.89E-03_wp,5.334E-07_wp, 3.734E-05_wp,          &
                       0.0000E00_wp, 0.0000E00_wp, 0.0000E00_wp,0.0000E00_wp, 0.0000E00_wp,         &
                       0.0000E00_wp, 0.0000E00_wp, 0.0000E00_wp,0.0000E00_wp, 0.0000E00_wp /)
-
+!
 !-- Parameters for simple photolysis frequencies from MCM (http://mcm.leeds.ac.uk/MCM)
 !-- Saunders et al., 2003, Atmos. Chem. Phys., 3, 161-180
     INTEGER,PARAMETER :: nsimple = 15               !< available predefined photolysis prequencies for simple parameterisation
+!
 !-- Names for simple photolysis frequencies parameterisation (
     CHARACTER(LEN=10), PARAMETER, DIMENSION(nsimple) :: names_s =  (/                              &
@@ -127,5 +127,5 @@
                      'J_NO3_B   ','J_HONO    ','J_HNO3    ','J_HCHO_A  ','J_HCHO_B  ',             &
                      'J_CH3CHO  ','J         ','J         ','J         ','J_RCHO    ' /)
-
+!
 !-- Species dependent parameters for simple photolysis frequencies from MCM
 !-- (http://mcm.leeds.ac.uk/MCM)
@@ -136,10 +136,10 @@
                        7.344E-06_wp, 0.0000E00_wp, 0.0000E00_wp, 0.000E00_wp,  6.853E-05_wp /)
 
-   REAL(wp), PARAMETER, DIMENSION(nconst) :: par_m =  (/                                           &
+    REAL(wp), PARAMETER, DIMENSION(nconst) :: par_m =  (/                                          &
                            1.743_wp,    0.298_wp,    0.723_wp,    0.244_wp,    0.168_wp,           &
                            0.155_wp,    0.261_wp,    1.230_wp,    0.762_wp,    0.477_wp,           &
                            1.202_wp,    0.000_wp,    0.000_wp,    0.000_wp,    0.477_wp /)
 
-   REAL(wp), PARAMETER, DIMENSION(nconst) :: par_n =  (/                                           &
+    REAL(wp), PARAMETER, DIMENSION(nconst) :: par_n =  (/                                          &
                            0.474_wp,    0.080_wp,    0.279_wp,    0.267_wp,    0.108_wp,           &
                            0.125_wp,    0.288_wp,    0.307_wp,    0.353_wp,    0.323_wp,           &
@@ -150,5 +150,5 @@
                                                     !< specified otherwise)
 
-!
+
     INTERFACE photolysis_constant
        MODULE PROCEDURE photolysis_constant
Index: /palm/trunk/SOURCE/chemistry_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 4576)
+++ /palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 4577)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! further re-formatting to follow the PALM coding standard
+!
+! 4559 2020-06-11 08:51:48Z raasch
 ! file re-formatted to follow the PALM coding standard
 !
@@ -364,7 +367,5 @@
     REAL(kind=wp), ALLOCATABLE, DIMENSION(:,:,:,:), TARGET ::  spec_conc_3  !< pointer for swapping of timelevels for conc
     REAL(kind=wp), ALLOCATABLE, DIMENSION(:,:,:,:), TARGET ::  freq_1       !< pointer for phtolysis frequncies
-                                                                            !< (only 1 timelevel required)
-                                                                            !< (e.g. solver type)
-
+                                                                            !< (only 1 timelevel required) (e.g. solver type)
 
 !
@@ -1567,4 +1568,6 @@
     USE control_parameters
 
+    REAL(wp), PARAMETER ::  fill_value = -9999.0_wp    !< value for the _FillValue attribute
+
     CHARACTER(LEN=16) ::  spec_name
     CHARACTER(LEN=*)  ::  variable    !<
@@ -1586,5 +1589,4 @@
     REAL(wp), DIMENSION(mask_size_l(mid,1),mask_size_l(mid,2),mask_size_l(mid,3)) ::  local_pf   !<
 
-    REAL(wp), PARAMETER ::  fill_value = -9999.0_wp    !< value for the _FillValue attribute
 
 !
@@ -2279,4 +2281,12 @@
         ONLY:  dt_3d, intermediate_timestep_count, time_since_reference_point
 
+    REAL(wp), PARAMETER              ::  fr2ppm  = 1.0e6_wp              !< Conversion factor fraction to ppm
+!    REAL(wp), PARAMETER              ::  xm_air  = 28.96_wp              !< Mole mass of dry air
+!    REAL(wp), PARAMETER              ::  xm_h2o  = 18.01528_wp           !< Mole mass of water vapor
+    REAL(wp), PARAMETER              ::  p_std   = 101325.0_wp           !< standard pressure (Pa)
+    REAL(wp), PARAMETER              ::  ppm2fr  = 1.0e-6_wp             !< Conversion factor ppm to fraction
+    REAL(wp), PARAMETER              ::  t_std   = 273.15_wp             !< standard pressure (Pa)
+    REAL(wp), PARAMETER              ::  vmolcm  = 22.414e3_wp           !< Mole volume (22.414 l) in cm^3
+    REAL(wp), PARAMETER              ::  xna     = 6.022e23_wp           !< Avogadro number (molecules/mol)
 
     INTEGER,INTENT(IN)       :: i
@@ -2294,17 +2304,4 @@
     REAL(wp)                         ::  conv                                !< conversion factor
     REAL(kind=wp)                    ::  dt_chem
-
-    REAL(wp), PARAMETER              ::  fr2ppm  = 1.0e6_wp              !< Conversion factor
-                                                                         !< fraction to ppm
-!    REAL(wp), PARAMETER              ::  xm_air  = 28.96_wp              !< Mole mass of dry air
-!    REAL(wp), PARAMETER              ::  xm_h2o  = 18.01528_wp           !< Mole mass of water vapor
-    REAL(wp), PARAMETER              ::  p_std   = 101325.0_wp           !< standard pressure (Pa)
-    REAL(wp), PARAMETER              ::  ppm2fr  = 1.0e-6_wp             !< Conversion factor ppm to
-                                                                         !< fraction
-    REAL(wp), PARAMETER              ::  t_std   = 273.15_wp             !< standard pressure (Pa)
-    REAL(wp), PARAMETER              ::  vmolcm  = 22.414e3_wp           !< Mole volume (22.414 l)
-                                                                         !< in cm^3
-    REAL(wp), PARAMETER              ::  xna     = 6.022e23_wp           !< Avogadro number
-                                                                         !< (molecules/mol)
 
     REAL(wp),DIMENSION(size(rcntrl)) :: rcntrl_local
@@ -3442,11 +3439,12 @@
 !-- Particle parameters (PM10 (1), PM25 (2)) partsize (diameter in m), rhopart (density in kg/m3),
 !-- slipcor (slip correction factor dimensionless, Seinfeld and Pandis 2006, Table 9.3)
-    LOGICAL ::  match_lsm     !< flag indicating natural-type surface
-    LOGICAL ::  match_usm     !< flag indicating urban-type surface
-
     REAL(wp), DIMENSION(1:3,1:2), PARAMETER ::  particle_pars = RESHAPE( (/                        &
                                                          8.0e-6_wp, 1.14e3_wp, 1.016_wp, &   !<  1
                                                          0.7e-6_wp, 1.14e3_wp, 1.082_wp  &   !<  2
                                                          /), (/ 3, 2 /) )
+
+    LOGICAL ::  match_lsm     !< flag indicating natural-type surface
+    LOGICAL ::  match_usm     !< flag indicating urban-type surface
+
 !
 !-- List of names of possible tracers
@@ -5301,7 +5299,8 @@
 !
 !-- Local variables
+    REAL(wp), PARAMETER ::  dO3 = 0.13e-4          !< diffusion coefficient of ozon (m2/s)
+
     REAL(wp) ::  vpd                               !< vapour pressure deficit (kPa)
 
-    REAL(wp), PARAMETER ::  dO3 = 0.13e-4          !< diffusion coefficient of ozon (m2/s)
 !
 !-- Next line is to avoid compiler warning about unused variables
@@ -5395,4 +5394,6 @@
 !
 !-- Local variables:
+    REAL(wp), PARAMETER ::  p_sealevel = 1.01325e05    !< Pa
+
     REAL(wp) ::  bt
     REAL(wp) ::  f_env
@@ -5411,5 +5412,4 @@
     REAL(wp) ::  sinphi
 
-    REAL(wp), PARAMETER ::  p_sealevel = 1.01325e05    !< Pa
 !
 !-- Check whether vegetation is present:
@@ -6029,5 +6029,4 @@
 !
 !-- const
-
     REAL(wp), PARAMETER ::  kappa_stab = 0.35     !< von Karman constant
     REAL(wp), PARAMETER ::  thk = 0.19e-4         !< thermal diffusivity of dry air 20 C
Index: /palm/trunk/SOURCE/cpulog_mod.f90
===================================================================
--- /palm/trunk/SOURCE/cpulog_mod.f90	(revision 4576)
+++ /palm/trunk/SOURCE/cpulog_mod.f90	(revision 4577)
@@ -24,4 +24,7 @@
 ! -----------------
 ! $Id$
+! further re-formatting concerning Fortran parameter variables
+!
+! 4559 2020-06-11 08:51:48Z raasch
 ! file re-formatted to follow the PALM coding standard
 !
@@ -131,6 +134,7 @@
     INTEGER(iwp), PARAMETER ::  cpu_log_stop = 3      !<
 
+    LOGICAL, PARAMETER ::  cpu_log_nowait = .FALSE.       !<
+
     LOGICAL            ::  cpu_log_barrierwait = .FALSE.  !<
-    LOGICAL, PARAMETER ::  cpu_log_nowait = .FALSE.       !<
 
     REAL(dp) ::  initial_wallclock_time  !<
Index: /palm/trunk/SOURCE/data_output_binary_module.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_binary_module.f90	(revision 4576)
+++ /palm/trunk/SOURCE/data_output_binary_module.f90	(revision 4577)
@@ -24,4 +24,7 @@
 ! -----------------
 ! $Id$
+! further re-formatting to follow the PALM coding standard
+!
+! 4559 2020-06-11 08:51:48Z raasch
 ! file re-formatted to follow the PALM coding standard
 !
@@ -64,29 +67,21 @@
 
 
-    CHARACTER(LEN=*), PARAMETER ::  config_file_name = 'BINARY_TO_NETCDF_CONFIG'  !< name of config
-                                                                                  !< file
-    CHARACTER(LEN=*), PARAMETER ::  file_prefix = 'BIN_'                          !< file prefix for
-                                                                                  !< binary files
-    CHARACTER(LEN=*), PARAMETER ::  mode_binary = 'binary'                        !< string to
-                                                                                  !< select operation mode of module
+    CHARACTER(LEN=*), PARAMETER ::  config_file_name = 'BINARY_TO_NETCDF_CONFIG'  !< name of config file
+    CHARACTER(LEN=*), PARAMETER ::  file_prefix = 'BIN_'                          !< file prefix for binary files
+    CHARACTER(LEN=*), PARAMETER ::  mode_binary = 'binary'                        !< string to select operation mode of module
 
     INTEGER, PARAMETER ::  charlen = 100  !< maximum length of character variables
 
-    CHARACTER(LEN=charlen)      ::  file_suffix = ''             !< file suffix added to each file
-                                                                 !< name
-    CHARACTER(LEN=800)          ::  internal_error_message = ''  !< string containing the last error
-                                                                 !< message
+    CHARACTER(LEN=charlen)      ::  file_suffix = ''             !< file suffix added to each file name
+    CHARACTER(LEN=800)          ::  internal_error_message = ''  !< string containing the last error message
     CHARACTER(LEN=800)          ::  temp_string                  !< dummy string
 
-    INTEGER ::  binary_file_lowest_unit = 1000  !< lowest unit number of all binary files created by
-                                                !< this module
+    INTEGER ::  binary_file_lowest_unit = 1000  !< lowest unit number of all binary files created by this module
     INTEGER ::  config_file_unit                !< unit number of config file
     INTEGER ::  debug_output_unit               !< Fortran Unit Number of the debug-output file
     INTEGER ::  global_id_in_file = -1          !< value of global ID within a file
-    INTEGER ::  master_rank                     !< master rank for tasks to be executed by single PE
-                                                !< only
+    INTEGER ::  master_rank                     !< master rank for tasks to be executed by single PE only
     INTEGER ::  next_available_unit             !< next unit number available for new file
-    INTEGER ::  output_group_comm               !< MPI communicator addressing all MPI ranks which
-                                                !< participate in output
+    INTEGER ::  output_group_comm               !< MPI communicator addressing all MPI ranks which participate in output
 
     INTEGER, DIMENSION(:), ALLOCATABLE ::  files_highest_variable_id  !< highest assigned ID of
@@ -194,12 +189,11 @@
  SUBROUTINE binary_open_file( mode, file_name, file_id, return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_open_file'  !< name of this routine
+
     CHARACTER(LEN=charlen)             ::  bin_filename = ''  !< actual name of binary file
-    CHARACTER(LEN=7)                   ::  my_rank_char       !< string containing value of my_rank
-                                                              !< with leading zeros
+    CHARACTER(LEN=7)                   ::  my_rank_char       !< string containing value of my_rank with leading zeros
 
     CHARACTER(LEN=charlen), INTENT(IN) ::  file_name          !< name of file
     CHARACTER(LEN=*),       INTENT(IN) ::  mode               !< operation mode
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_open_file'  !< name of this routine
 
     INTEGER              ::  my_rank       !< MPI rank of local processor
@@ -256,6 +250,6 @@
           ENDIF
 
-          OPEN( config_file_unit, FILE = TRIM( config_file_name ) // TRIM( file_suffix ),          &
-                FORM = 'UNFORMATTED', STATUS = 'NEW', IOSTAT=return_value )
+          OPEN( config_file_unit, FILE=TRIM( config_file_name ) // TRIM( file_suffix ),          &
+                FORM='UNFORMATTED', STATUS='NEW', IOSTAT=return_value )
 
           IF ( return_value == 0 )  THEN
@@ -290,5 +284,5 @@
 !
 !--    Remove any pre-existing file
-       INQUIRE( FILE = TRIM( bin_filename ), EXIST = file_exists )
+       INQUIRE( FILE=TRIM( bin_filename ), EXIST=file_exists )
 
        IF ( file_exists )  THEN
@@ -304,6 +298,6 @@
 !--    Open binary file
        CALL internal_message( 'debug', routine_name // ': open file ' // TRIM( bin_filename ) )
-       OPEN ( next_available_unit, FILE = TRIM( bin_filename ), FORM = 'UNFORMATTED',              &
-              STATUS = 'NEW', IOSTAT = return_value )
+       OPEN ( next_available_unit, FILE=TRIM( bin_filename ), FORM='UNFORMATTED', STATUS='NEW',    &
+              IOSTAT=return_value )
 
        IF ( return_value == 0 )  THEN
@@ -355,4 +349,7 @@
                                     return_value )
 
+
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_write_attribute'  !< name of this routine
+
     CHARACTER(LEN=charlen)                       ::  attribute_type        !< data type of attribute
     CHARACTER(LEN=charlen)                       ::  output_string         !< output string
@@ -361,5 +358,4 @@
     CHARACTER(LEN=charlen), INTENT(IN), OPTIONAL ::  value_char            !< value of attribute
 
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_write_attribute'  !< name of this routine
 
     INTEGER, INTENT(IN)  ::  file_id       !< file ID
@@ -429,4 +425,6 @@
                                    dimension_type, dimension_length, return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_init_dimension'  !< name of this routine
+
     CHARACTER(LEN=charlen)             ::  output_string   !< output string
 
@@ -434,6 +432,4 @@
     CHARACTER(LEN=charlen), INTENT(IN) ::  dimension_type  !< data type of dimension
     CHARACTER(LEN=*),       INTENT(IN) ::  mode            !< operation mode
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_init_dimension'  !< name of this routine
 
     INTEGER, INTENT(IN)  ::  dimension_length  !< length of dimension
@@ -481,4 +477,5 @@
  SUBROUTINE binary_init_variable( mode, file_id, variable_id, variable_name, variable_type,        &
                                   dimension_ids, is_global, return_value )
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_init_variable'  !< name of this routine
 
     CHARACTER(LEN=charlen)             ::  output_string   !< output string
@@ -487,9 +484,7 @@
     CHARACTER(LEN=charlen), INTENT(IN) ::  variable_type   !< data type of variable
 
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_init_variable'  !< name of this routine
-
     INTEGER, INTENT(IN)  ::  file_id       !< file ID
+    INTEGER, INTENT(OUT) ::  return_value  !< return value
     INTEGER, INTENT(OUT) ::  variable_id   !< variable ID
-    INTEGER, INTENT(OUT) ::  return_value  !< return value
 
     INTEGER, DIMENSION(:), INTENT(IN) ::  dimension_ids  !< list of dimension IDs used by variable
@@ -530,8 +525,7 @@
  SUBROUTINE binary_stop_file_header_definition( file_id, return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_stop_file_header_definition'  !< name of this routine
+
     CHARACTER(LEN=charlen) ::  output_string  !< output string
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_stop_file_header_definition'  !< name of
-                                                                                         !< this routine
 
     INTEGER, INTENT(IN)  ::  file_id       !< file ID
@@ -568,7 +562,8 @@
                            return_value )
 
+
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_write_variable'  !< name of this routine
+
     CHARACTER(LEN=charlen) ::  output_string  !< output string
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_write_variable'  !< name of this routine
 
     CHARACTER(LEN=1), POINTER,             INTENT(IN), OPTIONAL                   ::  values_char_0d  !< output variable
@@ -790,7 +785,7 @@
  SUBROUTINE binary_finalize( file_id, return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_finalize'  !< name of this routine
+
     CHARACTER(LEN=charlen) ::  output_string  !< output string
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'binary_finalize'  !< name of this routine
 
     INTEGER, INTENT(IN)  ::  file_id       !< file ID
Index: /palm/trunk/SOURCE/data_output_module.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_module.f90	(revision 4576)
+++ /palm/trunk/SOURCE/data_output_module.f90	(revision 4577)
@@ -3,15 +3,14 @@
 ! 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/>.
+! 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 2019-2020 Leibniz Universitaet Hannover
@@ -25,6 +24,9 @@
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4500 2020-04-17 10:12:45Z suehring
 ! Avoid uninitialized variables
-! 
+!
 ! 4481 2020-03-31 18:55:54Z maronga
 ! Enable character-array output
@@ -72,24 +74,24 @@
     USE kinds
 
-    USE data_output_netcdf4_module, &
-       ONLY: netcdf4_init_dimension, &
-             netcdf4_get_error_message, &
-             netcdf4_stop_file_header_definition, &
-             netcdf4_init_module, &
-             netcdf4_init_variable, &
-             netcdf4_finalize, &
-             netcdf4_open_file, &
-             netcdf4_write_attribute, &
+    USE data_output_netcdf4_module,                                                                &
+       ONLY: netcdf4_finalize,                                                                     &
+             netcdf4_get_error_message,                                                            &
+             netcdf4_init_dimension,                                                               &
+             netcdf4_init_module,                                                                  &
+             netcdf4_init_variable,                                                                &
+             netcdf4_open_file,                                                                    &
+             netcdf4_stop_file_header_definition,                                                  &
+             netcdf4_write_attribute,                                                              &
              netcdf4_write_variable
 
-    USE data_output_binary_module, &
-       ONLY: binary_finalize, &
-             binary_get_error_message, &
-             binary_init_dimension, &
-             binary_stop_file_header_definition, &
-             binary_init_module, &
-             binary_init_variable, &
-             binary_open_file, &
-             binary_write_attribute, &
+    USE data_output_binary_module,                                                                 &
+       ONLY: binary_finalize,                                                                      &
+             binary_get_error_message,                                                             &
+             binary_init_dimension,                                                                &
+             binary_init_module,                                                                   &
+             binary_init_variable,                                                                 &
+             binary_open_file,                                                                     &
+             binary_stop_file_header_definition,                                                   &
+             binary_write_attribute,                                                               &
              binary_write_variable
 
@@ -113,9 +115,13 @@
        CHARACTER(LEN=charlen)                            ::  data_type = ''       !< data type
        CHARACTER(LEN=charlen)                            ::  name                 !< variable name
+       CHARACTER(LEN=charlen), DIMENSION(:), ALLOCATABLE ::  dimension_names      !< list of
+                                                                                  !< dimension names used by variable
        INTEGER                                           ::  id = no_id           !< id within file
-       LOGICAL                                           ::  is_global = .FALSE.  !< true if global variable
-       CHARACTER(LEN=charlen), DIMENSION(:), ALLOCATABLE ::  dimension_names      !< list of dimension names used by variable
-       INTEGER,                DIMENSION(:), ALLOCATABLE ::  dimension_ids        !< list of dimension ids used by variable
-       TYPE(attribute_type),   DIMENSION(:), ALLOCATABLE ::  attributes           !< list of attributes
+       LOGICAL                                           ::  is_global = .FALSE.  !< true if global
+                                                                                  !< variable
+       INTEGER,                DIMENSION(:), ALLOCATABLE ::  dimension_ids        !< list of
+                                                                                  !< dimension ids used by variable
+       TYPE(attribute_type),   DIMENSION(:), ALLOCATABLE ::  attributes           !< list of
+                                                                                  !< attributes
     END TYPE variable_type
 
@@ -123,26 +129,45 @@
        CHARACTER(LEN=charlen)                     ::  data_type = ''        !< data type
        CHARACTER(LEN=charlen)                     ::  name                  !< dimension name
-       INTEGER                                    ::  id = no_id            !< dimension id within file
+       INTEGER                                    ::  id = no_id            !< dimension id within
+                                                                            !< file
        INTEGER                                    ::  length                !< length of dimension
-       INTEGER                                    ::  length_mask           !< length of masked dimension
-       INTEGER                                    ::  variable_id = no_id   !< associated variable id within file
+       INTEGER                                    ::  length_mask           !< length of masked
+                                                                            !< dimension
+       INTEGER                                    ::  variable_id = no_id   !< associated variable
+                                                                            !< id within file
        LOGICAL                                    ::  is_masked = .FALSE.   !< true if masked
-       INTEGER,         DIMENSION(2)              ::  bounds                !< lower and upper bound of dimension
-       INTEGER,         DIMENSION(:), ALLOCATABLE ::  masked_indices        !< list of masked indices of dimension
-       INTEGER(KIND=1), DIMENSION(:), ALLOCATABLE ::  masked_values_int8    !< masked dimension values if 16bit integer
-       INTEGER(KIND=2), DIMENSION(:), ALLOCATABLE ::  masked_values_int16   !< masked dimension values if 16bit integer
-       INTEGER(KIND=4), DIMENSION(:), ALLOCATABLE ::  masked_values_int32   !< masked dimension values if 32bit integer
-       INTEGER(iwp),    DIMENSION(:), ALLOCATABLE ::  masked_values_intwp   !< masked dimension values if working-precision int
-       INTEGER(KIND=1), DIMENSION(:), ALLOCATABLE ::  values_int8           !< dimension values if 16bit integer
-       INTEGER(KIND=2), DIMENSION(:), ALLOCATABLE ::  values_int16          !< dimension values if 16bit integer
-       INTEGER(KIND=4), DIMENSION(:), ALLOCATABLE ::  values_int32          !< dimension values if 32bit integer
-       INTEGER(iwp),    DIMENSION(:), ALLOCATABLE ::  values_intwp          !< dimension values if working-precision integer
+       INTEGER,         DIMENSION(2)              ::  bounds                !< lower and upper bound
+                                                                            !< of dimension
+       INTEGER,         DIMENSION(:), ALLOCATABLE ::  masked_indices        !< list of masked
+                                                                            !< indices of dimension
+       INTEGER(KIND=1), DIMENSION(:), ALLOCATABLE ::  masked_values_int8    !< masked dimension
+                                                                            !< values if 16bit integer
+       INTEGER(KIND=2), DIMENSION(:), ALLOCATABLE ::  masked_values_int16   !< masked dimension
+                                                                            !< values if 16bit integer
+       INTEGER(KIND=4), DIMENSION(:), ALLOCATABLE ::  masked_values_int32   !< masked dimension
+                                                                            !< values if 32bit integer
+       INTEGER(iwp),    DIMENSION(:), ALLOCATABLE ::  masked_values_intwp   !< masked dimension
+                                                                            !< values if working-precision int
+       INTEGER(KIND=1), DIMENSION(:), ALLOCATABLE ::  values_int8           !< dimension values if
+                                                                            !< 16bit integer
+       INTEGER(KIND=2), DIMENSION(:), ALLOCATABLE ::  values_int16          !< dimension values if
+                                                                            !< 16bit integer
+       INTEGER(KIND=4), DIMENSION(:), ALLOCATABLE ::  values_int32          !< dimension values if
+                                                                            !< 32bit integer
+       INTEGER(iwp),    DIMENSION(:), ALLOCATABLE ::  values_intwp          !< dimension values if
+                                                                            !< working-precision integer
        LOGICAL,         DIMENSION(:), ALLOCATABLE ::  mask                  !< mask
-       REAL(KIND=4),    DIMENSION(:), ALLOCATABLE ::  masked_values_real32  !< masked dimension values if 32bit real
-       REAL(KIND=8),    DIMENSION(:), ALLOCATABLE ::  masked_values_real64  !< masked dimension values if 64bit real
-       REAL(wp),        DIMENSION(:), ALLOCATABLE ::  masked_values_realwp  !< masked dimension values if working-precision real
-       REAL(KIND=4),    DIMENSION(:), ALLOCATABLE ::  values_real32         !< dimension values if 32bit real
-       REAL(KIND=8),    DIMENSION(:), ALLOCATABLE ::  values_real64         !< dimension values if 64bit real
-       REAL(wp),        DIMENSION(:), ALLOCATABLE ::  values_realwp         !< dimension values if working-precision real
+       REAL(KIND=4),    DIMENSION(:), ALLOCATABLE ::  masked_values_real32  !< masked dimension
+                                                                            !< values if 32bit real
+       REAL(KIND=8),    DIMENSION(:), ALLOCATABLE ::  masked_values_real64  !< masked dimension
+                                                                            !< values if 64bit real
+       REAL(wp),        DIMENSION(:), ALLOCATABLE ::  masked_values_realwp  !< masked dimension
+                                                                            !< values if working-precision real
+       REAL(KIND=4),    DIMENSION(:), ALLOCATABLE ::  values_real32         !< dimension values if
+                                                                            !< 32bit real
+       REAL(KIND=8),    DIMENSION(:), ALLOCATABLE ::  values_real64         !< dimension values if
+                                                                            !< 64bit real
+       REAL(wp),        DIMENSION(:), ALLOCATABLE ::  values_realwp         !< dimension values if
+                                                                            !< working-precision real
        TYPE(attribute_type), DIMENSION(:), ALLOCATABLE ::  attributes       !< list of attributes
     END TYPE dimension_type
@@ -159,6 +184,6 @@
 
 
+    CHARACTER(LEN=800)     ::  internal_error_message = ''  !< string containing the last error message
     CHARACTER(LEN=charlen) ::  output_file_suffix = ''      !< file suffix added to each file name
-    CHARACTER(LEN=800)     ::  internal_error_message = ''  !< string containing the last error message
     CHARACTER(LEN=800)     ::  temp_string                  !< dummy string
 
@@ -296,8 +321,8 @@
  FUNCTION dom_def_file( file_name, file_format ) RESULT( return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_file'  !< name of this routine
+
     CHARACTER(LEN=*), INTENT(IN) ::  file_name    !< name of file to be created
     CHARACTER(LEN=*), INTENT(IN) ::  file_format  !< format of file to be created
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_file'  !< name of this routine
 
     INTEGER ::  f             !< loop index
@@ -385,9 +410,9 @@
                        mask ) RESULT( return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_dim'  !< name of this routine
+
     CHARACTER(LEN=*), INTENT(IN) ::  file_name       !< name of file
     CHARACTER(LEN=*), INTENT(IN) ::  dimension_name  !< name of dimension
     CHARACTER(LEN=*), INTENT(IN) ::  output_type     !< data type of dimension variable in output file
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_dim'  !< name of this routine
 
     INTEGER ::  d             !< loop index
@@ -416,7 +441,7 @@
     return_value = 0
 
-    CALL internal_message( 'debug', routine_name //                    &
-                           ': define dimension ' //                    &
-                           '(dimension "' // TRIM( dimension_name ) // &
+    CALL internal_message( 'debug', routine_name //                                                &
+                           ': define dimension ' //                                                &
+                           '(dimension "' // TRIM( dimension_name ) //                             &
                            '", file "' // TRIM( file_name ) // '")' )
 
@@ -427,6 +452,5 @@
     IF ( SIZE( bounds ) == 1 )  THEN
 !
-!--    Dimension has only lower bound, which means it changes its size
-!--    during simulation.
+!--    Dimension has only lower bound, which means it changes its size during simulation.
 !--    Set length to -1 as indicator.
        dimension%bounds(:) = bounds(1)
@@ -435,7 +459,7 @@
        IF ( PRESENT( mask ) )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                      &
-                                 ': unlimited dimensions cannot be masked ' // &
-                                 '(dimension "' // TRIM( dimension_name ) //   &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': unlimited dimensions cannot be masked ' //                     &
+                                 '(dimension "' // TRIM( dimension_name ) //                       &
                                  '", file "' // TRIM( file_name ) // '")!' )
        ENDIF
@@ -512,7 +536,7 @@
        ELSE
           return_value = 1
-          CALL internal_message( 'error', routine_name //                    &
-                                 ': no values given ' //                     &
-                                 '(dimension "' // TRIM( dimension_name ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': no values given ' //                                           &
+                                 '(dimension "' // TRIM( dimension_name ) //                       &
                                  '", file "' // TRIM( file_name ) // '")!' )
        ENDIF
@@ -520,7 +544,7 @@
        IF ( return_value == 2 )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                               &
-                                 ': number of values and given bounds do not match ' // &
-                                 '(dimension "' // TRIM( dimension_name ) //            &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': number of values and given bounds do not match ' //            &
+                                 '(dimension "' // TRIM( dimension_name ) //                       &
                                  '", file "' // TRIM( file_name ) // '")!' )
        ENDIF
@@ -533,7 +557,7 @@
              IF ( ALL( mask ) )  THEN
 
-                CALL internal_message( 'debug', routine_name //                              &
-                                       ': mask contains only TRUE values. Ignoring mask ' // &
-                                       '(dimension "' // TRIM( dimension_name ) //           &
+                CALL internal_message( 'debug', routine_name //                                    &
+                                       ': mask contains only TRUE values. Ignoring mask ' //       &
+                                       '(dimension "' // TRIM( dimension_name ) //                 &
                                        '", file "' // TRIM( file_name ) // '")!' )
 
@@ -577,5 +601,5 @@
                    ALLOCATE( dimension%masked_values_int32(0:dimension%length_mask-1) )
                    j = 0
-                   DO  i =dimension%bounds(1), dimension%bounds(2)
+                   DO  i = dimension%bounds(1), dimension%bounds(2)
                       IF ( dimension%mask(i) )  THEN
                          dimension%masked_values_int32(j) = dimension%values_int32(i)
@@ -639,7 +663,7 @@
           ELSE
              return_value = 1
-             CALL internal_message( 'error', routine_name //                           &
-                                    ': size of mask and given bounds do not match ' // &
-                                    '(dimension "' // TRIM( dimension_name ) //        &
+             CALL internal_message( 'error', routine_name //                                       &
+                                    ': size of mask and given bounds do not match ' //             &
+                                    '(dimension "' // TRIM( dimension_name ) //                    &
                                     '", file "' // TRIM( file_name ) // '")!' )
           ENDIF
@@ -650,7 +674,7 @@
 
        return_value = 1
-       CALL internal_message( 'error', routine_name //                                       &
-                              ': at least one but no more than two bounds must be given ' // &
-                              '(dimension "' // TRIM( dimension_name ) //                    &
+       CALL internal_message( 'error', routine_name //                                             &
+                              ': at least one but no more than two bounds must be given ' //       &
+                              '(dimension "' // TRIM( dimension_name ) //                          &
                               '", file "' // TRIM( file_name ) // '")!' )
 
@@ -667,8 +691,8 @@
 
                 return_value = 1
-                CALL internal_message( 'error', routine_name //                      &
-                                       ': file already initialized. ' //             &
-                                       'No further dimension definition allowed ' // &
-                                       '(dimension "' // TRIM( dimension_name ) //   &
+                CALL internal_message( 'error', routine_name //                                    &
+                                       ': file already initialized. ' //                           &
+                                       'No further dimension definition allowed ' //               &
+                                       '(dimension "' // TRIM( dimension_name ) //                 &
                                        '", file "' // TRIM( file_name ) // '")!' )
                 EXIT
@@ -686,9 +710,9 @@
                       IF ( files(f)%variables(i)%name == dimension%name )  THEN
                          return_value = 1
-                         CALL internal_message( 'error', routine_name //                    &
-                                 ': file already has a variable of this name defined. ' //  &
-                                 'Defining a dimension of the same name is not allowed ' // &
-                                 '(dimension "' // TRIM( dimension_name ) //                &
-                                 '", file "' // TRIM( file_name ) // '")!' )
+                         CALL internal_message( 'error', routine_name //                           &
+                                        ': file already has a variable of this name defined. ' //  &
+                                        'Defining a dimension of the same name is not allowed ' // &
+                                        '(dimension "' // TRIM( dimension_name ) //                &
+                                       '", file "' // TRIM( file_name ) // '")!' )
                          EXIT
                       ENDIF
@@ -704,8 +728,8 @@
                       IF ( files(f)%dimensions(d)%name == dimension%name )  THEN
                          return_value = 1
-                         CALL internal_message( 'error', routine_name //     &
-                                 ': dimension already exists in file ' //    &
-                                 '(dimension "' // TRIM( dimension_name ) // &
-                                 '", file "' // TRIM( file_name ) // '")!' )
+                         CALL internal_message( 'error', routine_name //                           &
+                                                ': dimension already exists in file ' //           &
+                                                '(dimension "' // TRIM( dimension_name ) //        &
+                                                '", file "' // TRIM( file_name ) // '")!' )
                          EXIT
                       ENDIF
@@ -736,6 +760,6 @@
        IF ( f > nfiles )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                                     &
-                                 ': file not found (dimension "' // TRIM( dimension_name ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': file not found (dimension "' // TRIM( dimension_name ) //      &
                                  '", file "' // TRIM( file_name ) // '")!' )
        ENDIF
@@ -750,5 +774,5 @@
 !> Add variable to database.
 !> If a variable is identical for each MPI rank, the optional argument 'is_global' should be set to
-!> TRUE. This flags the variable to be a global variable and is later only written once by the
+!> .TRUE. This flags the variable to be a global variable and is later only written once by the
 !> master output rank.
 !> Example call:
@@ -770,12 +794,12 @@
 !>          ALLOCATE( u(<z>,<y>,<x>) )
 !--------------------------------------------------------------------------------------------------!
- FUNCTION dom_def_var( file_name, variable_name, dimension_names, output_type, is_global ) &
+ FUNCTION dom_def_var( file_name, variable_name, dimension_names, output_type, is_global )         &
              RESULT( return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_var'  !< name of this routine
+
     CHARACTER(LEN=*), INTENT(IN) ::  file_name      !< name of file
+    CHARACTER(LEN=*), INTENT(IN) ::  output_type    !< data type of variable
     CHARACTER(LEN=*), INTENT(IN) ::  variable_name  !< name of variable
-    CHARACTER(LEN=*), INTENT(IN) ::  output_type    !< data type of variable
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_var'  !< name of this routine
 
     CHARACTER(LEN=*), DIMENSION(:), INTENT(IN) ::  dimension_names  !< list of dimension names
@@ -797,6 +821,6 @@
     found = .FALSE.
 
-    CALL internal_message( 'debug', routine_name //                                     &
-                           ': define variable (variable "' // TRIM( variable_name ) //  &
+    CALL internal_message( 'debug', routine_name //                                                &
+                           ': define variable (variable "' // TRIM( variable_name ) //             &
                            '", file "' // TRIM( file_name ) // '")' )
 
@@ -824,8 +848,8 @@
 
              return_value = 1
-             CALL internal_message( 'error', routine_name //                                  &
-                     ': file already initialized. No further variable definition allowed ' // &
-                     '(variable "' // TRIM( variable_name ) //                                &
-                     '", file "' // TRIM( file_name ) // '")!' )
+             CALL internal_message( 'error', routine_name //                                       &
+                          ': file already initialized. No further variable definition allowed ' // &
+                          '(variable "' // TRIM( variable_name ) //                                &
+                          '", file "' // TRIM( file_name ) // '")!' )
              EXIT
 
@@ -836,9 +860,9 @@
                 IF ( files(f)%dimensions(d)%name == variable%name )  THEN
                    return_value = 1
-                   CALL internal_message( 'error', routine_name //                    &
-                           ': file already has a dimension of this name defined. ' // &
-                           'Defining a variable of the same name is not allowed ' //  &
-                           '(variable "' // TRIM( variable_name ) //                  &
-                           '", file "' // TRIM( file_name ) // '")!' )
+                   CALL internal_message( 'error', routine_name //                                 &
+                                        ': file already has a dimension of this name defined. ' // &
+                                        'Defining a variable of the same name is not allowed ' //  &
+                                        '(variable "' // TRIM( variable_name ) //                  &
+                                        '", file "' // TRIM( file_name ) // '")!' )
                    EXIT
                 ENDIF
@@ -857,9 +881,9 @@
                    IF ( .NOT. found )  THEN
                       return_value = 1
-                      CALL internal_message( 'error', routine_name //                            &
-                              ': required dimension "'//  TRIM( variable%dimension_names(i) ) // &
-                              '" for variable is not defined ' //                                &
-                              '(variable "' // TRIM( variable_name ) //                          &
-                              '", file "' // TRIM( file_name ) // '")!' )
+                      CALL internal_message( 'error', routine_name //                              &
+                                 ': required dimension "'// TRIM( variable%dimension_names(i) ) // &
+                                 '" for variable is not defined ' //                               &
+                                 '(variable "' // TRIM( variable_name ) //                         &
+                                 '", file "' // TRIM( file_name ) // '")!' )
                       EXIT
                    ENDIF
@@ -870,8 +894,8 @@
 
              return_value = 1
-             CALL internal_message( 'error', routine_name //                      &
-                     ': no dimensions defined in file. Cannot define variable '// &
-                     '(variable "' // TRIM( variable_name ) //                    &
-                     '", file "' // TRIM( file_name ) // '")!' )
+             CALL internal_message( 'error', routine_name //                                       &
+                                    ': no dimensions defined in file. Cannot define variable '//   &
+                                    '(variable "' // TRIM( variable_name ) //                      &
+                                    '", file "' // TRIM( file_name ) // '")!' )
 
           ENDIF
@@ -891,8 +915,8 @@
                    IF ( files(f)%variables(i)%name == variable%name )  THEN
                       return_value = 1
-                      CALL internal_message( 'error', routine_name //   &
-                              ': variable already exists '//            &
-                              '(variable "' // TRIM( variable_name ) // &
-                              '", file "' // TRIM( file_name ) // '")!' )
+                      CALL internal_message( 'error', routine_name //                              &
+                                             ': variable already exists '//                        &
+                                             '(variable "' // TRIM( variable_name ) //             &
+                                             '", file "' // TRIM( file_name ) // '")!' )
                       EXIT
                    ENDIF
@@ -926,6 +950,6 @@
     IF ( f > nfiles )  THEN
        return_value = 1
-       CALL internal_message( 'error', routine_name //                                   &
-                              ': file not found (variable "' // TRIM( variable_name ) // &
+       CALL internal_message( 'error', routine_name //                                             &
+                              ': file not found (variable "' // TRIM( variable_name ) //           &
                               '", file "' // TRIM( file_name ) // '")!' )
     ENDIF
@@ -961,6 +985,6 @@
              RESULT( return_value )
 
+    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN)           ::  file_name               !< name of file
-    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN)           ::  value                   !< attribute value
     CHARACTER(LEN=*),      INTENT(IN), OPTIONAL ::  variable_name           !< name of variable
@@ -995,7 +1019,7 @@
     ENDIF
 
-    return_value = save_attribute_in_database( file_name=TRIM( file_name ), &
-                      variable_name=TRIM( variable_name_internal ),         &
-                      attribute=attribute, append=append_internal )
+    return_value = save_attribute_in_database( file_name=TRIM( file_name ),                        &
+                                               variable_name=TRIM( variable_name_internal ),       &
+                                               attribute=attribute, append=append_internal )
 
  END FUNCTION dom_def_att_char
@@ -1020,13 +1044,13 @@
 !>                   value=1_1 )
 !--------------------------------------------------------------------------------------------------!
- FUNCTION dom_def_att_int8( file_name, variable_name, attribute_name, value, append ) &
+ FUNCTION dom_def_att_int8( file_name, variable_name, attribute_name, value, append )              &
              RESULT( return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_att_int8'  !< name of routine
+
+    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN)           ::  file_name               !< name of file
-    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN), OPTIONAL ::  variable_name           !< name of variable
     CHARACTER(LEN=charlen)                      ::  variable_name_internal  !< internal copy of variable_name
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_att_int8'  !< name of routine
 
     INTEGER(KIND=1), INTENT(IN) ::  value  !< attribute value
@@ -1051,8 +1075,8 @@
        IF ( append )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                             &
-                                 ': numeric attribute cannot be appended ' //         &
-                                 '(attribute "' // TRIM( attribute_name ) //          &
-                                 '", variable "' // TRIM( variable_name_internal ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': numeric attribute cannot be appended ' //                      &
+                                 '(attribute "' // TRIM( attribute_name ) //                       &
+                                 '", variable "' // TRIM( variable_name_internal ) //              &
                                  '", file "' // TRIM( file_name ) // '")!' )
        ENDIF
@@ -1066,7 +1090,7 @@
        attribute%value_int8 = value
 
-       return_value = save_attribute_in_database( file_name=TRIM( file_name ), &
-                         variable_name=TRIM( variable_name_internal ),         &
-                         attribute=attribute, append=append_internal )
+       return_value = save_attribute_in_database( file_name=TRIM( file_name ),                     &
+                                                  variable_name=TRIM( variable_name_internal ),    &
+                                                  attribute=attribute, append=append_internal )
     ENDIF
 
@@ -1092,13 +1116,13 @@
 !>                   value=1_2 )
 !--------------------------------------------------------------------------------------------------!
- FUNCTION dom_def_att_int16( file_name, variable_name, attribute_name, value, append ) &
+ FUNCTION dom_def_att_int16( file_name, variable_name, attribute_name, value, append )             &
              RESULT( return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_att_int16'  !< name of routine
+
+    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN)           ::  file_name               !< name of file
-    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN), OPTIONAL ::  variable_name           !< name of variable
     CHARACTER(LEN=charlen)                      ::  variable_name_internal  !< internal copy of variable_name
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_att_int16'  !< name of routine
 
     INTEGER(KIND=2), INTENT(IN) ::  value  !< attribute value
@@ -1123,8 +1147,8 @@
        IF ( append )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                             &
-                                 ': numeric attribute cannot be appended ' //         &
-                                 '(attribute "' // TRIM( attribute_name ) //          &
-                                 '", variable "' // TRIM( variable_name_internal ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': numeric attribute cannot be appended ' //                      &
+                                 '(attribute "' // TRIM( attribute_name ) //                       &
+                                 '", variable "' // TRIM( variable_name_internal ) //              &
                                  '", file "' // TRIM( file_name ) // '")!' )
        ENDIF
@@ -1138,7 +1162,7 @@
        attribute%value_int16 = value
 
-       return_value = save_attribute_in_database( file_name=TRIM( file_name ), &
-                         variable_name=TRIM( variable_name_internal ),         &
-                         attribute=attribute, append=append_internal )
+       return_value = save_attribute_in_database( file_name=TRIM( file_name ),                     &
+                                                  variable_name=TRIM( variable_name_internal ),    &
+                                                  attribute=attribute, append=append_internal )
     ENDIF
 
@@ -1164,13 +1188,14 @@
 !>                   value=1_4 )
 !--------------------------------------------------------------------------------------------------!
- FUNCTION dom_def_att_int32( file_name, variable_name, attribute_name, value, append ) &
+ FUNCTION dom_def_att_int32( file_name, variable_name, attribute_name, value, append )             &
              RESULT( return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_att_int32'  !< name of routine
+
+
+    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN)           ::  file_name               !< name of file
-    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN), OPTIONAL ::  variable_name           !< name of variable
     CHARACTER(LEN=charlen)                      ::  variable_name_internal  !< internal copy of variable_name
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_att_int32'  !< name of routine
 
     INTEGER(KIND=4), INTENT(IN) ::  value  !< attribute value
@@ -1195,8 +1220,8 @@
        IF ( append )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                             &
-                                 ': numeric attribute cannot be appended ' //         &
-                                 '(attribute "' // TRIM( attribute_name ) //          &
-                                 '", variable "' // TRIM( variable_name_internal ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': numeric attribute cannot be appended ' //                      &
+                                 '(attribute "' // TRIM( attribute_name ) //                       &
+                                 '", variable "' // TRIM( variable_name_internal ) //              &
                                  '", file "' // TRIM( file_name ) // '")!' )
        ENDIF
@@ -1210,7 +1235,7 @@
        attribute%value_int32 = value
 
-       return_value = save_attribute_in_database( file_name=TRIM( file_name ), &
-                         variable_name=TRIM( variable_name_internal ),         &
-                         attribute=attribute, append=append_internal )
+       return_value = save_attribute_in_database( file_name=TRIM( file_name ),                     &
+                                                  variable_name=TRIM( variable_name_internal ),    &
+                                                  attribute=attribute, append=append_internal )
     ENDIF
 
@@ -1236,13 +1261,13 @@
 !>                   value=1.0_4 )
 !--------------------------------------------------------------------------------------------------!
- FUNCTION dom_def_att_real32( file_name, variable_name, attribute_name, value, append ) &
+ FUNCTION dom_def_att_real32( file_name, variable_name, attribute_name, value, append )            &
              RESULT( return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_att_real32'  !< name of routine
+
+    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN)           ::  file_name               !< name of file
-    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN), OPTIONAL ::  variable_name           !< name of variable
     CHARACTER(LEN=charlen)                      ::  variable_name_internal  !< internal copy of variable_name
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_att_real32'  !< name of routine
 
     INTEGER ::  return_value  !< return value
@@ -1267,8 +1292,8 @@
        IF ( append )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                             &
-                                 ': numeric attribute cannot be appended ' //         &
-                                 '(attribute "' // TRIM( attribute_name ) //          &
-                                 '", variable "' // TRIM( variable_name_internal ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': numeric attribute cannot be appended ' //                      &
+                                 '(attribute "' // TRIM( attribute_name ) //                       &
+                                 '", variable "' // TRIM( variable_name_internal ) //              &
                                  '", file "' // TRIM( file_name ) // '")!' )
        ENDIF
@@ -1282,7 +1307,7 @@
        attribute%value_real32 = value
 
-       return_value = save_attribute_in_database( file_name=TRIM( file_name ), &
-                         variable_name=TRIM( variable_name_internal ),         &
-                         attribute=attribute, append=append_internal )
+       return_value = save_attribute_in_database( file_name=TRIM( file_name ),                     &
+                                                  variable_name=TRIM( variable_name_internal ),    &
+                                                  attribute=attribute, append=append_internal )
     ENDIF
 
@@ -1308,13 +1333,13 @@
 !>                   value=1.0_8 )
 !--------------------------------------------------------------------------------------------------!
- FUNCTION dom_def_att_real64( file_name, variable_name, attribute_name, value, append ) &
+ FUNCTION dom_def_att_real64( file_name, variable_name, attribute_name, value, append )            &
              RESULT( return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_att_real64'  !< name of routine
+
+    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN)           ::  file_name               !< name of file
-    CHARACTER(LEN=*),      INTENT(IN)           ::  attribute_name          !< name of attribute
     CHARACTER(LEN=*),      INTENT(IN), OPTIONAL ::  variable_name           !< name of variable
     CHARACTER(LEN=charlen)                      ::  variable_name_internal  !< internal copy of variable_name
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_def_att_real64'  !< name of routine
 
     INTEGER ::  return_value  !< return value
@@ -1339,8 +1364,8 @@
        IF ( append )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                             &
-                                 ': numeric attribute cannot be appended ' //         &
-                                 '(attribute "' // TRIM( attribute_name ) //          &
-                                 '", variable "' // TRIM( variable_name_internal ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': numeric attribute cannot be appended ' //                      &
+                                 '(attribute "' // TRIM( attribute_name ) //                       &
+                                 '", variable "' // TRIM( variable_name_internal ) //              &
                                  '", file "' // TRIM( file_name ) // '")!' )
        ENDIF
@@ -1354,7 +1379,7 @@
        attribute%value_real64 = value
 
-       return_value = save_attribute_in_database( file_name=TRIM( file_name ), &
-                         variable_name=TRIM( variable_name_internal ),         &
-                         attribute=attribute, append=append_internal )
+       return_value = save_attribute_in_database( file_name=TRIM( file_name ),                     &
+                                                  variable_name=TRIM( variable_name_internal ),    &
+                                                  attribute=attribute, append=append_internal )
     ENDIF
 
@@ -1408,20 +1433,19 @@
           IF ( files(f)%is_init )  CYCLE
 
-          CALL internal_message( 'debug', routine_name // ': initialize file "' // &
+          CALL internal_message( 'debug', routine_name // ': initialize file "' //                 &
                                  TRIM( files(f)%name ) // '"' )
 !
 !--       Open file
-          CALL open_output_file( files(f)%format, files(f)%name, files(f)%id, &
+          CALL open_output_file( files(f)%format, files(f)%name, files(f)%id,                      &
                                  return_value=return_value )
 !
 !--       Initialize file header:
 !--       define dimensions and variables and write attributes
-          IF ( return_value == 0 )  &
-             CALL init_file_header( files(f), return_value=return_value )
+          IF ( return_value == 0 )  CALL init_file_header( files(f), return_value=return_value )
 !
 !--       End file definition
-          IF ( return_value == 0 )  &
-             CALL stop_file_header_definition( files(f)%format, files(f)%id, &
-                                               files(f)%name, return_value )
+          IF ( return_value == 0 )                                                                 &
+             CALL stop_file_header_definition( files(f)%format, files(f)%id, files(f)%name,        &
+                                               return_value )
 
           IF ( return_value == 0 )  THEN
@@ -1433,71 +1457,71 @@
              DO  d = 1, SIZE( files(f)%dimensions )
                 IF ( ALLOCATED( files(f)%dimensions(d)%values_int8 ) )  THEN
-                   ALLOCATE( values_int8(files(f)%dimensions(d)%bounds(1): &
+                   ALLOCATE( values_int8(files(f)%dimensions(d)%bounds(1):                         &
                                          files(f)%dimensions(d)%bounds(2)) )
                    values_int8 = files(f)%dimensions(d)%values_int8
                    values_int8_pointer => values_int8
-                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name, &
-                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),    &
-                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),    &
+                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name,       &
+                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),          &
+                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),          &
                                      values_int8_1d=values_int8_pointer )
                    DEALLOCATE( values_int8 )
                 ELSEIF ( ALLOCATED( files(f)%dimensions(d)%values_int16 ) )  THEN
-                   ALLOCATE( values_int16(files(f)%dimensions(d)%bounds(1): &
+                   ALLOCATE( values_int16(files(f)%dimensions(d)%bounds(1):                        &
                                           files(f)%dimensions(d)%bounds(2)) )
                    values_int16 = files(f)%dimensions(d)%values_int16
                    values_int16_pointer => values_int16
-                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name, &
-                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),    &
-                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),    &
+                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name,       &
+                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),          &
+                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),          &
                                      values_int16_1d=values_int16_pointer )
                    DEALLOCATE( values_int16 )
                 ELSEIF ( ALLOCATED( files(f)%dimensions(d)%values_int32 ) )  THEN
-                   ALLOCATE( values_int32(files(f)%dimensions(d)%bounds(1): &
+                   ALLOCATE( values_int32(files(f)%dimensions(d)%bounds(1):                        &
                                           files(f)%dimensions(d)%bounds(2)) )
                    values_int32 = files(f)%dimensions(d)%values_int32
                    values_int32_pointer => values_int32
-                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name, &
-                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),    &
-                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),    &
+                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name,       &
+                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),          &
+                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),          &
                                      values_int32_1d=values_int32_pointer )
                    DEALLOCATE( values_int32 )
                 ELSEIF ( ALLOCATED( files(f)%dimensions(d)%values_intwp ) )  THEN
-                   ALLOCATE( values_intwp(files(f)%dimensions(d)%bounds(1): &
+                   ALLOCATE( values_intwp(files(f)%dimensions(d)%bounds(1):                        &
                                           files(f)%dimensions(d)%bounds(2)) )
                    values_intwp = files(f)%dimensions(d)%values_intwp
                    values_intwp_pointer => values_intwp
-                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name, &
-                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),    &
-                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),    &
+                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name,       &
+                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),          &
+                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),          &
                                      values_intwp_1d=values_intwp_pointer )
                    DEALLOCATE( values_intwp )
                 ELSEIF ( ALLOCATED( files(f)%dimensions(d)%values_real32 ) )  THEN
-                   ALLOCATE( values_real32(files(f)%dimensions(d)%bounds(1): &
+                   ALLOCATE( values_real32(files(f)%dimensions(d)%bounds(1):                       &
                                            files(f)%dimensions(d)%bounds(2)) )
                    values_real32 = files(f)%dimensions(d)%values_real32
                    values_real32_pointer => values_real32
-                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name, &
-                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),    &
-                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),    &
+                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name,       &
+                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),          &
+                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),          &
                                      values_real32_1d=values_real32_pointer )
                    DEALLOCATE( values_real32 )
                 ELSEIF ( ALLOCATED( files(f)%dimensions(d)%values_real64 ) )  THEN
-                   ALLOCATE( values_real64(files(f)%dimensions(d)%bounds(1): &
+                   ALLOCATE( values_real64(files(f)%dimensions(d)%bounds(1):                       &
                                            files(f)%dimensions(d)%bounds(2)) )
                    values_real64 = files(f)%dimensions(d)%values_real64
                    values_real64_pointer => values_real64
-                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name, &
-                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),    &
-                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),    &
+                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name,       &
+                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),          &
+                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),          &
                                      values_real64_1d=values_real64_pointer )
                    DEALLOCATE( values_real64 )
                 ELSEIF ( ALLOCATED( files(f)%dimensions(d)%values_realwp ) )  THEN
-                   ALLOCATE( values_realwp(files(f)%dimensions(d)%bounds(1): &
+                   ALLOCATE( values_realwp(files(f)%dimensions(d)%bounds(1):                       &
                                            files(f)%dimensions(d)%bounds(2)) )
                    values_realwp = files(f)%dimensions(d)%values_realwp
                    values_realwp_pointer => values_realwp
-                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name, &
-                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),    &
-                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),    &
+                   return_value = dom_write_var( files(f)%name, files(f)%dimensions(d)%name,       &
+                                     bounds_start=(/ files(f)%dimensions(d)%bounds(1) /),          &
+                                     bounds_end  =(/ files(f)%dimensions(d)%bounds(2) /),          &
                                      values_realwp_1d=values_realwp_pointer )
                    DEALLOCATE( values_realwp )
@@ -1538,20 +1562,20 @@
 !>       chosen, the values are written to file as given in the 'dom_write_var' call.
 !--------------------------------------------------------------------------------------------------!
- FUNCTION dom_write_var( file_name, variable_name, bounds_start, bounds_end,         &
-             values_char_0d,   values_char_1d,   values_char_2d,   values_char_3d,   &
-             values_int8_0d,   values_int8_1d,   values_int8_2d,   values_int8_3d,   &
-             values_int16_0d,  values_int16_1d,  values_int16_2d,  values_int16_3d,  &
-             values_int32_0d,  values_int32_1d,  values_int32_2d,  values_int32_3d,  &
-             values_intwp_0d,  values_intwp_1d,  values_intwp_2d,  values_intwp_3d,  &
-             values_real32_0d, values_real32_1d, values_real32_2d, values_real32_3d, &
-             values_real64_0d, values_real64_1d, values_real64_2d, values_real64_3d, &
-             values_realwp_0d, values_realwp_1d, values_realwp_2d, values_realwp_3d  &
+ FUNCTION dom_write_var( file_name, variable_name, bounds_start, bounds_end,                       &
+             values_char_0d,   values_char_1d,   values_char_2d,   values_char_3d,                 &
+             values_int8_0d,   values_int8_1d,   values_int8_2d,   values_int8_3d,                 &
+             values_int16_0d,  values_int16_1d,  values_int16_2d,  values_int16_3d,                &
+             values_int32_0d,  values_int32_1d,  values_int32_2d,  values_int32_3d,                &
+             values_intwp_0d,  values_intwp_1d,  values_intwp_2d,  values_intwp_3d,                &
+             values_real32_0d, values_real32_1d, values_real32_2d, values_real32_3d,               &
+             values_real64_0d, values_real64_1d, values_real64_2d, values_real64_3d,               &
+             values_realwp_0d, values_realwp_1d, values_realwp_2d, values_realwp_3d                &
              ) RESULT( return_value )
+
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_write_var'  !< name of routine
 
     CHARACTER(LEN=charlen)            ::  file_format    !< file format chosen for file
     CHARACTER(LEN=*),      INTENT(IN) ::  file_name      !< name of file
     CHARACTER(LEN=*),      INTENT(IN) ::  variable_name  !< name of variable
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_write_var'  !< name of routine
 
     CHARACTER(LEN=1), POINTER, INTENT(IN), OPTIONAL                   ::  values_char_0d           !< output variable
@@ -1579,4 +1603,5 @@
     INTEGER, DIMENSION(:),   INTENT(IN)  ::  bounds_end             !< end index per dimension of variable
     INTEGER, DIMENSION(:),   INTENT(IN)  ::  bounds_start           !< start index per dimension of variable
+
     INTEGER, DIMENSION(:),   ALLOCATABLE ::  bounds_origin          !< first index of each dimension
     INTEGER, DIMENSION(:),   ALLOCATABLE ::  bounds_start_internal  !< start index per dim. for output after masking
@@ -1604,17 +1629,4 @@
     INTEGER(iwp),    POINTER, INTENT(IN), OPTIONAL, DIMENSION(:,:,:) ::  values_intwp_3d            !< output variable
 
-    INTEGER(KIND=1), TARGET, ALLOCATABLE, DIMENSION(:)               ::  values_int8_1d_resorted    !< resorted output variable
-    INTEGER(KIND=2), TARGET, ALLOCATABLE, DIMENSION(:)               ::  values_int16_1d_resorted   !< resorted output variable
-    INTEGER(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:)               ::  values_int32_1d_resorted   !< resorted output variable
-    INTEGER(iwp),    TARGET, ALLOCATABLE, DIMENSION(:)               ::  values_intwp_1d_resorted   !< resorted output variable
-    INTEGER(KIND=1), TARGET, ALLOCATABLE, DIMENSION(:,:)             ::  values_int8_2d_resorted    !< resorted output variable
-    INTEGER(KIND=2), TARGET, ALLOCATABLE, DIMENSION(:,:)             ::  values_int16_2d_resorted   !< resorted output variable
-    INTEGER(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:,:)             ::  values_int32_2d_resorted   !< resorted output variable
-    INTEGER(iwp),    TARGET, ALLOCATABLE, DIMENSION(:,:)             ::  values_intwp_2d_resorted   !< resorted output variable
-    INTEGER(KIND=1), TARGET, ALLOCATABLE, DIMENSION(:,:,:)           ::  values_int8_3d_resorted    !< resorted output variable
-    INTEGER(KIND=2), TARGET, ALLOCATABLE, DIMENSION(:,:,:)           ::  values_int16_3d_resorted   !< resorted output variable
-    INTEGER(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:,:,:)           ::  values_int32_3d_resorted   !< resorted output variable
-    INTEGER(iwp),    TARGET, ALLOCATABLE, DIMENSION(:,:,:)           ::  values_intwp_3d_resorted   !< resorted output variable
-
     INTEGER(KIND=1), POINTER                                         ::  values_int8_0d_pointer     !< pointer to resortet array
     INTEGER(KIND=2), POINTER                                         ::  values_int16_0d_pointer    !< pointer to resortet array
@@ -1634,4 +1646,17 @@
     INTEGER(iwp),    POINTER, CONTIGUOUS, DIMENSION(:,:,:)           ::  values_intwp_3d_pointer    !< pointer to resortet array
 
+    INTEGER(KIND=1), TARGET, ALLOCATABLE, DIMENSION(:)               ::  values_int8_1d_resorted    !< resorted output variable
+    INTEGER(KIND=2), TARGET, ALLOCATABLE, DIMENSION(:)               ::  values_int16_1d_resorted   !< resorted output variable
+    INTEGER(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:)               ::  values_int32_1d_resorted   !< resorted output variable
+    INTEGER(iwp),    TARGET, ALLOCATABLE, DIMENSION(:)               ::  values_intwp_1d_resorted   !< resorted output variable
+    INTEGER(KIND=1), TARGET, ALLOCATABLE, DIMENSION(:,:)             ::  values_int8_2d_resorted    !< resorted output variable
+    INTEGER(KIND=2), TARGET, ALLOCATABLE, DIMENSION(:,:)             ::  values_int16_2d_resorted   !< resorted output variable
+    INTEGER(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:,:)             ::  values_int32_2d_resorted   !< resorted output variable
+    INTEGER(iwp),    TARGET, ALLOCATABLE, DIMENSION(:,:)             ::  values_intwp_2d_resorted   !< resorted output variable
+    INTEGER(KIND=1), TARGET, ALLOCATABLE, DIMENSION(:,:,:)           ::  values_int8_3d_resorted    !< resorted output variable
+    INTEGER(KIND=2), TARGET, ALLOCATABLE, DIMENSION(:,:,:)           ::  values_int16_3d_resorted   !< resorted output variable
+    INTEGER(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:,:,:)           ::  values_int32_3d_resorted   !< resorted output variable
+    INTEGER(iwp),    TARGET, ALLOCATABLE, DIMENSION(:,:,:)           ::  values_intwp_3d_resorted   !< resorted output variable
+
     REAL(KIND=4), POINTER, INTENT(IN), OPTIONAL                      ::  values_real32_0d           !< output variable
     REAL(KIND=8), POINTER, INTENT(IN), OPTIONAL                      ::  values_real64_0d           !< output variable
@@ -1647,14 +1672,4 @@
     REAL(wp),     POINTER, INTENT(IN), OPTIONAL, DIMENSION(:,:,:)    ::  values_realwp_3d           !< output variable
 
-    REAL(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:)                  ::  values_real32_1d_resorted  !< resorted output variable
-    REAL(KIND=8), TARGET, ALLOCATABLE, DIMENSION(:)                  ::  values_real64_1d_resorted  !< resorted output variable
-    REAL(wp),     TARGET, ALLOCATABLE, DIMENSION(:)                  ::  values_realwp_1d_resorted  !< resorted output variable
-    REAL(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:,:)                ::  values_real32_2d_resorted  !< resorted output variable
-    REAL(KIND=8), TARGET, ALLOCATABLE, DIMENSION(:,:)                ::  values_real64_2d_resorted  !< resorted output variable
-    REAL(wp),     TARGET, ALLOCATABLE, DIMENSION(:,:)                ::  values_realwp_2d_resorted  !< resorted output variable
-    REAL(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:,:,:)              ::  values_real32_3d_resorted  !< resorted output variable
-    REAL(KIND=8), TARGET, ALLOCATABLE, DIMENSION(:,:,:)              ::  values_real64_3d_resorted  !< resorted output variable
-    REAL(wp),     TARGET, ALLOCATABLE, DIMENSION(:,:,:)              ::  values_realwp_3d_resorted  !< resorted output variable
-
     REAL(KIND=4), POINTER                                            ::  values_real32_0d_pointer   !< pointer to resortet array
     REAL(KIND=8), POINTER                                            ::  values_real64_0d_pointer   !< pointer to resortet array
@@ -1670,4 +1685,14 @@
     REAL(wp),     POINTER, CONTIGUOUS, DIMENSION(:,:,:)              ::  values_realwp_3d_pointer   !< pointer to resortet array
 
+    REAL(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:)                  ::  values_real32_1d_resorted  !< resorted output variable
+    REAL(KIND=8), TARGET, ALLOCATABLE, DIMENSION(:)                  ::  values_real64_1d_resorted  !< resorted output variable
+    REAL(wp),     TARGET, ALLOCATABLE, DIMENSION(:)                  ::  values_realwp_1d_resorted  !< resorted output variable
+    REAL(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:,:)                ::  values_real32_2d_resorted  !< resorted output variable
+    REAL(KIND=8), TARGET, ALLOCATABLE, DIMENSION(:,:)                ::  values_real64_2d_resorted  !< resorted output variable
+    REAL(wp),     TARGET, ALLOCATABLE, DIMENSION(:,:)                ::  values_realwp_2d_resorted  !< resorted output variable
+    REAL(KIND=4), TARGET, ALLOCATABLE, DIMENSION(:,:,:)              ::  values_real32_3d_resorted  !< resorted output variable
+    REAL(KIND=8), TARGET, ALLOCATABLE, DIMENSION(:,:,:)              ::  values_real64_3d_resorted  !< resorted output variable
+    REAL(wp),     TARGET, ALLOCATABLE, DIMENSION(:,:,:)              ::  values_realwp_3d_resorted  !< resorted output variable
+
     TYPE(dimension_type), DIMENSION(:), ALLOCATABLE ::  dimension_list  !< list of used dimensions of variable
 
@@ -1676,9 +1701,9 @@
     output_return_value = 0
 
-    CALL internal_message( 'debug', routine_name // ': write ' // TRIM( variable_name ) // &
+    CALL internal_message( 'debug', routine_name // ': write ' // TRIM( variable_name ) //         &
                            ' into file ' // TRIM( file_name ) )
 !
 !-- Search for variable within file
-    CALL find_var_in_file( file_name, variable_name, file_format, file_id, variable_id, &
+    CALL find_var_in_file( file_name, variable_name, file_format, file_id, variable_id,            &
                            is_global, dimension_list, return_value=return_value  )
 
@@ -1686,11 +1711,11 @@
 !
 !--    Check if the correct amount of variable bounds were given
-       IF ( SIZE( bounds_start ) /= SIZE( dimension_list )  .OR.  &
-            SIZE( bounds_end ) /= SIZE( dimension_list ) )  THEN
+       IF ( SIZE( bounds_start ) /= SIZE( dimension_list )  .OR.                                   &
+            SIZE( bounds_end )   /= SIZE( dimension_list ) )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                  &
-                                 ': number bounds do not match with ' //   &
-                                 'number of dimensions of variable ' //    &
-                                 '(variable "' // TRIM( variable_name ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': number bounds do not match with ' //                           &
+                                 'number of dimensions of variable ' //                            &
+                                 '(variable "' // TRIM( variable_name ) //                         &
                                  '", file "' // TRIM( file_name ) // '")!' )
        ENDIF
@@ -1706,30 +1731,29 @@
 
        WRITE( temp_string, * ) bounds_start
-       CALL internal_message( 'debug', routine_name //                    &
-                              ': file "' // TRIM( file_name ) //          &
-                              '", variable "' // TRIM( variable_name ) // &
+       CALL internal_message( 'debug', routine_name //                                             &
+                              ': file "' // TRIM( file_name ) //                                   &
+                              '", variable "' // TRIM( variable_name ) //                          &
                               '", bounds_start =' // TRIM( temp_string ) )
        WRITE( temp_string, * ) bounds_end
-       CALL internal_message( 'debug', routine_name //                    &
-                              ': file "' // TRIM( file_name ) //          &
-                              '", variable "' // TRIM( variable_name ) // &
+       CALL internal_message( 'debug', routine_name //                                             &
+                              ': file "' // TRIM( file_name ) //                                   &
+                              '", variable "' // TRIM( variable_name ) //                          &
                               '", bounds_end =' // TRIM( temp_string ) )
 !
 !--    Get bounds for masking
-       CALL get_masked_indices_and_masked_dimension_bounds( dimension_list,                  &
-               bounds_start, bounds_end, bounds_start_internal, value_counts, bounds_origin, &
-               masked_indices )
+       CALL get_masked_indices_and_masked_dimension_bounds( dimension_list, bounds_start,          &
+               bounds_end, bounds_start_internal, value_counts, bounds_origin, masked_indices )
 
        do_output = .NOT. ANY( value_counts == 0 )
 
        WRITE( temp_string, * ) bounds_start_internal
-       CALL internal_message( 'debug', routine_name //                    &
-                              ': file "' // TRIM( file_name ) //          &
-                              '", variable "' // TRIM( variable_name ) // &
+       CALL internal_message( 'debug', routine_name //                                             &
+                              ': file "' // TRIM( file_name ) //                                   &
+                              '", variable "' // TRIM( variable_name ) //                          &
                               '", bounds_start_internal =' // TRIM( temp_string ) )
        WRITE( temp_string, * ) value_counts
-       CALL internal_message( 'debug', routine_name //                    &
-                              ': file "' // TRIM( file_name ) //          &
-                              '", variable "' // TRIM( variable_name ) // &
+       CALL internal_message( 'debug', routine_name //                                             &
+                              ': file "' // TRIM( file_name ) //                                   &
+                              '", variable "' // TRIM( variable_name ) //                          &
                               '", value_counts =' // TRIM( temp_string ) )
 !
@@ -1754,12 +1778,11 @@
        ELSEIF ( PRESENT( values_char_2d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_char_2d_resorted(0:value_counts(1)-1, &
-                                               0:value_counts(2)-1) )
+             ALLOCATE( values_char_2d_resorted(0:value_counts(1)-1,0:value_counts(2)-1) )
              !$OMP PARALLEL PRIVATE (i,j)
              !$OMP DO
              DO  i = 0, value_counts(1) - 1
                 DO  j = 0, value_counts(2) - 1
-                   values_char_2d_resorted(i,j) = values_char_2d(masked_indices(2,j), &
-                                                                 masked_indices(1,i)  )
+                   values_char_2d_resorted(i,j) = values_char_2d(masked_indices(2,j),              &
+                                                                 masked_indices(1,i))
                 ENDDO
              ENDDO
@@ -1772,6 +1795,6 @@
        ELSEIF ( PRESENT( values_char_3d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_char_3d_resorted(0:value_counts(1)-1, &
-                                               0:value_counts(2)-1, &
+             ALLOCATE( values_char_3d_resorted(0:value_counts(1)-1,                                &
+                                               0:value_counts(2)-1,                                &
                                                0:value_counts(3)-1) )
              !$OMP PARALLEL PRIVATE (i,j,k)
@@ -1780,7 +1803,7 @@
                 DO  j = 0, value_counts(2) - 1
                    DO  k = 0, value_counts(3) - 1
-                      values_char_3d_resorted(i,j,k) = values_char_3d(masked_indices(3,k), &
-                                                                      masked_indices(2,j), &
-                                                                      masked_indices(1,i)  )
+                      values_char_3d_resorted(i,j,k) = values_char_3d(masked_indices(3,k),         &
+                                                                      masked_indices(2,j),         &
+                                                                      masked_indices(1,i))
                    ENDDO
                 ENDDO
@@ -1812,12 +1835,11 @@
        ELSEIF ( PRESENT( values_int8_2d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_int8_2d_resorted(0:value_counts(1)-1, &
-                                               0:value_counts(2)-1) )
+             ALLOCATE( values_int8_2d_resorted(0:value_counts(1)-1,0:value_counts(2)-1) )
              !$OMP PARALLEL PRIVATE (i,j)
              !$OMP DO
              DO  i = 0, value_counts(1) - 1
                 DO  j = 0, value_counts(2) - 1
-                   values_int8_2d_resorted(i,j) = values_int8_2d(masked_indices(2,j), &
-                                                                 masked_indices(1,i)  )
+                   values_int8_2d_resorted(i,j) = values_int8_2d(masked_indices(2,j),              &
+                                                                 masked_indices(1,i))
                 ENDDO
              ENDDO
@@ -1830,6 +1852,6 @@
        ELSEIF ( PRESENT( values_int8_3d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_int8_3d_resorted(0:value_counts(1)-1, &
-                                               0:value_counts(2)-1, &
+             ALLOCATE( values_int8_3d_resorted(0:value_counts(1)-1,                                &
+                                               0:value_counts(2)-1,                                &
                                                0:value_counts(3)-1) )
              !$OMP PARALLEL PRIVATE (i,j,k)
@@ -1838,6 +1860,6 @@
                 DO  j = 0, value_counts(2) - 1
                    DO  k = 0, value_counts(3) - 1
-                      values_int8_3d_resorted(i,j,k) = values_int8_3d(masked_indices(3,k), &
-                                                                      masked_indices(2,j), &
+                      values_int8_3d_resorted(i,j,k) = values_int8_3d(masked_indices(3,k),         &
+                                                                      masked_indices(2,j),         &
                                                                       masked_indices(1,i)  )
                    ENDDO
@@ -1870,11 +1892,10 @@
        ELSEIF ( PRESENT( values_int16_2d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_int16_2d_resorted(0:value_counts(1)-1, &
-                                                0:value_counts(2)-1) )
+             ALLOCATE( values_int16_2d_resorted(0:value_counts(1)-1,0:value_counts(2)-1) )
              !$OMP PARALLEL PRIVATE (i,j)
              !$OMP DO
              DO  i = 0, value_counts(1) - 1
                 DO  j = 0, value_counts(2) - 1
-                   values_int16_2d_resorted(i,j) = values_int16_2d(masked_indices(2,j), &
+                   values_int16_2d_resorted(i,j) = values_int16_2d(masked_indices(2,j),            &
                                                                    masked_indices(1,i))
                 ENDDO
@@ -1888,6 +1909,6 @@
        ELSEIF ( PRESENT( values_int16_3d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_int16_3d_resorted(0:value_counts(1)-1, &
-                                                0:value_counts(2)-1, &
+             ALLOCATE( values_int16_3d_resorted(0:value_counts(1)-1,                               &
+                                                0:value_counts(2)-1,                               &
                                                 0:value_counts(3)-1) )
              !$OMP PARALLEL PRIVATE (i,j,k)
@@ -1896,7 +1917,7 @@
                 DO  j = 0, value_counts(2) - 1
                    DO  k = 0, value_counts(3) - 1
-                      values_int16_3d_resorted(i,j,k) = values_int16_3d(masked_indices(3,k), &
-                                                                        masked_indices(2,j), &
-                                                                        masked_indices(1,i)  )
+                      values_int16_3d_resorted(i,j,k) = values_int16_3d(masked_indices(3,k),       &
+                                                                        masked_indices(2,j),       &
+                                                                        masked_indices(1,i))
                    ENDDO
                 ENDDO
@@ -1928,12 +1949,11 @@
        ELSEIF ( PRESENT( values_int32_2d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_int32_2d_resorted(0:value_counts(1)-1, &
-                                                0:value_counts(2)-1) )
+             ALLOCATE( values_int32_2d_resorted(0:value_counts(1)-1,0:value_counts(2)-1) )
              !$OMP PARALLEL PRIVATE (i,j)
              !$OMP DO
              DO  i = 0, value_counts(1) - 1
                 DO  j = 0, value_counts(2) - 1
-                   values_int32_2d_resorted(i,j) = values_int32_2d(masked_indices(2,j), &
-                                                                   masked_indices(1,i)  )
+                   values_int32_2d_resorted(i,j) = values_int32_2d(masked_indices(2,j),            &
+                                                                   masked_indices(1,i))
                 ENDDO
              ENDDO
@@ -1946,6 +1966,6 @@
        ELSEIF ( PRESENT( values_int32_3d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_int32_3d_resorted(0:value_counts(1)-1, &
-                                                0:value_counts(2)-1, &
+             ALLOCATE( values_int32_3d_resorted(0:value_counts(1)-1,                               &
+                                                0:value_counts(2)-1,                               &
                                                 0:value_counts(3)-1) )
              !$OMP PARALLEL PRIVATE (i,j,k)
@@ -1954,7 +1974,7 @@
                 DO  j = 0, value_counts(2) - 1
                    DO  k = 0, value_counts(3) - 1
-                      values_int32_3d_resorted(i,j,k) = values_int32_3d(masked_indices(3,k), &
-                                                                        masked_indices(2,j), &
-                                                                        masked_indices(1,i)  )
+                      values_int32_3d_resorted(i,j,k) = values_int32_3d(masked_indices(3,k),       &
+                                                                        masked_indices(2,j),       &
+                                                                        masked_indices(1,i))
                    ENDDO
                 ENDDO
@@ -1967,5 +1987,5 @@
           values_int32_3d_pointer => values_int32_3d_resorted
 !
-!--    working-precision integer output
+!--    Working-precision integer output
        ELSEIF ( PRESENT( values_intwp_0d ) )  THEN
           values_intwp_0d_pointer => values_intwp_0d
@@ -1986,12 +2006,11 @@
        ELSEIF ( PRESENT( values_intwp_2d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_intwp_2d_resorted(0:value_counts(1)-1, &
-                                                0:value_counts(2)-1) )
+             ALLOCATE( values_intwp_2d_resorted(0:value_counts(1)-1,0:value_counts(2)-1) )
              !$OMP PARALLEL PRIVATE (i,j)
              !$OMP DO
              DO  i = 0, value_counts(1) - 1
                 DO  j = 0, value_counts(2) - 1
-                   values_intwp_2d_resorted(i,j) = values_intwp_2d(masked_indices(2,j), &
-                                                                   masked_indices(1,i)  )
+                   values_intwp_2d_resorted(i,j) = values_intwp_2d(masked_indices(2,j),            &
+                                                                   masked_indices(1,i))
                 ENDDO
              ENDDO
@@ -2004,6 +2023,6 @@
        ELSEIF ( PRESENT( values_intwp_3d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_intwp_3d_resorted(0:value_counts(1)-1, &
-                                                0:value_counts(2)-1, &
+             ALLOCATE( values_intwp_3d_resorted(0:value_counts(1)-1,                               &
+                                                0:value_counts(2)-1,                               &
                                                 0:value_counts(3)-1) )
              !$OMP PARALLEL PRIVATE (i,j,k)
@@ -2012,7 +2031,7 @@
                 DO  j = 0, value_counts(2) - 1
                    DO  k = 0, value_counts(3) - 1
-                      values_intwp_3d_resorted(i,j,k) = values_intwp_3d(masked_indices(3,k), &
-                                                                        masked_indices(2,j), &
-                                                                        masked_indices(1,i)  )
+                      values_intwp_3d_resorted(i,j,k) = values_intwp_3d(masked_indices(3,k),       &
+                                                                        masked_indices(2,j),       &
+                                                                        masked_indices(1,i))
                    ENDDO
                 ENDDO
@@ -2044,12 +2063,11 @@
        ELSEIF ( PRESENT( values_real32_2d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_real32_2d_resorted(0:value_counts(1)-1, &
-                                                 0:value_counts(2)-1) )
+             ALLOCATE( values_real32_2d_resorted(0:value_counts(1)-1,0:value_counts(2)-1) )
              !$OMP PARALLEL PRIVATE (i,j)
              !$OMP DO
              DO  i = 0, value_counts(1) - 1
                 DO  j = 0, value_counts(2) - 1
-                   values_real32_2d_resorted(i,j) = values_real32_2d(masked_indices(2,j), &
-                                                                     masked_indices(1,i)  )
+                   values_real32_2d_resorted(i,j) = values_real32_2d(masked_indices(2,j),          &
+                                                                     masked_indices(1,i))
                 ENDDO
              ENDDO
@@ -2062,6 +2080,6 @@
        ELSEIF ( PRESENT( values_real32_3d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_real32_3d_resorted(0:value_counts(1)-1, &
-                                                 0:value_counts(2)-1, &
+             ALLOCATE( values_real32_3d_resorted(0:value_counts(1)-1,                              &
+                                                 0:value_counts(2)-1,                              &
                                                  0:value_counts(3)-1) )
              !$OMP PARALLEL PRIVATE (i,j,k)
@@ -2070,7 +2088,7 @@
                 DO  j = 0, value_counts(2) - 1
                    DO  k = 0, value_counts(3) - 1
-                      values_real32_3d_resorted(i,j,k) = values_real32_3d(masked_indices(3,k), &
-                                                                          masked_indices(2,j), &
-                                                                          masked_indices(1,i)  )
+                      values_real32_3d_resorted(i,j,k) = values_real32_3d(masked_indices(3,k),     &
+                                                                          masked_indices(2,j),     &
+                                                                          masked_indices(1,i))
                    ENDDO
                 ENDDO
@@ -2102,12 +2120,11 @@
        ELSEIF ( PRESENT( values_real64_2d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_real64_2d_resorted(0:value_counts(1)-1, &
-                                                 0:value_counts(2)-1) )
+             ALLOCATE( values_real64_2d_resorted(0:value_counts(1)-1,0:value_counts(2)-1) )
              !$OMP PARALLEL PRIVATE (i,j)
              !$OMP DO
              DO  i = 0, value_counts(1) - 1
                 DO  j = 0, value_counts(2) - 1
-                   values_real64_2d_resorted(i,j) = values_real64_2d(masked_indices(2,j), &
-                                                                     masked_indices(1,i)  )
+                   values_real64_2d_resorted(i,j) = values_real64_2d(masked_indices(2,j),          &
+                                                                     masked_indices(1,i))
                 ENDDO
              ENDDO
@@ -2120,6 +2137,6 @@
        ELSEIF ( PRESENT( values_real64_3d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_real64_3d_resorted(0:value_counts(1)-1, &
-                                                 0:value_counts(2)-1, &
+             ALLOCATE( values_real64_3d_resorted(0:value_counts(1)-1,                              &
+                                                 0:value_counts(2)-1,                              &
                                                  0:value_counts(3)-1) )
              !$OMP PARALLEL PRIVATE (i,j,k)
@@ -2128,7 +2145,7 @@
                 DO  j = 0, value_counts(2) - 1
                    DO  k = 0, value_counts(3) - 1
-                      values_real64_3d_resorted(i,j,k) = values_real64_3d(masked_indices(3,k), &
-                                                                          masked_indices(2,j), &
-                                                                          masked_indices(1,i)  )
+                      values_real64_3d_resorted(i,j,k) = values_real64_3d(masked_indices(3,k),     &
+                                                                          masked_indices(2,j),     &
+                                                                          masked_indices(1,i))
                    ENDDO
                 ENDDO
@@ -2141,5 +2158,5 @@
           values_real64_3d_pointer => values_real64_3d_resorted
 !
-!--    working-precision real output
+!--    Working-precision real output
        ELSEIF ( PRESENT( values_realwp_0d ) )  THEN
           values_realwp_0d_pointer => values_realwp_0d
@@ -2160,12 +2177,11 @@
        ELSEIF ( PRESENT( values_realwp_2d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_realwp_2d_resorted(0:value_counts(1)-1, &
-                                                 0:value_counts(2)-1) )
+             ALLOCATE( values_realwp_2d_resorted(0:value_counts(1)-1,0:value_counts(2)-1) )
              !$OMP PARALLEL PRIVATE (i,j)
              !$OMP DO
              DO  i = 0, value_counts(1) - 1
                 DO  j = 0, value_counts(2) - 1
-                   values_realwp_2d_resorted(i,j) = values_realwp_2d(masked_indices(2,j), &
-                                                                     masked_indices(1,i)  )
+                   values_realwp_2d_resorted(i,j) = values_realwp_2d(masked_indices(2,j),          &
+                                                                     masked_indices(1,i))
                 ENDDO
              ENDDO
@@ -2178,6 +2194,6 @@
        ELSEIF ( PRESENT( values_realwp_3d ) )  THEN
           IF ( do_output ) THEN
-             ALLOCATE( values_realwp_3d_resorted(0:value_counts(1)-1, &
-                                                 0:value_counts(2)-1, &
+             ALLOCATE( values_realwp_3d_resorted(0:value_counts(1)-1,                              &
+                                                 0:value_counts(2)-1,                              &
                                                  0:value_counts(3)-1) )
              !$OMP PARALLEL PRIVATE (i,j,k)
@@ -2186,7 +2202,7 @@
                 DO  j = 0, value_counts(2) - 1
                    DO  k = 0, value_counts(3) - 1
-                      values_realwp_3d_resorted(i,j,k) = values_realwp_3d(masked_indices(3,k), &
-                                                                          masked_indices(2,j), &
-                                                                          masked_indices(1,i)  )
+                      values_realwp_3d_resorted(i,j,k) = values_realwp_3d(masked_indices(3,k),     &
+                                                                          masked_indices(2,j),     &
+                                                                          masked_indices(1,i))
                    ENDDO
                 ENDDO
@@ -2201,7 +2217,7 @@
        ELSE
           return_value = 1
-          CALL internal_message( 'error', routine_name //                  &
-                                 ': no output values given ' //            &
-                                 '(variable "' // TRIM( variable_name ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': no output values given ' //                                    &
+                                 '(variable "' // TRIM( variable_name ) //                         &
                                  '", file "' // TRIM( file_name ) // '")!'  )
        ENDIF
@@ -2218,153 +2234,153 @@
           CASE ( 'binary' )
 !
-!--          character output
+!--          Character output
              IF ( PRESENT( values_char_0d ) )  THEN
-                 CALL binary_write_variable( file_id, variable_id,                      &
-                         bounds_start_internal, value_counts, bounds_origin, is_global, &
+                 CALL binary_write_variable( file_id, variable_id,                                 &
+                         bounds_start_internal, value_counts, bounds_origin, is_global,            &
                         values_char_0d=values_char_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_char_1d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_char_1d=values_char_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_char_2d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_char_2d=values_char_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_char_3d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_char_3d=values_char_3d_pointer, return_value=output_return_value )
 !
 !--          8bit integer output
              ELSEIF ( PRESENT( values_int8_0d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int8_0d=values_int8_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int8_1d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int8_1d=values_int8_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int8_2d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int8_2d=values_int8_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int8_3d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int8_3d=values_int8_3d_pointer, return_value=output_return_value )
 !
 !--          16bit integer output
              ELSEIF ( PRESENT( values_int16_0d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int16_0d=values_int16_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int16_1d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int16_1d=values_int16_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int16_2d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int16_2d=values_int16_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int16_3d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int16_3d=values_int16_3d_pointer, return_value=output_return_value )
 !
 !--          32bit integer output
              ELSEIF ( PRESENT( values_int32_0d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int32_0d=values_int32_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int32_1d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int32_1d=values_int32_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int32_2d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int32_2d=values_int32_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int32_3d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int32_3d=values_int32_3d_pointer, return_value=output_return_value )
 !
-!--          working-precision integer output
+!--          Working-precision integer output
              ELSEIF ( PRESENT( values_intwp_0d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_intwp_0d=values_intwp_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_intwp_1d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_intwp_1d=values_intwp_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_intwp_2d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_intwp_2d=values_intwp_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_intwp_3d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_intwp_3d=values_intwp_3d_pointer, return_value=output_return_value )
 !
 !--          32bit real output
              ELSEIF ( PRESENT( values_real32_0d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real32_0d=values_real32_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real32_1d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real32_1d=values_real32_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real32_2d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real32_2d=values_real32_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real32_3d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real32_3d=values_real32_3d_pointer, return_value=output_return_value )
 !
 !--          64bit real output
              ELSEIF ( PRESENT( values_real64_0d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real64_0d=values_real64_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real64_1d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real64_1d=values_real64_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real64_2d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real64_2d=values_real64_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real64_3d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real64_3d=values_real64_3d_pointer, return_value=output_return_value )
 !
 !--          working-precision real output
              ELSEIF ( PRESENT( values_realwp_0d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_realwp_0d=values_realwp_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_realwp_1d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_realwp_1d=values_realwp_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_realwp_2d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_realwp_2d=values_realwp_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_realwp_3d ) )  THEN
-                CALL binary_write_variable( file_id, variable_id,                      &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL binary_write_variable( file_id, variable_id,                                  &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_realwp_3d=values_realwp_3d_pointer, return_value=output_return_value )
              ELSE
                 return_value = 1
-                CALL internal_message( 'error', routine_name //                          &
-                                       ': output_type not supported by file format "' // &
-                                       TRIM( file_format ) // '" ' //                    &
-                                       '(variable "' // TRIM( variable_name ) //         &
+                CALL internal_message( 'error', routine_name //                                    &
+                                       ': output_type not supported by file format "' //           &
+                                       TRIM( file_format ) // '" ' //                              &
+                                       '(variable "' // TRIM( variable_name ) //                   &
                                        '", file "' // TRIM( file_name ) // '")!' )
              ENDIF
@@ -2372,153 +2388,153 @@
           CASE ( 'netcdf4-parallel', 'netcdf4-serial' )
 !
-!--          character output
+!--          Character output
              IF ( PRESENT( values_char_0d ) )  THEN
-                 CALL netcdf4_write_variable( file_id, variable_id,                     &
-                         bounds_start_internal, value_counts, bounds_origin, is_global, &
+                 CALL netcdf4_write_variable( file_id, variable_id,                                &
+                         bounds_start_internal, value_counts, bounds_origin, is_global,            &
                         values_char_0d=values_char_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_char_1d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_char_1d=values_char_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_char_2d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_char_2d=values_char_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_char_3d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_char_3d=values_char_3d_pointer, return_value=output_return_value )
 !
 !--          8bit integer output
              ELSEIF ( PRESENT( values_int8_0d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int8_0d=values_int8_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int8_1d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int8_1d=values_int8_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int8_2d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int8_2d=values_int8_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int8_3d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int8_3d=values_int8_3d_pointer, return_value=output_return_value )
 !
 !--          16bit integer output
              ELSEIF ( PRESENT( values_int16_0d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int16_0d=values_int16_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int16_1d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int16_1d=values_int16_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int16_2d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int16_2d=values_int16_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int16_3d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int16_3d=values_int16_3d_pointer, return_value=output_return_value )
 !
 !--          32bit integer output
              ELSEIF ( PRESENT( values_int32_0d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int32_0d=values_int32_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int32_1d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int32_1d=values_int32_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int32_2d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int32_2d=values_int32_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_int32_3d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_int32_3d=values_int32_3d_pointer, return_value=output_return_value )
 !
-!--          working-precision integer output
+!--          Working-precision integer output
              ELSEIF ( PRESENT( values_intwp_0d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_intwp_0d=values_intwp_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_intwp_1d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_intwp_1d=values_intwp_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_intwp_2d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_intwp_2d=values_intwp_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_intwp_3d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_intwp_3d=values_intwp_3d_pointer, return_value=output_return_value )
 !
 !--          32bit real output
              ELSEIF ( PRESENT( values_real32_0d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real32_0d=values_real32_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real32_1d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real32_1d=values_real32_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real32_2d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real32_2d=values_real32_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real32_3d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real32_3d=values_real32_3d_pointer, return_value=output_return_value )
 !
 !--          64bit real output
              ELSEIF ( PRESENT( values_real64_0d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real64_0d=values_real64_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real64_1d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real64_1d=values_real64_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real64_2d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real64_2d=values_real64_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_real64_3d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_real64_3d=values_real64_3d_pointer, return_value=output_return_value )
 !
 !--          working-precision real output
              ELSEIF ( PRESENT( values_realwp_0d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_realwp_0d=values_realwp_0d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_realwp_1d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_realwp_1d=values_realwp_1d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_realwp_2d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_realwp_2d=values_realwp_2d_pointer, return_value=output_return_value )
              ELSEIF ( PRESENT( values_realwp_3d ) )  THEN
-                CALL netcdf4_write_variable( file_id, variable_id,                     &
-                        bounds_start_internal, value_counts, bounds_origin, is_global, &
+                CALL netcdf4_write_variable( file_id, variable_id,                                 &
+                        bounds_start_internal, value_counts, bounds_origin, is_global,             &
                         values_realwp_3d=values_realwp_3d_pointer, return_value=output_return_value )
              ELSE
                 return_value = 1
-                CALL internal_message( 'error', routine_name //                          &
-                                       ': output_type not supported by file format "' // &
-                                       TRIM( file_format ) // '" ' //                    &
-                                       '(variable "' // TRIM( variable_name ) //         &
+                CALL internal_message( 'error', routine_name //                                    &
+                                       ': output_type not supported by file format "' //           &
+                                       TRIM( file_format ) // '" ' //                              &
+                                       '(variable "' // TRIM( variable_name ) //                   &
                                        '", file "' // TRIM( file_name ) // '")!' )
              ENDIF
@@ -2526,8 +2542,8 @@
           CASE DEFAULT
              return_value = 1
-             CALL internal_message( 'error', routine_name //                    &
-                                    ': file format "' // TRIM( file_format ) // &
-                                    '" not supported ' //                       &
-                                    '(variable "' // TRIM( variable_name ) //   &
+             CALL internal_message( 'error', routine_name //                                       &
+                                    ': file format "' // TRIM( file_format ) //                    &
+                                    '" not supported ' //                                          &
+                                    '(variable "' // TRIM( variable_name ) //                      &
                                     '", file "' // TRIM( file_name ) // '")!' )
 
@@ -2536,7 +2552,7 @@
        IF ( return_value == 0  .AND.  output_return_value /= 0 )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                  &
-                                 ': error while writing variable ' //      &
-                                 '(variable "' // TRIM( variable_name ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': error while writing variable ' //                              &
+                                 '(variable "' // TRIM( variable_name ) //                         &
                                  '", file "' // TRIM( file_name ) // '")!' )
        ENDIF
@@ -2589,12 +2605,12 @@
           IF ( output_return_value /= 0 )  THEN
              return_value = output_return_value
-             CALL internal_message( 'error', routine_name //             &
-                                    ': error while finalizing file "' // &
+             CALL internal_message( 'error', routine_name //                                       &
+                                    ': error while finalizing file "' //                           &
                                     TRIM( files(f)%name ) // '"' )
           ELSEIF ( return_value_internal /= 0 )  THEN
              return_value = return_value_internal
-             CALL internal_message( 'error', routine_name //                     &
-                                    ': unsupported file format "' //             &
-                                    TRIM( files(f)%format ) // '" for file "' // &
+             CALL internal_message( 'error', routine_name //                                       &
+                                    ': unsupported file format "' //                               &
+                                    TRIM( files(f)%format ) // '" for file "' //                   &
                                     TRIM( files(f)%name ) // '"' )
           ENDIF
@@ -2636,8 +2652,8 @@
              RESULT( return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'save_attribute_in_database'  !< name of routine
+
     CHARACTER(LEN=*), INTENT(IN) ::  file_name      !< name of file
     CHARACTER(LEN=*), INTENT(IN) ::  variable_name  !< name of variable
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'save_attribute_in_database'  !< name of routine
 
     INTEGER ::  a             !< loop index
@@ -2658,7 +2674,7 @@
     found = .FALSE.
 
-    CALL internal_message( 'debug', routine_name //                            &
-                           ': define attribute "' // TRIM( attribute%name ) // &
-                           '" of variable "' // TRIM( variable_name ) //       &
+    CALL internal_message( 'debug', routine_name //                                                &
+                           ': define attribute "' // TRIM( attribute%name ) //                     &
+                           '" of variable "' // TRIM( variable_name ) //                           &
                            '" in file "' // TRIM( file_name ) // '"' )
 
@@ -2669,5 +2685,5 @@
           IF ( files(f)%is_init )  THEN
              return_value = 1
-             CALL internal_message( 'error', routine_name // ': file "' // TRIM( file_name ) // &
+             CALL internal_message( 'error', routine_name // ': file "' // TRIM( file_name ) //    &
                      '" is already initialized. No further attribute definition allowed!' )
              EXIT
@@ -2690,7 +2706,7 @@
 !
 !--                      Append existing string attribute
-                         files(f)%attributes(a)%value_char =             &
-                            TRIM( files(f)%attributes(a)%value_char ) // &
-                            TRIM( attribute%value_char )
+                         files(f)%attributes(a)%value_char =                                       &
+                                                      TRIM( files(f)%attributes(a)%value_char ) // &
+                                                      TRIM( attribute%value_char )
                       ELSE
                          files(f)%attributes(a) = attribute
@@ -2745,6 +2761,6 @@
 !
 !--                               Append existing character attribute
-                                  files(f)%dimensions(d)%attributes(a)%value_char =             &
-                                     TRIM( files(f)%dimensions(d)%attributes(a)%value_char ) // &
+                                  files(f)%dimensions(d)%attributes(a)%value_char =                &
+                                     TRIM( files(f)%dimensions(d)%attributes(a)%value_char ) //    &
                                      TRIM( attribute%value_char )
                                ELSE
@@ -2801,11 +2817,10 @@
 !--                      Check if attribute already exists
                          DO  a = 1, natts
-                            IF ( files(f)%variables(d)%attributes(a)%name == attribute%name )  &
-                            THEN
+                            IF ( files(f)%variables(d)%attributes(a)%name == attribute%name )  THEN
                                IF ( append )  THEN
 !
 !--                               Append existing character attribute
-                                  files(f)%variables(d)%attributes(a)%value_char =             &
-                                     TRIM( files(f)%variables(d)%attributes(a)%value_char ) // &
+                                  files(f)%variables(d)%attributes(a)%value_char =                 &
+                                     TRIM( files(f)%variables(d)%attributes(a)%value_char ) //     &
                                      TRIM( attribute%value_char )
                                ELSE
@@ -2848,9 +2863,9 @@
              IF ( .NOT. found )  THEN
                 return_value = 1
-                CALL internal_message( 'error',                                        &
-                        routine_name //                                                &
-                        ': requested dimension/variable "' // TRIM( variable_name ) // &
-                        '" for attribute "' // TRIM( attribute%name ) //               &
-                        '" does not exist in file "' // TRIM( file_name ) // '"' )
+                CALL internal_message( 'error',                                                    &
+                                    routine_name //                                                &
+                                    ': requested dimension/variable "' // TRIM( variable_name ) // &
+                                    '" for attribute "' // TRIM( attribute%name ) //               &
+                                    '" does not exist in file "' // TRIM( file_name ) // '"' )
              ENDIF
 
@@ -2865,8 +2880,8 @@
     IF ( .NOT. found  .AND.  return_value == 0 )  THEN
        return_value = 1
-       CALL internal_message( 'error',                                         &
-                              routine_name //                                  &
-                              ': requested file "' // TRIM( file_name ) //     &
-                              '" for attribute "' // TRIM( attribute%name ) // &
+       CALL internal_message( 'error',                                                             &
+                              routine_name //                                                      &
+                              ': requested file "' // TRIM( file_name ) //                         &
+                              '" for attribute "' // TRIM( attribute%name ) //                     &
                               '" does not exist' )
     ENDIF
@@ -2943,6 +2958,6 @@
        DO  d = 1, ndims
           DO  i = 1, nvars
-             dimension_is_used(d) = &
-                ANY( files(f)%dimensions(d)%name == files(f)%variables(i)%dimension_names )
+             dimension_is_used(d) =                                                                &
+                         ANY( files(f)%dimensions(d)%name == files(f)%variables(i)%dimension_names )
              IF ( dimension_is_used(d) )  EXIT
           ENDDO
@@ -2979,8 +2994,8 @@
  SUBROUTINE open_output_file( file_format, file_name, file_id, return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'open_output_file'  !< name of routine
+
     CHARACTER(LEN=*), INTENT(IN) ::  file_format  !< file format chosen for file
     CHARACTER(LEN=*), INTENT(IN) ::  file_name    !< name of file to be checked
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'open_output_file'  !< name of routine
 
     INTEGER, INTENT(OUT) ::  file_id              !< file ID
@@ -3010,10 +3025,10 @@
     IF ( output_return_value /= 0 )  THEN
        return_value = output_return_value
-       CALL internal_message( 'error', routine_name // &
+       CALL internal_message( 'error', routine_name //                                             &
                               ': error while opening file "' // TRIM( file_name ) // '"' )
     ELSEIF ( return_value /= 0 )  THEN
-       CALL internal_message( 'error', routine_name //                     &
-                              ': file "' // TRIM( file_name ) //           &
-                              '": file format "' // TRIM( file_format ) // &
+       CALL internal_message( 'error', routine_name //                                             &
+                              ': file "' // TRIM( file_name ) //                                   &
+                              '": file format "' // TRIM( file_format ) //                         &
                               '" not supported' )
     ENDIF
@@ -3042,6 +3057,6 @@
     IF ( ALLOCATED( file%attributes ) )  THEN
        DO  a = 1, SIZE( file%attributes )
-          return_value = write_attribute( file%format, file%id, file%name,     &
-                                          variable_id=no_id, variable_name='', &
+          return_value = write_attribute( file%format, file%id, file%name,                         &
+                                          variable_id=no_id, variable_name='',                     &
                                           attribute=file%attributes(a) )
           IF ( return_value /= 0 )  EXIT
@@ -3057,16 +3072,16 @@
 !
 !--          Initialize non-masked dimension
-             CALL init_file_dimension( file%format, file%id, file%name,       &
-                     file%dimensions(d)%id, file%dimensions(d)%name,          &
-                     file%dimensions(d)%data_type, file%dimensions(d)%length, &
-                     file%dimensions(d)%variable_id, return_value )
+             CALL init_file_dimension( file%format, file%id, file%name,                            &
+                                       file%dimensions(d)%id, file%dimensions(d)%name,             &
+                                       file%dimensions(d)%data_type, file%dimensions(d)%length,    &
+                                       file%dimensions(d)%variable_id, return_value )
 
           ELSE
 !
 !--          Initialize masked dimension
-             CALL init_file_dimension( file%format, file%id, file%name,            &
-                     file%dimensions(d)%id, file%dimensions(d)%name,               &
-                     file%dimensions(d)%data_type, file%dimensions(d)%length_mask, &
-                     file%dimensions(d)%variable_id, return_value )
+             CALL init_file_dimension( file%format, file%id, file%name,                            &
+                                       file%dimensions(d)%id, file%dimensions(d)%name,             &
+                                       file%dimensions(d)%data_type, file%dimensions(d)%length_mask,&
+                                       file%dimensions(d)%variable_id, return_value )
 
           ENDIF
@@ -3076,8 +3091,8 @@
 !--          Write dimension attributes
              DO  a = 1, SIZE( file%dimensions(d)%attributes )
-                return_value = write_attribute( file%format, file%id, file%name, &
-                                  variable_id=file%dimensions(d)%variable_id,    &
-                                  variable_name=file%dimensions(d)%name,         &
-                                  attribute=file%dimensions(d)%attributes(a) )
+                return_value = write_attribute( file%format, file%id, file%name,                   &
+                                                variable_id=file%dimensions(d)%variable_id,        &
+                                                variable_name=file%dimensions(d)%name,             &
+                                                attribute=file%dimensions(d)%attributes(a) )
                 IF ( return_value /= 0 )  EXIT
              ENDDO
@@ -3089,5 +3104,5 @@
 !
 !--    Save dimension IDs for variables wihtin database
-       IF ( return_value == 0 )  &
+       IF ( return_value == 0 )                                                                    &
           CALL collect_dimesion_ids_for_variables( file%name, file%variables, file%dimensions, &
                                                    return_value )
@@ -3097,7 +3112,7 @@
           DO  d = 1, SIZE( file%variables )
 
-             CALL init_file_variable( file%format, file%id, file%name,                          &
-                     file%variables(d)%id, file%variables(d)%name, file%variables(d)%data_type, &
-                     file%variables(d)%dimension_ids,                                           &
+             CALL init_file_variable( file%format, file%id, file%name,                             &
+                     file%variables(d)%id, file%variables(d)%name, file%variables(d)%data_type,    &
+                     file%variables(d)%dimension_ids,                                              &
                      file%variables(d)%is_global, return_value )
 
@@ -3106,8 +3121,8 @@
 !--             Write variable attributes
                 DO  a = 1, SIZE( file%variables(d)%attributes )
-                   return_value = write_attribute( file%format, file%id, file%name, &
-                                     variable_id=file%variables(d)%id,              &
-                                     variable_name=file%variables(d)%name,          &
-                                     attribute=file%variables(d)%attributes(a) )
+                   return_value = write_attribute( file%format, file%id, file%name,                &
+                                                   variable_id=file%variables(d)%id,               &
+                                                   variable_name=file%variables(d)%name,           &
+                                                   attribute=file%variables(d)%attributes(a) )
                    IF ( return_value /= 0 )  EXIT
                 ENDDO
@@ -3128,7 +3143,9 @@
 !> Initialize dimension in file.
 !--------------------------------------------------------------------------------------------------!
- SUBROUTINE init_file_dimension( file_format, file_id, file_name,              &
-               dimension_id, dimension_name, dimension_type, dimension_length, &
-               variable_id, return_value )
+ SUBROUTINE init_file_dimension( file_format, file_id, file_name,                                  &
+                                 dimension_id, dimension_name, dimension_type, dimension_length,   &
+                                 variable_id, return_value )
+
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'init_file_dimension'  !< file format chosen for file
 
     CHARACTER(LEN=*), INTENT(IN) ::  dimension_name  !< name of dimension
@@ -3136,6 +3153,4 @@
     CHARACTER(LEN=*), INTENT(IN) ::  file_format     !< file format chosen for file
     CHARACTER(LEN=*), INTENT(IN) ::  file_name       !< name of file
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'init_file_dimension'  !< file format chosen for file
 
     INTEGER, INTENT(OUT) ::  dimension_id         !< dimension ID
@@ -3150,5 +3165,5 @@
     output_return_value = 0
 
-    temp_string = '(file "' // TRIM( file_name ) // &
+    temp_string = '(file "' // TRIM( file_name ) //                                                &
                   '", dimension "' // TRIM( dimension_name ) // '")'
 
@@ -3156,22 +3171,22 @@
 
        CASE ( 'binary' )
-          CALL binary_init_dimension( 'binary', file_id, dimension_id, variable_id, &
-                  dimension_name, dimension_type, dimension_length,                 &
-                  return_value=output_return_value )
+          CALL binary_init_dimension( 'binary', file_id, dimension_id, variable_id,                &
+                                       dimension_name, dimension_type, dimension_length,           &
+                                       return_value=output_return_value )
 
        CASE ( 'netcdf4-serial' )
-          CALL netcdf4_init_dimension( 'serial', file_id, dimension_id, variable_id, &
-                  dimension_name, dimension_type, dimension_length,                  &
-                  return_value=output_return_value )
+          CALL netcdf4_init_dimension( 'serial', file_id, dimension_id, variable_id,               &
+                                       dimension_name, dimension_type, dimension_length,           &
+                                       return_value=output_return_value )
 
        CASE ( 'netcdf4-parallel' )
-          CALL netcdf4_init_dimension( 'parallel', file_id, dimension_id, variable_id, &
-                  dimension_name, dimension_type, dimension_length,                    &
-                  return_value=output_return_value )
+          CALL netcdf4_init_dimension( 'parallel', file_id, dimension_id, variable_id,             &
+                                       dimension_name, dimension_type, dimension_length,           &
+                                       return_value=output_return_value )
 
        CASE DEFAULT
           return_value = 1
-          CALL internal_message( 'error', routine_name //                    &
-                                 ': file format "' // TRIM( file_format ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': file format "' // TRIM( file_format ) //                       &
                                  '" not supported ' // TRIM( temp_string ) )
 
@@ -3180,5 +3195,5 @@
     IF ( output_return_value /= 0 )  THEN
        return_value = output_return_value
-       CALL internal_message( 'error', routine_name // &
+       CALL internal_message( 'error', routine_name //                                             &
                               ': error while defining dimension ' // TRIM( temp_string ) )
     ENDIF
@@ -3191,7 +3206,9 @@
 !> Initialize variable.
 !--------------------------------------------------------------------------------------------------!
- SUBROUTINE init_file_variable( file_format, file_id, file_name,        &
-                                variable_id, variable_name, variable_type, dimension_ids, &
+ SUBROUTINE init_file_variable( file_format, file_id, file_name,                                   &
+                                variable_id, variable_name, variable_type, dimension_ids,          &
                                 is_global, return_value )
+
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'init_file_variable'  !< file format chosen for file
 
     CHARACTER(LEN=*), INTENT(IN) ::  file_format    !< file format chosen for file
@@ -3200,6 +3217,4 @@
     CHARACTER(LEN=*), INTENT(IN) ::  variable_type  !< data type of variable
 
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'init_file_variable'  !< file format chosen for file
-
     INTEGER, INTENT(IN)  ::  file_id              !< file ID
     INTEGER              ::  output_return_value  !< return value of a called output routine
@@ -3221,19 +3236,19 @@
 
        CASE ( 'binary' )
-          CALL binary_init_variable( 'binary', file_id, variable_id, variable_name, &
+          CALL binary_init_variable( 'binary', file_id, variable_id, variable_name,                &
                   variable_type, dimension_ids, is_global, return_value=output_return_value )
 
        CASE ( 'netcdf4-serial' )
-          CALL netcdf4_init_variable( 'serial', file_id, variable_id, variable_name, &
+          CALL netcdf4_init_variable( 'serial', file_id, variable_id, variable_name,               &
                   variable_type, dimension_ids, is_global, return_value=output_return_value )
 
        CASE ( 'netcdf4-parallel' )
-          CALL netcdf4_init_variable( 'parallel', file_id, variable_id, variable_name, &
+          CALL netcdf4_init_variable( 'parallel', file_id, variable_id, variable_name,             &
                   variable_type, dimension_ids, is_global, return_value=output_return_value )
 
        CASE DEFAULT
           return_value = 1
-          CALL internal_message( 'error', routine_name //                    &
-                                 ': file format "' // TRIM( file_format ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': file format "' // TRIM( file_format ) //                       &
                                  '" not supported ' // TRIM( temp_string ) )
 
@@ -3253,6 +3268,8 @@
 !> Write attribute to file.
 !--------------------------------------------------------------------------------------------------!
- FUNCTION write_attribute( file_format, file_id, file_name,        &
-                           variable_id, variable_name, attribute ) RESULT( return_value )
+ FUNCTION write_attribute( file_format, file_id, file_name, variable_id, variable_name, attribute )&
+    RESULT( return_value )
+
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'write_attribute'  !< file format chosen for file
 
     CHARACTER(LEN=*), INTENT(IN) ::  file_format    !< file format chosen for file
@@ -3260,9 +3277,7 @@
     CHARACTER(LEN=*), INTENT(IN) ::  variable_name  !< variable name
 
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'write_attribute'  !< file format chosen for file
-
     INTEGER, INTENT(IN) ::  file_id              !< file ID
+    INTEGER             ::  output_return_value  !< return value of a called output routine
     INTEGER             ::  return_value         !< return value
-    INTEGER             ::  output_return_value  !< return value of a called output routine
     INTEGER, INTENT(IN) ::  variable_id          !< variable ID
 
@@ -3274,6 +3289,6 @@
 !
 !-- Prepare for possible error message
-    temp_string = '(file "' // TRIM( file_name ) //           &
-                  '", variable "' // TRIM( variable_name ) // &
+    temp_string = '(file "' // TRIM( file_name ) //                                                &
+                  '", variable "' // TRIM( variable_name ) //                                      &
                   '", attribute "' // TRIM( attribute%name ) // '")'
 !
@@ -3286,39 +3301,39 @@
 
              CASE( 'char' )
-                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,  &
-                        attribute_name=attribute%name, value_char=attribute%value_char, &
+                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,             &
+                        attribute_name=attribute%name, value_char=attribute%value_char,            &
                         return_value=output_return_value )
 
              CASE( 'int8' )
-                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,  &
-                        attribute_name=attribute%name, value_int8=attribute%value_int8, &
+                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,             &
+                        attribute_name=attribute%name, value_int8=attribute%value_int8,            &
                         return_value=output_return_value )
 
              CASE( 'int16' )
-                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,    &
-                        attribute_name=attribute%name, value_int16=attribute%value_int16, &
+                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,             &
+                        attribute_name=attribute%name, value_int16=attribute%value_int16,          &
                         return_value=output_return_value )
 
              CASE( 'int32' )
-                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,    &
-                        attribute_name=attribute%name, value_int32=attribute%value_int32, &
+                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,             &
+                        attribute_name=attribute%name, value_int32=attribute%value_int32,          &
                         return_value=output_return_value )
 
              CASE( 'real32' )
-                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,      &
-                        attribute_name=attribute%name, value_real32=attribute%value_real32, &
+                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,             &
+                        attribute_name=attribute%name, value_real32=attribute%value_real32,        &
                         return_value=output_return_value )
 
              CASE( 'real64' )
-                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,      &
-                        attribute_name=attribute%name, value_real64=attribute%value_real64, &
+                CALL binary_write_attribute( file_id=file_id, variable_id=variable_id,             &
+                        attribute_name=attribute%name, value_real64=attribute%value_real64,        &
                         return_value=output_return_value )
 
              CASE DEFAULT
                 return_value = 1
-                CALL internal_message( 'error', routine_name //                     &
-                                       ': file format "' // TRIM( file_format ) //  &
-                                       '" does not support attribute data type "'// &
-                                       TRIM( attribute%data_type ) //               &
+                CALL internal_message( 'error', routine_name //                                    &
+                                       ': file format "' // TRIM( file_format ) //                 &
+                                       '" does not support attribute data type "'//                &
+                                       TRIM( attribute%data_type ) //                              &
                                        '" ' // TRIM( temp_string ) )
 
@@ -3330,39 +3345,39 @@
 
              CASE( 'char' )
-                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id, &
-                        attribute_name=attribute%name, value_char=attribute%value_char, &
+                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id,            &
+                        attribute_name=attribute%name, value_char=attribute%value_char,            &
                         return_value=output_return_value )
 
              CASE( 'int8' )
-                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id, &
-                        attribute_name=attribute%name, value_int8=attribute%value_int8, &
+                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id,            &
+                        attribute_name=attribute%name, value_int8=attribute%value_int8,            &
                         return_value=output_return_value )
 
              CASE( 'int16' )
-                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id,   &
-                        attribute_name=attribute%name, value_int16=attribute%value_int16, &
+                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id,            &
+                        attribute_name=attribute%name, value_int16=attribute%value_int16,          &
                         return_value=output_return_value )
 
              CASE( 'int32' )
-                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id,   &
-                        attribute_name=attribute%name, value_int32=attribute%value_int32, &
+                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id,            &
+                        attribute_name=attribute%name, value_int32=attribute%value_int32,          &
                         return_value=output_return_value )
 
              CASE( 'real32' )
-                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id,     &
-                        attribute_name=attribute%name, value_real32=attribute%value_real32, &
+                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id,            &
+                        attribute_name=attribute%name, value_real32=attribute%value_real32,        &
                         return_value=output_return_value )
 
              CASE( 'real64' )
-                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id,     &
-                        attribute_name=attribute%name, value_real64=attribute%value_real64, &
+                CALL netcdf4_write_attribute( file_id=file_id, variable_id=variable_id,            &
+                        attribute_name=attribute%name, value_real64=attribute%value_real64,        &
                         return_value=output_return_value )
 
              CASE DEFAULT
                 return_value = 1
-                CALL internal_message( 'error', routine_name //                     &
-                                       ': file format "' // TRIM( file_format ) //  &
-                                       '" does not support attribute data type "'// &
-                                       TRIM( attribute%data_type ) //               &
+                CALL internal_message( 'error', routine_name //                                    &
+                                       ': file format "' // TRIM( file_format ) //                 &
+                                       '" does not support attribute data type "'//                &
+                                       TRIM( attribute%data_type ) //                              &
                                        '" ' // TRIM( temp_string ) )
 
@@ -3371,6 +3386,6 @@
        CASE DEFAULT
           return_value = 1
-          CALL internal_message( 'error', routine_name //                                &
-                                 ': unsupported file format "' // TRIM( file_format ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': unsupported file format "' // TRIM( file_format ) //           &
                                  '" ' // TRIM( temp_string ) )
 
@@ -3379,5 +3394,5 @@
     IF ( output_return_value /= 0 )  THEN
        return_value = output_return_value
-       CALL internal_message( 'error', routine_name // &
+       CALL internal_message( 'error', routine_name //                                             &
                               ': error while writing attribute ' // TRIM( temp_string ) )
     ENDIF
@@ -3392,7 +3407,7 @@
  SUBROUTINE collect_dimesion_ids_for_variables( file_name, variables, dimensions, return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'collect_dimesion_ids_for_variables'  !< file format chosen for file
+
     CHARACTER(LEN=*), INTENT(IN) ::  file_name !< name of file
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'collect_dimesion_ids_for_variables'  !< file format chosen for file
 
     INTEGER              ::  d             !< loop index
@@ -3403,5 +3418,5 @@
     INTEGER, INTENT(OUT) ::  return_value  !< return value
 
-    LOGICAL ::  found = .False. !< true if dimension required by variable was found in dimension list
+    LOGICAL ::  found = .FALSE. !< true if dimension required by variable was found in dimension list
 
     TYPE(dimension_type), DIMENSION(:), INTENT(IN) ::  dimensions  !< list of dimensions in file
@@ -3426,7 +3441,7 @@
           IF ( .NOT. found )  THEN
              return_value = 1
-             CALL internal_message( 'error', routine_name //                                &
-                     ': required dimension "' // TRIM( variables(i)%dimension_names(j) ) // &
-                     '" is undefined (variable "' // TRIM( variables(i)%name ) //           &
+             CALL internal_message( 'error', routine_name //                                       &
+                     ': required dimension "' // TRIM( variables(i)%dimension_names(j) ) //        &
+                     '" is undefined (variable "' // TRIM( variables(i)%name ) //                  &
                      '", file "' // TRIM( file_name ) // '")!' )
              EXIT
@@ -3447,8 +3462,8 @@
  SUBROUTINE stop_file_header_definition( file_format, file_id, file_name, return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'stop_file_header_definition'  !< name of routine
+
     CHARACTER(LEN=*), INTENT(IN) ::  file_format  !< file format
     CHARACTER(LEN=*), INTENT(IN) ::  file_name    !< file name
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'stop_file_header_definition'  !< name of routine
 
     INTEGER, INTENT(IN)  ::  file_id              !< file id
@@ -3472,6 +3487,6 @@
        CASE DEFAULT
           return_value = 1
-          CALL internal_message( 'error', routine_name //                    &
-                                 ': file format "' // TRIM( file_format ) // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': file format "' // TRIM( file_format ) //                       &
                                  '" not supported ' // TRIM( temp_string ) )
 
@@ -3480,6 +3495,6 @@
     IF ( output_return_value /= 0 )  THEN
        return_value = output_return_value
-       CALL internal_message( 'error', routine_name //                          &
-                              ': error while leaving file-definition state ' // &
+       CALL internal_message( 'error', routine_name //                                             &
+                              ': error while leaving file-definition state ' //                    &
                               TRIM( temp_string ) )
     ENDIF
@@ -3494,12 +3509,12 @@
 !> Find a requested variable 'variable_name' and its used dimensions in requested file 'file_name'.
 !--------------------------------------------------------------------------------------------------!
- SUBROUTINE find_var_in_file( file_name, variable_name, file_format, file_id, variable_id, &
+ SUBROUTINE find_var_in_file( file_name, variable_name, file_format, file_id, variable_id,         &
                               is_global, dimensions, return_value )
+
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'find_var_in_file'  !< name of routine
 
     CHARACTER(LEN=charlen), INTENT(OUT) ::  file_format    !< file format chosen for file
     CHARACTER(LEN=*),       INTENT(IN)  ::  file_name      !< name of file
     CHARACTER(LEN=*),       INTENT(IN)  ::  variable_name  !< name of variable
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'find_var_in_file'  !< name of routine
 
     INTEGER              ::  d             !< loop index
@@ -3526,8 +3541,8 @@
           IF ( .NOT. files(f)%is_init )  THEN
              return_value = 1
-             CALL internal_message( 'error', routine_name //                     &
-                                    ': file not initialized. ' //                &
-                                    'Writing variable to file is impossible ' // &
-                                    '(variable "' // TRIM( variable_name ) //    &
+             CALL internal_message( 'error', routine_name //                                       &
+                                    ': file not initialized. ' //                                  &
+                                    'Writing variable to file is impossible ' //                   &
+                                    '(variable "' // TRIM( variable_name ) //                      &
                                     '", file "' // TRIM( file_name ) // '")!' )
              EXIT
@@ -3591,7 +3606,7 @@
           IF ( .NOT. found )  THEN
              return_value = 1
-             CALL internal_message( 'error', routine_name //                  &
-                                    ': variable not found in file ' //        &
-                                    '(variable "' // TRIM( variable_name ) // &
+             CALL internal_message( 'error', routine_name //                                       &
+                                    ': variable not found in file ' //                             &
+                                    '(variable "' // TRIM( variable_name ) //                      &
                                     '", file "' // TRIM( file_name ) // '")!' )
           ENDIF
@@ -3604,7 +3619,7 @@
     IF ( .NOT. found  .AND.  return_value == 0 )  THEN
        return_value = 1
-       CALL internal_message( 'error', routine_name //                  &
-                              ': file not found ' //                    &
-                              '(variable "' // TRIM( variable_name ) // &
+       CALL internal_message( 'error', routine_name //                                             &
+                              ': file not found ' //                                               &
+                              '(variable "' // TRIM( variable_name ) //                            &
                               '", file "' // TRIM( file_name ) // '")!' )
     ENDIF
@@ -3622,6 +3637,6 @@
 !> starts and origins are set to zero for all dimensions.
 !--------------------------------------------------------------------------------------------------!
- SUBROUTINE get_masked_indices_and_masked_dimension_bounds(                             &
-               dimensions, bounds_start, bounds_end, bounds_masked_start, value_counts, &
+ SUBROUTINE get_masked_indices_and_masked_dimension_bounds(                                        &
+               dimensions, bounds_start, bounds_end, bounds_masked_start, value_counts,            &
                bounds_origin, masked_indices )
 
@@ -3656,9 +3671,9 @@
 !--       Find number of masked values within given variable bounds
           value_counts(d) = 0
-          DO  i = LBOUND( dimensions(d)%masked_indices, DIM=1 ), &
+          DO  i = LBOUND( dimensions(d)%masked_indices, DIM=1 ),                                   &
                   UBOUND( dimensions(d)%masked_indices, DIM=1 )
 !
 !--          Is masked index within given bounds?
-             IF ( dimensions(d)%masked_indices(i) >= bounds_start(d)  .AND.  &
+             IF ( dimensions(d)%masked_indices(i) >= bounds_start(d)  .AND.                        &
                   dimensions(d)%masked_indices(i) <= bounds_end(d)           )  THEN
 !
@@ -3702,6 +3717,6 @@
 ! Description:
 ! ------------
-!> Message routine writing debug information into the debug file
-!> or creating the error message string.
+!> Message routine writing debug information into the debug file or creating the error message
+!> string.
 !--------------------------------------------------------------------------------------------------!
  SUBROUTINE internal_message( level, string )
@@ -3733,11 +3748,13 @@
 
     CHARACTER(LEN=*), PARAMETER ::  separation_string = '---'                   !< string separating blocks in output
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_database_debug_output'  !< name of this routine
+
+    INTEGER, PARAMETER ::  indent_depth = 3        !< space per indentation
+    INTEGER, PARAMETER ::  max_keyname_length = 6  !< length of longest key name
+
     CHARACTER(LEN=50)           ::  write_format1                               !< format for write statements
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_database_debug_output'  !< name of this routine
 
     INTEGER            ::  f                       !< loop index
-    INTEGER, PARAMETER ::  indent_depth = 3        !< space per indentation
     INTEGER            ::  indent_level            !< indentation level
-    INTEGER, PARAMETER ::  max_keyname_length = 6  !< length of longest key name
     INTEGER            ::  natts                   !< number of attributes
     INTEGER            ::  ndims                   !< number of dimensions
@@ -3750,5 +3767,5 @@
     WRITE( debug_output_unit, '(A)' ) REPEAT( separation_string // ' ', 4 )
 
-    IF ( .NOT. ALLOCATED( files ) .OR. nfiles == 0 )  THEN
+    IF ( .NOT. ALLOCATED( files )  .OR.  nfiles == 0 )  THEN
 
        WRITE( debug_output_unit, '(A)' ) 'database is empty'
@@ -3757,7 +3774,7 @@
 
        indent_level = 1
-       WRITE( write_format1, '(A,I3,A,I3,A)' ) '(T', indent_level * indent_depth + 1, ',A,T',  &
-                                         indent_level * indent_depth + 1 + max_keyname_length, &
-                                         ',(": ")'
+       WRITE( write_format1, '(A,I3,A,I3,A)' ) '(T', indent_level * indent_depth + 1, ',A,T',      &
+                                             indent_level * indent_depth + 1 + max_keyname_length, &
+                                             ',(": ")'
 
        DO  f = 1, nfiles
@@ -3791,10 +3808,12 @@
     CONTAINS
 
-!--------------------------------------------------------------------------------------------!
-    ! Description:
-    ! ------------
-    !> Print list of attributes.
-!--------------------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Print list of attributes.
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE print_attributes( indent_level, attributes )
+
+       INTEGER, PARAMETER  ::  max_keyname_length = 6  !< length of longest key name
 
        CHARACTER(LEN=50) ::  write_format1  !< format for write statements
@@ -3803,5 +3822,4 @@
        INTEGER             ::  i                       !< loop index
        INTEGER, INTENT(IN) ::  indent_level            !< indentation level
-       INTEGER, PARAMETER  ::  max_keyname_length = 6  !< length of longest key name
        INTEGER             ::  nelement                !< number of elements to print
 
@@ -3810,9 +3828,9 @@
 
        WRITE( write_format1, '(A,I3,A)' ) '(T', indent_level * indent_depth + 1, ',A'
-       WRITE( write_format2, '(A,I3,A,I3,A)' ) &
-          '(T', ( indent_level + 1 ) * indent_depth + 1, ',A,T', &
+       WRITE( write_format2, '(A,I3,A,I3,A)' )                                                     &
+          '(T', ( indent_level + 1 ) * indent_depth + 1, ',A,T',                                   &
           ( indent_level + 1 ) * indent_depth + 1 + max_keyname_length, ',(": ")'
 
-       WRITE( debug_output_unit, TRIM( write_format1 ) // ',A)' ) &
+       WRITE( debug_output_unit, TRIM( write_format1 ) // ',A)' )                                  &
           REPEAT( separation_string // ' ', 4 )
        WRITE( debug_output_unit, TRIM( write_format1 ) // ')' ) 'attributes:'
@@ -3820,29 +3838,29 @@
        nelement = SIZE( attributes )
        DO  i = 1, nelement
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' )                               &
              'name', TRIM( attributes(i)%name )
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' )                               &
              'type', TRIM( attributes(i)%data_type )
 
           IF ( TRIM( attributes(i)%data_type ) == 'char' )  THEN
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' )                            &
                 'value', TRIM( attributes(i)%value_char )
           ELSEIF ( TRIM( attributes(i)%data_type ) == 'int8' )  THEN
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I4)' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I4)' )                           &
                 'value', attributes(i)%value_int8
           ELSEIF ( TRIM( attributes(i)%data_type ) == 'int16' )  THEN
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I6)' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I6)' )                           &
                 'value', attributes(i)%value_int16
           ELSEIF ( TRIM( attributes(i)%data_type ) == 'int32' )  THEN
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I11)' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I11)' )                          &
                 'value', attributes(i)%value_int32
           ELSEIF ( TRIM( attributes(i)%data_type ) == 'real32' )  THEN
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',E14.7)' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',E14.7)' )                        &
                 'value', attributes(i)%value_real32
           ELSEIF (  TRIM(attributes(i)%data_type) == 'real64' )  THEN
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',E22.15)' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',E22.15)' )                       &
                 'value', attributes(i)%value_real64
           ENDIF
-          IF ( i < nelement )  &
+          IF ( i < nelement )                                                                      &
              WRITE( debug_output_unit, TRIM( write_format1 ) // ')' ) separation_string
        ENDDO
@@ -3850,10 +3868,12 @@
     END SUBROUTINE print_attributes
 
-!--------------------------------------------------------------------------------------------!
-    ! Description:
-    ! ------------
-    !> Print list of dimensions.
-!--------------------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Print list of dimensions.
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE print_dimensions( indent_level, dimensions )
+
+       INTEGER, PARAMETER  ::  max_keyname_length = 15  !< length of longest key name
 
        CHARACTER(LEN=50) ::  write_format1  !< format for write statements
@@ -3863,5 +3883,4 @@
        INTEGER, INTENT(IN) ::  indent_level             !< indentation level
        INTEGER             ::  j                        !< loop index
-       INTEGER, PARAMETER  ::  max_keyname_length = 15  !< length of longest key name
        INTEGER             ::  nelement                 !< number of elements to print
 
@@ -3872,9 +3891,9 @@
 
        WRITE( write_format1, '(A,I3,A)' ) '(T', indent_level * indent_depth + 1, ',A'
-       WRITE( write_format2, '(A,I3,A,I3,A)' ) &
-          '(T', ( indent_level + 1 ) * indent_depth + 1, ',A,T', &
+       WRITE( write_format2, '(A,I3,A,I3,A)' )                                                     &
+          '(T', ( indent_level + 1 ) * indent_depth + 1, ',A,T',                                   &
           ( indent_level + 1 ) * indent_depth + 1 + max_keyname_length, ',(": ")'
 
-       WRITE( debug_output_unit, TRIM( write_format1 ) // ',A)' ) &
+       WRITE( debug_output_unit, TRIM( write_format1 ) // ',A)' )                                  &
           REPEAT( separation_string // ' ', 4 )
        WRITE( debug_output_unit, TRIM( write_format1 ) // ')' ) 'dimensions:'
@@ -3885,23 +3904,23 @@
 !
 !--       Print general information
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' )                               &
              'name', TRIM( dimensions(i)%name )
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' )                               &
              'type', TRIM( dimensions(i)%data_type )
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7)' )                              &
              'id', dimensions(i)%id
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7)' )                              &
              'length', dimensions(i)%length
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7,A,I7)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7,A,I7)' )                         &
              'bounds', dimensions(i)%bounds(1), ',', dimensions(i)%bounds(2)
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',L1)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',L1)' )                              &
              'is masked', dimensions(i)%is_masked
 !
 !--       Print information about mask
           IF ( is_masked )  THEN
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7)' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7)' )                           &
                 'masked length', dimensions(i)%length_mask
 
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',L1)', ADVANCE='no' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',L1)', ADVANCE='no' )             &
                 'mask', dimensions(i)%mask(dimensions(i)%bounds(1))
              DO  j = dimensions(i)%bounds(1)+1, dimensions(i)%bounds(2)
@@ -3910,8 +3929,8 @@
              WRITE( debug_output_unit, '(A)' )  ''  ! write line-end
 
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I6)', ADVANCE='no' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I6)', ADVANCE='no' )             &
                 'masked indices', dimensions(i)%masked_indices(0)
              DO  j = 1, dimensions(i)%length_mask-1
-                WRITE( debug_output_unit, '(A,I6)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, '(A,I6)', ADVANCE='no' )                                 &
                    ',', dimensions(i)%masked_indices(j)
              ENDDO
@@ -3922,16 +3941,16 @@
           IF ( ALLOCATED( dimensions(i)%values_int8 ) )  THEN
 
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I4)', ADVANCE='no' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I4)', ADVANCE='no' )             &
                 'values', dimensions(i)%values_int8(dimensions(i)%bounds(1))
              DO  j = dimensions(i)%bounds(1)+1, dimensions(i)%bounds(2)
-                WRITE( debug_output_unit, '(A,I4)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, '(A,I4)', ADVANCE='no' )                                 &
                    ',', dimensions(i)%values_int8(j)
              ENDDO
              WRITE( debug_output_unit, '(A)' )  ''  ! write line-end
              IF ( is_masked )  THEN
-                WRITE( debug_output_unit, TRIM( write_format2 ) // ',I4)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, TRIM( write_format2 ) // ',I4)', ADVANCE='no' )          &
                    'masked values', dimensions(i)%masked_values_int8(0)
                 DO  j = 1, dimensions(i)%length_mask-1
-                   WRITE( debug_output_unit, '(A,I4)', ADVANCE='no' ) &
+                   WRITE( debug_output_unit, '(A,I4)', ADVANCE='no' )                              &
                       ',', dimensions(i)%masked_values_int8(j)
                 ENDDO
@@ -3941,16 +3960,16 @@
           ELSEIF ( ALLOCATED( dimensions(i)%values_int16 ) )  THEN
 
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I6)', ADVANCE='no' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I6)', ADVANCE='no' )             &
                 'values', dimensions(i)%values_int16(dimensions(i)%bounds(1))
              DO  j = dimensions(i)%bounds(1)+1, dimensions(i)%bounds(2)
-                WRITE( debug_output_unit, '(A,I6)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, '(A,I6)', ADVANCE='no' )                                 &
                    ',', dimensions(i)%values_int16(j)
              ENDDO
              WRITE( debug_output_unit, '(A)' )  ''  ! write line-end
              IF ( is_masked )  THEN
-                WRITE( debug_output_unit, TRIM( write_format2 ) // ',I6)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, TRIM( write_format2 ) // ',I6)', ADVANCE='no' )          &
                    'masked values', dimensions(i)%masked_values_int16(0)
                 DO  j = 1, dimensions(i)%length_mask-1
-                   WRITE( debug_output_unit, '(A,I6)', ADVANCE='no' ) &
+                   WRITE( debug_output_unit, '(A,I6)', ADVANCE='no' )                              &
                       ',', dimensions(i)%masked_values_int16(j)
                 ENDDO
@@ -3960,16 +3979,16 @@
           ELSEIF ( ALLOCATED( dimensions(i)%values_int32 ) )  THEN
 
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I11)', ADVANCE='no' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I11)', ADVANCE='no' )            &
                 'values', dimensions(i)%values_int32(dimensions(i)%bounds(1))
              DO  j = dimensions(i)%bounds(1)+1, dimensions(i)%bounds(2)
-                WRITE( debug_output_unit, '(A,I11)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, '(A,I11)', ADVANCE='no' )                                &
                    ',', dimensions(i)%values_int32(j)
              ENDDO
              WRITE( debug_output_unit, '(A)' )  ''  ! write line-end
              IF ( is_masked )  THEN
-                WRITE( debug_output_unit, TRIM( write_format2 ) // ',I11)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, TRIM( write_format2 ) // ',I11)', ADVANCE='no' )         &
                    'masked values', dimensions(i)%masked_values_int32(0)
                 DO  j = 1, dimensions(i)%length_mask-1
-                   WRITE( debug_output_unit, '(A,I11)', ADVANCE='no' ) &
+                   WRITE( debug_output_unit, '(A,I11)', ADVANCE='no' )                             &
                       ',', dimensions(i)%masked_values_int32(j)
                 ENDDO
@@ -3979,16 +3998,16 @@
           ELSEIF ( ALLOCATED( dimensions(i)%values_intwp ) )  THEN
 
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I11)', ADVANCE='no' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',I11)', ADVANCE='no' )            &
                 'values', dimensions(i)%values_intwp(dimensions(i)%bounds(1))
              DO  j = dimensions(i)%bounds(1)+1, dimensions(i)%bounds(2)
-                WRITE( debug_output_unit, '(A,I11)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, '(A,I11)', ADVANCE='no' )                                &
                    ',', dimensions(i)%values_intwp(j)
              ENDDO
              WRITE( debug_output_unit, '(A)' )  ''  ! write line-end
              IF ( is_masked )  THEN
-                WRITE( debug_output_unit, TRIM( write_format2 ) // ',I11)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, TRIM( write_format2 ) // ',I11)', ADVANCE='no' )         &
                    'masked values', dimensions(i)%masked_values_intwp(0)
                 DO  j = 1, dimensions(i)%length_mask-1
-                   WRITE( debug_output_unit, '(A,I11)', ADVANCE='no' ) &
+                   WRITE( debug_output_unit, '(A,I11)', ADVANCE='no' )                             &
                       ',', dimensions(i)%masked_values_intwp(j)
                 ENDDO
@@ -3998,16 +4017,16 @@
           ELSEIF ( ALLOCATED( dimensions(i)%values_real32 ) )  THEN
 
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',E14.7)', ADVANCE='no' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',E14.7)', ADVANCE='no' )          &
                 'values', dimensions(i)%values_real32(dimensions(i)%bounds(1))
              DO  j = dimensions(i)%bounds(1)+1, dimensions(i)%bounds(2)
-                WRITE( debug_output_unit, '(A,E14.7)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, '(A,E14.7)', ADVANCE='no' )                              &
                    ',', dimensions(i)%values_real32(j)
              ENDDO
              WRITE( debug_output_unit, '(A)' )  ''  ! write line-end
              IF ( is_masked )  THEN
-                WRITE( debug_output_unit, TRIM( write_format2 ) // ',E14.7)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, TRIM( write_format2 ) // ',E14.7)', ADVANCE='no' )       &
                    'masked values', dimensions(i)%masked_values_real32(0)
                 DO  j = 1, dimensions(i)%length_mask-1
-                   WRITE( debug_output_unit, '(A,E14.7)', ADVANCE='no' ) &
+                   WRITE( debug_output_unit, '(A,E14.7)', ADVANCE='no' )                           &
                       ',', dimensions(i)%masked_values_real32(j)
                 ENDDO
@@ -4017,16 +4036,16 @@
           ELSEIF ( ALLOCATED( dimensions(i)%values_real64 ) )  THEN
 
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',E22.15)', ADVANCE='no' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',E22.15)', ADVANCE='no' )         &
                 'values', dimensions(i)%values_real64(dimensions(i)%bounds(1))
              DO  j = dimensions(i)%bounds(1)+1, dimensions(i)%bounds(2)
-                WRITE( debug_output_unit, '(A,E22.15)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, '(A,E22.15)', ADVANCE='no' )                             &
                    ',', dimensions(i)%values_real64(j)
              ENDDO
              WRITE( debug_output_unit, '(A)' )  ''  ! write line-end
              IF ( is_masked )  THEN
-                WRITE( debug_output_unit, TRIM( write_format2 ) // ',E22.15)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, TRIM( write_format2 ) // ',E22.15)', ADVANCE='no' )      &
                    'masked values', dimensions(i)%masked_values_real64(0)
                 DO  j = 1, dimensions(i)%length_mask-1
-                   WRITE( debug_output_unit, '(A,E22.15)', ADVANCE='no' ) &
+                   WRITE( debug_output_unit, '(A,E22.15)', ADVANCE='no' )                          &
                       ',', dimensions(i)%masked_values_real64(j)
                 ENDDO
@@ -4036,16 +4055,16 @@
           ELSEIF ( ALLOCATED( dimensions(i)%values_realwp ) )  THEN
 
-             WRITE( debug_output_unit, TRIM( write_format2 ) // ',E22.15)', ADVANCE='no' ) &
+             WRITE( debug_output_unit, TRIM( write_format2 ) // ',E22.15)', ADVANCE='no' )         &
                 'values', dimensions(i)%values_realwp(dimensions(i)%bounds(1))
              DO  j = dimensions(i)%bounds(1)+1, dimensions(i)%bounds(2)
-                WRITE( debug_output_unit, '(A,E22.15)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, '(A,E22.15)', ADVANCE='no' )                             &
                    ',', dimensions(i)%values_realwp(j)
              ENDDO
              WRITE( debug_output_unit, '(A)' )  ''  ! write line-end
              IF ( is_masked )  THEN
-                WRITE( debug_output_unit, TRIM( write_format2 ) // ',E22.15)', ADVANCE='no' ) &
+                WRITE( debug_output_unit, TRIM( write_format2 ) // ',E22.15)', ADVANCE='no' )      &
                    'masked values', dimensions(i)%masked_values_realwp(0)
                 DO  j = 1, dimensions(i)%length_mask-1
-                   WRITE( debug_output_unit, '(A,E22.15)', ADVANCE='no' ) &
+                   WRITE( debug_output_unit, '(A,E22.15)', ADVANCE='no' )                          &
                       ',', dimensions(i)%masked_values_realwp(j)
                 ENDDO
@@ -4055,8 +4074,8 @@
           ENDIF
 
-          IF ( ALLOCATED( dimensions(i)%attributes ) )  &
+          IF ( ALLOCATED( dimensions(i)%attributes ) )                                             &
              CALL print_attributes( indent_level+1, dimensions(i)%attributes )
 
-          IF ( i < nelement )  &
+          IF ( i < nelement )                                                                      &
              WRITE( debug_output_unit, TRIM( write_format1 ) // ')' ) separation_string
        ENDDO
@@ -4064,10 +4083,12 @@
     END SUBROUTINE print_dimensions
 
-!--------------------------------------------------------------------------------------------!
-    ! Description:
-    ! ------------
-    !> Print list of variables.
-!--------------------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Print list of variables.
+!--------------------------------------------------------------------------------------------------!
     SUBROUTINE print_variables( indent_level, variables )
+
+       INTEGER, PARAMETER  ::  max_keyname_length = 16  !< length of longest key name
 
        CHARACTER(LEN=50) ::  write_format1  !< format for write statements
@@ -4077,5 +4098,4 @@
        INTEGER, INTENT(IN) ::  indent_level             !< indentation level
        INTEGER             ::  j                        !< loop index
-       INTEGER, PARAMETER  ::  max_keyname_length = 16  !< length of longest key name
        INTEGER             ::  nelement                 !< number of elements to print
 
@@ -4084,9 +4104,9 @@
 
        WRITE( write_format1, '(A,I3,A)' ) '(T', indent_level * indent_depth + 1, ',A'
-       WRITE( write_format2, '(A,I3,A,I3,A)' ) &
-          '(T', ( indent_level + 1 ) * indent_depth + 1, ',A,T', &
+       WRITE( write_format2, '(A,I3,A,I3,A)' )                                                     &
+          '(T', ( indent_level + 1 ) * indent_depth + 1, ',A,T',                                   &
           ( indent_level + 1 ) * indent_depth + 1 + max_keyname_length, ',(": ")'
 
-       WRITE( debug_output_unit, TRIM( write_format1 ) // ',A)' ) &
+       WRITE( debug_output_unit, TRIM( write_format1 ) // ',A)' )                                  &
           REPEAT( separation_string // ' ', 4 )
        WRITE( debug_output_unit, TRIM( write_format1 ) // ')' ) 'variables:'
@@ -4094,32 +4114,32 @@
        nelement = SIZE( variables )
        DO  i = 1, nelement
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' )                               &
              'name', TRIM( variables(i)%name )
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)' )                               &
              'type', TRIM( variables(i)%data_type )
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7)' )                              &
              'id', variables(i)%id
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',L1)' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',L1)' )                              &
              'is global', variables(i)%is_global
 
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)', ADVANCE='no' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',A)', ADVANCE='no' )                 &
              'dimension names', TRIM( variables(i)%dimension_names(1) )
           DO  j = 2, SIZE( variables(i)%dimension_names )
-             WRITE( debug_output_unit, '(A,A)', ADVANCE='no' ) &
+             WRITE( debug_output_unit, '(A,A)', ADVANCE='no' )                                     &
                 ',', TRIM( variables(i)%dimension_names(j) )
           ENDDO
           WRITE( debug_output_unit, '(A)' )  ''  ! write line-end
 
-          WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7)', ADVANCE='no' ) &
+          WRITE( debug_output_unit, TRIM( write_format2 ) // ',I7)', ADVANCE='no' )                &
              'dimension ids', variables(i)%dimension_ids(1)
           DO  j = 2, SIZE( variables(i)%dimension_names )
-             WRITE( debug_output_unit, '(A,I7)', ADVANCE='no' ) &
+             WRITE( debug_output_unit, '(A,I7)', ADVANCE='no' )                                    &
                 ',', variables(i)%dimension_ids(j)
           ENDDO
           WRITE( debug_output_unit, '(A)' )  ''  ! write line-end
 
-          IF ( ALLOCATED( variables(i)%attributes ) )  &
+          IF ( ALLOCATED( variables(i)%attributes ) )                                              &
              CALL print_attributes( indent_level+1, variables(i)%attributes )
-          IF ( i < nelement )  &
+          IF ( i < nelement )                                                                      &
              WRITE( debug_output_unit, TRIM( write_format1 ) // ')' ) separation_string
        ENDDO
Index: /palm/trunk/SOURCE/data_output_netcdf4_module.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_netcdf4_module.f90	(revision 4576)
+++ /palm/trunk/SOURCE/data_output_netcdf4_module.f90	(revision 4577)
@@ -3,15 +3,14 @@
 ! 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/>.
+! 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 2019-2020 Leibniz Universitaet Hannover
@@ -25,6 +24,9 @@
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4481 2020-03-31 18:55:54Z maronga
 ! bugfix: cpp-directive moved to avoid compile error due to unused dummy argument
-! 
+!
 ! 4408 2020-02-14 10:04:39Z gronemeier
 ! Enable character-array output
@@ -67,10 +69,10 @@
 #endif
 
-    CHARACTER(LEN=800) ::  internal_error_message = ''  !< string containing the last error message
-    CHARACTER(LEN=100) ::  file_suffix = ''             !< file suffix added to each file name
-    CHARACTER(LEN=800) ::  temp_string                  !< dummy string
-
     CHARACTER(LEN=*), PARAMETER ::  mode_parallel = 'parallel'  !< string selecting netcdf4 parallel mode
     CHARACTER(LEN=*), PARAMETER ::  mode_serial   = 'serial'    !< string selecting netcdf4 serial mode
+
+    CHARACTER(LEN=100) ::  file_suffix = ''             !< file suffix added to each file name
+    CHARACTER(LEN=800) ::  internal_error_message = ''  !< string containing the last error message
+    CHARACTER(LEN=800) ::  temp_string                  !< dummy string
 
     INTEGER ::  debug_output_unit       !< Fortran Unit Number of the debug-output file
@@ -121,13 +123,13 @@
     END INTERFACE netcdf4_get_error_message
 
-    PUBLIC &
-       netcdf4_finalize, &
-       netcdf4_get_error_message, &
-       netcdf4_init_dimension, &
-       netcdf4_stop_file_header_definition, &
-       netcdf4_init_module, &
-       netcdf4_init_variable, &
-       netcdf4_open_file, &
-       netcdf4_write_attribute, &
+    PUBLIC                                                                                         &
+       netcdf4_finalize,                                                                           &
+       netcdf4_get_error_message,                                                                  &
+       netcdf4_init_dimension,                                                                     &
+       netcdf4_init_module,                                                                        &
+       netcdf4_init_variable,                                                                      &
+       netcdf4_open_file,                                                                          &
+       netcdf4_stop_file_header_definition,                                                        &
+       netcdf4_write_attribute,                                                                    &
        netcdf4_write_variable
 
@@ -141,6 +143,6 @@
 !> Initialize data-output module.
 !--------------------------------------------------------------------------------------------------!
- SUBROUTINE netcdf4_init_module( file_suffix_of_output_group, mpi_comm_of_output_group, &
-                                 master_output_rank,                                    &
+ SUBROUTINE netcdf4_init_module( file_suffix_of_output_group, mpi_comm_of_output_group,            &
+                                 master_output_rank,                                               &
                                  program_debug_output_unit, debug_output, dom_global_id )
 
@@ -174,8 +176,8 @@
  SUBROUTINE netcdf4_open_file( mode, file_name, file_id, return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'netcdf4_open_file'  !< name of this routine
+
     CHARACTER(LEN=*), INTENT(IN) ::  file_name  !< name of file
     CHARACTER(LEN=*), INTENT(IN) ::  mode       !< operation mode (either parallel or serial)
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'netcdf4_open_file'  !< name of this routine
 
     INTEGER, INTENT(OUT) ::  file_id       !< file ID
@@ -201,7 +203,7 @@
        IF ( my_rank /= master_rank )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name // &
-                                 ': trying to define a NetCDF file in serial mode by an MPI ' // &
-                                 'rank other than the master output rank. Serial NetCDF ' // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': trying to define a NetCDF file in serial mode by an MPI ' //   &
+                                 'rank other than the master output rank. Serial NetCDF ' //       &
                                  'files can only be defined by the master output rank!' )
        ENDIF
@@ -212,12 +214,11 @@
 
        IF ( return_value == 0 )  &
-          nc_stat = NF90_CREATE( TRIM( file_name ) // TRIM( file_suffix ), &
-                                 IOR( NF90_NOCLOBBER, NF90_NETCDF4 ),      &
-                                 file_id )
+          nc_stat = NF90_CREATE( TRIM( file_name ) // TRIM( file_suffix ),                         &
+                                 IOR( NF90_NOCLOBBER, NF90_NETCDF4 ), file_id )
 #else
        nc_stat = 0
        return_value = 1
-       CALL internal_message( 'error', routine_name //                               &
-                              ': pre-processor directive "__netcdf4" not given. ' // &
+       CALL internal_message( 'error', routine_name //                                             &
+                              ': pre-processor directive "__netcdf4" not given. ' //               &
                               'Using NetCDF4 output not possible' )
 #endif
@@ -226,13 +227,13 @@
 
 #if defined( __parallel ) && defined( __netcdf4 ) && defined( __netcdf4_parallel )
-       nc_stat = NF90_CREATE( TRIM( file_name ) // TRIM( file_suffix ),               &
-                              IOR( NF90_NOCLOBBER, IOR( NF90_NETCDF4, NF90_MPIIO ) ), &
+       nc_stat = NF90_CREATE( TRIM( file_name ) // TRIM( file_suffix ),                            &
+                              IOR( NF90_NOCLOBBER, IOR( NF90_NETCDF4, NF90_MPIIO ) ),              &
                               file_id, COMM = output_group_comm, INFO = MPI_INFO_NULL )
 #else
        nc_stat = 0
        return_value = 1
-       CALL internal_message( 'error', routine_name //                                 &
-                              ': pre-processor directives "__parallel" and/or ' //     &
-                              '"__netcdf4" and/or "__netcdf4_parallel" not given. ' // &
+       CALL internal_message( 'error', routine_name //                                             &
+                              ': pre-processor directives "__parallel" and/or ' //                 &
+                              '"__netcdf4" and/or "__netcdf4_parallel" not given. ' //             &
                               'Using parallel NetCDF4 output not possible' )
 #endif
@@ -241,6 +242,6 @@
        nc_stat = 0
        return_value = 1
-       CALL internal_message( 'error', routine_name // ': selected mode "' //  &
-                                       TRIM( mode ) // '" must be either "' // &
+       CALL internal_message( 'error', routine_name // ': selected mode "' //                      &
+                                       TRIM( mode ) // '" must be either "' //                     &
                                        mode_serial // '" or "' // mode_parallel // '"' )
     ENDIF
@@ -249,6 +250,6 @@
     IF ( nc_stat /= NF90_NOERR  .AND.  return_value == 0 )  THEN
        return_value = 1
-       CALL internal_message( 'error', routine_name //                 &
-                              ': NetCDF error while opening file "' // &
+       CALL internal_message( 'error', routine_name //                                             &
+                              ': NetCDF error while opening file "' //                             &
                               TRIM( file_name ) // '": ' // NF90_STRERROR( nc_stat ) )
     ENDIF
@@ -262,12 +263,12 @@
 !> Write attribute to netcdf file.
 !--------------------------------------------------------------------------------------------------!
- SUBROUTINE netcdf4_write_attribute( file_id, variable_id, attribute_name, &
-                  value_char, value_int8, value_int16, value_int32,        &
-                  value_real32, value_real64, return_value )
+ SUBROUTINE netcdf4_write_attribute( file_id, variable_id, attribute_name,                         &
+                                     value_char, value_int8, value_int16, value_int32,             &
+                                     value_real32, value_real64, return_value )
+
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'netcdf4_write_attribute'  !< name of this routine
 
     CHARACTER(LEN=*), INTENT(IN)           ::  attribute_name  !< name of attribute
     CHARACTER(LEN=*), INTENT(IN), OPTIONAL ::  value_char      !< value of attribute
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'netcdf4_write_attribute'  !< name of this routine
 
     INTEGER ::  nc_stat    !< netcdf return value
@@ -295,5 +296,5 @@
     ENDIF
 
-    CALL internal_message( 'debug', routine_name // &
+    CALL internal_message( 'debug', routine_name //                                                &
                            ': write attribute "' // TRIM( attribute_name ) // '"' )
 
@@ -312,5 +313,5 @@
     ELSE
        return_value = 1
-       CALL internal_message( 'error', routine_name // &
+       CALL internal_message( 'error', routine_name //                                             &
                               ': no value given for attribute "' // TRIM( attribute_name ) // '"' )
     ENDIF
@@ -319,6 +320,6 @@
        IF ( nc_stat /= NF90_NOERR )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                      &
-                                 ': NetCDF error while writing attribute "' // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': NetCDF error while writing attribute "' //                     &
                                  TRIM( attribute_name ) // '": ' // NF90_STRERROR( nc_stat ) )
        ENDIF
@@ -337,10 +338,10 @@
  SUBROUTINE netcdf4_init_dimension( mode, file_id, dimension_id, variable_id, &
                dimension_name, dimension_type, dimension_length, return_value )
+
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'netcdf4_init_dimension'  !< name of this routine
 
     CHARACTER(LEN=*), INTENT(IN) ::  dimension_name  !< name of dimension
     CHARACTER(LEN=*), INTENT(IN) ::  dimension_type  !< data type of dimension
     CHARACTER(LEN=*), INTENT(IN) ::  mode            !< operation mode (either parallel or serial)
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'netcdf4_init_dimension'  !< name of this routine
 
     INTEGER, INTENT(OUT) ::  dimension_id         !< dimension ID
@@ -357,5 +358,5 @@
     variable_id = -1
 
-    CALL internal_message( 'debug', routine_name // &
+    CALL internal_message( 'debug', routine_name //                                                &
                            ': init dimension "' // TRIM( dimension_name ) // '"' )
 !
@@ -378,6 +379,6 @@
     ELSE
        return_value = 1
-       CALL internal_message( 'error', routine_name //                           &
-                              ': NetCDF error while initializing dimension "' // &
+       CALL internal_message( 'error', routine_name //                                             &
+                              ': NetCDF error while initializing dimension "' //                   &
                               TRIM( dimension_name ) // '": ' // NF90_STRERROR( nc_stat ) )
     ENDIF
@@ -395,12 +396,12 @@
 !> Initialize variable.
 !--------------------------------------------------------------------------------------------------!
- SUBROUTINE netcdf4_init_variable( mode, file_id, variable_id, variable_name, variable_type, &
+ SUBROUTINE netcdf4_init_variable( mode, file_id, variable_id, variable_name, variable_type,       &
                                    dimension_ids, is_global, return_value )
+
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'netcdf4_init_variable'  !< name of this routine
 
     CHARACTER(LEN=*), INTENT(IN) ::  mode           !< operation mode (either parallel or serial)
     CHARACTER(LEN=*), INTENT(IN) ::  variable_name  !< name of variable
     CHARACTER(LEN=*), INTENT(IN) ::  variable_type  !< data type of variable
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'netcdf4_init_variable'  !< name of this routine
 
     INTEGER, INTENT(IN)  ::  file_id           !< file ID
@@ -419,6 +420,6 @@
 
     WRITE( temp_string, * ) is_global
-    CALL internal_message( 'debug', routine_name //                        &
-                           ': init variable "' // TRIM( variable_name ) // &
+    CALL internal_message( 'debug', routine_name //                                                &
+                           ': init variable "' // TRIM( variable_name ) //                         &
                            '" ( is_global = ' // TRIM( temp_string ) // ')' )
 
@@ -446,6 +447,6 @@
        IF ( nc_stat /= NF90_NOERR )  THEN
           return_value = 1
-          CALL internal_message( 'error', routine_name //                          &
-                                 ': NetCDF error while initializing variable "' // &
+          CALL internal_message( 'error', routine_name //                                          &
+                                 ': NetCDF error while initializing variable "' //                 &
                                  TRIM( variable_name ) // '": ' // NF90_STRERROR( nc_stat ) )
        ENDIF
@@ -507,15 +508,15 @@
 !> Write variable of different kind into netcdf file.
 !--------------------------------------------------------------------------------------------------!
- SUBROUTINE netcdf4_write_variable(                                                    &
-               file_id, variable_id, bounds_start, value_counts, bounds_origin,        &
-               is_global,                                                              &
-               values_char_0d,   values_char_1d,   values_char_2d,   values_char_3d,   &
-               values_int8_0d,   values_int8_1d,   values_int8_2d,   values_int8_3d,   &
-               values_int16_0d,  values_int16_1d,  values_int16_2d,  values_int16_3d,  &
-               values_int32_0d,  values_int32_1d,  values_int32_2d,  values_int32_3d,  &
-               values_intwp_0d,  values_intwp_1d,  values_intwp_2d,  values_intwp_3d,  &
-               values_real32_0d, values_real32_1d, values_real32_2d, values_real32_3d, &
-               values_real64_0d, values_real64_1d, values_real64_2d, values_real64_3d, &
-               values_realwp_0d, values_realwp_1d, values_realwp_2d, values_realwp_3d, &
+ SUBROUTINE netcdf4_write_variable(                                                                &
+               file_id, variable_id, bounds_start, value_counts, bounds_origin,                    &
+               is_global,                                                                          &
+               values_char_0d,   values_char_1d,   values_char_2d,   values_char_3d,               &
+               values_int8_0d,   values_int8_1d,   values_int8_2d,   values_int8_3d,               &
+               values_int16_0d,  values_int16_1d,  values_int16_2d,  values_int16_3d,              &
+               values_int32_0d,  values_int32_1d,  values_int32_2d,  values_int32_3d,              &
+               values_intwp_0d,  values_intwp_1d,  values_intwp_2d,  values_intwp_3d,              &
+               values_real32_0d, values_real32_1d, values_real32_2d, values_real32_3d,             &
+               values_real64_0d, values_real64_1d, values_real64_2d, values_real64_3d,             &
+               values_realwp_0d, values_realwp_1d, values_realwp_2d, values_realwp_3d,             &
                return_value )
 
@@ -586,5 +587,5 @@
 #endif
 
-    IF ( return_value == 0  .AND.  ( .NOT. is_global  .OR.  my_rank == master_rank ) )  THEN
+    IF ( return_value == 0  .AND.  ( .NOT. is_global .OR. my_rank == master_rank ) )  THEN
 
        WRITE( temp_string, * ) variable_id
@@ -596,144 +597,144 @@
 !--    character output
        IF ( PRESENT( values_char_0d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_char_0d /), &
-                                  start = bounds_start - bounds_origin + 1,   &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_char_0d /),                      &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_char_1d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_char_1d,     &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_char_1d,                            &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_char_2d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_char_2d,     &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_char_2d,                            &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_char_3d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_char_3d,     &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_char_3d,                            &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
 !
 !--    8bit integer output
        ELSEIF ( PRESENT( values_int8_0d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_int8_0d /), &
-                                  start = bounds_start - bounds_origin + 1,   &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_int8_0d /),                      &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_int8_1d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int8_1d,     &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int8_1d,                            &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_int8_2d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int8_2d,     &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int8_2d,                            &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_int8_3d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int8_3d,     &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int8_3d,                            &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
 !
 !--    16bit integer output
        ELSEIF ( PRESENT( values_int16_0d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_int16_0d /), &
-                                  start = bounds_start - bounds_origin + 1,    &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_int16_0d /),                     &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_int16_1d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int16_1d,    &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int16_1d,                           &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_int16_2d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int16_2d,    &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int16_2d,                           &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_int16_3d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int16_3d,    &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int16_3d,                           &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
 !
 !--    32bit integer output
        ELSEIF ( PRESENT( values_int32_0d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_int32_0d /),  &
-                                  start = bounds_start - bounds_origin + 1,     &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_int32_0d /),                     &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_int32_1d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int32_1d,    &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int32_1d,                           &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_int32_2d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int32_2d,    &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int32_2d,                           &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_int32_3d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int32_3d,    &
-                                  start = bounds_start - bounds_origin + 1, &
-                                  count = value_counts )
-!
-!--    working-precision integer output
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_int32_3d,                           &
+                                  start = bounds_start - bounds_origin + 1,                        &
+                                  count = value_counts )
+!
+!--    Working-precision integer output
        ELSEIF ( PRESENT( values_intwp_0d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_intwp_0d /),  &
-                                  start = bounds_start - bounds_origin + 1,     &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_intwp_0d /),                     &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_intwp_1d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_intwp_1d,    &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_intwp_1d,                           &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_intwp_2d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_intwp_2d,    &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_intwp_2d,                           &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_intwp_3d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_intwp_3d,    &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_intwp_3d,                           &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
 !
 !--    32bit real output
        ELSEIF ( PRESENT( values_real32_0d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_real32_0d /), &
-                                  start = bounds_start - bounds_origin + 1,     &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_real32_0d /),                    &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_real32_1d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real32_1d,   &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real32_1d,                          &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_real32_2d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real32_2d,   &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real32_2d,                          &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_real32_3d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real32_3d,   &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real32_3d,                          &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
 !
 !--    64bit real output
        ELSEIF ( PRESENT( values_real64_0d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_real64_0d /), &
-                                  start = bounds_start - bounds_origin + 1,     &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_real64_0d /),                    &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_real64_1d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real64_1d,   &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real64_1d,                          &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_real64_2d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real64_2d,   &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real64_2d,                          &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_real64_3d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real64_3d,   &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_real64_3d,                          &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
 !
 !--    working-precision real output
        ELSEIF ( PRESENT( values_realwp_0d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_realwp_0d /), &
-                                  start = bounds_start - bounds_origin + 1,     &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, (/ values_realwp_0d /),                    &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_realwp_1d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_realwp_1d,   &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_realwp_1d,                          &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_realwp_2d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_realwp_2d,   &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_realwp_2d,                          &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSEIF ( PRESENT( values_realwp_3d ) )  THEN
-          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_realwp_3d,   &
-                                  start = bounds_start - bounds_origin + 1, &
+          nc_stat = NF90_PUT_VAR( file_id, variable_id, values_realwp_3d,                          &
+                                  start = bounds_start - bounds_origin + 1,                        &
                                   count = value_counts )
        ELSE
@@ -741,5 +742,5 @@
           nc_stat = NF90_NOERR
           WRITE( temp_string, '(": variable_id=",I6,", file_id=",I6)' ) variable_id, file_id
-          CALL internal_message( 'error', routine_name // &
+          CALL internal_message( 'error', routine_name //                                          &
                                  ': no output values given ' // TRIM( temp_string ) )
        ENDIF
@@ -761,5 +762,5 @@
              d = 1
              DO WHILE ( d <= ndims .AND. nc_stat == NF90_NOERR )
-                nc_stat = NF90_INQUIRE_DIMENSION( file_id, dimension_ids(d), &
+                nc_stat = NF90_INQUIRE_DIMENSION( file_id, dimension_ids(d),                       &
                                                   LEN=dimension_lengths(d) )
                 d = d + 1
@@ -767,13 +768,13 @@
 
              IF ( nc_stat == NF90_NOERR )  THEN
-                WRITE( temp_string, * )  TRIM( temp_string ) // '; given variable bounds: ' //  &
+                WRITE( temp_string, * )  TRIM( temp_string ) // '; given variable bounds: ' //     &
                    'start=', bounds_start, ', count=', value_counts, ', origin=', bounds_origin
-                CALL internal_message( 'error', routine_name //     &
+                CALL internal_message( 'error', routine_name //                                    &
                                        ': error while writing: ' // TRIM( temp_string ) )
              ELSE
 !
 !--             Error occured during NF90_INQUIRE_VARIABLE or NF90_INQUIRE_DIMENSION
-                CALL internal_message( 'error', routine_name //            &
-                                       ': error while accessing file: ' // &
+                CALL internal_message( 'error', routine_name //                                    &
+                                       ': error while accessing file: ' //                         &
                                         NF90_STRERROR( nc_stat ) )
              ENDIF
@@ -782,5 +783,5 @@
 !
 !--          Other NetCDF error
-             CALL internal_message( 'error', routine_name //     &
+             CALL internal_message( 'error', routine_name //                                       &
                                     ': error while writing: ' // NF90_STRERROR( nc_stat ) )
           ENDIF
@@ -810,5 +811,5 @@
 #if defined( __netcdf4 )
     WRITE( temp_string, * ) file_id
-    CALL internal_message( 'debug', routine_name // &
+    CALL internal_message( 'debug', routine_name //                                                &
                            ': close file (file_id=' // TRIM( temp_string ) // ')' )
 
@@ -818,5 +819,5 @@
     ELSE
        return_value = 1
-       CALL internal_message( 'error', routine_name // &
+       CALL internal_message( 'error', routine_name //                                             &
                               ': NetCDF error: ' // NF90_STRERROR( nc_stat ) )
     ENDIF
@@ -834,7 +835,7 @@
  FUNCTION get_netcdf_data_type( data_type ) RESULT( return_value )
 
+    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'get_netcdf_data_type'  !< name of this routine
+
     CHARACTER(LEN=*), INTENT(IN) ::  data_type  !< requested data type
-
-    CHARACTER(LEN=*), PARAMETER ::  routine_name = 'get_netcdf_data_type'  !< name of this routine
 
     INTEGER ::  return_value  !< netcdf data type
@@ -864,5 +865,5 @@
 
        CASE DEFAULT
-          CALL internal_message( 'error', routine_name // &
+          CALL internal_message( 'error', routine_name //                                          &
                                  ': data type unknown (' // TRIM( data_type ) // ')' )
           return_value = -1
@@ -875,6 +876,6 @@
 ! Description:
 ! ------------
-!> Message routine writing debug information into the debug file
-!> or creating the error message string.
+!> Message routine writing debug information into the debug file or creating the error message
+!> string.
 !--------------------------------------------------------------------------------------------------!
  SUBROUTINE internal_message( level, string )
Index: /palm/trunk/SOURCE/data_output_profiles.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_profiles.f90	(revision 4576)
+++ /palm/trunk/SOURCE/data_output_profiles.f90	(revision 4577)
@@ -1,20 +1,19 @@
 !> @file data_output_profiles.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/>.
+! 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-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
@@ -25,6 +24,9 @@
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4360 2020-01-07 11:25:50Z suehring
 ! Corrected "Former revisions" section
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! add variable description
@@ -37,17 +39,16 @@
 ! ------------
 !> Plot output of 1D-profiles for PROFIL
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE data_output_profiles
- 
-
-    USE control_parameters,                                                    &
-        ONLY:  average_count_pr, averaging_interval_pr, coupling_start_time,   &
-               dopr_n, dopr_time_count, normalizing_region,                    &
-               time_since_reference_point
-
-    USE cpulog,                                                                &
+
+
+    USE control_parameters,                                                                        &
+        ONLY:  average_count_pr, averaging_interval_pr, coupling_start_time,                       &
+               dopr_n, dopr_time_count, normalizing_region, time_since_reference_point
+
+    USE cpulog,                                                                                    &
         ONLY:  cpu_log, log_point
 
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  nzb, nzt
 
@@ -58,7 +59,7 @@
 #endif
 
-    USE netcdf_interface,                                                      &
-        ONLY:  id_set_pr, id_var_dopr, id_var_norm_dopr, id_var_time_pr,       &
-               nc_stat, netcdf_handle_error, output_for_t0
+    USE netcdf_interface,                                                                          &
+        ONLY:  id_set_pr, id_var_dopr, id_var_norm_dopr, id_var_time_pr, nc_stat,                  &
+               netcdf_handle_error, output_for_t0
 
     USE pegrid
@@ -66,5 +67,5 @@
     USE profil_parameter
 
-    USE statistics,                                                            &
+    USE statistics,                                                                                &
         ONLY:  flow_statistics_called, hom, hom_sum, pr_palm, statistic_regions
 
@@ -92,11 +93,10 @@
        ELSE
 !
-!--       This case may happen if dt_dopr is changed in the 
-!--       runtime_parameters-list of a restart run
+!--       This case may happen if dt_dopr is changed in the runtime_parameters-list of a restart run
           RETURN
        ENDIF
     ENDIF
 
-    
+
     IF ( myid == 0 )  THEN
 
@@ -115,18 +115,17 @@
 !--    Output of initial profiles
        IF ( dopr_time_count == 1 )  THEN
-        
-          IF ( .NOT. output_for_t0 ) THEN 
-
-#if defined( __netcdf )          
-!
-!--          Store initial time to time axis, but only if an output
-!--          is required for at least one of the profiles. The initial time
-!--          is either 0, or, in case of a prerun for coupled atmosphere-ocean
-!--          runs, has a negative value
+
+          IF ( .NOT. output_for_t0 ) THEN
+
+#if defined( __netcdf )
+!
+!--          Store initial time to time axis, but only if an output is required for at least one of
+!--          the profiles. The initial time is either 0, or, in case of a prerun for coupled
+!--          atmosphere-ocean runs, has a negative value
              DO  i = 1, dopr_n
                 IF ( dopr_initial_index(i) /= 0 )  THEN
-                   nc_stat = NF90_PUT_VAR( id_set_pr, id_var_time_pr,          &
-                                        (/ -coupling_start_time /),            &
-                                        start = (/ 1 /), count = (/ 1 /) )
+                   nc_stat = NF90_PUT_VAR( id_set_pr, id_var_time_pr,                              &
+                                           (/ -coupling_start_time /),                             &
+                                           start = (/ 1 /), count = (/ 1 /) )
                    CALL netcdf_handle_error( 'data_output_profiles', 329 )
                    output_for_t0 = .TRUE.
@@ -138,38 +137,38 @@
 !--          Store normalization factors
              nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(1), & ! wpt0
-                                  (/ hom_sum(nzb,18,normalizing_region) /), &
+                                     (/ hom_sum(nzb,18,normalizing_region) /),                     &
                                      start = (/ 1 /), count = (/ 1 /) )
              CALL netcdf_handle_error( 'data_output_profiles', 330 )
 
              nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(2), & ! ws2
-                        (/ hom_sum(nzb+8,pr_palm,normalizing_region)**2 /), &
+                                     (/ hom_sum(nzb+8,pr_palm,normalizing_region)**2 /),           &
                                      start = (/ 1 /), count = (/ 1 /) )
              CALL netcdf_handle_error( 'data_output_profiles', 331 )
              nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(3), & ! tsw2
-                        (/ hom_sum(nzb+3,pr_palm,normalizing_region)**2 /), &
-                                  start = (/ 1 /), count = (/ 1 /) )
+                                     (/ hom_sum(nzb+3,pr_palm,normalizing_region)**2 /),           &
+                                      start = (/ 1 /), count = (/ 1 /) )
              CALL netcdf_handle_error( 'data_output_profiles', 332 )
              nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(4), & ! ws3
-                        (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 /), &
+                                     (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 /),           &
                                      start = (/ 1 /), count = (/ 1 /) )
              CALL netcdf_handle_error( 'data_output_profiles', 333 )
 
-             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), &!ws2tsw
-                        (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 *   &
-                           hom_sum(nzb+3,pr_palm,normalizing_region)    /), &
+             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), & ! ws2tsw
+                                     (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 *             &
+                                        hom_sum(nzb+3,pr_palm,normalizing_region)    /),           &
                                      start = (/ 1 /), count = (/ 1 /) )
              CALL netcdf_handle_error( 'data_output_profiles', 334 )
 
-             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(6), &!wstsw2
-                        (/ hom_sum(nzb+8,pr_palm,normalizing_region) *      &
-                           hom_sum(nzb+3,pr_palm,normalizing_region)**2 /), &
+             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(6), & ! wstsw2
+                                     (/ hom_sum(nzb+8,pr_palm,normalizing_region) *                &
+                                        hom_sum(nzb+3,pr_palm,normalizing_region)**2 /),           &
                                      start = (/ 1 /), count = (/ 1 /) )
              CALL netcdf_handle_error( 'data_output_profiles', 335 )
 
              nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(7), & ! z_i
-                           (/ hom_sum(nzb+6,pr_palm,normalizing_region) /), &
+                                     (/ hom_sum(nzb+6,pr_palm,normalizing_region) /),              &
                                      start = (/ 1 /), count = (/ 1 /) )
              CALL netcdf_handle_error( 'data_output_profiles', 336 )
-             
+
 #endif
 !
@@ -186,7 +185,7 @@
 !
 !--                   Write data to netcdf file
-                      nc_stat = NF90_PUT_VAR( id_set_pr, id_var_dopr(i,sr),    &
-                                    hom(nzb:nzt+1,1,dopr_initial_index(i),sr), &
-                                              start = (/ 1, 1 /),              &
+                      nc_stat = NF90_PUT_VAR( id_set_pr, id_var_dopr(i,sr),                        &
+                                              hom(nzb:nzt+1,1,dopr_initial_index(i),sr),           &
+                                              start = (/ 1, 1 /),                                  &
                                               count = (/ nzt-nzb+2, 1 /) )
                       CALL netcdf_handle_error( 'data_output_profiles', 337 )
@@ -210,7 +209,7 @@
 !
 !--    Store time to time axis
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_time_pr,        &
-                               (/ time_since_reference_point /), &
-                               start = (/ dopr_time_count /),    &
+       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_time_pr,                                          &
+                               (/ time_since_reference_point /),                                   &
+                               start = (/ dopr_time_count /),                                      &
                                count = (/ 1 /) )
        CALL netcdf_handle_error( 'data_output_profiles', 338 )
@@ -219,44 +218,44 @@
 !--    Store normalization factors
        nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(1), &  ! wpt0
-                               (/ hom_sum(nzb,18,normalizing_region) /), &
+                               (/ hom_sum(nzb,18,normalizing_region) /),                           &
+                               start = (/ dopr_time_count /),                                      &
+                               count = (/ 1 /) )
+       CALL netcdf_handle_error( 'data_output_profiles', 339 )
+
+       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(2), &  ! ws2
+                               (/ hom_sum(nzb+8,pr_palm,normalizing_region)**2 /),                 &
+                               start = (/ dopr_time_count /),                                      &
+                               count = (/ 1 /) )
+       CALL netcdf_handle_error( 'data_output_profiles', 340 )
+
+       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(3), &  ! tsw2
+                               (/ hom_sum(nzb+3,pr_palm,normalizing_region)**2 /),                 &
+                               start = (/ dopr_time_count /),                                      &
+                               count = (/ 1 /) )
+       CALL netcdf_handle_error( 'data_output_profiles', 341 )
+
+       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(4), &  ! ws3
+                               (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 /),                 &
+                               start = (/ dopr_time_count /),                                      &
+                               count = (/ 1 /) )
+       CALL netcdf_handle_error( 'data_output_profiles', 342 )
+
+       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), &  ! ws2tsw
+                               (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 *                   &
+                                  hom_sum(nzb+3,pr_palm,normalizing_region) /),                    &
                                start = (/ dopr_time_count /),               &
                                count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 339 )
-
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(2), &  ! ws2
-                     (/ hom_sum(nzb+8,pr_palm,normalizing_region)**2 /), &
-                               start = (/ dopr_time_count /),               &
-                               count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 340 )
-
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(3), &  ! tsw2
-                     (/ hom_sum(nzb+3,pr_palm,normalizing_region)**2 /), &
-                               start = (/ dopr_time_count /),               &
-                               count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 341 )
-
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(4), &  ! ws3
-                     (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 /), &
-                               start = (/ dopr_time_count /),               &
-                               count = (/ 1 /) )
-       CALL netcdf_handle_error( 'data_output_profiles', 342 )
-
-       nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(5), &  ! ws2tsw
-                     (/ hom_sum(nzb+8,pr_palm,normalizing_region)**3 *   &
-                        hom_sum(nzb+3,pr_palm,normalizing_region)    /), &
-                               start = (/ dopr_time_count /),               &
-                               count = (/ 1 /) )
        CALL netcdf_handle_error( 'data_output_profiles', 343 )
 
        nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(6), &  ! wstsw2
-                     (/ hom_sum(nzb+8,pr_palm,normalizing_region) *      &
-                        hom_sum(nzb+3,pr_palm,normalizing_region)**2 /), &
-                               start = (/ dopr_time_count /),               &
+                               (/ hom_sum(nzb+8,pr_palm,normalizing_region) *                      &
+                                  hom_sum(nzb+3,pr_palm,normalizing_region)**2 /),                 &
+                               start = (/ dopr_time_count /),                                      &
                                count = (/ 1 /) )
        CALL netcdf_handle_error( 'data_output_profiles', 344 )
 
        nc_stat = NF90_PUT_VAR( id_set_pr, id_var_norm_dopr(7), &  ! z_i
-                        (/ hom_sum(nzb+6,pr_palm,normalizing_region) /), &
-                               start = (/ dopr_time_count /),               &
+                               (/ hom_sum(nzb+6,pr_palm,normalizing_region) /),                    &
+                               start = (/ dopr_time_count /),                                      &
                                count = (/ 1 /) )
        CALL netcdf_handle_error( 'data_output_profiles', 345 )
@@ -274,7 +273,7 @@
 !
 !--          Write data to netcdf file
-             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_dopr(i,sr),          &
-                                     hom_sum(nzb:nzt+1,dopr_index(i),sr),&
-                                     start = (/ 1, dopr_time_count /),      &
+             nc_stat = NF90_PUT_VAR( id_set_pr, id_var_dopr(i,sr),                                 &
+                                     hom_sum(nzb:nzt+1,dopr_index(i),sr),                          &
+                                     start = (/ 1, dopr_time_count /),                             &
                                      count = (/ nzt-nzb+2, 1 /) )
              CALL netcdf_handle_error( 'data_output_profiles', 346 )
Index: /palm/trunk/SOURCE/data_output_spectra.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_spectra.f90	(revision 4576)
+++ /palm/trunk/SOURCE/data_output_spectra.f90	(revision 4577)
@@ -1,20 +1,19 @@
 !> @file data_output_spectra.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/>.
+! 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-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
@@ -25,6 +24,9 @@
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4360 2020-01-07 11:25:50Z suehring
 ! Corrected "Former revisions" section
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! variables documented
@@ -38,12 +40,12 @@
 !> Writing spectra data on file, using a special format which allows
 !> plotting of these data with PROFIL-graphic-software
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE data_output_spectra
- 
+
 #if defined( __netcdf )
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  message_string, time_since_reference_point
 
-    USE cpulog,                                                                &
+    USE cpulog,                                                                                    &
         ONLY:  cpu_log, log_point
 
@@ -52,13 +54,12 @@
     USE NETCDF
 
-    USE netcdf_interface,                                                      &
+    USE netcdf_interface,                                                                          &
         ONLY:  id_set_sp, id_var_time_sp, nc_stat, netcdf_handle_error
 
     USE pegrid
 
-    USE spectra_mod,                                                           &
-        ONLY:  average_count_sp, averaging_interval_sp, comp_spectra_level,    &
-               data_output_sp, dosp_time_count, spectra_direction, spectrum_x, &
-               spectrum_y
+    USE spectra_mod,                                                                               &
+        ONLY:  average_count_sp, averaging_interval_sp, comp_spectra_level, data_output_sp,        &
+               dosp_time_count, spectra_direction, spectrum_x, spectrum_y
 
 
@@ -67,5 +68,5 @@
     INTEGER(iwp) ::  m       !< running index over spectra output
     INTEGER(iwp) ::  pr      !< index used to assign default quantities to data output
-    
+
     CALL cpu_log( log_point(31), 'data_output_spectra', 'start' )
 
@@ -88,6 +89,6 @@
 !
 !--    Update the spectra time axis
-       nc_stat = NF90_PUT_VAR( id_set_sp, id_var_time_sp,        &
-                               (/ time_since_reference_point /), &
+       nc_stat = NF90_PUT_VAR( id_set_sp, id_var_time_sp,                                          &
+                               (/ time_since_reference_point /),                                   &
                                start = (/ dosp_time_count /), count = (/ 1 /) )
        CALL netcdf_handle_error( 'data_output_spectra', 47 )
@@ -96,6 +97,6 @@
 !--    If necessary, calculate time average and reset average counter
        IF ( average_count_sp == 0 )  THEN
-           message_string = 'no spectra data available'
-           CALL message( 'data_output_spectra', 'PA0186', 0, 0, 0, 6, 0 )
+          message_string = 'no spectra data available'
+          CALL message( 'data_output_spectra', 'PA0186', 0, 0, 0, 6, 0 )
        ENDIF
        IF ( average_count_sp /= 1 )  THEN
@@ -132,8 +133,7 @@
              CASE DEFAULT
 !
-!--             The DEFAULT case is reached either if the parameter 
-!--             data_output_sp(m) contains a wrong character string or if the 
-!--             user has coded a special case in the user interface. There, the 
-!--             subroutine user_spectra checks which of these two conditions 
+!--             The DEFAULT case is reached either if the parameter data_output_sp(m) contains a
+!--             wrong character string or if the user has coded a special case in the user
+!--             interface. There, the subroutine user_spectra checks which of these two conditions
 !--             applies.
                 CALL user_spectra( 'data_output', m, pr )
@@ -175,19 +175,19 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> @todo Missing subroutine description.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE output_spectra_netcdf( nsp, direction )
 #if defined( __netcdf )
 
-    USE basic_constants_and_equations_mod,                                     &
+    USE basic_constants_and_equations_mod,                                                         &
         ONLY:  pi
 
-    USE grid_variables,                                                        &
+    USE grid_variables,                                                                            &
         ONLY:  dx, dy
 
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  nx, ny
 
@@ -196,9 +196,8 @@
     USE NETCDF
 
-    USE netcdf_interface,                                                      &
-        ONLY:  id_set_sp, id_var_dospx, id_var_dospy, nc_stat,                 &
-               netcdf_handle_error
-
-    USE spectra_mod,                                                           &
+    USE netcdf_interface,                                                                          &
+        ONLY:  id_set_sp, id_var_dospx, id_var_dospy, nc_stat, netcdf_handle_error
+
+    USE spectra_mod,                                                                               &
         ONLY:  dosp_time_count, n_sp_x, n_sp_y, spectrum_x, spectrum_y
 
@@ -228,6 +227,6 @@
           ENDDO
 
-          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospx(nsp), netcdf_data_x, &
-                                  start = (/ 1, k, dosp_time_count /), &
+          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospx(nsp), netcdf_data_x,                     &
+                                  start = (/ 1, k, dosp_time_count /),                             &
                                   count = (/ nx/2, 1, 1 /) )
           CALL netcdf_handle_error( 'data_output_spectra', 348 )
@@ -246,6 +245,6 @@
           ENDDO
 
-          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospy(nsp), netcdf_data_y, &
-                                  start = (/ 1, k, dosp_time_count /), &
+          nc_stat = NF90_PUT_VAR( id_set_sp, id_var_dospy(nsp), netcdf_data_y,                     &
+                                  start = (/ 1, k, dosp_time_count /),                             &
                                   count = (/ ny/2, 1, 1 /) )
           CALL netcdf_handle_error( 'data_output_spectra', 349 )
Index: /palm/trunk/SOURCE/surface_data_output_mod.f90
===================================================================
--- /palm/trunk/SOURCE/surface_data_output_mod.f90	(revision 4576)
+++ /palm/trunk/SOURCE/surface_data_output_mod.f90	(revision 4577)
@@ -1,23 +1,23 @@
 !> @file surface_data_output_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/>.
+! 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-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+!
 !
 ! Current revisions:
-! ------------------
+! -----------------
 ! 
 ! 
@@ -25,19 +25,22 @@
 ! -----------------
 ! $Id$
-! Added surface albedo and emissivity, which are defined using
-! the tile approach
-! 
+! File re-formatted to follow the PALM coding standard
+!
+!
+! 4547 2020-05-27 09:05:24Z moh.hefny
+! Added surface albedo and emissivity, which are defined using the tile approach
+!
 ! 4535 2020-05-15 12:07:23Z raasch
-! bugfix for restart data format query
-! 
+! Bugfix for restart data format query
+!
 ! 4535 2020-05-15 12:07:23Z raasch
-! bugfix for restart data format query
-! 
+! Bugfix for restart data format query
+!
 ! 4517 2020-05-03 14:29:30Z raasch
-! added restart with MPI-IO for reading local arrays
-! 
+! Added restart with MPI-IO for reading local arrays
+!
 ! 4502 2020-04-17 16:14:16Z schwenkel
 ! Implementation of ice microphysics
-! 
+!
 ! 4500 2020-04-17 10:12:45Z suehring
 ! - Correct output of ground/wall heat flux at USM surfaces
@@ -45,28 +48,27 @@
 !
 ! 4495 2020-04-13 20:11:20Z raasch
-! restart data handling with MPI-IO added
-! 
+! Restart data handling with MPI-IO added
+!
 ! 4444 2020-03-05 15:59:50Z raasch
-! bugfix: cpp-directives for serial mode added
-! 
+! Bugfix: cpp-directives for serial mode added
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Fix wrongly declared nc_stat variable in surface_data_output_mod
-! 
+!
 ! 4205 2019-08-30 13:25:00Z suehring
 ! - Correct x,y-coordinates of vertical surfaces in netcdf output
 ! - Change definition of azimuth angle, reference is north 0 degree
-! - zenith angle is always defined, also for vertical surfaces where it is 
-!   90 degree, while azimuth angle is only defined for vertical surfaces, not
-!   for horizontal ones
-! 
+! - Zenith angle is always defined, also for vertical surfaces where it is 90 degree, while azimuth
+!   angle is only defined for vertical surfaces, not for horizontal ones
+!
 ! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
-! 
+!
 ! 4129 2019-07-31 12:56:07Z gronemeier
-! - bugfix: corrected loop over horizontal default surfaces
-! - change default setting of to_vtk and to_netcdf
+! - Bugfix: corrected loop over horizontal default surfaces
+! - Change default setting of to_vtk and to_netcdf
 !
 ! 4029 2019-06-14 14:04:35Z raasch
-! netcdf variable NF90_NOFILL is used as argument instead of "1" in call to NF90_DEF_VAR_FILL
+! Netcdf variable NF90_NOFILL is used as argument instead of "1" in call to NF90_DEF_VAR_FILL
 !
 ! 3881 2019-04-10 09:31:22Z suehring
@@ -77,9 +79,9 @@
 !
 ! 3766 2019-02-26 16:23:41Z raasch
-! bugfix in surface_data_output_rrd_local (variable k removed)
+! Bugfix in surface_data_output_rrd_local (variable k removed)
 !
 ! 3762 2019-02-25 16:54:16Z suehring
-! Remove unused variables and add preprocessor directives for variables that
-! are used only when netcdf4 is defined
+! Remove unused variables and add preprocessor directives for variables that are used only when
+! netcdf4 is defined
 !
 ! 3745 2019-02-15 18:57:56Z suehring
@@ -87,10 +89,9 @@
 !
 ! 3744 2019-02-15 18:38:58Z suehring
-! Add azimuth and zenith to output file; set long-name attributes;
-! clean-up coding layout
+! Add azimuth and zenith to output file; set long-name attributes; clean-up coding layout
 !
 ! 3735 2019-02-12 09:52:40Z suehring
-! - Split initialization into initialization of arrays and further initialization
-!   in order to enable reading of restart data.
+! - Split initialization into initialization of arrays and further initialization in order to enable
+!   reading of restart data.
 ! - Consider restarts in surface data averaging.
 ! - Correct error message numbers
@@ -115,4 +116,5 @@
 ! @author Klaus Ketelsen, Matthias Suehring, Tobias Gronemeier
 !
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
@@ -120,5 +122,5 @@
 !>
 !> @todo Create namelist file for post-processing tool.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 
 MODULE surface_data_output_mod
@@ -134,14 +136,25 @@
 
    USE control_parameters,                                                                         &
-       ONLY:  coupling_char, data_output_during_spinup, end_time,                                  &
+       ONLY:  coupling_char,                                                                       &
+              data_output_during_spinup,                                                           &
+              end_time,                                                                            &
               message_string,                                                                      &
-              restart_data_format_output, run_description_header, simulated_time_at_begin,         &
-              spinup_time, surface_output
-
-   USE grid_variables,                                                         &
-       ONLY: dx,dy
-
-   USE indices,                                                                &
-       ONLY: nxl, nxr, nys, nyn, nzb, nzt
+              restart_data_format_output,                                                          &
+              run_description_header,                                                              &
+              simulated_time_at_begin,                                                             &
+              spinup_time,                                                                         &
+              surface_output
+
+   USE grid_variables,                                                                             &
+       ONLY: dx,                                                                                   &
+             dy
+
+   USE indices,                                                                                    &
+       ONLY: nxl,                                                                                  &
+             nxr,                                                                                  &
+             nys,                                                                                  &
+             nyn,                                                                                  &
+             nzb,                                                                                  &
+             nzt
 
 #if defined( __netcdf )
@@ -149,16 +162,23 @@
 #endif
 
-   USE netcdf_data_input_mod,                                                  &
+   USE netcdf_data_input_mod,                                                                      &
        ONLY:  init_model
 
-   USE netcdf_interface,                                                       &
-       ONLY:  nc_stat, netcdf_create_att, netcdf_create_dim,                   &
-              netcdf_create_file, netcdf_create_global_atts,                   &
-              netcdf_create_var, netcdf_data_format, netcdf_handle_error
+   USE netcdf_interface,                                                                           &
+       ONLY:  nc_stat,                                                                             &
+              netcdf_create_att,                                                                   &
+              netcdf_create_dim,                                                                   &
+              netcdf_create_file,                                                                  &
+              netcdf_create_global_atts,                                                           &
+              netcdf_create_var,                                                                   &
+              netcdf_data_format,                                                                  &
+              netcdf_handle_error
 
    USE pegrid
 
    USE restart_data_mpi_io_mod,                                                                    &
-       ONLY:  rd_mpi_io_check_array, rrd_mpi_io, wrd_mpi_io
+       ONLY:  rd_mpi_io_check_array,                                                               &
+              rrd_mpi_io,                                                                          &
+              wrd_mpi_io
 
    USE surface_mod,                                                                                &
@@ -182,63 +202,64 @@
       INTEGER(iwp) ::  npoints_total  !< total number of points / vertices which define a surface element
 
-      INTEGER(iwp), DIMENSION(:), ALLOCATABLE   ::  s        !< coordinate for NetCDF output, number of the surface element
-
-      REAL(wp) ::  fillvalue = -9999.0_wp !< fillvalue for surface elements which are not defined
-
-      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  azimuth  !< azimuth orientation coordinate for NetCDF output
-      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  es_utm   !< E-UTM coordinate for NetCDF output
-      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  ns_utm   !< E-UTM coordinate for NetCDF output
-      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  xs       !< x-coordinate for NetCDF output
-      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  ys       !< y-coordinate for NetCDF output
-      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  zs       !< z-coordinate for NetCDF output
-      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  zenith   !< zenith orientation coordinate for NetCDF output
-      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  var_out  !< output variables
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  var_av   !< variables used for averaging
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  points   !< points  / vertices of a surface element
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  polygons !< polygon data of a surface element
+      INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  s  !< coordinate for NetCDF output, number of the surface element
+
+      REAL(wp) ::  fillvalue = -9999.0_wp  !< fillvalue for surface elements which are not defined
+
+      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  azimuth   !< azimuth orientation coordinate for NetCDF output
+      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  es_utm    !< E-UTM coordinate for NetCDF output
+      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  ns_utm    !< E-UTM coordinate for NetCDF output
+      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  xs        !< x-coordinate for NetCDF output
+      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  ys        !< y-coordinate for NetCDF output
+      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  zs        !< z-coordinate for NetCDF output
+      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  zenith    !< zenith orientation coordinate for NetCDF output
+      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  var_out   !< output variables
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  var_av    !< variables used for averaging
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  points    !< points  / vertices of a surface element
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  polygons  !< polygon data of a surface element
    END TYPE surf_out
 
-   CHARACTER(LEN=100), DIMENSION(300)       ::  data_output_surf = ' '  !< namelist variable which describes the output variables
-   CHARACTER(LEN=100), DIMENSION(0:1,300)   ::  dosurf = ' '            !< internal variable which describes the output variables
-                                                                        !<  and separates averaged from non-averaged output
-   CHARACTER(LEN=100), DIMENSION(0:1,300)   ::  dosurf_unit = ' '       !< internal variable which holds the unit of the given output variable
-
-   INTEGER(iwp) ::  average_count_surf = 0   !< number of ensemble members used for averaging
-   INTEGER(iwp) ::  dosurf_no(0:1) = 0       !< number of surface output quantities
+   CHARACTER(LEN=100), DIMENSION(300)     ::  data_output_surf = ' '  !< namelist variable which describes the output variables
+   CHARACTER(LEN=100), DIMENSION(0:1,300) ::  dosurf = ' '            !< internal variable which describes the output variables
+                                                                      !< and separates averaged from non-averaged output
+   CHARACTER(LEN=100), DIMENSION(0:1,300) ::  dosurf_unit = ' '       !< internal variable which holds the unit of the given output
+                                                                      !< variable
+
+   INTEGER(iwp) ::  average_count_surf = 0  !< number of ensemble members used for averaging
+   INTEGER(iwp) ::  dosurf_no(0:1)     = 0  !< number of surface output quantities
 #if defined( __netcdf4_parallel )
-   INTEGER(iwp) ::  oldmode                  !< save old set-fill-mode of netcdf file (not needed, but required for routine call)
-
-   INTEGER(iwp), DIMENSION(0:1) ::  dosurf_time_count = 0 !< count of output time steps
-   INTEGER(iwp), DIMENSION(0:1) ::  id_dim_s_surf         !< netcdf ID for dimension s
-   INTEGER(iwp), DIMENSION(0:1) ::  id_dim_time_surf      !< netcdf ID for dimension time
-   INTEGER(iwp), DIMENSION(0:1) ::  id_set_surf           !< netcdf ID for file
-   INTEGER(iwp), DIMENSION(0:1) ::  id_var_azimuth_surf   !< netcdf ID for variable azimuth
-   INTEGER(iwp), DIMENSION(0:1) ::  id_var_etum_surf      !< netcdf ID for variable Es_UTM
-   INTEGER(iwp), DIMENSION(0:1) ::  id_var_nutm_surf      !< netcdf ID for variable Ns_UTM
-   INTEGER(iwp), DIMENSION(0:1) ::  id_var_time_surf      !< netcdf ID for variable time
-   INTEGER(iwp), DIMENSION(0:1) ::  id_var_s_surf         !< netcdf ID for variable s
-   INTEGER(iwp), DIMENSION(0:1) ::  id_var_xs_surf        !< netcdf ID for variable xs
-   INTEGER(iwp), DIMENSION(0:1) ::  id_var_ys_surf        !< netcdf ID for variable ys
-   INTEGER(iwp), DIMENSION(0:1) ::  id_var_zenith_surf    !< netcdf ID for variable zenith
-   INTEGER(iwp), DIMENSION(0:1) ::  id_var_zs_surf        !< netcdf ID for variable zs
-   INTEGER(iwp), DIMENSION(0:1) ::  ntdim_surf            !< number of output time steps
-
-   INTEGER(iwp), DIMENSION(0:1,300) ::  id_var_dosurf     !< netcdf ID for output variables
+   INTEGER(iwp) ::  oldmode                 !< save old set-fill-mode of netcdf file (not needed, but required for routine call)
+
+   INTEGER(iwp), DIMENSION(0:1) ::  dosurf_time_count = 0  !< count of output time steps
+   INTEGER(iwp), DIMENSION(0:1) ::  id_dim_s_surf          !< netcdf ID for dimension s
+   INTEGER(iwp), DIMENSION(0:1) ::  id_dim_time_surf       !< netcdf ID for dimension time
+   INTEGER(iwp), DIMENSION(0:1) ::  id_set_surf            !< netcdf ID for file
+   INTEGER(iwp), DIMENSION(0:1) ::  id_var_azimuth_surf    !< netcdf ID for variable azimuth
+   INTEGER(iwp), DIMENSION(0:1) ::  id_var_etum_surf       !< netcdf ID for variable Es_UTM
+   INTEGER(iwp), DIMENSION(0:1) ::  id_var_nutm_surf       !< netcdf ID for variable Ns_UTM
+   INTEGER(iwp), DIMENSION(0:1) ::  id_var_time_surf       !< netcdf ID for variable time
+   INTEGER(iwp), DIMENSION(0:1) ::  id_var_s_surf          !< netcdf ID for variable s
+   INTEGER(iwp), DIMENSION(0:1) ::  id_var_xs_surf         !< netcdf ID for variable xs
+   INTEGER(iwp), DIMENSION(0:1) ::  id_var_ys_surf         !< netcdf ID for variable ys
+   INTEGER(iwp), DIMENSION(0:1) ::  id_var_zenith_surf     !< netcdf ID for variable zenith
+   INTEGER(iwp), DIMENSION(0:1) ::  id_var_zs_surf         !< netcdf ID for variable zs
+   INTEGER(iwp), DIMENSION(0:1) ::  ntdim_surf             !< number of output time steps
+
+   INTEGER(iwp), DIMENSION(0:1,300) ::  id_var_dosurf      !< netcdf ID for output variables
 #endif
 
-   LOGICAL :: first_output(0:1) = .FALSE.                 !< true if first output was already called
-   LOGICAL :: to_netcdf = .FALSE.                         !< flag indicating parallel NetCDF output
-   LOGICAL :: to_vtk = .FALSE.                            !< flag indicating binary surface-data output that can be further
-                                                          !< processed to VTK format
-
-   REAL(wp) ::  averaging_interval_surf  = 9999999.9_wp   !< averaging interval
-   REAL(wp) ::  dt_dosurf = 9999999.9_wp                  !< time interval for instantaneous data output
-   REAL(wp) ::  dt_dosurf_av = 9999999.9_wp               !< time interval for averaged data output
-   REAL(wp) ::  skip_time_dosurf = 0.0_wp                 !< skip time for instantaneous data output
-   REAL(wp) ::  skip_time_dosurf_av = 0.0_wp              !< skip time for averaged data output
-   REAL(wp) ::  time_dosurf = 0.0_wp                      !< internal counter variable to check for instantaneous data output
-   REAL(wp) ::  time_dosurf_av = 0.0_wp                   !< internal counter variable to check for averaged data output
-
-   TYPE(surf_out) ::  surfaces      !< variable which contains all required output information
+   LOGICAL ::  first_output(0:1) = .FALSE.  !< true if first output was already called
+   LOGICAL ::  to_netcdf         = .FALSE.  !< flag indicating parallel NetCDF output
+   LOGICAL ::  to_vtk            = .FALSE.  !< flag indicating binary surface-data output that can be further
+                                            !< processed to VTK format
+
+   REAL(wp) ::  averaging_interval_surf  = 9999999.9_wp  !< averaging interval
+   REAL(wp) ::  dt_dosurf                = 9999999.9_wp  !< time interval for instantaneous data output
+   REAL(wp) ::  dt_dosurf_av             = 9999999.9_wp  !< time interval for averaged data output
+   REAL(wp) ::  skip_time_dosurf         = 0.0_wp        !< skip time for instantaneous data output
+   REAL(wp) ::  skip_time_dosurf_av      = 0.0_wp        !< skip time for averaged data output
+   REAL(wp) ::  time_dosurf              = 0.0_wp        !< internal counter variable to check for instantaneous data output
+   REAL(wp) ::  time_dosurf_av           = 0.0_wp        !< internal counter variable to check for averaged data output
+
+   TYPE(surf_out) ::  surfaces  !< variable which contains all required output information
 
    SAVE
@@ -304,5286 +325,4384 @@
 !
 !--Public subroutines
-   PUBLIC surface_data_output, surface_data_output_averaging,                  &
-          surface_data_output_check_parameters, surface_data_output_init,      &
-          surface_data_output_init_arrays, surface_data_output_last_action,    &
-          surface_data_output_parin, surface_data_output_rrd_global,           &
-          surface_data_output_rrd_local, surface_data_output_wrd_local,        &
+   PUBLIC surface_data_output,                                                                     &
+          surface_data_output_averaging,                                                           &
+          surface_data_output_check_parameters,                                                    &
+          surface_data_output_init,                                                                &
+          surface_data_output_init_arrays,                                                         &
+          surface_data_output_last_action,                                                         &
+          surface_data_output_parin,                                                               &
+          surface_data_output_rrd_global,                                                          &
+          surface_data_output_rrd_local,                                                           &
+          surface_data_output_wrd_local,                                                           &
           surface_data_output_wrd_global
 !
 !--Public variables
-   PUBLIC average_count_surf, averaging_interval_surf, dt_dosurf, dt_dosurf_av,&
-          skip_time_dosurf, skip_time_dosurf_av, time_dosurf, time_dosurf_av
+   PUBLIC average_count_surf,                                                                      &
+          averaging_interval_surf,                                                                 &
+          dt_dosurf,                                                                               &
+          dt_dosurf_av,                                                                            &
+          skip_time_dosurf,                                                                        &
+          skip_time_dosurf_av,                                                                     &
+          time_dosurf,                                                                             &
+          time_dosurf_av
 
  CONTAINS
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> This routine counts the number of surfaces on each core and allocates
-!> arrays.
-!------------------------------------------------------------------------------!
-   SUBROUTINE surface_data_output_init_arrays
-
-      IMPLICIT NONE
-
-!
-!--   Determine the number of surface elements on subdomain
-      surfaces%ns = surf_def_h(0)%ns + surf_lsm_h%ns + surf_usm_h%ns           & !horizontal upward-facing
-                  + surf_def_h(1)%ns                                           & !horizontal downard-facing
-                  + surf_def_v(0)%ns + surf_lsm_v(0)%ns + surf_usm_v(0)%ns     & !northward-facing
-                  + surf_def_v(1)%ns + surf_lsm_v(1)%ns + surf_usm_v(1)%ns     & !southward-facing
-                  + surf_def_v(2)%ns + surf_lsm_v(2)%ns + surf_usm_v(2)%ns     & !westward-facing
-                  + surf_def_v(3)%ns + surf_lsm_v(3)%ns + surf_usm_v(3)%ns       !eastward-facing
-!
-!--    Determine the total number of surfaces in the model domain
+!> This routine counts the number of surfaces on each core and allocates arrays.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_init_arrays
+
+    IMPLICIT NONE
+
+!
+!-- Determine the number of surface elements on subdomain
+    surfaces%ns = surf_def_h(0)%ns + surf_lsm_h%ns + surf_usm_h%ns           & !horizontal upward-facing
+                + surf_def_h(1)%ns                                           & !horizontal downard-facing
+                + surf_def_v(0)%ns + surf_lsm_v(0)%ns + surf_usm_v(0)%ns     & !northward-facing
+                + surf_def_v(1)%ns + surf_lsm_v(1)%ns + surf_usm_v(1)%ns     & !southward-facing
+                + surf_def_v(2)%ns + surf_lsm_v(2)%ns + surf_usm_v(2)%ns     & !westward-facing
+                + surf_def_v(3)%ns + surf_lsm_v(3)%ns + surf_usm_v(3)%ns       !eastward-facing
+!
+!--  Determine the total number of surfaces in the model domain
 #if defined( __parallel )
-       CALL MPI_ALLREDUCE( surfaces%ns, surfaces%ns_total, 1,                  &
-                           MPI_INTEGER, MPI_SUM, comm2d, ierr )
+     CALL MPI_ALLREDUCE( surfaces%ns, surfaces%ns_total, 1, MPI_INTEGER, MPI_SUM, comm2d, ierr )
 #else
-       surfaces%ns_total = surfaces%ns
+     surfaces%ns_total = surfaces%ns
 #endif
 !
-!--   Allocate output variable and set to _FillValue attribute
-      ALLOCATE ( surfaces%var_out(1:surfaces%ns) )
-      surfaces%var_out = surfaces%fillvalue
-!
-!--   If there is an output of time average output variables, allocate the
-!--   required array.
-      IF ( dosurf_no(1) > 0 )  THEN
-         ALLOCATE ( surfaces%var_av(1:surfaces%ns,1:dosurf_no(1)) )
-         surfaces%var_av = 0.0_wp
-      ENDIF
-
-   END SUBROUTINE surface_data_output_init_arrays
-
-
-!------------------------------------------------------------------------------!
+!-- Allocate output variable and set to _FillValue attribute
+    ALLOCATE ( surfaces%var_out(1:surfaces%ns) )
+    surfaces%var_out = surfaces%fillvalue
+!
+!-- If there is an output of time average output variables, allocate the required array.
+    IF ( dosurf_no(1) > 0 )  THEN
+       ALLOCATE ( surfaces%var_av(1:surfaces%ns,1:dosurf_no(1)) )
+       surfaces%var_av = 0.0_wp
+    ENDIF
+
+ END SUBROUTINE surface_data_output_init_arrays
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Initialization surface-data output data structure: calculation of vertices
-!> and polygon data for the surface elements, allocation of required arrays.
-!------------------------------------------------------------------------------!
-   SUBROUTINE surface_data_output_init
-
-      IMPLICIT NONE
+!> Initialization surface-data output data structure: calculation of vertices and polygon data for
+!> the surface elements, allocation of required arrays.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_init
+
+    IMPLICIT NONE
 
 #if defined( __netcdf4_parallel )
-      CHARACTER (LEN=100)  :: filename            !< name of output file
-      CHARACTER (LEN=80)   ::  time_average_text  !< string written to file attribute time_avg
-      CHARACTER (LEN=4000) ::  var_list           !< list of variables written to NetCDF file
-
-      INTEGER(iwp) ::  av                !< flag for averaged (=1) and non-averaged (=0) data
+    CHARACTER (LEN=100)  ::  filename            !< name of output file
+    CHARACTER (LEN=80)   ::   time_average_text  !< string written to file attribute time_avg
+    CHARACTER (LEN=4000) ::   var_list           !< list of variables written to NetCDF file
+
+    INTEGER(iwp) ::  av                 !< flag for averaged (=1) and non-averaged (=0) data
 #endif
-      INTEGER(iwp) ::  i                 !< grid index in x-direction, also running variable for counting non-average data output
-      INTEGER(iwp) ::  j                 !< grid index in y-direction, also running variable for counting average data output
-      INTEGER(iwp) ::  k                 !< grid index in z-direction
-      INTEGER(iwp) ::  l                 !< running index for surface-element orientation
-      INTEGER(iwp) ::  m                 !< running index for surface elements
-      INTEGER(iwp) ::  mm                !< local counting variable for surface elements
-      INTEGER(iwp) ::  npg               !< counter variable for all surface elements ( or polygons )
-      INTEGER(iwp) ::  point_index_count !< local counter variable for point index
-      INTEGER(iwp) ::  start_count       !< local start counter for the surface index
-
-      INTEGER(iwp), DIMENSION(0:numprocs-1) :: num_points_on_pe   !< array which contains the number of points on all mpi ranks
-      INTEGER(iwp), DIMENSION(0:numprocs-1) :: num_surfaces_on_pe !< array which contains the number of surfaces on all mpi ranks
-      INTEGER(iwp), ALLOCATABLE, DIMENSION(:,:,:) ::  point_index !< dummy array used to check where the reference points for surface polygons are located
-
-      REAL(wp) ::  az    !< azimuth angle, indicated the vertical orientation of a surface element
-      REAL(wp) ::  off_x !< grid offset in x-direction between the stored grid index and the actual wall
-      REAL(wp) ::  off_y !< grid offset in y-direction between the stored grid index and the actual wall
+    INTEGER(iwp) ::  i                  !< grid index in x-direction, also running variable for counting non-average data output
+    INTEGER(iwp) ::  j                  !< grid index in y-direction, also running variable for counting average data output
+    INTEGER(iwp) ::  k                  !< grid index in z-direction
+    INTEGER(iwp) ::  l                  !< running index for surface-element orientation
+    INTEGER(iwp) ::  m                  !< running index for surface elements
+    INTEGER(iwp) ::  mm                 !< local counting variable for surface elements
+    INTEGER(iwp) ::  npg                !< counter variable for all surface elements ( or polygons )
+    INTEGER(iwp) ::  point_index_count  !< local counter variable for point index
+    INTEGER(iwp) ::  start_count        !< local start counter for the surface index
+
+    INTEGER(iwp), DIMENSION(0:numprocs-1) ::  num_points_on_pe    !< array which contains the number of points on all mpi ranks
+    INTEGER(iwp), DIMENSION(0:numprocs-1) ::  num_surfaces_on_pe  !< array which contains the number of surfaces on all mpi ranks
+    INTEGER(iwp), ALLOCATABLE, DIMENSION(:,:,:) ::  point_index   !< dummy array used to check where the reference points for
+                                                                  !< surface polygons are located
+
+    REAL(wp) ::  az     !< azimuth angle, indicated the vertical orientation of a surface element
+    REAL(wp) ::  off_x  !< grid offset in x-direction between the stored grid index and the actual wall
+    REAL(wp) ::  off_y  !< grid offset in y-direction between the stored grid index and the actual wall
 #if defined( __netcdf4_parallel )
-      REAL(wp), DIMENSION(:), ALLOCATABLE ::  netcdf_data_1d  !< dummy array to output 1D data into netcdf file
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  netcdf_data_1d  !< dummy array to output 1D data into netcdf file
 #endif
 
 !
-!--   If output to VTK format is enabled, initialize point and polygon data.
-!--   In a first step, count the number of points which are defining
-!--   the surfaces and the polygons.
-      IF ( to_vtk )  THEN
-         ALLOCATE( point_index(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-         point_index = -1
-!
-!--      Horizontal default surfaces
-         surfaces%npoints = 0
-         DO  l = 0, 1
-            DO  m = 1, surf_def_h(0)%ns
-!
-!--            Determine the indices of the respective grid cell inside the topography
-               i = surf_def_h(0)%i(m) + surf_def_h(0)%ioff
-               j = surf_def_h(0)%j(m) + surf_def_h(0)%joff
-               k = surf_def_h(0)%k(m) + surf_def_h(0)%koff
-!
-!--            Check if the vertices that define the surface element are already
-!--            defined, if not, increment the counter.
-               IF ( point_index(k,j,i) < 0 )  THEN
-                  surfaces%npoints   = surfaces%npoints + 1
-                  point_index(k,j,i) = surfaces%npoints - 1
-               ENDIF
-               IF ( point_index(k,j,i+1) < 0 )  THEN
-                  surfaces%npoints     = surfaces%npoints + 1
-                  point_index(k,j,i+1) = surfaces%npoints - 1
-               ENDIF
-               IF ( point_index(k,j+1,i+1) < 0 )  THEN
-                  surfaces%npoints       = surfaces%npoints + 1
-                  point_index(k,j+1,i+1) = surfaces%npoints - 1
-               ENDIF
-               IF ( point_index(k,j+1,i) < 0 )  THEN
-                  surfaces%npoints     = surfaces%npoints + 1
-                  point_index(k,j+1,i) = surfaces%npoints - 1
-               ENDIF
-            ENDDO
-         ENDDO
-         DO  m = 1, surf_lsm_h%ns
-            i = surf_lsm_h%i(m) + surf_lsm_h%ioff
-            j = surf_lsm_h%j(m) + surf_lsm_h%joff
-            k = surf_lsm_h%k(m) + surf_lsm_h%koff
-
-            IF ( point_index(k,j,i) < 0 )  THEN
-               surfaces%npoints   = surfaces%npoints + 1
-               point_index(k,j,i) = surfaces%npoints - 1
-            ENDIF
-            IF ( point_index(k,j,i+1) < 0 )  THEN
-               surfaces%npoints     = surfaces%npoints + 1
-               point_index(k,j,i+1) = surfaces%npoints - 1
-            ENDIF
-            IF ( point_index(k,j+1,i+1) < 0 )  THEN
-               surfaces%npoints       = surfaces%npoints + 1
-               point_index(k,j+1,i+1) = surfaces%npoints - 1
-            ENDIF
-            IF ( point_index(k,j+1,i) < 0 )  THEN
-               surfaces%npoints     = surfaces%npoints + 1
-               point_index(k,j+1,i) = surfaces%npoints - 1
-            ENDIF
-         ENDDO
-         DO  m = 1, surf_usm_h%ns
-            i = surf_usm_h%i(m) + surf_usm_h%ioff
-            j = surf_usm_h%j(m) + surf_usm_h%joff
-            k = surf_usm_h%k(m) + surf_usm_h%koff
-
-            IF ( point_index(k,j,i) < 0 )  THEN
-               surfaces%npoints   = surfaces%npoints + 1
-               point_index(k,j,i) = surfaces%npoints - 1
-            ENDIF
-            IF ( point_index(k,j,i+1) < 0 )  THEN
-               surfaces%npoints     = surfaces%npoints + 1
-               point_index(k,j,i+1) = surfaces%npoints - 1
-            ENDIF
-            IF ( point_index(k,j+1,i+1) < 0 )  THEN
-               surfaces%npoints       = surfaces%npoints + 1
-               point_index(k,j+1,i+1) = surfaces%npoints - 1
-            ENDIF
-            IF ( point_index(k,j+1,i) < 0 )  THEN
-               surfaces%npoints     = surfaces%npoints + 1
-               point_index(k,j+1,i) = surfaces%npoints - 1
-            ENDIF
-         ENDDO
-!
-!--      Vertical surfaces
-         DO  l = 0, 3
-            DO  m = 1, surf_def_v(l)%ns
-!
-!--            Determine the indices of the respective grid cell inside the
-!--            topography. Please note, j-index for north-facing surfaces
-!--            ( l==0 ) is identical to the reference j-index outside the grid
-!--            box. Equivalent for east-facing surfaces and i-index.
-               i = surf_def_v(l)%i(m) + MERGE( surf_def_v(l)%ioff, 0, l == 3 )
-               j = surf_def_v(l)%j(m) + MERGE( surf_def_v(l)%joff, 0, l == 1 )
-               k = surf_def_v(l)%k(m) + surf_def_v(l)%koff
-!
-!--            Lower left /front vertex
-               IF ( point_index(k,j,i) < 0 )  THEN
-                  surfaces%npoints   = surfaces%npoints + 1
-                  point_index(k,j,i) = surfaces%npoints - 1
-               ENDIF
-!
-!--            Upper / lower right index for north- and south-facing surfaces
-               IF ( l == 0  .OR.  l == 1 )  THEN
-                  IF ( point_index(k,j,i+1) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j,i+1) = surfaces%npoints - 1
-                  ENDIF
-                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j,i+1) = surfaces%npoints - 1
-                  ENDIF
-!
-!--            Upper / lower front index for east- and west-facing surfaces
-               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
-                  IF ( point_index(k,j+1,i) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j+1,i) = surfaces%npoints - 1
-                  ENDIF
-                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j+1,i) = surfaces%npoints - 1
-                  ENDIF
-               ENDIF
-!
-!--            Upper left / front vertex
-               IF ( point_index(k+1,j,i) < 0 )  THEN
-                  surfaces%npoints     = surfaces%npoints + 1
-                  point_index(k+1,j,i) = surfaces%npoints - 1
-               ENDIF
-            ENDDO
-            DO  m = 1, surf_lsm_v(l)%ns
-               i = surf_lsm_v(l)%i(m) + MERGE( surf_lsm_v(l)%ioff, 0, l == 3 )
-               j = surf_lsm_v(l)%j(m) + MERGE( surf_lsm_v(l)%joff, 0, l == 1 )
-               k = surf_lsm_v(l)%k(m) + surf_lsm_v(l)%koff
-!
-!--            Lower left /front vertex
-               IF ( point_index(k,j,i) < 0 )  THEN
-                  surfaces%npoints   = surfaces%npoints + 1
-                  point_index(k,j,i) = surfaces%npoints - 1
-               ENDIF
-!
-!--            Upper / lower right index for north- and south-facing surfaces
-               IF ( l == 0  .OR.  l == 1 )  THEN
-                  IF ( point_index(k,j,i+1) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j,i+1) = surfaces%npoints - 1
-                  ENDIF
-                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j,i+1) = surfaces%npoints - 1
-                  ENDIF
-!
-!--            Upper / lower front index for east- and west-facing surfaces
-               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
-                  IF ( point_index(k,j+1,i) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j+1,i) = surfaces%npoints - 1
-                  ENDIF
-                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j+1,i) = surfaces%npoints - 1
-                  ENDIF
-               ENDIF
-!
-!--            Upper left / front vertex
-               IF ( point_index(k+1,j,i) < 0 )  THEN
-                  surfaces%npoints     = surfaces%npoints + 1
-                  point_index(k+1,j,i) = surfaces%npoints - 1
-               ENDIF
-            ENDDO
-
-            DO  m = 1, surf_usm_v(l)%ns
-               i = surf_usm_v(l)%i(m) + MERGE( surf_usm_v(l)%ioff, 0, l == 3 )
-               j = surf_usm_v(l)%j(m) + MERGE( surf_usm_v(l)%joff, 0, l == 1 )
-               k = surf_usm_v(l)%k(m) + surf_usm_v(l)%koff
-!
-!--            Lower left /front vertex
-               IF ( point_index(k,j,i) < 0 )  THEN
-                  surfaces%npoints   = surfaces%npoints + 1
-                  point_index(k,j,i) = surfaces%npoints - 1
-               ENDIF
-!
-!--            Upper / lower right index for north- and south-facing surfaces
-               IF ( l == 0  .OR.  l == 1 )  THEN
-                  IF ( point_index(k,j,i+1) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j,i+1) = surfaces%npoints - 1
-                  ENDIF
-                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j,i+1) = surfaces%npoints - 1
-                  ENDIF
-!
-!--            Upper / lower front index for east- and west-facing surfaces
-               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
-                  IF ( point_index(k,j+1,i) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j+1,i) = surfaces%npoints - 1
-                  ENDIF
-                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j+1,i) = surfaces%npoints - 1
-                  ENDIF
-               ENDIF
-!
-!--            Upper left / front vertex
-               IF ( point_index(k+1,j,i) < 0 )  THEN
-                  surfaces%npoints     = surfaces%npoints + 1
-                  point_index(k+1,j,i) = surfaces%npoints - 1
-               ENDIF
-            ENDDO
-
-         ENDDO
-!
-!--      Allocate the number of points and polygons. Note, the number of
-!--      polygons is identical to the number of surfaces elements, whereas the
-!--      number of points (vertices), which define the polygons, can be larger.
-         ALLOCATE( surfaces%points(3,1:surfaces%npoints) )
-         ALLOCATE( surfaces%polygons(5,1:surfaces%ns)    )
-!
-!--      Note, PARAVIEW expects consecutively ordered points, in order to
-!--      unambiguously identify surfaces.
-!--      Hence, all PEs should know where they start counting, depending on the
-!--      number of points on the other PE's with lower MPI rank.
+!-- If output to VTK format is enabled, initialize point and polygon data.
+!-- In a first step, count the number of points which are defining the surfaces and the polygons.
+    IF ( to_vtk )  THEN
+       ALLOCATE( point_index(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
+       point_index = -1
+!
+!--    Horizontal default surfaces
+       surfaces%npoints = 0
+       DO  l = 0, 1
+          DO  m = 1, surf_def_h(0)%ns
+!
+!--          Determine the indices of the respective grid cell inside the topography
+             i = surf_def_h(0)%i(m) + surf_def_h(0)%ioff
+             j = surf_def_h(0)%j(m) + surf_def_h(0)%joff
+             k = surf_def_h(0)%k(m) + surf_def_h(0)%koff
+!
+!--          Check if the vertices that define the surface element are already defined, if not,
+!--          increment the counter.
+             IF ( point_index(k,j,i) < 0 )  THEN
+                surfaces%npoints   = surfaces%npoints + 1
+                point_index(k,j,i) = surfaces%npoints - 1
+             ENDIF
+             IF ( point_index(k,j,i+1) < 0 )  THEN
+                surfaces%npoints     = surfaces%npoints + 1
+                point_index(k,j,i+1) = surfaces%npoints - 1
+             ENDIF
+             IF ( point_index(k,j+1,i+1) < 0 )  THEN
+                surfaces%npoints       = surfaces%npoints + 1
+                point_index(k,j+1,i+1) = surfaces%npoints - 1
+             ENDIF
+             IF ( point_index(k,j+1,i) < 0 )  THEN
+                surfaces%npoints     = surfaces%npoints + 1
+                point_index(k,j+1,i) = surfaces%npoints - 1
+             ENDIF
+          ENDDO
+       ENDDO
+       DO  m = 1, surf_lsm_h%ns
+          i = surf_lsm_h%i(m) + surf_lsm_h%ioff
+          j = surf_lsm_h%j(m) + surf_lsm_h%joff
+          k = surf_lsm_h%k(m) + surf_lsm_h%koff
+
+          IF ( point_index(k,j,i) < 0 )  THEN
+             surfaces%npoints   = surfaces%npoints + 1
+             point_index(k,j,i) = surfaces%npoints - 1
+          ENDIF
+          IF ( point_index(k,j,i+1) < 0 )  THEN
+             surfaces%npoints     = surfaces%npoints + 1
+             point_index(k,j,i+1) = surfaces%npoints - 1
+          ENDIF
+          IF ( point_index(k,j+1,i+1) < 0 )  THEN
+             surfaces%npoints       = surfaces%npoints + 1
+             point_index(k,j+1,i+1) = surfaces%npoints - 1
+          ENDIF
+          IF ( point_index(k,j+1,i) < 0 )  THEN
+             surfaces%npoints     = surfaces%npoints + 1
+             point_index(k,j+1,i) = surfaces%npoints - 1
+          ENDIF
+       ENDDO
+       DO  m = 1, surf_usm_h%ns
+          i = surf_usm_h%i(m) + surf_usm_h%ioff
+          j = surf_usm_h%j(m) + surf_usm_h%joff
+          k = surf_usm_h%k(m) + surf_usm_h%koff
+
+          IF ( point_index(k,j,i) < 0 )  THEN
+             surfaces%npoints   = surfaces%npoints + 1
+             point_index(k,j,i) = surfaces%npoints - 1
+          ENDIF
+          IF ( point_index(k,j,i+1) < 0 )  THEN
+             surfaces%npoints     = surfaces%npoints + 1
+             point_index(k,j,i+1) = surfaces%npoints - 1
+          ENDIF
+          IF ( point_index(k,j+1,i+1) < 0 )  THEN
+             surfaces%npoints       = surfaces%npoints + 1
+             point_index(k,j+1,i+1) = surfaces%npoints - 1
+          ENDIF
+          IF ( point_index(k,j+1,i) < 0 )  THEN
+             surfaces%npoints     = surfaces%npoints + 1
+             point_index(k,j+1,i) = surfaces%npoints - 1
+          ENDIF
+       ENDDO
+!
+!--    Vertical surfaces
+       DO  l = 0, 3
+          DO  m = 1, surf_def_v(l)%ns
+!
+!--          Determine the indices of the respective grid cell inside the topography. Please note,
+!--          j-index for north-facing surfaces ( l==0 ) is identical to the reference j-index
+!--          outside the grid box. Equivalent for east-facing surfaces and i-index.
+             i = surf_def_v(l)%i(m) + MERGE( surf_def_v(l)%ioff, 0, l == 3 )
+             j = surf_def_v(l)%j(m) + MERGE( surf_def_v(l)%joff, 0, l == 1 )
+             k = surf_def_v(l)%k(m) + surf_def_v(l)%koff
+!
+!--          Lower left /front vertex
+             IF ( point_index(k,j,i) < 0 )  THEN
+                surfaces%npoints   = surfaces%npoints + 1
+                point_index(k,j,i) = surfaces%npoints - 1
+             ENDIF
+!
+!--          Upper / lower right index for north- and south-facing surfaces
+             IF ( l == 0  .OR.  l == 1 )  THEN
+                IF ( point_index(k,j,i+1) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j,i+1) = surfaces%npoints - 1
+                ENDIF
+                IF ( point_index(k+1,j,i+1) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j,i+1) = surfaces%npoints - 1
+                ENDIF
+!
+!--          Upper / lower front index for east- and west-facing surfaces
+             ELSEIF ( l == 2  .OR.  l == 3 )  THEN
+                IF ( point_index(k,j+1,i) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j+1,i) = surfaces%npoints - 1
+                ENDIF
+                IF ( point_index(k+1,j+1,i) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j+1,i) = surfaces%npoints - 1
+                ENDIF
+             ENDIF
+!
+!--          Upper left / front vertex
+             IF ( point_index(k+1,j,i) < 0 )  THEN
+                surfaces%npoints     = surfaces%npoints + 1
+                point_index(k+1,j,i) = surfaces%npoints - 1
+             ENDIF
+          ENDDO
+          DO  m = 1, surf_lsm_v(l)%ns
+             i = surf_lsm_v(l)%i(m) + MERGE( surf_lsm_v(l)%ioff, 0, l == 3 )
+             j = surf_lsm_v(l)%j(m) + MERGE( surf_lsm_v(l)%joff, 0, l == 1 )
+             k = surf_lsm_v(l)%k(m) + surf_lsm_v(l)%koff
+!
+!--          Lower left /front vertex
+             IF ( point_index(k,j,i) < 0 )  THEN
+                surfaces%npoints   = surfaces%npoints + 1
+                point_index(k,j,i) = surfaces%npoints - 1
+             ENDIF
+!
+!--          Upper / lower right index for north- and south-facing surfaces
+             IF ( l == 0  .OR.  l == 1 )  THEN
+                IF ( point_index(k,j,i+1) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j,i+1) = surfaces%npoints - 1
+                ENDIF
+                IF ( point_index(k+1,j,i+1) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j,i+1) = surfaces%npoints - 1
+                ENDIF
+!
+!--          Upper / lower front index for east- and west-facing surfaces
+             ELSEIF ( l == 2  .OR.  l == 3 )  THEN
+                IF ( point_index(k,j+1,i) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j+1,i) = surfaces%npoints - 1
+                ENDIF
+                IF ( point_index(k+1,j+1,i) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j+1,i) = surfaces%npoints - 1
+                ENDIF
+             ENDIF
+!
+!--          Upper left / front vertex
+             IF ( point_index(k+1,j,i) < 0 )  THEN
+                surfaces%npoints     = surfaces%npoints + 1
+                point_index(k+1,j,i) = surfaces%npoints - 1
+             ENDIF
+          ENDDO
+
+          DO  m = 1, surf_usm_v(l)%ns
+             i = surf_usm_v(l)%i(m) + MERGE( surf_usm_v(l)%ioff, 0, l == 3 )
+             j = surf_usm_v(l)%j(m) + MERGE( surf_usm_v(l)%joff, 0, l == 1 )
+             k = surf_usm_v(l)%k(m) + surf_usm_v(l)%koff
+!
+!--          Lower left /front vertex
+             IF ( point_index(k,j,i) < 0 )  THEN
+                surfaces%npoints   = surfaces%npoints + 1
+                point_index(k,j,i) = surfaces%npoints - 1
+             ENDIF
+!
+!--          Upper / lower right index for north- and south-facing surfaces
+             IF ( l == 0  .OR.  l == 1 )  THEN
+                IF ( point_index(k,j,i+1) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j,i+1) = surfaces%npoints - 1
+                ENDIF
+                IF ( point_index(k+1,j,i+1) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j,i+1) = surfaces%npoints - 1
+                ENDIF
+!
+!--          Upper / lower front index for east- and west-facing surfaces
+             ELSEIF ( l == 2  .OR.  l == 3 )  THEN
+                IF ( point_index(k,j+1,i) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j+1,i) = surfaces%npoints - 1
+                ENDIF
+                IF ( point_index(k+1,j+1,i) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j+1,i) = surfaces%npoints - 1
+                ENDIF
+             ENDIF
+!
+!--          Upper left / front vertex
+             IF ( point_index(k+1,j,i) < 0 )  THEN
+                surfaces%npoints     = surfaces%npoints + 1
+                point_index(k+1,j,i) = surfaces%npoints - 1
+             ENDIF
+          ENDDO
+
+       ENDDO
+!
+!--    Allocate the number of points and polygons. Note, the number of polygons is identical to the
+!--    number of surfaces elements, whereas the number of points (vertices), which define the
+!--    polygons, can be larger.
+       ALLOCATE( surfaces%points(3,1:surfaces%npoints) )
+       ALLOCATE( surfaces%polygons(5,1:surfaces%ns)    )
+!
+!--    Note, PARAVIEW expects consecutively ordered points, in order to unambiguously identify
+!--    surfaces. Hence, all PEs should know where they start counting, depending on the number of
+!--    points on the other PE's with lower MPI rank.
 #if defined( __parallel )
-         CALL MPI_ALLGATHER( surfaces%npoints, 1, MPI_INTEGER,                 &
-                             num_points_on_pe, 1, MPI_INTEGER, comm2d, ierr  )
+       CALL MPI_ALLGATHER( surfaces%npoints, 1, MPI_INTEGER, num_points_on_pe, 1, MPI_INTEGER,     &
+                           comm2d, ierr  )
 #else
-         num_points_on_pe = surfaces%npoints
+       num_points_on_pe = surfaces%npoints
 #endif
 
 !
-!--      After the number of vertices is counted, repeat the loops and define
-!--      the vertices. Start with the horizontal default surfaces.
-!--      First, however, determine the offset where couting of points should be
-!--      started, which is the sum of points of all PE's with lower MPI rank.
-         i                 = 0
-         point_index_count = 0
-         DO WHILE ( i < myid  .AND.  i <= SIZE( num_points_on_pe ) )
-            point_index_count = point_index_count + num_points_on_pe(i)
-            i                 = i + 1
-         ENDDO
-
-         surfaces%npoints = 0
-         point_index      = -1
-         npg              = 0
-
-         DO  l = 0, 1
-            DO  m = 1, surf_def_h(l)%ns
-!
-!--            Determine the indices of the respective grid cell inside the
-!--            topography.
-               i = surf_def_h(l)%i(m) + surf_def_h(l)%ioff
-               j = surf_def_h(l)%j(m) + surf_def_h(l)%joff
-               k = surf_def_h(l)%k(m) + surf_def_h(l)%koff
-!
-!--            Check if the vertices that define the surface element are
-!--            already defined, if not, increment the counter.
-               IF ( point_index(k,j,i) < 0 )  THEN
-                  surfaces%npoints   = surfaces%npoints + 1
-                  point_index(k,j,i) = point_index_count
-                  point_index_count  = point_index_count + 1
-                  surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
-                  surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
-                  surfaces%points(3,surfaces%npoints) = zw(k)
-               ENDIF
-               IF ( point_index(k,j,i+1) < 0 )  THEN
-                  surfaces%npoints     = surfaces%npoints + 1
-                  point_index(k,j,i+1) = point_index_count
-                  point_index_count    = point_index_count + 1
-                  surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-                  surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
-                  surfaces%points(3,surfaces%npoints) = zw(k)
-               ENDIF
-               IF ( point_index(k,j+1,i+1) < 0 )  THEN
-                  surfaces%npoints       = surfaces%npoints + 1
-                  point_index(k,j+1,i+1) = point_index_count
-                  point_index_count      = point_index_count + 1
-                  surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-                  surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-                  surfaces%points(3,surfaces%npoints) = zw(k)
-               ENDIF
-               IF ( point_index(k,j+1,i) < 0 )  THEN
-                  surfaces%npoints     = surfaces%npoints + 1
-                  point_index(k,j+1,i) = point_index_count
-                  point_index_count    = point_index_count + 1
-                  surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
-                  surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-                  surfaces%points(3,surfaces%npoints) = zw(k)
-               ENDIF
-
-               npg                        = npg + 1
-               surfaces%polygons(1,npg)   = 4
-               surfaces%polygons(2,npg)   = point_index(k,j,i)
-               surfaces%polygons(3,npg)   = point_index(k,j,i+1)
-               surfaces%polygons(4,npg)   = point_index(k,j+1,i+1)
-               surfaces%polygons(5,npg)   = point_index(k,j+1,i)
-            ENDDO
-         ENDDO
-         DO  m = 1, surf_lsm_h%ns
-            i = surf_lsm_h%i(m) + surf_lsm_h%ioff
-            j = surf_lsm_h%j(m) + surf_lsm_h%joff
-            k = surf_lsm_h%k(m) + surf_lsm_h%koff
-            IF ( point_index(k,j,i) < 0 )  THEN
-               surfaces%npoints   = surfaces%npoints + 1
-               point_index(k,j,i) = point_index_count
-               point_index_count  = point_index_count + 1
-               surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
-               surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
-               surfaces%points(3,surfaces%npoints) = zw(k)
-            ENDIF
-            IF ( point_index(k,j,i+1) < 0 )  THEN
-               surfaces%npoints     = surfaces%npoints + 1
-               point_index(k,j,i+1) = point_index_count
-               point_index_count    = point_index_count + 1
-               surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-               surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
-               surfaces%points(3,surfaces%npoints) = zw(k)
-            ENDIF
-            IF ( point_index(k,j+1,i+1) < 0 )  THEN
-               surfaces%npoints       = surfaces%npoints + 1
-               point_index(k,j+1,i+1) = point_index_count
-               point_index_count      = point_index_count + 1
-               surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-               surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-               surfaces%points(3,surfaces%npoints) = zw(k)
-            ENDIF
-            IF ( point_index(k,j+1,i) < 0 )  THEN
-               surfaces%npoints     = surfaces%npoints + 1
-               point_index(k,j+1,i) = point_index_count
-               point_index_count    = point_index_count + 1
-               surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
-               surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-               surfaces%points(3,surfaces%npoints) = zw(k)
-            ENDIF
-
-            npg                        = npg + 1
-            surfaces%polygons(1,npg)   = 4
-            surfaces%polygons(2,npg)   = point_index(k,j,i)
-            surfaces%polygons(3,npg)   = point_index(k,j,i+1)
-            surfaces%polygons(4,npg)   = point_index(k,j+1,i+1)
-            surfaces%polygons(5,npg)   = point_index(k,j+1,i)
-         ENDDO
-
-         DO  m = 1, surf_usm_h%ns
-            i = surf_usm_h%i(m) + surf_usm_h%ioff
-            j = surf_usm_h%j(m) + surf_usm_h%joff
-            k = surf_usm_h%k(m) + surf_usm_h%koff
-
-            IF ( point_index(k,j,i) < 0 )  THEN
-               surfaces%npoints   = surfaces%npoints + 1
-               point_index(k,j,i) = point_index_count
-               point_index_count  = point_index_count + 1
-               surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
-               surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
-               surfaces%points(3,surfaces%npoints) = zw(k)
-            ENDIF
-            IF ( point_index(k,j,i+1) < 0 )  THEN
-               surfaces%npoints     = surfaces%npoints + 1
-               point_index(k,j,i+1) = point_index_count
-               point_index_count    = point_index_count + 1
-               surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-               surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
-               surfaces%points(3,surfaces%npoints) = zw(k)
-            ENDIF
-            IF ( point_index(k,j+1,i+1) < 0 )  THEN
-               surfaces%npoints       = surfaces%npoints + 1
-               point_index(k,j+1,i+1) = point_index_count
-               point_index_count      = point_index_count + 1
-               surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-               surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-               surfaces%points(3,surfaces%npoints) = zw(k)
-            ENDIF
-            IF ( point_index(k,j+1,i) < 0 )  THEN
-               surfaces%npoints     = surfaces%npoints + 1
-               point_index(k,j+1,i) = point_index_count
-               point_index_count    = point_index_count + 1
-               surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
-               surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-               surfaces%points(3,surfaces%npoints) = zw(k)
-            ENDIF
-
-            npg                        = npg + 1
-            surfaces%polygons(1,npg)   = 4
-            surfaces%polygons(2,npg)   = point_index(k,j,i)
-            surfaces%polygons(3,npg)   = point_index(k,j,i+1)
-            surfaces%polygons(4,npg)   = point_index(k,j+1,i+1)
-            surfaces%polygons(5,npg)   = point_index(k,j+1,i)
-         ENDDO
-
-         DO  l = 0, 3
-            DO  m = 1, surf_def_v(l)%ns
-!
-!--            Determine the indices of the respective grid cell inside the
-!--            topography.
-!--            NOTE, j-index for north-facing surfaces ( l==0 ) is
-!--            identical to the reference j-index outside the grid box.
-!--            Equivalent for east-facing surfaces and i-index.
-               i = surf_def_v(l)%i(m) + MERGE( surf_def_v(l)%ioff, 0, l == 3 )
-               j = surf_def_v(l)%j(m) + MERGE( surf_def_v(l)%joff, 0, l == 1 )
-               k = surf_def_v(l)%k(m) + surf_def_v(l)%koff
-!
-!--            Lower left /front vertex
-               IF ( point_index(k,j,i) < 0 )  THEN
-                  surfaces%npoints   = surfaces%npoints + 1
-                  point_index(k,j,i) = point_index_count
-                  point_index_count  = point_index_count + 1
-                  surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
-                  surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
-                  surfaces%points(3,surfaces%npoints) = zw(k-1)
-               ENDIF
-!
-!--            Upper / lower right index for north- and south-facing surfaces
-               IF ( l == 0  .OR.  l == 1 )  THEN
-                  IF ( point_index(k,j,i+1) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j,i+1) = point_index_count
-                     point_index_count    = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k-1)
-                  ENDIF
-                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j,i+1) = point_index_count
-                     point_index_count      = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k)
-                  ENDIF
-!
-!--            Upper / lower front index for east- and west-facing surfaces
-               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
-                  IF ( point_index(k,j+1,i) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j+1,i) = point_index_count
-                     point_index_count    = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k-1)
-                  ENDIF
-                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j+1,i) = point_index_count
-                     point_index_count      = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k)
-                  ENDIF
-               ENDIF
-!
-!--            Upper left / front vertex
-               IF ( point_index(k+1,j,i) < 0 )  THEN
-                  surfaces%npoints     = surfaces%npoints + 1
-                  point_index(k+1,j,i) = point_index_count
-                  point_index_count    = point_index_count + 1
-                  surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
-                  surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
-                  surfaces%points(3,surfaces%npoints) = zw(k)
-               ENDIF
-
-               npg = npg + 1
-               IF ( l == 0  .OR.  l == 1 )  THEN
-                  surfaces%polygons(1,npg)   = 4
-                  surfaces%polygons(2,npg)   = point_index(k,j,i)
-                  surfaces%polygons(3,npg)   = point_index(k,j,i+1)
-                  surfaces%polygons(4,npg)   = point_index(k+1,j,i+1)
-                  surfaces%polygons(5,npg)   = point_index(k+1,j,i)
-               ELSE
-                  surfaces%polygons(1,npg)   = 4
-                  surfaces%polygons(2,npg)   = point_index(k,j,i)
-                  surfaces%polygons(3,npg)   = point_index(k,j+1,i)
-                  surfaces%polygons(4,npg)   = point_index(k+1,j+1,i)
-                  surfaces%polygons(5,npg)   = point_index(k+1,j,i)
-               ENDIF
-
-            ENDDO
-
-            DO  m = 1, surf_lsm_v(l)%ns
-               i = surf_lsm_v(l)%i(m) + MERGE( surf_lsm_v(l)%ioff, 0, l == 3 )
-               j = surf_lsm_v(l)%j(m) + MERGE( surf_lsm_v(l)%joff, 0, l == 1 )
-               k = surf_lsm_v(l)%k(m) + surf_lsm_v(l)%koff
-!
-!--            Lower left /front vertex
-               IF ( point_index(k,j,i) < 0 )  THEN
-                  surfaces%npoints   = surfaces%npoints + 1
-                  point_index(k,j,i) = point_index_count
-                  point_index_count  = point_index_count + 1
-                  surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
-                  surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
-                  surfaces%points(3,surfaces%npoints) = zw(k-1)
-               ENDIF
-!
-!--            Upper / lower right index for north- and south-facing surfaces
-               IF ( l == 0  .OR.  l == 1 )  THEN
-                  IF ( point_index(k,j,i+1) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j,i+1) = point_index_count
-                     point_index_count    = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k-1)
-                  ENDIF
-                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j,i+1) = point_index_count
-                     point_index_count      = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k)
-                  ENDIF
-!
-!--            Upper / lower front index for east- and west-facing surfaces
-               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
-                  IF ( point_index(k,j+1,i) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j+1,i) = point_index_count
-                     point_index_count    = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k-1)
-                  ENDIF
-                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j+1,i) = point_index_count
-                     point_index_count      = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k)
-                  ENDIF
-               ENDIF
-!
-!--            Upper left / front vertex
-               IF ( point_index(k+1,j,i) < 0 )  THEN
-                  surfaces%npoints     = surfaces%npoints + 1
-                  point_index(k+1,j,i) = point_index_count
-                  point_index_count    = point_index_count + 1
-                  surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
-                  surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
-                  surfaces%points(3,surfaces%npoints) = zw(k)
-               ENDIF
-
-               npg = npg + 1
-               IF ( l == 0  .OR.  l == 1 )  THEN
-                  surfaces%polygons(1,npg)   = 4
-                  surfaces%polygons(2,npg)   = point_index(k,j,i)
-                  surfaces%polygons(3,npg)   = point_index(k,j,i+1)
-                  surfaces%polygons(4,npg)   = point_index(k+1,j,i+1)
-                  surfaces%polygons(5,npg)   = point_index(k+1,j,i)
-               ELSE
-                  surfaces%polygons(1,npg)   = 4
-                  surfaces%polygons(2,npg)   = point_index(k,j,i)
-                  surfaces%polygons(3,npg)   = point_index(k,j+1,i)
-                  surfaces%polygons(4,npg)   = point_index(k+1,j+1,i)
-                  surfaces%polygons(5,npg)   = point_index(k+1,j,i)
-               ENDIF
-            ENDDO
-            DO  m = 1, surf_usm_v(l)%ns
-               i = surf_usm_v(l)%i(m) + MERGE( surf_usm_v(l)%ioff, 0, l == 3 )
-               j = surf_usm_v(l)%j(m) + MERGE( surf_usm_v(l)%joff, 0, l == 1 )
-               k = surf_usm_v(l)%k(m) + surf_usm_v(l)%koff
-!
-!--            Lower left /front vertex
-               IF ( point_index(k,j,i) < 0 )  THEN
-                  surfaces%npoints   = surfaces%npoints + 1
-                  point_index(k,j,i) = point_index_count
-                  point_index_count  = point_index_count + 1
-                  surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
-                  surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
-                  surfaces%points(3,surfaces%npoints) = zw(k-1)
-               ENDIF
-!
-!--            Upper / lower right index for north- and south-facing surfaces
-               IF ( l == 0  .OR.  l == 1 )  THEN
-                  IF ( point_index(k,j,i+1) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j,i+1) = point_index_count
-                     point_index_count    = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k-1)
-                  ENDIF
-                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j,i+1) = point_index_count
-                     point_index_count      = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k)
-                  ENDIF
-!
-!--            Upper / lower front index for east- and west-facing surfaces
-               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
-                  IF ( point_index(k,j+1,i) < 0 )  THEN
-                     surfaces%npoints     = surfaces%npoints + 1
-                     point_index(k,j+1,i) = point_index_count
-                     point_index_count    = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k-1)
-                  ENDIF
-                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
-                     surfaces%npoints       = surfaces%npoints + 1
-                     point_index(k+1,j+1,i) = point_index_count
-                     point_index_count      = point_index_count + 1
-                     surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
-                     surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
-                     surfaces%points(3,surfaces%npoints) = zw(k)
-                  ENDIF
-               ENDIF
-!
-!--            Upper left / front vertex
-               IF ( point_index(k+1,j,i) < 0 )  THEN
-                  surfaces%npoints     = surfaces%npoints + 1
-                  point_index(k+1,j,i) = point_index_count
-                  point_index_count    = point_index_count + 1
-                  surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
-                  surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
-                  surfaces%points(3,surfaces%npoints) = zw(k)
-               ENDIF
-
-               npg = npg + 1
-               IF ( l == 0  .OR.  l == 1 )  THEN
-                  surfaces%polygons(1,npg)   = 4
-                  surfaces%polygons(2,npg)   = point_index(k,j,i)
-                  surfaces%polygons(3,npg)   = point_index(k,j,i+1)
-                  surfaces%polygons(4,npg)   = point_index(k+1,j,i+1)
-                  surfaces%polygons(5,npg)   = point_index(k+1,j,i)
-               ELSE
-                  surfaces%polygons(1,npg)   = 4
-                  surfaces%polygons(2,npg)   = point_index(k,j,i)
-                  surfaces%polygons(3,npg)   = point_index(k,j+1,i)
-                  surfaces%polygons(4,npg)   = point_index(k+1,j+1,i)
-                  surfaces%polygons(5,npg)   = point_index(k+1,j,i)
-               ENDIF
-            ENDDO
-
-         ENDDO
-!
-!--      Deallocate temporary dummy variable
-         DEALLOCATE ( point_index )
-!
-!--      Sum-up total number of vertices on domain. This
-!--      will be needed for post-processing.
-         surfaces%npoints_total = 0
+!--    After the number of vertices is counted, repeat the loops and define the vertices. Start with
+!--    the horizontal default surfaces. First, however, determine the offset where couting of points
+!--    should be started, which is the sum of points of all PE's with lower MPI rank.
+       i                 = 0
+       point_index_count = 0
+       DO WHILE  ( i < myid  .AND.  i <= SIZE( num_points_on_pe ) )
+          point_index_count = point_index_count + num_points_on_pe(i)
+          i                 = i + 1
+       ENDDO
+
+       surfaces%npoints = 0
+       point_index      = -1
+       npg              = 0
+
+       DO  l = 0, 1
+          DO  m = 1, surf_def_h(l)%ns
+!
+!--          Determine the indices of the respective grid cell inside the topography.
+             i = surf_def_h(l)%i(m) + surf_def_h(l)%ioff
+             j = surf_def_h(l)%j(m) + surf_def_h(l)%joff
+             k = surf_def_h(l)%k(m) + surf_def_h(l)%koff
+!
+!--          Check if the vertices that define the surface element are already defined, if not,
+!--          increment the counter.
+             IF ( point_index(k,j,i) < 0 )  THEN
+                surfaces%npoints   = surfaces%npoints + 1
+                point_index(k,j,i) = point_index_count
+                point_index_count  = point_index_count + 1
+                surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
+                surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
+                surfaces%points(3,surfaces%npoints) = zw(k)
+             ENDIF
+             IF ( point_index(k,j,i+1) < 0 )  THEN
+                surfaces%npoints     = surfaces%npoints + 1
+                point_index(k,j,i+1) = point_index_count
+                point_index_count    = point_index_count + 1
+                surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+                surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
+                surfaces%points(3,surfaces%npoints) = zw(k)
+             ENDIF
+             IF ( point_index(k,j+1,i+1) < 0 )  THEN
+                surfaces%npoints       = surfaces%npoints + 1
+                point_index(k,j+1,i+1) = point_index_count
+                point_index_count      = point_index_count + 1
+                surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+                surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+                surfaces%points(3,surfaces%npoints) = zw(k)
+             ENDIF
+             IF ( point_index(k,j+1,i) < 0 )  THEN
+                surfaces%npoints     = surfaces%npoints + 1
+                point_index(k,j+1,i) = point_index_count
+                point_index_count    = point_index_count + 1
+                surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
+                surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+                surfaces%points(3,surfaces%npoints) = zw(k)
+             ENDIF
+
+             npg                        = npg + 1
+             surfaces%polygons(1,npg)   = 4
+             surfaces%polygons(2,npg)   = point_index(k,j,i)
+             surfaces%polygons(3,npg)   = point_index(k,j,i+1)
+             surfaces%polygons(4,npg)   = point_index(k,j+1,i+1)
+             surfaces%polygons(5,npg)   = point_index(k,j+1,i)
+          ENDDO
+       ENDDO
+       DO  m = 1, surf_lsm_h%ns
+          i = surf_lsm_h%i(m) + surf_lsm_h%ioff
+          j = surf_lsm_h%j(m) + surf_lsm_h%joff
+          k = surf_lsm_h%k(m) + surf_lsm_h%koff
+          IF ( point_index(k,j,i) < 0 )  THEN
+             surfaces%npoints   = surfaces%npoints + 1
+             point_index(k,j,i) = point_index_count
+             point_index_count  = point_index_count + 1
+             surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
+             surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
+             surfaces%points(3,surfaces%npoints) = zw(k)
+          ENDIF
+          IF ( point_index(k,j,i+1) < 0 )  THEN
+             surfaces%npoints     = surfaces%npoints + 1
+             point_index(k,j,i+1) = point_index_count
+             point_index_count    = point_index_count + 1
+             surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+             surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
+             surfaces%points(3,surfaces%npoints) = zw(k)
+          ENDIF
+          IF ( point_index(k,j+1,i+1) < 0 )  THEN
+             surfaces%npoints       = surfaces%npoints + 1
+             point_index(k,j+1,i+1) = point_index_count
+             point_index_count      = point_index_count + 1
+             surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+             surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+             surfaces%points(3,surfaces%npoints) = zw(k)
+          ENDIF
+          IF ( point_index(k,j+1,i) < 0 )  THEN
+             surfaces%npoints     = surfaces%npoints + 1
+             point_index(k,j+1,i) = point_index_count
+             point_index_count    = point_index_count + 1
+             surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
+             surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+             surfaces%points(3,surfaces%npoints) = zw(k)
+          ENDIF
+
+          npg                        = npg + 1
+          surfaces%polygons(1,npg)   = 4
+          surfaces%polygons(2,npg)   = point_index(k,j,i)
+          surfaces%polygons(3,npg)   = point_index(k,j,i+1)
+          surfaces%polygons(4,npg)   = point_index(k,j+1,i+1)
+          surfaces%polygons(5,npg)   = point_index(k,j+1,i)
+       ENDDO
+
+       DO  m = 1, surf_usm_h%ns
+          i = surf_usm_h%i(m) + surf_usm_h%ioff
+          j = surf_usm_h%j(m) + surf_usm_h%joff
+          k = surf_usm_h%k(m) + surf_usm_h%koff
+
+          IF ( point_index(k,j,i) < 0 )  THEN
+             surfaces%npoints   = surfaces%npoints + 1
+             point_index(k,j,i) = point_index_count
+             point_index_count  = point_index_count + 1
+             surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
+             surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
+             surfaces%points(3,surfaces%npoints) = zw(k)
+          ENDIF
+          IF ( point_index(k,j,i+1) < 0 )  THEN
+             surfaces%npoints     = surfaces%npoints + 1
+             point_index(k,j,i+1) = point_index_count
+             point_index_count    = point_index_count + 1
+             surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+             surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
+             surfaces%points(3,surfaces%npoints) = zw(k)
+          ENDIF
+          IF ( point_index(k,j+1,i+1) < 0 )  THEN
+             surfaces%npoints       = surfaces%npoints + 1
+             point_index(k,j+1,i+1) = point_index_count
+             point_index_count      = point_index_count + 1
+             surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+             surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+             surfaces%points(3,surfaces%npoints) = zw(k)
+          ENDIF
+          IF ( point_index(k,j+1,i) < 0 )  THEN
+             surfaces%npoints     = surfaces%npoints + 1
+             point_index(k,j+1,i) = point_index_count
+             point_index_count    = point_index_count + 1
+             surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
+             surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+             surfaces%points(3,surfaces%npoints) = zw(k)
+          ENDIF
+
+          npg                        = npg + 1
+          surfaces%polygons(1,npg)   = 4
+          surfaces%polygons(2,npg)   = point_index(k,j,i)
+          surfaces%polygons(3,npg)   = point_index(k,j,i+1)
+          surfaces%polygons(4,npg)   = point_index(k,j+1,i+1)
+          surfaces%polygons(5,npg)   = point_index(k,j+1,i)
+       ENDDO
+
+       DO  l = 0, 3
+          DO  m = 1, surf_def_v(l)%ns
+!
+!--          Determine the indices of the respective grid cell inside the topography.
+!--          NOTE, j-index for north-facing surfaces ( l==0 ) is identical to the reference j-index
+!--          outside the grid box. Equivalent for east-facing surfaces and i-index.
+             i = surf_def_v(l)%i(m) + MERGE( surf_def_v(l)%ioff, 0, l == 3 )
+             j = surf_def_v(l)%j(m) + MERGE( surf_def_v(l)%joff, 0, l == 1 )
+             k = surf_def_v(l)%k(m) + surf_def_v(l)%koff
+!
+!--          Lower left /front vertex
+             IF ( point_index(k,j,i) < 0 )  THEN
+                surfaces%npoints   = surfaces%npoints + 1
+                point_index(k,j,i) = point_index_count
+                point_index_count  = point_index_count + 1
+                surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
+                surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
+                surfaces%points(3,surfaces%npoints) = zw(k-1)
+             ENDIF
+!
+!--          Upper / lower right index for north- and south-facing surfaces
+             IF ( l == 0  .OR.  l == 1 )  THEN
+                IF ( point_index(k,j,i+1) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j,i+1) = point_index_count
+                   point_index_count    = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k-1)
+                ENDIF
+                IF ( point_index(k+1,j,i+1) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j,i+1) = point_index_count
+                   point_index_count      = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k)
+                ENDIF
+!
+!--          Upper / lower front index for east- and west-facing surfaces
+             ELSEIF ( l == 2  .OR.  l == 3 )  THEN
+                IF ( point_index(k,j+1,i) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j+1,i) = point_index_count
+                   point_index_count    = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k-1)
+                ENDIF
+                IF ( point_index(k+1,j+1,i) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j+1,i) = point_index_count
+                   point_index_count      = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k)
+                ENDIF
+             ENDIF
+!
+!--          Upper left / front vertex
+             IF ( point_index(k+1,j,i) < 0 )  THEN
+                surfaces%npoints     = surfaces%npoints + 1
+                point_index(k+1,j,i) = point_index_count
+                point_index_count    = point_index_count + 1
+                surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
+                surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
+                surfaces%points(3,surfaces%npoints) = zw(k)
+             ENDIF
+
+             npg = npg + 1
+             IF ( l == 0  .OR.  l == 1 )  THEN
+                surfaces%polygons(1,npg)   = 4
+                surfaces%polygons(2,npg)   = point_index(k,j,i)
+                surfaces%polygons(3,npg)   = point_index(k,j,i+1)
+                surfaces%polygons(4,npg)   = point_index(k+1,j,i+1)
+                surfaces%polygons(5,npg)   = point_index(k+1,j,i)
+             ELSE
+                surfaces%polygons(1,npg)   = 4
+                surfaces%polygons(2,npg)   = point_index(k,j,i)
+                surfaces%polygons(3,npg)   = point_index(k,j+1,i)
+                surfaces%polygons(4,npg)   = point_index(k+1,j+1,i)
+                surfaces%polygons(5,npg)   = point_index(k+1,j,i)
+             ENDIF
+
+          ENDDO
+
+          DO  m = 1, surf_lsm_v(l)%ns
+             i = surf_lsm_v(l)%i(m) + MERGE( surf_lsm_v(l)%ioff, 0, l == 3 )
+             j = surf_lsm_v(l)%j(m) + MERGE( surf_lsm_v(l)%joff, 0, l == 1 )
+             k = surf_lsm_v(l)%k(m) + surf_lsm_v(l)%koff
+!
+!--          Lower left /front vertex
+             IF ( point_index(k,j,i) < 0 )  THEN
+                surfaces%npoints   = surfaces%npoints + 1
+                point_index(k,j,i) = point_index_count
+                point_index_count  = point_index_count + 1
+                surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
+                surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
+                surfaces%points(3,surfaces%npoints) = zw(k-1)
+             ENDIF
+!
+!--          Upper / lower right index for north- and south-facing surfaces
+             IF ( l == 0  .OR.  l == 1 )  THEN
+                IF ( point_index(k,j,i+1) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j,i+1) = point_index_count
+                   point_index_count    = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k-1)
+                ENDIF
+                IF ( point_index(k+1,j,i+1) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j,i+1) = point_index_count
+                   point_index_count      = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k)
+                ENDIF
+!
+!--          Upper / lower front index for east- and west-facing surfaces
+             ELSEIF ( l == 2  .OR.  l == 3 )  THEN
+                IF ( point_index(k,j+1,i) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j+1,i) = point_index_count
+                   point_index_count    = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k-1)
+                ENDIF
+                IF ( point_index(k+1,j+1,i) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j+1,i) = point_index_count
+                   point_index_count      = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k)
+                ENDIF
+             ENDIF
+!
+!--          Upper left / front vertex
+             IF ( point_index(k+1,j,i) < 0 )  THEN
+                surfaces%npoints     = surfaces%npoints + 1
+                point_index(k+1,j,i) = point_index_count
+                point_index_count    = point_index_count + 1
+                surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
+                surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
+                surfaces%points(3,surfaces%npoints) = zw(k)
+             ENDIF
+
+             npg = npg + 1
+             IF ( l == 0  .OR.  l == 1 )  THEN
+                surfaces%polygons(1,npg)   = 4
+                surfaces%polygons(2,npg)   = point_index(k,j,i)
+                surfaces%polygons(3,npg)   = point_index(k,j,i+1)
+                surfaces%polygons(4,npg)   = point_index(k+1,j,i+1)
+                surfaces%polygons(5,npg)   = point_index(k+1,j,i)
+             ELSE
+                surfaces%polygons(1,npg)   = 4
+                surfaces%polygons(2,npg)   = point_index(k,j,i)
+                surfaces%polygons(3,npg)   = point_index(k,j+1,i)
+                surfaces%polygons(4,npg)   = point_index(k+1,j+1,i)
+                surfaces%polygons(5,npg)   = point_index(k+1,j,i)
+             ENDIF
+          ENDDO
+          DO  m = 1, surf_usm_v(l)%ns
+             i = surf_usm_v(l)%i(m) + MERGE( surf_usm_v(l)%ioff, 0, l == 3 )
+             j = surf_usm_v(l)%j(m) + MERGE( surf_usm_v(l)%joff, 0, l == 1 )
+             k = surf_usm_v(l)%k(m) + surf_usm_v(l)%koff
+!
+!--          Lower left /front vertex
+             IF ( point_index(k,j,i) < 0 )  THEN
+                surfaces%npoints   = surfaces%npoints + 1
+                point_index(k,j,i) = point_index_count
+                point_index_count  = point_index_count + 1
+                surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
+                surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
+                surfaces%points(3,surfaces%npoints) = zw(k-1)
+             ENDIF
+!
+!--          Upper / lower right index for north- and south-facing surfaces
+             IF ( l == 0  .OR.  l == 1 )  THEN
+                IF ( point_index(k,j,i+1) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j,i+1) = point_index_count
+                   point_index_count    = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k-1)
+                ENDIF
+                IF ( point_index(k+1,j,i+1) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j,i+1) = point_index_count
+                   point_index_count      = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k)
+                ENDIF
+!
+!--          Upper / lower front index for east- and west-facing surfaces
+             ELSEIF ( l == 2  .OR.  l == 3 )  THEN
+                IF ( point_index(k,j+1,i) < 0 )  THEN
+                   surfaces%npoints     = surfaces%npoints + 1
+                   point_index(k,j+1,i) = point_index_count
+                   point_index_count    = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k-1)
+                ENDIF
+                IF ( point_index(k+1,j+1,i) < 0 )  THEN
+                   surfaces%npoints       = surfaces%npoints + 1
+                   point_index(k+1,j+1,i) = point_index_count
+                   point_index_count      = point_index_count + 1
+                   surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
+                   surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
+                   surfaces%points(3,surfaces%npoints) = zw(k)
+                ENDIF
+             ENDIF
+!
+!--          Upper left / front vertex
+             IF ( point_index(k+1,j,i) < 0 )  THEN
+                surfaces%npoints     = surfaces%npoints + 1
+                point_index(k+1,j,i) = point_index_count
+                point_index_count    = point_index_count + 1
+                surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
+                surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
+                surfaces%points(3,surfaces%npoints) = zw(k)
+             ENDIF
+
+             npg = npg + 1
+             IF ( l == 0  .OR.  l == 1 )  THEN
+                surfaces%polygons(1,npg)   = 4
+                surfaces%polygons(2,npg)   = point_index(k,j,i)
+                surfaces%polygons(3,npg)   = point_index(k,j,i+1)
+                surfaces%polygons(4,npg)   = point_index(k+1,j,i+1)
+                surfaces%polygons(5,npg)   = point_index(k+1,j,i)
+             ELSE
+                surfaces%polygons(1,npg)   = 4
+                surfaces%polygons(2,npg)   = point_index(k,j,i)
+                surfaces%polygons(3,npg)   = point_index(k,j+1,i)
+                surfaces%polygons(4,npg)   = point_index(k+1,j+1,i)
+                surfaces%polygons(5,npg)   = point_index(k+1,j,i)
+             ENDIF
+          ENDDO
+
+       ENDDO
+!
+!--    Deallocate temporary dummy variable
+       DEALLOCATE ( point_index )
+!
+!--    Sum-up total number of vertices on domain. This will be needed for post-processing.
+       surfaces%npoints_total = 0
 #if defined( __parallel )
-          CALL MPI_ALLREDUCE( surfaces%npoints, surfaces%npoints_total, 1,     &
-                              MPI_INTEGER, MPI_SUM, comm2d, ierr )
+        CALL MPI_ALLREDUCE( surfaces%npoints, surfaces%npoints_total, 1, MPI_INTEGER, MPI_SUM,     &
+                            comm2d, ierr )
 #else
-          surfaces%npoints_total = surfaces%npoints
+        surfaces%npoints_total = surfaces%npoints
+#endif
+     ENDIF
+!
+!--  If output to netcdf is enabled, set-up the coordinate arrays that unambiguously describe the
+!--  position and orientation of each surface element.
+     IF ( to_netcdf )  THEN
+!
+!--     Allocate local coordinate arrays
+        ALLOCATE( surfaces%s(1:surfaces%ns)       )
+        ALLOCATE( surfaces%xs(1:surfaces%ns)      )
+        ALLOCATE( surfaces%ys(1:surfaces%ns)      )
+        ALLOCATE( surfaces%zs(1:surfaces%ns)      )
+        ALLOCATE( surfaces%azimuth(1:surfaces%ns) )
+        ALLOCATE( surfaces%zenith(1:surfaces%ns)  )
+        ALLOCATE( surfaces%es_utm(1:surfaces%ns)  )
+        ALLOCATE( surfaces%ns_utm(1:surfaces%ns)  )
+!
+!--     Gather the number of surface on each processor, in order to number the surface elements in
+!--     ascending order with respect to the total number of surfaces in the domain.
+#if defined( __parallel )
+        CALL MPI_ALLGATHER( surfaces%ns, 1, MPI_INTEGER, num_surfaces_on_pe, 1, MPI_INTEGER,       &
+                            comm2d, ierr  )
+#else
+        num_surfaces_on_pe = surfaces%ns
+#endif
+!
+!--     First, however, determine the offset where couting of the surfaces should start (the sum of
+!--     surfaces on all PE's with lower MPI rank).
+        i           = 0
+        start_count = 1
+        DO WHILE  ( i < myid  .AND.  i <= SIZE( num_surfaces_on_pe ) )
+           start_count = start_count + num_surfaces_on_pe(i)
+           i           = i + 1
+        ENDDO
+!
+!--     Set coordinate arrays. For horizontal surfaces, azimuth angles are not defined (fill value).
+!--     Zenith angle is 0 (180) for upward (downward)-facing surfaces.
+        i  = start_count
+        mm = 1
+        DO  m = 1, surf_def_h(0)%ns
+           surfaces%s(mm)       = i
+           surfaces%xs(mm)      = ( surf_def_h(0)%i(m) + 0.5_wp ) * dx
+           surfaces%ys(mm)      = ( surf_def_h(0)%j(m) + 0.5_wp ) * dy
+           surfaces%zs(mm)      = zw(surf_def_h(0)%k(m)+surf_def_h(0)%koff)
+           surfaces%azimuth(mm) = surfaces%fillvalue
+           surfaces%zenith(mm)  = 0.0
+           i                    = i + 1
+           mm                   = mm + 1
+        ENDDO
+        DO  m = 1, surf_lsm_h%ns
+           surfaces%s(mm)       = i
+           surfaces%xs(mm)      = ( surf_lsm_h%i(m) + 0.5_wp ) * dx
+           surfaces%ys(mm)      = ( surf_lsm_h%j(m) + 0.5_wp ) * dy
+           surfaces%zs(mm)      = zw(surf_lsm_h%k(m)+surf_lsm_h%koff)
+           surfaces%azimuth(mm) = surfaces%fillvalue
+           surfaces%zenith(mm)  = 0.0
+           i                    = i + 1
+           mm                   = mm + 1
+        ENDDO
+        DO  m = 1, surf_usm_h%ns
+           surfaces%s(mm)       = i
+           surfaces%xs(mm)      = ( surf_usm_h%i(m) + 0.5_wp ) * dx
+           surfaces%ys(mm)      = ( surf_usm_h%j(m) + 0.5_wp ) * dy
+           surfaces%zs(mm)      = zw(surf_usm_h%k(m)+surf_usm_h%koff)
+           surfaces%azimuth(mm) = surfaces%fillvalue
+           surfaces%zenith(mm)  = 0.0
+           i                    = i + 1
+           mm                   = mm + 1
+        ENDDO
+        DO  m = 1, surf_def_h(1)%ns
+           surfaces%s(mm)       = i
+           surfaces%xs(mm)      = ( surf_def_h(1)%i(m) + 0.5_wp ) * dx
+           surfaces%ys(mm)      = ( surf_def_h(1)%j(m) + 0.5_wp ) * dy
+           surfaces%zs(mm)      = zw(surf_def_h(1)%k(m)+surf_def_h(1)%koff)
+           surfaces%azimuth(mm) = surfaces%fillvalue
+           surfaces%zenith(mm)  = 180.0
+           i                    = i + 1
+           mm                   = mm + 1
+        ENDDO
+!
+!--     For vertical surfaces, zenith angles are not defined (fill value).
+!--     Azimuth angle: northward (0), eastward (90), southward (180), westward (270).
+!--     Note, for vertical surfaces, zenith angles are 90.0_wp.
+        DO  l = 0, 3
+           IF ( l == 0 )  THEN
+              az    = 0.0_wp
+              off_x = 0.5_wp
+              off_y = 0.0_wp
+           ELSEIF ( l == 1 )  THEN
+              az    = 180.0_wp
+              off_x = 0.5_wp
+              off_y = 1.0_wp
+           ELSEIF ( l == 2 )  THEN
+              az    = 90.0_wp
+              off_x = 0.0_wp
+              off_y = 0.5_wp
+           ELSEIF ( l == 3 )  THEN
+              az    = 270.0_wp
+              off_x = 1.0_wp
+              off_y = 0.5_wp
+           ENDIF
+
+           DO  m = 1, surf_def_v(l)%ns
+              surfaces%s(mm)       = i
+              surfaces%xs(mm)      = ( surf_def_v(l)%i(m) + off_x ) * dx
+              surfaces%ys(mm)      = ( surf_def_v(l)%j(m) + off_y ) * dy
+              surfaces%zs(mm)      = zu(surf_def_v(l)%k(m))
+              surfaces%azimuth(mm) = az
+              surfaces%zenith(mm)  = 90.0_wp
+              i                    = i + 1
+              mm                   = mm + 1
+           ENDDO
+           DO  m = 1, surf_lsm_v(l)%ns
+              surfaces%s(mm)       = i
+              surfaces%xs(mm)      = ( surf_lsm_v(l)%i(m) + off_x ) * dx
+              surfaces%ys(mm)      = ( surf_lsm_v(l)%j(m) + off_y ) * dy
+              surfaces%zs(mm)      = zu(surf_lsm_v(l)%k(m))
+              surfaces%azimuth(mm) = az
+              surfaces%zenith(mm)  = 90.0_wp
+              i                    = i + 1
+              mm                   = mm + 1
+           ENDDO
+           DO  m = 1, surf_usm_v(l)%ns
+              surfaces%s(mm)       = i
+              surfaces%xs(mm)      = ( surf_usm_v(l)%i(m) + off_x ) * dx
+              surfaces%ys(mm)      = ( surf_usm_v(l)%j(m) + off_y ) * dy
+              surfaces%zs(mm)      = zu(surf_usm_v(l)%k(m))
+              surfaces%azimuth(mm) = az
+              surfaces%zenith(mm)  = 90.0_wp
+              i                    = i + 1
+              mm                   = mm + 1
+           ENDDO
+        ENDDO
+!
+!--     Finally, define UTM coordinates, which are the x/y-coordinates plus the origin (lower-left
+!--     coordinate of the model domain).
+        surfaces%es_utm = surfaces%xs + init_model%origin_x
+        surfaces%ns_utm = surfaces%ys + init_model%origin_y
+!
+!--     Initialize NetCDF data output. Please note, local start position for the surface elements in
+!--     the NetCDF file is surfaces%s(1), while the number of surfaces on the subdomain is given by
+!--     surfaces%ns.
+#if defined( __netcdf4_parallel )
+
+!
+!--     Calculate number of time steps to be output
+        ntdim_surf(0) = dosurf_time_count(0) + CEILING( ( end_time - MAX(                          &
+                          MERGE( skip_time_dosurf, skip_time_dosurf + spinup_time,                 &
+                                 data_output_during_spinup ), simulated_time_at_begin )            &
+                                                        ) / dt_dosurf )
+
+        ntdim_surf(1) = dosurf_time_count(1) + CEILING( ( end_time - MAX(                          &
+                          MERGE( skip_time_dosurf_av, skip_time_dosurf_av + spinup_time,           &
+                                 data_output_during_spinup ), simulated_time_at_begin )            &
+                                                        ) / dt_dosurf_av )
+
+!
+!--     Create NetCDF4 files for parallel writing
+        DO  av = 0, 1
+!
+!--        If there is no instantaneous data (av=0) or averaged data (av=1) requested, do not create
+!--        the corresponding NetCDF file
+           IF ( dosurf_no(av) == 0 ) CYCLE
+
+           IF ( av == 0 )  THEN
+              filename = 'SURFACE_DATA_NETCDF' // TRIM( coupling_char )
+           ELSE
+              filename = 'SURFACE_DATA_AV_NETCDF' // TRIM( coupling_char )
+           ENDIF
+!
+!--        Open file using netCDF4/HDF5 format, parallel
+           nc_stat = NF90_CREATE( TRIM(filename),                                                  &
+                                  IOR( NF90_NOCLOBBER, IOR( NF90_NETCDF4, NF90_MPIIO ) ),          &
+                                  id_set_surf(av), COMM = comm2d, INFO = MPI_INFO_NULL )
+           CALL netcdf_handle_error( 'surface_data_output_mod', 5550 )
+
+           !- Write some global attributes
+           IF ( av == 0 )  THEN
+              CALL netcdf_create_global_atts( id_set_surf(av), 'surface-data',                     &
+                                              TRIM( run_description_header ), 5551 )
+              time_average_text = ' '
+           ELSE
+              CALL netcdf_create_global_atts( id_set_surf(av), 'surface-data_av',                  &
+                                              TRIM( run_description_header ), 5552 )
+              WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval_surf
+              nc_stat = NF90_PUT_ATT( id_set_surf(av), NF90_GLOBAL, 'time_avg',                    &
+                                      TRIM( time_average_text ) )
+              CALL netcdf_handle_error( 'surface_data_output_mod', 5553 )
+           ENDIF
+
+
+!
+!--        Define time coordinate for surface data.
+!--        For parallel output the time dimension has to be limited (ntdim_surf), otherwise the
+!--        performance drops significantly.
+           CALL netcdf_create_dim( id_set_surf(av), 'time', ntdim_surf(av), id_dim_time_surf(av),  &
+                                   5554 )
+
+           CALL netcdf_create_var( id_set_surf(av), (/ id_dim_time_surf(av) /),                    &
+                                   'time', NF90_DOUBLE, id_var_time_surf(av),                      &
+                                   'seconds since '// TRIM(init_model%origin_time),                &
+                                   'time', 5555, 5555, 5555 )
+
+           CALL netcdf_create_att( id_set_surf(av), id_var_time_surf(av), 'standard_name', 'time', &
+                                   5556)
+
+           CALL netcdf_create_att( id_set_surf(av), id_var_time_surf(av), 'axis', 'T', 5557)
+!
+!--        Define spatial dimensions and coordinates:
+!--        Define index of surface element
+           CALL netcdf_create_dim( id_set_surf(av), 's', surfaces%ns_total, id_dim_s_surf(av),     &
+                                   5558 )
+           CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), 's', NF90_DOUBLE,     &
+                                   id_var_s_surf(av), '1', 'number of surface element', 5559,      &
+                                   5559, 5559 )
+!
+!--        Define x coordinate
+           CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), 'xs', NF90_DOUBLE,    &
+                                   id_var_xs_surf(av), 'meters',                                   &
+                                   'distance to origin in x-direction', 5561, 5561, 5561 )
+!
+!--         Define y coordinate
+           CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), 'ys', NF90_DOUBLE,    &
+                                   id_var_ys_surf(av), 'meters',                                   &
+                                   'distance to origin in y-direction', 5562, 5562, 5562 )
+!
+!--        Define z coordinate
+           CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), 'zs', NF90_DOUBLE,    &
+                                   id_var_zs_surf(av), 'meters', 'height', 5560, 5560, 5560 )
+           CALL netcdf_create_att( id_set_surf(av), id_var_zs_surf(av), 'standard_name', 'height', &
+                                   5583 )
+
+!
+!--        Define UTM coordinates
+           CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), 'Es_UTM',             &
+                                   NF90_DOUBLE, id_var_etum_surf(av), 'meters', '', 5563, 5563,    &
+                                   5563 )
+           CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), 'Ns_UTM',             &
+                                   NF90_DOUBLE, id_var_nutm_surf(av), 'meters', '', 5564, 5564,    &
+                                   5564 )
+
+!
+!--        Define angles
+           CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), 'azimuth',            &
+                                   NF90_DOUBLE, id_var_azimuth_surf(av), 'degree',                 &
+                                   'azimuth angle', 5577, 5578, 5579, fill = .TRUE. )
+           CALL netcdf_create_att( id_set_surf(av), id_var_azimuth_surf(av), 'standard_name',      &
+                                   'surface_azimuth_angle', 5584 )
+
+           CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), 'zenith',             &
+                                   NF90_DOUBLE, id_var_zenith_surf(av), 'degree', '', 5580, 5581,  &
+                                   5582, fill = .TRUE. )
+!
+!--        Define the variables
+           var_list = ';'
+           i = 1
+
+           DO WHILE ( dosurf(av,i)(1:1) /= ' ' )
+
+              CALL netcdf_create_var( id_set_surf(av),                                             &
+                                      (/ id_dim_s_surf(av), id_dim_time_surf(av) /), dosurf(av,i), &
+                                      NF90_REAL4, id_var_dosurf(av,i), dosurf_unit(av,i),          &
+                                      dosurf(av,i), 5565, 5565, 5565, .TRUE. )
+!
+!--           Set no fill for every variable to increase performance.
+              nc_stat = NF90_DEF_VAR_FILL( id_set_surf(av), id_var_dosurf(av,i), NF90_NOFILL, 0 )
+              CALL netcdf_handle_error( 'surface_data_output_init', 5566 )
+!
+!--           Set collective io operations for parallel io
+              nc_stat = NF90_VAR_PAR_ACCESS( id_set_surf(av), id_var_dosurf(av,i), NF90_COLLECTIVE )
+              CALL netcdf_handle_error( 'surface_data_output_init', 5567 )
+              var_list = TRIM( var_list ) // TRIM( dosurf(av,i) ) // ';'
+
+              i = i + 1
+
+           ENDDO
+!
+!--        Write the list of variables as global attribute (this is used by restart runs and by
+!--        combine_plot_fields)
+           nc_stat = NF90_PUT_ATT( id_set_surf(av), NF90_GLOBAL, 'VAR_LIST', var_list )
+           CALL netcdf_handle_error( 'surface_data_output_init', 5568 )
+
+!
+!--        Set general no fill, otherwise the performance drops significantly for parallel output.
+           nc_stat = NF90_SET_FILL( id_set_surf(av), NF90_NOFILL, oldmode )
+           CALL netcdf_handle_error( 'surface_data_output_init', 5569 )
+
+!
+!--        Leave netCDF define mode
+           nc_stat = NF90_ENDDEF( id_set_surf(av) )
+           CALL netcdf_handle_error( 'surface_data_output_init', 5570 )
+
+!
+!--        These data are only written by PE0 for parallel output to increase the performance.
+           IF ( myid == 0 )  THEN
+!
+!--           Write data for surface indices
+              ALLOCATE( netcdf_data_1d(1:surfaces%ns_total) )
+
+              DO  i = 1, surfaces%ns_total
+                 netcdf_data_1d(i) = i
+              ENDDO
+
+              nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_s_surf(av), netcdf_data_1d,          &
+                                      start = (/ 1 /), count = (/ surfaces%ns_total /) )
+              CALL netcdf_handle_error( 'surface_data_output_init', 5571 )
+
+              DEALLOCATE( netcdf_data_1d )
+
+           ENDIF
+
+!
+!--        Write surface positions to file
+           nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_xs_surf(av),                            &
+                                   surfaces%xs, start = (/ surfaces%s(1) /),                       &
+                                   count = (/ surfaces%ns /) )
+           CALL netcdf_handle_error( 'surface_data_output_init', 5572 )
+
+           nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_ys_surf(av), surfaces%ys,               &
+                                   start = (/ surfaces%s(1) /), count = (/ surfaces%ns /) )
+           CALL netcdf_handle_error( 'surface_data_output_init', 5573 )
+
+           nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_zs_surf(av), surfaces%zs,               &
+                                   start = (/ surfaces%s(1) /), count = (/ surfaces%ns /) )
+           CALL netcdf_handle_error( 'surface_data_output_init', 5574 )
+
+           nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_etum_surf(av), surfaces%es_utm,         &
+                                   start = (/ surfaces%s(1) /), count = (/ surfaces%ns /) )
+           CALL netcdf_handle_error( 'surface_data_output_init', 5575 )
+
+           nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_nutm_surf(av), surfaces%ns_utm,         &
+                                   start = (/ surfaces%s(1) /), count = (/ surfaces%ns /) )
+           CALL netcdf_handle_error( 'surface_data_output_init', 5576 )
+
+           nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_azimuth_surf(av), surfaces%azimuth,     &
+                                   start = (/ surfaces%s(1) /), count = (/ surfaces%ns /) )
+           CALL netcdf_handle_error( 'surface_data_output_init', 5585 )
+
+           nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_zenith_surf(av), surfaces%zenith,       &
+                                   start = (/ surfaces%s(1) /), count = (/ surfaces%ns /) )
+           CALL netcdf_handle_error( 'surface_data_output_init', 5586 )
+
+          ENDDO
+#endif
+
+     ENDIF
+
+ END SUBROUTINE surface_data_output_init
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Routine for controlling the data output. Surface data is collected from different types of
+!> surfaces (default, natural, urban) and different orientation and written to one 1D-output array.
+!> Further, NetCDF routines are called to write the surface data in the respective NetCDF files.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output( av )
+
+    USE control_parameters,                                                                        &
+        ONLY:  io_blocks,                                                                          &
+               io_group,                                                                           &
+               time_since_reference_point
+
+#if defined( __parallel )
+    USE pegrid,                                                                                    &
+        ONLY:  comm2d,                                                                             &
+               ierr
+#endif
+
+
+    IMPLICIT NONE
+
+    CHARACTER(LEN=100) ::  trimvar = ' '  !< dummy for single output variable
+
+    INTEGER(iwp) ::  av     !< id indicating average or non-average data output
+    INTEGER(iwp) ::  i      !< loop index
+    INTEGER(iwp) ::  l      !< running index for surface orientation
+    INTEGER(iwp) ::  m      !< running index for surface elements
+    INTEGER(iwp) ::  n_out  !< counter variables for surface output
+
+!
+!-- Return, if nothing to output
+    IF ( dosurf_no(av) == 0 )  RETURN
+!
+!-- In case of VTK output, check if binary files are open and write coordinates.
+    IF ( to_vtk )  THEN
+
+       CALL check_open( 25 + av )
+
+       IF ( .NOT. first_output(av) )  THEN
+          DO  i = 0, io_blocks - 1
+             IF ( i == io_group )  THEN
+                WRITE ( 25 + av )  surfaces%npoints
+                WRITE ( 25 + av )  surfaces%npoints_total
+                WRITE ( 25 + av )  surfaces%ns
+                WRITE ( 25 + av )  surfaces%ns_total
+                WRITE ( 25 + av )  surfaces%points
+                WRITE ( 25 + av )  surfaces%polygons
+             ENDIF
+#if defined( __parallel )
+             CALL MPI_BARRIER( comm2d, ierr )
+#endif
+             first_output(av) = .TRUE.
+          ENDDO
+       ENDIF
+    ENDIF
+!
+!-- In case of NetCDF output, check if enough time steps are available in file and update time axis.
+    IF ( to_netcdf )  THEN
+#if defined( __netcdf4_parallel )
+       IF ( dosurf_time_count(av) + 1 > ntdim_surf(av) )  THEN
+          WRITE ( message_string, * ) 'Output of surface data is not given at t=',                 &
+                                      time_since_reference_point, 's because the maximum ',        &
+                                      'number of output time levels is exceeded.'
+          CALL message( 'surface_data_output', 'PA0539', 0, 1, 0, 6, 0 )
+
+          RETURN
+
+       ENDIF
+!
+!--    Update the netCDF time axis
+!--    In case of parallel output, this is only done by PE0 to increase the performance.
+       dosurf_time_count(av) = dosurf_time_count(av) + 1
+       IF ( myid == 0 )  THEN
+          nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_time_surf(av),                           &
+                                  (/ time_since_reference_point /),                                &
+                                  start = (/ dosurf_time_count(av) /), count = (/ 1 /) )
+          CALL netcdf_handle_error( 'surface_data_output', 6666 )
+       ENDIF
+#endif
+    ENDIF
+
+!
+!-- Cycle through output quantities and write them to file.
+    n_out = 0
+    DO  WHILE ( dosurf(av,n_out+1)(1:1) /= ' ' )
+
+       n_out   = n_out + 1
+       trimvar = TRIM( dosurf(av,n_out) )
+!
+!--    Set the output array to the _FillValue in case it is not defined for each type of surface.
+       surfaces%var_out = surfaces%fillvalue
+       SELECT CASE ( trimvar )
+
+          CASE ( 'us' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%us, surf_def_h(1)%us,              &
+                                                  surf_lsm_h%us, surf_usm_h%us, surf_def_v(0)%us,  &
+                                                  surf_lsm_v(0)%us, surf_usm_v(0)%us,              &
+                                                  surf_def_v(1)%us, surf_lsm_v(1)%us,              &
+                                                  surf_usm_v(1)%us, surf_def_v(2)%us,              &
+                                                  surf_lsm_v(2)%us, surf_usm_v(2)%us,              &
+                                                  surf_def_v(3)%us, surf_lsm_v(3)%us,              &
+                                                  surf_usm_v(3)%us )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'ts' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%ts, surf_def_h(1)%ts,              &
+                                                  surf_lsm_h%ts, surf_usm_h%ts, surf_def_v(0)%ts,  &
+                                                  surf_lsm_v(0)%ts, surf_usm_v(0)%ts,              &
+                                                  surf_def_v(1)%ts, surf_lsm_v(1)%ts,              &
+                                                  surf_usm_v(1)%ts, surf_def_v(2)%ts,              &
+                                                  surf_lsm_v(2)%ts, surf_usm_v(2)%ts,              &
+                                                  surf_def_v(3)%ts, surf_lsm_v(3)%ts,              &
+                                                  surf_usm_v(3)%ts )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'qs' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%qs, surf_def_h(1)%qs,              &
+                                                  surf_lsm_h%qs, surf_usm_h%qs, surf_def_v(0)%qs,  &
+                                                  surf_lsm_v(0)%qs, surf_usm_v(0)%qs,              &
+                                                  surf_def_v(1)%qs, surf_lsm_v(1)%qs,              &
+                                                  surf_usm_v(1)%qs, surf_def_v(2)%qs,              &
+                                                  surf_lsm_v(2)%qs, surf_usm_v(2)%qs,              &
+                                                  surf_def_v(3)%qs, surf_lsm_v(3)%qs,              &
+                                                  surf_usm_v(3)%qs )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'ss' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%ss, surf_def_h(1)%ss,              &
+                                                  surf_lsm_h%ss, surf_usm_h%ss, surf_def_v(0)%ss,  &
+                                                  surf_lsm_v(0)%ss, surf_usm_v(0)%ss,              &
+                                                  surf_def_v(1)%ss, surf_lsm_v(1)%ss,              &
+                                                  surf_usm_v(1)%ss, surf_def_v(2)%ss,              &
+                                                  surf_lsm_v(2)%ss, surf_usm_v(2)%ss,              &
+                                                  surf_def_v(3)%ss, surf_lsm_v(3)%ss,              &
+                                                  surf_usm_v(3)%ss )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'qcs' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%qcs, surf_def_h(1)%qcs,            &
+                                                  surf_lsm_h%qcs, surf_usm_h%qcs,                  &
+                                                  surf_def_v(0)%qcs, surf_lsm_v(0)%qcs,            &
+                                                  surf_usm_v(0)%qcs, surf_def_v(1)%qcs,            &
+                                                  surf_lsm_v(1)%qcs, surf_usm_v(1)%qcs,            &
+                                                  surf_def_v(2)%qcs, surf_lsm_v(2)%qcs,            &
+                                                  surf_usm_v(2)%qcs, surf_def_v(3)%qcs,            &
+                                                  surf_lsm_v(3)%qcs, surf_usm_v(3)%qcs )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'ncs' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%ncs, surf_def_h(1)%ncs,            &
+                                                 surf_lsm_h%ncs, surf_usm_h%ncs,                   &
+                                                 surf_def_v(0)%ncs, surf_lsm_v(0)%ncs,             &
+                                                 surf_usm_v(0)%ncs, surf_def_v(1)%ncs,             &
+                                                 surf_lsm_v(1)%ncs, surf_usm_v(1)%ncs,             &
+                                                 surf_def_v(2)%ncs, surf_lsm_v(2)%ncs,             &
+                                                 surf_usm_v(2)%ncs, surf_def_v(3)%ncs,             &
+                                                 surf_lsm_v(3)%ncs, surf_usm_v(3)%ncs )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'qis' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%qis, surf_def_h(1)%qis,            &
+                                                  surf_lsm_h%qis, surf_usm_h%qis,                  &
+                                                  surf_def_v(0)%qis, surf_lsm_v(0)%qis,            &
+                                                  surf_usm_v(0)%qis, surf_def_v(1)%qis,            &
+                                                  surf_lsm_v(1)%qis, surf_usm_v(1)%qis,            &
+                                                  surf_def_v(2)%qis, surf_lsm_v(2)%qis,            &
+                                                  surf_usm_v(2)%qis, surf_def_v(3)%qis,            &
+                                                  surf_lsm_v(3)%qis, surf_usm_v(3)%qis )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'nis' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%nis, surf_def_h(1)%nis,            &
+                                                  surf_lsm_h%nis, surf_usm_h%nis,                  &
+                                                  surf_def_v(0)%nis, surf_lsm_v(0)%nis,            &
+                                                  surf_usm_v(0)%nis, surf_def_v(1)%nis,            &
+                                                  surf_lsm_v(1)%nis, surf_usm_v(1)%nis,            &
+                                                  surf_def_v(2)%nis, surf_lsm_v(2)%nis,            &
+                                                  surf_usm_v(2)%nis, surf_def_v(3)%nis,            &
+                                                  surf_lsm_v(3)%nis, surf_usm_v(3)%nis )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'qrs' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%qrs, surf_def_h(1)%qrs,            &
+                                                  surf_lsm_h%qrs, surf_usm_h%qrs,                  &
+                                                  surf_def_v(0)%qrs, surf_lsm_v(0)%qrs,            &
+                                                  surf_usm_v(0)%qrs, surf_def_v(1)%qrs,            &
+                                                  surf_lsm_v(1)%qrs, surf_usm_v(1)%qrs,            &
+                                                  surf_def_v(2)%qrs, surf_lsm_v(2)%qrs,            &
+                                                  surf_usm_v(2)%qrs, surf_def_v(3)%qrs,            &
+                                                  surf_lsm_v(3)%qrs, surf_usm_v(3)%qrs )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'nrs' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%nrs, surf_def_h(1)%nrs,            &
+                                                  surf_lsm_h%nrs, surf_usm_h%nrs,                  &
+                                                  surf_def_v(0)%nrs, surf_lsm_v(0)%nrs,            &
+                                                  surf_usm_v(0)%nrs, surf_def_v(1)%nrs,            &
+                                                  surf_lsm_v(1)%nrs, surf_usm_v(1)%nrs,            &
+                                                  surf_def_v(2)%nrs, surf_lsm_v(2)%nrs,            &
+                                                  surf_usm_v(2)%nrs, surf_def_v(3)%nrs,            &
+                                                  surf_lsm_v(3)%nrs, surf_usm_v(3)%nrs )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'ol' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%ol, surf_def_h(1)%ol,              &
+                                                  surf_lsm_h%ol, surf_usm_h%ol, surf_def_v(0)%ol,  &
+                                                  surf_lsm_v(0)%ol, surf_usm_v(0)%ol,              &
+                                                  surf_def_v(1)%ol, surf_lsm_v(1)%ol,              &
+                                                  surf_usm_v(1)%ol, surf_def_v(2)%ol,              &
+                                                  surf_lsm_v(2)%ol, surf_usm_v(2)%ol,              &
+                                                  surf_def_v(3)%ol, surf_lsm_v(3)%ol,              &
+                                                  surf_usm_v(3)%ol )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'z0' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%z0, surf_def_h(1)%z0,              &
+                                                  surf_lsm_h%z0, surf_usm_h%z0, surf_def_v(0)%z0,  &
+                                                  surf_lsm_v(0)%z0, surf_usm_v(0)%z0,              &
+                                                  surf_def_v(1)%z0, surf_lsm_v(1)%z0,              &
+                                                  surf_usm_v(1)%z0, surf_def_v(2)%z0,              &
+                                                  surf_lsm_v(2)%z0, surf_usm_v(2)%z0,              &
+                                                  surf_def_v(3)%z0, surf_lsm_v(3)%z0,              &
+                                                  surf_usm_v(3)%z0 )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'z0h' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%z0h, surf_def_h(1)%z0h,            &
+                                                  surf_lsm_h%z0h, surf_usm_h%z0h,                  &
+                                                  surf_def_v(0)%z0h, surf_lsm_v(0)%z0h,            &
+                                                  surf_usm_v(0)%z0h, surf_def_v(1)%z0h,            &
+                                                  surf_lsm_v(1)%z0h, surf_usm_v(1)%z0h,            &
+                                                  surf_def_v(2)%z0h, surf_lsm_v(2)%z0h,            &
+                                                  surf_usm_v(2)%z0h, surf_def_v(3)%z0h,            &
+                                                  surf_lsm_v(3)%z0h, surf_usm_v(3)%z0h )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'z0q' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%z0q, surf_def_h(1)%z0q,            &
+                                                  surf_lsm_h%z0q, surf_usm_h%z0q,                  &
+                                                  surf_def_v(0)%z0q, surf_lsm_v(0)%z0q,            &
+                                                  surf_usm_v(0)%z0q, surf_def_v(1)%z0q,            &
+                                                  surf_lsm_v(1)%z0q, surf_usm_v(1)%z0q,            &
+                                                  surf_def_v(2)%z0q, surf_lsm_v(2)%z0q,            &
+                                                  surf_usm_v(2)%z0q, surf_def_v(3)%z0q,            &
+                                                  surf_lsm_v(3)%z0q, surf_usm_v(3)%z0q )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'theta1' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%pt1, surf_def_h(1)%pt1,            &
+                                                  surf_lsm_h%pt1, surf_usm_h%pt1,                  &
+                                                  surf_def_v(0)%pt1, surf_lsm_v(0)%pt1,            &
+                                                  surf_usm_v(0)%pt1, surf_def_v(1)%pt1,            &
+                                                  surf_lsm_v(1)%pt1, surf_usm_v(1)%pt1,            &
+                                                  surf_def_v(2)%pt1, surf_lsm_v(2)%pt1,            &
+                                                  surf_usm_v(2)%pt1, surf_def_v(3)%pt1,            &
+                                                  surf_lsm_v(3)%pt1, surf_usm_v(3)%pt1 )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'qv1' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%qv1, surf_def_h(1)%qv1,            &
+                                                  surf_lsm_h%qv1, surf_usm_h%qv1,                  &
+                                                  surf_def_v(0)%qv1, surf_lsm_v(0)%qv1,            &
+                                                  surf_usm_v(0)%qv1, surf_def_v(1)%qv1,            &
+                                                  surf_lsm_v(1)%qv1, surf_usm_v(1)%qv1,            &
+                                                  surf_def_v(2)%qv1, surf_lsm_v(2)%qv1,            &
+                                                  surf_usm_v(2)%qv1, surf_def_v(3)%qv1,            &
+                                                  surf_lsm_v(3)%qv1, surf_usm_v(3)%qv1 )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'thetav1' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%vpt1, surf_def_h(1)%vpt1,          &
+                                                  surf_lsm_h%vpt1, surf_usm_h%vpt1,                &
+                                                  surf_def_v(0)%vpt1, surf_lsm_v(0)%vpt1,          &
+                                                  surf_usm_v(0)%vpt1, surf_def_v(1)%vpt1,          &
+                                                  surf_lsm_v(1)%vpt1, surf_usm_v(1)%vpt1,          &
+                                                  surf_def_v(2)%vpt1, surf_lsm_v(2)%vpt1,          &
+                                                  surf_usm_v(2)%vpt1, surf_def_v(3)%vpt1,          &
+                                                  surf_lsm_v(3)%vpt1, surf_usm_v(3)%vpt1 )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'usws' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%usws, surf_def_h(1)%usws,          &
+                                                  surf_lsm_h%usws, surf_usm_h%usws,                &
+                                                  surf_def_v(0)%usws, surf_lsm_v(0)%usws,          &
+                                                  surf_usm_v(0)%usws, surf_def_v(1)%usws,          &
+                                                  surf_lsm_v(1)%usws, surf_usm_v(1)%usws,          &
+                                                  surf_def_v(2)%usws, surf_lsm_v(2)%usws,          &
+                                                  surf_usm_v(2)%usws, surf_def_v(3)%usws,          &
+                                                  surf_lsm_v(3)%usws, surf_usm_v(3)%usws,          &
+                                                  momentumflux_output_conversion )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'vsws' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%vsws, surf_def_h(1)%vsws,          &
+                                                  surf_lsm_h%vsws, surf_usm_h%vsws,                &
+                                                  surf_def_v(0)%vsws, surf_lsm_v(0)%vsws,          &
+                                                  surf_usm_v(0)%vsws, surf_def_v(1)%vsws,          &
+                                                  surf_lsm_v(1)%vsws, surf_usm_v(1)%vsws,          &
+                                                  surf_def_v(2)%vsws, surf_lsm_v(2)%vsws,          &
+                                                  surf_usm_v(2)%vsws, surf_def_v(3)%vsws,          &
+                                                  surf_lsm_v(3)%vsws, surf_usm_v(3)%vsws,          &
+                                                  momentumflux_output_conversion )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'shf' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%shf, surf_def_h(1)%shf,            &
+                                                  surf_lsm_h%shf, surf_usm_h%shf,                  &
+                                                  surf_def_v(0)%shf, surf_lsm_v(0)%shf,            &
+                                                  surf_usm_v(0)%shf, surf_def_v(1)%shf,            &
+                                                  surf_lsm_v(1)%shf, surf_usm_v(1)%shf,            &
+                                                  surf_def_v(2)%shf, surf_lsm_v(2)%shf,            &
+                                                  surf_usm_v(2)%shf, surf_def_v(3)%shf,            &
+                                                  surf_lsm_v(3)%shf, surf_usm_v(3)%shf,            &
+                                                  heatflux_output_conversion )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+             ENDIF
+
+          CASE ( 'qsws' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%qsws, surf_def_h(1)%qsws,          &
+                                                  surf_lsm_h%qsws, surf_usm_h%qsws,                &
+                                                  surf_def_v(0)%qsws, surf_lsm_v(0)%qsws,          &
+                                                  surf_usm_v(0)%qsws, surf_def_v(1)%qsws,          &
+                                                  surf_lsm_v(1)%qsws, surf_usm_v(1)%qsws,          &
+                                                  surf_def_v(2)%qsws, surf_lsm_v(2)%qsws,          &
+                                                  surf_usm_v(2)%qsws, surf_def_v(3)%qsws,          &
+                                                  surf_lsm_v(3)%qsws, surf_usm_v(3)%qsws,          &
+                                                  waterflux_output_conversion )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'ssws' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%ssws, surf_def_h(1)%ssws,          &
+                                                  surf_lsm_h%ssws, surf_usm_h%ssws,                &
+                                                  surf_def_v(0)%ssws, surf_lsm_v(0)%ssws,          &
+                                                  surf_usm_v(0)%ssws, surf_def_v(1)%ssws,          &
+                                                  surf_lsm_v(1)%ssws, surf_usm_v(1)%ssws,          &
+                                                  surf_def_v(2)%ssws, surf_lsm_v(2)%ssws,          &
+                                                  surf_usm_v(2)%ssws, surf_def_v(3)%ssws,          &
+                                                  surf_lsm_v(3)%ssws, surf_usm_v(3)%ssws )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'qcsws' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%qcsws, surf_def_h(1)%qcsws,        &
+                                                  surf_lsm_h%qcsws, surf_usm_h%qcsws,              &
+                                                  surf_def_v(0)%qcsws, surf_lsm_v(0)%qcsws,        &
+                                                  surf_usm_v(0)%qcsws, surf_def_v(1)%qcsws,        &
+                                                  surf_lsm_v(1)%qcsws, surf_usm_v(1)%qcsws,        &
+                                                  surf_def_v(2)%qcsws, surf_lsm_v(2)%qcsws,        &
+                                                  surf_usm_v(2)%qcsws, surf_def_v(3)%qcsws,        &
+                                                  surf_lsm_v(3)%qcsws, surf_usm_v(3)%qcsws )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'ncsws' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%ncsws, surf_def_h(1)%ncsws,        &
+                                                  surf_lsm_h%ncsws, surf_usm_h%ncsws,              &
+                                                  surf_def_v(0)%ncsws, surf_lsm_v(0)%ncsws,        &
+                                                  surf_usm_v(0)%ncsws, surf_def_v(1)%ncsws,        &
+                                                  surf_lsm_v(1)%ncsws, surf_usm_v(1)%ncsws,        &
+                                                  surf_def_v(2)%ncsws, surf_lsm_v(2)%ncsws,        &
+                                                  surf_usm_v(2)%ncsws, surf_def_v(3)%ncsws,        &
+                                                  surf_lsm_v(3)%ncsws, surf_usm_v(3)%ncsws )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+
+          CASE ( 'qisws' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%qisws, surf_def_h(1)%qisws,        &
+                                                  surf_lsm_h%qisws, surf_usm_h%qisws,              &
+                                                  surf_def_v(0)%qisws, surf_lsm_v(0)%qisws,        &
+                                                  surf_usm_v(0)%qisws, surf_def_v(1)%qisws,        &
+                                                  surf_lsm_v(1)%qisws, surf_usm_v(1)%qisws,        &
+                                                  surf_def_v(2)%qisws, surf_lsm_v(2)%qisws,        &
+                                                  surf_usm_v(2)%qisws, surf_def_v(3)%qisws,        &
+                                                  surf_lsm_v(3)%qisws, surf_usm_v(3)%qisws )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'nisws' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%nisws, surf_def_h(1)%nisws,        &
+                                                  surf_lsm_h%nisws, surf_usm_h%nisws,              &
+                                                  surf_def_v(0)%nisws, surf_lsm_v(0)%nisws,        &
+                                                  surf_usm_v(0)%nisws, surf_def_v(1)%nisws,        &
+                                                  surf_lsm_v(1)%nisws, surf_usm_v(1)%nisws,        &
+                                                  surf_def_v(2)%nisws, surf_lsm_v(2)%nisws,        &
+                                                  surf_usm_v(2)%nisws, surf_def_v(3)%nisws,        &
+                                                  surf_lsm_v(3)%nisws, surf_usm_v(3)%nisws )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'qrsws' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%qrsws, surf_def_h(1)%qrsws,        &
+                                                  surf_lsm_h%qrsws, surf_usm_h%qrsws,              &
+                                                  surf_def_v(0)%qrsws, surf_lsm_v(0)%qrsws,        &
+                                                  surf_usm_v(0)%qrsws, surf_def_v(1)%qrsws,        &
+                                                  surf_lsm_v(1)%qrsws, surf_usm_v(1)%qrsws,        &
+                                                  surf_def_v(2)%qrsws, surf_lsm_v(2)%qrsws,        &
+                                                  surf_usm_v(2)%qrsws, surf_def_v(3)%qrsws,        &
+                                                  surf_lsm_v(3)%qrsws, surf_usm_v(3)%qrsws )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'nrsws' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%nrsws, surf_def_h(1)%nrsws,        &
+                                                  surf_lsm_h%nrsws, surf_usm_h%nrsws,              &
+                                                  surf_def_v(0)%nrsws, surf_lsm_v(0)%nrsws,        &
+                                                  surf_usm_v(0)%nrsws, surf_def_v(1)%nrsws,        &
+                                                  surf_lsm_v(1)%nrsws, surf_usm_v(1)%nrsws,        &
+                                                  surf_def_v(2)%nrsws, surf_lsm_v(2)%nrsws,        &
+                                                  surf_usm_v(2)%nrsws, surf_def_v(3)%nrsws,        &
+                                                  surf_lsm_v(3)%nrsws, surf_usm_v(3)%nrsws )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'sasws' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%sasws, surf_def_h(1)%sasws,        &
+                                                  surf_lsm_h%sasws, surf_usm_h%sasws,              &
+                                                  surf_def_v(0)%sasws, surf_lsm_v(0)%sasws,        &
+                                                  surf_usm_v(0)%sasws, surf_def_v(1)%sasws,        &
+                                                  surf_lsm_v(1)%sasws, surf_usm_v(1)%sasws,        &
+                                                  surf_def_v(2)%sasws, surf_lsm_v(2)%sasws,        &
+                                                  surf_usm_v(2)%sasws, surf_def_v(3)%sasws,        &
+                                                  surf_lsm_v(3)%sasws, surf_usm_v(3)%sasws )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'q_surface' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%q_surface, surf_def_h(1)%q_surface,&
+                                                  surf_lsm_h%q_surface, surf_usm_h%q_surface,      &
+                                                  surf_def_v(0)%q_surface, surf_lsm_v(0)%q_surface,&
+                                                  surf_usm_v(0)%q_surface, surf_def_v(1)%q_surface,&
+                                                  surf_lsm_v(1)%q_surface, surf_usm_v(1)%q_surface,&
+                                                  surf_def_v(2)%q_surface, surf_lsm_v(2)%q_surface,&
+                                                  surf_usm_v(2)%q_surface, surf_def_v(3)%q_surface,&
+                                                  surf_lsm_v(3)%q_surface, surf_usm_v(3)%q_surface )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'theta_surface' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%pt_surface,                        &
+                                                  surf_def_h(1)%pt_surface,                        &
+                                                  surf_lsm_h%pt_surface, surf_usm_h%pt_surface,    &
+                                                  surf_def_v(0)%pt_surface,                        &
+                                                  surf_lsm_v(0)%pt_surface,                        &
+                                                  surf_usm_v(0)%pt_surface,                        &
+                                                  surf_def_v(1)%pt_surface,                        &
+                                                  surf_lsm_v(1)%pt_surface,                        &
+                                                  surf_usm_v(1)%pt_surface,                        &
+                                                  surf_def_v(2)%pt_surface,                        &
+                                                  surf_lsm_v(2)%pt_surface,                        &
+                                                  surf_usm_v(2)%pt_surface,                        &
+                                                  surf_def_v(3)%pt_surface,                        &
+                                                  surf_lsm_v(3)%pt_surface,                        &
+                                                  surf_usm_v(3)%pt_surface )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'thetav_surface' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%vpt_surface,                       &
+                                                  surf_def_h(1)%vpt_surface,                       &
+                                                  surf_lsm_h%vpt_surface, surf_usm_h%vpt_surface,  &
+                                                  surf_def_v(0)%vpt_surface,                       &
+                                                  surf_lsm_v(0)%vpt_surface,                       &
+                                                  surf_usm_v(0)%vpt_surface,                       &
+                                                  surf_def_v(1)%vpt_surface,                       &
+                                                  surf_lsm_v(1)%vpt_surface,                       &
+                                                  surf_usm_v(1)%vpt_surface,                       &
+                                                  surf_def_v(2)%vpt_surface,                       &
+                                                  surf_lsm_v(2)%vpt_surface,                       &
+                                                  surf_usm_v(2)%vpt_surface,                       &
+                                                  surf_def_v(3)%vpt_surface,                       &
+                                                  surf_lsm_v(3)%vpt_surface,                       &
+                                                  surf_usm_v(3)%vpt_surface)
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_net' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_net, surf_def_h(1)%rad_net,    &
+                                                  surf_lsm_h%rad_net, surf_usm_h%rad_net,          &
+                                                  surf_def_v(0)%rad_net, surf_lsm_v(0)%rad_net,    &
+                                                  surf_usm_v(0)%rad_net, surf_def_v(1)%rad_net,    &
+                                                  surf_lsm_v(1)%rad_net, surf_usm_v(1)%rad_net,    &
+                                                  surf_def_v(2)%rad_net, surf_lsm_v(2)%rad_net,    &
+                                                  surf_usm_v(2)%rad_net, surf_def_v(3)%rad_net,    &
+                                                  surf_lsm_v(3)%rad_net, surf_usm_v(3)%rad_net )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_lw_in' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_lw_in,                         &
+                                                  surf_def_h(1)%rad_lw_in, surf_lsm_h%rad_lw_in,   &
+                                                  surf_usm_h%rad_lw_in, surf_def_v(0)%rad_lw_in,   &
+                                                  surf_lsm_v(0)%rad_lw_in,                         &
+                                                  surf_usm_v(0)%rad_lw_in,                         &
+                                                  surf_def_v(1)%rad_lw_in,                         &
+                                                  surf_lsm_v(1)%rad_lw_in,                         &
+                                                  surf_usm_v(1)%rad_lw_in,                         &
+                                                  surf_def_v(2)%rad_lw_in,                         &
+                                                  surf_lsm_v(2)%rad_lw_in,                         &
+                                                  surf_usm_v(2)%rad_lw_in,                         &
+                                                  surf_def_v(3)%rad_lw_in,                         &
+                                                  surf_lsm_v(3)%rad_lw_in,                         &
+                                                  surf_usm_v(3)%rad_lw_in )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_lw_out' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_lw_out,                        &
+                                                  surf_def_h(1)%rad_lw_out, surf_lsm_h%rad_lw_out, &
+                                                  surf_usm_h%rad_lw_out, surf_def_v(0)%rad_lw_out, &
+                                                  surf_lsm_v(0)%rad_lw_out,                        &
+                                                  surf_usm_v(0)%rad_lw_out,                        &
+                                                  surf_def_v(1)%rad_lw_out,                        &
+                                                  surf_lsm_v(1)%rad_lw_out,                        &
+                                                  surf_usm_v(1)%rad_lw_out,                        &
+                                                  surf_def_v(2)%rad_lw_out,                        &
+                                                  surf_lsm_v(2)%rad_lw_out,                        &
+                                                  surf_usm_v(2)%rad_lw_out,                        &
+                                                  surf_def_v(3)%rad_lw_out,                        &
+                                                  surf_lsm_v(3)%rad_lw_out,                        &
+                                                  surf_usm_v(3)%rad_lw_out )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_sw_in' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_sw_in,                         &
+                                                  surf_def_h(1)%rad_sw_in, surf_lsm_h%rad_sw_in,   &
+                                                  surf_usm_h%rad_sw_in, surf_def_v(0)%rad_sw_in,   &
+                                                  surf_lsm_v(0)%rad_sw_in,                         &
+                                                  surf_usm_v(0)%rad_sw_in,                         &
+                                                  surf_def_v(1)%rad_sw_in,                         &
+                                                  surf_lsm_v(1)%rad_sw_in,                         &
+                                                  surf_usm_v(1)%rad_sw_in,                         &
+                                                  surf_def_v(2)%rad_sw_in,                         &
+                                                  surf_lsm_v(2)%rad_sw_in,                         &
+                                                  surf_usm_v(2)%rad_sw_in,                         &
+                                                  surf_def_v(3)%rad_sw_in,                         &
+                                                  surf_lsm_v(3)%rad_sw_in,                         &
+                                                  surf_usm_v(3)%rad_sw_in )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_sw_out' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_sw_out,                        &
+                                                  surf_def_h(1)%rad_sw_out, surf_lsm_h%rad_sw_out, &
+                                                  surf_usm_h%rad_sw_out, surf_def_v(0)%rad_sw_out, &
+                                                  surf_lsm_v(0)%rad_sw_out,                        &
+                                                  surf_usm_v(0)%rad_sw_out,                        &
+                                                  surf_def_v(1)%rad_sw_out,                        &
+                                                  surf_lsm_v(1)%rad_sw_out,                        &
+                                                  surf_usm_v(1)%rad_sw_out,                        &
+                                                  surf_def_v(2)%rad_sw_out,                        &
+                                                  surf_lsm_v(2)%rad_sw_out,                        &
+                                                  surf_usm_v(2)%rad_sw_out,                        &
+                                                  surf_def_v(3)%rad_sw_out,                        &
+                                                  surf_lsm_v(3)%rad_sw_out,                        &
+                                                  surf_usm_v(3)%rad_sw_out )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'ghf' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+!
+!--             Sum up ground / wall heat flux. Note, for urban surfaces the wall heat flux is
+!--             aggregated from the different green, window and wall tiles.
+                DO  m = 1, surf_usm_h%ns
+                   surf_usm_h%ghf(m) = surf_usm_h%frac(m,ind_veg_wall) * surf_usm_h%wghf_eb(m) +   &
+                                       surf_usm_h%frac(m,ind_pav_green) *                          &
+                                       surf_usm_h%wghf_eb_green(m) +                               &
+                                       surf_usm_h%frac(m,ind_wat_win) *                            &
+                                       surf_usm_h%wghf_eb_window(m)
+                ENDDO
+                DO  l = 0, 3
+                   DO  m = 1, surf_usm_v(l)%ns
+                      surf_usm_v(l)%ghf(m) = surf_usm_v(l)%frac(m,ind_veg_wall) *                  &
+                                             surf_usm_v(l)%wghf_eb(m) +                            &
+                                             surf_usm_v(l)%frac(m,ind_pav_green) *                 &
+                                             surf_usm_v(l)%wghf_eb_green(m) +                      &
+                                             surf_usm_v(l)%frac(m,ind_wat_win) *                   &
+                                             surf_usm_v(l)%wghf_eb_window(m)
+                   ENDDO
+                ENDDO
+
+                CALL surface_data_output_collect( surf_def_h(0)%ghf, surf_def_h(1)%ghf,            &
+                                                  surf_lsm_h%ghf, surf_usm_h%ghf,                  &
+                                                  surf_def_v(0)%ghf, surf_lsm_v(0)%ghf,            &
+                                                  surf_usm_v(0)%ghf, surf_def_v(1)%ghf,            &
+                                                  surf_lsm_v(1)%ghf, surf_usm_v(1)%ghf,            &
+                                                  surf_def_v(2)%ghf, surf_lsm_v(2)%ghf,            &
+                                                  surf_usm_v(2)%ghf, surf_def_v(3)%ghf,            &
+                                                  surf_lsm_v(3)%ghf, surf_usm_v(3)%ghf )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'r_a' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%r_a, surf_def_h(1)%r_a,            &
+                                                  surf_lsm_h%r_a, surf_usm_h%r_a,                  &
+                                                  surf_def_v(0)%r_a, surf_lsm_v(0)%r_a,            &
+                                                  surf_usm_v(0)%r_a, surf_def_v(1)%r_a,            &
+                                                  surf_lsm_v(1)%r_a, surf_usm_v(1)%r_a,            &
+                                                  surf_def_v(2)%r_a, surf_lsm_v(2)%r_a,            &
+                                                  surf_usm_v(2)%r_a, surf_def_v(3)%r_a,            &
+                                                  surf_lsm_v(3)%r_a, surf_usm_v(3)%r_a )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'r_soil' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%r_soil, surf_def_h(1)%r_soil,      &
+                                                  surf_lsm_h%r_soil, surf_usm_h%r_soil,            &
+                                                  surf_def_v(0)%r_soil, surf_lsm_v(0)%r_soil,      &
+                                                  surf_usm_v(0)%r_soil, surf_def_v(1)%r_soil,      &
+                                                  surf_lsm_v(1)%r_soil, surf_usm_v(1)%r_soil,      &
+                                                  surf_def_v(2)%r_soil, surf_lsm_v(2)%r_soil,      &
+                                                  surf_usm_v(2)%r_soil, surf_def_v(3)%r_soil,      &
+                                                  surf_lsm_v(3)%r_soil, surf_usm_v(3)%r_soil )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'r_canopy' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%r_canopy, surf_def_h(1)%r_canopy,  &
+                                                  surf_lsm_h%r_canopy, surf_usm_h%r_canopy,        &
+                                                  surf_def_v(0)%r_canopy, surf_lsm_v(0)%r_canopy,  &
+                                                  surf_usm_v(0)%r_canopy, surf_def_v(1)%r_canopy,  &
+                                                  surf_lsm_v(1)%r_canopy, surf_usm_v(1)%r_canopy,  &
+                                                  surf_def_v(2)%r_canopy, surf_lsm_v(2)%r_canopy,  &
+                                                  surf_usm_v(2)%r_canopy, surf_def_v(3)%r_canopy,  &
+                                                  surf_lsm_v(3)%r_canopy, surf_usm_v(3)%r_canopy )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'r_s' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%r_s, surf_def_h(1)%r_s,            &
+                                                  surf_lsm_h%r_s, surf_usm_h%r_s,                  &
+                                                  surf_def_v(0)%r_s, surf_lsm_v(0)%r_s,            &
+                                                  surf_usm_v(0)%r_s, surf_def_v(1)%r_s,            &
+                                                  surf_lsm_v(1)%r_s, surf_usm_v(1)%r_s,            &
+                                                  surf_def_v(2)%r_s, surf_lsm_v(2)%r_s,            &
+                                                  surf_usm_v(2)%r_s, surf_def_v(3)%r_s,            &
+                                                  surf_lsm_v(3)%r_s, surf_usm_v(3)%r_s )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_sw_dir' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_sw_dir,                        &
+                                                  surf_def_h(1)%rad_sw_dir, surf_lsm_h%rad_sw_dir, &
+                                                  surf_usm_h%rad_sw_dir, surf_def_v(0)%rad_sw_dir, &
+                                                  surf_lsm_v(0)%rad_sw_dir,                        &
+                                                  surf_usm_v(0)%rad_sw_dir,                        &
+                                                  surf_def_v(1)%rad_sw_dir,                        &
+                                                  surf_lsm_v(1)%rad_sw_dir,                        &
+                                                  surf_usm_v(1)%rad_sw_dir,                        &
+                                                  surf_def_v(2)%rad_sw_dir,                        &
+                                                  surf_lsm_v(2)%rad_sw_dir,                        &
+                                                  surf_usm_v(2)%rad_sw_dir,                        &
+                                                  surf_def_v(3)%rad_sw_dir,                        &
+                                                  surf_lsm_v(3)%rad_sw_dir,                        &
+                                                  surf_usm_v(3)%rad_sw_dir )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_sw_dif' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_sw_dif,                        &
+                                                  surf_def_h(1)%rad_sw_dif, surf_lsm_h%rad_sw_dif, &
+                                                  surf_usm_h%rad_sw_dif, surf_def_v(0)%rad_sw_dif, &
+                                                  surf_lsm_v(0)%rad_sw_dif,                        &
+                                                  surf_usm_v(0)%rad_sw_dif,                        &
+                                                  surf_def_v(1)%rad_sw_dif,                        &
+                                                  surf_lsm_v(1)%rad_sw_dif,                        &
+                                                  surf_usm_v(1)%rad_sw_dif,                        &
+                                                  surf_def_v(2)%rad_sw_dif,                        &
+                                                  surf_lsm_v(2)%rad_sw_dif,                        &
+                                                  surf_usm_v(2)%rad_sw_dif,                        &
+                                                  surf_def_v(3)%rad_sw_dif,                        &
+                                                  surf_lsm_v(3)%rad_sw_dif,                        &
+                                                  surf_usm_v(3)%rad_sw_dif )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_sw_ref' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_sw_ref,                        &
+                                                  surf_def_h(1)%rad_sw_ref, surf_lsm_h%rad_sw_ref, &
+                                                  surf_usm_h%rad_sw_ref, surf_def_v(0)%rad_sw_ref, &
+                                                  surf_lsm_v(0)%rad_sw_ref,                        &
+                                                  surf_usm_v(0)%rad_sw_ref,                        &
+                                                  surf_def_v(1)%rad_sw_ref,                        &
+                                                  surf_lsm_v(1)%rad_sw_ref,                        &
+                                                  surf_usm_v(1)%rad_sw_ref,                        &
+                                                  surf_def_v(2)%rad_sw_ref,                        &
+                                                  surf_lsm_v(2)%rad_sw_ref,                        &
+                                                  surf_usm_v(2)%rad_sw_ref,                        &
+                                                  surf_def_v(3)%rad_sw_ref,                        &
+                                                  surf_lsm_v(3)%rad_sw_ref,                        &
+                                                  surf_usm_v(3)%rad_sw_ref )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_sw_res' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_sw_res,                        &
+                                                  surf_def_h(1)%rad_sw_res, surf_lsm_h%rad_sw_res, &
+                                                  surf_usm_h%rad_sw_res, surf_def_v(0)%rad_sw_res, &
+                                                  surf_lsm_v(0)%rad_sw_res,                        &
+                                                  surf_usm_v(0)%rad_sw_res,                        &
+                                                  surf_def_v(1)%rad_sw_res,                        &
+                                                  surf_lsm_v(1)%rad_sw_res,                        &
+                                                  surf_usm_v(1)%rad_sw_res,                        &
+                                                  surf_def_v(2)%rad_sw_res,                        &
+                                                  surf_lsm_v(2)%rad_sw_res,                        &
+                                                  surf_usm_v(2)%rad_sw_res,                        &
+                                                  surf_def_v(3)%rad_sw_res,                        &
+                                                  surf_lsm_v(3)%rad_sw_res,                        &
+                                                  surf_usm_v(3)%rad_sw_res )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_lw_dif' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_lw_dif,                        &
+                                                  surf_def_h(1)%rad_lw_dif, surf_lsm_h%rad_lw_dif, &
+                                                  surf_usm_h%rad_lw_dif, surf_def_v(0)%rad_lw_dif, &
+                                                  surf_lsm_v(0)%rad_lw_dif,                        &
+                                                  surf_usm_v(0)%rad_lw_dif,                        &
+                                                  surf_def_v(1)%rad_lw_dif,                        &
+                                                  surf_lsm_v(1)%rad_lw_dif,                        &
+                                                  surf_usm_v(1)%rad_lw_dif,                        &
+                                                  surf_def_v(2)%rad_lw_dif,                        &
+                                                  surf_lsm_v(2)%rad_lw_dif,                        &
+                                                  surf_usm_v(2)%rad_lw_dif,                        &
+                                                  surf_def_v(3)%rad_lw_dif,                        &
+                                                  surf_lsm_v(3)%rad_lw_dif,                        &
+                                                  surf_usm_v(3)%rad_lw_dif )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_lw_ref' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_lw_ref,                        &
+                                                  surf_def_h(1)%rad_lw_ref, surf_lsm_h%rad_lw_ref, &
+                                                  surf_usm_h%rad_lw_ref, surf_def_v(0)%rad_lw_ref, &
+                                                  surf_lsm_v(0)%rad_lw_ref,                        &
+                                                  surf_usm_v(0)%rad_lw_ref,                        &
+                                                  surf_def_v(1)%rad_lw_ref,                        &
+                                                  surf_lsm_v(1)%rad_lw_ref,                        &
+                                                  surf_usm_v(1)%rad_lw_ref,                        &
+                                                  surf_def_v(2)%rad_lw_ref,                        &
+                                                  surf_lsm_v(2)%rad_lw_ref,                        &
+                                                  surf_usm_v(2)%rad_lw_ref,                        &
+                                                  surf_def_v(3)%rad_lw_ref,                        &
+                                                  surf_lsm_v(3)%rad_lw_ref,                        &
+                                                  surf_usm_v(3)%rad_lw_ref )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'rad_lw_res' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%rad_lw_res,                        &
+                                                  surf_def_h(1)%rad_lw_res, surf_lsm_h%rad_lw_res, &
+                                                  surf_usm_h%rad_lw_res, surf_def_v(0)%rad_lw_res, &
+                                                  surf_lsm_v(0)%rad_lw_res,                        &
+                                                  surf_usm_v(0)%rad_lw_res,                        &
+                                                  surf_def_v(1)%rad_lw_res,                        &
+                                                  surf_lsm_v(1)%rad_lw_res,                        &
+                                                  surf_usm_v(1)%rad_lw_res,                        &
+                                                  surf_def_v(2)%rad_lw_res,                        &
+                                                  surf_lsm_v(2)%rad_lw_res,                        &
+                                                  surf_usm_v(2)%rad_lw_res,                        &
+                                                  surf_def_v(3)%rad_lw_res,                        &
+                                                  surf_lsm_v(3)%rad_lw_res,                        &
+                                                  surf_usm_v(3)%rad_lw_res )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+
+          CASE ( 'uvw1' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%uvw_abs,                           &
+                                                  surf_def_h(1)%uvw_abs, surf_lsm_h%uvw_abs,       &
+                                                  surf_usm_h%uvw_abs, surf_def_v(0)%uvw_abs,       &
+                                                  surf_lsm_v(0)%uvw_abs,                           &
+                                                  surf_usm_v(0)%uvw_abs,                           &
+                                                  surf_def_v(1)%uvw_abs,                           &
+                                                  surf_lsm_v(1)%uvw_abs,                           &
+                                                  surf_usm_v(1)%uvw_abs,                           &
+                                                  surf_def_v(2)%uvw_abs,                           &
+                                                  surf_lsm_v(2)%uvw_abs,                           &
+                                                  surf_usm_v(2)%uvw_abs,                           &
+                                                  surf_def_v(3)%uvw_abs,                           &
+                                                  surf_lsm_v(3)%uvw_abs,                           &
+                                                  surf_usm_v(3)%uvw_abs )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+!
+!--       Waste heat from indoor model
+          CASE ( 'waste_heat' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%waste_heat,                        &
+                                                  surf_def_h(1)%waste_heat, surf_lsm_h%waste_heat, &
+                                                  surf_usm_h%waste_heat, surf_def_v(0)%waste_heat, &
+                                                  surf_lsm_v(0)%waste_heat,                        &
+                                                  surf_usm_v(0)%waste_heat,                        &
+                                                  surf_def_v(1)%waste_heat,                        &
+                                                  surf_lsm_v(1)%waste_heat,                        &
+                                                  surf_usm_v(1)%waste_heat,                        &
+                                                  surf_def_v(2)%waste_heat,                        &
+                                                  surf_lsm_v(2)%waste_heat,                        &
+                                                  surf_usm_v(2)%waste_heat,                        &
+                                                  surf_def_v(3)%waste_heat,                        &
+                                                  surf_lsm_v(3)%waste_heat,                        &
+                                                  surf_usm_v(3)%waste_heat )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+!
+!--       Innermost building wall flux from indoor model
+          CASE ( 'im_hf' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%iwghf_eb, surf_def_h(1)%iwghf_eb,  &
+                                                  surf_lsm_h%iwghf_eb, surf_usm_h%iwghf_eb,        &
+                                                  surf_def_v(0)%iwghf_eb, surf_lsm_v(0)%iwghf_eb,  &
+                                                  surf_usm_v(0)%iwghf_eb, surf_def_v(1)%iwghf_eb,  &
+                                                  surf_lsm_v(1)%iwghf_eb, surf_usm_v(1)%iwghf_eb,  &
+                                                  surf_def_v(2)%iwghf_eb, surf_lsm_v(2)%iwghf_eb,  &
+                                                  surf_usm_v(2)%iwghf_eb, surf_def_v(3)%iwghf_eb,  &
+                                                  surf_lsm_v(3)%iwghf_eb, surf_usm_v(3)%iwghf_eb )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+!
+!--       Surface albedo (tile approach)
+          CASE ( 'albedo' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%albedo, surf_def_h(1)%albedo,      &
+                                                  surf_lsm_h%albedo, surf_usm_h%albedo,            &
+                                                  surf_def_v(0)%albedo, surf_lsm_v(0)%albedo,      &
+                                                  surf_usm_v(0)%albedo, surf_def_v(1)%albedo,      &
+                                                  surf_lsm_v(1)%albedo, surf_usm_v(1)%albedo,      &
+                                                  surf_def_v(2)%albedo, surf_lsm_v(2)%albedo,      &
+                                                  surf_usm_v(2)%albedo, surf_def_v(3)%albedo,      &
+                                                  surf_lsm_v(3)%albedo, surf_usm_v(3)%albedo )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+!
+!--       Surface emissivity (tile approach)
+          CASE ( 'emissivity' )
+!
+!--          Output of instantaneous data
+             IF ( av == 0 )  THEN
+                CALL surface_data_output_collect( surf_def_h(0)%emissivity,                        &
+                                                  surf_def_h(1)%emissivity, surf_lsm_h%emissivity, &
+                                                  surf_usm_h%emissivity, surf_def_v(0)%emissivity, &
+                                                  surf_lsm_v(0)%emissivity,                        &
+                                                  surf_usm_v(0)%emissivity,                        &
+                                                  surf_def_v(1)%emissivity,                        &
+                                                  surf_lsm_v(1)%emissivity,                        &
+                                                  surf_usm_v(1)%emissivity,                        &
+                                                  surf_def_v(2)%emissivity,                        &
+                                                  surf_lsm_v(2)%emissivity,                        &
+                                                  surf_usm_v(2)%emissivity,                        &
+                                                  surf_def_v(3)%emissivity,                        &
+                                                  surf_lsm_v(3)%emissivity,                        &
+                                                  surf_usm_v(3)%emissivity )
+             ELSE
+!
+!--             Output of averaged data
+                surfaces%var_out(:) = surfaces%var_av(:,n_out) / REAL( average_count_surf, KIND=wp )
+                surfaces%var_av(:,n_out) = 0.0_wp
+
+             ENDIF
+!
+!--          Add further variables:
+!--          'css', 'cssws', 'qsws_liq', 'qsws_soil', 'qsws_veg'
+
+       END SELECT
+!
+!--    Write to binary file:
+!--    - surfaces%points ( 3, 1-npoints )
+!--    - surfaces%polygons ( 5, 1-ns )
+!--    - surfaces%var_out ( 1-ns, time )
+!--    - Dimension: 1-nsurfaces, 1-npoints - can be ordered consecutively
+!--    - Distinguish between average and non-average data
+       IF ( to_vtk )  THEN
+          DO  i = 0, io_blocks - 1
+             IF ( i == io_group )  THEN
+                WRITE ( 25 + av )  LEN_TRIM( 'time' )
+                WRITE ( 25 + av )  'time'
+                WRITE ( 25 + av )  time_since_reference_point
+                WRITE ( 25 + av )  LEN_TRIM( trimvar )
+                WRITE ( 25 + av )  TRIM( trimvar )
+                WRITE ( 25 + av )  surfaces%var_out
+             ENDIF
+#if defined( __parallel )
+             CALL MPI_BARRIER( comm2d, ierr )
+#endif
+          ENDDO
+       ENDIF
+
+       IF ( to_netcdf )  THEN
+#if defined( __netcdf4_parallel )
+!
+!--       Write output array to file
+          nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_dosurf(av,n_out), surfaces%var_out,      &
+                                  start = (/ surfaces%s(1), dosurf_time_count(av) /),              &
+                                  count = (/ surfaces%ns, 1 /) )
+          CALL netcdf_handle_error( 'surface_data_output', 6667 )
 #endif
        ENDIF
-!
-!--    If output to netcdf is enabled, set-up the coordinate arrays that
-!--    unambiguously describe the position and orientation of each surface
-!--    element.
-       IF ( to_netcdf )  THEN
-!
-!--       Allocate local coordinate arrays
-          ALLOCATE( surfaces%s(1:surfaces%ns)       )
-          ALLOCATE( surfaces%xs(1:surfaces%ns)      )
-          ALLOCATE( surfaces%ys(1:surfaces%ns)      )
-          ALLOCATE( surfaces%zs(1:surfaces%ns)      )
-          ALLOCATE( surfaces%azimuth(1:surfaces%ns) )
-          ALLOCATE( surfaces%zenith(1:surfaces%ns)  )
-          ALLOCATE( surfaces%es_utm(1:surfaces%ns)  )
-          ALLOCATE( surfaces%ns_utm(1:surfaces%ns)  )
-!
-!--       Gather the number of surface on each processor, in order to number
-!--       the surface elements in ascending order with respect to the total
-!--       number of surfaces in the domain.
-#if defined( __parallel )
-          CALL MPI_ALLGATHER( surfaces%ns, 1, MPI_INTEGER,                     &
-                              num_surfaces_on_pe, 1, MPI_INTEGER, comm2d, ierr  )
-#else
-          num_surfaces_on_pe = surfaces%ns
-#endif
-!
-!--       First, however, determine the offset where couting of the surfaces
-!--       should start (the sum of surfaces on all PE's with lower MPI rank).
-          i           = 0
-          start_count = 1
-          DO WHILE ( i < myid  .AND.  i <= SIZE( num_surfaces_on_pe ) )
-             start_count = start_count + num_surfaces_on_pe(i)
-             i           = i + 1
-          ENDDO
-!
-!--       Set coordinate arrays. For horizontal surfaces, azimuth
-!--       angles are not defined (fill value). Zenith angle is 0 (180) for
-!--       upward (downward)-facing surfaces.
-          i  = start_count
-          mm = 1
-          DO  m = 1, surf_def_h(0)%ns
-             surfaces%s(mm)       = i
-             surfaces%xs(mm)      = ( surf_def_h(0)%i(m) + 0.5_wp ) * dx
-             surfaces%ys(mm)      = ( surf_def_h(0)%j(m) + 0.5_wp ) * dy
-             surfaces%zs(mm)      = zw(surf_def_h(0)%k(m)+surf_def_h(0)%koff)
-             surfaces%azimuth(mm) = surfaces%fillvalue
-             surfaces%zenith(mm)  = 0.0
-             i                    = i + 1
-             mm                   = mm + 1
-          ENDDO
-          DO  m = 1, surf_lsm_h%ns
-             surfaces%s(mm)       = i
-             surfaces%xs(mm)      = ( surf_lsm_h%i(m) + 0.5_wp ) * dx
-             surfaces%ys(mm)      = ( surf_lsm_h%j(m) + 0.5_wp ) * dy
-             surfaces%zs(mm)      = zw(surf_lsm_h%k(m)+surf_lsm_h%koff)
-             surfaces%azimuth(mm) = surfaces%fillvalue
-             surfaces%zenith(mm)  = 0.0
-             i                    = i + 1
-             mm                   = mm + 1
-          ENDDO
-          DO  m = 1, surf_usm_h%ns
-             surfaces%s(mm)       = i
-             surfaces%xs(mm)      = ( surf_usm_h%i(m) + 0.5_wp ) * dx
-             surfaces%ys(mm)      = ( surf_usm_h%j(m) + 0.5_wp ) * dy
-             surfaces%zs(mm)      = zw(surf_usm_h%k(m)+surf_usm_h%koff)
-             surfaces%azimuth(mm) = surfaces%fillvalue
-             surfaces%zenith(mm)  = 0.0
-             i                    = i + 1
-             mm                   = mm + 1
-          ENDDO
-          DO  m = 1, surf_def_h(1)%ns
-             surfaces%s(mm)       = i
-             surfaces%xs(mm)      = ( surf_def_h(1)%i(m) + 0.5_wp ) * dx
-             surfaces%ys(mm)      = ( surf_def_h(1)%j(m) + 0.5_wp ) * dy
-             surfaces%zs(mm)      = zw(surf_def_h(1)%k(m)+surf_def_h(1)%koff)
-             surfaces%azimuth(mm) = surfaces%fillvalue
-             surfaces%zenith(mm)  = 180.0
-             i                    = i + 1
-             mm                   = mm + 1
-          ENDDO
-!
-!--       For vertical surfaces, zenith angles are not defined (fill value).
-!--       Azimuth angle: northward (0), eastward (90), southward (180), 
-!--       westward (270). 
-!--       Note, for vertical surfaces, zenith angles are 90.0_wp. 
-          DO  l = 0, 3
-             IF ( l == 0 )  THEN
-                az    = 0.0_wp
-                off_x = 0.5_wp
-                off_y = 0.0_wp
-             ELSEIF ( l == 1 )  THEN
-                az    = 180.0_wp
-                off_x = 0.5_wp
-                off_y = 1.0_wp
-             ELSEIF ( l == 2 )  THEN
-                az    = 90.0_wp
-                off_x = 0.0_wp
-                off_y = 0.5_wp
-             ELSEIF ( l == 3 )  THEN
-                az    = 270.0_wp
-                off_x = 1.0_wp
-                off_y = 0.5_wp
-             ENDIF
-
-             DO  m = 1, surf_def_v(l)%ns
-                surfaces%s(mm)       = i
-                surfaces%xs(mm)      = ( surf_def_v(l)%i(m) + off_x ) * dx
-                surfaces%ys(mm)      = ( surf_def_v(l)%j(m) + off_y ) * dy
-                surfaces%zs(mm)      = zu(surf_def_v(l)%k(m))
-                surfaces%azimuth(mm) = az
-                surfaces%zenith(mm)  = 90.0_wp
-                i                    = i + 1
-                mm                   = mm + 1
-             ENDDO
-             DO  m = 1, surf_lsm_v(l)%ns
-                surfaces%s(mm)       = i
-                surfaces%xs(mm)      = ( surf_lsm_v(l)%i(m) + off_x ) * dx
-                surfaces%ys(mm)      = ( surf_lsm_v(l)%j(m) + off_y ) * dy
-                surfaces%zs(mm)      = zu(surf_lsm_v(l)%k(m))
-                surfaces%azimuth(mm) = az
-                surfaces%zenith(mm)  = 90.0_wp
-                i                    = i + 1
-                mm                   = mm + 1
-             ENDDO
-             DO  m = 1, surf_usm_v(l)%ns
-                surfaces%s(mm)       = i
-                surfaces%xs(mm)      = ( surf_usm_v(l)%i(m) + off_x ) * dx
-                surfaces%ys(mm)      = ( surf_usm_v(l)%j(m) + off_y ) * dy
-                surfaces%zs(mm)      = zu(surf_usm_v(l)%k(m))
-                surfaces%azimuth(mm) = az
-                surfaces%zenith(mm)  = 90.0_wp
-                i                    = i + 1
-                mm                   = mm + 1
-             ENDDO
-          ENDDO
-!
-!--       Finally, define UTM coordinates, which are the x/y-coordinates
-!--       plus the origin (lower-left coordinate of the model domain).
-          surfaces%es_utm = surfaces%xs + init_model%origin_x
-          surfaces%ns_utm = surfaces%ys + init_model%origin_y
-!
-!--       Initialize NetCDF data output. Please note, local start position for
-!--       the surface elements in the NetCDF file is surfaces%s(1), while
-!--       the number of surfaces on the subdomain is given by surfaces%ns.
-#if defined( __netcdf4_parallel )
-
-!
-!--       Calculate number of time steps to be output
-          ntdim_surf(0) = dosurf_time_count(0) + CEILING(                      &
-                        ( end_time - MAX(                                      &
-                            MERGE( skip_time_dosurf,                           &
-                                   skip_time_dosurf + spinup_time,             &
-                                   data_output_during_spinup ),                &
-                            simulated_time_at_begin )                          &
-                        ) / dt_dosurf )
-
-          ntdim_surf(1) = dosurf_time_count(1) + CEILING(                      &
-                        ( end_time - MAX(                                      &
-                            MERGE( skip_time_dosurf_av,                        &
-                                   skip_time_dosurf_av + spinup_time,          &
-                                   data_output_during_spinup ),                &
-                            simulated_time_at_begin )                          &
-                        ) / dt_dosurf_av )
-
-!
-!--       Create NetCDF4 files for parallel writing
-          DO  av = 0, 1
-!
-!--          If there is no instantaneous data (av=0) or averaged data (av=1)
-!--          requested, do not create the corresponding NetCDF file
-             IF ( dosurf_no(av) == 0 ) CYCLE
-
-             IF ( av == 0 )  THEN
-                filename = 'SURFACE_DATA_NETCDF' // TRIM( coupling_char )
-             ELSE
-                filename = 'SURFACE_DATA_AV_NETCDF' // TRIM( coupling_char )
-             ENDIF
-!
-!--          Open file using netCDF4/HDF5 format, parallel
-             nc_stat = NF90_CREATE( TRIM(filename),                            &
-                                    IOR( NF90_NOCLOBBER,                       &
-                                    IOR( NF90_NETCDF4, NF90_MPIIO ) ),         &
-                                    id_set_surf(av),                           &
-                                    COMM = comm2d, INFO = MPI_INFO_NULL )
-             CALL netcdf_handle_error( 'surface_data_output_mod', 5550 )
-
-             !- Write some global attributes
-             IF ( av == 0 )  THEN
-                CALL netcdf_create_global_atts( id_set_surf(av),               &
-                                                'surface-data',                &
-                                                TRIM( run_description_header ),&
-                                                5551 )
-                time_average_text = ' '
-             ELSE
-                CALL netcdf_create_global_atts( id_set_surf(av),               &
-                                                'surface-data_av',             &
-                                                TRIM( run_description_header ),&
-                                                5552 )
-                WRITE ( time_average_text,'(F7.1,'' s avg'')' )  &
-                   averaging_interval_surf
-                nc_stat = NF90_PUT_ATT( id_set_surf(av), NF90_GLOBAL,          &
-                                        'time_avg',                            &
-                                        TRIM( time_average_text ) )
-                CALL netcdf_handle_error( 'surface_data_output_mod', 5553 )
-             ENDIF
-
-
-!
-!--          Define time coordinate for surface data.
-!--          For parallel output the time dimension has to be limited
-!--          (ntdim_surf), otherwise the performance drops significantly.
-             CALL netcdf_create_dim( id_set_surf(av), 'time', ntdim_surf(av),  &
-                                     id_dim_time_surf(av), 5554 )
-
-             CALL netcdf_create_var( id_set_surf(av),                          &
-                                     (/ id_dim_time_surf(av) /),               &
-                                     'time', NF90_DOUBLE,                      &
-                                     id_var_time_surf(av),                     &
-                                     'seconds since '//                        &
-                                     TRIM(init_model%origin_time),             &
-                                     'time', 5555, 5555, 5555 )
-
-             CALL netcdf_create_att( id_set_surf(av), id_var_time_surf(av),    &
-                                     'standard_name', 'time', 5556)
-
-             CALL netcdf_create_att( id_set_surf(av), id_var_time_surf(av),    &
-                                     'axis', 'T', 5557)
-!
-!--          Define spatial dimensions and coordinates:
-!--          Define index of surface element
-             CALL netcdf_create_dim( id_set_surf(av), 's', surfaces%ns_total,  &
-                                     id_dim_s_surf(av), 5558 )
-             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
-                                     's', NF90_DOUBLE, id_var_s_surf(av),      &
-                                     '1', 'number of surface element',         &
-                                     5559, 5559, 5559 )
-!
-!--          Define x coordinate
-             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
-                                     'xs', NF90_DOUBLE, id_var_xs_surf(av),    &
-                                     'meters',                                 &
-                                     'distance to origin in x-direction',      &
-                                     5561, 5561, 5561 )
-!
-!--           Define y coordinate
-             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
-                                     'ys', NF90_DOUBLE, id_var_ys_surf(av),    &
-                                     'meters',                                 &
-                                     'distance to origin in y-direction',      &
-                                     5562, 5562, 5562 )
-!
-!--          Define z coordinate
-             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
-                                     'zs', NF90_DOUBLE, id_var_zs_surf(av),    &
-                                     'meters', 'height', 5560, 5560, 5560 )
-             CALL netcdf_create_att( id_set_surf(av), id_var_zs_surf(av),      &
-                                     'standard_name', 'height', 5583 )
-
-!
-!--          Define UTM coordinates
-             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
-                                     'Es_UTM', NF90_DOUBLE,                    &
-                                     id_var_etum_surf(av),                     &
-                                     'meters', '', 5563, 5563, 5563 )
-             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
-                                     'Ns_UTM', NF90_DOUBLE,                    &
-                                     id_var_nutm_surf(av),                     &
-                                     'meters', '', 5564, 5564, 5564 )
-
-!
-!--          Define angles
-             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
-                                     'azimuth', NF90_DOUBLE,                   &
-                                     id_var_azimuth_surf(av),                  &
-                                     'degree', 'azimuth angle',                &
-                                     5577, 5578, 5579,                         &
-                                     fill = .TRUE. )
-             CALL netcdf_create_att( id_set_surf(av), id_var_azimuth_surf(av), &
-                                     'standard_name', 'surface_azimuth_angle', &
-                                     5584 )
-
-             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
-                                     'zenith', NF90_DOUBLE,                    &
-                                     id_var_zenith_surf(av),                   &
-                                     'degree', '', 5580, 5581, 5582,           &
-                                     fill = .TRUE. )
-!
-!--          Define the variables
-             var_list = ';'
-             i = 1
-
-             DO WHILE ( dosurf(av,i)(1:1) /= ' ' )
-
-                CALL netcdf_create_var( id_set_surf(av),(/ id_dim_s_surf(av),  &
-                                        id_dim_time_surf(av) /), dosurf(av,i), &
-                                        NF90_REAL4, id_var_dosurf(av,i),       &
-                                        dosurf_unit(av,i), dosurf(av,i), 5565, &
-                                        5565, 5565, .TRUE. )
-!
-!--                Set no fill for every variable to increase performance.
-                nc_stat = NF90_DEF_VAR_FILL( id_set_surf(av),                  &
-                                             id_var_dosurf(av,i),              &
-                                             NF90_NOFILL, 0 )
-                CALL netcdf_handle_error( 'surface_data_output_init', 5566 )
-!
-!--                Set collective io operations for parallel io
-                nc_stat = NF90_VAR_PAR_ACCESS( id_set_surf(av),                &
-                                               id_var_dosurf(av,i),            &
-                                               NF90_COLLECTIVE )
-                CALL netcdf_handle_error( 'surface_data_output_init', 5567 )
-                var_list = TRIM( var_list ) // TRIM( dosurf(av,i) ) // ';'
-
-                i = i + 1
-
-             ENDDO
-!
-!--          Write the list of variables as global attribute (this is used by
-!--          restart runs and by combine_plot_fields)
-             nc_stat = NF90_PUT_ATT( id_set_surf(av), NF90_GLOBAL, 'VAR_LIST', &
-                                     var_list )
-             CALL netcdf_handle_error( 'surface_data_output_init', 5568 )
-
-!
-!--          Set general no fill, otherwise the performance drops significantly
-!--          for parallel output.
-             nc_stat = NF90_SET_FILL( id_set_surf(av), NF90_NOFILL, oldmode )
-             CALL netcdf_handle_error( 'surface_data_output_init', 5569 )
-
-!
-!--          Leave netCDF define mode
-             nc_stat = NF90_ENDDEF( id_set_surf(av) )
-             CALL netcdf_handle_error( 'surface_data_output_init', 5570 )
-
-!
-!--          These data are only written by PE0 for parallel output to increase
-!--          the performance.
-             IF ( myid == 0 )  THEN
-!
-!--             Write data for surface indices
-                ALLOCATE( netcdf_data_1d(1:surfaces%ns_total) )
-
-                DO  i = 1, surfaces%ns_total
-                   netcdf_data_1d(i) = i
-                ENDDO
-
-                nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_s_surf(av),    &
-                                        netcdf_data_1d, start = (/ 1 /),       &
-                                        count = (/ surfaces%ns_total /) )
-                CALL netcdf_handle_error( 'surface_data_output_init', 5571 )
-
-                DEALLOCATE( netcdf_data_1d )
-
-             ENDIF
-
-!
-!--          Write surface positions to file
-             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_xs_surf(av),      &
-                                     surfaces%xs, start = (/ surfaces%s(1) /), &
-                                     count = (/ surfaces%ns /) )
-             CALL netcdf_handle_error( 'surface_data_output_init', 5572 )
-
-             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_ys_surf(av),      &
-                                     surfaces%ys, start = (/ surfaces%s(1) /), &
-                                     count = (/ surfaces%ns /) )
-             CALL netcdf_handle_error( 'surface_data_output_init', 5573 )
-
-             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_zs_surf(av),      &
-                                     surfaces%zs, start = (/ surfaces%s(1) /), &
-                                     count = (/ surfaces%ns /) )
-             CALL netcdf_handle_error( 'surface_data_output_init', 5574 )
-
-             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_etum_surf(av),    &
-                                     surfaces%es_utm,                          &
-                                     start = (/ surfaces%s(1) /),              &
-                                     count = (/ surfaces%ns /) )
-             CALL netcdf_handle_error( 'surface_data_output_init', 5575 )
-
-             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_nutm_surf(av),    &
-                                     surfaces%ns_utm,                          &
-                                     start = (/ surfaces%s(1) /),              &
-                                     count = (/ surfaces%ns /) )
-             CALL netcdf_handle_error( 'surface_data_output_init', 5576 )
-
-             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_azimuth_surf(av), &
-                                     surfaces%azimuth,                         &
-                                     start = (/ surfaces%s(1) /),              &
-                                     count = (/ surfaces%ns /) )
-             CALL netcdf_handle_error( 'surface_data_output_init', 5585 )
-
-             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_zenith_surf(av),  &
-                                     surfaces%zenith,                          &
-                                     start = (/ surfaces%s(1) /),              &
-                                     count = (/ surfaces%ns /) )
-             CALL netcdf_handle_error( 'surface_data_output_init', 5586 )
-
-          ENDDO
-#endif
-
-       ENDIF
-
-   END SUBROUTINE surface_data_output_init
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Routine for controlling the data output. Surface data is collected from
-!> different types of surfaces (default, natural, urban) and different
-!> orientation and written to one 1D-output array. Further, NetCDF routines
-!> are called to write the surface data in the respective NetCDF files.
-!------------------------------------------------------------------------------!
-   SUBROUTINE surface_data_output( av )
-
-      USE control_parameters,                                                  &
-          ONLY:  io_blocks, io_group, time_since_reference_point
-
-#if defined( __parallel )
-      USE pegrid,                                                              &
-          ONLY:  comm2d, ierr
-#endif
-
-
-      IMPLICIT NONE
-
-      CHARACTER(LEN=100) ::  trimvar = ' ' !< dummy for single output variable
-
-      INTEGER(iwp) ::  av     !< id indicating average or non-average data output
-      INTEGER(iwp) ::  i      !< loop index
-      INTEGER(iwp) ::  l      !< running index for surface orientation
-      INTEGER(iwp) ::  m      !< running index for surface elements
-      INTEGER(iwp) ::  n_out  !< counter variables for surface output
-
-!
-!--   Return, if nothing to output
-      IF ( dosurf_no(av) == 0 )  RETURN
-!
-!--   In case of VTK output, check if binary files are open and write coordinates.
-      IF ( to_vtk )  THEN
-
-         CALL check_open( 25+av )
-
-         IF ( .NOT. first_output(av) )  THEN
-            DO  i = 0, io_blocks-1
-               IF ( i == io_group )  THEN
-                  WRITE ( 25+av )  surfaces%npoints
-                  WRITE ( 25+av )  surfaces%npoints_total
-                  WRITE ( 25+av )  surfaces%ns
-                  WRITE ( 25+av )  surfaces%ns_total
-                  WRITE ( 25+av )  surfaces%points
-                  WRITE ( 25+av )  surfaces%polygons
-               ENDIF
-#if defined( __parallel )
-               CALL MPI_BARRIER( comm2d, ierr )
-#endif
-               first_output(av) = .TRUE.
-            ENDDO
-         ENDIF
-      ENDIF
-!
-!--   In case of NetCDF output, check if enough time steps are available in file
-!--   and update time axis.
-      IF ( to_netcdf )  THEN
-#if defined( __netcdf4_parallel )
-         IF ( dosurf_time_count(av) + 1 > ntdim_surf(av) )  THEN
-            WRITE ( message_string, * )                               &
-               'Output of surface data is not given at t=',           &
-               time_since_reference_point, 's because the maximum ',  &
-               'number of output time levels is exceeded.'
-            CALL message( 'surface_data_output', 'PA0539', 0, 1, 0, 6, 0 )
-
-            RETURN
-
-         ENDIF
-!
-!--      Update the netCDF time axis
-!--      In case of parallel output, this is only done by PE0 to increase the
-!--      performance.
-         dosurf_time_count(av) = dosurf_time_count(av) + 1
-         IF ( myid == 0 )  THEN
-            nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_time_surf(av),  &
-                                    (/ time_since_reference_point /),       &
-                                    start = (/ dosurf_time_count(av) /),    &
-                                    count = (/ 1 /) )
-            CALL netcdf_handle_error( 'surface_data_output', 6666 )
-         ENDIF
-#endif
-      ENDIF
-
-!
-!--   Cycle through output quantities and write them to file.
-      n_out = 0
-      DO  WHILE ( dosurf(av,n_out+1)(1:1) /= ' ' )
-
-         n_out   = n_out + 1
-         trimvar = TRIM( dosurf(av,n_out) )
-!
-!--      Set the output array to the _FillValue in case it is not
-!--      defined for each type of surface.
-         surfaces%var_out = surfaces%fillvalue
-         SELECT CASE ( trimvar )
-
-            CASE ( 'us' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%us,          &
-                                               surf_def_h(1)%us,               &
-                                               surf_lsm_h%us,                  &
-                                               surf_usm_h%us,                  &
-                                               surf_def_v(0)%us,               &
-                                               surf_lsm_v(0)%us,               &
-                                               surf_usm_v(0)%us,               &
-                                               surf_def_v(1)%us,               &
-                                               surf_lsm_v(1)%us,               &
-                                               surf_usm_v(1)%us,               &
-                                               surf_def_v(2)%us,               &
-                                               surf_lsm_v(2)%us,               &
-                                               surf_usm_v(2)%us,               &
-                                               surf_def_v(3)%us,               &
-                                               surf_lsm_v(3)%us,               &
-                                               surf_usm_v(3)%us )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'ts' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%ts,          &
-                                               surf_def_h(1)%ts,               &
-                                               surf_lsm_h%ts,                  &
-                                               surf_usm_h%ts,                  &
-                                               surf_def_v(0)%ts,               &
-                                               surf_lsm_v(0)%ts,               &
-                                               surf_usm_v(0)%ts,               &
-                                               surf_def_v(1)%ts,               &
-                                               surf_lsm_v(1)%ts,               &
-                                               surf_usm_v(1)%ts,               &
-                                               surf_def_v(2)%ts,               &
-                                               surf_lsm_v(2)%ts,               &
-                                               surf_usm_v(2)%ts,               &
-                                               surf_def_v(3)%ts,               &
-                                               surf_lsm_v(3)%ts,               &
-                                               surf_usm_v(3)%ts )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'qs' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%qs,          &
-                                               surf_def_h(1)%qs,               &
-                                               surf_lsm_h%qs,                  &
-                                               surf_usm_h%qs,                  &
-                                               surf_def_v(0)%qs,               &
-                                               surf_lsm_v(0)%qs,               &
-                                               surf_usm_v(0)%qs,               &
-                                               surf_def_v(1)%qs,               &
-                                               surf_lsm_v(1)%qs,               &
-                                               surf_usm_v(1)%qs,               &
-                                               surf_def_v(2)%qs,               &
-                                               surf_lsm_v(2)%qs,               &
-                                               surf_usm_v(2)%qs,               &
-                                               surf_def_v(3)%qs,               &
-                                               surf_lsm_v(3)%qs,               &
-                                               surf_usm_v(3)%qs )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'ss' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%ss,          &
-                                               surf_def_h(1)%ss,               &
-                                               surf_lsm_h%ss,                  &
-                                               surf_usm_h%ss,                  &
-                                               surf_def_v(0)%ss,               &
-                                               surf_lsm_v(0)%ss,               &
-                                               surf_usm_v(0)%ss,               &
-                                               surf_def_v(1)%ss,               &
-                                               surf_lsm_v(1)%ss,               &
-                                               surf_usm_v(1)%ss,               &
-                                               surf_def_v(2)%ss,               &
-                                               surf_lsm_v(2)%ss,               &
-                                               surf_usm_v(2)%ss,               &
-                                               surf_def_v(3)%ss,               &
-                                               surf_lsm_v(3)%ss,               &
-                                               surf_usm_v(3)%ss )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'qcs' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%qcs,         &
-                                               surf_def_h(1)%qcs,              &
-                                               surf_lsm_h%qcs,                 &
-                                               surf_usm_h%qcs,                 &
-                                               surf_def_v(0)%qcs,              &
-                                               surf_lsm_v(0)%qcs,              &
-                                               surf_usm_v(0)%qcs,              &
-                                               surf_def_v(1)%qcs,              &
-                                               surf_lsm_v(1)%qcs,              &
-                                               surf_usm_v(1)%qcs,              &
-                                               surf_def_v(2)%qcs,              &
-                                               surf_lsm_v(2)%qcs,              &
-                                               surf_usm_v(2)%qcs,              &
-                                               surf_def_v(3)%qcs,              &
-                                               surf_lsm_v(3)%qcs,              &
-                                               surf_usm_v(3)%qcs )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'ncs' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%ncs,         &
-                                               surf_def_h(1)%ncs,              &
-                                               surf_lsm_h%ncs,                 &
-                                               surf_usm_h%ncs,                 &
-                                               surf_def_v(0)%ncs,              &
-                                               surf_lsm_v(0)%ncs,              &
-                                               surf_usm_v(0)%ncs,              &
-                                               surf_def_v(1)%ncs,              &
-                                               surf_lsm_v(1)%ncs,              &
-                                               surf_usm_v(1)%ncs,              &
-                                               surf_def_v(2)%ncs,              &
-                                               surf_lsm_v(2)%ncs,              &
-                                               surf_usm_v(2)%ncs,              &
-                                               surf_def_v(3)%ncs,              &
-                                               surf_lsm_v(3)%ncs,              &
-                                               surf_usm_v(3)%ncs )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'qis' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%qis,         &
-                                               surf_def_h(1)%qis,              &
-                                               surf_lsm_h%qis,                 &
-                                               surf_usm_h%qis,                 &
-                                               surf_def_v(0)%qis,              &
-                                               surf_lsm_v(0)%qis,              &
-                                               surf_usm_v(0)%qis,              &
-                                               surf_def_v(1)%qis,              &
-                                               surf_lsm_v(1)%qis,              &
-                                               surf_usm_v(1)%qis,              &
-                                               surf_def_v(2)%qis,              &
-                                               surf_lsm_v(2)%qis,              &
-                                               surf_usm_v(2)%qis,              &
-                                               surf_def_v(3)%qis,              &
-                                               surf_lsm_v(3)%qis,              &
-                                               surf_usm_v(3)%qis )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'nis' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%nis,         &
-                                               surf_def_h(1)%nis,              &
-                                               surf_lsm_h%nis,                 &
-                                               surf_usm_h%nis,                 &
-                                               surf_def_v(0)%nis,              &
-                                               surf_lsm_v(0)%nis,              &
-                                               surf_usm_v(0)%nis,              &
-                                               surf_def_v(1)%nis,              &
-                                               surf_lsm_v(1)%nis,              &
-                                               surf_usm_v(1)%nis,              &
-                                               surf_def_v(2)%nis,              &
-                                               surf_lsm_v(2)%nis,              &
-                                               surf_usm_v(2)%nis,              &
-                                               surf_def_v(3)%nis,              &
-                                               surf_lsm_v(3)%nis,              &
-                                               surf_usm_v(3)%nis )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'qrs' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%qrs,         &
-                                               surf_def_h(1)%qrs,              &
-                                               surf_lsm_h%qrs,                 &
-                                               surf_usm_h%qrs,                 &
-                                               surf_def_v(0)%qrs,              &
-                                               surf_lsm_v(0)%qrs,              &
-                                               surf_usm_v(0)%qrs,              &
-                                               surf_def_v(1)%qrs,              &
-                                               surf_lsm_v(1)%qrs,              &
-                                               surf_usm_v(1)%qrs,              &
-                                               surf_def_v(2)%qrs,              &
-                                               surf_lsm_v(2)%qrs,              &
-                                               surf_usm_v(2)%qrs,              &
-                                               surf_def_v(3)%qrs,              &
-                                               surf_lsm_v(3)%qrs,              &
-                                               surf_usm_v(3)%qrs )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'nrs' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%nrs,         &
-                                               surf_def_h(1)%nrs,              &
-                                               surf_lsm_h%nrs,                 &
-                                               surf_usm_h%nrs,                 &
-                                               surf_def_v(0)%nrs,              &
-                                               surf_lsm_v(0)%nrs,              &
-                                               surf_usm_v(0)%nrs,              &
-                                               surf_def_v(1)%nrs,              &
-                                               surf_lsm_v(1)%nrs,              &
-                                               surf_usm_v(1)%nrs,              &
-                                               surf_def_v(2)%nrs,              &
-                                               surf_lsm_v(2)%nrs,              &
-                                               surf_usm_v(2)%nrs,              &
-                                               surf_def_v(3)%nrs,              &
-                                               surf_lsm_v(3)%nrs,              &
-                                               surf_usm_v(3)%nrs )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'ol' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%ol,          &
-                                               surf_def_h(1)%ol,               &
-                                               surf_lsm_h%ol,                  &
-                                               surf_usm_h%ol,                  &
-                                               surf_def_v(0)%ol,               &
-                                               surf_lsm_v(0)%ol,               &
-                                               surf_usm_v(0)%ol,               &
-                                               surf_def_v(1)%ol,               &
-                                               surf_lsm_v(1)%ol,               &
-                                               surf_usm_v(1)%ol,               &
-                                               surf_def_v(2)%ol,               &
-                                               surf_lsm_v(2)%ol,               &
-                                               surf_usm_v(2)%ol,               &
-                                               surf_def_v(3)%ol,               &
-                                               surf_lsm_v(3)%ol,               &
-                                               surf_usm_v(3)%ol )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'z0' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%z0,          &
-                                               surf_def_h(1)%z0,               &
-                                               surf_lsm_h%z0,                  &
-                                               surf_usm_h%z0,                  &
-                                               surf_def_v(0)%z0,               &
-                                               surf_lsm_v(0)%z0,               &
-                                               surf_usm_v(0)%z0,               &
-                                               surf_def_v(1)%z0,               &
-                                               surf_lsm_v(1)%z0,               &
-                                               surf_usm_v(1)%z0,               &
-                                               surf_def_v(2)%z0,               &
-                                               surf_lsm_v(2)%z0,               &
-                                               surf_usm_v(2)%z0,               &
-                                               surf_def_v(3)%z0,               &
-                                               surf_lsm_v(3)%z0,               &
-                                               surf_usm_v(3)%z0 )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'z0h' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%z0h,         &
-                                               surf_def_h(1)%z0h,              &
-                                               surf_lsm_h%z0h,                 &
-                                               surf_usm_h%z0h,                 &
-                                               surf_def_v(0)%z0h,              &
-                                               surf_lsm_v(0)%z0h,              &
-                                               surf_usm_v(0)%z0h,              &
-                                               surf_def_v(1)%z0h,              &
-                                               surf_lsm_v(1)%z0h,              &
-                                               surf_usm_v(1)%z0h,              &
-                                               surf_def_v(2)%z0h,              &
-                                               surf_lsm_v(2)%z0h,              &
-                                               surf_usm_v(2)%z0h,              &
-                                               surf_def_v(3)%z0h,              &
-                                               surf_lsm_v(3)%z0h,              &
-                                               surf_usm_v(3)%z0h )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'z0q' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%z0q,         &
-                                               surf_def_h(1)%z0q,              &
-                                               surf_lsm_h%z0q,                 &
-                                               surf_usm_h%z0q,                 &
-                                               surf_def_v(0)%z0q,              &
-                                               surf_lsm_v(0)%z0q,              &
-                                               surf_usm_v(0)%z0q,              &
-                                               surf_def_v(1)%z0q,              &
-                                               surf_lsm_v(1)%z0q,              &
-                                               surf_usm_v(1)%z0q,              &
-                                               surf_def_v(2)%z0q,              &
-                                               surf_lsm_v(2)%z0q,              &
-                                               surf_usm_v(2)%z0q,              &
-                                               surf_def_v(3)%z0q,              &
-                                               surf_lsm_v(3)%z0q,              &
-                                               surf_usm_v(3)%z0q )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'theta1' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%pt1,         &
-                                               surf_def_h(1)%pt1,              &
-                                               surf_lsm_h%pt1,                 &
-                                               surf_usm_h%pt1,                 &
-                                               surf_def_v(0)%pt1,              &
-                                               surf_lsm_v(0)%pt1,              &
-                                               surf_usm_v(0)%pt1,              &
-                                               surf_def_v(1)%pt1,              &
-                                               surf_lsm_v(1)%pt1,              &
-                                               surf_usm_v(1)%pt1,              &
-                                               surf_def_v(2)%pt1,              &
-                                               surf_lsm_v(2)%pt1,              &
-                                               surf_usm_v(2)%pt1,              &
-                                               surf_def_v(3)%pt1,              &
-                                               surf_lsm_v(3)%pt1,              &
-                                               surf_usm_v(3)%pt1 )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'qv1' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%qv1,         &
-                                               surf_def_h(1)%qv1,              &
-                                               surf_lsm_h%qv1,                 &
-                                               surf_usm_h%qv1,                 &
-                                               surf_def_v(0)%qv1,              &
-                                               surf_lsm_v(0)%qv1,              &
-                                               surf_usm_v(0)%qv1,              &
-                                               surf_def_v(1)%qv1,              &
-                                               surf_lsm_v(1)%qv1,              &
-                                               surf_usm_v(1)%qv1,              &
-                                               surf_def_v(2)%qv1,              &
-                                               surf_lsm_v(2)%qv1,              &
-                                               surf_usm_v(2)%qv1,              &
-                                               surf_def_v(3)%qv1,              &
-                                               surf_lsm_v(3)%qv1,              &
-                                               surf_usm_v(3)%qv1 )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'thetav1' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%vpt1,        &
-                                               surf_def_h(1)%vpt1,             &
-                                               surf_lsm_h%vpt1,                &
-                                               surf_usm_h%vpt1,                &
-                                               surf_def_v(0)%vpt1,             &
-                                               surf_lsm_v(0)%vpt1,             &
-                                               surf_usm_v(0)%vpt1,             &
-                                               surf_def_v(1)%vpt1,             &
-                                               surf_lsm_v(1)%vpt1,             &
-                                               surf_usm_v(1)%vpt1,             &
-                                               surf_def_v(2)%vpt1,             &
-                                               surf_lsm_v(2)%vpt1,             &
-                                               surf_usm_v(2)%vpt1,             &
-                                               surf_def_v(3)%vpt1,             &
-                                               surf_lsm_v(3)%vpt1,             &
-                                               surf_usm_v(3)%vpt1 )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'usws' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%usws,        &
-                                               surf_def_h(1)%usws,             &
-                                               surf_lsm_h%usws,                &
-                                               surf_usm_h%usws,                &
-                                               surf_def_v(0)%usws,             &
-                                               surf_lsm_v(0)%usws,             &
-                                               surf_usm_v(0)%usws,             &
-                                               surf_def_v(1)%usws,             &
-                                               surf_lsm_v(1)%usws,             &
-                                               surf_usm_v(1)%usws,             &
-                                               surf_def_v(2)%usws,             &
-                                               surf_lsm_v(2)%usws,             &
-                                               surf_usm_v(2)%usws,             &
-                                               surf_def_v(3)%usws,             &
-                                               surf_lsm_v(3)%usws,             &
-                                               surf_usm_v(3)%usws,             &
-                                               momentumflux_output_conversion )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'vsws' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%vsws,        &
-                                               surf_def_h(1)%vsws,             &
-                                               surf_lsm_h%vsws,                &
-                                               surf_usm_h%vsws,                &
-                                               surf_def_v(0)%vsws,             &
-                                               surf_lsm_v(0)%vsws,             &
-                                               surf_usm_v(0)%vsws,             &
-                                               surf_def_v(1)%vsws,             &
-                                               surf_lsm_v(1)%vsws,             &
-                                               surf_usm_v(1)%vsws,             &
-                                               surf_def_v(2)%vsws,             &
-                                               surf_lsm_v(2)%vsws,             &
-                                               surf_usm_v(2)%vsws,             &
-                                               surf_def_v(3)%vsws,             &
-                                               surf_lsm_v(3)%vsws,             &
-                                               surf_usm_v(3)%vsws,             &
-                                               momentumflux_output_conversion )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'shf' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%shf,         &
-                                               surf_def_h(1)%shf,              &
-                                               surf_lsm_h%shf,                 &
-                                               surf_usm_h%shf,                 &
-                                               surf_def_v(0)%shf,              &
-                                               surf_lsm_v(0)%shf,              &
-                                               surf_usm_v(0)%shf,              &
-                                               surf_def_v(1)%shf,              &
-                                               surf_lsm_v(1)%shf,              &
-                                               surf_usm_v(1)%shf,              &
-                                               surf_def_v(2)%shf,              &
-                                               surf_lsm_v(2)%shf,              &
-                                               surf_usm_v(2)%shf,              &
-                                               surf_def_v(3)%shf,              &
-                                               surf_lsm_v(3)%shf,              &
-                                               surf_usm_v(3)%shf,              &
-                                               heatflux_output_conversion )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-               ENDIF
-
-            CASE ( 'qsws' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%qsws,        &
-                                               surf_def_h(1)%qsws,             &
-                                               surf_lsm_h%qsws,                &
-                                               surf_usm_h%qsws,                &
-                                               surf_def_v(0)%qsws,             &
-                                               surf_lsm_v(0)%qsws,             &
-                                               surf_usm_v(0)%qsws,             &
-                                               surf_def_v(1)%qsws,             &
-                                               surf_lsm_v(1)%qsws,             &
-                                               surf_usm_v(1)%qsws,             &
-                                               surf_def_v(2)%qsws,             &
-                                               surf_lsm_v(2)%qsws,             &
-                                               surf_usm_v(2)%qsws,             &
-                                               surf_def_v(3)%qsws,             &
-                                               surf_lsm_v(3)%qsws,             &
-                                               surf_usm_v(3)%qsws,             &
-                                               waterflux_output_conversion )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'ssws' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%ssws,        &
-                                               surf_def_h(1)%ssws,             &
-                                               surf_lsm_h%ssws,                &
-                                               surf_usm_h%ssws,                &
-                                               surf_def_v(0)%ssws,             &
-                                               surf_lsm_v(0)%ssws,             &
-                                               surf_usm_v(0)%ssws,             &
-                                               surf_def_v(1)%ssws,             &
-                                               surf_lsm_v(1)%ssws,             &
-                                               surf_usm_v(1)%ssws,             &
-                                               surf_def_v(2)%ssws,             &
-                                               surf_lsm_v(2)%ssws,             &
-                                               surf_usm_v(2)%ssws,             &
-                                               surf_def_v(3)%ssws,             &
-                                               surf_lsm_v(3)%ssws,             &
-                                               surf_usm_v(3)%ssws )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'qcsws' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%qcsws,       &
-                                               surf_def_h(1)%qcsws,            &
-                                               surf_lsm_h%qcsws,               &
-                                               surf_usm_h%qcsws,               &
-                                               surf_def_v(0)%qcsws,            &
-                                               surf_lsm_v(0)%qcsws,            &
-                                               surf_usm_v(0)%qcsws,            &
-                                               surf_def_v(1)%qcsws,            &
-                                               surf_lsm_v(1)%qcsws,            &
-                                               surf_usm_v(1)%qcsws,            &
-                                               surf_def_v(2)%qcsws,            &
-                                               surf_lsm_v(2)%qcsws,            &
-                                               surf_usm_v(2)%qcsws,            &
-                                               surf_def_v(3)%qcsws,            &
-                                               surf_lsm_v(3)%qcsws,            &
-                                               surf_usm_v(3)%qcsws )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'ncsws' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%ncsws,       &
-                                               surf_def_h(1)%ncsws,            &
-                                               surf_lsm_h%ncsws,               &
-                                               surf_usm_h%ncsws,               &
-                                               surf_def_v(0)%ncsws,            &
-                                               surf_lsm_v(0)%ncsws,            &
-                                               surf_usm_v(0)%ncsws,            &
-                                               surf_def_v(1)%ncsws,            &
-                                               surf_lsm_v(1)%ncsws,            &
-                                               surf_usm_v(1)%ncsws,            &
-                                               surf_def_v(2)%ncsws,            &
-                                               surf_lsm_v(2)%ncsws,            &
-                                               surf_usm_v(2)%ncsws,            &
-                                               surf_def_v(3)%ncsws,            &
-                                               surf_lsm_v(3)%ncsws,            &
-                                               surf_usm_v(3)%ncsws )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-
-            CASE ( 'qisws' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%qisws,       &
-                                               surf_def_h(1)%qisws,            &
-                                               surf_lsm_h%qisws,               &
-                                               surf_usm_h%qisws,               &
-                                               surf_def_v(0)%qisws,            &
-                                               surf_lsm_v(0)%qisws,            &
-                                               surf_usm_v(0)%qisws,            &
-                                               surf_def_v(1)%qisws,            &
-                                               surf_lsm_v(1)%qisws,            &
-                                               surf_usm_v(1)%qisws,            &
-                                               surf_def_v(2)%qisws,            &
-                                               surf_lsm_v(2)%qisws,            &
-                                               surf_usm_v(2)%qisws,            &
-                                               surf_def_v(3)%qisws,            &
-                                               surf_lsm_v(3)%qisws,            &
-                                               surf_usm_v(3)%qisws )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'nisws' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%nisws,       &
-                                               surf_def_h(1)%nisws,            &
-                                               surf_lsm_h%nisws,               &
-                                               surf_usm_h%nisws,               &
-                                               surf_def_v(0)%nisws,            &
-                                               surf_lsm_v(0)%nisws,            &
-                                               surf_usm_v(0)%nisws,            &
-                                               surf_def_v(1)%nisws,            &
-                                               surf_lsm_v(1)%nisws,            &
-                                               surf_usm_v(1)%nisws,            &
-                                               surf_def_v(2)%nisws,            &
-                                               surf_lsm_v(2)%nisws,            &
-                                               surf_usm_v(2)%nisws,            &
-                                               surf_def_v(3)%nisws,            &
-                                               surf_lsm_v(3)%nisws,            &
-                                               surf_usm_v(3)%nisws )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'qrsws' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%qrsws,       &
-                                               surf_def_h(1)%qrsws,            &
-                                               surf_lsm_h%qrsws,               &
-                                               surf_usm_h%qrsws,               &
-                                               surf_def_v(0)%qrsws,            &
-                                               surf_lsm_v(0)%qrsws,            &
-                                               surf_usm_v(0)%qrsws,            &
-                                               surf_def_v(1)%qrsws,            &
-                                               surf_lsm_v(1)%qrsws,            &
-                                               surf_usm_v(1)%qrsws,            &
-                                               surf_def_v(2)%qrsws,            &
-                                               surf_lsm_v(2)%qrsws,            &
-                                               surf_usm_v(2)%qrsws,            &
-                                               surf_def_v(3)%qrsws,            &
-                                               surf_lsm_v(3)%qrsws,            &
-                                               surf_usm_v(3)%qrsws )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'nrsws' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%nrsws,       &
-                                               surf_def_h(1)%nrsws,            &
-                                               surf_lsm_h%nrsws,               &
-                                               surf_usm_h%nrsws,               &
-                                               surf_def_v(0)%nrsws,            &
-                                               surf_lsm_v(0)%nrsws,            &
-                                               surf_usm_v(0)%nrsws,            &
-                                               surf_def_v(1)%nrsws,            &
-                                               surf_lsm_v(1)%nrsws,            &
-                                               surf_usm_v(1)%nrsws,            &
-                                               surf_def_v(2)%nrsws,            &
-                                               surf_lsm_v(2)%nrsws,            &
-                                               surf_usm_v(2)%nrsws,            &
-                                               surf_def_v(3)%nrsws,            &
-                                               surf_lsm_v(3)%nrsws,            &
-                                               surf_usm_v(3)%nrsws )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'sasws' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%sasws,       &
-                                               surf_def_h(1)%sasws,            &
-                                               surf_lsm_h%sasws,               &
-                                               surf_usm_h%sasws,               &
-                                               surf_def_v(0)%sasws,            &
-                                               surf_lsm_v(0)%sasws,            &
-                                               surf_usm_v(0)%sasws,            &
-                                               surf_def_v(1)%sasws,            &
-                                               surf_lsm_v(1)%sasws,            &
-                                               surf_usm_v(1)%sasws,            &
-                                               surf_def_v(2)%sasws,            &
-                                               surf_lsm_v(2)%sasws,            &
-                                               surf_usm_v(2)%sasws,            &
-                                               surf_def_v(3)%sasws,            &
-                                               surf_lsm_v(3)%sasws,            &
-                                               surf_usm_v(3)%sasws )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'q_surface' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%q_surface,   &
-                                               surf_def_h(1)%q_surface,        &
-                                               surf_lsm_h%q_surface,           &
-                                               surf_usm_h%q_surface,           &
-                                               surf_def_v(0)%q_surface,        &
-                                               surf_lsm_v(0)%q_surface,        &
-                                               surf_usm_v(0)%q_surface,        &
-                                               surf_def_v(1)%q_surface,        &
-                                               surf_lsm_v(1)%q_surface,        &
-                                               surf_usm_v(1)%q_surface,        &
-                                               surf_def_v(2)%q_surface,        &
-                                               surf_lsm_v(2)%q_surface,        &
-                                               surf_usm_v(2)%q_surface,        &
-                                               surf_def_v(3)%q_surface,        &
-                                               surf_lsm_v(3)%q_surface,        &
-                                               surf_usm_v(3)%q_surface )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'theta_surface' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%pt_surface,  &
-                                               surf_def_h(1)%pt_surface,       &
-                                               surf_lsm_h%pt_surface,          &
-                                               surf_usm_h%pt_surface,          &
-                                               surf_def_v(0)%pt_surface,       &
-                                               surf_lsm_v(0)%pt_surface,       &
-                                               surf_usm_v(0)%pt_surface,       &
-                                               surf_def_v(1)%pt_surface,       &
-                                               surf_lsm_v(1)%pt_surface,       &
-                                               surf_usm_v(1)%pt_surface,       &
-                                               surf_def_v(2)%pt_surface,       &
-                                               surf_lsm_v(2)%pt_surface,       &
-                                               surf_usm_v(2)%pt_surface,       &
-                                               surf_def_v(3)%pt_surface,       &
-                                               surf_lsm_v(3)%pt_surface,       &
-                                               surf_usm_v(3)%pt_surface )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'thetav_surface' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%vpt_surface, &
-                                               surf_def_h(1)%vpt_surface,      &
-                                               surf_lsm_h%vpt_surface,         &
-                                               surf_usm_h%vpt_surface,         &
-                                               surf_def_v(0)%vpt_surface,      &
-                                               surf_lsm_v(0)%vpt_surface,      &
-                                               surf_usm_v(0)%vpt_surface,      &
-                                               surf_def_v(1)%vpt_surface,      &
-                                               surf_lsm_v(1)%vpt_surface,      &
-                                               surf_usm_v(1)%vpt_surface,      &
-                                               surf_def_v(2)%vpt_surface,      &
-                                               surf_lsm_v(2)%vpt_surface,      &
-                                               surf_usm_v(2)%vpt_surface,      &
-                                               surf_def_v(3)%vpt_surface,      &
-                                               surf_lsm_v(3)%vpt_surface,      &
-                                               surf_usm_v(3)%vpt_surface)
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_net' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_net,     &
-                                               surf_def_h(1)%rad_net,          &
-                                               surf_lsm_h%rad_net,             &
-                                               surf_usm_h%rad_net,             &
-                                               surf_def_v(0)%rad_net,          &
-                                               surf_lsm_v(0)%rad_net,          &
-                                               surf_usm_v(0)%rad_net,          &
-                                               surf_def_v(1)%rad_net,          &
-                                               surf_lsm_v(1)%rad_net,          &
-                                               surf_usm_v(1)%rad_net,          &
-                                               surf_def_v(2)%rad_net,          &
-                                               surf_lsm_v(2)%rad_net,          &
-                                               surf_usm_v(2)%rad_net,          &
-                                               surf_def_v(3)%rad_net,          &
-                                               surf_lsm_v(3)%rad_net,          &
-                                               surf_usm_v(3)%rad_net )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_lw_in' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_lw_in,   &
-                                               surf_def_h(1)%rad_lw_in,        &
-                                               surf_lsm_h%rad_lw_in,           &
-                                               surf_usm_h%rad_lw_in,           &
-                                               surf_def_v(0)%rad_lw_in,        &
-                                               surf_lsm_v(0)%rad_lw_in,        &
-                                               surf_usm_v(0)%rad_lw_in,        &
-                                               surf_def_v(1)%rad_lw_in,        &
-                                               surf_lsm_v(1)%rad_lw_in,        &
-                                               surf_usm_v(1)%rad_lw_in,        &
-                                               surf_def_v(2)%rad_lw_in,        &
-                                               surf_lsm_v(2)%rad_lw_in,        &
-                                               surf_usm_v(2)%rad_lw_in,        &
-                                               surf_def_v(3)%rad_lw_in,        &
-                                               surf_lsm_v(3)%rad_lw_in,        &
-                                               surf_usm_v(3)%rad_lw_in )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_lw_out' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_lw_out,  &
-                                               surf_def_h(1)%rad_lw_out,       &
-                                               surf_lsm_h%rad_lw_out,          &
-                                               surf_usm_h%rad_lw_out,          &
-                                               surf_def_v(0)%rad_lw_out,       &
-                                               surf_lsm_v(0)%rad_lw_out,       &
-                                               surf_usm_v(0)%rad_lw_out,       &
-                                               surf_def_v(1)%rad_lw_out,       &
-                                               surf_lsm_v(1)%rad_lw_out,       &
-                                               surf_usm_v(1)%rad_lw_out,       &
-                                               surf_def_v(2)%rad_lw_out,       &
-                                               surf_lsm_v(2)%rad_lw_out,       &
-                                               surf_usm_v(2)%rad_lw_out,       &
-                                               surf_def_v(3)%rad_lw_out,       &
-                                               surf_lsm_v(3)%rad_lw_out,       &
-                                               surf_usm_v(3)%rad_lw_out )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_sw_in' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_sw_in,   &
-                                               surf_def_h(1)%rad_sw_in,        &
-                                               surf_lsm_h%rad_sw_in,           &
-                                               surf_usm_h%rad_sw_in,           &
-                                               surf_def_v(0)%rad_sw_in,        &
-                                               surf_lsm_v(0)%rad_sw_in,        &
-                                               surf_usm_v(0)%rad_sw_in,        &
-                                               surf_def_v(1)%rad_sw_in,        &
-                                               surf_lsm_v(1)%rad_sw_in,        &
-                                               surf_usm_v(1)%rad_sw_in,        &
-                                               surf_def_v(2)%rad_sw_in,        &
-                                               surf_lsm_v(2)%rad_sw_in,        &
-                                               surf_usm_v(2)%rad_sw_in,        &
-                                               surf_def_v(3)%rad_sw_in,        &
-                                               surf_lsm_v(3)%rad_sw_in,        &
-                                               surf_usm_v(3)%rad_sw_in )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_sw_out' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_sw_out,  &
-                                               surf_def_h(1)%rad_sw_out,       &
-                                               surf_lsm_h%rad_sw_out,          &
-                                               surf_usm_h%rad_sw_out,          &
-                                               surf_def_v(0)%rad_sw_out,       &
-                                               surf_lsm_v(0)%rad_sw_out,       &
-                                               surf_usm_v(0)%rad_sw_out,       &
-                                               surf_def_v(1)%rad_sw_out,       &
-                                               surf_lsm_v(1)%rad_sw_out,       &
-                                               surf_usm_v(1)%rad_sw_out,       &
-                                               surf_def_v(2)%rad_sw_out,       &
-                                               surf_lsm_v(2)%rad_sw_out,       &
-                                               surf_usm_v(2)%rad_sw_out,       &
-                                               surf_def_v(3)%rad_sw_out,       &
-                                               surf_lsm_v(3)%rad_sw_out,       &
-                                               surf_usm_v(3)%rad_sw_out )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'ghf' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-!
-!--               Sum up ground / wall heat flux. Note, for urban surfaces the 
-!--               wall heat flux is aggregated from the different green, window
-!--               and wall tiles.
-                  DO  m = 1, surf_usm_h%ns
-                     surf_usm_h%ghf(m) = surf_usm_h%frac(m,ind_veg_wall)       &
-                                       * surf_usm_h%wghf_eb(m) +               &
-                                         surf_usm_h%frac(m,ind_pav_green)      &
-                                       * surf_usm_h%wghf_eb_green(m) +         &
-                                         surf_usm_h%frac(m,ind_wat_win)        &
-                                       * surf_usm_h%wghf_eb_window(m)
-                  ENDDO
-                  DO  l = 0, 3
-                     DO  m = 1, surf_usm_v(l)%ns
-                        surf_usm_v(l)%ghf(m) = surf_usm_v(l)%frac(m,ind_veg_wall) &
-                                             * surf_usm_v(l)%wghf_eb(m) +          &
-                                               surf_usm_v(l)%frac(m,ind_pav_green) &
-                                             * surf_usm_v(l)%wghf_eb_green(m) +    &
-                                               surf_usm_v(l)%frac(m,ind_wat_win)   &
-                                             * surf_usm_v(l)%wghf_eb_window(m)
-                     ENDDO
-                  ENDDO
-
-                  CALL surface_data_output_collect( surf_def_h(0)%ghf,         &
-                                               surf_def_h(1)%ghf,              &
-                                               surf_lsm_h%ghf,                 &
-                                               surf_usm_h%ghf,                 &
-                                               surf_def_v(0)%ghf,              &
-                                               surf_lsm_v(0)%ghf,              &
-                                               surf_usm_v(0)%ghf,              &
-                                               surf_def_v(1)%ghf,              &
-                                               surf_lsm_v(1)%ghf,              &
-                                               surf_usm_v(1)%ghf,              &
-                                               surf_def_v(2)%ghf,              &
-                                               surf_lsm_v(2)%ghf,              &
-                                               surf_usm_v(2)%ghf,              &
-                                               surf_def_v(3)%ghf,              &
-                                               surf_lsm_v(3)%ghf,              &
-                                               surf_usm_v(3)%ghf )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'r_a' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%r_a,         &
-                                               surf_def_h(1)%r_a,              &
-                                               surf_lsm_h%r_a,                 &
-                                               surf_usm_h%r_a,                 &
-                                               surf_def_v(0)%r_a,              &
-                                               surf_lsm_v(0)%r_a,              &
-                                               surf_usm_v(0)%r_a,              &
-                                               surf_def_v(1)%r_a,              &
-                                               surf_lsm_v(1)%r_a,              &
-                                               surf_usm_v(1)%r_a,              &
-                                               surf_def_v(2)%r_a,              &
-                                               surf_lsm_v(2)%r_a,              &
-                                               surf_usm_v(2)%r_a,              &
-                                               surf_def_v(3)%r_a,              &
-                                               surf_lsm_v(3)%r_a,              &
-                                               surf_usm_v(3)%r_a )
-                                                                      ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'r_soil' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%r_soil,      &
-                                               surf_def_h(1)%r_soil,           &
-                                               surf_lsm_h%r_soil,              &
-                                               surf_usm_h%r_soil,              &
-                                               surf_def_v(0)%r_soil,           &
-                                               surf_lsm_v(0)%r_soil,           &
-                                               surf_usm_v(0)%r_soil,           &
-                                               surf_def_v(1)%r_soil,           &
-                                               surf_lsm_v(1)%r_soil,           &
-                                               surf_usm_v(1)%r_soil,           &
-                                               surf_def_v(2)%r_soil,           &
-                                               surf_lsm_v(2)%r_soil,           &
-                                               surf_usm_v(2)%r_soil,           &
-                                               surf_def_v(3)%r_soil,           &
-                                               surf_lsm_v(3)%r_soil,           &
-                                               surf_usm_v(3)%r_soil )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'r_canopy' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%r_canopy,    &
-                                               surf_def_h(1)%r_canopy,         &
-                                               surf_lsm_h%r_canopy,            &
-                                               surf_usm_h%r_canopy,            &
-                                               surf_def_v(0)%r_canopy,         &
-                                               surf_lsm_v(0)%r_canopy,         &
-                                               surf_usm_v(0)%r_canopy,         &
-                                               surf_def_v(1)%r_canopy,         &
-                                               surf_lsm_v(1)%r_canopy,         &
-                                               surf_usm_v(1)%r_canopy,         &
-                                               surf_def_v(2)%r_canopy,         &
-                                               surf_lsm_v(2)%r_canopy,         &
-                                               surf_usm_v(2)%r_canopy,         &
-                                               surf_def_v(3)%r_canopy,         &
-                                               surf_lsm_v(3)%r_canopy,         &
-                                               surf_usm_v(3)%r_canopy )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'r_s' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%r_s,         &
-                                               surf_def_h(1)%r_s,              &
-                                               surf_lsm_h%r_s,                 &
-                                               surf_usm_h%r_s,                 &
-                                               surf_def_v(0)%r_s,              &
-                                               surf_lsm_v(0)%r_s,              &
-                                               surf_usm_v(0)%r_s,              &
-                                               surf_def_v(1)%r_s,              &
-                                               surf_lsm_v(1)%r_s,              &
-                                               surf_usm_v(1)%r_s,              &
-                                               surf_def_v(2)%r_s,              &
-                                               surf_lsm_v(2)%r_s,              &
-                                               surf_usm_v(2)%r_s,              &
-                                               surf_def_v(3)%r_s,              &
-                                               surf_lsm_v(3)%r_s,              &
-                                               surf_usm_v(3)%r_s )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_sw_dir' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_sw_dir,  &
-                                               surf_def_h(1)%rad_sw_dir,       &
-                                               surf_lsm_h%rad_sw_dir,          &
-                                               surf_usm_h%rad_sw_dir,          &
-                                               surf_def_v(0)%rad_sw_dir,       &
-                                               surf_lsm_v(0)%rad_sw_dir,       &
-                                               surf_usm_v(0)%rad_sw_dir,       &
-                                               surf_def_v(1)%rad_sw_dir,       &
-                                               surf_lsm_v(1)%rad_sw_dir,       &
-                                               surf_usm_v(1)%rad_sw_dir,       &
-                                               surf_def_v(2)%rad_sw_dir,       &
-                                               surf_lsm_v(2)%rad_sw_dir,       &
-                                               surf_usm_v(2)%rad_sw_dir,       &
-                                               surf_def_v(3)%rad_sw_dir,       &
-                                               surf_lsm_v(3)%rad_sw_dir,       &
-                                               surf_usm_v(3)%rad_sw_dir )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_sw_dif' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_sw_dif,  &
-                                               surf_def_h(1)%rad_sw_dif,       &
-                                               surf_lsm_h%rad_sw_dif,          &
-                                               surf_usm_h%rad_sw_dif,          &
-                                               surf_def_v(0)%rad_sw_dif,       &
-                                               surf_lsm_v(0)%rad_sw_dif,       &
-                                               surf_usm_v(0)%rad_sw_dif,       &
-                                               surf_def_v(1)%rad_sw_dif,       &
-                                               surf_lsm_v(1)%rad_sw_dif,       &
-                                               surf_usm_v(1)%rad_sw_dif,       &
-                                               surf_def_v(2)%rad_sw_dif,       &
-                                               surf_lsm_v(2)%rad_sw_dif,       &
-                                               surf_usm_v(2)%rad_sw_dif,       &
-                                               surf_def_v(3)%rad_sw_dif,       &
-                                               surf_lsm_v(3)%rad_sw_dif,       &
-                                               surf_usm_v(3)%rad_sw_dif )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_sw_ref' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_sw_ref,  &
-                                               surf_def_h(1)%rad_sw_ref,       &
-                                               surf_lsm_h%rad_sw_ref,          &
-                                               surf_usm_h%rad_sw_ref,          &
-                                               surf_def_v(0)%rad_sw_ref,       &
-                                               surf_lsm_v(0)%rad_sw_ref,       &
-                                               surf_usm_v(0)%rad_sw_ref,       &
-                                               surf_def_v(1)%rad_sw_ref,       &
-                                               surf_lsm_v(1)%rad_sw_ref,       &
-                                               surf_usm_v(1)%rad_sw_ref,       &
-                                               surf_def_v(2)%rad_sw_ref,       &
-                                               surf_lsm_v(2)%rad_sw_ref,       &
-                                               surf_usm_v(2)%rad_sw_ref,       &
-                                               surf_def_v(3)%rad_sw_ref,       &
-                                               surf_lsm_v(3)%rad_sw_ref,       &
-                                               surf_usm_v(3)%rad_sw_ref )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_sw_res' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_sw_res,  &
-                                               surf_def_h(1)%rad_sw_res,       &
-                                               surf_lsm_h%rad_sw_res,          &
-                                               surf_usm_h%rad_sw_res,          &
-                                               surf_def_v(0)%rad_sw_res,       &
-                                               surf_lsm_v(0)%rad_sw_res,       &
-                                               surf_usm_v(0)%rad_sw_res,       &
-                                               surf_def_v(1)%rad_sw_res,       &
-                                               surf_lsm_v(1)%rad_sw_res,       &
-                                               surf_usm_v(1)%rad_sw_res,       &
-                                               surf_def_v(2)%rad_sw_res,       &
-                                               surf_lsm_v(2)%rad_sw_res,       &
-                                               surf_usm_v(2)%rad_sw_res,       &
-                                               surf_def_v(3)%rad_sw_res,       &
-                                               surf_lsm_v(3)%rad_sw_res,       &
-                                               surf_usm_v(3)%rad_sw_res )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_lw_dif' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_lw_dif,  &
-                                               surf_def_h(1)%rad_lw_dif,       &
-                                               surf_lsm_h%rad_lw_dif,          &
-                                               surf_usm_h%rad_lw_dif,          &
-                                               surf_def_v(0)%rad_lw_dif,       &
-                                               surf_lsm_v(0)%rad_lw_dif,       &
-                                               surf_usm_v(0)%rad_lw_dif,       &
-                                               surf_def_v(1)%rad_lw_dif,       &
-                                               surf_lsm_v(1)%rad_lw_dif,       &
-                                               surf_usm_v(1)%rad_lw_dif,       &
-                                               surf_def_v(2)%rad_lw_dif,       &
-                                               surf_lsm_v(2)%rad_lw_dif,       &
-                                               surf_usm_v(2)%rad_lw_dif,       &
-                                               surf_def_v(3)%rad_lw_dif,       &
-                                               surf_lsm_v(3)%rad_lw_dif,       &
-                                               surf_usm_v(3)%rad_lw_dif )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_lw_ref' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_lw_ref,  &
-                                               surf_def_h(1)%rad_lw_ref,       &
-                                               surf_lsm_h%rad_lw_ref,          &
-                                               surf_usm_h%rad_lw_ref,          &
-                                               surf_def_v(0)%rad_lw_ref,       &
-                                               surf_lsm_v(0)%rad_lw_ref,       &
-                                               surf_usm_v(0)%rad_lw_ref,       &
-                                               surf_def_v(1)%rad_lw_ref,       &
-                                               surf_lsm_v(1)%rad_lw_ref,       &
-                                               surf_usm_v(1)%rad_lw_ref,       &
-                                               surf_def_v(2)%rad_lw_ref,       &
-                                               surf_lsm_v(2)%rad_lw_ref,       &
-                                               surf_usm_v(2)%rad_lw_ref,       &
-                                               surf_def_v(3)%rad_lw_ref,       &
-                                               surf_lsm_v(3)%rad_lw_ref,       &
-                                               surf_usm_v(3)%rad_lw_ref )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'rad_lw_res' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%rad_lw_res,  &
-                                               surf_def_h(1)%rad_lw_res,       &
-                                               surf_lsm_h%rad_lw_res,          &
-                                               surf_usm_h%rad_lw_res,          &
-                                               surf_def_v(0)%rad_lw_res,       &
-                                               surf_lsm_v(0)%rad_lw_res,       &
-                                               surf_usm_v(0)%rad_lw_res,       &
-                                               surf_def_v(1)%rad_lw_res,       &
-                                               surf_lsm_v(1)%rad_lw_res,       &
-                                               surf_usm_v(1)%rad_lw_res,       &
-                                               surf_def_v(2)%rad_lw_res,       &
-                                               surf_lsm_v(2)%rad_lw_res,       &
-                                               surf_usm_v(2)%rad_lw_res,       &
-                                               surf_def_v(3)%rad_lw_res,       &
-                                               surf_lsm_v(3)%rad_lw_res,       &
-                                               surf_usm_v(3)%rad_lw_res )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-
-            CASE ( 'uvw1' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%uvw_abs,     &
-                                               surf_def_h(1)%uvw_abs,          &
-                                               surf_lsm_h%uvw_abs,             &
-                                               surf_usm_h%uvw_abs,             &
-                                               surf_def_v(0)%uvw_abs,          &
-                                               surf_lsm_v(0)%uvw_abs,          &
-                                               surf_usm_v(0)%uvw_abs,          &
-                                               surf_def_v(1)%uvw_abs,          &
-                                               surf_lsm_v(1)%uvw_abs,          &
-                                               surf_usm_v(1)%uvw_abs,          &
-                                               surf_def_v(2)%uvw_abs,          &
-                                               surf_lsm_v(2)%uvw_abs,          &
-                                               surf_usm_v(2)%uvw_abs,          &
-                                               surf_def_v(3)%uvw_abs,          &
-                                               surf_lsm_v(3)%uvw_abs,          &
-                                               surf_usm_v(3)%uvw_abs )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-!
-!--         Waste heat from indoor model
-            CASE ( 'waste_heat' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%waste_heat,  &
-                                               surf_def_h(1)%waste_heat,       &
-                                               surf_lsm_h%waste_heat,          &
-                                               surf_usm_h%waste_heat,          &
-                                               surf_def_v(0)%waste_heat,       &
-                                               surf_lsm_v(0)%waste_heat,       &
-                                               surf_usm_v(0)%waste_heat,       &
-                                               surf_def_v(1)%waste_heat,       &
-                                               surf_lsm_v(1)%waste_heat,       &
-                                               surf_usm_v(1)%waste_heat,       &
-                                               surf_def_v(2)%waste_heat,       &
-                                               surf_lsm_v(2)%waste_heat,       &
-                                               surf_usm_v(2)%waste_heat,       &
-                                               surf_def_v(3)%waste_heat,       &
-                                               surf_lsm_v(3)%waste_heat,       &
-                                               surf_usm_v(3)%waste_heat )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-!
-!--         Innermost building wall flux from indoor model
-            CASE ( 'im_hf' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%iwghf_eb,    &
-                                               surf_def_h(1)%iwghf_eb,         &
-                                               surf_lsm_h%iwghf_eb,            &
-                                               surf_usm_h%iwghf_eb,            &
-                                               surf_def_v(0)%iwghf_eb,         &
-                                               surf_lsm_v(0)%iwghf_eb,         &
-                                               surf_usm_v(0)%iwghf_eb,         &
-                                               surf_def_v(1)%iwghf_eb,         &
-                                               surf_lsm_v(1)%iwghf_eb,         &
-                                               surf_usm_v(1)%iwghf_eb,         &
-                                               surf_def_v(2)%iwghf_eb,         &
-                                               surf_lsm_v(2)%iwghf_eb,         &
-                                               surf_usm_v(2)%iwghf_eb,         &
-                                               surf_def_v(3)%iwghf_eb,         &
-                                               surf_lsm_v(3)%iwghf_eb,         &
-                                               surf_usm_v(3)%iwghf_eb )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-!
-!--         Surface albedo (tile approach)
-            CASE ( 'albedo' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%albedo,     &
-                                               surf_def_h(1)%albedo,          &
-                                               surf_lsm_h%albedo,             &
-                                               surf_usm_h%albedo,             &
-                                               surf_def_v(0)%albedo,          &
-                                               surf_lsm_v(0)%albedo,          &
-                                               surf_usm_v(0)%albedo,          &
-                                               surf_def_v(1)%albedo,          &
-                                               surf_lsm_v(1)%albedo,          &
-                                               surf_usm_v(1)%albedo,          &
-                                               surf_def_v(2)%albedo,          &
-                                               surf_lsm_v(2)%albedo,          &
-                                               surf_usm_v(2)%albedo,          &
-                                               surf_def_v(3)%albedo,          &
-                                               surf_lsm_v(3)%albedo,          &
-                                               surf_usm_v(3)%albedo )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /            &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-!
-!--         Surface emissivity (tile approach)
-            CASE ( 'emissivity' )
-!
-!--            Output of instantaneous data
-               IF ( av == 0 )  THEN
-                  CALL surface_data_output_collect( surf_def_h(0)%emissivity, &
-                                               surf_def_h(1)%emissivity,      &
-                                               surf_lsm_h%emissivity,         &
-                                               surf_usm_h%emissivity,         &
-                                               surf_def_v(0)%emissivity,      &
-                                               surf_lsm_v(0)%emissivity,      &
-                                               surf_usm_v(0)%emissivity,      &
-                                               surf_def_v(1)%emissivity,      &
-                                               surf_lsm_v(1)%emissivity,      &
-                                               surf_usm_v(1)%emissivity,      &
-                                               surf_def_v(2)%emissivity,      &
-                                               surf_lsm_v(2)%emissivity,      &
-                                               surf_usm_v(2)%emissivity,      &
-                                               surf_def_v(3)%emissivity,      &
-                                               surf_lsm_v(3)%emissivity,      &
-                                               surf_usm_v(3)%emissivity )
-               ELSE
-!
-!--               Output of averaged data
-                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /            &
-                                        REAL( average_count_surf, KIND=wp )
-                  surfaces%var_av(:,n_out) = 0.0_wp
-
-               ENDIF
-!
-!--            Add further variables:
-!--            'css', 'cssws', 'qsws_liq', 'qsws_soil', 'qsws_veg'
-
-         END SELECT
-!
-!--      Write to binary file:
-!--      - surfaces%points ( 3, 1-npoints )
-!--      - surfaces%polygons ( 5, 1-ns )
-!--      - surfaces%var_out ( 1-ns, time )
-!--      - Dimension: 1-nsurfaces, 1-npoints - can be ordered consecutively
-!--      - Distinguish between average and non-average data
-         IF ( to_vtk )  THEN
-            DO  i = 0, io_blocks-1
-               IF ( i == io_group )  THEN
-                  WRITE ( 25+av )  LEN_TRIM( 'time' )
-                  WRITE ( 25+av )  'time'
-                  WRITE ( 25+av )  time_since_reference_point
-                  WRITE ( 25+av )  LEN_TRIM( trimvar )
-                  WRITE ( 25+av )  TRIM( trimvar )
-                  WRITE ( 25+av )  surfaces%var_out
-               ENDIF
-#if defined( __parallel )
-               CALL MPI_BARRIER( comm2d, ierr )
-#endif
-            ENDDO
-         ENDIF
-
-         IF ( to_netcdf )  THEN
-#if defined( __netcdf4_parallel )
-!
-!--         Write output array to file
-            nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_dosurf(av,n_out),  &
-                                    surfaces%var_out,                          &
-                                    start = (/ surfaces%s(1),                  &
-                                               dosurf_time_count(av) /),       &
-                                    count = (/ surfaces%ns, 1 /) )
-            CALL netcdf_handle_error( 'surface_data_output', 6667 )
-#endif
-         ENDIF
-
-      ENDDO
-
-!
-!--   If averaged output was written to NetCDF file, set the counter to zero
-      IF ( av == 1 )  average_count_surf = 0
-
-   END SUBROUTINE surface_data_output
-
-!------------------------------------------------------------------------------!
+
+    ENDDO
+
+!
+!-- If averaged output was written to NetCDF file, set the counter to zero
+    IF ( av == 1 )  average_count_surf = 0
+
+ END SUBROUTINE surface_data_output
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Routine for controlling the data averaging.
-!------------------------------------------------------------------------------!
-   SUBROUTINE surface_data_output_averaging
-
-      IMPLICIT NONE
-
-      CHARACTER(LEN=100) ::  trimvar !< dummy variable for current output variable
-
-      INTEGER(iwp) ::  l      !< running index for surface orientation
-      INTEGER(iwp) ::  m      !< running index for surface elements
-      INTEGER(iwp) ::  n_out  !< counter variables for surface output
-
-      n_out = 0
-      DO  WHILE ( dosurf(1,n_out+1)(1:1) /= ' ' )
-
-         n_out   = n_out + 1
-         trimvar = TRIM( dosurf(1,n_out) )
-
-         SELECT CASE ( trimvar )
-
-            CASE ( 'us' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%us,              &
-                                           surf_def_h(1)%us,                   &
-                                           surf_lsm_h%us,                      &
-                                           surf_usm_h%us,                      &
-                                           surf_def_v(0)%us,                   &
-                                           surf_lsm_v(0)%us,                   &
-                                           surf_usm_v(0)%us,                   &
-                                           surf_def_v(1)%us,                   &
-                                           surf_lsm_v(1)%us,                   &
-                                           surf_usm_v(1)%us,                   &
-                                           surf_def_v(2)%us,                   &
-                                           surf_lsm_v(2)%us,                   &
-                                           surf_usm_v(2)%us,                   &
-                                           surf_def_v(3)%us,                   &
-                                           surf_lsm_v(3)%us,                   &
-                                           surf_usm_v(3)%us, n_out )
-
-            CASE ( 'ts' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%ts,              &
-                                           surf_def_h(1)%ts,                   &
-                                           surf_lsm_h%ts,                      &
-                                           surf_usm_h%ts,                      &
-                                           surf_def_v(0)%ts,                   &
-                                           surf_lsm_v(0)%ts,                   &
-                                           surf_usm_v(0)%ts,                   &
-                                           surf_def_v(1)%ts,                   &
-                                           surf_lsm_v(1)%ts,                   &
-                                           surf_usm_v(1)%ts,                   &
-                                           surf_def_v(2)%ts,                   &
-                                           surf_lsm_v(2)%ts,                   &
-                                           surf_usm_v(2)%ts,                   &
-                                           surf_def_v(3)%ts,                   &
-                                           surf_lsm_v(3)%ts,                   &
-                                           surf_usm_v(3)%ts, n_out )
-
-            CASE ( 'qs' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%qs,              &
-                                           surf_def_h(1)%qs,                   &
-                                           surf_lsm_h%qs,                      &
-                                           surf_usm_h%qs,                      &
-                                           surf_def_v(0)%qs,                   &
-                                           surf_lsm_v(0)%qs,                   &
-                                           surf_usm_v(0)%qs,                   &
-                                           surf_def_v(1)%qs,                   &
-                                           surf_lsm_v(1)%qs,                   &
-                                           surf_usm_v(1)%qs,                   &
-                                           surf_def_v(2)%qs,                   &
-                                           surf_lsm_v(2)%qs,                   &
-                                           surf_usm_v(2)%qs,                   &
-                                           surf_def_v(3)%qs,                   &
-                                           surf_lsm_v(3)%qs,                   &
-                                           surf_usm_v(3)%qs, n_out )
-
-            CASE ( 'ss' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%ss,              &
-                                           surf_def_h(1)%ss,                   &
-                                           surf_lsm_h%ss,                      &
-                                           surf_usm_h%ss,                      &
-                                           surf_def_v(0)%ss,                   &
-                                           surf_lsm_v(0)%ss,                   &
-                                           surf_usm_v(0)%ss,                   &
-                                           surf_def_v(1)%ss,                   &
-                                           surf_lsm_v(1)%ss,                   &
-                                           surf_usm_v(1)%ss,                   &
-                                           surf_def_v(2)%ss,                   &
-                                           surf_lsm_v(2)%ss,                   &
-                                           surf_usm_v(2)%ss,                   &
-                                           surf_def_v(3)%ss,                   &
-                                           surf_lsm_v(3)%ss,                   &
-                                           surf_usm_v(3)%ss, n_out )
-
-            CASE ( 'qcs' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%qcs,             &
-                                           surf_def_h(1)%qcs,                  &
-                                           surf_lsm_h%qcs,                     &
-                                           surf_usm_h%qcs,                     &
-                                           surf_def_v(0)%qcs,                  &
-                                           surf_lsm_v(0)%qcs,                  &
-                                           surf_usm_v(0)%qcs,                  &
-                                           surf_def_v(1)%qcs,                  &
-                                           surf_lsm_v(1)%qcs,                  &
-                                           surf_usm_v(1)%qcs,                  &
-                                           surf_def_v(2)%qcs,                  &
-                                           surf_lsm_v(2)%qcs,                  &
-                                           surf_usm_v(2)%qcs,                  &
-                                           surf_def_v(3)%qcs,                  &
-                                           surf_lsm_v(3)%qcs,                  &
-                                           surf_usm_v(3)%qcs, n_out )
-
-            CASE ( 'ncs' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%ncs,             &
-                                           surf_def_h(1)%ncs,                  &
-                                           surf_lsm_h%ncs,                     &
-                                           surf_usm_h%ncs,                     &
-                                           surf_def_v(0)%ncs,                  &
-                                           surf_lsm_v(0)%ncs,                  &
-                                           surf_usm_v(0)%ncs,                  &
-                                           surf_def_v(1)%ncs,                  &
-                                           surf_lsm_v(1)%ncs,                  &
-                                           surf_usm_v(1)%ncs,                  &
-                                           surf_def_v(2)%ncs,                  &
-                                           surf_lsm_v(2)%ncs,                  &
-                                           surf_usm_v(2)%ncs,                  &
-                                           surf_def_v(3)%ncs,                  &
-                                           surf_lsm_v(3)%ncs,                  &
-                                           surf_usm_v(3)%ncs, n_out )
-
-            CASE ( 'qis' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%qis,             &
-                                           surf_def_h(1)%qis,                  &
-                                           surf_lsm_h%qis,                     &
-                                           surf_usm_h%qis,                     &
-                                           surf_def_v(0)%qis,                  &
-                                           surf_lsm_v(0)%qis,                  &
-                                           surf_usm_v(0)%qis,                  &
-                                           surf_def_v(1)%qis,                  &
-                                           surf_lsm_v(1)%qis,                  &
-                                           surf_usm_v(1)%qis,                  &
-                                           surf_def_v(2)%qis,                  &
-                                           surf_lsm_v(2)%qis,                  &
-                                           surf_usm_v(2)%qis,                  &
-                                           surf_def_v(3)%qis,                  &
-                                           surf_lsm_v(3)%qis,                  &
-                                           surf_usm_v(3)%qrs, n_out )
-
-            CASE ( 'nis' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%nis,             &
-                                           surf_def_h(1)%nis,                  &
-                                           surf_lsm_h%nis,                     &
-                                           surf_usm_h%nis,                     &
-                                           surf_def_v(0)%nis,                  &
-                                           surf_lsm_v(0)%nis,                  &
-                                           surf_usm_v(0)%nis,                  &
-                                           surf_def_v(1)%nis,                  &
-                                           surf_lsm_v(1)%nis,                  &
-                                           surf_usm_v(1)%nis,                  &
-                                           surf_def_v(2)%nis,                  &
-                                           surf_lsm_v(2)%nis,                  &
-                                           surf_usm_v(2)%nis,                  &
-                                           surf_def_v(3)%nis,                  &
-                                           surf_lsm_v(3)%nis,                  &
-                                           surf_usm_v(3)%nis, n_out )
-
-            CASE ( 'qrs' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%qrs,             &
-                                           surf_def_h(1)%qrs,                  &
-                                           surf_lsm_h%qrs,                     &
-                                           surf_usm_h%qrs,                     &
-                                           surf_def_v(0)%qrs,                  &
-                                           surf_lsm_v(0)%qrs,                  &
-                                           surf_usm_v(0)%qrs,                  &
-                                           surf_def_v(1)%qrs,                  &
-                                           surf_lsm_v(1)%qrs,                  &
-                                           surf_usm_v(1)%qrs,                  &
-                                           surf_def_v(2)%qrs,                  &
-                                           surf_lsm_v(2)%qrs,                  &
-                                           surf_usm_v(2)%qrs,                  &
-                                           surf_def_v(3)%qrs,                  &
-                                           surf_lsm_v(3)%qrs,                  &
-                                           surf_usm_v(3)%qrs, n_out )
-
-            CASE ( 'nrs' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%nrs,             &
-                                           surf_def_h(1)%nrs,                  &
-                                           surf_lsm_h%nrs,                     &
-                                           surf_usm_h%nrs,                     &
-                                           surf_def_v(0)%nrs,                  &
-                                           surf_lsm_v(0)%nrs,                  &
-                                           surf_usm_v(0)%nrs,                  &
-                                           surf_def_v(1)%nrs,                  &
-                                           surf_lsm_v(1)%nrs,                  &
-                                           surf_usm_v(1)%nrs,                  &
-                                           surf_def_v(2)%nrs,                  &
-                                           surf_lsm_v(2)%nrs,                  &
-                                           surf_usm_v(2)%nrs,                  &
-                                           surf_def_v(3)%nrs,                  &
-                                           surf_lsm_v(3)%nrs,                  &
-                                           surf_usm_v(3)%nrs, n_out )
-
-            CASE ( 'ol' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%ol,              &
-                                           surf_def_h(1)%ol,                   &
-                                           surf_lsm_h%ol,                      &
-                                           surf_usm_h%ol,                      &
-                                           surf_def_v(0)%ol,                   &
-                                           surf_lsm_v(0)%ol,                   &
-                                           surf_usm_v(0)%ol,                   &
-                                           surf_def_v(1)%ol,                   &
-                                           surf_lsm_v(1)%ol,                   &
-                                           surf_usm_v(1)%ol,                   &
-                                           surf_def_v(2)%ol,                   &
-                                           surf_lsm_v(2)%ol,                   &
-                                           surf_usm_v(2)%ol,                   &
-                                           surf_def_v(3)%ol,                   &
-                                           surf_lsm_v(3)%ol,                   &
-                                           surf_usm_v(3)%ol, n_out )
-
-            CASE ( 'z0' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%z0,              &
-                                           surf_def_h(1)%z0,                   &
-                                           surf_lsm_h%z0,                      &
-                                           surf_usm_h%z0,                      &
-                                           surf_def_v(0)%z0,                   &
-                                           surf_lsm_v(0)%z0,                   &
-                                           surf_usm_v(0)%z0,                   &
-                                           surf_def_v(1)%z0,                   &
-                                           surf_lsm_v(1)%z0,                   &
-                                           surf_usm_v(1)%z0,                   &
-                                           surf_def_v(2)%z0,                   &
-                                           surf_lsm_v(2)%z0,                   &
-                                           surf_usm_v(2)%z0,                   &
-                                           surf_def_v(3)%z0,                   &
-                                           surf_lsm_v(3)%z0,                   &
-                                           surf_usm_v(3)%z0, n_out )
-
-            CASE ( 'z0h' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%z0h,             &
-                                           surf_def_h(1)%z0h,                  &
-                                           surf_lsm_h%z0h,                     &
-                                           surf_usm_h%z0h,                     &
-                                           surf_def_v(0)%z0h,                  &
-                                           surf_lsm_v(0)%z0h,                  &
-                                           surf_usm_v(0)%z0h,                  &
-                                           surf_def_v(1)%z0h,                  &
-                                           surf_lsm_v(1)%z0h,                  &
-                                           surf_usm_v(1)%z0h,                  &
-                                           surf_def_v(2)%z0h,                  &
-                                           surf_lsm_v(2)%z0h,                  &
-                                           surf_usm_v(2)%z0h,                  &
-                                           surf_def_v(3)%z0h,                  &
-                                           surf_lsm_v(3)%z0h,                  &
-                                           surf_usm_v(3)%z0h, n_out )
-
-            CASE ( 'z0q' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%z0q,             &
-                                           surf_def_h(1)%z0q,                  &
-                                           surf_lsm_h%z0q,                     &
-                                           surf_usm_h%z0q,                     &
-                                           surf_def_v(0)%z0q,                  &
-                                           surf_lsm_v(0)%z0q,                  &
-                                           surf_usm_v(0)%z0q,                  &
-                                           surf_def_v(1)%z0q,                  &
-                                           surf_lsm_v(1)%z0q,                  &
-                                           surf_usm_v(1)%z0q,                  &
-                                           surf_def_v(2)%z0q,                  &
-                                           surf_lsm_v(2)%z0q,                  &
-                                           surf_usm_v(2)%z0q,                  &
-                                           surf_def_v(3)%z0q,                  &
-                                           surf_lsm_v(3)%z0q,                  &
-                                           surf_usm_v(3)%z0q, n_out )
-
-            CASE ( 'theta1' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%pt1,             &
-                                           surf_def_h(1)%pt1,                  &
-                                           surf_lsm_h%pt1,                     &
-                                           surf_usm_h%pt1,                     &
-                                           surf_def_v(0)%pt1,                  &
-                                           surf_lsm_v(0)%pt1,                  &
-                                           surf_usm_v(0)%pt1,                  &
-                                           surf_def_v(1)%pt1,                  &
-                                           surf_lsm_v(1)%pt1,                  &
-                                           surf_usm_v(1)%pt1,                  &
-                                           surf_def_v(2)%pt1,                  &
-                                           surf_lsm_v(2)%pt1,                  &
-                                           surf_usm_v(2)%pt1,                  &
-                                           surf_def_v(3)%pt1,                  &
-                                           surf_lsm_v(3)%pt1,                  &
-                                           surf_usm_v(3)%pt1, n_out )
-
-            CASE ( 'qv1' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%qv1,             &
-                                           surf_def_h(1)%qv1,                  &
-                                           surf_lsm_h%qv1,                     &
-                                           surf_usm_h%qv1,                     &
-                                           surf_def_v(0)%qv1,                  &
-                                           surf_lsm_v(0)%qv1,                  &
-                                           surf_usm_v(0)%qv1,                  &
-                                           surf_def_v(1)%qv1,                  &
-                                           surf_lsm_v(1)%qv1,                  &
-                                           surf_usm_v(1)%qv1,                  &
-                                           surf_def_v(2)%qv1,                  &
-                                           surf_lsm_v(2)%qv1,                  &
-                                           surf_usm_v(2)%qv1,                  &
-                                           surf_def_v(3)%qv1,                  &
-                                           surf_lsm_v(3)%qv1,                  &
-                                           surf_usm_v(3)%qv1, n_out )
-
-            CASE ( 'thetav1' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%vpt1,            &
-                                           surf_def_h(1)%vpt1,                 &
-                                           surf_lsm_h%vpt1,                    &
-                                           surf_usm_h%vpt1,                    &
-                                           surf_def_v(0)%vpt1,                 &
-                                           surf_lsm_v(0)%vpt1,                 &
-                                           surf_usm_v(0)%vpt1,                 &
-                                           surf_def_v(1)%vpt1,                 &
-                                           surf_lsm_v(1)%vpt1,                 &
-                                           surf_usm_v(1)%vpt1,                 &
-                                           surf_def_v(2)%vpt1,                 &
-                                           surf_lsm_v(2)%vpt1,                 &
-                                           surf_usm_v(2)%vpt1,                 &
-                                           surf_def_v(3)%vpt1,                 &
-                                           surf_lsm_v(3)%vpt1,                 &
-                                           surf_usm_v(3)%vpt1, n_out )
-
-            CASE ( 'usws' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%usws,            &
-                                           surf_def_h(1)%usws,                 &
-                                           surf_lsm_h%usws,                    &
-                                           surf_usm_h%usws,                    &
-                                           surf_def_v(0)%usws,                 &
-                                           surf_lsm_v(0)%usws,                 &
-                                           surf_usm_v(0)%usws,                 &
-                                           surf_def_v(1)%usws,                 &
-                                           surf_lsm_v(1)%usws,                 &
-                                           surf_usm_v(1)%usws,                 &
-                                           surf_def_v(2)%usws,                 &
-                                           surf_lsm_v(2)%usws,                 &
-                                           surf_usm_v(2)%usws,                 &
-                                           surf_def_v(3)%usws,                 &
-                                           surf_lsm_v(3)%usws,                 &
-                                           surf_usm_v(3)%usws, n_out,          &
-                                           momentumflux_output_conversion )
-
-            CASE ( 'vsws' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%vsws,            &
-                                           surf_def_h(1)%vsws,                 &
-                                           surf_lsm_h%vsws,                    &
-                                           surf_usm_h%vsws,                    &
-                                           surf_def_v(0)%vsws,                 &
-                                           surf_lsm_v(0)%vsws,                 &
-                                           surf_usm_v(0)%vsws,                 &
-                                           surf_def_v(1)%vsws,                 &
-                                           surf_lsm_v(1)%vsws,                 &
-                                           surf_usm_v(1)%vsws,                 &
-                                           surf_def_v(2)%vsws,                 &
-                                           surf_lsm_v(2)%vsws,                 &
-                                           surf_usm_v(2)%vsws,                 &
-                                           surf_def_v(3)%vsws,                 &
-                                           surf_lsm_v(3)%vsws,                 &
-                                           surf_usm_v(3)%vsws, n_out,          &
-                                           momentumflux_output_conversion )
-
-            CASE ( 'shf' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%shf,             &
-                                           surf_def_h(1)%shf,                  &
-                                           surf_lsm_h%shf,                     &
-                                           surf_usm_h%shf,                     &
-                                           surf_def_v(0)%shf,                  &
-                                           surf_lsm_v(0)%shf,                  &
-                                           surf_usm_v(0)%shf,                  &
-                                           surf_def_v(1)%shf,                  &
-                                           surf_lsm_v(1)%shf,                  &
-                                           surf_usm_v(1)%shf,                  &
-                                           surf_def_v(2)%shf,                  &
-                                           surf_lsm_v(2)%shf,                  &
-                                           surf_usm_v(2)%shf,                  &
-                                           surf_def_v(3)%shf,                  &
-                                           surf_lsm_v(3)%shf,                  &
-                                           surf_usm_v(3)%shf, n_out,          &
-                                           heatflux_output_conversion )
-
-            CASE ( 'qsws' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%qsws,            &
-                                           surf_def_h(1)%qsws,                 &
-                                           surf_lsm_h%qsws,                    &
-                                           surf_usm_h%qsws,                    &
-                                           surf_def_v(0)%qsws,                 &
-                                           surf_lsm_v(0)%qsws,                 &
-                                           surf_usm_v(0)%qsws,                 &
-                                           surf_def_v(1)%qsws,                 &
-                                           surf_lsm_v(1)%qsws,                 &
-                                           surf_usm_v(1)%qsws,                 &
-                                           surf_def_v(2)%qsws,                 &
-                                           surf_lsm_v(2)%qsws,                 &
-                                           surf_usm_v(2)%qsws,                 &
-                                           surf_def_v(3)%qsws,                 &
-                                           surf_lsm_v(3)%qsws,                 &
-                                           surf_usm_v(3)%qsws, n_out,          &
-                                           waterflux_output_conversion )
-
-            CASE ( 'ssws' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%ssws,            &
-                                           surf_def_h(1)%ssws,                 &
-                                           surf_lsm_h%ssws,                    &
-                                           surf_usm_h%ssws,                    &
-                                           surf_def_v(0)%ssws,                 &
-                                           surf_lsm_v(0)%ssws,                 &
-                                           surf_usm_v(0)%ssws,                 &
-                                           surf_def_v(1)%ssws,                 &
-                                           surf_lsm_v(1)%ssws,                 &
-                                           surf_usm_v(1)%ssws,                 &
-                                           surf_def_v(2)%ssws,                 &
-                                           surf_lsm_v(2)%ssws,                 &
-                                           surf_usm_v(2)%ssws,                 &
-                                           surf_def_v(3)%ssws,                 &
-                                           surf_lsm_v(3)%ssws,                 &
-                                           surf_usm_v(3)%ssws, n_out )
-
-            CASE ( 'qcsws' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%qcsws,           &
-                                           surf_def_h(1)%qcsws,                &
-                                           surf_lsm_h%qcsws,                   &
-                                           surf_usm_h%qcsws,                   &
-                                           surf_def_v(0)%qcsws,                &
-                                           surf_lsm_v(0)%qcsws,                &
-                                           surf_usm_v(0)%qcsws,                &
-                                           surf_def_v(1)%qcsws,                &
-                                           surf_lsm_v(1)%qcsws,                &
-                                           surf_usm_v(1)%qcsws,                &
-                                           surf_def_v(2)%qcsws,                &
-                                           surf_lsm_v(2)%qcsws,                &
-                                           surf_usm_v(2)%qcsws,                &
-                                           surf_def_v(3)%qcsws,                &
-                                           surf_lsm_v(3)%qcsws,                &
-                                           surf_usm_v(3)%qcsws, n_out )
-
-            CASE ( 'ncsws' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%ncsws,           &
-                                           surf_def_h(1)%ncsws,                &
-                                           surf_lsm_h%ncsws,                   &
-                                           surf_usm_h%ncsws,                   &
-                                           surf_def_v(0)%ncsws,                &
-                                           surf_lsm_v(0)%ncsws,                &
-                                           surf_usm_v(0)%ncsws,                &
-                                           surf_def_v(1)%ncsws,                &
-                                           surf_lsm_v(1)%ncsws,                &
-                                           surf_usm_v(1)%ncsws,                &
-                                           surf_def_v(2)%ncsws,                &
-                                           surf_lsm_v(2)%ncsws,                &
-                                           surf_usm_v(2)%ncsws,                &
-                                           surf_def_v(3)%ncsws,                &
-                                           surf_lsm_v(3)%ncsws,                &
-                                           surf_usm_v(3)%ncsws, n_out )
-
-            CASE ( 'qisws' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%qisws,           &
-                                           surf_def_h(1)%qisws,                &
-                                           surf_lsm_h%qisws,                   &
-                                           surf_usm_h%qisws,                   &
-                                           surf_def_v(0)%qisws,                &
-                                           surf_lsm_v(0)%qisws,                &
-                                           surf_usm_v(0)%qisws,                &
-                                           surf_def_v(1)%qisws,                &
-                                           surf_lsm_v(1)%qisws,                &
-                                           surf_usm_v(1)%qisws,                &
-                                           surf_def_v(2)%qisws,                &
-                                           surf_lsm_v(2)%qisws,                &
-                                           surf_usm_v(2)%qisws,                &
-                                           surf_def_v(3)%qisws,                &
-                                           surf_lsm_v(3)%qisws,                &
-                                           surf_usm_v(3)%qisws, n_out )
-
-            CASE ( 'nisws' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%nisws,           &
-                                           surf_def_h(1)%nisws,                &
-                                           surf_lsm_h%nisws,                   &
-                                           surf_usm_h%nisws,                   &
-                                           surf_def_v(0)%nisws,                &
-                                           surf_lsm_v(0)%nisws,                &
-                                           surf_usm_v(0)%nisws,                &
-                                           surf_def_v(1)%nisws,                &
-                                           surf_lsm_v(1)%nisws,                &
-                                           surf_usm_v(1)%nisws,                &
-                                           surf_def_v(2)%nisws,                &
-                                           surf_lsm_v(2)%nisws,                &
-                                           surf_usm_v(2)%nisws,                &
-                                           surf_def_v(3)%nisws,                &
-                                           surf_lsm_v(3)%nisws,                &
-                                           surf_usm_v(3)%nisws, n_out )
-
-            CASE ( 'qrsws' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%qrsws,           &
-                                           surf_def_h(1)%qrsws,                &
-                                           surf_lsm_h%qrsws,                   &
-                                           surf_usm_h%qrsws,                   &
-                                           surf_def_v(0)%qrsws,                &
-                                           surf_lsm_v(0)%qrsws,                &
-                                           surf_usm_v(0)%qrsws,                &
-                                           surf_def_v(1)%qrsws,                &
-                                           surf_lsm_v(1)%qrsws,                &
-                                           surf_usm_v(1)%qrsws,                &
-                                           surf_def_v(2)%qrsws,                &
-                                           surf_lsm_v(2)%qrsws,                &
-                                           surf_usm_v(2)%qrsws,                &
-                                           surf_def_v(3)%qrsws,                &
-                                           surf_lsm_v(3)%qrsws,                &
-                                           surf_usm_v(3)%qrsws, n_out )
-
-            CASE ( 'nrsws' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%nrsws,           &
-                                           surf_def_h(1)%nrsws,                &
-                                           surf_lsm_h%nrsws,                   &
-                                           surf_usm_h%nrsws,                   &
-                                           surf_def_v(0)%nrsws,                &
-                                           surf_lsm_v(0)%nrsws,                &
-                                           surf_usm_v(0)%nrsws,                &
-                                           surf_def_v(1)%nrsws,                &
-                                           surf_lsm_v(1)%nrsws,                &
-                                           surf_usm_v(1)%nrsws,                &
-                                           surf_def_v(2)%nrsws,                &
-                                           surf_lsm_v(2)%nrsws,                &
-                                           surf_usm_v(2)%nrsws,                &
-                                           surf_def_v(3)%nrsws,                &
-                                           surf_lsm_v(3)%nrsws,                &
-                                           surf_usm_v(3)%nrsws, n_out )
-
-            CASE ( 'sasws' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%sasws,           &
-                                           surf_def_h(1)%sasws,                &
-                                           surf_lsm_h%sasws,                   &
-                                           surf_usm_h%sasws,                   &
-                                           surf_def_v(0)%sasws,                &
-                                           surf_lsm_v(0)%sasws,                &
-                                           surf_usm_v(0)%sasws,                &
-                                           surf_def_v(1)%sasws,                &
-                                           surf_lsm_v(1)%sasws,                &
-                                           surf_usm_v(1)%sasws,                &
-                                           surf_def_v(2)%sasws,                &
-                                           surf_lsm_v(2)%sasws,                &
-                                           surf_usm_v(2)%sasws,                &
-                                           surf_def_v(3)%sasws,                &
-                                           surf_lsm_v(3)%sasws,                &
-                                           surf_usm_v(3)%sasws, n_out )
-
-            CASE ( 'q_surface' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%q_surface,       &
-                                           surf_def_h(1)%q_surface,            &
-                                           surf_lsm_h%q_surface,               &
-                                           surf_usm_h%q_surface,               &
-                                           surf_def_v(0)%q_surface,            &
-                                           surf_lsm_v(0)%q_surface,            &
-                                           surf_usm_v(0)%q_surface,            &
-                                           surf_def_v(1)%q_surface,            &
-                                           surf_lsm_v(1)%q_surface,            &
-                                           surf_usm_v(1)%q_surface,            &
-                                           surf_def_v(2)%q_surface,            &
-                                           surf_lsm_v(2)%q_surface,            &
-                                           surf_usm_v(2)%q_surface,            &
-                                           surf_def_v(3)%q_surface,            &
-                                           surf_lsm_v(3)%q_surface,            &
-                                           surf_usm_v(3)%q_surface, n_out )
-
-
-            CASE ( 'theta_surface' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%pt_surface,      &
-                                           surf_def_h(1)%pt_surface,           &
-                                           surf_lsm_h%pt_surface,              &
-                                           surf_usm_h%pt_surface,              &
-                                           surf_def_v(0)%pt_surface,           &
-                                           surf_lsm_v(0)%pt_surface,           &
-                                           surf_usm_v(0)%pt_surface,           &
-                                           surf_def_v(1)%pt_surface,           &
-                                           surf_lsm_v(1)%pt_surface,           &
-                                           surf_usm_v(1)%pt_surface,           &
-                                           surf_def_v(2)%pt_surface,           &
-                                           surf_lsm_v(2)%pt_surface,           &
-                                           surf_usm_v(2)%pt_surface,           &
-                                           surf_def_v(3)%pt_surface,           &
-                                           surf_lsm_v(3)%pt_surface,           &
-                                           surf_usm_v(3)%pt_surface, n_out )
-
-            CASE ( 'thetav_surface' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%vpt_surface,     &
-                                           surf_def_h(1)%vpt_surface,          &
-                                           surf_lsm_h%vpt_surface,             &
-                                           surf_usm_h%vpt_surface,             &
-                                           surf_def_v(0)%vpt_surface,          &
-                                           surf_lsm_v(0)%vpt_surface,          &
-                                           surf_usm_v(0)%vpt_surface,          &
-                                           surf_def_v(1)%vpt_surface,          &
-                                           surf_lsm_v(1)%vpt_surface,          &
-                                           surf_usm_v(1)%vpt_surface,          &
-                                           surf_def_v(2)%vpt_surface,          &
-                                           surf_lsm_v(2)%vpt_surface,          &
-                                           surf_usm_v(2)%vpt_surface,          &
-                                           surf_def_v(3)%vpt_surface,          &
-                                           surf_lsm_v(3)%vpt_surface,          &
-                                           surf_usm_v(3)%vpt_surface, n_out )
-
-            CASE ( 'rad_net' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_net,         &
-                                           surf_def_h(1)%rad_net,              &
-                                           surf_lsm_h%rad_net,                 &
-                                           surf_usm_h%rad_net,                 &
-                                           surf_def_v(0)%rad_net,              &
-                                           surf_lsm_v(0)%rad_net,              &
-                                           surf_usm_v(0)%rad_net,              &
-                                           surf_def_v(1)%rad_net,              &
-                                           surf_lsm_v(1)%rad_net,              &
-                                           surf_usm_v(1)%rad_net,              &
-                                           surf_def_v(2)%rad_net,              &
-                                           surf_lsm_v(2)%rad_net,              &
-                                           surf_usm_v(2)%rad_net,              &
-                                           surf_def_v(3)%rad_net,              &
-                                           surf_lsm_v(3)%rad_net,              &
-                                           surf_usm_v(3)%rad_net, n_out )
-
-            CASE ( 'rad_lw_in' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_lw_in,       &
-                                           surf_def_h(1)%rad_lw_in,            &
-                                           surf_lsm_h%rad_lw_in,               &
-                                           surf_usm_h%rad_lw_in,               &
-                                           surf_def_v(0)%rad_lw_in,            &
-                                           surf_lsm_v(0)%rad_lw_in,            &
-                                           surf_usm_v(0)%rad_lw_in,            &
-                                           surf_def_v(1)%rad_lw_in,            &
-                                           surf_lsm_v(1)%rad_lw_in,            &
-                                           surf_usm_v(1)%rad_lw_in,            &
-                                           surf_def_v(2)%rad_lw_in,            &
-                                           surf_lsm_v(2)%rad_lw_in,            &
-                                           surf_usm_v(2)%rad_lw_in,            &
-                                           surf_def_v(3)%rad_lw_in,            &
-                                           surf_lsm_v(3)%rad_lw_in,            &
-                                           surf_usm_v(3)%rad_lw_in, n_out )
-
-            CASE ( 'rad_lw_out' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_lw_out,      &
-                                           surf_def_h(1)%rad_lw_out,           &
-                                           surf_lsm_h%rad_lw_out,              &
-                                           surf_usm_h%rad_lw_out,              &
-                                           surf_def_v(0)%rad_lw_out,           &
-                                           surf_lsm_v(0)%rad_lw_out,           &
-                                           surf_usm_v(0)%rad_lw_out,           &
-                                           surf_def_v(1)%rad_lw_out,           &
-                                           surf_lsm_v(1)%rad_lw_out,           &
-                                           surf_usm_v(1)%rad_lw_out,           &
-                                           surf_def_v(2)%rad_lw_out,           &
-                                           surf_lsm_v(2)%rad_lw_out,           &
-                                           surf_usm_v(2)%rad_lw_out,           &
-                                           surf_def_v(3)%rad_lw_out,           &
-                                           surf_lsm_v(3)%rad_lw_out,           &
-                                           surf_usm_v(3)%rad_lw_out, n_out )
-
-            CASE ( 'rad_sw_in' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_in,       &
-                                           surf_def_h(1)%rad_sw_in,            &
-                                           surf_lsm_h%rad_sw_in,               &
-                                           surf_usm_h%rad_sw_in,               &
-                                           surf_def_v(0)%rad_sw_in,            &
-                                           surf_lsm_v(0)%rad_sw_in,            &
-                                           surf_usm_v(0)%rad_sw_in,            &
-                                           surf_def_v(1)%rad_sw_in,            &
-                                           surf_lsm_v(1)%rad_sw_in,            &
-                                           surf_usm_v(1)%rad_sw_in,            &
-                                           surf_def_v(2)%rad_sw_in,            &
-                                           surf_lsm_v(2)%rad_sw_in,            &
-                                           surf_usm_v(2)%rad_sw_in,            &
-                                           surf_def_v(3)%rad_sw_in,            &
-                                           surf_lsm_v(3)%rad_sw_in,            &
-                                           surf_usm_v(3)%rad_sw_in, n_out )
-
-            CASE ( 'rad_sw_out' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_out,      &
-                                           surf_def_h(1)%rad_sw_out,           &
-                                           surf_lsm_h%rad_sw_out,              &
-                                           surf_usm_h%rad_sw_out,              &
-                                           surf_def_v(0)%rad_sw_out,           &
-                                           surf_lsm_v(0)%rad_sw_out,           &
-                                           surf_usm_v(0)%rad_sw_out,           &
-                                           surf_def_v(1)%rad_sw_out,           &
-                                           surf_lsm_v(1)%rad_sw_out,           &
-                                           surf_usm_v(1)%rad_sw_out,           &
-                                           surf_def_v(2)%rad_sw_out,           &
-                                           surf_lsm_v(2)%rad_sw_out,           &
-                                           surf_usm_v(2)%rad_sw_out,           &
-                                           surf_def_v(3)%rad_sw_out,           &
-                                           surf_lsm_v(3)%rad_sw_out,           &
-                                           surf_usm_v(3)%rad_sw_out, n_out )
-
-            CASE ( 'ghf' )
-!
-!--            Sum up ground / wall heat flux. Note, for urban surfaces the 
-!--            wall heat flux is aggregated from the different green, window
-!--            and wall tiles.
-               DO  m = 1, surf_usm_h%ns
-                  surf_usm_h%ghf(m) = surf_usm_h%frac(m,ind_veg_wall)          &
-                                    * surf_usm_h%wghf_eb(m) +                  &
-                                      surf_usm_h%frac(m,ind_pav_green)         &
-                                    * surf_usm_h%wghf_eb_green(m) +            &
-                                      surf_usm_h%frac(m,ind_wat_win)           &
-                                    * surf_usm_h%wghf_eb_window(m)
-               ENDDO
-               DO  l = 0, 3
-                  DO  m = 1, surf_usm_v(l)%ns
-                     surf_usm_v(l)%ghf(m) = surf_usm_v(l)%frac(m,ind_veg_wall) &
-                                          * surf_usm_v(l)%wghf_eb(m) +         &
-                                            surf_usm_v(l)%frac(m,ind_pav_green)&
-                                          * surf_usm_v(l)%wghf_eb_green(m) +   &
-                                            surf_usm_v(l)%frac(m,ind_wat_win)  &
-                                          * surf_usm_v(l)%wghf_eb_window(m)
-                  ENDDO
-               ENDDO
-
-               CALL surface_data_output_sum_up( surf_def_h(0)%ghf,             &
-                                           surf_def_h(1)%ghf,                  &
-                                           surf_lsm_h%ghf,                     &
-                                           surf_usm_h%ghf,                     &
-                                           surf_def_v(0)%ghf,                  &
-                                           surf_lsm_v(0)%ghf,                  &
-                                           surf_usm_v(0)%ghf,                  &
-                                           surf_def_v(1)%ghf,                  &
-                                           surf_lsm_v(1)%ghf,                  &
-                                           surf_usm_v(1)%ghf,                  &
-                                           surf_def_v(2)%ghf,                  &
-                                           surf_lsm_v(2)%ghf,                  &
-                                           surf_usm_v(2)%ghf,                  &
-                                           surf_def_v(3)%ghf,                  &
-                                           surf_lsm_v(3)%ghf,                  &
-                                           surf_usm_v(3)%ghf, n_out )
-
-            CASE ( 'r_a' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%r_a,             &
-                                           surf_def_h(1)%r_a,                  &
-                                           surf_lsm_h%r_a,                     &
-                                           surf_usm_h%r_a,                     &
-                                           surf_def_v(0)%r_a,                  &
-                                           surf_lsm_v(0)%r_a,                  &
-                                           surf_usm_v(0)%r_a,                  &
-                                           surf_def_v(1)%r_a,                  &
-                                           surf_lsm_v(1)%r_a,                  &
-                                           surf_usm_v(1)%r_a,                  &
-                                           surf_def_v(2)%r_a,                  &
-                                           surf_lsm_v(2)%r_a,                  &
-                                           surf_usm_v(2)%r_a,                  &
-                                           surf_def_v(3)%r_a,                  &
-                                           surf_lsm_v(3)%r_a,                  &
-                                           surf_usm_v(3)%r_a, n_out )
-
-            CASE ( 'r_soil' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%r_soil,          &
-                                           surf_def_h(1)%r_soil,               &
-                                           surf_lsm_h%r_soil,                  &
-                                           surf_usm_h%r_soil,                  &
-                                           surf_def_v(0)%r_soil,               &
-                                           surf_lsm_v(0)%r_soil,               &
-                                           surf_usm_v(0)%r_soil,               &
-                                           surf_def_v(1)%r_soil,               &
-                                           surf_lsm_v(1)%r_soil,               &
-                                           surf_usm_v(1)%r_soil,               &
-                                           surf_def_v(2)%r_soil,               &
-                                           surf_lsm_v(2)%r_soil,               &
-                                           surf_usm_v(2)%r_soil,               &
-                                           surf_def_v(3)%r_soil,               &
-                                           surf_lsm_v(3)%r_soil,               &
-                                           surf_usm_v(3)%r_soil, n_out )
-
-            CASE ( 'r_canopy' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%r_canopy,        &
-                                           surf_def_h(1)%r_canopy,             &
-                                           surf_lsm_h%r_canopy,                &
-                                           surf_usm_h%r_canopy,                &
-                                           surf_def_v(0)%r_canopy,             &
-                                           surf_lsm_v(0)%r_canopy,             &
-                                           surf_usm_v(0)%r_canopy,             &
-                                           surf_def_v(1)%r_canopy,             &
-                                           surf_lsm_v(1)%r_canopy,             &
-                                           surf_usm_v(1)%r_canopy,             &
-                                           surf_def_v(2)%r_canopy,             &
-                                           surf_lsm_v(2)%r_canopy,             &
-                                           surf_usm_v(2)%r_canopy,             &
-                                           surf_def_v(3)%r_canopy,             &
-                                           surf_lsm_v(3)%r_canopy,             &
-                                           surf_usm_v(3)%r_canopy, n_out )
-
-            CASE ( 'r_s' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%r_s,             &
-                                           surf_def_h(1)%r_s,                  &
-                                           surf_lsm_h%r_s,                     &
-                                           surf_usm_h%r_s,                     &
-                                           surf_def_v(0)%r_s,                  &
-                                           surf_lsm_v(0)%r_s,                  &
-                                           surf_usm_v(0)%r_s,                  &
-                                           surf_def_v(1)%r_s,                  &
-                                           surf_lsm_v(1)%r_s,                  &
-                                           surf_usm_v(1)%r_s,                  &
-                                           surf_def_v(2)%r_s,                  &
-                                           surf_lsm_v(2)%r_s,                  &
-                                           surf_usm_v(2)%r_s,                  &
-                                           surf_def_v(3)%r_s,                  &
-                                           surf_lsm_v(3)%r_s,                  &
-                                           surf_usm_v(3)%r_s, n_out )
-
-
-            CASE ( 'rad_sw_dir' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_dir,      &
-                                           surf_def_h(1)%rad_sw_dir,           &
-                                           surf_lsm_h%rad_sw_dir,              &
-                                           surf_usm_h%rad_sw_dir,              &
-                                           surf_def_v(0)%rad_sw_dir,           &
-                                           surf_lsm_v(0)%rad_sw_dir,           &
-                                           surf_usm_v(0)%rad_sw_dir,           &
-                                           surf_def_v(1)%rad_sw_dir,           &
-                                           surf_lsm_v(1)%rad_sw_dir,           &
-                                           surf_usm_v(1)%rad_sw_dir,           &
-                                           surf_def_v(2)%rad_sw_dir,           &
-                                           surf_lsm_v(2)%rad_sw_dir,           &
-                                           surf_usm_v(2)%rad_sw_dir,           &
-                                           surf_def_v(3)%rad_sw_dir,           &
-                                           surf_lsm_v(3)%rad_sw_dir,           &
-                                           surf_usm_v(3)%rad_sw_dir, n_out )
-            CASE ( 'rad_sw_dif' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_dif,      &
-                                           surf_def_h(1)%rad_sw_dif,           &
-                                           surf_lsm_h%rad_sw_dif,              &
-                                           surf_usm_h%rad_sw_dif,              &
-                                           surf_def_v(0)%rad_sw_dif,           &
-                                           surf_lsm_v(0)%rad_sw_dif,           &
-                                           surf_usm_v(0)%rad_sw_dif,           &
-                                           surf_def_v(1)%rad_sw_dif,           &
-                                           surf_lsm_v(1)%rad_sw_dif,           &
-                                           surf_usm_v(1)%rad_sw_dif,           &
-                                           surf_def_v(2)%rad_sw_dif,           &
-                                           surf_lsm_v(2)%rad_sw_dif,           &
-                                           surf_usm_v(2)%rad_sw_dif,           &
-                                           surf_def_v(3)%rad_sw_dif,           &
-                                           surf_lsm_v(3)%rad_sw_dif,           &
-                                           surf_usm_v(3)%rad_sw_dif, n_out )
-
-            CASE ( 'rad_sw_ref' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_ref,      &
-                                           surf_def_h(1)%rad_sw_ref,           &
-                                           surf_lsm_h%rad_sw_ref,              &
-                                           surf_usm_h%rad_sw_ref,              &
-                                           surf_def_v(0)%rad_sw_ref,           &
-                                           surf_lsm_v(0)%rad_sw_ref,           &
-                                           surf_usm_v(0)%rad_sw_ref,           &
-                                           surf_def_v(1)%rad_sw_ref,           &
-                                           surf_lsm_v(1)%rad_sw_ref,           &
-                                           surf_usm_v(1)%rad_sw_ref,           &
-                                           surf_def_v(2)%rad_sw_ref,           &
-                                           surf_lsm_v(2)%rad_sw_ref,           &
-                                           surf_usm_v(2)%rad_sw_ref,           &
-                                           surf_def_v(3)%rad_sw_ref,           &
-                                           surf_lsm_v(3)%rad_sw_ref,           &
-                                           surf_usm_v(3)%rad_sw_ref, n_out )
-
-            CASE ( 'rad_sw_res' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_res,      &
-                                           surf_def_h(1)%rad_sw_res,           &
-                                           surf_lsm_h%rad_sw_res,              &
-                                           surf_usm_h%rad_sw_res,              &
-                                           surf_def_v(0)%rad_sw_res,           &
-                                           surf_lsm_v(0)%rad_sw_res,           &
-                                           surf_usm_v(0)%rad_sw_res,           &
-                                           surf_def_v(1)%rad_sw_res,           &
-                                           surf_lsm_v(1)%rad_sw_res,           &
-                                           surf_usm_v(1)%rad_sw_res,           &
-                                           surf_def_v(2)%rad_sw_res,           &
-                                           surf_lsm_v(2)%rad_sw_res,           &
-                                           surf_usm_v(2)%rad_sw_res,           &
-                                           surf_def_v(3)%rad_sw_res,           &
-                                           surf_lsm_v(3)%rad_sw_res,           &
-                                           surf_usm_v(3)%rad_sw_res, n_out )
-
-            CASE ( 'rad_lw_dif' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_lw_dif,      &
-                                           surf_def_h(1)%rad_lw_dif,           &
-                                           surf_lsm_h%rad_lw_dif,              &
-                                           surf_usm_h%rad_lw_dif,              &
-                                           surf_def_v(0)%rad_lw_dif,           &
-                                           surf_lsm_v(0)%rad_lw_dif,           &
-                                           surf_usm_v(0)%rad_lw_dif,           &
-                                           surf_def_v(1)%rad_lw_dif,           &
-                                           surf_lsm_v(1)%rad_lw_dif,           &
-                                           surf_usm_v(1)%rad_lw_dif,           &
-                                           surf_def_v(2)%rad_lw_dif,           &
-                                           surf_lsm_v(2)%rad_lw_dif,           &
-                                           surf_usm_v(2)%rad_lw_dif,           &
-                                           surf_def_v(3)%rad_lw_dif,           &
-                                           surf_lsm_v(3)%rad_lw_dif,           &
-                                           surf_usm_v(3)%rad_lw_dif, n_out )
-
-            CASE ( 'rad_lw_ref' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_lw_ref,      &
-                                           surf_def_h(1)%rad_lw_ref,           &
-                                           surf_lsm_h%rad_lw_ref,              &
-                                           surf_usm_h%rad_lw_ref,              &
-                                           surf_def_v(0)%rad_lw_ref,           &
-                                           surf_lsm_v(0)%rad_lw_ref,           &
-                                           surf_usm_v(0)%rad_lw_ref,           &
-                                           surf_def_v(1)%rad_lw_ref,           &
-                                           surf_lsm_v(1)%rad_lw_ref,           &
-                                           surf_usm_v(1)%rad_lw_ref,           &
-                                           surf_def_v(2)%rad_lw_ref,           &
-                                           surf_lsm_v(2)%rad_lw_ref,           &
-                                           surf_usm_v(2)%rad_lw_ref,           &
-                                           surf_def_v(3)%rad_lw_ref,           &
-                                           surf_lsm_v(3)%rad_lw_ref,           &
-                                           surf_usm_v(3)%rad_lw_ref, n_out )
-
-            CASE ( 'rad_lw_res' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%rad_lw_res,      &
-                                           surf_def_h(1)%rad_lw_res,           &
-                                           surf_lsm_h%rad_lw_res,              &
-                                           surf_usm_h%rad_lw_res,              &
-                                           surf_def_v(0)%rad_lw_res,           &
-                                           surf_lsm_v(0)%rad_lw_res,           &
-                                           surf_usm_v(0)%rad_lw_res,           &
-                                           surf_def_v(1)%rad_lw_res,           &
-                                           surf_lsm_v(1)%rad_lw_res,           &
-                                           surf_usm_v(1)%rad_lw_res,           &
-                                           surf_def_v(2)%rad_lw_res,           &
-                                           surf_lsm_v(2)%rad_lw_res,           &
-                                           surf_usm_v(2)%rad_lw_res,           &
-                                           surf_def_v(3)%rad_lw_res,           &
-                                           surf_lsm_v(3)%rad_lw_res,           &
-                                           surf_usm_v(3)%rad_lw_res, n_out )
-
-            CASE ( 'uvw1' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%uvw_abs,         &
-                                           surf_def_h(1)%uvw_abs,              &
-                                           surf_lsm_h%uvw_abs,                 &
-                                           surf_usm_h%uvw_abs,                 &
-                                           surf_def_v(0)%uvw_abs,              &
-                                           surf_lsm_v(0)%uvw_abs,              &
-                                           surf_usm_v(0)%uvw_abs,              &
-                                           surf_def_v(1)%uvw_abs,              &
-                                           surf_lsm_v(1)%uvw_abs,              &
-                                           surf_usm_v(1)%uvw_abs,              &
-                                           surf_def_v(2)%uvw_abs,              &
-                                           surf_lsm_v(2)%uvw_abs,              &
-                                           surf_usm_v(2)%uvw_abs,              &
-                                           surf_def_v(3)%uvw_abs,              &
-                                           surf_lsm_v(3)%uvw_abs,              &
-                                           surf_usm_v(3)%uvw_abs, n_out )
-
-            CASE ( 'waste_heat' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%waste_heat,      &
-                                           surf_def_h(1)%waste_heat,           &
-                                           surf_lsm_h%waste_heat,              &
-                                           surf_usm_h%waste_heat,              &
-                                           surf_def_v(0)%waste_heat,           &
-                                           surf_lsm_v(0)%waste_heat,           &
-                                           surf_usm_v(0)%waste_heat,           &
-                                           surf_def_v(1)%waste_heat,           &
-                                           surf_lsm_v(1)%waste_heat,           &
-                                           surf_usm_v(1)%waste_heat,           &
-                                           surf_def_v(2)%waste_heat,           &
-                                           surf_lsm_v(2)%waste_heat,           &
-                                           surf_usm_v(2)%waste_heat,           &
-                                           surf_def_v(3)%waste_heat,           &
-                                           surf_lsm_v(3)%waste_heat,           &
-                                           surf_usm_v(3)%waste_heat, n_out )
-
-            CASE ( 'im_hf' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%iwghf_eb,        &
-                                           surf_def_h(1)%iwghf_eb,             &
-                                           surf_lsm_h%iwghf_eb,                &
-                                           surf_usm_h%iwghf_eb,                &
-                                           surf_def_v(0)%iwghf_eb,             &
-                                           surf_lsm_v(0)%iwghf_eb,             &
-                                           surf_usm_v(0)%iwghf_eb,             &
-                                           surf_def_v(1)%iwghf_eb,             &
-                                           surf_lsm_v(1)%iwghf_eb,             &
-                                           surf_usm_v(1)%iwghf_eb,             &
-                                           surf_def_v(2)%iwghf_eb,             &
-                                           surf_lsm_v(2)%iwghf_eb,             &
-                                           surf_usm_v(2)%iwghf_eb,             &
-                                           surf_def_v(3)%iwghf_eb,             &
-                                           surf_lsm_v(3)%iwghf_eb,             &
-                                           surf_usm_v(3)%iwghf_eb, n_out )
-
-            CASE ( 'albedo' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%albedo,          &
-                                           surf_def_h(1)%albedo,               &
-                                           surf_lsm_h%albedo,                  &
-                                           surf_usm_h%albedo,                  &
-                                           surf_def_v(0)%albedo,               &
-                                           surf_lsm_v(0)%albedo,               &
-                                           surf_usm_v(0)%albedo,               &
-                                           surf_def_v(1)%albedo,               &
-                                           surf_lsm_v(1)%albedo,               &
-                                           surf_usm_v(1)%albedo,               &
-                                           surf_def_v(2)%albedo,               &
-                                           surf_lsm_v(2)%albedo,               &
-                                           surf_usm_v(2)%albedo,               &
-                                           surf_def_v(3)%albedo,               &
-                                           surf_lsm_v(3)%albedo,               &
-                                           surf_usm_v(3)%albedo, n_out )
-
-
-            CASE ( 'emissivity' )
-               CALL surface_data_output_sum_up( surf_def_h(0)%emissivity,      &
-                                           surf_def_h(1)%emissivity,           &
-                                           surf_lsm_h%emissivity,              &
-                                           surf_usm_h%emissivity,              &
-                                           surf_def_v(0)%emissivity,           &
-                                           surf_lsm_v(0)%emissivity,           &
-                                           surf_usm_v(0)%emissivity,           &
-                                           surf_def_v(1)%emissivity,           &
-                                           surf_lsm_v(1)%emissivity,           &
-                                           surf_usm_v(1)%emissivity,           &
-                                           surf_def_v(2)%emissivity,           &
-                                           surf_lsm_v(2)%emissivity,           &
-                                           surf_usm_v(2)%emissivity,           &
-                                           surf_def_v(3)%emissivity,           &
-                                           surf_lsm_v(3)%emissivity,           &
-                                           surf_usm_v(3)%emissivity, n_out )
-
-         END SELECT
-      ENDDO
-
-
-   END SUBROUTINE surface_data_output_averaging
-
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_averaging
+
+    IMPLICIT NONE
+
+    CHARACTER(LEN=100) ::  trimvar  !< dummy variable for current output variable
+
+    INTEGER(iwp) ::  l      !< running index for surface orientation
+    INTEGER(iwp) ::  m      !< running index for surface elements
+    INTEGER(iwp) ::  n_out  !< counter variables for surface output
+
+    n_out = 0
+    DO  WHILE ( dosurf(1,n_out+1)(1:1) /= ' ' )
+
+       n_out   = n_out + 1
+       trimvar = TRIM( dosurf(1,n_out) )
+
+       SELECT CASE ( trimvar )
+
+          CASE ( 'us' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%us, surf_def_h(1)%us, surf_lsm_h%us,   &
+                                              surf_usm_h%us, surf_def_v(0)%us, surf_lsm_v(0)%us,   &
+                                              surf_usm_v(0)%us, surf_def_v(1)%us,                  &
+                                              surf_lsm_v(1)%us, surf_usm_v(1)%us,                  &
+                                              surf_def_v(2)%us, surf_lsm_v(2)%us,                  &
+                                              surf_usm_v(2)%us, surf_def_v(3)%us,                  &
+                                              surf_lsm_v(3)%us, surf_usm_v(3)%us, n_out )
+
+          CASE ( 'ts' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%ts, surf_def_h(1)%ts, surf_lsm_h%ts,   &
+                                              surf_usm_h%ts, surf_def_v(0)%ts, surf_lsm_v(0)%ts,   &
+                                              surf_usm_v(0)%ts, surf_def_v(1)%ts,                  &
+                                              surf_lsm_v(1)%ts, surf_usm_v(1)%ts,                  &
+                                              surf_def_v(2)%ts, surf_lsm_v(2)%ts,                  &
+                                              surf_usm_v(2)%ts, surf_def_v(3)%ts,                  &
+                                              surf_lsm_v(3)%ts, surf_usm_v(3)%ts, n_out )
+
+          CASE ( 'qs' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%qs, surf_def_h(1)%qs, surf_lsm_h%qs,   &
+                                              surf_usm_h%qs, surf_def_v(0)%qs, surf_lsm_v(0)%qs,   &
+                                              surf_usm_v(0)%qs, surf_def_v(1)%qs,                  &
+                                              surf_lsm_v(1)%qs, surf_usm_v(1)%qs,                  &
+                                              surf_def_v(2)%qs, surf_lsm_v(2)%qs,                  &
+                                              surf_usm_v(2)%qs, surf_def_v(3)%qs,                  &
+                                              surf_lsm_v(3)%qs, surf_usm_v(3)%qs, n_out )
+
+          CASE ( 'ss' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%ss, surf_def_h(1)%ss, surf_lsm_h%ss,   &
+                                              surf_usm_h%ss, surf_def_v(0)%ss, surf_lsm_v(0)%ss,   &
+                                              surf_usm_v(0)%ss, surf_def_v(1)%ss,                  &
+                                              surf_lsm_v(1)%ss, surf_usm_v(1)%ss,                  &
+                                              surf_def_v(2)%ss, surf_lsm_v(2)%ss,                  &
+                                              surf_usm_v(2)%ss, surf_def_v(3)%ss,                  &
+                                              surf_lsm_v(3)%ss, surf_usm_v(3)%ss, n_out )
+
+          CASE ( 'qcs' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%qcs, surf_def_h(1)%qcs,                &
+                                              surf_lsm_h%qcs, surf_usm_h%qcs, surf_def_v(0)%qcs,   &
+                                              surf_lsm_v(0)%qcs, surf_usm_v(0)%qcs,                &
+                                              surf_def_v(1)%qcs, surf_lsm_v(1)%qcs,                &
+                                              surf_usm_v(1)%qcs, surf_def_v(2)%qcs,                &
+                                              surf_lsm_v(2)%qcs, surf_usm_v(2)%qcs,                &
+                                              surf_def_v(3)%qcs, surf_lsm_v(3)%qcs,                &
+                                              surf_usm_v(3)%qcs, n_out )
+
+          CASE ( 'ncs' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%ncs, surf_def_h(1)%ncs, surf_lsm_h%ncs,&
+                                              surf_usm_h%ncs, surf_def_v(0)%ncs,                   &
+                                              surf_lsm_v(0)%ncs, surf_usm_v(0)%ncs,                &
+                                              surf_def_v(1)%ncs, surf_lsm_v(1)%ncs,                &
+                                              surf_usm_v(1)%ncs, surf_def_v(2)%ncs,                &
+                                              surf_lsm_v(2)%ncs, surf_usm_v(2)%ncs,                &
+                                              surf_def_v(3)%ncs, surf_lsm_v(3)%ncs,                &
+                                              surf_usm_v(3)%ncs, n_out )
+
+          CASE ( 'qis' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%qis, surf_def_h(1)%qis,                &
+                                              surf_lsm_h%qis, surf_usm_h%qis, surf_def_v(0)%qis,   &
+                                              surf_lsm_v(0)%qis, surf_usm_v(0)%qis,                &
+                                              surf_def_v(1)%qis, surf_lsm_v(1)%qis,                &
+                                              surf_usm_v(1)%qis, surf_def_v(2)%qis,                &
+                                              surf_lsm_v(2)%qis, surf_usm_v(2)%qis,                &
+                                              surf_def_v(3)%qis, surf_lsm_v(3)%qis,                &
+                                              surf_usm_v(3)%qrs, n_out )
+
+          CASE ( 'nis' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%nis, surf_def_h(1)%nis,                &
+                                              surf_lsm_h%nis, surf_usm_h%nis, surf_def_v(0)%nis,   &
+                                              surf_lsm_v(0)%nis, surf_usm_v(0)%nis,                &
+                                              surf_def_v(1)%nis, surf_lsm_v(1)%nis,                &
+                                              surf_usm_v(1)%nis, surf_def_v(2)%nis,                &
+                                              surf_lsm_v(2)%nis, surf_usm_v(2)%nis,                &
+                                              surf_def_v(3)%nis, surf_lsm_v(3)%nis,                &
+                                              surf_usm_v(3)%nis, n_out )
+
+          CASE ( 'qrs' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%qrs, surf_def_h(1)%qrs,                &
+                                              surf_lsm_h%qrs, surf_usm_h%qrs, surf_def_v(0)%qrs,   &
+                                              surf_lsm_v(0)%qrs, surf_usm_v(0)%qrs,                &
+                                              surf_def_v(1)%qrs, surf_lsm_v(1)%qrs,                &
+                                              surf_usm_v(1)%qrs, surf_def_v(2)%qrs,                &
+                                              surf_lsm_v(2)%qrs, surf_usm_v(2)%qrs,                &
+                                              surf_def_v(3)%qrs, surf_lsm_v(3)%qrs,                &
+                                              surf_usm_v(3)%qrs, n_out )
+
+          CASE ( 'nrs' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%nrs, surf_def_h(1)%nrs,                &
+                                              surf_lsm_h%nrs, surf_usm_h%nrs, surf_def_v(0)%nrs,   &
+                                              surf_lsm_v(0)%nrs, surf_usm_v(0)%nrs,                &
+                                              surf_def_v(1)%nrs, surf_lsm_v(1)%nrs,                &
+                                              surf_usm_v(1)%nrs, surf_def_v(2)%nrs,                &
+                                              surf_lsm_v(2)%nrs, surf_usm_v(2)%nrs,                &
+                                              surf_def_v(3)%nrs, surf_lsm_v(3)%nrs,                &
+                                              surf_usm_v(3)%nrs, n_out )
+
+          CASE ( 'ol' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%ol, surf_def_h(1)%ol, surf_lsm_h%ol,   &
+                                              surf_usm_h%ol, surf_def_v(0)%ol, surf_lsm_v(0)%ol,   &
+                                              surf_usm_v(0)%ol, surf_def_v(1)%ol,                  &
+                                              surf_lsm_v(1)%ol, surf_usm_v(1)%ol,                  &
+                                              surf_def_v(2)%ol, surf_lsm_v(2)%ol,                  &
+                                              surf_usm_v(2)%ol, surf_def_v(3)%ol,                  &
+                                              surf_lsm_v(3)%ol, surf_usm_v(3)%ol, n_out )
+
+          CASE ( 'z0' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%z0, surf_def_h(1)%z0, surf_lsm_h%z0,   &
+                                              surf_usm_h%z0, surf_def_v(0)%z0, surf_lsm_v(0)%z0,   &
+                                              surf_usm_v(0)%z0, surf_def_v(1)%z0,                  &
+                                              surf_lsm_v(1)%z0, surf_usm_v(1)%z0,                  &
+                                              surf_def_v(2)%z0, surf_lsm_v(2)%z0,                  &
+                                              surf_usm_v(2)%z0, surf_def_v(3)%z0,                  &
+                                              surf_lsm_v(3)%z0, surf_usm_v(3)%z0, n_out )
+
+          CASE ( 'z0h' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%z0h, surf_def_h(1)%z0h,                &
+                                              surf_lsm_h%z0h, surf_usm_h%z0h, surf_def_v(0)%z0h,   &
+                                              surf_lsm_v(0)%z0h, surf_usm_v(0)%z0h,                &
+                                              surf_def_v(1)%z0h, surf_lsm_v(1)%z0h,                &
+                                              surf_usm_v(1)%z0h, surf_def_v(2)%z0h,                &
+                                              surf_lsm_v(2)%z0h, surf_usm_v(2)%z0h,                &
+                                              surf_def_v(3)%z0h, surf_lsm_v(3)%z0h,                &
+                                              surf_usm_v(3)%z0h, n_out )
+
+          CASE ( 'z0q' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%z0q, surf_def_h(1)%z0q,                &
+                                              surf_lsm_h%z0q, surf_usm_h%z0q, surf_def_v(0)%z0q,   &
+                                              surf_lsm_v(0)%z0q, surf_usm_v(0)%z0q,                &
+                                              surf_def_v(1)%z0q, surf_lsm_v(1)%z0q,                &
+                                              surf_usm_v(1)%z0q, surf_def_v(2)%z0q,                &
+                                              surf_lsm_v(2)%z0q, surf_usm_v(2)%z0q,                &
+                                              surf_def_v(3)%z0q, surf_lsm_v(3)%z0q,                &
+                                              surf_usm_v(3)%z0q, n_out )
+
+          CASE ( 'theta1' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%pt1, surf_def_h(1)%pt1,                &
+                                              surf_lsm_h%pt1, surf_usm_h%pt1, surf_def_v(0)%pt1,   &
+                                              surf_lsm_v(0)%pt1, surf_usm_v(0)%pt1,                &
+                                              surf_def_v(1)%pt1, surf_lsm_v(1)%pt1,                &
+                                              surf_usm_v(1)%pt1, surf_def_v(2)%pt1,                &
+                                              surf_lsm_v(2)%pt1, surf_usm_v(2)%pt1,                &
+                                              surf_def_v(3)%pt1, surf_lsm_v(3)%pt1,                &
+                                              surf_usm_v(3)%pt1, n_out )
+
+          CASE ( 'qv1' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%qv1, surf_def_h(1)%qv1,                &
+                                              surf_lsm_h%qv1, surf_usm_h%qv1, surf_def_v(0)%qv1,   &
+                                              surf_lsm_v(0)%qv1, surf_usm_v(0)%qv1,                &
+                                              surf_def_v(1)%qv1, surf_lsm_v(1)%qv1,                &
+                                              surf_usm_v(1)%qv1, surf_def_v(2)%qv1,                &
+                                              surf_lsm_v(2)%qv1, surf_usm_v(2)%qv1,                &
+                                              surf_def_v(3)%qv1, surf_lsm_v(3)%qv1,                &
+                                              surf_usm_v(3)%qv1, n_out )
+
+          CASE ( 'thetav1' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%vpt1, surf_def_h(1)%vpt1,              &
+                                              surf_lsm_h%vpt1, surf_usm_h%vpt1,                    &
+                                              surf_def_v(0)%vpt1, surf_lsm_v(0)%vpt1,              &
+                                              surf_usm_v(0)%vpt1, surf_def_v(1)%vpt1,              &
+                                              surf_lsm_v(1)%vpt1, surf_usm_v(1)%vpt1,              &
+                                              surf_def_v(2)%vpt1, surf_lsm_v(2)%vpt1,              &
+                                              surf_usm_v(2)%vpt1, surf_def_v(3)%vpt1,              &
+                                              surf_lsm_v(3)%vpt1, surf_usm_v(3)%vpt1, n_out )
+
+          CASE ( 'usws' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%usws, surf_def_h(1)%usws,              &
+                                              surf_lsm_h%usws, surf_usm_h%usws,                    &
+                                              surf_def_v(0)%usws, surf_lsm_v(0)%usws,              &
+                                              surf_usm_v(0)%usws, surf_def_v(1)%usws,              &
+                                              surf_lsm_v(1)%usws, surf_usm_v(1)%usws,              &
+                                              surf_def_v(2)%usws, surf_lsm_v(2)%usws,              &
+                                              surf_usm_v(2)%usws, surf_def_v(3)%usws,              &
+                                              surf_lsm_v(3)%usws, surf_usm_v(3)%usws, n_out,       &
+                                              momentumflux_output_conversion )
+
+          CASE ( 'vsws' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%vsws, surf_def_h(1)%vsws,              &
+                                              surf_lsm_h%vsws, surf_usm_h%vsws,                    &
+                                              surf_def_v(0)%vsws, surf_lsm_v(0)%vsws,              &
+                                              surf_usm_v(0)%vsws, surf_def_v(1)%vsws,              &
+                                              surf_lsm_v(1)%vsws, surf_usm_v(1)%vsws,              &
+                                              surf_def_v(2)%vsws, surf_lsm_v(2)%vsws,              &
+                                              surf_usm_v(2)%vsws, surf_def_v(3)%vsws,              &
+                                              surf_lsm_v(3)%vsws, surf_usm_v(3)%vsws, n_out,       &
+                                              momentumflux_output_conversion )
+
+          CASE ( 'shf' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%shf, surf_def_h(1)%shf,                &
+                                              surf_lsm_h%shf, surf_usm_h%shf, surf_def_v(0)%shf,   &
+                                              surf_lsm_v(0)%shf, surf_usm_v(0)%shf,                &
+                                              surf_def_v(1)%shf, surf_lsm_v(1)%shf,                &
+                                              surf_usm_v(1)%shf, surf_def_v(2)%shf,                &
+                                              surf_lsm_v(2)%shf, surf_usm_v(2)%shf,                &
+                                              surf_def_v(3)%shf, surf_lsm_v(3)%shf,                &
+                                              surf_usm_v(3)%shf, n_out, heatflux_output_conversion )
+
+          CASE ( 'qsws' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%qsws, surf_def_h(1)%qsws,              &
+                                              surf_lsm_h%qsws, surf_usm_h%qsws,                    &
+                                              surf_def_v(0)%qsws, surf_lsm_v(0)%qsws,              &
+                                              surf_usm_v(0)%qsws, surf_def_v(1)%qsws,              &
+                                              surf_lsm_v(1)%qsws, surf_usm_v(1)%qsws,              &
+                                              surf_def_v(2)%qsws, surf_lsm_v(2)%qsws,              &
+                                              surf_usm_v(2)%qsws, surf_def_v(3)%qsws,              &
+                                              surf_lsm_v(3)%qsws, surf_usm_v(3)%qsws, n_out,       &
+                                              waterflux_output_conversion )
+
+          CASE ( 'ssws' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%ssws, surf_def_h(1)%ssws,              &
+                                              surf_lsm_h%ssws, surf_usm_h%ssws,                    &
+                                              surf_def_v(0)%ssws, surf_lsm_v(0)%ssws,              &
+                                              surf_usm_v(0)%ssws, surf_def_v(1)%ssws,              &
+                                              surf_lsm_v(1)%ssws, surf_usm_v(1)%ssws,              &
+                                              surf_def_v(2)%ssws, surf_lsm_v(2)%ssws,              &
+                                              surf_usm_v(2)%ssws, surf_def_v(3)%ssws,              &
+                                              surf_lsm_v(3)%ssws, surf_usm_v(3)%ssws, n_out )
+
+          CASE ( 'qcsws' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%qcsws, surf_def_h(1)%qcsws,            &
+                                              surf_lsm_h%qcsws, surf_usm_h%qcsws,                  &
+                                              surf_def_v(0)%qcsws, surf_lsm_v(0)%qcsws,            &
+                                              surf_usm_v(0)%qcsws, surf_def_v(1)%qcsws,            &
+                                              surf_lsm_v(1)%qcsws, surf_usm_v(1)%qcsws,            &
+                                              surf_def_v(2)%qcsws, surf_lsm_v(2)%qcsws,            &
+                                              surf_usm_v(2)%qcsws, surf_def_v(3)%qcsws,            &
+                                              surf_lsm_v(3)%qcsws, surf_usm_v(3)%qcsws, n_out )
+
+          CASE ( 'ncsws' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%ncsws, surf_def_h(1)%ncsws,            &
+                                              surf_lsm_h%ncsws, surf_usm_h%ncsws,                  &
+                                              surf_def_v(0)%ncsws, surf_lsm_v(0)%ncsws,            &
+                                              surf_usm_v(0)%ncsws, surf_def_v(1)%ncsws,            &
+                                              surf_lsm_v(1)%ncsws, surf_usm_v(1)%ncsws,            &
+                                              surf_def_v(2)%ncsws, surf_lsm_v(2)%ncsws,            &
+                                              surf_usm_v(2)%ncsws, surf_def_v(3)%ncsws,            &
+                                              surf_lsm_v(3)%ncsws, surf_usm_v(3)%ncsws, n_out )
+
+          CASE ( 'qisws' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%qisws, surf_def_h(1)%qisws,            &
+                                              surf_lsm_h%qisws, surf_usm_h%qisws,                  &
+                                              surf_def_v(0)%qisws, surf_lsm_v(0)%qisws,            &
+                                              surf_usm_v(0)%qisws, surf_def_v(1)%qisws,            &
+                                              surf_lsm_v(1)%qisws, surf_usm_v(1)%qisws,            &
+                                              surf_def_v(2)%qisws, surf_lsm_v(2)%qisws,            &
+                                              surf_usm_v(2)%qisws, surf_def_v(3)%qisws,            &
+                                              surf_lsm_v(3)%qisws, surf_usm_v(3)%qisws, n_out )
+
+          CASE ( 'nisws' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%nisws, surf_def_h(1)%nisws,            &
+                                              surf_lsm_h%nisws, surf_usm_h%nisws,                  &
+                                              surf_def_v(0)%nisws, surf_lsm_v(0)%nisws,            &
+                                              surf_usm_v(0)%nisws, surf_def_v(1)%nisws,            &
+                                              surf_lsm_v(1)%nisws, surf_usm_v(1)%nisws,            &
+                                              surf_def_v(2)%nisws, surf_lsm_v(2)%nisws,            &
+                                              surf_usm_v(2)%nisws, surf_def_v(3)%nisws,            &
+                                              surf_lsm_v(3)%nisws, surf_usm_v(3)%nisws, n_out )
+
+          CASE ( 'qrsws' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%qrsws, surf_def_h(1)%qrsws,            &
+                                              surf_lsm_h%qrsws, surf_usm_h%qrsws,                  &
+                                              surf_def_v(0)%qrsws, surf_lsm_v(0)%qrsws,            &
+                                              surf_usm_v(0)%qrsws, surf_def_v(1)%qrsws,            &
+                                              surf_lsm_v(1)%qrsws, surf_usm_v(1)%qrsws,            &
+                                              surf_def_v(2)%qrsws, surf_lsm_v(2)%qrsws,            &
+                                              surf_usm_v(2)%qrsws, surf_def_v(3)%qrsws,            &
+                                              surf_lsm_v(3)%qrsws, surf_usm_v(3)%qrsws, n_out )
+
+          CASE ( 'nrsws' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%nrsws, surf_def_h(1)%nrsws,            &
+                                              surf_lsm_h%nrsws, surf_usm_h%nrsws,                  &
+                                              surf_def_v(0)%nrsws, surf_lsm_v(0)%nrsws,            &
+                                              surf_usm_v(0)%nrsws, surf_def_v(1)%nrsws,            &
+                                              surf_lsm_v(1)%nrsws, surf_usm_v(1)%nrsws,            &
+                                              surf_def_v(2)%nrsws, surf_lsm_v(2)%nrsws,            &
+                                              surf_usm_v(2)%nrsws, surf_def_v(3)%nrsws,            &
+                                              surf_lsm_v(3)%nrsws, surf_usm_v(3)%nrsws, n_out )
+
+          CASE ( 'sasws' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%sasws, surf_def_h(1)%sasws,            &
+                                              surf_lsm_h%sasws, surf_usm_h%sasws,                  &
+                                              surf_def_v(0)%sasws, surf_lsm_v(0)%sasws,            &
+                                              surf_usm_v(0)%sasws, surf_def_v(1)%sasws,            &
+                                              surf_lsm_v(1)%sasws, surf_usm_v(1)%sasws,            &
+                                              surf_def_v(2)%sasws, surf_lsm_v(2)%sasws,            &
+                                              surf_usm_v(2)%sasws, surf_def_v(3)%sasws,            &
+                                              surf_lsm_v(3)%sasws, surf_usm_v(3)%sasws, n_out )
+
+          CASE ( 'q_surface' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%q_surface, surf_def_h(1)%q_surface,    &
+                                              surf_lsm_h%q_surface, surf_usm_h%q_surface,          &
+                                              surf_def_v(0)%q_surface, surf_lsm_v(0)%q_surface,    &
+                                              surf_usm_v(0)%q_surface, surf_def_v(1)%q_surface,    &
+                                              surf_lsm_v(1)%q_surface, surf_usm_v(1)%q_surface,    &
+                                              surf_def_v(2)%q_surface, surf_lsm_v(2)%q_surface,    &
+                                              surf_usm_v(2)%q_surface, surf_def_v(3)%q_surface,    &
+                                              surf_lsm_v(3)%q_surface, surf_usm_v(3)%q_surface,    &
+                                              n_out )
+
+
+          CASE ( 'theta_surface' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%pt_surface, surf_def_h(1)%pt_surface,  &
+                                              surf_lsm_h%pt_surface, surf_usm_h%pt_surface,        &
+                                              surf_def_v(0)%pt_surface, surf_lsm_v(0)%pt_surface,  &
+                                              surf_usm_v(0)%pt_surface, surf_def_v(1)%pt_surface,  &
+                                              surf_lsm_v(1)%pt_surface, surf_usm_v(1)%pt_surface,  &
+                                              surf_def_v(2)%pt_surface, surf_lsm_v(2)%pt_surface,  &
+                                              surf_usm_v(2)%pt_surface, surf_def_v(3)%pt_surface,  &
+                                              surf_lsm_v(3)%pt_surface, surf_usm_v(3)%pt_surface,  &
+                                              n_out )
+
+          CASE ( 'thetav_surface' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%vpt_surface,                           &
+                                              surf_def_h(1)%vpt_surface, surf_lsm_h%vpt_surface,   &
+                                              surf_usm_h%vpt_surface, surf_def_v(0)%vpt_surface,   &
+                                              surf_lsm_v(0)%vpt_surface,                           &
+                                              surf_usm_v(0)%vpt_surface,                           &
+                                              surf_def_v(1)%vpt_surface,                           &
+                                              surf_lsm_v(1)%vpt_surface,                           &
+                                              surf_usm_v(1)%vpt_surface,                           &
+                                              surf_def_v(2)%vpt_surface,                           &
+                                              surf_lsm_v(2)%vpt_surface,                           &
+                                              surf_usm_v(2)%vpt_surface,                           &
+                                              surf_def_v(3)%vpt_surface,                           &
+                                              surf_lsm_v(3)%vpt_surface,                           &
+                                              surf_usm_v(3)%vpt_surface, n_out )
+
+          CASE ( 'rad_net' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_net, surf_def_h(1)%rad_net,        &
+                                              surf_lsm_h%rad_net, surf_usm_h%rad_net,              &
+                                              surf_def_v(0)%rad_net, surf_lsm_v(0)%rad_net,        &
+                                              surf_usm_v(0)%rad_net, surf_def_v(1)%rad_net,        &
+                                              surf_lsm_v(1)%rad_net, surf_usm_v(1)%rad_net,        &
+                                              surf_def_v(2)%rad_net, surf_lsm_v(2)%rad_net,        &
+                                              surf_usm_v(2)%rad_net, surf_def_v(3)%rad_net,        &
+                                              surf_lsm_v(3)%rad_net, surf_usm_v(3)%rad_net, n_out )
+
+          CASE ( 'rad_lw_in' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_lw_in, surf_def_h(1)%rad_lw_in,    &
+                                              surf_lsm_h%rad_lw_in, surf_usm_h%rad_lw_in,          &
+                                              surf_def_v(0)%rad_lw_in, surf_lsm_v(0)%rad_lw_in,    &
+                                              surf_usm_v(0)%rad_lw_in, surf_def_v(1)%rad_lw_in,    &
+                                              surf_lsm_v(1)%rad_lw_in, surf_usm_v(1)%rad_lw_in,    &
+                                              surf_def_v(2)%rad_lw_in, surf_lsm_v(2)%rad_lw_in,    &
+                                              surf_usm_v(2)%rad_lw_in, surf_def_v(3)%rad_lw_in,    &
+                                              surf_lsm_v(3)%rad_lw_in, surf_usm_v(3)%rad_lw_in,    &
+                                              n_out )
+
+          CASE ( 'rad_lw_out' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_lw_out, surf_def_h(1)%rad_lw_out,  &
+                                              surf_lsm_h%rad_lw_out, surf_usm_h%rad_lw_out,        &
+                                              surf_def_v(0)%rad_lw_out, surf_lsm_v(0)%rad_lw_out,  &
+                                              surf_usm_v(0)%rad_lw_out, surf_def_v(1)%rad_lw_out,  &
+                                              surf_lsm_v(1)%rad_lw_out, surf_usm_v(1)%rad_lw_out,  &
+                                              surf_def_v(2)%rad_lw_out, surf_lsm_v(2)%rad_lw_out,  &
+                                              surf_usm_v(2)%rad_lw_out, surf_def_v(3)%rad_lw_out,  &
+                                              surf_lsm_v(3)%rad_lw_out, surf_usm_v(3)%rad_lw_out,  &
+                                              n_out )
+
+          CASE ( 'rad_sw_in' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_in, surf_def_h(1)%rad_sw_in,    &
+                                              surf_lsm_h%rad_sw_in, surf_usm_h%rad_sw_in,          &
+                                              surf_def_v(0)%rad_sw_in, surf_lsm_v(0)%rad_sw_in,    &
+                                              surf_usm_v(0)%rad_sw_in, surf_def_v(1)%rad_sw_in,    &
+                                              surf_lsm_v(1)%rad_sw_in, surf_usm_v(1)%rad_sw_in,    &
+                                              surf_def_v(2)%rad_sw_in, surf_lsm_v(2)%rad_sw_in,    &
+                                              surf_usm_v(2)%rad_sw_in, surf_def_v(3)%rad_sw_in,    &
+                                              surf_lsm_v(3)%rad_sw_in, surf_usm_v(3)%rad_sw_in,    &
+                                              n_out )
+
+          CASE ( 'rad_sw_out' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_out, surf_def_h(1)%rad_sw_out,  &
+                                              surf_lsm_h%rad_sw_out, surf_usm_h%rad_sw_out,        &
+                                              surf_def_v(0)%rad_sw_out, surf_lsm_v(0)%rad_sw_out,  &
+                                              surf_usm_v(0)%rad_sw_out, surf_def_v(1)%rad_sw_out,  &
+                                              surf_lsm_v(1)%rad_sw_out, surf_usm_v(1)%rad_sw_out,  &
+                                              surf_def_v(2)%rad_sw_out, surf_lsm_v(2)%rad_sw_out,  &
+                                              surf_usm_v(2)%rad_sw_out, surf_def_v(3)%rad_sw_out,  &
+                                              surf_lsm_v(3)%rad_sw_out, surf_usm_v(3)%rad_sw_out,  &
+                                              n_out )
+
+          CASE ( 'ghf' )
+!
+!--          Sum up ground / wall heat flux. Note, for urban surfaces the wall heat flux is
+!--          aggregated from the different green, window and wall tiles.
+             DO  m = 1, surf_usm_h%ns
+                surf_usm_h%ghf(m) = surf_usm_h%frac(m,ind_veg_wall) * surf_usm_h%wghf_eb(m) +      &
+                                    surf_usm_h%frac(m,ind_pav_green) *                             &
+                                    surf_usm_h%wghf_eb_green(m) + surf_usm_h%frac(m,ind_wat_win) * &
+                                    surf_usm_h%wghf_eb_window(m)
+             ENDDO
+             DO  l = 0, 3
+                DO  m = 1, surf_usm_v(l)%ns
+                   surf_usm_v(l)%ghf(m) = surf_usm_v(l)%frac(m,ind_veg_wall) *                     &
+                                          surf_usm_v(l)%wghf_eb(m) +                               &
+                                          surf_usm_v(l)%frac(m,ind_pav_green) *                    &
+                                          surf_usm_v(l)%wghf_eb_green(m) +                         &
+                                          surf_usm_v(l)%frac(m,ind_wat_win) *                      &
+                                          surf_usm_v(l)%wghf_eb_window(m)
+                ENDDO
+             ENDDO
+
+             CALL surface_data_output_sum_up( surf_def_h(0)%ghf, surf_def_h(1)%ghf,                &
+                                              surf_lsm_h%ghf, surf_usm_h%ghf, surf_def_v(0)%ghf,   &
+                                              surf_lsm_v(0)%ghf, surf_usm_v(0)%ghf,                &
+                                              surf_def_v(1)%ghf, surf_lsm_v(1)%ghf,                &
+                                              surf_usm_v(1)%ghf, surf_def_v(2)%ghf,                &
+                                              surf_lsm_v(2)%ghf, surf_usm_v(2)%ghf,                &
+                                              surf_def_v(3)%ghf, surf_lsm_v(3)%ghf,                &
+                                              surf_usm_v(3)%ghf, n_out )
+
+          CASE ( 'r_a' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%r_a, surf_def_h(1)%r_a,                &
+                                              surf_lsm_h%r_a, surf_usm_h%r_a,                      &
+                                              surf_def_v(0)%r_a, surf_lsm_v(0)%r_a,                &
+                                              surf_usm_v(0)%r_a, surf_def_v(1)%r_a,                &
+                                              surf_lsm_v(1)%r_a, surf_usm_v(1)%r_a,                &
+                                              surf_def_v(2)%r_a, surf_lsm_v(2)%r_a,                &
+                                              surf_usm_v(2)%r_a, surf_def_v(3)%r_a,                &
+                                              surf_lsm_v(3)%r_a, surf_usm_v(3)%r_a, n_out )
+
+          CASE ( 'r_soil' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%r_soil, surf_def_h(1)%r_soil,          &
+                                              surf_lsm_h%r_soil, surf_usm_h%r_soil,                &
+                                              surf_def_v(0)%r_soil, surf_lsm_v(0)%r_soil,          &
+                                              surf_usm_v(0)%r_soil, surf_def_v(1)%r_soil,          &
+                                              surf_lsm_v(1)%r_soil, surf_usm_v(1)%r_soil,          &
+                                              surf_def_v(2)%r_soil, surf_lsm_v(2)%r_soil,          &
+                                              surf_usm_v(2)%r_soil, surf_def_v(3)%r_soil,          &
+                                              surf_lsm_v(3)%r_soil, surf_usm_v(3)%r_soil, n_out )
+
+          CASE ( 'r_canopy' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%r_canopy, surf_def_h(1)%r_canopy,      &
+                                              surf_lsm_h%r_canopy, surf_usm_h%r_canopy,            &
+                                              surf_def_v(0)%r_canopy, surf_lsm_v(0)%r_canopy,      &
+                                              surf_usm_v(0)%r_canopy, surf_def_v(1)%r_canopy,      &
+                                              surf_lsm_v(1)%r_canopy, surf_usm_v(1)%r_canopy,      &
+                                              surf_def_v(2)%r_canopy, surf_lsm_v(2)%r_canopy,      &
+                                              surf_usm_v(2)%r_canopy, surf_def_v(3)%r_canopy,      &
+                                              surf_lsm_v(3)%r_canopy, surf_usm_v(3)%r_canopy,      &
+                                              n_out )
+
+          CASE ( 'r_s' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%r_s, surf_def_h(1)%r_s,                &
+                                              surf_lsm_h%r_s, surf_usm_h%r_s, surf_def_v(0)%r_s,   &
+                                              surf_lsm_v(0)%r_s, surf_usm_v(0)%r_s,                &
+                                              surf_def_v(1)%r_s, surf_lsm_v(1)%r_s,                &
+                                              surf_usm_v(1)%r_s, surf_def_v(2)%r_s,                &
+                                              surf_lsm_v(2)%r_s, surf_usm_v(2)%r_s,                &
+                                              surf_def_v(3)%r_s, surf_lsm_v(3)%r_s,                &
+                                              surf_usm_v(3)%r_s, n_out )
+
+
+          CASE ( 'rad_sw_dir' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_dir, surf_def_h(1)%rad_sw_dir,  &
+                                              surf_lsm_h%rad_sw_dir, surf_usm_h%rad_sw_dir,        &
+                                              surf_def_v(0)%rad_sw_dir, surf_lsm_v(0)%rad_sw_dir,  &
+                                              surf_usm_v(0)%rad_sw_dir, surf_def_v(1)%rad_sw_dir,  &
+                                              surf_lsm_v(1)%rad_sw_dir, surf_usm_v(1)%rad_sw_dir,  &
+                                              surf_def_v(2)%rad_sw_dir, surf_lsm_v(2)%rad_sw_dir,  &
+                                              surf_usm_v(2)%rad_sw_dir, surf_def_v(3)%rad_sw_dir,  &
+                                              surf_lsm_v(3)%rad_sw_dir, surf_usm_v(3)%rad_sw_dir,  &
+                                              n_out )
+          CASE ( 'rad_sw_dif' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_dif, surf_def_h(1)%rad_sw_dif,  &
+                                              surf_lsm_h%rad_sw_dif, surf_usm_h%rad_sw_dif,        &
+                                              surf_def_v(0)%rad_sw_dif, surf_lsm_v(0)%rad_sw_dif,  &
+                                              surf_usm_v(0)%rad_sw_dif, surf_def_v(1)%rad_sw_dif,  &
+                                              surf_lsm_v(1)%rad_sw_dif, surf_usm_v(1)%rad_sw_dif,  &
+                                              surf_def_v(2)%rad_sw_dif, surf_lsm_v(2)%rad_sw_dif,  &
+                                              surf_usm_v(2)%rad_sw_dif, surf_def_v(3)%rad_sw_dif,  &
+                                              surf_lsm_v(3)%rad_sw_dif, surf_usm_v(3)%rad_sw_dif,  &
+                                              n_out )
+
+          CASE ( 'rad_sw_ref' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_ref, surf_def_h(1)%rad_sw_ref,  &
+                                              surf_lsm_h%rad_sw_ref, surf_usm_h%rad_sw_ref,        &
+                                              surf_def_v(0)%rad_sw_ref, surf_lsm_v(0)%rad_sw_ref,  &
+                                              surf_usm_v(0)%rad_sw_ref, surf_def_v(1)%rad_sw_ref,  &
+                                              surf_lsm_v(1)%rad_sw_ref, surf_usm_v(1)%rad_sw_ref,  &
+                                              surf_def_v(2)%rad_sw_ref, surf_lsm_v(2)%rad_sw_ref,  &
+                                              surf_usm_v(2)%rad_sw_ref, surf_def_v(3)%rad_sw_ref,  &
+                                              surf_lsm_v(3)%rad_sw_ref, surf_usm_v(3)%rad_sw_ref,  &
+                                              n_out )
+
+          CASE ( 'rad_sw_res' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_res, surf_def_h(1)%rad_sw_res,  &
+                                              surf_lsm_h%rad_sw_res, surf_usm_h%rad_sw_res,        &
+                                              surf_def_v(0)%rad_sw_res, surf_lsm_v(0)%rad_sw_res,  &
+                                              surf_usm_v(0)%rad_sw_res, surf_def_v(1)%rad_sw_res,  &
+                                              surf_lsm_v(1)%rad_sw_res, surf_usm_v(1)%rad_sw_res,  &
+                                              surf_def_v(2)%rad_sw_res, surf_lsm_v(2)%rad_sw_res,  &
+                                              surf_usm_v(2)%rad_sw_res, surf_def_v(3)%rad_sw_res,  &
+                                              surf_lsm_v(3)%rad_sw_res, surf_usm_v(3)%rad_sw_res,  &
+                                              n_out )
+
+          CASE ( 'rad_lw_dif' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_lw_dif, surf_def_h(1)%rad_lw_dif,  &
+                                              surf_lsm_h%rad_lw_dif, surf_usm_h%rad_lw_dif,        &
+                                              surf_def_v(0)%rad_lw_dif, surf_lsm_v(0)%rad_lw_dif,  &
+                                              surf_usm_v(0)%rad_lw_dif, surf_def_v(1)%rad_lw_dif,  &
+                                              surf_lsm_v(1)%rad_lw_dif, surf_usm_v(1)%rad_lw_dif,  &
+                                              surf_def_v(2)%rad_lw_dif, surf_lsm_v(2)%rad_lw_dif,  &
+                                              surf_usm_v(2)%rad_lw_dif, surf_def_v(3)%rad_lw_dif,  &
+                                              surf_lsm_v(3)%rad_lw_dif, surf_usm_v(3)%rad_lw_dif,  &
+                                              n_out )
+
+          CASE ( 'rad_lw_ref' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_lw_ref, surf_def_h(1)%rad_lw_ref,  &
+                                              surf_lsm_h%rad_lw_ref, surf_usm_h%rad_lw_ref,        &
+                                              surf_def_v(0)%rad_lw_ref, surf_lsm_v(0)%rad_lw_ref,  &
+                                              surf_usm_v(0)%rad_lw_ref, surf_def_v(1)%rad_lw_ref,  &
+                                              surf_lsm_v(1)%rad_lw_ref, surf_usm_v(1)%rad_lw_ref,  &
+                                              surf_def_v(2)%rad_lw_ref, surf_lsm_v(2)%rad_lw_ref,  &
+                                              surf_usm_v(2)%rad_lw_ref, surf_def_v(3)%rad_lw_ref,  &
+                                              surf_lsm_v(3)%rad_lw_ref, surf_usm_v(3)%rad_lw_ref,  &
+                                              n_out )
+
+          CASE ( 'rad_lw_res' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%rad_lw_res, surf_def_h(1)%rad_lw_res,  &
+                                              surf_lsm_h%rad_lw_res, surf_usm_h%rad_lw_res,        &
+                                              surf_def_v(0)%rad_lw_res, surf_lsm_v(0)%rad_lw_res,  &
+                                              surf_usm_v(0)%rad_lw_res, surf_def_v(1)%rad_lw_res,  &
+                                              surf_lsm_v(1)%rad_lw_res, surf_usm_v(1)%rad_lw_res,  &
+                                              surf_def_v(2)%rad_lw_res, surf_lsm_v(2)%rad_lw_res,  &
+                                              surf_usm_v(2)%rad_lw_res, surf_def_v(3)%rad_lw_res,  &
+                                              surf_lsm_v(3)%rad_lw_res, surf_usm_v(3)%rad_lw_res,  &
+                                              n_out )
+
+          CASE ( 'uvw1' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%uvw_abs, surf_def_h(1)%uvw_abs,        &
+                                              surf_lsm_h%uvw_abs, surf_usm_h%uvw_abs,              &
+                                              surf_def_v(0)%uvw_abs, surf_lsm_v(0)%uvw_abs,        &
+                                              surf_usm_v(0)%uvw_abs, surf_def_v(1)%uvw_abs,        &
+                                              surf_lsm_v(1)%uvw_abs, surf_usm_v(1)%uvw_abs,        &
+                                              surf_def_v(2)%uvw_abs, surf_lsm_v(2)%uvw_abs,        &
+                                              surf_usm_v(2)%uvw_abs, surf_def_v(3)%uvw_abs,        &
+                                              surf_lsm_v(3)%uvw_abs, surf_usm_v(3)%uvw_abs, n_out )
+
+          CASE ( 'waste_heat' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%waste_heat, surf_def_h(1)%waste_heat,  &
+                                              surf_lsm_h%waste_heat, surf_usm_h%waste_heat,        &
+                                              surf_def_v(0)%waste_heat, surf_lsm_v(0)%waste_heat,  &
+                                              surf_usm_v(0)%waste_heat, surf_def_v(1)%waste_heat,  &
+                                              surf_lsm_v(1)%waste_heat, surf_usm_v(1)%waste_heat,  &
+                                              surf_def_v(2)%waste_heat, surf_lsm_v(2)%waste_heat,  &
+                                              surf_usm_v(2)%waste_heat, surf_def_v(3)%waste_heat,  &
+                                              surf_lsm_v(3)%waste_heat, surf_usm_v(3)%waste_heat,  &
+                                              n_out )
+
+          CASE ( 'im_hf' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%iwghf_eb, surf_def_h(1)%iwghf_eb,      &
+                                              surf_lsm_h%iwghf_eb, surf_usm_h%iwghf_eb,            &
+                                              surf_def_v(0)%iwghf_eb, surf_lsm_v(0)%iwghf_eb,      &
+                                              surf_usm_v(0)%iwghf_eb, surf_def_v(1)%iwghf_eb,      &
+                                              surf_lsm_v(1)%iwghf_eb, surf_usm_v(1)%iwghf_eb,      &
+                                              surf_def_v(2)%iwghf_eb, surf_lsm_v(2)%iwghf_eb,      &
+                                              surf_usm_v(2)%iwghf_eb, surf_def_v(3)%iwghf_eb,      &
+                                              surf_lsm_v(3)%iwghf_eb, surf_usm_v(3)%iwghf_eb, n_out )
+
+          CASE ( 'albedo' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%albedo, surf_def_h(1)%albedo,          &
+                                              surf_lsm_h%albedo, surf_usm_h%albedo,                &
+                                              surf_def_v(0)%albedo, surf_lsm_v(0)%albedo,          &
+                                              surf_usm_v(0)%albedo, surf_def_v(1)%albedo,          &
+                                              surf_lsm_v(1)%albedo, surf_usm_v(1)%albedo,          &
+                                              surf_def_v(2)%albedo, surf_lsm_v(2)%albedo,          &
+                                              surf_usm_v(2)%albedo, surf_def_v(3)%albedo,          &
+                                              surf_lsm_v(3)%albedo, surf_usm_v(3)%albedo, n_out )
+
+
+          CASE ( 'emissivity' )
+             CALL surface_data_output_sum_up( surf_def_h(0)%emissivity, surf_def_h(1)%emissivity,  &
+                                              surf_lsm_h%emissivity, surf_usm_h%emissivity,        &
+                                              surf_def_v(0)%emissivity, surf_lsm_v(0)%emissivity,  &
+                                              surf_usm_v(0)%emissivity, surf_def_v(1)%emissivity,  &
+                                              surf_lsm_v(1)%emissivity, surf_usm_v(1)%emissivity,  &
+                                              surf_def_v(2)%emissivity, surf_lsm_v(2)%emissivity,  &
+                                              surf_usm_v(2)%emissivity, surf_def_v(3)%emissivity,  &
+                                              surf_lsm_v(3)%emissivity, surf_usm_v(3)%emissivity,  &
+                                              n_out )
+
+       END SELECT
+    ENDDO
+
+
+ END SUBROUTINE surface_data_output_averaging
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Sum-up the surface data for average output variables.
-!------------------------------------------------------------------------------!
-   SUBROUTINE surface_data_output_sum_up_1d( var_def_h0, var_def_h1,           &
-                                     var_lsm_h,  var_usm_h,                    &
-                                     var_def_v0, var_lsm_v0, var_usm_v0,       &
-                                     var_def_v1, var_lsm_v1, var_usm_v1,       &
-                                     var_def_v2, var_lsm_v2, var_usm_v2,       &
-                                     var_def_v3, var_lsm_v3, var_usm_v3, n_out,&
-                                     fac )
-
-      IMPLICIT NONE
-
-      INTEGER(iwp) ::  k          !< height index of surface element
-      INTEGER(iwp) ::  m          !< running index for surface elements
-      INTEGER(iwp) ::  n_out      !< index for output variable
-      INTEGER(iwp) ::  n_surf     !< running index for surface elements
-
-      REAL(wp), DIMENSION(:), OPTIONAL                ::  fac               !< passed output conversion factor for heatflux output
-      REAL(wp), DIMENSION(nzb:nzt+1)                  ::  conversion_factor !< effective array for output conversion factor
-
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h0 !< output variable at upward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h1 !< output variable at downward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_h  !< output variable at upward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_h  !< output variable at upward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v0 !< output variable at northward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v1 !< output variable at southward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v2 !< output variable at eastward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v3 !< output variable at westward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v0 !< output variable at northward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v1 !< output variable at southward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v2 !< output variable at eastward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v3 !< output variable at westward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v0 !< output variable at northward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v1 !< output variable at southward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v2 !< output variable at eastward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v3 !< output variable at westward-facing urban-type surfaces
-
-!
-!--   Set conversion factor to one if not present
-      IF ( .NOT. PRESENT( fac ) )  THEN
-         conversion_factor = 1.0_wp
-      ELSE
-         conversion_factor = fac
-      ENDIF
-!
-!--   Set counter variable to zero before the variable is written to
-!--   the output array.
-      n_surf = 0
-
-!
-!--   Write the horizontal surfaces.
-!--   Before each the variable is written to the output data structure, first
-!--   check if the variable for the respective surface type is defined.
-!--   If a variable is not defined, skip the block and increment the counter
-!--   variable by the number of surface elements of this type. Usually this
-!--   is zere, however, there might be the situation that e.g. urban surfaces
-!--   are defined but the respective variable is not allocated for this surface
-!--   type. To write the data on the exact position, increment the counter.
-      IF ( ALLOCATED( var_def_h0 ) )  THEN
-         DO  m = 1, surf_def_h(0)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_def_h(0)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_def_h0(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_h(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_def_h1 ) )  THEN
-         DO  m = 1, surf_def_h(1)%ns
-            n_surf                   = n_surf + 1
-            k                             = surf_def_h(1)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_def_h1(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_h(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_h ) )  THEN
-         DO  m = 1, surf_lsm_h%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_lsm_h%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_lsm_h(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_h%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_h ) )  THEN
-         DO  m = 1, surf_usm_h%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_usm_h%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_usm_h(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_h%ns
-      ENDIF
-!
-!--   Write northward-facing
-      IF ( ALLOCATED( var_def_v0 ) )  THEN
-         DO  m = 1, surf_def_v(0)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_def_v(0)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_def_v0(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v0 ) )  THEN
-         DO  m = 1, surf_lsm_v(0)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_lsm_v(0)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_lsm_v0(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v0 ) )  THEN
-         DO  m = 1, surf_usm_v(0)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_usm_v(0)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_usm_v0(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(0)%ns
-      ENDIF
-!
-!--   Write southward-facing
-      IF ( ALLOCATED( var_def_v1 ) )  THEN
-         DO  m = 1, surf_def_v(1)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_def_v(1)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_def_v1(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v1 ) )  THEN
-         DO  m = 1, surf_lsm_v(1)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_lsm_v(1)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_lsm_v1(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v1 ) )  THEN
-         DO  m = 1, surf_usm_v(1)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_usm_v(1)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_usm_v1(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(1)%ns
-      ENDIF
-!
-!--   Write eastward-facing
-      IF ( ALLOCATED( var_def_v2 ) )  THEN
-         DO  m = 1, surf_def_v(2)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_def_v(2)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_def_v2(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(2)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v2 ) )  THEN
-         DO  m = 1, surf_lsm_v(2)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_lsm_v(2)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_lsm_v2(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(2)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v2 ) )  THEN
-         DO  m = 1, surf_usm_v(2)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_usm_v(2)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_usm_v2(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(2)%ns
-      ENDIF
-!
-!--   Write westward-facing
-      IF ( ALLOCATED( var_def_v3 ) )  THEN
-         DO  m = 1, surf_def_v(3)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_def_v(3)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_def_v3(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(3)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v3 ) )  THEN
-         DO  m = 1, surf_lsm_v(3)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_lsm_v(3)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_lsm_v3(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(3)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v3 ) )  THEN
-         DO  m = 1, surf_usm_v(3)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_usm_v(3)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
-                                          + var_usm_v3(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(3)%ns
-      ENDIF
-
-   END SUBROUTINE surface_data_output_sum_up_1d
-
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_sum_up_1d( var_def_h0, var_def_h1, var_lsm_h, var_usm_h,           &
+                                           var_def_v0, var_lsm_v0, var_usm_v0, var_def_v1,         &
+                                           var_lsm_v1, var_usm_v1, var_def_v2, var_lsm_v2,         &
+                                           var_usm_v2, var_def_v3, var_lsm_v3, var_usm_v3, n_out,  &
+                                           fac )
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  k       !< height index of surface element
+    INTEGER(iwp) ::  m       !< running index for surface elements
+    INTEGER(iwp) ::  n_out   !< index for output variable
+    INTEGER(iwp) ::  n_surf  !< running index for surface elements
+
+    REAL(wp), DIMENSION(:), OPTIONAL                ::  fac                !< passed output conversion factor for heatflux output
+    REAL(wp), DIMENSION(nzb:nzt+1)                  ::  conversion_factor  !< effective array for output conversion factor
+
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h0  !< output variable at upward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h1  !< output variable at downward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_h   !< output variable at upward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_h   !< output variable at upward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v0  !< output variable at northward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v1  !< output variable at southward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v2  !< output variable at eastward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v3  !< output variable at westward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v0  !< output variable at northward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v1  !< output variable at southward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v2  !< output variable at eastward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v3  !< output variable at westward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v0  !< output variable at northward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v1  !< output variable at southward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v2  !< output variable at eastward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v3  !< output variable at westward-facing urban-type surfaces
+
+!
+!-- Set conversion factor to one if not present
+    IF ( .NOT. PRESENT( fac ) )  THEN
+       conversion_factor = 1.0_wp
+    ELSE
+       conversion_factor = fac
+    ENDIF
+!
+!-- Set counter variable to zero before the variable is written to the output array.
+    n_surf = 0
+
+!
+!-- Write the horizontal surfaces.
+!-- Before each variable is written to the output data structure, first check if the variable
+!-- for the respective surface type is defined. If a variable is not defined, skip the block and
+!-- increment the counter variable by the number of surface elements of this type. Usually this is
+!-- zero, however, there might be the situation that e.g. urban surfaces are defined but the
+!-- respective variable is not allocated for this surface type. To write the data on the exact
+!-- position, increment the counter.
+    IF ( ALLOCATED( var_def_h0 ) )  THEN
+       DO  m = 1, surf_def_h(0)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_def_h(0)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out) + var_def_h0(m) *          &
+                                          conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_h(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_def_h1 ) )  THEN
+       DO  m = 1, surf_def_h(1)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_def_h(1)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out) + var_def_h1(m) *          &
+                                          conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_h(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_h ) )  THEN
+       DO  m = 1, surf_lsm_h%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_lsm_h%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out) + var_lsm_h(m) *           &
+                                          conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_h%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_h ) )  THEN
+       DO  m = 1, surf_usm_h%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_usm_h%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out) + var_usm_h(m) *           &
+                                          conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_h%ns
+    ENDIF
+!
+!-- Write northward-facing
+    IF ( ALLOCATED( var_def_v0 ) )  THEN
+       DO  m = 1, surf_def_v(0)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_def_v(0)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out) + var_def_v0(m) *          &
+                                          conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v0 ) )  THEN
+       DO  m = 1, surf_lsm_v(0)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_lsm_v(0)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out) + var_lsm_v0(m) *          &
+                                          conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v0 ) )  THEN
+       DO  m = 1, surf_usm_v(0)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_usm_v(0)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out) + var_usm_v0(m) *          &
+                                          conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(0)%ns
+    ENDIF
+!
+!-- Write southward-facing
+    IF ( ALLOCATED( var_def_v1 ) )  THEN
+       DO  m = 1, surf_def_v(1)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_def_v(1)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out) + var_def_v1(m) *          &
+                                          conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v1 ) )  THEN
+       DO  m = 1, surf_lsm_v(1)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_lsm_v(1)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out) + var_lsm_v1(m) *          &
+                                          conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v1 ) )  THEN
+       DO  m = 1, surf_usm_v(1)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_usm_v(1)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out) + var_usm_v1(m) *          &
+                                          conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(1)%ns
+    ENDIF
+!
+!-- Write eastward-facing
+    IF ( ALLOCATED( var_def_v2 ) )  THEN
+       DO  m = 1, surf_def_v(2)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_def_v(2)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + var_def_v2(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(2)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v2 ) )  THEN
+       DO  m = 1, surf_lsm_v(2)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_lsm_v(2)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + var_lsm_v2(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(2)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v2 ) )  THEN
+       DO  m = 1, surf_usm_v(2)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_usm_v(2)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + var_usm_v2(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(2)%ns
+    ENDIF
+!
+!-- Write westward-facing
+    IF ( ALLOCATED( var_def_v3 ) )  THEN
+       DO  m = 1, surf_def_v(3)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_def_v(3)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + var_def_v3(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(3)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v3 ) )  THEN
+       DO  m = 1, surf_lsm_v(3)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_lsm_v(3)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + var_lsm_v3(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(3)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v3 ) )  THEN
+       DO  m = 1, surf_usm_v(3)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_usm_v(3)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + var_usm_v3(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(3)%ns
+    ENDIF
+
+ END SUBROUTINE surface_data_output_sum_up_1d
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Sum-up the surface data for average output variables for properties which
-!> are defined using tile approach.
-!------------------------------------------------------------------------------!
-   SUBROUTINE surface_data_output_sum_up_2d( var_def_h0, var_def_h1,           &
-                                     var_lsm_h,  var_usm_h,                    &
-                                     var_def_v0, var_lsm_v0, var_usm_v0,       &
-                                     var_def_v1, var_lsm_v1, var_usm_v1,       &
-                                     var_def_v2, var_lsm_v2, var_usm_v2,       &
-                                     var_def_v3, var_lsm_v3, var_usm_v3, n_out,&
-                                     fac )
-
-      IMPLICIT NONE
-
-      INTEGER(iwp) ::  k          !< height index of surface element
-      INTEGER(iwp) ::  m          !< running index for surface elements
-      INTEGER(iwp) ::  n_out      !< index for output variable
-      INTEGER(iwp) ::  n_surf     !< running index for surface elements
-
-      REAL(wp), DIMENSION(:), OPTIONAL                ::  fac               !< passed output conversion factor for heatflux output
-      REAL(wp), DIMENSION(nzb:nzt+1)                  ::  conversion_factor !< effective array for output conversion factor
-
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_h0 !< output variable at upward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_h1 !< output variable at downward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_h  !< output variable at upward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_h  !< output variable at upward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v0 !< output variable at northward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v1 !< output variable at southward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v2 !< output variable at eastward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v3 !< output variable at westward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v0 !< output variable at northward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v1 !< output variable at southward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v2 !< output variable at eastward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v3 !< output variable at westward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v0 !< output variable at northward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v1 !< output variable at southward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v2 !< output variable at eastward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v3 !< output variable at westward-facing urban-type surfaces
-
-!
-!--   Set conversion factor to one if not present
-      IF ( .NOT. PRESENT( fac ) )  THEN
-         conversion_factor = 1.0_wp
-      ELSE
-         conversion_factor = fac
-      ENDIF
-!
-!--   Set counter variable to zero before the variable is written to
-!--   the output array.
-      n_surf = 0
-
-!
-!--   Write the horizontal surfaces.
-!--   Before each the variable is written to the output data structure, first
-!--   check if the variable for the respective surface type is defined.
-!--   If a variable is not defined, skip the block and increment the counter
-!--   variable by the number of surface elements of this type. Usually this
-!--   is zere, however, there might be the situation that e.g. urban surfaces
-!--   are defined but the respective variable is not allocated for this surface
-!--   type. To write the data on the exact position, increment the counter.
-      IF ( ALLOCATED( var_def_h0 ) )  THEN
-         DO  m = 1, surf_def_h(0)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_def_h(0)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_def_h(0)%frac(m,:) *        &
-                                            var_def_h0(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_h(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_def_h1 ) )  THEN
-         DO  m = 1, surf_def_h(1)%ns
-            n_surf                   = n_surf + 1
-            k                             = surf_def_h(1)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_def_h(1)%frac(m,:) *        &
-                                            var_def_h1(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_h(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_h ) )  THEN
-         DO  m = 1, surf_lsm_h%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_lsm_h%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_lsm_h%frac(m,:) *           &
-                                            var_lsm_h(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_h%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_h ) )  THEN
-         DO  m = 1, surf_usm_h%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_usm_h%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_usm_h%frac(m,:) *           &
-                                            var_usm_h(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_h%ns
-      ENDIF
-!
-!--   Write northward-facing
-      IF ( ALLOCATED( var_def_v0 ) )  THEN
-         DO  m = 1, surf_def_v(0)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_def_v(0)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_def_v(0)%frac(m,:) *        &
-                                            var_def_v0(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v0 ) )  THEN
-         DO  m = 1, surf_lsm_v(0)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_lsm_v(0)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_lsm_v(0)%frac(m,:) *        &
-                                            var_lsm_v0(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v0 ) )  THEN
-         DO  m = 1, surf_usm_v(0)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_usm_v(0)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_usm_v(0)%frac(m,:) *        &
-                                            var_usm_v0(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(0)%ns
-      ENDIF
-!
-!--   Write southward-facing
-      IF ( ALLOCATED( var_def_v1 ) )  THEN
-         DO  m = 1, surf_def_v(1)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_def_v(1)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_def_v(1)%frac(m,:) *        &
-                                            var_def_v1(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v1 ) )  THEN
-         DO  m = 1, surf_lsm_v(1)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_lsm_v(1)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_lsm_v(1)%frac(m,:) *        &
-                                            var_lsm_v1(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v1 ) )  THEN
-         DO  m = 1, surf_usm_v(1)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_usm_v(1)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_usm_v(1)%frac(m,:) *        &
-                                            var_usm_v1(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(1)%ns
-      ENDIF
-!
-!--   Write eastward-facing
-      IF ( ALLOCATED( var_def_v2 ) )  THEN
-         DO  m = 1, surf_def_v(2)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_def_v(2)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_def_v(2)%frac(m,:) *        &
-                                            var_def_v2(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(2)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v2 ) )  THEN
-         DO  m = 1, surf_lsm_v(2)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_lsm_v(2)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_lsm_v(2)%frac(m,:) *        &
-                                            var_lsm_v2(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(2)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v2 ) )  THEN
-         DO  m = 1, surf_usm_v(2)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_usm_v(2)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_usm_v(2)%frac(m,:) *        &
-                                            var_usm_v2(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(2)%ns
-      ENDIF
-!
-!--   Write westward-facing
-      IF ( ALLOCATED( var_def_v3 ) )  THEN
-         DO  m = 1, surf_def_v(3)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_def_v(3)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_def_v(3)%frac(m,:) *        &
-                                            var_def_v3(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(3)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v3 ) )  THEN
-         DO  m = 1, surf_lsm_v(3)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_lsm_v(3)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_lsm_v(3)%frac(m,:) *        &
-                                            var_lsm_v3(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(3)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v3 ) )  THEN
-         DO  m = 1, surf_usm_v(3)%ns
-            n_surf                        = n_surf + 1
-            k                             = surf_usm_v(3)%k(m)
-            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)          &
-                                          + SUM ( surf_usm_v(3)%frac(m,:) *        &
-                                            var_usm_v3(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(3)%ns
-      ENDIF
-
-   END SUBROUTINE surface_data_output_sum_up_2d
-
-!------------------------------------------------------------------------------!
+!> Sum-up the surface data for average output variables for properties which are defined using tile
+!> approach.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_sum_up_2d( var_def_h0, var_def_h1, var_lsm_h, var_usm_h,           &
+                                           var_def_v0, var_lsm_v0, var_usm_v0, var_def_v1,         &
+                                           var_lsm_v1, var_usm_v1, var_def_v2, var_lsm_v2,         &
+                                           var_usm_v2, var_def_v3, var_lsm_v3, var_usm_v3, n_out,  &
+                                           fac )
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  k       !< height index of surface element
+    INTEGER(iwp) ::  m       !< running index for surface elements
+    INTEGER(iwp) ::  n_out   !< index for output variable
+    INTEGER(iwp) ::  n_surf  !< running index for surface elements
+
+    REAL(wp), DIMENSION(:), OPTIONAL                  ::  fac                !< passed output conversion factor for heatflux output
+    REAL(wp), DIMENSION(nzb:nzt+1)                    ::  conversion_factor  !< effective array for output conversion factor
+
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_h0  !< output variable at upward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_h1  !< output variable at downward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_h   !< output variable at upward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_h   !< output variable at upward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v0  !< output variable at northward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v1  !< output variable at southward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v2  !< output variable at eastward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v3  !< output variable at westward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v0  !< output variable at northward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v1  !< output variable at southward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v2  !< output variable at eastward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v3  !< output variable at westward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v0  !< output variable at northward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v1  !< output variable at southward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v2  !< output variable at eastward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v3  !< output variable at westward-facing urban-type surfaces
+
+!
+!-- Set conversion factor to one if not present
+    IF ( .NOT. PRESENT( fac ) )  THEN
+       conversion_factor = 1.0_wp
+    ELSE
+       conversion_factor = fac
+    ENDIF
+!
+!-- Set counter variable to zero before the variable is written to the output array.
+    n_surf = 0
+
+!
+!-- Write the horizontal surfaces.
+!-- Before each variable is written to the output data structure, first check if the variable
+!-- for the respective surface type is defined. If a variable is not defined, skip the block and
+!-- increment the counter variable by the number of surface elements of this type. Usually this is
+!-- zero, however, there might be the situation that e.g. urban surfaces are defined but the
+!-- respective variable is not allocated for this surface type. To write the data on the exact
+!-- position, increment the counter.
+    IF ( ALLOCATED( var_def_h0 ) )  THEN
+       DO  m = 1, surf_def_h(0)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_def_h(0)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                          + SUM ( surf_def_h(0)%frac(m,:) *                        &
+                                          var_def_h0(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_h(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_def_h1 ) )  THEN
+       DO  m = 1, surf_def_h(1)%ns
+          n_surf                   = n_surf + 1
+          k                             = surf_def_h(1)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_def_h(1)%frac(m,:) *                          &
+                                          var_def_h1(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_h(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_h ) )  THEN
+       DO  m = 1, surf_lsm_h%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_lsm_h%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_lsm_h%frac(m,:) *                             &
+                                          var_lsm_h(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_h%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_h ) )  THEN
+       DO  m = 1, surf_usm_h%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_usm_h%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_usm_h%frac(m,:) *                             &
+                                          var_usm_h(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_h%ns
+    ENDIF
+!
+!-- Write northward-facing
+    IF ( ALLOCATED( var_def_v0 ) )  THEN
+       DO  m = 1, surf_def_v(0)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_def_v(0)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_def_v(0)%frac(m,:) *                          &
+                                          var_def_v0(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v0 ) )  THEN
+       DO  m = 1, surf_lsm_v(0)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_lsm_v(0)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_lsm_v(0)%frac(m,:) *                          &
+                                          var_lsm_v0(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v0 ) )  THEN
+       DO  m = 1, surf_usm_v(0)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_usm_v(0)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_usm_v(0)%frac(m,:) *                          &
+                                          var_usm_v0(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(0)%ns
+    ENDIF
+!
+!-- Write southward-facing
+    IF ( ALLOCATED( var_def_v1 ) )  THEN
+       DO  m = 1, surf_def_v(1)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_def_v(1)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_def_v(1)%frac(m,:) *                          &
+                                          var_def_v1(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v1 ) )  THEN
+       DO  m = 1, surf_lsm_v(1)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_lsm_v(1)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_lsm_v(1)%frac(m,:) *                          &
+                                          var_lsm_v1(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v1 ) )  THEN
+       DO  m = 1, surf_usm_v(1)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_usm_v(1)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_usm_v(1)%frac(m,:) *                          &
+                                          var_usm_v1(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(1)%ns
+    ENDIF
+!
+!-- Write eastward-facing
+    IF ( ALLOCATED( var_def_v2 ) )  THEN
+       DO  m = 1, surf_def_v(2)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_def_v(2)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_def_v(2)%frac(m,:) *                          &
+                                          var_def_v2(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(2)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v2 ) )  THEN
+       DO  m = 1, surf_lsm_v(2)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_lsm_v(2)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_lsm_v(2)%frac(m,:) *                          &
+                                          var_lsm_v2(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(2)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v2 ) )  THEN
+       DO  m = 1, surf_usm_v(2)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_usm_v(2)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_usm_v(2)%frac(m,:) *                          &
+                                          var_usm_v2(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(2)%ns
+    ENDIF
+!
+!-- Write westward-facing
+    IF ( ALLOCATED( var_def_v3 ) )  THEN
+       DO  m = 1, surf_def_v(3)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_def_v(3)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_def_v(3)%frac(m,:) *                          &
+                                          var_def_v3(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(3)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v3 ) )  THEN
+       DO  m = 1, surf_lsm_v(3)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_lsm_v(3)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_lsm_v(3)%frac(m,:) *                          &
+                                          var_lsm_v3(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(3)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v3 ) )  THEN
+       DO  m = 1, surf_usm_v(3)%ns
+          n_surf                        = n_surf + 1
+          k                             = surf_usm_v(3)%k(m)
+          surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)                            &
+                                        + SUM ( surf_usm_v(3)%frac(m,:) *                          &
+                                          var_usm_v3(m,:) ) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(3)%ns
+    ENDIF
+
+ END SUBROUTINE surface_data_output_sum_up_2d
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Collect the surface data from different types and different orientation.
-!------------------------------------------------------------------------------!
-   SUBROUTINE surface_data_output_collect_1d( var_def_h0, var_def_h1,          &
-                                      var_lsm_h,  var_usm_h,                   &
-                                      var_def_v0, var_lsm_v0, var_usm_v0,      &
-                                      var_def_v1, var_lsm_v1, var_usm_v1,      &
-                                      var_def_v2, var_lsm_v2, var_usm_v2,      &
-                                      var_def_v3, var_lsm_v3, var_usm_v3,      &
-                                      fac )
-
-      IMPLICIT NONE
-
-      INTEGER(iwp) ::  k      !< height index of surface element
-      INTEGER(iwp) ::  m      !< running index for surface elements
-      INTEGER(iwp) ::  n_surf !< running index for surface elements
-
-      REAL(wp), DIMENSION(:), OPTIONAL                ::  fac               !< passed output conversion factor for heatflux output
-      REAL(wp), DIMENSION(nzb:nzt+1)                  ::  conversion_factor !< effective array for output conversion factor
-
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h0 !< output variable at upward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h1 !< output variable at downward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_h  !< output variable at upward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_h  !< output variable at upward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v0 !< output variable at northward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v1 !< output variable at southward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v2 !< output variable at eastward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v3 !< output variable at westward-facing default-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v0 !< output variable at northward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v1 !< output variable at southward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v2 !< output variable at eastward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v3 !< output variable at westward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v0 !< output variable at northward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v1 !< output variable at southward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v2 !< output variable at eastward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v3 !< output variable at westward-facing urban-type surfaces
-
-!
-!--   Set conversion factor to one if not present
-      IF ( .NOT. PRESENT( fac ) )  THEN
-         conversion_factor = 1.0_wp
-      ELSE
-         conversion_factor = fac
-      ENDIF
-!
-!--   Set counter variable to zero before the variable is written to
-!--   the output array.
-      n_surf = 0
-!
-!--   Write the horizontal surfaces.
-!--   Before each the variable is written to the output data structure, first
-!--   check if the variable for the respective surface type is defined.
-!--   If a variable is not defined, skip the block and increment the counter
-!--   variable by the number of surface elements of this type. Usually this
-!--   is zero, however, there might be the situation that e.g. urban surfaces
-!--   are defined but the respective variable is not allocated for this surface
-!--   type. To write the data on the exact position, increment the counter.
-      IF ( ALLOCATED( var_def_h0 ) )  THEN
-         DO  m = 1, surf_def_h(0)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_h(0)%k(m)
-            surfaces%var_out(n_surf) = var_def_h0(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_h(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_def_h1 ) )  THEN
-         DO  m = 1, surf_def_h(1)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_h(1)%k(m)
-            surfaces%var_out(n_surf) = var_def_h1(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_h(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_h ) )  THEN
-         DO  m = 1, surf_lsm_h%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_lsm_h%k(m)
-            surfaces%var_out(n_surf) = var_lsm_h(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_h%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_h ) )  THEN
-         DO  m = 1, surf_usm_h%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_usm_h%k(m)
-            surfaces%var_out(n_surf) = var_usm_h(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_h%ns
-      ENDIF
-!
-!--   Write northward-facing
-      IF ( ALLOCATED( var_def_v0 ) )  THEN
-         DO  m = 1, surf_def_v(0)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_v(0)%k(m)
-            surfaces%var_out(n_surf) = var_def_v0(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v0 ) )  THEN
-         DO  m = 1, surf_lsm_v(0)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_lsm_v(0)%k(m)
-            surfaces%var_out(n_surf) = var_lsm_v0(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v0 ) )  THEN
-         DO  m = 1, surf_usm_v(0)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_usm_v(0)%k(m)
-            surfaces%var_out(n_surf) = var_usm_v0(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(0)%ns
-      ENDIF
-!
-!--   Write southward-facing
-      IF ( ALLOCATED( var_def_v1 ) )  THEN
-         DO  m = 1, surf_def_v(1)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_v(1)%k(m)
-            surfaces%var_out(n_surf) = var_def_v1(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v1 ) )  THEN
-         DO  m = 1, surf_lsm_v(1)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_lsm_v(1)%k(m)
-            surfaces%var_out(n_surf) = var_lsm_v1(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v1 ) )  THEN
-         DO  m = 1, surf_usm_v(1)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_usm_v(1)%k(m)
-            surfaces%var_out(n_surf) = var_usm_v1(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(1)%ns
-      ENDIF
-!
-!--   Write eastward-facing
-      IF ( ALLOCATED( var_def_v2 ) )  THEN
-         DO  m = 1, surf_def_v(2)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_v(2)%k(m)
-            surfaces%var_out(n_surf) = var_def_v2(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(2)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v2 ) )  THEN
-         DO  m = 1, surf_lsm_v(2)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_lsm_v(2)%k(m)
-            surfaces%var_out(n_surf) = var_lsm_v2(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(2)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v2 ) )  THEN
-         DO  m = 1, surf_usm_v(2)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_usm_v(2)%k(m)
-            surfaces%var_out(n_surf) = var_usm_v2(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(2)%ns
-      ENDIF
-!
-!--   Write westward-facing
-      IF ( ALLOCATED( var_def_v3 ) )  THEN
-         DO  m = 1, surf_def_v(3)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_v(3)%k(m)
-            surfaces%var_out(n_surf) = var_def_v3(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(3)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v3 ) )  THEN
-         DO  m = 1, surf_lsm_v(3)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_lsm_v(3)%k(m)
-            surfaces%var_out(n_surf) = var_lsm_v3(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(3)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v3 ) )  THEN
-         DO  m = 1, surf_usm_v(3)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_usm_v(3)%k(m)
-            surfaces%var_out(n_surf) = var_usm_v3(m) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(3)%ns
-      ENDIF
-
-   END SUBROUTINE surface_data_output_collect_1d
-
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_collect_1d( var_def_h0, var_def_h1, var_lsm_h, var_usm_h,          &
+                                           var_def_v0, var_lsm_v0, var_usm_v0, var_def_v1,         &
+                                           var_lsm_v1, var_usm_v1, var_def_v2, var_lsm_v2,         &
+                                           var_usm_v2, var_def_v3, var_lsm_v3, var_usm_v3, fac )
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  k       !< height index of surface element
+    INTEGER(iwp) ::  m       !< running index for surface elements
+    INTEGER(iwp) ::  n_surf  !< running index for surface elements
+
+    REAL(wp), DIMENSION(:), OPTIONAL                ::  fac                !< passed output conversion factor for heatflux output
+    REAL(wp), DIMENSION(nzb:nzt+1)                  ::  conversion_factor  !< effective array for output conversion factor
+
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h0  !< output variable at upward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h1  !< output variable at downward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_h   !< output variable at upward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_h   !< output variable at upward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v0  !< output variable at northward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v1  !< output variable at southward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v2  !< output variable at eastward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_v3  !< output variable at westward-facing default-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v0  !< output variable at northward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v1  !< output variable at southward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v2  !< output variable at eastward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v3  !< output variable at westward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v0  !< output variable at northward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v1  !< output variable at southward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v2  !< output variable at eastward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v3  !< output variable at westward-facing urban-type surfaces
+
+!
+!-- Set conversion factor to one if not present
+    IF ( .NOT. PRESENT( fac ) )  THEN
+       conversion_factor = 1.0_wp
+    ELSE
+       conversion_factor = fac
+    ENDIF
+!
+!-- Set counter variable to zero before the variable is written to the output array.
+    n_surf = 0
+!
+!-- Write the horizontal surfaces.
+!-- Before each variable is written to the output data structure, first check if the variable
+!-- for the respective surface type is defined. If a variable is not defined, skip the block and
+!-- increment the counter variable by the number of surface elements of this type. Usually this is
+!-- zero, however, there might be the situation that e.g. urban surfaces are defined but the
+!-- respective variable is not allocated for this surface type. To write the data on the exact
+!-- position, increment the counter.
+    IF ( ALLOCATED( var_def_h0 ) )  THEN
+       DO  m = 1, surf_def_h(0)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_h(0)%k(m)
+          surfaces%var_out(n_surf) = var_def_h0(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_h(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_def_h1 ) )  THEN
+       DO  m = 1, surf_def_h(1)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_h(1)%k(m)
+          surfaces%var_out(n_surf) = var_def_h1(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_h(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_h ) )  THEN
+       DO  m = 1, surf_lsm_h%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_lsm_h%k(m)
+          surfaces%var_out(n_surf) = var_lsm_h(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_h%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_h ) )  THEN
+       DO  m = 1, surf_usm_h%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_usm_h%k(m)
+          surfaces%var_out(n_surf) = var_usm_h(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_h%ns
+    ENDIF
+!
+!-- Write northward-facing
+    IF ( ALLOCATED( var_def_v0 ) )  THEN
+       DO  m = 1, surf_def_v(0)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_v(0)%k(m)
+          surfaces%var_out(n_surf) = var_def_v0(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v0 ) )  THEN
+       DO  m = 1, surf_lsm_v(0)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_lsm_v(0)%k(m)
+          surfaces%var_out(n_surf) = var_lsm_v0(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v0 ) )  THEN
+       DO  m = 1, surf_usm_v(0)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_usm_v(0)%k(m)
+          surfaces%var_out(n_surf) = var_usm_v0(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(0)%ns
+    ENDIF
+!
+!-- Write southward-facing
+    IF ( ALLOCATED( var_def_v1 ) )  THEN
+       DO  m = 1, surf_def_v(1)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_v(1)%k(m)
+          surfaces%var_out(n_surf) = var_def_v1(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v1 ) )  THEN
+       DO  m = 1, surf_lsm_v(1)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_lsm_v(1)%k(m)
+          surfaces%var_out(n_surf) = var_lsm_v1(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v1 ) )  THEN
+       DO  m = 1, surf_usm_v(1)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_usm_v(1)%k(m)
+          surfaces%var_out(n_surf) = var_usm_v1(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(1)%ns
+    ENDIF
+!
+!-- Write eastward-facing
+    IF ( ALLOCATED( var_def_v2 ) )  THEN
+       DO  m = 1, surf_def_v(2)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_v(2)%k(m)
+          surfaces%var_out(n_surf) = var_def_v2(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(2)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v2 ) )  THEN
+       DO  m = 1, surf_lsm_v(2)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_lsm_v(2)%k(m)
+          surfaces%var_out(n_surf) = var_lsm_v2(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(2)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v2 ) )  THEN
+       DO  m = 1, surf_usm_v(2)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_usm_v(2)%k(m)
+          surfaces%var_out(n_surf) = var_usm_v2(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(2)%ns
+    ENDIF
+!
+!-- Write westward-facing
+    IF ( ALLOCATED( var_def_v3 ) )  THEN
+       DO  m = 1, surf_def_v(3)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_v(3)%k(m)
+          surfaces%var_out(n_surf) = var_def_v3(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(3)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v3 ) )  THEN
+       DO  m = 1, surf_lsm_v(3)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_lsm_v(3)%k(m)
+          surfaces%var_out(n_surf) = var_lsm_v3(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(3)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v3 ) )  THEN
+       DO  m = 1, surf_usm_v(3)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_usm_v(3)%k(m)
+          surfaces%var_out(n_surf) = var_usm_v3(m) * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(3)%ns
+    ENDIF
+
+ END SUBROUTINE surface_data_output_collect_1d
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Collect the surface data from different types and different orientation
-!>  for properties which are defined using tile approach.
-!------------------------------------------------------------------------------!
-   SUBROUTINE surface_data_output_collect_2d( var_def_h0, var_def_h1,          &
-                                      var_lsm_h,  var_usm_h,                   &
-                                      var_def_v0, var_lsm_v0, var_usm_v0,      &
-                                      var_def_v1, var_lsm_v1, var_usm_v1,      &
-                                      var_def_v2, var_lsm_v2, var_usm_v2,      &
-                                      var_def_v3, var_lsm_v3, var_usm_v3,      &
-                                      fac )
-
-      IMPLICIT NONE
-
-      INTEGER(iwp) ::  k      !< height index of surface element
-      INTEGER(iwp) ::  m      !< running index for surface elements
-      INTEGER(iwp) ::  n_surf !< running index for surface elements
-
-      REAL(wp), DIMENSION(:), OPTIONAL                ::  fac               !< passed output conversion factor for heatflux output
-      REAL(wp), DIMENSION(nzb:nzt+1)                  ::  conversion_factor !< effective array for output conversion factor
-
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_h0 !< output variable at upward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_h1 !< output variable at downward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_h  !< output variable at upward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_h  !< output variable at upward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v0 !< output variable at northward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v1 !< output variable at southward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v2 !< output variable at eastward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v3 !< output variable at westward-facing default-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v0 !< output variable at northward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v1 !< output variable at southward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v2 !< output variable at eastward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v3 !< output variable at westward-facing natural-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v0 !< output variable at northward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v1 !< output variable at southward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v2 !< output variable at eastward-facing urban-type surfaces
-      REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v3 !< output variable at westward-facing urban-type surfaces
-
-!
-!--   Set conversion factor to one if not present
-      IF ( .NOT. PRESENT( fac ) )  THEN
-         conversion_factor = 1.0_wp
-      ELSE
-         conversion_factor = fac
-      ENDIF
-!
-!--   Set counter variable to zero before the variable is written to
-!--   the output array.
-      n_surf = 0
-!
-!--   Write the horizontal surfaces.
-!--   Before each the variable is written to the output data structure, first
-!--   check if the variable for the respective surface type is defined.
-!--   If a variable is not defined, skip the block and increment the counter
-!--   variable by the number of surface elements of this type. Usually this
-!--   is zero, however, there might be the situation that e.g. urban surfaces
-!--   are defined but the respective variable is not allocated for this surface
-!--   type. To write the data on the exact position, increment the counter.
-      IF ( ALLOCATED( var_def_h0 ) )  THEN
-         DO  m = 1, surf_def_h(0)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_h(0)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_def_h(0)%frac(m,:) *              &
-                                             var_def_h0(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_h(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_def_h1 ) )  THEN
-         DO  m = 1, surf_def_h(1)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_h(1)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_def_h(1)%frac(m,:) *              &
-                                             var_def_h1(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_h(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_h ) )  THEN
-         DO  m = 1, surf_lsm_h%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_lsm_h%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_lsm_h%frac(m,:) *                 &
-                                             var_lsm_h(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_h%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_h ) )  THEN
-         DO  m = 1, surf_usm_h%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_usm_h%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_usm_h%frac(m,:) *                 &
-                                             var_usm_h(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_h%ns
-      ENDIF
-!
-!--   Write northward-facing
-      IF ( ALLOCATED( var_def_v0 ) )  THEN
-         DO  m = 1, surf_def_v(0)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_v(0)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_def_v(0)%frac(m,:) *              &
-                                             var_def_v0(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v0 ) )  THEN
-         DO  m = 1, surf_lsm_v(0)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_lsm_v(0)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_lsm_v(0)%frac(m,:) *              &
-                                             var_lsm_v0(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(0)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v0 ) )  THEN
-         DO  m = 1, surf_usm_v(0)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_usm_v(0)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_usm_v(0)%frac(m,:) *              &
-                                             var_usm_v0(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(0)%ns
-      ENDIF
-!
-!--   Write southward-facing
-      IF ( ALLOCATED( var_def_v1 ) )  THEN
-         DO  m = 1, surf_def_v(1)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_v(1)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_def_v(1)%frac(m,:) *                   &
-                                             var_def_v1(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v1 ) )  THEN
-         DO  m = 1, surf_lsm_v(1)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_lsm_v(1)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_lsm_v(1)%frac(m,:) *              &
-                                             var_lsm_v1(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(1)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v1 ) )  THEN
-         DO  m = 1, surf_usm_v(1)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_usm_v(1)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_usm_v(1)%frac(m,:) *              &
-                                             var_usm_v1(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(1)%ns
-      ENDIF
-!
-!--   Write eastward-facing
-      IF ( ALLOCATED( var_def_v2 ) )  THEN
-         DO  m = 1, surf_def_v(2)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_v(2)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_def_v(2)%frac(m,:) *              &
-                                             var_def_v2(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(2)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v2 ) )  THEN
-         DO  m = 1, surf_lsm_v(2)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_lsm_v(2)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_lsm_v(2)%frac(m,:) *              &
-                                             var_lsm_v2(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(2)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v2 ) )  THEN
-         DO  m = 1, surf_usm_v(2)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_usm_v(2)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_usm_v(2)%frac(m,:) *              &
-                                             var_usm_v2(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(2)%ns
-      ENDIF
-!
-!--   Write westward-facing
-      IF ( ALLOCATED( var_def_v3 ) )  THEN
-         DO  m = 1, surf_def_v(3)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_def_v(3)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_def_v(3)%frac(m,:) *              &
-                                             var_def_v3(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_def_v(3)%ns
-      ENDIF
-      IF ( ALLOCATED( var_lsm_v3 ) )  THEN
-         DO  m = 1, surf_lsm_v(3)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_lsm_v(3)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_lsm_v(3)%frac(m,:) *              &
-                                             var_lsm_v3(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_lsm_v(3)%ns
-      ENDIF
-      IF ( ALLOCATED( var_usm_v3 ) )  THEN
-         DO  m = 1, surf_usm_v(3)%ns
-            n_surf                   = n_surf + 1
-            k                        = surf_usm_v(3)%k(m)
-            surfaces%var_out(n_surf) = SUM ( surf_usm_v(3)%frac(m,:) *              &
-                                             var_usm_v3(m,:) ) * conversion_factor(k)
-         ENDDO
-      ELSE
-         n_surf = n_surf + surf_usm_v(3)%ns
-      ENDIF
-
-   END SUBROUTINE surface_data_output_collect_2d
-
-!------------------------------------------------------------------------------!
+!> Collect the surface data from different types and different orientation for properties which are
+!> defined using tile approach.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_collect_2d( var_def_h0, var_def_h1, var_lsm_h, var_usm_h,          &
+                                            var_def_v0, var_lsm_v0, var_usm_v0, var_def_v1,        &
+                                            var_lsm_v1, var_usm_v1, var_def_v2, var_lsm_v2,        &
+                                            var_usm_v2, var_def_v3, var_lsm_v3, var_usm_v3, fac )
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  k       !< height index of surface element
+    INTEGER(iwp) ::  m       !< running index for surface elements
+    INTEGER(iwp) ::  n_surf  !< running index for surface elements
+
+    REAL(wp), DIMENSION(:), OPTIONAL                  ::  fac                !< passed output conversion factor for heatflux output
+    REAL(wp), DIMENSION(nzb:nzt+1)                    ::  conversion_factor  !< effective array for output conversion factor
+
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_h0  !< output variable at upward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_h1  !< output variable at downward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_h   !< output variable at upward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_h   !< output variable at upward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v0  !< output variable at northward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v1  !< output variable at southward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v2  !< output variable at eastward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_def_v3  !< output variable at westward-facing default-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v0  !< output variable at northward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v1  !< output variable at southward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v2  !< output variable at eastward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_lsm_v3  !< output variable at westward-facing natural-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v0  !< output variable at northward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v1  !< output variable at southward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v2  !< output variable at eastward-facing urban-type surfaces
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE, INTENT(IN) ::  var_usm_v3  !< output variable at westward-facing urban-type surfaces
+
+!
+!-- Set conversion factor to one if not present
+    IF ( .NOT. PRESENT( fac ) )  THEN
+       conversion_factor = 1.0_wp
+    ELSE
+       conversion_factor = fac
+    ENDIF
+!
+!-- Set counter variable to zero before the variable is written to the output array.
+    n_surf = 0
+!
+!-- Write the horizontal surfaces.
+!-- Before each variable is written to the output data structure, first check if the variable
+!-- for the respective surface type is defined. If a variable is not defined, skip the block and
+!-- increment the counter variable by the number of surface elements of this type. Usually this is
+!-- zero, however, there might be the situation that e.g. urban surfaces are defined but the
+!-- respective variable is not allocated for this surface type. To write the data on the exact
+!-- position, increment the counter.
+    IF ( ALLOCATED( var_def_h0 ) )  THEN
+       DO  m = 1, surf_def_h(0)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_h(0)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_def_h(0)%frac(m,:) * var_def_h0(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_h(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_def_h1 ) )  THEN
+       DO  m = 1, surf_def_h(1)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_h(1)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_def_h(1)%frac(m,:) * var_def_h1(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_h(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_h ) )  THEN
+       DO  m = 1, surf_lsm_h%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_lsm_h%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_lsm_h%frac(m,:) * var_lsm_h(m,:) ) *               &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_h%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_h ) )  THEN
+       DO  m = 1, surf_usm_h%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_usm_h%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_usm_h%frac(m,:) * var_usm_h(m,:) )                 &
+                                     * conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_h%ns
+    ENDIF
+!
+!-- Write northward-facing
+    IF ( ALLOCATED( var_def_v0 ) )  THEN
+       DO  m = 1, surf_def_v(0)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_v(0)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_def_v(0)%frac(m,:) * var_def_v0(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v0 ) )  THEN
+       DO  m = 1, surf_lsm_v(0)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_lsm_v(0)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_lsm_v(0)%frac(m,:) * var_lsm_v0(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(0)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v0 ) )  THEN
+       DO  m = 1, surf_usm_v(0)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_usm_v(0)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_usm_v(0)%frac(m,:) * var_usm_v0(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(0)%ns
+    ENDIF
+!
+!-- Write southward-facing
+    IF ( ALLOCATED( var_def_v1 ) )  THEN
+       DO  m = 1, surf_def_v(1)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_v(1)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_def_v(1)%frac(m,:) * var_def_v1(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v1 ) )  THEN
+       DO  m = 1, surf_lsm_v(1)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_lsm_v(1)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_lsm_v(1)%frac(m,:) * var_lsm_v1(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(1)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v1 ) )  THEN
+       DO  m = 1, surf_usm_v(1)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_usm_v(1)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_usm_v(1)%frac(m,:) * var_usm_v1(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(1)%ns
+    ENDIF
+!
+!-- Write eastward-facing
+    IF ( ALLOCATED( var_def_v2 ) )  THEN
+       DO  m = 1, surf_def_v(2)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_v(2)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_def_v(2)%frac(m,:) * var_def_v2(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(2)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v2 ) )  THEN
+       DO  m = 1, surf_lsm_v(2)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_lsm_v(2)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_lsm_v(2)%frac(m,:) * var_lsm_v2(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(2)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v2 ) )  THEN
+       DO  m = 1, surf_usm_v(2)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_usm_v(2)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_usm_v(2)%frac(m,:) * var_usm_v2(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(2)%ns
+    ENDIF
+!
+!-- Write westward-facing
+    IF ( ALLOCATED( var_def_v3 ) )  THEN
+       DO  m = 1, surf_def_v(3)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_def_v(3)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_def_v(3)%frac(m,:) * var_def_v3(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_def_v(3)%ns
+    ENDIF
+    IF ( ALLOCATED( var_lsm_v3 ) )  THEN
+       DO  m = 1, surf_lsm_v(3)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_lsm_v(3)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_lsm_v(3)%frac(m,:) * var_lsm_v3(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_lsm_v(3)%ns
+    ENDIF
+    IF ( ALLOCATED( var_usm_v3 ) )  THEN
+       DO  m = 1, surf_usm_v(3)%ns
+          n_surf                   = n_surf + 1
+          k                        = surf_usm_v(3)%k(m)
+          surfaces%var_out(n_surf) = SUM ( surf_usm_v(3)%frac(m,:) * var_usm_v3(m,:) ) *           &
+                                     conversion_factor(k)
+       ENDDO
+    ELSE
+       n_surf = n_surf + surf_usm_v(3)%ns
+    ENDIF
+
+ END SUBROUTINE surface_data_output_collect_2d
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Parin for output of surface parameters
-!------------------------------------------------------------------------------!
-    SUBROUTINE surface_data_output_parin
-
-       IMPLICIT NONE
-
-       CHARACTER (LEN=80) ::  line  !< dummy string that contains the current line of the parameter file
-
-
-       NAMELIST /surface_data_output_parameters/                               &
-                                  averaging_interval_surf, data_output_surf,   &
-                                  dt_dosurf, dt_dosurf_av,                     &
-                                  skip_time_dosurf, skip_time_dosurf_av,       &
-                                  to_netcdf, to_vtk
-
-       line = ' '
-
-!
-!--    Try to find the namelist
-       REWIND ( 11 )
-       line = ' '
-       DO WHILE ( INDEX( line, '&surface_data_output_parameters' ) == 0 )
-          READ ( 11, '(A)', END=14 )  line
-       ENDDO
-       BACKSPACE ( 11 )
-
-!
-!--    Read namelist
-       READ ( 11, surface_data_output_parameters, ERR = 10 )
-!
-!--    Set flag that indicates that surface data output is switched on
-       surface_output = .TRUE.
-       GOTO 14
-
- 10    BACKSPACE( 11 )
-       READ( 11 , '(A)') line
-       CALL parin_fail_message( 'surface_data_output_parameters', line )
-
- 14    CONTINUE
-
-
-    END SUBROUTINE surface_data_output_parin
-
-
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_parin
+
+    IMPLICIT NONE
+
+    CHARACTER (LEN=80) ::  line  !< dummy string that contains the current line of the parameter file
+
+
+    NAMELIST /surface_data_output_parameters/ averaging_interval_surf, data_output_surf,           &
+                                              dt_dosurf, dt_dosurf_av, skip_time_dosurf,           &
+                                              skip_time_dosurf_av, to_netcdf, to_vtk
+
+    line = ' '
+
+!
+!-- Try to find the namelist
+    REWIND ( 11 )
+    line = ' '
+    DO WHILE ( INDEX( line, '&surface_data_output_parameters' ) == 0 )
+       READ ( 11, '(A)', END=14 )  line
+    ENDDO
+    BACKSPACE ( 11 )
+
+!
+!-- Read namelist
+    READ ( 11, surface_data_output_parameters, ERR = 10 )
+!
+!-- Set flag that indicates that surface data output is switched on
+    surface_output = .TRUE.
+    GOTO 14
+
+ 10 BACKSPACE( 11 )
+    READ( 11 , '(A)') line
+    CALL parin_fail_message( 'surface_data_output_parameters', line )
+
+ 14 CONTINUE
+
+
+ END SUBROUTINE surface_data_output_parin
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
-!> Check the input parameters for consistency. Further pre-process the given
-!> output variables, i.e. separate them into average and non-average output
-!> variables and map them onto internal output array.
-!------------------------------------------------------------------------------!
-    SUBROUTINE surface_data_output_check_parameters
-
-       USE control_parameters,                                                 &
-           ONLY:  averaging_interval, dt_data_output, indoor_model,            &
-                  initializing_actions, message_string
-
-       USE pegrid,                                                             &
-           ONLY:  numprocs_previous_run
-
-       IMPLICIT NONE
-
-       CHARACTER(LEN=100) ::  trimvar !< dummy for single output variable
-       CHARACTER(LEN=100) ::  unit    !< dummy for unit of output variable
-
-       INTEGER(iwp) ::  av    !< id indicating average or non-average data output
-       INTEGER(iwp) ::  ilen  !< string length
-       INTEGER(iwp) ::  n_out !< running index for number of output variables
-!
-!--    Check if any output file type is selected
-       IF ( .NOT. to_vtk  .AND.  .NOT. to_netcdf )  THEN
-          WRITE( message_string, * )                                     &
-             'no output file type selected for surface-data output!&' // &
-             'Set at least either "to_vtk" or "to_netcdf" to .TRUE.'
-          CALL message( 'surface_data_output_check_parameters',          &
-                        'PA0662', 1, 2, 0, 6, 0 )
+!> Check the input parameters for consistency. Further pre-process the given output variables, i.e.
+!> separate them into average and non-average output variables and map them onto internal output
+!> array.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_check_parameters
+
+    USE control_parameters,                                                                        &
+        ONLY:  averaging_interval,                                                                 &
+               dt_data_output,                                                                     &
+               indoor_model,                                                                       &
+               initializing_actions,                                                               &
+               message_string
+
+    USE pegrid,                                                                                    &
+        ONLY:  numprocs_previous_run
+
+    IMPLICIT NONE
+
+    CHARACTER(LEN=100) ::  trimvar  !< dummy for single output variable
+    CHARACTER(LEN=100) ::  unit     !< dummy for unit of output variable
+
+    INTEGER(iwp) ::  av     !< id indicating average or non-average data output
+    INTEGER(iwp) ::  ilen   !< string length
+    INTEGER(iwp) ::  n_out  !< running index for number of output variables
+!
+!-- Check if any output file type is selected
+    IF ( .NOT. to_vtk  .AND.  .NOT. to_netcdf )  THEN
+       WRITE( message_string, * ) 'no output file type selected for surface-data output!&' //      &
+                                  'Set at least either "to_vtk" or "to_netcdf" to .TRUE.'
+       CALL message( 'surface_data_output_check_parameters', 'PA0662', 1, 2, 0, 6, 0 )
+    ENDIF
+!
+!-- Check the average interval
+    IF ( averaging_interval_surf == 9999999.9_wp )  THEN
+       averaging_interval_surf = averaging_interval
+    ENDIF
+!
+!-- Set the default data-output interval dt_data_output if necessary
+    IF ( dt_dosurf    == 9999999.9_wp )  dt_dosurf    = dt_data_output
+    IF ( dt_dosurf_av == 9999999.9_wp )  dt_dosurf_av = dt_data_output
+
+    IF ( averaging_interval_surf > dt_dosurf_av )  THEN
+       WRITE( message_string, * )  'averaging_interval_surf = ', averaging_interval_surf,          &
+                                   ' must be <= dt_dosurf_av = ', dt_dosurf_av
+       CALL message( 'surface_data_output_check_parameters', 'PA0536', 1, 2, 0, 6, 0 )
+    ENDIF
+
+#if ! defined( __netcdf4_parallel )
+!
+!-- Surface output via NetCDF requires parallel NetCDF
+    IF ( to_netcdf )  THEN
+       message_string = 'to_netcdf = .True. requires parallel NetCDF'
+       CALL message( 'surface_data_output_check_parameters', 'PA0116', 1, 2, 0, 6, 0 )
+    ENDIF
+#endif
+!
+!-- In case of parallel NetCDF output the output timestep must not be zero. This is because the
+!-- number of requiered output timesteps is pre-calculated, which is not possible with zero output
+!-- timestep.
+    IF ( netcdf_data_format > 4 )  THEN
+       IF ( dt_dosurf == 0.0_wp )  THEN
+          message_string = 'dt_dosurf = 0.0 while using a variable timestep and parallel ' //      &
+                           'netCDF4 is not allowed.'
+          CALL message( 'surface_data_output_check_parameters', 'PA0081', 1, 2, 0, 6, 0 )
        ENDIF
-!
-!--    Check the average interval
-       IF ( averaging_interval_surf == 9999999.9_wp )  THEN
-          averaging_interval_surf = averaging_interval
+
+       IF ( dt_dosurf_av == 0.0_wp )  THEN
+          message_string = 'dt_dosurf_av = 0.0 while using a variable timestep and parallel ' //   &
+                           'netCDF4 is not allowed.'
+          CALL message( 'surface_data_output_check_parameters', 'PA0081', 1, 2, 0, 6, 0 )
        ENDIF
-!
-!--    Set the default data-output interval dt_data_output if necessary
-       IF ( dt_dosurf    == 9999999.9_wp )  dt_dosurf    = dt_data_output
-       IF ( dt_dosurf_av == 9999999.9_wp )  dt_dosurf_av = dt_data_output
-
-       IF ( averaging_interval_surf > dt_dosurf_av )  THEN
-          WRITE( message_string, * )  'averaging_interval_surf = ',            &
-                averaging_interval_surf, ' must be <= dt_dosurf_av = ',        &
-                dt_dosurf_av
-          CALL message( 'surface_data_output_check_parameters',                &
-                        'PA0536', 1, 2, 0, 6, 0 )
-       ENDIF
-
-#if ! defined( __netcdf4_parallel )
-!
-!--    Surface output via NetCDF requires parallel NetCDF
-       IF ( to_netcdf )  THEN
-          message_string = 'to_netcdf = .True. requires parallel NetCDF'
-          CALL message( 'surface_data_output_check_parameters',                &
-                        'PA0116', 1, 2, 0, 6, 0 )
-       ENDIF
-#endif
-!
-!--    In case of parallel NetCDF output the output timestep must not be zero.
-!--    This is because the number of requiered output timesteps is
-!--    pre-calculated, which is not possible with zero output timestep.
-       IF ( netcdf_data_format > 4 )  THEN
-          IF ( dt_dosurf == 0.0_wp )  THEN
-             message_string = 'dt_dosurf = 0.0 while using a ' //             &
-                              'variable timestep and parallel netCDF4 ' //    &
-                              'is not allowed.'
-             CALL message( 'surface_data_output_check_parameters', 'PA0081',  &
-                           1, 2, 0, 6, 0 )
-          ENDIF
-
-          IF ( dt_dosurf_av == 0.0_wp )  THEN
-             message_string = 'dt_dosurf_av = 0.0 while using a ' //          &
-                              'variable timestep and parallel netCDF4 ' //    &
-                              'is not allowed.'
-             CALL message( 'surface_data_output_check_parameters', 'PA0081',  &
-                           1, 2, 0, 6, 0 )
+    ENDIF
+
+!
+!-- In case of restart runs, check it the number of cores has been changed.
+!-- With surface output this is not allowed.
+    IF ( TRIM( initializing_actions ) == 'read_restart_data'  .AND.                                &
+         numprocs_previous_run /= numprocs ) THEN
+       message_string = 'The number of cores has been changed between restart runs. ' //           &
+                        'This is not allowed when surface data output is used.'
+        CALL message( 'surface_data_output_check_parameters', 'PA0585', 1, 2, 0, 6, 0 )
+    ENDIF
+!
+!-- Count number of output variables and separate output strings for average and non-average output
+!-- variables.
+    n_out = 0
+    DO WHILE ( data_output_surf(n_out+1)(1:1) /= ' ' )
+
+       n_out = n_out + 1
+       ilen = LEN_TRIM( data_output_surf(n_out) )
+       trimvar = TRIM( data_output_surf(n_out) )
+
+!
+!--    Check for data averaging
+       av = 0
+       IF ( ilen > 3 )  THEN
+          IF ( data_output_surf(n_out)(ilen-2:ilen) == '_av' )  THEN
+             trimvar = data_output_surf(n_out)(1:ilen-3)
+             av      = 1
           ENDIF
        ENDIF
 
-!
-!--   In case of restart runs, check it the number of cores has been changed.
-!--   With surface output this is not allowed.
-      IF ( TRIM( initializing_actions ) == 'read_restart_data'  .AND.          &
-           numprocs_previous_run /= numprocs ) THEN
-         message_string = 'The number of cores has been changed between ' //   &
-                          'restart runs. This is not allowed when surface ' // &
-                          'data output is used.'
-          CALL message( 'surface_data_output_check_parameters',                &
-                        'PA0585', 1, 2, 0, 6, 0 )
-      ENDIF
-!
-!--   Count number of output variables and separate output strings for
-!--   average and non-average output variables.
-      n_out = 0
-      DO WHILE ( data_output_surf(n_out+1)(1:1) /= ' ' )
-
-         n_out = n_out + 1
-         ilen = LEN_TRIM( data_output_surf(n_out) )
-         trimvar = TRIM( data_output_surf(n_out) )
-
-!
-!--      Check for data averaging
-         av = 0
-         IF ( ilen > 3 )  THEN
-            IF ( data_output_surf(n_out)(ilen-2:ilen) == '_av' )  THEN
-               trimvar = data_output_surf(n_out)(1:ilen-3)
-               av      = 1
-            ENDIF
-         ENDIF
-
-         dosurf_no(av) = dosurf_no(av) + 1
-         dosurf(av,dosurf_no(av)) = TRIM( trimvar )
-
-!
-!--      Check if all output variables are known and assign a unit
-         unit = 'not set'
-         SELECT CASE ( TRIM( trimvar ) )
-
-            CASE ( 'css', 'cssws', 'qsws_liq', 'qsws_soil', 'qsws_veg' )
-               message_string = TRIM( trimvar ) //                             &
-                             ' is not yet implemented in the surface output'
-               CALL message( 'surface_data_output_check_parameters',           &
-                             'PA0537', 1, 2, 0, 6, 0 )
-
-            CASE ( 'us', 'uvw1' )
-               unit = 'm/s'
-
-            CASE ( 'ss', 'qcs', 'ncs', 'qis', 'nis', 'qrs', 'nrs' )
-               unit = '1'
-
-            CASE ( 'z0', 'z0h', 'z0q', 'ol' )
-               unit = 'm'
-
-            CASE ( 'ts', 'theta1', 'thetav1', 'theta_surface', 'thetav_surface' )
-               unit = 'K'
-
-            CASE ( 'usws', 'vsws' )
-               unit = 'm2/s2'
-
-            CASE ( 'qcsws', 'ncsws', 'qisws', 'nisws', 'qrsws', 'nrsws', 'sasws' )
-
-            CASE ( 'shf' )
-               unit = 'K m/s'
-
-            CASE ( 'qsws' )
-               unit = 'kg/kg m/s'
-
-            CASE ( 'ssws' )
-               unit = 'kg/m2/s'
-
-            CASE ( 'qs', 'q_surface', 'qv1' )
-               unit = 'kg/kg'
-
-            CASE ( 'rad_net' )
-               unit = 'W/m2'
-
-            CASE ( 'rad_lw_in', 'rad_lw_out', 'rad_lw_dif', 'rad_lw_ref',     &
-                   'rad_lw_res' )
-               unit = 'W/m2'
-
-            CASE ( 'rad_sw_in', 'rad_sw_out', 'rad_sw_dif', 'rad_sw_ref',     &
-                   'rad_sw_res', 'rad_sw_dir' )
-               unit = 'W/m2'
-
-            CASE ( 'ghf' )
-               unit = 'W/m2'
-
-            CASE ( 'r_a', 'r_canopy', 'r_soil', 'r_s' )
-               unit = 's/m'
-
-            CASE ( 'waste_heat', 'im_hf' )
-               IF ( .NOT. indoor_model )  THEN
-                  message_string = TRIM( trimvar ) //                          &
-                             ' requires the indoor model'
-               CALL message( 'surface_data_output_check_parameters',           &
-                             'PA0588', 1, 2, 0, 6, 0 )
-               ENDIF
-
-               unit = 'W/m2'
-
-            CASE ( 'albedo', 'emissivity' )
-               unit = '1'
-
-            CASE DEFAULT
-               message_string = TRIM( trimvar ) //                             &
-                             ' is not part of the surface output'
-               CALL message( 'surface_data_output_check_parameters',           &
-                             'PA0538', 1, 2, 0, 6, 0 )
-         END SELECT
-
-         dosurf_unit(av,dosurf_no(av)) = unit
-
-       ENDDO
-
-    END SUBROUTINE surface_data_output_check_parameters
-
-
-!------------------------------------------------------------------------------!
+       dosurf_no(av) = dosurf_no(av) + 1
+       dosurf(av,dosurf_no(av)) = TRIM( trimvar )
+
+!
+!--    Check if all output variables are known and assign a unit
+       unit = 'not set'
+       SELECT CASE ( TRIM( trimvar ) )
+
+          CASE ( 'css', 'cssws', 'qsws_liq', 'qsws_soil', 'qsws_veg' )
+             message_string = TRIM( trimvar ) // ' is not yet implemented in the surface output'
+             CALL message( 'surface_data_output_check_parameters', 'PA0537', 1, 2, 0, 6, 0 )
+
+          CASE ( 'us', 'uvw1' )
+             unit = 'm/s'
+
+          CASE ( 'ss', 'qcs', 'ncs', 'qis', 'nis', 'qrs', 'nrs' )
+             unit = '1'
+
+          CASE ( 'z0', 'z0h', 'z0q', 'ol' )
+             unit = 'm'
+
+          CASE ( 'ts', 'theta1', 'thetav1', 'theta_surface', 'thetav_surface' )
+             unit = 'K'
+
+          CASE ( 'usws', 'vsws' )
+             unit = 'm2/s2'
+
+          CASE ( 'qcsws', 'ncsws', 'qisws', 'nisws', 'qrsws', 'nrsws', 'sasws' )
+
+          CASE ( 'shf' )
+             unit = 'K m/s'
+
+          CASE ( 'qsws' )
+             unit = 'kg/kg m/s'
+
+          CASE ( 'ssws' )
+             unit = 'kg/m2/s'
+
+          CASE ( 'qs', 'q_surface', 'qv1' )
+             unit = 'kg/kg'
+
+          CASE ( 'rad_net' )
+             unit = 'W/m2'
+
+          CASE ( 'rad_lw_in', 'rad_lw_out', 'rad_lw_dif', 'rad_lw_ref', 'rad_lw_res' )
+             unit = 'W/m2'
+
+          CASE ( 'rad_sw_in', 'rad_sw_out', 'rad_sw_dif', 'rad_sw_ref', 'rad_sw_res', 'rad_sw_dir' )
+             unit = 'W/m2'
+
+          CASE ( 'ghf' )
+             unit = 'W/m2'
+
+          CASE ( 'r_a', 'r_canopy', 'r_soil', 'r_s' )
+             unit = 's/m'
+
+          CASE ( 'waste_heat', 'im_hf' )
+             IF ( .NOT. indoor_model )  THEN
+                message_string = TRIM( trimvar ) // ' requires the indoor model'
+             CALL message( 'surface_data_output_check_parameters', 'PA0588', 1, 2, 0, 6, 0 )
+             ENDIF
+
+             unit = 'W/m2'
+
+          CASE ( 'albedo', 'emissivity' )
+             unit = '1'
+
+          CASE DEFAULT
+             message_string = TRIM( trimvar ) // ' is not part of the surface output'
+             CALL message( 'surface_data_output_check_parameters', 'PA0538', 1, 2, 0, 6, 0 )
+       END SELECT
+
+       dosurf_unit(av,dosurf_no(av)) = unit
+
+    ENDDO
+
+ END SUBROUTINE surface_data_output_check_parameters
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Last action.
-!------------------------------------------------------------------------------!
-    SUBROUTINE surface_data_output_last_action( av )
-
-      USE control_parameters,                                                  &
-          ONLY:  io_blocks, io_group
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_last_action( av )
+
+   USE control_parameters,                                                                         &
+       ONLY:  io_blocks,                                                                           &
+              io_group
 
 #if defined( __parallel )
-      USE pegrid,                                                              &
-          ONLY:  comm2d, ierr
+   USE pegrid,                                                                                     &
+       ONLY:  comm2d,                                                                              &
+              ierr
 #endif
 
-      IMPLICIT NONE
-
-      INTEGER(iwp) ::  av     !< id indicating average or non-average data output
-      INTEGER(iwp) ::  i      !< loop index
-
-!
-!--   Return, if nothing to output
-      IF ( dosurf_no(av) == 0 )  RETURN
-!
-!--   If output to VTK files is enabled, check if files are open and write
-!--   an end-of-file statement.
-      IF ( to_vtk )  THEN
-         CALL check_open( 25+av )
-!
-!--      Write time coordinate
-         DO  i = 0, io_blocks-1
-            IF ( i == io_group )  THEN
-               WRITE ( 25+av )  LEN_TRIM( 'END' )
-               WRITE ( 25+av )  'END'
-            ENDIF
+   IMPLICIT NONE
+
+   INTEGER(iwp) ::  av  !< id indicating average or non-average data output
+   INTEGER(iwp) ::  i   !< loop index
+
+!
+!--Return, if nothing to output
+   IF ( dosurf_no(av) == 0 )  RETURN
+!
+!--If output to VTK files is enabled, check if files are open and write an end-of-file statement.
+   IF ( to_vtk )  THEN
+      CALL check_open( 25 + av )
+!
+!--   Write time coordinate
+      DO  i = 0, io_blocks - 1
+         IF ( i == io_group )  THEN
+            WRITE ( 25 + av )  LEN_TRIM( 'END' )
+            WRITE ( 25 + av )  'END'
+         ENDIF
 #if defined( __parallel )
-            CALL MPI_BARRIER( comm2d, ierr )
+         CALL MPI_BARRIER( comm2d, ierr )
 #endif
-         ENDDO
-      ENDIF
-
-    END SUBROUTINE surface_data_output_last_action
-
-
-!------------------------------------------------------------------------------!
+      ENDDO
+   ENDIF
+
+ END SUBROUTINE surface_data_output_last_action
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific global restart data (Fortran binary format).
-!------------------------------------------------------------------------------!
-    SUBROUTINE surface_data_output_rrd_global_ftn( found )
-
-
-       USE control_parameters,                                                 &
-           ONLY: length, restart_string
-
-       IMPLICIT NONE
-
-       LOGICAL, INTENT(OUT)  ::  found !< flag indicating if variable was found
-
-       found = .TRUE.
-
-       SELECT CASE ( restart_string(1:length) )
-
-          CASE ( 'average_count_surf' )
-             READ ( 13 )  average_count_surf
-
-          CASE DEFAULT
-
-             found = .FALSE.
-
-       END SELECT
-
-
-    END SUBROUTINE surface_data_output_rrd_global_ftn
-
-
-!------------------------------------------------------------------------------!
+!---------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_rrd_global_ftn( found )
+
+
+    USE control_parameters,                                                                        &
+        ONLY: length,                                                                              &
+              restart_string
+
+    IMPLICIT NONE
+
+    LOGICAL, INTENT(OUT) ::  found  !< flag indicating if variable was found
+
+    found = .TRUE.
+
+    SELECT CASE ( restart_string(1:length) )
+
+       CASE ( 'average_count_surf' )
+          READ ( 13 )  average_count_surf
+
+       CASE DEFAULT
+
+          found = .FALSE.
+
+    END SELECT
+
+
+ END SUBROUTINE surface_data_output_rrd_global_ftn
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific global restart data (MPI-IO).
-!------------------------------------------------------------------------------!
-    SUBROUTINE surface_data_output_rrd_global_mpi
-
-       CALL rrd_mpi_io( 'average_count_surf', average_count_surf )
-
-    END SUBROUTINE surface_data_output_rrd_global_mpi
-
-
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_rrd_global_mpi
+
+    CALL rrd_mpi_io( 'average_count_surf', average_count_surf )
+
+ END SUBROUTINE surface_data_output_rrd_global_mpi
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific local restart data arrays (Fortran binary format).
-!------------------------------------------------------------------------------!
-    SUBROUTINE surface_data_output_rrd_local_ftn( found )
-
-
-       USE control_parameters,                                                 &
-           ONLY: length, restart_string
-
-       IMPLICIT NONE
-
-       LOGICAL, INTENT(OUT)  ::  found
-
-
-       found = .TRUE.
-
-       SELECT CASE ( restart_string(1:length) )
-
-          CASE ( 'surfaces%var_av' )
-             READ ( 13 )  surfaces%var_av
-
-          CASE DEFAULT
-
-             found = .FALSE.
-
-          END SELECT
-
-
-    END SUBROUTINE surface_data_output_rrd_local_ftn
-
-
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_rrd_local_ftn( found )
+
+
+    USE control_parameters,                                                                        &
+        ONLY: length,                                                                              &
+              restart_string
+
+    IMPLICIT NONE
+
+    LOGICAL, INTENT(OUT) ::  found
+
+
+    found = .TRUE.
+
+    SELECT CASE ( restart_string(1:length) )
+
+       CASE ( 'surfaces%var_av' )
+          READ ( 13 )  surfaces%var_av
+
+       CASE DEFAULT
+
+          found = .FALSE.
+
+       END SELECT
+
+
+ END SUBROUTINE surface_data_output_rrd_local_ftn
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Read module-specific local restart data arrays (MPI-IO).
-!------------------------------------------------------------------------------!
-    SUBROUTINE surface_data_output_rrd_local_mpi
-
-       IMPLICIT NONE
-
-       LOGICAL ::  array_found  !<
-
-
-       CALL rd_mpi_io_check_array( 'surfaces%var_av' , found = array_found )
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_rrd_local_mpi
+
+    IMPLICIT NONE
+
+    LOGICAL ::  array_found  !<
+
+
+    CALL rd_mpi_io_check_array( 'surfaces%var_av' , found = array_found )
 
 !> does not work this way: surface%var_av has non-standard dimensions
-!       IF ( array_found )  THEN
-!          IF ( .NOT. ALLOCATED( surfaces%var_av ) )  ALLOCATE( ....... )
-!          CALL rrd_mpi_io( 'surfaces%var_av', surfaces%var_av )
-!       ENDIF
-
-    END SUBROUTINE surface_data_output_rrd_local_mpi
-
-
-!------------------------------------------------------------------------------!
+!    IF ( array_found )  THEN
+!       IF ( .NOT. ALLOCATED( surfaces%var_av ) )  ALLOCATE( ....... )
+!       CALL rrd_mpi_io( 'surfaces%var_av', surfaces%var_av )
+!    ENDIF
+
+ END SUBROUTINE surface_data_output_rrd_local_mpi
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> This routine writes the respective restart data.
-!------------------------------------------------------------------------------!
-    SUBROUTINE surface_data_output_wrd_global
-
-       IMPLICIT NONE
-
-       IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
-
-          CALL wrd_write_string( 'average_count_surf' )
-          WRITE ( 14 )  average_count_surf
-
-       ELSEIF ( restart_data_format_output(1:3) == 'mpi' )  THEN
-
-         CALL wrd_mpi_io( 'average_count_surf', average_count_surf )
-
-       ENDIF
-
-    END SUBROUTINE surface_data_output_wrd_global
-
-
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_wrd_global
+
+    IMPLICIT NONE
+
+    IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
+
+       CALL wrd_write_string( 'average_count_surf' )
+       WRITE ( 14 )  average_count_surf
+
+    ELSEIF ( restart_data_format_output(1:3) == 'mpi' )  THEN
+
+      CALL wrd_mpi_io( 'average_count_surf', average_count_surf )
+
+    ENDIF
+
+ END SUBROUTINE surface_data_output_wrd_global
+
+
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> This routine writes restart data which individual on each PE
-!------------------------------------------------------------------------------!
-    SUBROUTINE surface_data_output_wrd_local
-
-       IMPLICIT NONE
-
-       IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
-
-          IF ( ALLOCATED( surfaces%var_av ) )  THEN
-             CALL wrd_write_string( 'surfaces%var_av' )
-             WRITE ( 14 )  surfaces%var_av
-          ENDIF
-
-       ELSEIF ( restart_data_format_output(1:3) == 'mpi' )  THEN
-
-          IF ( ALLOCATED( surfaces%var_av ) )  CALL wrd_mpi_io( 'surfaces%var_av', surfaces%var_av )
-
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE surface_data_output_wrd_local
+
+    IMPLICIT NONE
+
+    IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
+
+       IF ( ALLOCATED( surfaces%var_av ) )  THEN
+          CALL wrd_write_string( 'surfaces%var_av' )
+          WRITE ( 14 )  surfaces%var_av
        ENDIF
 
-    END SUBROUTINE surface_data_output_wrd_local
+    ELSEIF ( restart_data_format_output(1:3) == 'mpi' )  THEN
+
+       IF ( ALLOCATED( surfaces%var_av ) )  CALL wrd_mpi_io( 'surfaces%var_av', surfaces%var_av )
+
+    ENDIF
+
+ END SUBROUTINE surface_data_output_wrd_local
 
 
