Changeset 3736 for palm


Ignore:
Timestamp:
Feb 12, 2019 12:57:51 PM (5 years ago)
Author:
gronemeier
Message:

Add azimuth and zenith to output file; set long-name attributes; clean-up coding layout (surface_data_output_mod)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SOURCE/surface_data_output_mod.f90

    r3735 r3736  
    2525! -----------------
    2626! $Id$
     27! Add azimuth and zenith to output file; set long-name attributes;
     28! clean-up coding layout
     29!
     30! 3735 2019-02-12 09:52:40Z dom_dwd_user
    2731! - Split initialization into initialization of arrays and further initialization
    2832!   in order to enable reading of restart data.
    2933! - Consider restarts in surface data averaging.
    3034! - Correct error message numbers
    31 ! 
     35!
    3236! 3731 2019-02-11 13:06:27Z suehring
    3337! Bugfix: add cpp options
    34 ! 
     38!
    3539! 3727 2019-02-08 14:52:10Z gronemeier
    3640! Enable NetCDF output for surface data (suehring, gronemeier)
    37 ! 
     41!
    3842! 3691 2019-01-23 09:57:04Z suehring
    39 ! Add output of surface-parallel flow speed 
    40 ! 
     43! Add output of surface-parallel flow speed
     44!
    4145! 3648 2019-01-02 16:35:46Z suehring
    4246! Rename module and subroutines
    43 ! 
     47!
    4448! 3646 2018-12-28 17:58:49Z kanani
    4549! Bugfix: use time_since_reference_point instead of simulated_time (relevant
    4650! when using wall/soil spinup)
    47 ! 
     51!
    4852! 3614 2018-12-10 07:05:46Z raasch
    4953! unused variables removed
    50 ! 
     54!
    5155! 3572 2018-11-28 11:40:28Z suehring
    5256! Added short- and longwave radiation flux arrays (e.g. diffuse, direct,
    5357! reflected, resedual) for all surfaces (M. Salim)
    54 ! 
     58!
    5559! 3494 2018-11-06 14:51:27Z suehring
    56 ! Bugfix in gathering surface data from different types and orientation. 
     60! Bugfix in gathering surface data from different types and orientation.
    5761! Output of total number of surfaces and vertices added.
    5862! String length is output, for more convinient post-processing.
    5963! Last actions added.
    60 ! 
     64!
    6165! 3483 2018-11-02 14:19:26Z raasch
    6266! bugfix: missed directives for MPI added
    63 ! 
     67!
    6468! 3421 2018-10-24 18:39:32Z gronemeier
    6569! Add output variables
     
    7781! ------------
    7882!> Generate output for surface data.
    79 !> 
    80 !> @todo Create namelist file for post-processing tool. 
     83!>
     84!> @todo Create namelist file for post-processing tool.
    8185!------------------------------------------------------------------------------!
    8286
     
    8791   USE arrays_3d,                                                              &
    8892       ONLY:  zu, zw
    89        
     93
    9094   USE control_parameters,                                                     &
    9195       ONLY:  coupling_char, data_output_during_spinup, end_time,              &
    9296              message_string, run_description_header, simulated_time_at_begin, &
    9397              spinup_time, surface_output
    94        
     98
    9599   USE grid_variables,                                                         &
    96100       ONLY: dx,dy
    97        
     101
    98102   USE indices,                                                                &
    99103       ONLY: nxl, nxr, nys, nyn, nzb, nzt
    100        
     104
    101105#if defined( __netcdf )
    102106   USE NETCDF
     
    109113       ONLY:  netcdf_create_att, netcdf_create_dim, netcdf_create_file,        &
    110114              netcdf_create_global_atts, netcdf_create_var, netcdf_handle_error
    111        
     115
    112116   USE pegrid
    113        
     117
    114118   USE surface_mod,                                                            &
    115119       ONLY:  surf_def_h, surf_def_v, surf_lsm_h, surf_lsm_v,                  &
     
    119123
    120124   TYPE surf_out                      !< data structure which contains all surfaces elements of all types on subdomain
    121    
     125
    122126      INTEGER(iwp) ::  ns             !< number of surface elements on subdomain
    123127      INTEGER(iwp) ::  ns_total       !< total number of surface elements
    124128      INTEGER(iwp) ::  npoints        !< number of points / vertices which define a surface element (on subdomain)
    125129      INTEGER(iwp) ::  npoints_total  !< total number of points / vertices which define a surface element
    126      
     130
    127131      INTEGER(iwp), DIMENSION(:), ALLOCATABLE   ::  s        !< coordinate for NetCDF output, number of the surface element
    128      
    129       REAL(wp) ::  fillvalue = -9999.9_wp !< fillvalue for surface elements which are not defined
    130      
    131       REAL(wp), DIMENSION(:), ALLOCATABLE   ::  azimuth  !< azimuth orientation coordinate for NetCDF output 
    132       REAL(wp), DIMENSION(:), ALLOCATABLE   ::  es_utm   !< E-UTM coordinate for NetCDF output 
    133       REAL(wp), DIMENSION(:), ALLOCATABLE   ::  ns_utm   !< E-UTM coordinate for NetCDF output 
    134       REAL(wp), DIMENSION(:), ALLOCATABLE   ::  xs       !< x-coordinate for NetCDF output 
    135       REAL(wp), DIMENSION(:), ALLOCATABLE   ::  ys       !< y-coordinate for NetCDF output 
    136       REAL(wp), DIMENSION(:), ALLOCATABLE   ::  zs       !< z-coordinate for NetCDF output 
    137       REAL(wp), DIMENSION(:), ALLOCATABLE   ::  zenith   !< zenith orientation coordinate for NetCDF output 
     132
     133      REAL(wp) ::  fillvalue = -9999.0_wp !< fillvalue for surface elements which are not defined
     134
     135      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  azimuth  !< azimuth orientation coordinate for NetCDF output
     136      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  es_utm   !< E-UTM coordinate for NetCDF output
     137      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  ns_utm   !< E-UTM coordinate for NetCDF output
     138      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  xs       !< x-coordinate for NetCDF output
     139      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  ys       !< y-coordinate for NetCDF output
     140      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  zs       !< z-coordinate for NetCDF output
     141      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  zenith   !< zenith orientation coordinate for NetCDF output
    138142      REAL(wp), DIMENSION(:), ALLOCATABLE   ::  var_out  !< output variables
    139143      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  var_av   !< variables used for averaging
     
    141145      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  polygons !< polygon data of a surface element
    142146   END TYPE surf_out
    143    
     147
    144148   CHARACTER(LEN=100), DIMENSION(300)       ::  data_output_surf = ' '  !< namelist variable which describes the output variables
    145    CHARACTER(LEN=100), DIMENSION(0:1,300)   ::  dosurf = ' '            !< internal variable which describes the output variables 
     149   CHARACTER(LEN=100), DIMENSION(0:1,300)   ::  dosurf = ' '            !< internal variable which describes the output variables
    146150                                                                        !<  and separates averaged from non-averaged output
    147151   CHARACTER(LEN=100), DIMENSION(0:1,300)   ::  dosurf_unit = ' '       !< internal variable which holds the unit of the given output variable
    148    
     152
    149153   INTEGER(iwp) ::  average_count_surf = 0   !< number of ensemble members used for averaging
    150154   INTEGER(iwp) ::  dosurf_no(0:1) = 0       !< number of surface output quantities
    151155
    152156   INTEGER(iwp) :: nc_stat                   !< error code for netcdf routines
    153    INTEGER(iwp), SAVE ::  oldmode            !< save old set-fill-mode of netcdf file (not needed, but required for routine call)
     157   INTEGER(iwp) ::  oldmode                  !< save old set-fill-mode of netcdf file (not needed, but required for routine call)
    154158
    155159   INTEGER(iwp), DIMENSION(0:1) ::  id_dim_s_surf         !< netcdf ID for dimension s
    156160   INTEGER(iwp), DIMENSION(0:1) ::  id_dim_time_surf      !< netcdf ID for dimension time
    157161   INTEGER(iwp), DIMENSION(0:1) ::  id_set_surf           !< netcdf ID for file
     162   INTEGER(iwp), DIMENSION(0:1) ::  id_var_azimuth_surf   !< netcdf ID for variable azimuth
    158163   INTEGER(iwp), DIMENSION(0:1) ::  id_var_etum_surf      !< netcdf ID for variable Es_UTM
    159164   INTEGER(iwp), DIMENSION(0:1) ::  id_var_nutm_surf      !< netcdf ID for variable Ns_UTM
     
    162167   INTEGER(iwp), DIMENSION(0:1) ::  id_var_xs_surf        !< netcdf ID for variable xs
    163168   INTEGER(iwp), DIMENSION(0:1) ::  id_var_ys_surf        !< netcdf ID for variable ys
     169   INTEGER(iwp), DIMENSION(0:1) ::  id_var_zenith_surf    !< netcdf ID for variable zenith
    164170   INTEGER(iwp), DIMENSION(0:1) ::  id_var_zs_surf        !< netcdf ID for variable zs
    165171   INTEGER(iwp), DIMENSION(0:1) ::  dosurf_time_count = 0 !< count of output time steps
    166172   INTEGER(iwp), DIMENSION(0:1) ::  ntdim_surf            !< number of output time steps
    167    
     173
    168174   INTEGER(iwp), DIMENSION(0:1,300) ::  id_var_dosurf     !< netcdf ID for output variables
    169175
    170176   LOGICAL :: first_output(0:1) = .FALSE.                 !< true if first output was already called
    171    LOGICAL :: to_netcdf = .TRUE.                          !< flag indicating parallel NetCDF output 
    172    LOGICAL :: to_vtk = .TRUE.                             !< flag indicating binary surface-data output that can be further 
     177   LOGICAL :: to_netcdf = .TRUE.                          !< flag indicating parallel NetCDF output
     178   LOGICAL :: to_vtk = .TRUE.                             !< flag indicating binary surface-data output that can be further
    173179                                                          !< processed to VTK format
    174180
     
    182188
    183189   TYPE(surf_out) ::  surfaces      !< variable which contains all required output information
    184    
     190
    185191   SAVE
    186192
     
    190196      MODULE PROCEDURE surface_data_output
    191197   END INTERFACE  surface_data_output
    192    
     198
    193199   INTERFACE  surface_data_output_averaging
    194200      MODULE PROCEDURE surface_data_output_averaging
    195201   END INTERFACE  surface_data_output_averaging
    196    
     202
    197203   INTERFACE  surface_data_output_check_parameters
    198204      MODULE PROCEDURE surface_data_output_check_parameters
    199205   END INTERFACE  surface_data_output_check_parameters
    200    
     206
    201207   INTERFACE  surface_data_output_init
    202208      MODULE PROCEDURE surface_data_output_init
    203209   END INTERFACE  surface_data_output_init
    204    
     210
    205211   INTERFACE  surface_data_output_init_arrays
    206212      MODULE PROCEDURE surface_data_output_init_arrays
    207213   END INTERFACE  surface_data_output_init_arrays
    208    
     214
    209215   INTERFACE  surface_data_output_last_action
    210216      MODULE PROCEDURE surface_data_output_last_action
    211217   END INTERFACE  surface_data_output_last_action
    212      
     218
    213219   INTERFACE  surface_data_output_parin
    214220      MODULE PROCEDURE surface_data_output_parin
    215221   END INTERFACE  surface_data_output_parin
    216    
     222
    217223   INTERFACE  surface_data_output_rrd_global
    218224      MODULE PROCEDURE surface_data_output_rrd_global
    219225   END INTERFACE  surface_data_output_rrd_global
    220    
     226
    221227   INTERFACE  surface_data_output_rrd_local
    222228      MODULE PROCEDURE surface_data_output_rrd_local
    223229   END INTERFACE  surface_data_output_rrd_local
    224    
     230
    225231   INTERFACE  surface_data_output_wrd_global
    226232      MODULE PROCEDURE surface_data_output_wrd_global
    227233   END INTERFACE  surface_data_output_wrd_global
    228    
     234
    229235   INTERFACE  surface_data_output_wrd_local
    230236      MODULE PROCEDURE surface_data_output_wrd_local
     
    250256! ------------
    251257!> This routine counts the number of surfaces on each core and allocates
    252 !> arrays. 
     258!> arrays.
    253259!------------------------------------------------------------------------------!
    254260   SUBROUTINE surface_data_output_init_arrays
    255    
     261
    256262      IMPLICIT NONE
    257263
     
    259265!--   Determine the number of surface elements on subdomain
    260266      surfaces%ns = surf_def_h(0)%ns + surf_lsm_h%ns + surf_usm_h%ns           & !horizontal upward-facing
    261                   + surf_def_h(1)%ns                                           & !horizontal downard-facing   
     267                  + surf_def_h(1)%ns                                           & !horizontal downard-facing
    262268                  + surf_def_v(0)%ns + surf_lsm_v(0)%ns + surf_usm_v(0)%ns     & !northward-facing
    263                   + surf_def_v(1)%ns + surf_lsm_v(1)%ns + surf_usm_v(1)%ns     & !southward-facing   
    264                   + surf_def_v(2)%ns + surf_lsm_v(2)%ns + surf_usm_v(2)%ns     & !westward-facing   
    265                   + surf_def_v(3)%ns + surf_lsm_v(3)%ns + surf_usm_v(3)%ns       !eastward-facing   
     269                  + surf_def_v(1)%ns + surf_lsm_v(1)%ns + surf_usm_v(1)%ns     & !southward-facing
     270                  + surf_def_v(2)%ns + surf_lsm_v(2)%ns + surf_usm_v(2)%ns     & !westward-facing
     271                  + surf_def_v(3)%ns + surf_lsm_v(3)%ns + surf_usm_v(3)%ns       !eastward-facing
    266272!
    267273!--    Determine the total number of surfaces in the model domain
     
    277283      surfaces%var_out = surfaces%fillvalue
    278284!
    279 !--   If there is an output of time average output variables, allocate the 
     285!--   If there is an output of time average output variables, allocate the
    280286!--   required array.
    281287      IF ( dosurf_no(1) > 0 )  THEN
     
    283289         surfaces%var_av = 0.0_wp
    284290      ENDIF
    285      
     291
    286292   END SUBROUTINE surface_data_output_init_arrays
    287  
    288  
     293
     294
    289295!------------------------------------------------------------------------------!
    290296! Description:
     
    294300!------------------------------------------------------------------------------!
    295301   SUBROUTINE surface_data_output_init
    296    
     302
    297303      IMPLICIT NONE
    298304
     
    311317      INTEGER(iwp) ::  point_index_count !< local counter variable for point index
    312318      INTEGER(iwp) ::  start_count       !< local start counter for the surface index
    313      
     319
    314320      INTEGER(iwp), DIMENSION(0:numprocs-1) :: num_points_on_pe   !< array which contains the number of points on all mpi ranks
    315321      INTEGER(iwp), DIMENSION(0:numprocs-1) :: num_surfaces_on_pe !< array which contains the number of surfaces on all mpi ranks
    316322      INTEGER(iwp), ALLOCATABLE, DIMENSION(:,:,:) ::  point_index !< dummy array used to check where the reference points for surface polygons are located
    317            
     323
    318324      REAL(wp) ::  az    !< azimuth angle, indicated the vertical orientation of a surface element
    319325      REAL(wp) ::  off_x !< grid offset in x-direction between the stored grid index and the actual wall
     
    323329
    324330!
    325 !--   If output to VTK format is enabled, initialize point and polygon data. 
    326 !--   In a first step, count the number of points which are defining 
     331!--   If output to VTK format is enabled, initialize point and polygon data.
     332!--   In a first step, count the number of points which are defining
    327333!--   the surfaces and the polygons.
    328334      IF ( to_vtk )  THEN
     
    340346               k = surf_def_h(0)%k(m) + surf_def_h(0)%koff
    341347!
    342 !--            Check if the vertices that define the surface element are already 
     348!--            Check if the vertices that define the surface element are already
    343349!--            defined, if not, increment the counter.
    344350               IF ( point_index(k,j,i) < 0 )  THEN
    345                   surfaces%npoints   = surfaces%npoints + 1   
     351                  surfaces%npoints   = surfaces%npoints + 1
    346352                  point_index(k,j,i) = surfaces%npoints - 1
    347353               ENDIF
    348354               IF ( point_index(k,j,i+1) < 0 )  THEN
    349                   surfaces%npoints     = surfaces%npoints + 1   
     355                  surfaces%npoints     = surfaces%npoints + 1
    350356                  point_index(k,j,i+1) = surfaces%npoints - 1
    351357               ENDIF
    352358               IF ( point_index(k,j+1,i+1) < 0 )  THEN
    353                   surfaces%npoints       = surfaces%npoints + 1   
     359                  surfaces%npoints       = surfaces%npoints + 1
    354360                  point_index(k,j+1,i+1) = surfaces%npoints - 1
    355361               ENDIF
    356362               IF ( point_index(k,j+1,i) < 0 )  THEN
    357                   surfaces%npoints     = surfaces%npoints + 1   
     363                  surfaces%npoints     = surfaces%npoints + 1
    358364                  point_index(k,j+1,i) = surfaces%npoints - 1
    359                ENDIF           
     365               ENDIF
    360366            ENDDO
    361367         ENDDO
     
    366372
    367373            IF ( point_index(k,j,i) < 0 )  THEN
    368                surfaces%npoints   = surfaces%npoints + 1   
     374               surfaces%npoints   = surfaces%npoints + 1
    369375               point_index(k,j,i) = surfaces%npoints - 1
    370376            ENDIF
    371377            IF ( point_index(k,j,i+1) < 0 )  THEN
    372                surfaces%npoints     = surfaces%npoints + 1   
     378               surfaces%npoints     = surfaces%npoints + 1
    373379               point_index(k,j,i+1) = surfaces%npoints - 1
    374380            ENDIF
    375381            IF ( point_index(k,j+1,i+1) < 0 )  THEN
    376                surfaces%npoints       = surfaces%npoints + 1   
     382               surfaces%npoints       = surfaces%npoints + 1
    377383               point_index(k,j+1,i+1) = surfaces%npoints - 1
    378384            ENDIF
    379385            IF ( point_index(k,j+1,i) < 0 )  THEN
    380                surfaces%npoints     = surfaces%npoints + 1   
     386               surfaces%npoints     = surfaces%npoints + 1
    381387               point_index(k,j+1,i) = surfaces%npoints - 1
    382             ENDIF   
     388            ENDIF
    383389         ENDDO
    384390         DO  m = 1, surf_usm_h%ns
     
    388394
    389395            IF ( point_index(k,j,i) < 0 )  THEN
    390                surfaces%npoints   = surfaces%npoints + 1   
     396               surfaces%npoints   = surfaces%npoints + 1
    391397               point_index(k,j,i) = surfaces%npoints - 1
    392398            ENDIF
    393399            IF ( point_index(k,j,i+1) < 0 )  THEN
    394                surfaces%npoints     = surfaces%npoints + 1   
     400               surfaces%npoints     = surfaces%npoints + 1
    395401               point_index(k,j,i+1) = surfaces%npoints - 1
    396402            ENDIF
    397403            IF ( point_index(k,j+1,i+1) < 0 )  THEN
    398                surfaces%npoints       = surfaces%npoints + 1   
     404               surfaces%npoints       = surfaces%npoints + 1
    399405               point_index(k,j+1,i+1) = surfaces%npoints - 1
    400406            ENDIF
    401407            IF ( point_index(k,j+1,i) < 0 )  THEN
    402                surfaces%npoints     = surfaces%npoints + 1   
     408               surfaces%npoints     = surfaces%npoints + 1
    403409               point_index(k,j+1,i) = surfaces%npoints - 1
    404             ENDIF     
     410            ENDIF
    405411         ENDDO
    406412!
     
    410416!
    411417!--            Determine the indices of the respective grid cell inside the
    412 !--            topography. Please note, j-index for north-facing surfaces 
    413 !--            ( l==0 ) is identical to the reference j-index outside the grid 
     418!--            topography. Please note, j-index for north-facing surfaces
     419!--            ( l==0 ) is identical to the reference j-index outside the grid
    414420!--            box. Equivalent for east-facing surfaces and i-index.
    415421               i = surf_def_v(l)%i(m) + MERGE( surf_def_v(l)%ioff, 0, l == 3 )
     
    419425!--            Lower left /front vertex
    420426               IF ( point_index(k,j,i) < 0 )  THEN
    421                   surfaces%npoints   = surfaces%npoints + 1   
     427                  surfaces%npoints   = surfaces%npoints + 1
    422428                  point_index(k,j,i) = surfaces%npoints - 1
    423                ENDIF 
     429               ENDIF
    424430!
    425431!--            Upper / lower right index for north- and south-facing surfaces
    426432               IF ( l == 0  .OR.  l == 1 )  THEN
    427433                  IF ( point_index(k,j,i+1) < 0 )  THEN
    428                      surfaces%npoints     = surfaces%npoints + 1   
     434                     surfaces%npoints     = surfaces%npoints + 1
    429435                     point_index(k,j,i+1) = surfaces%npoints - 1
    430                   ENDIF 
     436                  ENDIF
    431437                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
    432                      surfaces%npoints       = surfaces%npoints + 1   
     438                     surfaces%npoints       = surfaces%npoints + 1
    433439                     point_index(k+1,j,i+1) = surfaces%npoints - 1
    434440                  ENDIF
     
    437443               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
    438444                  IF ( point_index(k,j+1,i) < 0 )  THEN
    439                      surfaces%npoints     = surfaces%npoints + 1   
     445                     surfaces%npoints     = surfaces%npoints + 1
    440446                     point_index(k,j+1,i) = surfaces%npoints - 1
    441                   ENDIF 
     447                  ENDIF
    442448                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
    443                      surfaces%npoints       = surfaces%npoints + 1   
     449                     surfaces%npoints       = surfaces%npoints + 1
    444450                     point_index(k+1,j+1,i) = surfaces%npoints - 1
    445451                  ENDIF
     
    448454!--            Upper left / front vertex
    449455               IF ( point_index(k+1,j,i) < 0 )  THEN
    450                   surfaces%npoints     = surfaces%npoints + 1   
     456                  surfaces%npoints     = surfaces%npoints + 1
    451457                  point_index(k+1,j,i) = surfaces%npoints - 1
    452458               ENDIF
     
    459465!--            Lower left /front vertex
    460466               IF ( point_index(k,j,i) < 0 )  THEN
    461                   surfaces%npoints   = surfaces%npoints + 1   
     467                  surfaces%npoints   = surfaces%npoints + 1
    462468                  point_index(k,j,i) = surfaces%npoints - 1
    463                ENDIF 
     469               ENDIF
    464470!
    465471!--            Upper / lower right index for north- and south-facing surfaces
    466472               IF ( l == 0  .OR.  l == 1 )  THEN
    467473                  IF ( point_index(k,j,i+1) < 0 )  THEN
    468                      surfaces%npoints     = surfaces%npoints + 1   
     474                     surfaces%npoints     = surfaces%npoints + 1
    469475                     point_index(k,j,i+1) = surfaces%npoints - 1
    470                   ENDIF 
     476                  ENDIF
    471477                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
    472                      surfaces%npoints       = surfaces%npoints + 1   
     478                     surfaces%npoints       = surfaces%npoints + 1
    473479                     point_index(k+1,j,i+1) = surfaces%npoints - 1
    474480                  ENDIF
     
    477483               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
    478484                  IF ( point_index(k,j+1,i) < 0 )  THEN
    479                      surfaces%npoints     = surfaces%npoints + 1   
     485                     surfaces%npoints     = surfaces%npoints + 1
    480486                     point_index(k,j+1,i) = surfaces%npoints - 1
    481                   ENDIF 
     487                  ENDIF
    482488                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
    483                      surfaces%npoints       = surfaces%npoints + 1   
     489                     surfaces%npoints       = surfaces%npoints + 1
    484490                     point_index(k+1,j+1,i) = surfaces%npoints - 1
    485491                  ENDIF
     
    488494!--            Upper left / front vertex
    489495               IF ( point_index(k+1,j,i) < 0 )  THEN
    490                   surfaces%npoints     = surfaces%npoints + 1   
     496                  surfaces%npoints     = surfaces%npoints + 1
    491497                  point_index(k+1,j,i) = surfaces%npoints - 1
    492498               ENDIF
     
    500506!--            Lower left /front vertex
    501507               IF ( point_index(k,j,i) < 0 )  THEN
    502                   surfaces%npoints   = surfaces%npoints + 1   
     508                  surfaces%npoints   = surfaces%npoints + 1
    503509                  point_index(k,j,i) = surfaces%npoints - 1
    504                ENDIF 
     510               ENDIF
    505511!
    506512!--            Upper / lower right index for north- and south-facing surfaces
    507513               IF ( l == 0  .OR.  l == 1 )  THEN
    508514                  IF ( point_index(k,j,i+1) < 0 )  THEN
    509                      surfaces%npoints     = surfaces%npoints + 1   
     515                     surfaces%npoints     = surfaces%npoints + 1
    510516                     point_index(k,j,i+1) = surfaces%npoints - 1
    511                   ENDIF 
     517                  ENDIF
    512518                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
    513                      surfaces%npoints       = surfaces%npoints + 1   
     519                     surfaces%npoints       = surfaces%npoints + 1
    514520                     point_index(k+1,j,i+1) = surfaces%npoints - 1
    515521                  ENDIF
     
    518524               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
    519525                  IF ( point_index(k,j+1,i) < 0 )  THEN
    520                      surfaces%npoints     = surfaces%npoints + 1   
     526                     surfaces%npoints     = surfaces%npoints + 1
    521527                     point_index(k,j+1,i) = surfaces%npoints - 1
    522                   ENDIF 
     528                  ENDIF
    523529                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
    524                      surfaces%npoints       = surfaces%npoints + 1   
     530                     surfaces%npoints       = surfaces%npoints + 1
    525531                     point_index(k+1,j+1,i) = surfaces%npoints - 1
    526532                  ENDIF
     
    529535!--            Upper left / front vertex
    530536               IF ( point_index(k+1,j,i) < 0 )  THEN
    531                   surfaces%npoints     = surfaces%npoints + 1   
     537                  surfaces%npoints     = surfaces%npoints + 1
    532538                  point_index(k+1,j,i) = surfaces%npoints - 1
    533539               ENDIF
     
    536542         ENDDO
    537543!
    538 !--      Allocate the number of points and polygons. Note, the number of polygons
    539 !--      is identical to the number of surfaces elements, whereas the number
    540 !--      of points (vertices), which define the polygons, can be larger.
     544!--      Allocate the number of points and polygons. Note, the number of
     545!--      polygons is identical to the number of surfaces elements, whereas the
     546!--      number of points (vertices), which define the polygons, can be larger.
    541547         ALLOCATE( surfaces%points(3,1:surfaces%npoints) )
    542548         ALLOCATE( surfaces%polygons(5,1:surfaces%ns)    )
    543549!
    544550!--      Note, PARAVIEW expects consecutively ordered points, in order to
    545 !--      unambiguously identify surfaces. 
     551!--      unambiguously identify surfaces.
    546552!--      Hence, all PEs should know where they start counting, depending on the
    547 !--      number of points on the other PE's with lower MPI rank. 
     553!--      number of points on the other PE's with lower MPI rank.
    548554#if defined( __parallel )
    549555         CALL MPI_ALLGATHER( surfaces%npoints, 1, MPI_INTEGER,                 &
     
    554560
    555561!
    556 !--      After the number of vertices is counted, repeat the loops and define the
    557 !--      vertices. Start with the horizontal default surfaces.
     562!--      After the number of vertices is counted, repeat the loops and define
     563!--      the vertices. Start with the horizontal default surfaces.
    558564!--      First, however, determine the offset where couting of points should be
    559565!--      started, which is the sum of points of all PE's with lower MPI rank.
     
    564570            i                 = i + 1
    565571         ENDDO
    566          
     572
    567573         surfaces%npoints = 0
    568574         point_index      = -1
    569575         npg              = 0
    570      
     576
    571577         DO  l = 0, 1
    572578            DO  m = 1, surf_def_h(0)%ns
    573579!
    574 !--            Determine the indices of the respective grid cell inside the 
     580!--            Determine the indices of the respective grid cell inside the
    575581!--            topography.
    576582               i = surf_def_h(0)%i(m) + surf_def_h(0)%ioff
     
    578584               k = surf_def_h(0)%k(m) + surf_def_h(0)%koff
    579585!
    580 !--            Check if the vertices that define the surface element are 
     586!--            Check if the vertices that define the surface element are
    581587!--            already defined, if not, increment the counter.
    582588               IF ( point_index(k,j,i) < 0 )  THEN
    583                   surfaces%npoints   = surfaces%npoints + 1   
     589                  surfaces%npoints   = surfaces%npoints + 1
    584590                  point_index(k,j,i) = point_index_count
    585                   point_index_count  = point_index_count + 1               
     591                  point_index_count  = point_index_count + 1
    586592                  surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
    587593                  surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
     
    589595               ENDIF
    590596               IF ( point_index(k,j,i+1) < 0 )  THEN
    591                   surfaces%npoints     = surfaces%npoints + 1   
     597                  surfaces%npoints     = surfaces%npoints + 1
    592598                  point_index(k,j,i+1) = point_index_count
    593                   point_index_count    = point_index_count + 1 
     599                  point_index_count    = point_index_count + 1
    594600                  surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
    595601                  surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
     
    597603               ENDIF
    598604               IF ( point_index(k,j+1,i+1) < 0 )  THEN
    599                   surfaces%npoints       = surfaces%npoints + 1   
     605                  surfaces%npoints       = surfaces%npoints + 1
    600606                  point_index(k,j+1,i+1) = point_index_count
    601                   point_index_count      = point_index_count + 1 
     607                  point_index_count      = point_index_count + 1
    602608                  surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
    603609                  surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
     
    605611               ENDIF
    606612               IF ( point_index(k,j+1,i) < 0 )  THEN
    607                   surfaces%npoints     = surfaces%npoints + 1   
     613                  surfaces%npoints     = surfaces%npoints + 1
    608614                  point_index(k,j+1,i) = point_index_count
    609                   point_index_count    = point_index_count + 1 
     615                  point_index_count    = point_index_count + 1
    610616                  surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
    611617                  surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
    612618                  surfaces%points(3,surfaces%npoints) = zw(k)
    613619               ENDIF
    614                
     620
    615621               npg                        = npg + 1
    616622               surfaces%polygons(1,npg)   = 4
     
    626632            k = surf_lsm_h%k(m) + surf_lsm_h%koff
    627633            IF ( point_index(k,j,i) < 0 )  THEN
    628                surfaces%npoints   = surfaces%npoints + 1   
     634               surfaces%npoints   = surfaces%npoints + 1
    629635               point_index(k,j,i) = point_index_count
    630                point_index_count  = point_index_count + 1 
     636               point_index_count  = point_index_count + 1
    631637               surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
    632638               surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
     
    634640            ENDIF
    635641            IF ( point_index(k,j,i+1) < 0 )  THEN
    636                surfaces%npoints     = surfaces%npoints + 1   
     642               surfaces%npoints     = surfaces%npoints + 1
    637643               point_index(k,j,i+1) = point_index_count
    638                point_index_count    = point_index_count + 1 
     644               point_index_count    = point_index_count + 1
    639645               surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
    640646               surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
     
    642648            ENDIF
    643649            IF ( point_index(k,j+1,i+1) < 0 )  THEN
    644                surfaces%npoints       = surfaces%npoints + 1   
     650               surfaces%npoints       = surfaces%npoints + 1
    645651               point_index(k,j+1,i+1) = point_index_count
    646                point_index_count      = point_index_count + 1 
     652               point_index_count      = point_index_count + 1
    647653               surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
    648654               surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
     
    650656            ENDIF
    651657            IF ( point_index(k,j+1,i) < 0 )  THEN
    652                surfaces%npoints     = surfaces%npoints + 1   
     658               surfaces%npoints     = surfaces%npoints + 1
    653659               point_index(k,j+1,i) = point_index_count
    654                point_index_count    = point_index_count + 1 
     660               point_index_count    = point_index_count + 1
    655661               surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
    656662               surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
    657663               surfaces%points(3,surfaces%npoints) = zw(k)
    658664            ENDIF
    659            
     665
    660666            npg                        = npg + 1
    661667            surfaces%polygons(1,npg)   = 4
     
    663669            surfaces%polygons(3,npg)   = point_index(k,j,i+1)
    664670            surfaces%polygons(4,npg)   = point_index(k,j+1,i+1)
    665             surfaces%polygons(5,npg)   = point_index(k,j+1,i) 
     671            surfaces%polygons(5,npg)   = point_index(k,j+1,i)
    666672         ENDDO
    667      
     673
    668674         DO  m = 1, surf_usm_h%ns
    669675            i = surf_usm_h%i(m) + surf_usm_h%ioff
    670676            j = surf_usm_h%j(m) + surf_usm_h%joff
    671677            k = surf_usm_h%k(m) + surf_usm_h%koff
    672      
     678
    673679            IF ( point_index(k,j,i) < 0 )  THEN
    674                surfaces%npoints   = surfaces%npoints + 1   
     680               surfaces%npoints   = surfaces%npoints + 1
    675681               point_index(k,j,i) = point_index_count
    676                point_index_count  = point_index_count + 1 
     682               point_index_count  = point_index_count + 1
    677683               surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
    678684               surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
     
    680686            ENDIF
    681687            IF ( point_index(k,j,i+1) < 0 )  THEN
    682                surfaces%npoints     = surfaces%npoints + 1   
     688               surfaces%npoints     = surfaces%npoints + 1
    683689               point_index(k,j,i+1) = point_index_count
    684                point_index_count    = point_index_count + 1 
     690               point_index_count    = point_index_count + 1
    685691               surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
    686692               surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
     
    688694            ENDIF
    689695            IF ( point_index(k,j+1,i+1) < 0 )  THEN
    690                surfaces%npoints       = surfaces%npoints + 1   
     696               surfaces%npoints       = surfaces%npoints + 1
    691697               point_index(k,j+1,i+1) = point_index_count
    692                point_index_count      = point_index_count + 1 
     698               point_index_count      = point_index_count + 1
    693699               surfaces%points(1,surfaces%npoints) = ( i + 1 - 0.5_wp ) * dx
    694700               surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
     
    696702            ENDIF
    697703            IF ( point_index(k,j+1,i) < 0 )  THEN
    698                surfaces%npoints     = surfaces%npoints + 1   
     704               surfaces%npoints     = surfaces%npoints + 1
    699705               point_index(k,j+1,i) = point_index_count
    700                point_index_count    = point_index_count + 1 
     706               point_index_count    = point_index_count + 1
    701707               surfaces%points(1,surfaces%npoints) = ( i     - 0.5_wp ) * dx
    702708               surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
    703709               surfaces%points(3,surfaces%npoints) = zw(k)
    704710            ENDIF
    705            
     711
    706712            npg                        = npg + 1
    707713            surfaces%polygons(1,npg)   = 4
     
    709715            surfaces%polygons(3,npg)   = point_index(k,j,i+1)
    710716            surfaces%polygons(4,npg)   = point_index(k,j+1,i+1)
    711             surfaces%polygons(5,npg)   = point_index(k,j+1,i)   
     717            surfaces%polygons(5,npg)   = point_index(k,j+1,i)
    712718         ENDDO
    713719
    714720         DO  l = 0, 3
    715721            DO  m = 1, surf_def_v(l)%ns
    716 !       
    717 !--            Determine the indices of the respective grid cell inside the topography.
    718 !--            Please note, j-index for north-facing surfaces ( l==0 ) is
    719 !--            identical to the reference j-index outside the grid box.
     722!
     723!--            Determine the indices of the respective grid cell inside the
     724!--            topography.
     725!--            NOTE, j-index for north-facing surfaces ( l==0 ) is
     726!--            identical to the reference j-index outside the grid box.
    720727!--            Equivalent for east-facing surfaces and i-index.
    721728               i = surf_def_v(l)%i(m) + MERGE( surf_def_v(l)%ioff, 0, l == 3 )
    722729               j = surf_def_v(l)%j(m) + MERGE( surf_def_v(l)%joff, 0, l == 1 )
    723730               k = surf_def_v(l)%k(m) + surf_def_v(l)%koff
    724 !       
     731!
    725732!--            Lower left /front vertex
    726733               IF ( point_index(k,j,i) < 0 )  THEN
    727                   surfaces%npoints   = surfaces%npoints + 1   
     734                  surfaces%npoints   = surfaces%npoints + 1
    728735                  point_index(k,j,i) = point_index_count
    729                   point_index_count  = point_index_count + 1 
     736                  point_index_count  = point_index_count + 1
    730737                  surfaces%points(1,surfaces%npoints) = ( i - 0.5_wp ) * dx
    731738                  surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
    732739                  surfaces%points(3,surfaces%npoints) = zw(k-1)
    733                ENDIF 
    734 !       
     740               ENDIF
     741!
    735742!--            Upper / lower right index for north- and south-facing surfaces
    736743               IF ( l == 0  .OR.  l == 1 )  THEN
    737744                  IF ( point_index(k,j,i+1) < 0 )  THEN
    738                      surfaces%npoints     = surfaces%npoints + 1   
     745                     surfaces%npoints     = surfaces%npoints + 1
    739746                     point_index(k,j,i+1) = point_index_count
    740747                     point_index_count    = point_index_count + 1
     
    742749                     surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
    743750                     surfaces%points(3,surfaces%npoints) = zw(k-1)
    744                   ENDIF 
     751                  ENDIF
    745752                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
    746                      surfaces%npoints       = surfaces%npoints + 1   
     753                     surfaces%npoints       = surfaces%npoints + 1
    747754                     point_index(k+1,j,i+1) = point_index_count
    748755                     point_index_count      = point_index_count + 1
     
    751758                     surfaces%points(3,surfaces%npoints) = zw(k)
    752759                  ENDIF
    753 !       
     760!
    754761!--            Upper / lower front index for east- and west-facing surfaces
    755762               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
    756763                  IF ( point_index(k,j+1,i) < 0 )  THEN
    757                      surfaces%npoints     = surfaces%npoints + 1   
     764                     surfaces%npoints     = surfaces%npoints + 1
    758765                     point_index(k,j+1,i) = point_index_count
    759766                     point_index_count    = point_index_count + 1
     
    761768                     surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
    762769                     surfaces%points(3,surfaces%npoints) = zw(k-1)
    763                   ENDIF 
     770                  ENDIF
    764771                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
    765                      surfaces%npoints       = surfaces%npoints + 1   
     772                     surfaces%npoints       = surfaces%npoints + 1
    766773                     point_index(k+1,j+1,i) = point_index_count
    767774                     point_index_count      = point_index_count + 1
     
    771778                  ENDIF
    772779               ENDIF
    773 !       
     780!
    774781!--            Upper left / front vertex
    775782               IF ( point_index(k+1,j,i) < 0 )  THEN
    776                   surfaces%npoints     = surfaces%npoints + 1   
     783                  surfaces%npoints     = surfaces%npoints + 1
    777784                  point_index(k+1,j,i) = point_index_count
    778785                  point_index_count    = point_index_count + 1
     
    781788                  surfaces%points(3,surfaces%npoints) = zw(k)
    782789               ENDIF
    783                
    784                npg = npg + 1           
     790
     791               npg = npg + 1
    785792               IF ( l == 0  .OR.  l == 1 )  THEN
    786793                  surfaces%polygons(1,npg)   = 4
     
    788795                  surfaces%polygons(3,npg)   = point_index(k,j,i+1)
    789796                  surfaces%polygons(4,npg)   = point_index(k+1,j,i+1)
    790                   surfaces%polygons(5,npg)   = point_index(k+1,j,i) 
     797                  surfaces%polygons(5,npg)   = point_index(k+1,j,i)
    791798               ELSE
    792799                  surfaces%polygons(1,npg)   = 4
     
    796803                  surfaces%polygons(5,npg)   = point_index(k+1,j,i)
    797804               ENDIF
    798                
     805
    799806            ENDDO
    800          
     807
    801808            DO  m = 1, surf_lsm_v(l)%ns
    802809               i = surf_lsm_v(l)%i(m) + MERGE( surf_lsm_v(l)%ioff, 0, l == 3 )
    803810               j = surf_lsm_v(l)%j(m) + MERGE( surf_lsm_v(l)%joff, 0, l == 1 )
    804811               k = surf_lsm_v(l)%k(m) + surf_lsm_v(l)%koff
    805 !       
     812!
    806813!--            Lower left /front vertex
    807814               IF ( point_index(k,j,i) < 0 )  THEN
    808                   surfaces%npoints   = surfaces%npoints + 1   
     815                  surfaces%npoints   = surfaces%npoints + 1
    809816                  point_index(k,j,i) = point_index_count
    810817                  point_index_count  = point_index_count + 1
     
    812819                  surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
    813820                  surfaces%points(3,surfaces%npoints) = zw(k-1)
    814                ENDIF 
    815 !       
     821               ENDIF
     822!
    816823!--            Upper / lower right index for north- and south-facing surfaces
    817824               IF ( l == 0  .OR.  l == 1 )  THEN
    818825                  IF ( point_index(k,j,i+1) < 0 )  THEN
    819                      surfaces%npoints     = surfaces%npoints + 1   
     826                     surfaces%npoints     = surfaces%npoints + 1
    820827                     point_index(k,j,i+1) = point_index_count
    821828                     point_index_count    = point_index_count + 1
     
    823830                     surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
    824831                     surfaces%points(3,surfaces%npoints) = zw(k-1)
    825                   ENDIF 
     832                  ENDIF
    826833                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
    827                      surfaces%npoints       = surfaces%npoints + 1   
     834                     surfaces%npoints       = surfaces%npoints + 1
    828835                     point_index(k+1,j,i+1) = point_index_count
    829836                     point_index_count      = point_index_count + 1
     
    832839                     surfaces%points(3,surfaces%npoints) = zw(k)
    833840                  ENDIF
    834 !       
     841!
    835842!--            Upper / lower front index for east- and west-facing surfaces
    836843               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
    837844                  IF ( point_index(k,j+1,i) < 0 )  THEN
    838                      surfaces%npoints     = surfaces%npoints + 1   
     845                     surfaces%npoints     = surfaces%npoints + 1
    839846                     point_index(k,j+1,i) = point_index_count
    840847                     point_index_count    = point_index_count + 1
     
    842849                     surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
    843850                     surfaces%points(3,surfaces%npoints) = zw(k-1)
    844                   ENDIF 
     851                  ENDIF
    845852                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
    846                      surfaces%npoints       = surfaces%npoints + 1   
     853                     surfaces%npoints       = surfaces%npoints + 1
    847854                     point_index(k+1,j+1,i) = point_index_count
    848855                     point_index_count      = point_index_count + 1
     
    852859                  ENDIF
    853860               ENDIF
    854 !       
     861!
    855862!--            Upper left / front vertex
    856863               IF ( point_index(k+1,j,i) < 0 )  THEN
    857                   surfaces%npoints     = surfaces%npoints + 1   
     864                  surfaces%npoints     = surfaces%npoints + 1
    858865                  point_index(k+1,j,i) = point_index_count
    859866                  point_index_count    = point_index_count + 1
     
    862869                  surfaces%points(3,surfaces%npoints) = zw(k)
    863870               ENDIF
    864                
    865                npg = npg + 1           
     871
     872               npg = npg + 1
    866873               IF ( l == 0  .OR.  l == 1 )  THEN
    867874                  surfaces%polygons(1,npg)   = 4
     
    869876                  surfaces%polygons(3,npg)   = point_index(k,j,i+1)
    870877                  surfaces%polygons(4,npg)   = point_index(k+1,j,i+1)
    871                   surfaces%polygons(5,npg)   = point_index(k+1,j,i) 
     878                  surfaces%polygons(5,npg)   = point_index(k+1,j,i)
    872879               ELSE
    873880                  surfaces%polygons(1,npg)   = 4
     
    882889               j = surf_usm_v(l)%j(m) + MERGE( surf_usm_v(l)%joff, 0, l == 1 )
    883890               k = surf_usm_v(l)%k(m) + surf_usm_v(l)%koff
    884 !       
     891!
    885892!--            Lower left /front vertex
    886893               IF ( point_index(k,j,i) < 0 )  THEN
    887                   surfaces%npoints   = surfaces%npoints + 1   
     894                  surfaces%npoints   = surfaces%npoints + 1
    888895                  point_index(k,j,i) = point_index_count
    889896                  point_index_count  = point_index_count + 1
     
    891898                  surfaces%points(2,surfaces%npoints) = ( j - 0.5_wp ) * dy
    892899                  surfaces%points(3,surfaces%npoints) = zw(k-1)
    893                ENDIF 
    894 !       
     900               ENDIF
     901!
    895902!--            Upper / lower right index for north- and south-facing surfaces
    896903               IF ( l == 0  .OR.  l == 1 )  THEN
    897904                  IF ( point_index(k,j,i+1) < 0 )  THEN
    898                      surfaces%npoints     = surfaces%npoints + 1   
     905                     surfaces%npoints     = surfaces%npoints + 1
    899906                     point_index(k,j,i+1) = point_index_count
    900907                     point_index_count    = point_index_count + 1
     
    902909                     surfaces%points(2,surfaces%npoints) = ( j     - 0.5_wp ) * dy
    903910                     surfaces%points(3,surfaces%npoints) = zw(k-1)
    904                   ENDIF 
     911                  ENDIF
    905912                  IF ( point_index(k+1,j,i+1) < 0 )  THEN
    906                      surfaces%npoints       = surfaces%npoints + 1   
     913                     surfaces%npoints       = surfaces%npoints + 1
    907914                     point_index(k+1,j,i+1) = point_index_count
    908915                     point_index_count      = point_index_count + 1
     
    911918                     surfaces%points(3,surfaces%npoints) = zw(k)
    912919                  ENDIF
    913 !       
     920!
    914921!--            Upper / lower front index for east- and west-facing surfaces
    915922               ELSEIF ( l == 2  .OR.  l == 3 )  THEN
    916923                  IF ( point_index(k,j+1,i) < 0 )  THEN
    917                      surfaces%npoints     = surfaces%npoints + 1   
     924                     surfaces%npoints     = surfaces%npoints + 1
    918925                     point_index(k,j+1,i) = point_index_count
    919926                     point_index_count    = point_index_count + 1
     
    921928                     surfaces%points(2,surfaces%npoints) = ( j + 1 - 0.5_wp ) * dy
    922929                     surfaces%points(3,surfaces%npoints) = zw(k-1)
    923                   ENDIF 
     930                  ENDIF
    924931                  IF ( point_index(k+1,j+1,i) < 0 )  THEN
    925                      surfaces%npoints       = surfaces%npoints + 1   
     932                     surfaces%npoints       = surfaces%npoints + 1
    926933                     point_index(k+1,j+1,i) = point_index_count
    927934                     point_index_count      = point_index_count + 1
     
    931938                  ENDIF
    932939               ENDIF
    933 !       
     940!
    934941!--            Upper left / front vertex
    935942               IF ( point_index(k+1,j,i) < 0 )  THEN
    936                   surfaces%npoints     = surfaces%npoints + 1   
     943                  surfaces%npoints     = surfaces%npoints + 1
    937944                  point_index(k+1,j,i) = point_index_count
    938945                  point_index_count    = point_index_count + 1
     
    941948                  surfaces%points(3,surfaces%npoints) = zw(k)
    942949               ENDIF
    943                
    944                npg = npg + 1           
     950
     951               npg = npg + 1
    945952               IF ( l == 0  .OR.  l == 1 )  THEN
    946953                  surfaces%polygons(1,npg)   = 4
     
    948955                  surfaces%polygons(3,npg)   = point_index(k,j,i+1)
    949956                  surfaces%polygons(4,npg)   = point_index(k+1,j,i+1)
    950                   surfaces%polygons(5,npg)   = point_index(k+1,j,i) 
     957                  surfaces%polygons(5,npg)   = point_index(k+1,j,i)
    951958               ELSE
    952959                  surfaces%polygons(1,npg)   = 4
     
    957964               ENDIF
    958965            ENDDO
    959          
     966
    960967         ENDDO
    961 !       
     968!
    962969!--      Deallocate temporary dummy variable
    963970         DEALLOCATE ( point_index )
    964971!
    965972!--      Sum-up total number of vertices on domain. This
    966 !--      will be needed for post-processing. 
     973!--      will be needed for post-processing.
    967974         surfaces%npoints_total = 0
    968975#if defined( __parallel )
     
    974981       ENDIF
    975982!
    976 !--    If output to netcdf is enabled, set-up the coordinate arrays that 
    977 !--    unambiguously describe the position and orientation of each surface 
    978 !--    element. 
     983!--    If output to netcdf is enabled, set-up the coordinate arrays that
     984!--    unambiguously describe the position and orientation of each surface
     985!--    element.
    979986       IF ( to_netcdf )  THEN
    980987!
     
    990997!
    991998!--       Gather the number of surface on each processor, in order to number
    992 !--       the surface elements in ascending order with respect to the total 
     999!--       the surface elements in ascending order with respect to the total
    9931000!--       number of surfaces in the domain.
    9941001#if defined( __parallel )
     
    9991006#endif
    10001007!
    1001 !--       First, however, determine the offset where couting of the surfaces 
     1008!--       First, however, determine the offset where couting of the surfaces
    10021009!--       should start (the sum of surfaces on all PE's with lower MPI rank).
    10031010          i           = 0
     
    10071014             i           = i + 1
    10081015          ENDDO
    1009 !       
    1010 !--       Set coordinate arrays. For horizontal surfaces, azimuth 
    1011 !--       angles are not defined (fill value). Zenith angle is 0 (180) for 
     1016!
     1017!--       Set coordinate arrays. For horizontal surfaces, azimuth
     1018!--       angles are not defined (fill value). Zenith angle is 0 (180) for
    10121019!--       upward (downward)-facing surfaces.
    10131020          i  = start_count
     
    10531060             mm                   = mm + 1
    10541061          ENDDO
    1055 !       
    1056 !--       For vertical surfaces, zenith angles are not defined (fill value). 
    1057 !--       Azimuth angle: eastward (0), westward (180), northward (270), 
    1058 !--       southward (90). 
     1062!
     1063!--       For vertical surfaces, zenith angles are not defined (fill value).
     1064!--       Azimuth angle: eastward (0), westward (180), northward (270),
     1065!--       southward (90).
    10591066          DO  l = 0, 3
    10601067             IF ( l == 0 )  THEN
     
    10751082                off_y =  0.0_wp
    10761083             ENDIF
    1077                
     1084
    10781085             DO  m = 1, surf_def_v(l)%ns
    10791086                surfaces%s(mm)       = i
     
    11071114             ENDDO
    11081115          ENDDO
    1109 !       
    1110 !--       Finally, define UTM coordinates, which are the x/y-coordinates 
     1116!
     1117!--       Finally, define UTM coordinates, which are the x/y-coordinates
    11111118!--       plus the origin (lower-left coordinate of the model domain).
    1112           surfaces%es_utm = surfaces%xs + init_model%origin_x 
    1113           surfaces%ns_utm = surfaces%ys + init_model%origin_y 
    1114 !
    1115 !--       Initialize NetCDF data output. Please note, local start position for 
    1116 !--       the surface elements in the NetCDF file is surfaces%s(1), while 
     1119          surfaces%es_utm = surfaces%xs + init_model%origin_x
     1120          surfaces%ns_utm = surfaces%ys + init_model%origin_y
     1121!
     1122!--       Initialize NetCDF data output. Please note, local start position for
     1123!--       the surface elements in the NetCDF file is surfaces%s(1), while
    11171124!--       the number of surfaces on the subdomain is given by surfaces%ns.
    11181125#if defined( __netcdf4_parallel )
     
    11201127!
    11211128!--       Calculate number of time steps to be output
    1122           ntdim_surf(0) = dosurf_time_count(0) + CEILING(                            &
    1123                         ( end_time - MAX(                                            &
    1124                             MERGE(skip_time_dosurf, skip_time_dosurf + spinup_time,  &
    1125                                   data_output_during_spinup ),                       &
    1126                             simulated_time_at_begin )                                &
     1129          ntdim_surf(0) = dosurf_time_count(0) + CEILING(                      &
     1130                        ( end_time - MAX(                                      &
     1131                            MERGE( skip_time_dosurf,                           &
     1132                                   skip_time_dosurf + spinup_time,             &
     1133                                   data_output_during_spinup ),                &
     1134                            simulated_time_at_begin )                          &
    11271135                        ) / dt_dosurf )
    11281136
    11291137          ntdim_surf(1) = dosurf_time_count(1) + CEILING(                      &
    11301138                        ( end_time - MAX(                                      &
    1131                             MERGE(   skip_time_dosurf_av, skip_time_dosurf_av  &
    1132                                   + spinup_time, data_output_during_spinup ),  &
     1139                            MERGE( skip_time_dosurf_av,                        &
     1140                                   skip_time_dosurf_av + spinup_time,          &
     1141                                   data_output_during_spinup ),                &
    11331142                            simulated_time_at_begin )                          &
    11341143                        ) / dt_dosurf_av )
     
    11521161                                    IOR( NF90_NOCLOBBER,                       &
    11531162                                    IOR( NF90_NETCDF4, NF90_MPIIO ) ),         &
    1154                                     id_set_surf(av), COMM = comm2d, INFO = MPI_INFO_NULL )
     1163                                    id_set_surf(av),                           &
     1164                                    COMM = comm2d, INFO = MPI_INFO_NULL )
    11551165             CALL netcdf_handle_error( 'surface_data_output_mod', 5550 )
    11561166
    11571167             !- Write some global attributes
    11581168             IF ( av == 0 )  THEN
    1159                 CALL netcdf_create_global_atts( id_set_surf(av), 'surface-data', TRIM( run_description_header ), 5551 )
     1169                CALL netcdf_create_global_atts( id_set_surf(av),               &
     1170                                                'surface-data',                &
     1171                                                TRIM( run_description_header ),&
     1172                                                5551 )
    11601173                time_average_text = ' '
    11611174             ELSE
    1162                 CALL netcdf_create_global_atts( id_set_surf(av), 'surface-data_av', TRIM( run_description_header ), 5552 )
    1163                 WRITE ( time_average_text,'(F7.1,'' s avg'')' )  averaging_interval_surf
    1164                 nc_stat = NF90_PUT_ATT( id_set_surf(av), NF90_GLOBAL, 'time_avg',  &
     1175                CALL netcdf_create_global_atts( id_set_surf(av),               &
     1176                                                'surface-data_av',             &
     1177                                                TRIM( run_description_header ),&
     1178                                                5552 )
     1179                WRITE ( time_average_text,'(F7.1,'' s avg'')' )  &
     1180                   averaging_interval_surf
     1181                nc_stat = NF90_PUT_ATT( id_set_surf(av), NF90_GLOBAL,          &
     1182                                        'time_avg',                            &
    11651183                                        TRIM( time_average_text ) )
    11661184                CALL netcdf_handle_error( 'surface_data_output_mod', 5553 )
     
    11701188!
    11711189!--          Define time coordinate for surface data.
    1172 !--          For parallel output the time dimension has to be limited (ntdim_surf),
    1173 !--          otherwise the performance drops significantly.
     1190!--          For parallel output the time dimension has to be limited
     1191!--          (ntdim_surf), otherwise the performance drops significantly.
    11741192             CALL netcdf_create_dim( id_set_surf(av), 'time', ntdim_surf(av),  &
    11751193                                     id_dim_time_surf(av), 5554 )
    11761194
    1177              CALL netcdf_create_var( id_set_surf(av), (/ id_dim_time_surf(av) /),    &
    1178                                      'time', NF90_DOUBLE, id_var_time_surf(av),      &
    1179                                      'seconds since '//TRIM(init_model%origin_time), &
     1195             CALL netcdf_create_var( id_set_surf(av),                          &
     1196                                     (/ id_dim_time_surf(av) /),               &
     1197                                     'time', NF90_DOUBLE,                      &
     1198                                     id_var_time_surf(av),                     &
     1199                                     'seconds since '//                        &
     1200                                     TRIM(init_model%origin_time),             &
    11801201                                     'time', 5555, 5555, 5555 )
    1181              CALL netcdf_create_att( id_set_surf(av), id_var_time_surf(av), 'standard_name', 'time', 5556)
    1182              CALL netcdf_create_att( id_set_surf(av), id_var_time_surf(av), 'axis', 'T', 5557)
     1202
     1203             CALL netcdf_create_att( id_set_surf(av), id_var_time_surf(av),    &
     1204                                     'standard_name', 'time', 5556)
     1205
     1206             CALL netcdf_create_att( id_set_surf(av), id_var_time_surf(av),    &
     1207                                     'axis', 'T', 5557)
    11831208!
    11841209!--          Define spatial dimensions and coordinates:
     
    11881213             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
    11891214                                     's', NF90_DOUBLE, id_var_s_surf(av),      &
    1190                                      '1', '', 5559, 5559, 5559 )
     1215                                     '1', 'number of surface element',         &
     1216                                     5559, 5559, 5559 )
    11911217!
    11921218!--          Define x coordinate
    11931219             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
    11941220                                     'xs', NF90_DOUBLE, id_var_xs_surf(av),    &
    1195                                      'meters', '', 5561, 5561, 5561 )
     1221                                     'meters',                                 &
     1222                                     'distance to origin in x-direction',      &
     1223                                     5561, 5561, 5561 )
    11961224!
    11971225!--           Define y coordinate
    11981226             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
    11991227                                     'ys', NF90_DOUBLE, id_var_ys_surf(av),    &
    1200                                      'meters', '', 5562, 5562, 5562 )
     1228                                     'meters',                                 &
     1229                                     'distance to origin in y-direction',      &
     1230                                     5562, 5562, 5562 )
    12011231!
    12021232!--          Define z coordinate
    12031233             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
    12041234                                     'zs', NF90_DOUBLE, id_var_zs_surf(av),    &
    1205                                      'meters', '', 5560, 5560, 5560 )
     1235                                     'meters', 'height', 5560, 5560, 5560 )
     1236             CALL netcdf_create_att( id_set_surf(av), id_var_zs_surf(av),      &
     1237                                     'standard_name', 'height', 5583 )
    12061238
    12071239!
    12081240!--          Define UTM coordinates
    1209              CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /),    &
    1210                                      'Es_UTM', NF90_DOUBLE, id_var_etum_surf(av), &
     1241             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
     1242                                     'Es_UTM', NF90_DOUBLE,                    &
     1243                                     id_var_etum_surf(av),                     &
    12111244                                     'meters', '', 5563, 5563, 5563 )
    1212              CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /),    &
    1213                                      'Ns_UTM', NF90_DOUBLE, id_var_nutm_surf(av), &
     1245             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
     1246                                     'Ns_UTM', NF90_DOUBLE,                    &
     1247                                     id_var_nutm_surf(av),                     &
    12141248                                     'meters', '', 5564, 5564, 5564 )
     1249
     1250!
     1251!--          Define angles
     1252             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
     1253                                     'azimuth', NF90_DOUBLE,                   &
     1254                                     id_var_azimuth_surf(av),                  &
     1255                                     'degree', 'azimuth angle',                &
     1256                                     5577, 5578, 5579,                         &
     1257                                     fill = .TRUE. )
     1258             CALL netcdf_create_att( id_set_surf(av), id_var_azimuth_surf(av), &
     1259                                     'standard_name', 'surface_azimuth_angle', &
     1260                                     5584 )
     1261
     1262             CALL netcdf_create_var( id_set_surf(av), (/ id_dim_s_surf(av) /), &
     1263                                     'zenith', NF90_DOUBLE,                    &
     1264                                     id_var_zenith_surf(av),                   &
     1265                                     'degree', '', 5580, 5581, 5582,           &
     1266                                     fill = .TRUE. )
    12151267!
    12161268!--          Define the variables
     
    12271279!
    12281280!--                Set no fill for every variable to increase performance.
    1229                 nc_stat = NF90_DEF_VAR_FILL( id_set_surf(av),     &
    1230                                              id_var_dosurf(av,i), &
     1281                nc_stat = NF90_DEF_VAR_FILL( id_set_surf(av),                  &
     1282                                             id_var_dosurf(av,i),              &
    12311283                                             1, 0 )
    12321284                CALL netcdf_handle_error( 'surface_data_output_init', 5566 )
    12331285!
    12341286!--                Set collective io operations for parallel io
    1235                 nc_stat = NF90_VAR_PAR_ACCESS( id_set_surf(av),     &
    1236                                                id_var_dosurf(av,i), &
     1287                nc_stat = NF90_VAR_PAR_ACCESS( id_set_surf(av),                &
     1288                                               id_var_dosurf(av,i),            &
    12371289                                               NF90_COLLECTIVE )
    12381290                CALL netcdf_handle_error( 'surface_data_output_init', 5567 )
     
    12501302
    12511303!
    1252 !--          Set general no fill, otherwise the performance drops significantly for
    1253 !--          parallel output.
     1304!--          Set general no fill, otherwise the performance drops significantly
     1305!--          for parallel output.
    12541306             nc_stat = NF90_SET_FILL( id_set_surf(av), NF90_NOFILL, oldmode )
    12551307             CALL netcdf_handle_error( 'surface_data_output_init', 5569 )
     
    12721324                ENDDO
    12731325
    1274                 nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_s_surf(av),  &
    1275                                         netcdf_data_1d, start = (/ 1 /),     &
     1326                nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_s_surf(av),    &
     1327                                        netcdf_data_1d, start = (/ 1 /),       &
    12761328                                        count = (/ surfaces%ns_total /) )
    12771329                CALL netcdf_handle_error( 'surface_data_output_init', 5571 )
     
    12981350             CALL netcdf_handle_error( 'surface_data_output_init', 5574 )
    12991351
    1300              nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_etum_surf(av),        &
    1301                                      surfaces%es_utm, start = (/ surfaces%s(1) /), &
     1352             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_etum_surf(av),    &
     1353                                     surfaces%es_utm,                          &
     1354                                     start = (/ surfaces%s(1) /),              &
    13021355                                     count = (/ surfaces%ns /) )
    13031356             CALL netcdf_handle_error( 'surface_data_output_init', 5575 )
    13041357
    1305              nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_nutm_surf(av),        &
    1306                                      surfaces%ns_utm, start = (/ surfaces%s(1) /), &
     1358             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_nutm_surf(av),    &
     1359                                     surfaces%ns_utm,                          &
     1360                                     start = (/ surfaces%s(1) /),              &
    13071361                                     count = (/ surfaces%ns /) )
    13081362             CALL netcdf_handle_error( 'surface_data_output_init', 5576 )
    1309              
     1363
     1364             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_azimuth_surf(av), &
     1365                                     surfaces%azimuth,                         &
     1366                                     start = (/ surfaces%s(1) /),              &
     1367                                     count = (/ surfaces%ns /) )
     1368             CALL netcdf_handle_error( 'surface_data_output_init', 5585 )
     1369
     1370             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_zenith_surf(av),  &
     1371                                     surfaces%zenith,                          &
     1372                                     start = (/ surfaces%s(1) /),              &
     1373                                     count = (/ surfaces%ns /) )
     1374             CALL netcdf_handle_error( 'surface_data_output_init', 5586 )
     1375
    13101376          ENDDO
    13111377#endif
     
    13141380
    13151381   END SUBROUTINE surface_data_output_init
    1316    
     1382
    13171383!------------------------------------------------------------------------------!
    13181384! Description:
    13191385! ------------
    1320 !> Routine for controlling the data output. Surface data is collected from 
    1321 !> different types of surfaces (default, natural, urban) and different 
     1386!> Routine for controlling the data output. Surface data is collected from
     1387!> different types of surfaces (default, natural, urban) and different
    13221388!> orientation and written to one 1D-output array. Further, NetCDF routines
    13231389!> are called to write the surface data in the respective NetCDF files.
    1324 !------------------------------------------------------------------------------!   
     1390!------------------------------------------------------------------------------!
    13251391   SUBROUTINE surface_data_output( av )
    1326    
     1392
    13271393      USE control_parameters,                                                  &
    13281394          ONLY:  io_blocks, io_group, time_since_reference_point
     
    13311397          ONLY:  comm2d, ierr
    13321398
    1333    
     1399
    13341400      IMPLICIT NONE
    13351401
    13361402      CHARACTER(LEN=100) ::  trimvar = ' ' !< dummy for single output variable
    1337      
     1403
    13381404      INTEGER(iwp) ::  av     !< id indicating average or non-average data output
    13391405      INTEGER(iwp) ::  i      !< loop index
     
    13441410      IF ( dosurf_no(av) == 0 )  RETURN
    13451411!
    1346 !--   In case of VTK output, check if binary files are open and write coordinates. 
     1412!--   In case of VTK output, check if binary files are open and write coordinates.
    13471413      IF ( to_vtk )  THEN
    13481414
     
    13721438#if defined( __netcdf4_parallel )
    13731439         IF ( dosurf_time_count(av) + 1 > ntdim_surf(av) )  THEN
    1374             WRITE ( message_string, * ) 'Output of surface data is not given at t=',          &
    1375                                         time_since_reference_point, 's because the maximum ', &
    1376                                         'number of output time levels is exceeded.'
     1440            WRITE ( message_string, * )                               &
     1441               'Output of surface data is not given at t=',           &
     1442               time_since_reference_point, 's because the maximum ',  &
     1443               'number of output time levels is exceeded.'
    13771444            CALL message( 'surface_data_output', 'PA0539', 0, 1, 0, 6, 0 )
    1378            
     1445
    13791446            RETURN
    13801447
     
    14031470         trimvar = TRIM( dosurf(av,n_out) )
    14041471!
    1405 !--      Set the output array to the _FillValue in case it is not 
     1472!--      Set the output array to the _FillValue in case it is not
    14061473!--      defined for each type of surface.
    14071474         surfaces%var_out = surfaces%fillvalue
     
    14271494                                               surf_def_v(3)%us,               &
    14281495                                               surf_lsm_v(3)%us,               &
    1429                                                surf_usm_v(3)%us ) 
    1430                ELSE
    1431 !
    1432 !--               Output of averaged data
    1433                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    1434                                         REAL( average_count_surf, KIND=wp )
    1435                   surfaces%var_av(:,n_out) = 0.0_wp
    1436                                                        
     1496                                               surf_usm_v(3)%us )
     1497               ELSE
     1498!
     1499!--               Output of averaged data
     1500                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     1501                                        REAL( average_count_surf, KIND=wp )
     1502                  surfaces%var_av(:,n_out) = 0.0_wp
     1503
    14371504               ENDIF
    14381505
     
    14561523                                               surf_def_v(3)%ts,               &
    14571524                                               surf_lsm_v(3)%ts,               &
    1458                                                surf_usm_v(3)%ts ) 
    1459                ELSE
    1460 !
    1461 !--               Output of averaged data
    1462                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    1463                                         REAL( average_count_surf, KIND=wp )
    1464                   surfaces%var_av(:,n_out) = 0.0_wp
    1465                                                        
     1525                                               surf_usm_v(3)%ts )
     1526               ELSE
     1527!
     1528!--               Output of averaged data
     1529                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     1530                                        REAL( average_count_surf, KIND=wp )
     1531                  surfaces%var_av(:,n_out) = 0.0_wp
     1532
    14661533               ENDIF
    14671534
     
    14851552                                               surf_def_v(3)%qs,               &
    14861553                                               surf_lsm_v(3)%qs,               &
    1487                                                surf_usm_v(3)%qs ) 
    1488                ELSE
    1489 !
    1490 !--               Output of averaged data
    1491                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    1492                                         REAL( average_count_surf, KIND=wp )
    1493                   surfaces%var_av(:,n_out) = 0.0_wp
    1494                                                        
     1554                                               surf_usm_v(3)%qs )
     1555               ELSE
     1556!
     1557!--               Output of averaged data
     1558                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     1559                                        REAL( average_count_surf, KIND=wp )
     1560                  surfaces%var_av(:,n_out) = 0.0_wp
     1561
    14951562               ENDIF
    14961563
     
    15141581                                               surf_def_v(3)%ss,               &
    15151582                                               surf_lsm_v(3)%ss,               &
    1516                                                surf_usm_v(3)%ss ) 
    1517                ELSE
    1518 !
    1519 !--               Output of averaged data
    1520                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    1521                                         REAL( average_count_surf, KIND=wp )
    1522                   surfaces%var_av(:,n_out) = 0.0_wp
    1523                                                        
     1583                                               surf_usm_v(3)%ss )
     1584               ELSE
     1585!
     1586!--               Output of averaged data
     1587                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     1588                                        REAL( average_count_surf, KIND=wp )
     1589                  surfaces%var_av(:,n_out) = 0.0_wp
     1590
    15241591               ENDIF
    15251592
     
    15431610                                               surf_def_v(3)%qcs,              &
    15441611                                               surf_lsm_v(3)%qcs,              &
    1545                                                surf_usm_v(3)%qcs ) 
    1546                ELSE
    1547 !
    1548 !--               Output of averaged data
    1549                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    1550                                         REAL( average_count_surf, KIND=wp )
    1551                   surfaces%var_av(:,n_out) = 0.0_wp
    1552                                                        
     1612                                               surf_usm_v(3)%qcs )
     1613               ELSE
     1614!
     1615!--               Output of averaged data
     1616                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     1617                                        REAL( average_count_surf, KIND=wp )
     1618                  surfaces%var_av(:,n_out) = 0.0_wp
     1619
    15531620               ENDIF
    15541621
     
    15721639                                               surf_def_v(3)%ncs,              &
    15731640                                               surf_lsm_v(3)%ncs,              &
    1574                                                surf_usm_v(3)%ncs ) 
    1575                ELSE
    1576 !
    1577 !--               Output of averaged data
    1578                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    1579                                         REAL( average_count_surf, KIND=wp )
    1580                   surfaces%var_av(:,n_out) = 0.0_wp
    1581                                                        
     1641                                               surf_usm_v(3)%ncs )
     1642               ELSE
     1643!
     1644!--               Output of averaged data
     1645                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     1646                                        REAL( average_count_surf, KIND=wp )
     1647                  surfaces%var_av(:,n_out) = 0.0_wp
     1648
    15821649               ENDIF
    15831650
     
    16011668                                               surf_def_v(3)%qrs,              &
    16021669                                               surf_lsm_v(3)%qrs,              &
    1603                                                surf_usm_v(3)%qrs ) 
    1604                ELSE
    1605 !
    1606 !--               Output of averaged data
    1607                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    1608                                         REAL( average_count_surf, KIND=wp )
    1609                   surfaces%var_av(:,n_out) = 0.0_wp
    1610                                                        
     1670                                               surf_usm_v(3)%qrs )
     1671               ELSE
     1672!
     1673!--               Output of averaged data
     1674                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     1675                                        REAL( average_count_surf, KIND=wp )
     1676                  surfaces%var_av(:,n_out) = 0.0_wp
     1677
    16111678               ENDIF
    16121679
     
    16301697                                               surf_def_v(3)%nrs,              &
    16311698                                               surf_lsm_v(3)%nrs,              &
    1632                                                surf_usm_v(3)%nrs ) 
    1633                ELSE
    1634 !
    1635 !--               Output of averaged data
    1636                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    1637                                         REAL( average_count_surf, KIND=wp )
    1638                   surfaces%var_av(:,n_out) = 0.0_wp
    1639                                                        
     1699                                               surf_usm_v(3)%nrs )
     1700               ELSE
     1701!
     1702!--               Output of averaged data
     1703                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     1704                                        REAL( average_count_surf, KIND=wp )
     1705                  surfaces%var_av(:,n_out) = 0.0_wp
     1706
    16401707               ENDIF
    16411708
     
    16591726                                               surf_def_v(3)%ol,               &
    16601727                                               surf_lsm_v(3)%ol,               &
    1661                                                surf_usm_v(3)%ol ) 
    1662                ELSE
    1663 !
    1664 !--               Output of averaged data
    1665                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    1666                                         REAL( average_count_surf, KIND=wp )
    1667                   surfaces%var_av(:,n_out) = 0.0_wp
    1668                                                        
     1728                                               surf_usm_v(3)%ol )
     1729               ELSE
     1730!
     1731!--               Output of averaged data
     1732                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     1733                                        REAL( average_count_surf, KIND=wp )
     1734                  surfaces%var_av(:,n_out) = 0.0_wp
     1735
    16691736               ENDIF
    16701737
     
    16951762                                        REAL( average_count_surf, KIND=wp )
    16961763                  surfaces%var_av(:,n_out) = 0.0_wp
    1697                                                        
     1764
    16981765               ENDIF
    16991766
     
    17241791                                        REAL( average_count_surf, KIND=wp )
    17251792                  surfaces%var_av(:,n_out) = 0.0_wp
    1726                                                        
     1793
    17271794               ENDIF
    17281795
     
    17461813                                               surf_def_v(3)%z0q,              &
    17471814                                               surf_lsm_v(3)%z0q,              &
    1748                                                surf_usm_v(3)%z0q ) 
     1815                                               surf_usm_v(3)%z0q )
    17491816               ELSE
    17501817!
     
    17821849                                        REAL( average_count_surf, KIND=wp )
    17831850                  surfaces%var_av(:,n_out) = 0.0_wp
    1784                                                        
     1851
    17851852               ENDIF
    17861853
     
    18111878                                        REAL( average_count_surf, KIND=wp )
    18121879                  surfaces%var_av(:,n_out) = 0.0_wp
    1813                                                        
     1880
    18141881               ENDIF
    18151882
     
    18401907                                        REAL( average_count_surf, KIND=wp )
    18411908                  surfaces%var_av(:,n_out) = 0.0_wp
    1842                                                        
     1909
    18431910               ENDIF
    18441911
     
    18691936                                        REAL( average_count_surf, KIND=wp )
    18701937                  surfaces%var_av(:,n_out) = 0.0_wp
    1871                                                        
     1938
    18721939               ENDIF
    18731940
     
    18981965                                        REAL( average_count_surf, KIND=wp )
    18991966                  surfaces%var_av(:,n_out) = 0.0_wp
    1900                                                        
     1967
    19011968               ENDIF
    19021969
     
    19552022                                        REAL( average_count_surf, KIND=wp )
    19562023                  surfaces%var_av(:,n_out) = 0.0_wp
    1957                                                        
     2024
    19582025               ENDIF
    19592026
     
    19842051                                        REAL( average_count_surf, KIND=wp )
    19852052                  surfaces%var_av(:,n_out) = 0.0_wp
    1986                                                        
     2053
    19872054               ENDIF
    19882055
     
    20132080                                        REAL( average_count_surf, KIND=wp )
    20142081                  surfaces%var_av(:,n_out) = 0.0_wp
    2015                                                        
     2082
    20162083               ENDIF
    20172084
     
    20422109                                        REAL( average_count_surf, KIND=wp )
    20432110                  surfaces%var_av(:,n_out) = 0.0_wp
    2044                                                        
     2111
    20452112               ENDIF
    20462113
     
    20712138                                        REAL( average_count_surf, KIND=wp )
    20722139                  surfaces%var_av(:,n_out) = 0.0_wp
    2073                                                        
     2140
    20742141               ENDIF
    20752142
     
    21002167                                        REAL( average_count_surf, KIND=wp )
    21012168                  surfaces%var_av(:,n_out) = 0.0_wp
    2102                                                        
     2169
    21032170               ENDIF
    21042171
     
    21292196                                        REAL( average_count_surf, KIND=wp )
    21302197                  surfaces%var_av(:,n_out) = 0.0_wp
    2131                                                        
     2198
    21322199               ENDIF
    21332200
     
    21582225                                        REAL( average_count_surf, KIND=wp )
    21592226                  surfaces%var_av(:,n_out) = 0.0_wp
    2160                                                        
     2227
    21612228               ENDIF
    21622229
     
    21872254                                        REAL( average_count_surf, KIND=wp )
    21882255                  surfaces%var_av(:,n_out) = 0.0_wp
    2189                                                        
     2256
    21902257               ENDIF
    21912258
     
    22162283                                        REAL( average_count_surf, KIND=wp )
    22172284                  surfaces%var_av(:,n_out) = 0.0_wp
    2218                                                        
     2285
    22192286               ENDIF
    22202287
     
    22382305                                               surf_def_v(3)%rad_net,          &
    22392306                                               surf_lsm_v(3)%rad_net,          &
    2240                                                surf_usm_v(3)%rad_net ) 
    2241                ELSE
    2242 !
    2243 !--               Output of averaged data
    2244                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    2245                                         REAL( average_count_surf, KIND=wp )
    2246                   surfaces%var_av(:,n_out) = 0.0_wp
    2247                                                        
     2307                                               surf_usm_v(3)%rad_net )
     2308               ELSE
     2309!
     2310!--               Output of averaged data
     2311                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     2312                                        REAL( average_count_surf, KIND=wp )
     2313                  surfaces%var_av(:,n_out) = 0.0_wp
     2314
    22482315               ENDIF
    22492316
     
    22742341                                        REAL( average_count_surf, KIND=wp )
    22752342                  surfaces%var_av(:,n_out) = 0.0_wp
    2276                                                        
     2343
    22772344               ENDIF
    22782345
     
    23032370                                        REAL( average_count_surf, KIND=wp )
    23042371                  surfaces%var_av(:,n_out) = 0.0_wp
    2305                                                        
     2372
    23062373               ENDIF
    23072374
     
    23322399                                        REAL( average_count_surf, KIND=wp )
    23332400                  surfaces%var_av(:,n_out) = 0.0_wp
    2334                                                        
     2401
    23352402               ENDIF
    23362403
     
    23612428                                        REAL( average_count_surf, KIND=wp )
    23622429                  surfaces%var_av(:,n_out) = 0.0_wp
    2363                                                        
     2430
    23642431               ENDIF
    23652432
     
    23832450                                               surf_def_v(3)%ghf,              &
    23842451                                               surf_lsm_v(3)%ghf,              &
    2385                                                surf_usm_v(3)%ghf )     
     2452                                               surf_usm_v(3)%ghf )
    23862453                                                                        ELSE
    23872454!
     
    23902457                                        REAL( average_count_surf, KIND=wp )
    23912458                  surfaces%var_av(:,n_out) = 0.0_wp
    2392                                                        
    2393                ENDIF
    2394                      
    2395             CASE ( 'r_a' )                                                     
     2459
     2460               ENDIF
     2461
     2462            CASE ( 'r_a' )
    23962463!
    23972464!--            Output of instantaneous data
     
    24122479                                               surf_def_v(3)%r_a,              &
    24132480                                               surf_lsm_v(3)%r_a,              &
    2414                                                surf_usm_v(3)%r_a )     
     2481                                               surf_usm_v(3)%r_a )
    24152482                                                                      ELSE
    24162483!
     
    24192486                                        REAL( average_count_surf, KIND=wp )
    24202487                  surfaces%var_av(:,n_out) = 0.0_wp
    2421                                                        
    2422                ENDIF
    2423                        
    2424             CASE ( 'r_soil' )                                                 
     2488
     2489               ENDIF
     2490
     2491            CASE ( 'r_soil' )
    24252492!
    24262493!--            Output of instantaneous data
     
    24412508                                               surf_def_v(3)%r_soil,           &
    24422509                                               surf_lsm_v(3)%r_soil,           &
    2443                                                surf_usm_v(3)%r_soil ) 
    2444                ELSE
    2445 !
    2446 !--               Output of averaged data
    2447                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    2448                                         REAL( average_count_surf, KIND=wp )
    2449                   surfaces%var_av(:,n_out) = 0.0_wp
    2450                                                        
     2510                                               surf_usm_v(3)%r_soil )
     2511               ELSE
     2512!
     2513!--               Output of averaged data
     2514                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     2515                                        REAL( average_count_surf, KIND=wp )
     2516                  surfaces%var_av(:,n_out) = 0.0_wp
     2517
    24512518               ENDIF
    24522519
     
    24702537                                               surf_def_v(3)%r_canopy,         &
    24712538                                               surf_lsm_v(3)%r_canopy,         &
    2472                                                surf_usm_v(3)%r_canopy ) 
    2473                ELSE
    2474 !
    2475 !--               Output of averaged data
    2476                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    2477                                         REAL( average_count_surf, KIND=wp )
    2478                   surfaces%var_av(:,n_out) = 0.0_wp
    2479                                                        
     2539                                               surf_usm_v(3)%r_canopy )
     2540               ELSE
     2541!
     2542!--               Output of averaged data
     2543                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     2544                                        REAL( average_count_surf, KIND=wp )
     2545                  surfaces%var_av(:,n_out) = 0.0_wp
     2546
    24802547               ENDIF
    24812548
     
    24992566                                               surf_def_v(3)%r_s,              &
    25002567                                               surf_lsm_v(3)%r_s,              &
    2501                                                surf_usm_v(3)%r_s ) 
    2502                ELSE
    2503 !
    2504 !--               Output of averaged data
    2505                   surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
    2506                                         REAL( average_count_surf, KIND=wp )
    2507                   surfaces%var_av(:,n_out) = 0.0_wp
    2508                                                        
     2568                                               surf_usm_v(3)%r_s )
     2569               ELSE
     2570!
     2571!--               Output of averaged data
     2572                  surfaces%var_out(:) = surfaces%var_av(:,n_out) /             &
     2573                                        REAL( average_count_surf, KIND=wp )
     2574                  surfaces%var_av(:,n_out) = 0.0_wp
     2575
    25092576               ENDIF
    25102577
     
    25352602                                        REAL( average_count_surf, KIND=wp )
    25362603                  surfaces%var_av(:,n_out) = 0.0_wp
    2537                                                        
     2604
    25382605               ENDIF
    25392606
     
    25642631                                        REAL( average_count_surf, KIND=wp )
    25652632                  surfaces%var_av(:,n_out) = 0.0_wp
    2566                                                        
     2633
    25672634               ENDIF
    25682635
     
    25932660                                        REAL( average_count_surf, KIND=wp )
    25942661                  surfaces%var_av(:,n_out) = 0.0_wp
    2595                                                        
     2662
    25962663               ENDIF
    25972664
     
    26222689                                        REAL( average_count_surf, KIND=wp )
    26232690                  surfaces%var_av(:,n_out) = 0.0_wp
    2624                                                        
     2691
    26252692               ENDIF
    26262693
     
    26512718                                        REAL( average_count_surf, KIND=wp )
    26522719                  surfaces%var_av(:,n_out) = 0.0_wp
    2653                                                        
     2720
    26542721               ENDIF
    26552722
     
    26802747                                        REAL( average_count_surf, KIND=wp )
    26812748                  surfaces%var_av(:,n_out) = 0.0_wp
    2682                                                        
     2749
    26832750               ENDIF
    26842751
     
    27092776                                        REAL( average_count_surf, KIND=wp )
    27102777                  surfaces%var_av(:,n_out) = 0.0_wp
    2711                                                        
    2712                ENDIF
    2713                
     2778
     2779               ENDIF
     2780
    27142781            CASE ( 'uvw1' )
    27152782!
     
    27382805                                        REAL( average_count_surf, KIND=wp )
    27392806                  surfaces%var_av(:,n_out) = 0.0_wp
    2740                                                        
    2741                ENDIF   
     2807
     2808               ENDIF
    27422809
    27432810!
     
    27472814         END SELECT
    27482815!
    2749 !--      Write to binary file: 
     2816!--      Write to binary file:
    27502817!--      - surfaces%points ( 3, 1-npoints )
    27512818!--      - surfaces%polygons ( 5, 1-ns )
     
    27682835            ENDDO
    27692836         ENDIF
    2770          
     2837
    27712838         IF ( to_netcdf )  THEN
    27722839#if defined( __netcdf4_parallel )
    27732840!
    27742841!--         Write output array to file
    2775             nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_dosurf(av,n_out),            &
    2776                                     surfaces%var_out,                                    &
    2777                                     start = (/ surfaces%s(1), dosurf_time_count(av) /),  &
     2842            nc_stat = NF90_PUT_VAR( id_set_surf(av), id_var_dosurf(av,n_out),  &
     2843                                    surfaces%var_out,                          &
     2844                                    start = (/ surfaces%s(1),                  &
     2845                                               dosurf_time_count(av) /),       &
    27782846                                    count = (/ surfaces%ns, 1 /) )
    27792847            CALL netcdf_handle_error( 'surface_data_output', 6667 )
     
    27822850
    27832851      ENDDO
    2784      
     2852
    27852853!
    27862854!--   If averaged output was written to NetCDF file, set the counter to zero
    27872855      IF ( av == 1 )  average_count_surf = 0
    2788              
     2856
    27892857   END SUBROUTINE surface_data_output
    2790    
     2858
    27912859!------------------------------------------------------------------------------!
    27922860! Description:
    27932861! ------------
    2794 !> Routine for controlling the data averaging. 
    2795 !------------------------------------------------------------------------------!     
     2862!> Routine for controlling the data averaging.
     2863!------------------------------------------------------------------------------!
    27962864   SUBROUTINE surface_data_output_averaging
    2797    
     2865
    27982866      IMPLICIT NONE
    2799      
     2867
    28002868      CHARACTER(LEN=100) ::  trimvar !< dummy variable for current output variable
    2801        
     2869
    28022870      INTEGER(iwp) ::  n_out  !< counter variables for surface output
    2803      
     2871
    28042872      n_out = 0
    28052873      DO  WHILE ( dosurf(1,n_out+1)(1:1) /= ' ' )
    2806          
     2874
    28072875         n_out   = n_out + 1
    28082876         trimvar = TRIM( dosurf(1,n_out) )
     
    28262894                                           surf_def_v(3)%us,                   &
    28272895                                           surf_lsm_v(3)%us,                   &
    2828                                            surf_usm_v(3)%us, n_out ) 
     2896                                           surf_usm_v(3)%us, n_out )
    28292897
    28302898            CASE ( 'ts' )
     
    28442912                                           surf_def_v(3)%ts,                   &
    28452913                                           surf_lsm_v(3)%ts,                   &
    2846                                            surf_usm_v(3)%ts, n_out ) 
     2914                                           surf_usm_v(3)%ts, n_out )
    28472915
    28482916            CASE ( 'qs' )
     
    28622930                                           surf_def_v(3)%qs,                   &
    28632931                                           surf_lsm_v(3)%qs,                   &
    2864                                            surf_usm_v(3)%qs, n_out ) 
     2932                                           surf_usm_v(3)%qs, n_out )
    28652933
    28662934            CASE ( 'ss' )
     
    28802948                                           surf_def_v(3)%ss,                   &
    28812949                                           surf_lsm_v(3)%ss,                   &
    2882                                            surf_usm_v(3)%ss, n_out ) 
     2950                                           surf_usm_v(3)%ss, n_out )
    28832951
    28842952            CASE ( 'qcs' )
     
    28982966                                           surf_def_v(3)%qcs,                  &
    28992967                                           surf_lsm_v(3)%qcs,                  &
    2900                                            surf_usm_v(3)%qcs, n_out ) 
     2968                                           surf_usm_v(3)%qcs, n_out )
    29012969
    29022970            CASE ( 'ncs' )
     
    29162984                                           surf_def_v(3)%ncs,                  &
    29172985                                           surf_lsm_v(3)%ncs,                  &
    2918                                            surf_usm_v(3)%ncs, n_out ) 
     2986                                           surf_usm_v(3)%ncs, n_out )
    29192987
    29202988            CASE ( 'qrs' )
     
    29343002                                           surf_def_v(3)%qrs,                  &
    29353003                                           surf_lsm_v(3)%qrs,                  &
    2936                                            surf_usm_v(3)%qrs, n_out ) 
     3004                                           surf_usm_v(3)%qrs, n_out )
    29373005
    29383006            CASE ( 'nrs' )
     
    29523020                                           surf_def_v(3)%nrs,                  &
    29533021                                           surf_lsm_v(3)%nrs,                  &
    2954                                            surf_usm_v(3)%nrs, n_out ) 
     3022                                           surf_usm_v(3)%nrs, n_out )
    29553023
    29563024            CASE ( 'ol' )
     
    29703038                                           surf_def_v(3)%ol,                   &
    29713039                                           surf_lsm_v(3)%ol,                   &
    2972                                            surf_usm_v(3)%ol, n_out ) 
     3040                                           surf_usm_v(3)%ol, n_out )
    29733041
    29743042            CASE ( 'z0' )
     
    29883056                                           surf_def_v(3)%z0,                   &
    29893057                                           surf_lsm_v(3)%z0,                   &
    2990                                            surf_usm_v(3)%z0, n_out ) 
     3058                                           surf_usm_v(3)%z0, n_out )
    29913059
    29923060            CASE ( 'z0h' )
     
    30063074                                           surf_def_v(3)%z0h,                  &
    30073075                                           surf_lsm_v(3)%z0h,                  &
    3008                                            surf_usm_v(3)%z0h, n_out )         
     3076                                           surf_usm_v(3)%z0h, n_out )
    30093077
    30103078            CASE ( 'z0q' )
     
    30243092                                           surf_def_v(3)%z0q,                  &
    30253093                                           surf_lsm_v(3)%z0q,                  &
    3026                                            surf_usm_v(3)%z0q, n_out ) 
    3027 
    3028             CASE ( 'theta1' )                                                 
     3094                                           surf_usm_v(3)%z0q, n_out )
     3095
     3096            CASE ( 'theta1' )
    30293097               CALL surface_data_output_sum_up( surf_def_h(0)%pt1,             &
    30303098                                           surf_def_h(1)%pt1,                  &
     
    30423110                                           surf_def_v(3)%pt1,                  &
    30433111                                           surf_lsm_v(3)%pt1,                  &
    3044                                            surf_usm_v(3)%pt1, n_out )         
    3045                                                                                
    3046             CASE ( 'qv1' )                                                     
     3112                                           surf_usm_v(3)%pt1, n_out )
     3113
     3114            CASE ( 'qv1' )
    30473115               CALL surface_data_output_sum_up( surf_def_h(0)%qv1,             &
    30483116                                           surf_def_h(1)%qv1,                  &
     
    30603128                                           surf_def_v(3)%qv1,                  &
    30613129                                           surf_lsm_v(3)%qv1,                  &
    3062                                            surf_usm_v(3)%qv1, n_out ) 
     3130                                           surf_usm_v(3)%qv1, n_out )
    30633131
    30643132            CASE ( 'thetav1' )
     
    30783146                                           surf_def_v(3)%vpt1,                 &
    30793147                                           surf_lsm_v(3)%vpt1,                 &
    3080                                            surf_usm_v(3)%vpt1, n_out ) 
     3148                                           surf_usm_v(3)%vpt1, n_out )
    30813149
    30823150            CASE ( 'usws' )
     
    30963164                                           surf_def_v(3)%usws,                 &
    30973165                                           surf_lsm_v(3)%usws,                 &
    3098                                            surf_usm_v(3)%usws, n_out ) 
     3166                                           surf_usm_v(3)%usws, n_out )
    30993167
    31003168            CASE ( 'vsws' )
     
    31143182                                           surf_def_v(3)%vsws,                 &
    31153183                                           surf_lsm_v(3)%vsws,                 &
    3116                                            surf_usm_v(3)%vsws, n_out ) 
     3184                                           surf_usm_v(3)%vsws, n_out )
    31173185
    31183186            CASE ( 'shf' )
     
    31203188                                           surf_def_h(1)%shf,                  &
    31213189                                           surf_lsm_h%shf,                     &
    3122                                            surf_usm_h%shf,                     & 
     3190                                           surf_usm_h%shf,                     &
    31233191                                           surf_def_v(0)%shf,                  &
    31243192                                           surf_lsm_v(0)%shf,                  &
     
    31503218                                           surf_def_v(3)%qsws,                 &
    31513219                                           surf_lsm_v(3)%qsws,                 &
    3152                                            surf_usm_v(3)%qsws, n_out ) 
     3220                                           surf_usm_v(3)%qsws, n_out )
    31533221
    31543222            CASE ( 'ssws' )
     
    31683236                                           surf_def_v(3)%ssws,                 &
    31693237                                           surf_lsm_v(3)%ssws,                 &
    3170                                            surf_usm_v(3)%ssws, n_out ) 
     3238                                           surf_usm_v(3)%ssws, n_out )
    31713239
    31723240            CASE ( 'qcsws' )
     
    31863254                                           surf_def_v(3)%qcsws,                &
    31873255                                           surf_lsm_v(3)%qcsws,                &
    3188                                            surf_usm_v(3)%qcsws, n_out ) 
     3256                                           surf_usm_v(3)%qcsws, n_out )
    31893257
    31903258            CASE ( 'ncsws' )
     
    32043272                                           surf_def_v(3)%ncsws,                &
    32053273                                           surf_lsm_v(3)%ncsws,                &
    3206                                            surf_usm_v(3)%ncsws, n_out ) 
     3274                                           surf_usm_v(3)%ncsws, n_out )
    32073275
    32083276            CASE ( 'qrsws' )
     
    32223290                                           surf_def_v(3)%qrsws,                &
    32233291                                           surf_lsm_v(3)%qrsws,                &
    3224                                            surf_usm_v(3)%qrsws, n_out ) 
     3292                                           surf_usm_v(3)%qrsws, n_out )
    32253293
    32263294            CASE ( 'nrsws' )
     
    32403308                                           surf_def_v(3)%nrsws,                &
    32413309                                           surf_lsm_v(3)%nrsws,                &
    3242                                            surf_usm_v(3)%nrsws, n_out ) 
     3310                                           surf_usm_v(3)%nrsws, n_out )
    32433311
    32443312            CASE ( 'sasws' )
     
    32583326                                           surf_def_v(3)%sasws,                &
    32593327                                           surf_lsm_v(3)%sasws,                &
    3260                                            surf_usm_v(3)%sasws, n_out ) 
     3328                                           surf_usm_v(3)%sasws, n_out )
    32613329
    32623330            CASE ( 'q_surface' )
     
    32763344                                           surf_def_v(3)%q_surface,            &
    32773345                                           surf_lsm_v(3)%q_surface,            &
    3278                                            surf_usm_v(3)%q_surface, n_out ) 
    3279                                            
     3346                                           surf_usm_v(3)%q_surface, n_out )
     3347
    32803348
    32813349            CASE ( 'theta_surface' )
     
    32953363                                           surf_def_v(3)%pt_surface,           &
    32963364                                           surf_lsm_v(3)%pt_surface,           &
    3297                                            surf_usm_v(3)%pt_surface, n_out ) 
     3365                                           surf_usm_v(3)%pt_surface, n_out )
    32983366
    32993367            CASE ( 'thetav_surface' )
     
    33133381                                           surf_def_v(3)%vpt_surface,          &
    33143382                                           surf_lsm_v(3)%vpt_surface,          &
    3315                                            surf_usm_v(3)%vpt_surface, n_out ) 
     3383                                           surf_usm_v(3)%vpt_surface, n_out )
    33163384
    33173385            CASE ( 'rad_net' )
     
    33313399                                           surf_def_v(3)%rad_net,              &
    33323400                                           surf_lsm_v(3)%rad_net,              &
    3333                                            surf_usm_v(3)%rad_net, n_out ) 
     3401                                           surf_usm_v(3)%rad_net, n_out )
    33343402
    33353403            CASE ( 'rad_lw_in' )
     
    33493417                                           surf_def_v(3)%rad_lw_in,            &
    33503418                                           surf_lsm_v(3)%rad_lw_in,            &
    3351                                            surf_usm_v(3)%rad_lw_in, n_out ) 
     3419                                           surf_usm_v(3)%rad_lw_in, n_out )
    33523420
    33533421            CASE ( 'rad_lw_out' )
     
    33673435                                           surf_def_v(3)%rad_lw_out,           &
    33683436                                           surf_lsm_v(3)%rad_lw_out,           &
    3369                                            surf_usm_v(3)%rad_lw_out, n_out ) 
     3437                                           surf_usm_v(3)%rad_lw_out, n_out )
    33703438
    33713439            CASE ( 'rad_sw_in' )
     
    33853453                                           surf_def_v(3)%rad_sw_in,            &
    33863454                                           surf_lsm_v(3)%rad_sw_in,            &
    3387                                            surf_usm_v(3)%rad_sw_in, n_out ) 
     3455                                           surf_usm_v(3)%rad_sw_in, n_out )
    33883456
    33893457            CASE ( 'rad_sw_out' )
     
    34033471                                           surf_def_v(3)%rad_sw_out,           &
    34043472                                           surf_lsm_v(3)%rad_sw_out,           &
    3405                                            surf_usm_v(3)%rad_sw_out, n_out ) 
     3473                                           surf_usm_v(3)%rad_sw_out, n_out )
    34063474
    34073475            CASE ( 'ghf' )
     
    34213489                                           surf_def_v(3)%ghf,                  &
    34223490                                           surf_lsm_v(3)%ghf,                  &
    3423                                            surf_usm_v(3)%ghf, n_out )         
    3424                                                                                
    3425             CASE ( 'r_a' )                                                     
     3491                                           surf_usm_v(3)%ghf, n_out )
     3492
     3493            CASE ( 'r_a' )
    34263494               CALL surface_data_output_sum_up( surf_def_h(0)%r_a,             &
    34273495                                           surf_def_h(1)%r_a,                  &
     
    34393507                                           surf_def_v(3)%r_a,                  &
    34403508                                           surf_lsm_v(3)%r_a,                  &
    3441                                            surf_usm_v(3)%r_a, n_out )         
    3442                                                                                
    3443             CASE ( 'r_soil' )                                                 
     3509                                           surf_usm_v(3)%r_a, n_out )
     3510
     3511            CASE ( 'r_soil' )
    34443512               CALL surface_data_output_sum_up( surf_def_h(0)%r_soil,          &
    34453513                                           surf_def_h(1)%r_soil,               &
     
    34573525                                           surf_def_v(3)%r_soil,               &
    34583526                                           surf_lsm_v(3)%r_soil,               &
    3459                                            surf_usm_v(3)%r_soil, n_out ) 
     3527                                           surf_usm_v(3)%r_soil, n_out )
    34603528
    34613529            CASE ( 'r_canopy' )
     
    34753543                                           surf_def_v(3)%r_canopy,             &
    34763544                                           surf_lsm_v(3)%r_canopy,             &
    3477                                            surf_usm_v(3)%r_canopy, n_out ) 
     3545                                           surf_usm_v(3)%r_canopy, n_out )
    34783546
    34793547            CASE ( 'r_s' )
     
    34933561                                           surf_def_v(3)%r_s,                  &
    34943562                                           surf_lsm_v(3)%r_s,                  &
    3495                                            surf_usm_v(3)%r_s, n_out ) 
     3563                                           surf_usm_v(3)%r_s, n_out )
    34963564
    34973565
     
    35483616                                           surf_lsm_v(3)%rad_sw_ref,           &
    35493617                                           surf_usm_v(3)%rad_sw_ref, n_out )
    3550                
     3618
    35513619            CASE ( 'rad_sw_res' )
    35523620               CALL surface_data_output_sum_up( surf_def_h(0)%rad_sw_res,      &
     
    36203688                                           surf_lsm_v(3)%rad_lw_res,           &
    36213689                                           surf_usm_v(3)%rad_lw_res, n_out )
    3622                                            
     3690
    36233691            CASE ( 'uvw1' )
    36243692               CALL surface_data_output_sum_up( surf_def_h(0)%uvw_abs,         &
     
    36373705                                           surf_def_v(3)%uvw_abs,              &
    36383706                                           surf_lsm_v(3)%uvw_abs,              &
    3639                                            surf_usm_v(3)%uvw_abs, n_out )                               
     3707                                           surf_usm_v(3)%uvw_abs, n_out )
    36403708
    36413709         END SELECT
    36423710      ENDDO
    3643      
    3644    
     3711
     3712
    36453713   END SUBROUTINE surface_data_output_averaging
    3646    
     3714
    36473715!------------------------------------------------------------------------------!
    36483716! Description:
    36493717! ------------
    3650 !> Sum-up the surface data for average output variables. 
    3651 !------------------------------------------------------------------------------!   
     3718!> Sum-up the surface data for average output variables.
     3719!------------------------------------------------------------------------------!
    36523720   SUBROUTINE surface_data_output_sum_up( var_def_h0, var_def_h1,              &
    36533721                                     var_lsm_h,  var_usm_h,                    &
     
    36563724                                     var_def_v2, var_lsm_v2, var_usm_v2,       &
    36573725                                     var_def_v3, var_lsm_v3, var_usm_v3, n_out )
    3658    
     3726
    36593727      IMPLICIT NONE
    36603728
     
    36623730      INTEGER(iwp) ::  n_out      !< index for output variable
    36633731      INTEGER(iwp) ::  n_surf     !< running index for surface elements
    3664      
     3732
    36653733      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h0 !< output variable at upward-facing default-type surfaces
    36663734      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h1 !< output variable at downward-facing default-type surfaces
     
    36793747      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v2 !< output variable at eastward-facing urban-type surfaces
    36803748      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v3 !< output variable at westward-facing urban-type surfaces
    3681      
    3682 !     
    3683 !--   Set counter variable to zero before the variable is written to 
    3684 !--   the output array. 
     3749
     3750!
     3751!--   Set counter variable to zero before the variable is written to
     3752!--   the output array.
    36853753      n_surf = 0
    3686      
     3754
    36873755!
    36883756!--   Write the horizontal surfaces.
    3689 !--   Before each the variable is written to the output data structure, first 
    3690 !--   check if the variable for the respective surface type is defined. 
     3757!--   Before each the variable is written to the output data structure, first
     3758!--   check if the variable for the respective surface type is defined.
    36913759!--   If a variable is not defined, skip the block and increment the counter
    3692 !--   variable by the number of surface elements of this type. Usually this 
     3760!--   variable by the number of surface elements of this type. Usually this
    36933761!--   is zere, however, there might be the situation that e.g. urban surfaces
    36943762!--   are defined but the respective variable is not allocated for this surface
    3695 !--   type. To write the data on the exact position, increment the counter. 
     3763!--   type. To write the data on the exact position, increment the counter.
    36963764      IF ( ALLOCATED( var_def_h0 ) )  THEN
    3697          DO  m = 1, surf_def_h(0)%ns 
     3765         DO  m = 1, surf_def_h(0)%ns
    36983766            n_surf                        = n_surf + 1
    36993767            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    37013769         ENDDO
    37023770      ELSE
    3703          n_surf = n_surf + surf_def_h(0)%ns 
     3771         n_surf = n_surf + surf_def_h(0)%ns
    37043772      ENDIF
    37053773      IF ( ALLOCATED( var_def_h1 ) )  THEN
    3706          DO  m = 1, surf_def_h(1)%ns 
     3774         DO  m = 1, surf_def_h(1)%ns
    37073775            n_surf                   = n_surf + 1
    37083776            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    37133781      ENDIF
    37143782      IF ( ALLOCATED( var_lsm_h ) )  THEN
    3715          DO  m = 1, surf_lsm_h%ns 
     3783         DO  m = 1, surf_lsm_h%ns
    37163784            n_surf                        = n_surf + 1
    37173785            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    37223790      ENDIF
    37233791      IF ( ALLOCATED( var_usm_h ) )  THEN
    3724          DO  m = 1, surf_usm_h%ns 
     3792         DO  m = 1, surf_usm_h%ns
    37253793            n_surf                        = n_surf + 1
    37263794            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    37333801!--   Write northward-facing
    37343802      IF ( ALLOCATED( var_def_v0 ) )  THEN
    3735          DO  m = 1, surf_def_v(0)%ns 
     3803         DO  m = 1, surf_def_v(0)%ns
    37363804            n_surf                        = n_surf + 1
    37373805            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    37423810      ENDIF
    37433811      IF ( ALLOCATED( var_lsm_v0 ) )  THEN
    3744          DO  m = 1, surf_lsm_v(0)%ns 
     3812         DO  m = 1, surf_lsm_v(0)%ns
    37453813            n_surf                        = n_surf + 1
    37463814            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    37513819      ENDIF
    37523820      IF ( ALLOCATED( var_usm_v0 ) )  THEN
    3753          DO  m = 1, surf_usm_v(0)%ns 
     3821         DO  m = 1, surf_usm_v(0)%ns
    37543822            n_surf                        = n_surf + 1
    37553823            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    37623830!--   Write southward-facing
    37633831      IF ( ALLOCATED( var_def_v1 ) )  THEN
    3764          DO  m = 1, surf_def_v(1)%ns 
     3832         DO  m = 1, surf_def_v(1)%ns
    37653833            n_surf                        = n_surf + 1
    37663834            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    37713839      ENDIF
    37723840      IF ( ALLOCATED( var_lsm_v1 ) )  THEN
    3773          DO  m = 1, surf_lsm_v(1)%ns 
     3841         DO  m = 1, surf_lsm_v(1)%ns
    37743842            n_surf                        = n_surf + 1
    37753843            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    37803848      ENDIF
    37813849      IF ( ALLOCATED( var_usm_v1 ) )  THEN
    3782          DO  m = 1, surf_usm_v(1)%ns 
     3850         DO  m = 1, surf_usm_v(1)%ns
    37833851            n_surf                        = n_surf + 1
    37843852            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    37913859!--   Write eastward-facing
    37923860      IF ( ALLOCATED( var_def_v2 ) )  THEN
    3793          DO  m = 1, surf_def_v(2)%ns 
     3861         DO  m = 1, surf_def_v(2)%ns
    37943862            n_surf                        = n_surf + 1
    37953863            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    38003868      ENDIF
    38013869      IF ( ALLOCATED( var_lsm_v2 ) )  THEN
    3802          DO  m = 1, surf_lsm_v(2)%ns 
     3870         DO  m = 1, surf_lsm_v(2)%ns
    38033871            n_surf                        = n_surf + 1
    38043872            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    38093877      ENDIF
    38103878      IF ( ALLOCATED( var_usm_v2 ) )  THEN
    3811          DO  m = 1, surf_usm_v(2)%ns 
     3879         DO  m = 1, surf_usm_v(2)%ns
    38123880            n_surf                        = n_surf + 1
    38133881            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    38203888!--   Write westward-facing
    38213889      IF ( ALLOCATED( var_def_v3 ) )  THEN
    3822          DO  m = 1, surf_def_v(3)%ns 
     3890         DO  m = 1, surf_def_v(3)%ns
    38233891            n_surf                        = n_surf + 1
    38243892            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    38293897      ENDIF
    38303898      IF ( ALLOCATED( var_lsm_v3 ) )  THEN
    3831          DO  m = 1, surf_lsm_v(3)%ns 
     3899         DO  m = 1, surf_lsm_v(3)%ns
    38323900            n_surf                        = n_surf + 1
    38333901            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    38383906      ENDIF
    38393907      IF ( ALLOCATED( var_usm_v3 ) )  THEN
    3840          DO  m = 1, surf_usm_v(3)%ns 
     3908         DO  m = 1, surf_usm_v(3)%ns
    38413909            n_surf                        = n_surf + 1
    38423910            surfaces%var_av(n_surf,n_out) = surfaces%var_av(n_surf,n_out)      &
     
    38463914         n_surf = n_surf + surf_usm_v(3)%ns
    38473915      ENDIF
    3848    
     3916
    38493917   END SUBROUTINE surface_data_output_sum_up
    3850    
     3918
    38513919!------------------------------------------------------------------------------!
    38523920! Description:
     
    38593927                                      var_def_v1, var_lsm_v1, var_usm_v1,      &
    38603928                                      var_def_v2, var_lsm_v2, var_usm_v2,      &
    3861                                       var_def_v3, var_lsm_v3, var_usm_v3 )                                               
    3862    
     3929                                      var_def_v3, var_lsm_v3, var_usm_v3 )
     3930
    38633931      IMPLICIT NONE
    38643932
    38653933      INTEGER(iwp) ::  m      !< running index for surface elements
    38663934      INTEGER(iwp) ::  n_surf !< running index for surface elements
    3867      
     3935
    38683936      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h0 !< output variable at upward-facing default-type surfaces
    38693937      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_def_h1 !< output variable at downward-facing default-type surfaces
     
    38823950      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v2 !< output variable at eastward-facing urban-type surfaces
    38833951      REAL(wp), DIMENSION(:), ALLOCATABLE, INTENT(IN) ::  var_usm_v3 !< output variable at westward-facing urban-type surfaces
    3884      
    3885 !     
    3886 !--   Set counter variable to zero before the variable is written to 
    3887 !--   the output array. 
     3952
     3953!
     3954!--   Set counter variable to zero before the variable is written to
     3955!--   the output array.
    38883956      n_surf = 0
    3889      
     3957
    38903958!
    38913959!--   Write the horizontal surfaces.
    3892 !--   Before each the variable is written to the output data structure, first 
    3893 !--   check if the variable for the respective surface type is defined. 
     3960!--   Before each the variable is written to the output data structure, first
     3961!--   check if the variable for the respective surface type is defined.
    38943962!--   If a variable is not defined, skip the block and increment the counter
    3895 !--   variable by the number of surface elements of this type. Usually this 
     3963!--   variable by the number of surface elements of this type. Usually this
    38963964!--   is zere, however, there might be the situation that e.g. urban surfaces
    38973965!--   are defined but the respective variable is not allocated for this surface
    3898 !--   type. To write the data on the exact position, increment the counter. 
     3966!--   type. To write the data on the exact position, increment the counter.
    38993967      IF ( ALLOCATED( var_def_h0 ) )  THEN
    3900          DO  m = 1, surf_def_h(0)%ns 
     3968         DO  m = 1, surf_def_h(0)%ns
    39013969            n_surf                   = n_surf + 1
    39023970            surfaces%var_out(n_surf) = var_def_h0(m)
    39033971         ENDDO
    39043972      ELSE
    3905          n_surf = n_surf + surf_def_h(0)%ns 
     3973         n_surf = n_surf + surf_def_h(0)%ns
    39063974      ENDIF
    39073975      IF ( ALLOCATED( var_def_h1 ) )  THEN
    3908          DO  m = 1, surf_def_h(1)%ns 
     3976         DO  m = 1, surf_def_h(1)%ns
    39093977            n_surf                   = n_surf + 1
    39103978            surfaces%var_out(n_surf) = var_def_h1(m)
     
    39143982      ENDIF
    39153983      IF ( ALLOCATED( var_lsm_h ) )  THEN
    3916          DO  m = 1, surf_lsm_h%ns 
     3984         DO  m = 1, surf_lsm_h%ns
    39173985            n_surf                   = n_surf + 1
    39183986            surfaces%var_out(n_surf) = var_lsm_h(m)
     
    39223990      ENDIF
    39233991      IF ( ALLOCATED( var_usm_h ) )  THEN
    3924          DO  m = 1, surf_usm_h%ns 
     3992         DO  m = 1, surf_usm_h%ns
    39253993            n_surf                   = n_surf + 1
    39263994            surfaces%var_out(n_surf) = var_usm_h(m)
     
    39324000!--   Write northward-facing
    39334001      IF ( ALLOCATED( var_def_v0 ) )  THEN
    3934          DO  m = 1, surf_def_v(0)%ns 
     4002         DO  m = 1, surf_def_v(0)%ns
    39354003            n_surf                   = n_surf + 1
    39364004            surfaces%var_out(n_surf) = var_def_v0(m)
     
    39404008      ENDIF
    39414009      IF ( ALLOCATED( var_lsm_v0 ) )  THEN
    3942          DO  m = 1, surf_lsm_v(0)%ns 
     4010         DO  m = 1, surf_lsm_v(0)%ns
    39434011            n_surf                   = n_surf + 1
    39444012            surfaces%var_out(n_surf) = var_lsm_v0(m)
     
    39484016      ENDIF
    39494017      IF ( ALLOCATED( var_usm_v0 ) )  THEN
    3950          DO  m = 1, surf_usm_v(0)%ns 
     4018         DO  m = 1, surf_usm_v(0)%ns
    39514019            n_surf                   = n_surf + 1
    39524020            surfaces%var_out(n_surf) = var_usm_v0(m)
     
    39584026!--   Write southward-facing
    39594027      IF ( ALLOCATED( var_def_v1 ) )  THEN
    3960          DO  m = 1, surf_def_v(1)%ns 
     4028         DO  m = 1, surf_def_v(1)%ns
    39614029            n_surf                   = n_surf + 1
    39624030            surfaces%var_out(n_surf) = var_def_v1(m)
     
    39664034      ENDIF
    39674035      IF ( ALLOCATED( var_lsm_v1 ) )  THEN
    3968          DO  m = 1, surf_lsm_v(1)%ns 
     4036         DO  m = 1, surf_lsm_v(1)%ns
    39694037            n_surf                   = n_surf + 1
    39704038            surfaces%var_out(n_surf) = var_lsm_v1(m)
     
    39744042      ENDIF
    39754043      IF ( ALLOCATED( var_usm_v1 ) )  THEN
    3976          DO  m = 1, surf_usm_v(1)%ns 
     4044         DO  m = 1, surf_usm_v(1)%ns
    39774045            n_surf                   = n_surf + 1
    39784046            surfaces%var_out(n_surf) = var_usm_v1(m)
     
    39844052!--   Write eastward-facing
    39854053      IF ( ALLOCATED( var_def_v2 ) )  THEN
    3986          DO  m = 1, surf_def_v(2)%ns 
     4054         DO  m = 1, surf_def_v(2)%ns
    39874055            n_surf                   = n_surf + 1
    39884056            surfaces%var_out(n_surf) = var_def_v2(m)
     
    39924060      ENDIF
    39934061      IF ( ALLOCATED( var_lsm_v2 ) )  THEN
    3994          DO  m = 1, surf_lsm_v(2)%ns 
     4062         DO  m = 1, surf_lsm_v(2)%ns
    39954063            n_surf                   = n_surf + 1
    39964064            surfaces%var_out(n_surf) = var_lsm_v2(m)
     
    40004068      ENDIF
    40014069      IF ( ALLOCATED( var_usm_v2 ) )  THEN
    4002          DO  m = 1, surf_usm_v(2)%ns 
     4070         DO  m = 1, surf_usm_v(2)%ns
    40034071            n_surf                   = n_surf + 1
    40044072            surfaces%var_out(n_surf) = var_usm_v2(m)
     
    40104078!--   Write westward-facing
    40114079      IF ( ALLOCATED( var_def_v3 ) )  THEN
    4012          DO  m = 1, surf_def_v(3)%ns 
     4080         DO  m = 1, surf_def_v(3)%ns
    40134081            n_surf                   = n_surf + 1
    40144082            surfaces%var_out(n_surf) = var_def_v3(m)
     
    40184086      ENDIF
    40194087      IF ( ALLOCATED( var_lsm_v3 ) )  THEN
    4020          DO  m = 1, surf_lsm_v(3)%ns 
     4088         DO  m = 1, surf_lsm_v(3)%ns
    40214089            n_surf                   = n_surf + 1
    40224090            surfaces%var_out(n_surf) = var_lsm_v3(m)
     
    40264094      ENDIF
    40274095      IF ( ALLOCATED( var_usm_v3 ) )  THEN
    4028          DO  m = 1, surf_usm_v(3)%ns 
     4096         DO  m = 1, surf_usm_v(3)%ns
    40294097            n_surf                   = n_surf + 1
    40304098            surfaces%var_out(n_surf) = var_usm_v3(m)
     
    40334101         n_surf = n_surf + surf_usm_v(3)%ns
    40344102      ENDIF
    4035    
     4103
    40364104   END SUBROUTINE surface_data_output_collect
    4037    
     4105
    40384106!------------------------------------------------------------------------------!
    40394107! Description:
     
    40454113       IMPLICIT NONE
    40464114
    4047        CHARACTER (LEN=80) ::  line  !< dummy string that contains the current line of the parameter file 
    4048        
     4115       CHARACTER (LEN=80) ::  line  !< dummy string that contains the current line of the parameter file
     4116
    40494117
    40504118       NAMELIST /surface_data_output_parameters/                               &
     
    40534121                                  skip_time_dosurf, skip_time_dosurf_av,       &
    40544122                                  to_netcdf, to_vtk
    4055                                  
     4123
    40564124       line = ' '
    4057  
     4125
    40584126!
    40594127!--    Try to find the namelist
     
    40754143 10    BACKSPACE( 11 )
    40764144       READ( 11 , '(A)') line
    4077        CALL parin_fail_message( 'surface_data_output_parameters', line )     
    4078        
     4145       CALL parin_fail_message( 'surface_data_output_parameters', line )
     4146
    40794147 14    CONTINUE
    4080        
     4148
    40814149
    40824150    END SUBROUTINE surface_data_output_parin
    4083    
    4084    
     4151
     4152
    40854153!------------------------------------------------------------------------------!
    40864154! Description:
    40874155! ------------
    4088 !> Check the input parameters for consistency. Further pre-process the given 
     4156!> Check the input parameters for consistency. Further pre-process the given
    40894157!> output variables, i.e. separate them into average and non-average output
    4090 !> variables and map them onto internal output array. 
     4158!> variables and map them onto internal output array.
    40914159!------------------------------------------------------------------------------!
    40924160    SUBROUTINE surface_data_output_check_parameters
     
    40954163           ONLY:  averaging_interval, dt_data_output, initializing_actions,    &
    40964164                  message_string
    4097                  
     4165
    40984166       USE pegrid,                                                             &
    40994167           ONLY:  numprocs_previous_run
     
    41254193                        'PA0536', 1, 2, 0, 6, 0 )
    41264194       ENDIF
    4127        
     4195
    41284196#if ! defined( __netcdf4_parallel )
    41294197!
     
    41474215      ENDIF
    41484216!
    4149 !--   Count number of output variables and separate output strings for 
     4217!--   Count number of output variables and separate output strings for
    41504218!--   average and non-average output variables.
    41514219      n_out = 0
     
    41944262            CASE ( 'usws', 'vsws' )
    41954263               unit = 'm2/s2'
    4196            
     4264
    41974265            CASE ( 'qcsws', 'ncsws', 'qrsws', 'nrsws', 'sasws' )
    41984266
     
    42384306
    42394307    END SUBROUTINE surface_data_output_check_parameters
    4240    
    4241    
     4308
     4309
    42424310!------------------------------------------------------------------------------!
    42434311! Description:
     
    42464314!------------------------------------------------------------------------------!
    42474315    SUBROUTINE surface_data_output_last_action( av )
    4248  
     4316
    42494317      USE control_parameters,                                                  &
    42504318          ONLY:  io_blocks, io_group
     
    42544322
    42554323      IMPLICIT NONE
    4256      
     4324
    42574325      INTEGER(iwp) ::  av     !< id indicating average or non-average data output
    42584326      INTEGER(iwp) ::  i      !< loop index
     
    42764344            CALL MPI_BARRIER( comm2d, ierr )
    42774345#endif
    4278          ENDDO   
     4346         ENDDO
    42794347      ENDIF
    42804348
    4281     END SUBROUTINE surface_data_output_last_action   
    4282    
     4349    END SUBROUTINE surface_data_output_last_action
     4350
    42834351!------------------------------------------------------------------------------!
    42844352! Description:
     
    42914359       USE control_parameters,                                                 &
    42924360           ONLY: length, restart_string
    4293        
     4361
    42944362       IMPLICIT NONE
    4295        
     4363
    42964364       LOGICAL, INTENT(OUT)  ::  found !< flag indicating if variable was found
    4297        
     4365
    42984366       found = .TRUE.
    4299        
     4367
    43004368       SELECT CASE ( restart_string(1:length) )
    4301        
     4369
    43024370          CASE ( 'average_count_surf' )
    43034371             READ ( 13 )  average_count_surf
    4304        
     4372
    43054373          CASE DEFAULT
    4306        
     4374
    43074375             found = .FALSE.
    4308        
     4376
    43094377       END SELECT
    43104378
    43114379
    43124380    END SUBROUTINE surface_data_output_rrd_global
    4313    
     4381
    43144382!------------------------------------------------------------------------------!
    43154383! Description:
     
    43244392       USE control_parameters,                                                 &
    43254393           ONLY: length, restart_string
    4326            
     4394
    43274395       IMPLICIT NONE
    43284396
     
    43324400       INTEGER(iwp)       ::  ns_h_on_file_usm  !< number of horizontal surface elements (urban type) on file
    43334401       INTEGER(iwp)       ::  nxlc              !< index of left boundary on current subdomain
    4334        INTEGER(iwp)       ::  nxlf              !< index of left boundary on former subdomain 
    4335        INTEGER(iwp)       ::  nxl_on_file       !< index of left boundary on former local domain 
     4402       INTEGER(iwp)       ::  nxlf              !< index of left boundary on former subdomain
     4403       INTEGER(iwp)       ::  nxl_on_file       !< index of left boundary on former local domain
    43364404       INTEGER(iwp)       ::  nxrc              !< index of right boundary on current subdomain
    43374405       INTEGER(iwp)       ::  nxrf              !< index of right boundary on former subdomain
    4338        INTEGER(iwp)       ::  nxr_on_file       !< index of right boundary on former local domain 
     4406       INTEGER(iwp)       ::  nxr_on_file       !< index of right boundary on former local domain
    43394407       INTEGER(iwp)       ::  nync              !< index of north boundary on current subdomain
    43404408       INTEGER(iwp)       ::  nynf              !< index of north boundary on former subdomain
    4341        INTEGER(iwp)       ::  nyn_on_file       !< index of north boundary on former local domain 
    4342        INTEGER(iwp)       ::  nysc              !< index of south boundary on current subdomain 
     4409       INTEGER(iwp)       ::  nyn_on_file       !< index of north boundary on former local domain
     4410       INTEGER(iwp)       ::  nysc              !< index of south boundary on current subdomain
    43434411       INTEGER(iwp)       ::  nysf              !< index of south boundary on former subdomain
    43444412       INTEGER(iwp)       ::  nys_on_file       !< index of south boundary on former local domain
     
    43544422          CASE ( 'surfaces%var_av' )
    43554423             IF ( k == 1 )  READ ( 13 )  surfaces%var_av
    4356              
     4424
    43574425          CASE DEFAULT
    43584426
     
    43634431
    43644432    END SUBROUTINE surface_data_output_rrd_local
    4365    
     4433
    43664434!------------------------------------------------------------------------------!
    43674435! Description:
     
    43774445
    43784446    END SUBROUTINE surface_data_output_wrd_global
    4379    
     4447
    43804448!------------------------------------------------------------------------------!
    43814449! Description:
Note: See TracChangeset for help on using the changeset viewer.