Index: palm/trunk/TUTORIALS/cases/lsm_short/USER_CODE/user_module.f90
===================================================================
--- palm/trunk/TUTORIALS/cases/lsm_short/USER_CODE/user_module.f90	(revision 4397)
+++ palm/trunk/TUTORIALS/cases/lsm_short/USER_CODE/user_module.f90	(revision 4765)
@@ -1,20 +1,20 @@
 !> @file user_module.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+!
 !
 ! Current revisions:
@@ -24,10 +24,40 @@
 ! Former revisions:
 ! -----------------
-! $Id: user_module.f90 3986 2019-05-20 14:08:14Z Giersch $
+! $Id: user_module.f90 4535 2020-05-15 12:07:23Z raasch $
+! bugfix for restart data format query
+! 
+! 4517 2020-05-03 14:29:30Z raasch
+! added restart with MPI-IO for reading local arrays
+!
+! 4504 2020-04-20 12:11:24Z raasch
+! hint for setting rmask arrays added
+! 
+! 4497 2020-04-15 10:20:51Z raasch
+! file re-formatted to follow the PALM coding standard
+!
+! 4495 2020-04-13 20:11:20Z raasch
+! restart data handling with MPI-IO added
+!
+! 4360 2020-01-07 11:25:50Z suehring
+! Introduction of wall_flags_total_0, which currently sets bits based on static topography
+! information used in wall_flags_static_0
+!
+! 4329 2019-12-10 15:46:36Z motisi
+! Renamed wall_flags_0 to wall_flags_static_0
+!
+! 4287 2019-11-01 14:50:20Z raasch
+! reading of namelist file and actions in case of namelist errors revised so that statement labels
+! and goto statements are not required any more; this revision also removes a previous bug which
+! appeared when the namelist has been commented out in the namelist file
+!
+! 4182 2019-08-22 15:20:23Z scharf
+! Corrected "Former revisions" section
+!
+! 3986 2019-05-20 14:08:14Z Giersch
 ! Redundant integration of control parameters in user_rrd_global removed
-! 
+!
 ! 3911 2019-04-17 12:26:19Z knoop
 ! Bugfix: added before_prognostic_equations case in user_actions
-! 
+!
 ! 3768 2019-02-27 14:35:58Z raasch
 ! variables commented + statements added to avoid compiler warnings about unused variables
@@ -35,43 +65,10 @@
 ! 3767 2019-02-27 08:18:02Z raasch
 ! unused variable for file index removed from rrd-subroutines parameter list
-! 
+!
 ! 3747 2019-02-16 15:15:23Z gronemeier
 ! Add routine user_init_arrays
-! 
+!
 ! 3703 2019-01-29 16:43:53Z knoop
 ! An example for a user defined global variable has been added (Giersch)
-! 
-! 2718 2018-01-02 08:49:38Z suehring
-! Corrected "Former revisions" section
-! 
-! 2696 2017-12-14 17:12:51Z kanani
-! Change in file header (GPL part)
-!
-! 2101 2017-01-05 16:42:31Z suehring
-!
-! 2000 2016-08-20 18:09:15Z knoop
-! Forced header and separation lines into 80 columns
-! 
-! 1873 2016-04-18 14:50:06Z maronga
-! Module renamed (removed _mod)
-! 
-! 
-! 1850 2016-04-08 13:29:27Z maronga
-! Module renamed
-! 
-! 
-! 1682 2015-10-07 23:56:08Z knoop
-! Code annotations made doxygen readable 
-!
-! 1320 2014-03-20 08:40:49Z raasch
-! kind-parameters added to all INTEGER and REAL declaration statements, 
-! kinds are defined in new module kinds, 
-! old module precision_kind is removed,
-! revision history before 2012 removed,
-! comment fields (!:) to be used for variable explanations added to
-! all variable declaration statements 
-!
-! 1036 2012-10-22 13:43:42Z raasch
-! code put under GPL (PALM 3.9)
 !
 ! Revision 1.1  1998/03/24 15:29:04  raasch
@@ -81,10 +78,9 @@
 ! Description:
 ! ------------
-!> Declaration of user-defined variables. This module may only be used
-!> in the user-defined routines (contained in user_interface.f90).
-!------------------------------------------------------------------------------!
+!> Declaration of user-defined variables. This module may only be used in the user-defined routines
+!> (contained in user_interface.f90).
+!--------------------------------------------------------------------------------------------------!
  MODULE user
 
-
     USE arrays_3d
 
@@ -105,19 +101,19 @@
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  dots_num_palm   !< 
-    INTEGER(iwp) ::  dots_num_user = 0  !< 
-    INTEGER(iwp) ::  user_idummy     !< 
-    
-    LOGICAL ::  user_module_enabled = .FALSE.   !< 
-    
-    REAL(wp) ::  user_rdummy   !< 
+    INTEGER(iwp) ::  dots_num_palm      !<
+    INTEGER(iwp) ::  dots_num_user = 0  !<
+    INTEGER(iwp) ::  user_idummy        !<
+
+    LOGICAL ::  user_module_enabled = .FALSE.  !<
+
+    REAL(wp) ::  user_rdummy  !<
 
 !
 !-- Sample for user-defined output
-!    REAL(wp) :: global_parameter !< user defined global parameter 
-!
-!    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u2       !< user defined array
-!    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u2_av    !< user defined array
-!    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  ustvst   !< user defined array
+!    REAL(wp) :: global_parameter  !< user defined global parameter
+!
+!    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u2      !< user defined array
+!    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u2_av   !< user defined array
+!    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  ustvst  !< user defined array
      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_h, v_h_av       !< user defined array
 
@@ -128,28 +124,29 @@
 !
 !- Public functions
-    PUBLIC &
-       user_parin, &
-       user_check_parameters, &
-       user_check_data_output_ts, &
-       user_check_data_output_pr, &
-       user_check_data_output, &
-       user_define_netcdf_grid, &
-       user_init, &
-       user_init_arrays, &
-       user_header, &
-       user_actions, &
-       user_3d_data_averaging, &
-       user_data_output_2d, &
-       user_data_output_3d, &
-       user_statistics, &
-       user_rrd_global, &
-       user_rrd_local, &
-       user_wrd_global, &
-       user_wrd_local, &
-       user_last_actions
+    PUBLIC                                                                                         &
+       user_actions,                                                                               &
+       user_check_data_output,                                                                     &
+       user_check_data_output_pr,                                                                  &
+       user_check_data_output_ts,                                                                  &
+       user_check_parameters,                                                                      &
+       user_data_output_2d,                                                                        &
+       user_data_output_3d,                                                                        &
+       user_define_netcdf_grid,                                                                    &
+       user_header,                                                                                &
+       user_init,                                                                                  &
+       user_init_arrays,                                                                           &
+       user_last_actions,                                                                          &
+       user_parin,                                                                                 &
+       user_rrd_global,                                                                            &
+       user_rrd_local,                                                                             &
+       user_statistics,                                                                            &
+       user_3d_data_averaging,                                                                     &
+       user_wrd_global,                                                                            &
+       user_wrd_local
+
 
 !
 !- Public parameters, constants and initial values
-   PUBLIC &
+   PUBLIC                                                                                          &
       user_module_enabled
 
@@ -212,9 +209,11 @@
 
     INTERFACE user_rrd_global
-       MODULE PROCEDURE user_rrd_global
+       MODULE PROCEDURE user_rrd_global_ftn
+       MODULE PROCEDURE user_rrd_global_mpi
     END INTERFACE user_rrd_global
 
     INTERFACE user_rrd_local
-       MODULE PROCEDURE user_rrd_local
+       MODULE PROCEDURE user_rrd_local_ftn
+       MODULE PROCEDURE user_rrd_local_mpi
     END INTERFACE user_rrd_local
 
@@ -235,24 +234,23 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Parin for &user_parameters for user module
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_parin
 
-
-    CHARACTER (LEN=80) ::  line   !< 
-
-    INTEGER(iwp) ::  i                 !< 
-    INTEGER(iwp) ::  j                 !< 
-
-
-    NAMELIST /user_parameters/  &
-       user_module_enabled, &
-       data_output_pr_user, &
-       data_output_user, &
-       region, &
-       data_output_masks_user
+    CHARACTER (LEN=80) ::  line  !< string containing the last line read from namelist file
+
+    INTEGER(iwp) ::  i          !<
+    INTEGER(iwp) ::  io_status  !< status after reading the namelist file
+    INTEGER(iwp) ::  j          !<
+
+
+    NAMELIST /user_parameters/                                                                     &
+       data_output_masks_user,                                                                     &
+       data_output_pr_user,                                                                        &
+       data_output_user,                                                                           &
+       region
 
 !
@@ -263,39 +261,37 @@
 
 !
-!-- Set revision number of this default interface version. It will be checked within
-!-- the main program (palm). Please change the revision number in case that the
-!-- current revision does not match with previous revisions (e.g. if routines
-!-- have been added/deleted or if parameter lists in subroutines have been changed).
-    user_interface_current_revision = 'r3703'
-
-!
-!-- Position the namelist-file at the beginning (it was already opened in
-!-- parin), search for user-defined namelist-group ("userpar", but any other
-!-- name can be choosed) and position the file at this line.
+!-- Set revision number of this default interface version. It will be checked within the main
+!-- program (palm). Please change the revision number in case that the current revision does not
+!-- match with previous revisions (e.g. if routines have been added/deleted or if parameter lists
+!-- in subroutines have been changed).
+    user_interface_current_revision = 'r4495'
+
+!
+!-- Position the namelist-file at the beginning (it has already been opened in parin), and try to
+!-- read (find) a namelist named "user_parameters".
     REWIND ( 11 )
-
-    line = ' '
-    DO WHILE ( INDEX( line, '&user_parameters' ) == 0 )
-       READ ( 11, '(A)', END=12 )  line
-    ENDDO
-    BACKSPACE ( 11 )
-
-!-- Set default module switch to true
-    user_module_enabled = .TRUE.
-
-!-- Read user-defined namelist
-    READ ( 11, user_parameters, ERR = 10 )
-
-    GOTO 12
-
-10  BACKSPACE( 11 )
-    READ( 11 , '(A)') line
-    CALL parin_fail_message( 'user_parameters', line )
-
-12  CONTINUE
-
-!
-!-- Determine the number of user-defined profiles and append them to the
-!-- standard data output (data_output_pr)
+    READ( 11, user_parameters, IOSTAT=io_status )
+
+!
+!-- Actions depending on the READ status
+    IF ( io_status == 0 )  THEN
+!
+!--    User namelist found and correctly read. Set default module switch to true. This activates
+!--    calls of the user-interface subroutines.
+       user_module_enabled = .TRUE.
+
+    ELSEIF ( io_status > 0 )  THEN
+!
+!--    User namelist was found, but contained errors. Print an error message containing the line
+!--    that caused the problem
+       BACKSPACE( 11 )
+       READ( 11 , '(A)') line
+       CALL parin_fail_message( 'user_parameters', line )
+
+    ENDIF
+
+!
+!-- Determine the number of user-defined profiles and append them to the standard data output
+!-- (data_output_pr)
     IF ( user_module_enabled )  THEN
        IF ( data_output_pr_user(1) /= ' ' )  THEN
@@ -318,14 +314,14 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Check &userpar control parameters and deduce further quantities.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_check_parameters
 
-
-!-- Here the user may add code to check the validity of further &userpar 
-!-- control parameters or deduce further quantities.
+!
+!-- Here the user may add code to check the validity of further &userpar control parameters or
+!-- deduce further quantities.
 
 
@@ -333,16 +329,16 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Set module-specific timeseries units and labels
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_check_data_output_ts( dots_max, dots_num, dots_label, dots_unit )
 
-
-    INTEGER(iwp),      INTENT(IN)     ::  dots_max
-    INTEGER(iwp),      INTENT(INOUT)  ::  dots_num
-    CHARACTER (LEN=*), DIMENSION(dots_max), INTENT(INOUT)  :: dots_label
-    CHARACTER (LEN=*), DIMENSION(dots_max), INTENT(INOUT)  :: dots_unit
+    INTEGER(iwp),      INTENT(IN)     ::  dots_max  !<
+    INTEGER(iwp),      INTENT(INOUT)  ::  dots_num  !<
+
+    CHARACTER(LEN=*), DIMENSION(dots_max), INTENT(INOUT)  ::  dots_label  !<
+    CHARACTER(LEN=*), DIMENSION(dots_max), INTENT(INOUT)  ::  dots_unit   !<
 
 !
@@ -351,11 +347,9 @@
 
 !
-!-- Sample for user-defined time series
-!-- For each time series quantity you have to give a label and a unit,
-!-- which will be used for the NetCDF file. They must not contain more than
-!-- seven characters. The value of dots_num has to be increased by the
-!-- number of new time series quantities. Its old value has to be store in
-!-- dots_num_palm. See routine user_statistics on how to output calculate
-!-- and output these quantities.
+!-- Sample for user-defined time series:
+!-- For each time series quantity you have to give a label and a unit, which will be used for the
+!-- NetCDF file. They must not contain more than seven characters. The value of dots_num has to be
+!-- increased by the number of new time series quantities. Its old value has to be stored in
+!-- dots_num_palm. See routine user_statistics on how to calculate and output these quantities.
 
 !    dots_num_palm = dots_num
@@ -375,12 +369,11 @@
 
 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Set the unit of user defined profile output quantities. For those variables
-!> not recognized by the user, the parameter unit is set to "illegal", which
-!> tells the calling routine that the output variable is not defined and leads
-!> to a program abort.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Set the unit of user defined profile output quantities. For those variables not recognized by the
+!> user, the parameter unit is set to "illegal", which tells the calling routine that the
+!> output variable is not defined and leads to a program abort.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_check_data_output_pr( variable, var_count, unit, dopr_unit )
 
@@ -389,10 +382,10 @@
 
 
-    CHARACTER (LEN=*) ::  unit     !< 
-    CHARACTER (LEN=*) ::  variable !< 
+    CHARACTER (LEN=*) ::  unit      !<
+    CHARACTER (LEN=*) ::  variable  !<
     CHARACTER (LEN=*) ::  dopr_unit !< local value of dopr_unit
 
-!    INTEGER(iwp) ::  user_pr_index !<
-    INTEGER(iwp) ::  var_count     !<
+!    INTEGER(iwp) ::  user_pr_index  !<
+    INTEGER(iwp) ::  var_count      !<
 
 !
@@ -404,20 +397,18 @@
 !
 !--    Uncomment and extend the following lines, if necessary.
-!--    Add additional CASE statements depending on the number of quantities
-!--    for which profiles are to be calculated. The respective calculations
-!--    to be performed have to be added in routine user_statistics.
-!--    The quantities are (internally) identified by a user-profile-number
-!--    (see variable "user_pr_index" below). The first user-profile must be assigned
-!--    the number "pr_palm+1", the second one "pr_palm+2", etc. The respective
-!--    user-profile-numbers have also to be used in routine user_statistics!
-!       CASE ( 'u*v*' )                      ! quantity string as given in
-!                                            ! data_output_pr_user
+!--    Add additional CASE statements depending on the number of quantities for which profiles are
+!--    to be calculated. The respective calculations to be performed have to be added in routine
+!--    user_statistics. The quantities are (internally) identified by a user-profile-number
+!--    (see variable "user_pr_index" below). The first user-profile must be assigned the number
+!--    "pr_palm+1", the second one "pr_palm+2", etc. The respective user-profile-numbers have also
+!--    to be used in routine user_statistics!
+!       CASE ( 'u*v*' )                      ! quantity string as given in data_output_pr_user
 !          user_pr_index = pr_palm + 1
 !          dopr_index(var_count)  = user_pr_index    ! quantities' user-profile-number
 !          dopr_unit = 'm2/s2'  ! quantity unit
 !          unit = dopr_unit
-!          hom(:,2,user_pr_index,:)       = SPREAD( zu, 2, statistic_regions+1 )
-!                                            ! grid on which the quantity is
-!                                            ! defined (use zu or zw)
+!          hom(:,2,user_pr_index,:) = SPREAD( zu, 2, statistic_regions+1 )
+!                                            ! grid on which the quantity is defined (use zu or zw)
+!
 
        CASE DEFAULT
@@ -430,17 +421,16 @@
 
 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Set the unit of user defined output quantities. For those variables
-!> not recognized by the user, the parameter unit is set to "illegal", which
-!> tells the calling routine that the output variable is not defined and leads
-!> to a program abort.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Set the unit of user defined output quantities. For those variables not recognized by the user,
+!> the parameter unit is set to "illegal", which tells the calling routine that the output variable
+!> is not defined and leads to a program abort.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_check_data_output( variable, unit )
 
 
-    CHARACTER (LEN=*) ::  unit     !< 
-    CHARACTER (LEN=*) ::  variable !<
+    CHARACTER (LEN=*) ::  unit      !<
+    CHARACTER (LEN=*) ::  variable  !<
 
 
@@ -451,11 +441,11 @@
 !       CASE ( 'u2' )
 !          unit = 'm2/s2'
-
+!
+!       CASE ( 'u*v*' )
+!          unit = 'm2/s2'
+!
       CASE ( 'v_h' )
          unit = 'm/s'
-!
-!       CASE ( 'u*v*' )
-!          unit = 'm2/s2'
-!
+
        CASE DEFAULT
           unit = 'illegal'
@@ -467,9 +457,9 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Initialize user-defined arrays
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_init_arrays
 
@@ -486,9 +476,14 @@
     ALLOCATE( v_h(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 
+
 !
 !-- Example for defining a statistic region:
+!-- ATTENTION: rmask = 0 is required at the ghost boundaries to guarantee correct statistic
+!--            evaluations (otherwise ghost points would be counted twice). This setting has
+!--            already been cared for in routine init_3d_model. Please don't set the ghost points
+!--            /= 0. i.e. run the following loop only over nxl,nxr and nys,nyn.
 !     IF ( statistic_regions >= 1 )  THEN
 !        region = 1
-! 
+!
 !        rmask(:,:,region) = 0.0_wp
 !        DO  i = nxl, nxr
@@ -501,5 +496,5 @@
 !           ENDIF
 !        ENDDO
-! 
+!
 !     ENDIF
 
@@ -507,13 +502,13 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Execution of user-defined initializing actions
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_init
 
 
-!    CHARACTER (LEN=20) :: field_char   !<
+!    CHARACTER(LEN=20) :: field_char  !<
 !
 !-- Here the user-defined initializing actions follow:
@@ -526,11 +521,10 @@
 
 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Set the grids on which user-defined output quantities are defined.
-!> Allowed values for grid_x are "x" and "xu", for grid_y "y" and "yv", and
-!> for grid_z "zu" and "zw".
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Set the grids on which user-defined output quantities are defined. Allowed values for grid_x are
+!> "x" and "xu", for grid_y "y" and "yv", and for grid_z "zu" and "zw".
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_define_netcdf_grid( variable, found, grid_x, grid_y, grid_z )
 
@@ -560,5 +554,4 @@
 !          grid_z = 'zu'
 
-
       CASE ( 'v_h', 'v_h_av' )
          found  = .TRUE.
@@ -581,18 +574,17 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Print a header with user-defined information.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_header( io )
 
 
-    INTEGER(iwp) ::  i    !< 
-    INTEGER(iwp) ::  io   !< 
-
-!
-!-- If no user-defined variables are read from the namelist-file, no
-!-- information will be printed.
+    INTEGER(iwp) ::  i   !<
+    INTEGER(iwp) ::  io  !<
+
+!
+!-- If no user-defined variables are read from the namelist-file, no information will be printed.
     IF ( .NOT. user_module_enabled )  THEN
        WRITE ( io, 100 )
@@ -614,7 +606,6 @@
 !-- Format-descriptors
 100 FORMAT (//' *** no user-defined variables found'/)
-110 FORMAT (//1X,78('#')                                                       &
-            //' User-defined variables and actions:'/                          &
-              ' -----------------------------------'//)
+110 FORMAT (//1X,78('#') // ' User-defined variables and actions:' /                               &
+            ' -----------------------------------'//)
 200 FORMAT (' Output of profiles and time series for following regions:' /)
 201 FORMAT (4X,'Region ',I1,':   ',A)
@@ -624,24 +615,23 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Call for all grid points
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_actions( location )
 
 
-    CHARACTER (LEN=*) ::  location !< 
-
-    INTEGER(iwp) ::  i !< 
-    INTEGER(iwp) ::  j !< 
-    INTEGER(iwp) ::  k !< 
+    CHARACTER(LEN=*) ::  location  !<
+
+    INTEGER(iwp) ::  i  !<
+    INTEGER(iwp) ::  j  !<
+    INTEGER(iwp) ::  k  !<
 
     CALL cpu_log( log_point(24), 'user_actions', 'start' )
 
 !
-!-- Here the user-defined actions follow
-!-- No calls for single grid points are allowed at locations before and
-!-- after the timestep, since these calls are not within an i,j-loop
+!-- Here the user-defined actions follow. No calls for single grid points are allowed at locations
+!-- before and after the timestep, since these calls are not within an i,j-loop
     SELECT CASE ( location )
 
@@ -656,6 +646,5 @@
        CASE ( 'after_integration' )
 !
-!--       Enter actions to be done after every time integration (before
-!--       data output)
+!--       Enter actions to be done after every time integration (before data output)
 !--       Sample for user-defined output:
 !          DO  i = nxlg, nxrg
@@ -670,5 +659,5 @@
 !                DO  k = nzb, nzt+1
 !                   ustvst(k,j,i) =  &
-!                      ( 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) - hom(k,1,1,0) ) * &
+!                      ( 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) - hom(k,1,1,0) ) *                      &
 !                      ( 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) - hom(k,1,2,0) )
 !                ENDDO
@@ -679,10 +668,9 @@
              DO  j = nysg, nyng
                 DO  k = nzb, nzt
-                   v_h(k,j,i) = SQRT(u(k,j,i)**2.+v(k,j,i)**2.)
+                   v_h(k,j,i) = SQRT( u(k,j,i)**2.0_wp + v(k,j,i)**2.0_wp )
                 ENDDO
              ENDDO
           ENDDO
 
-
        CASE ( 'after_timestep' )
 !
@@ -726,16 +714,16 @@
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Call for grid point i,j
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_actions_ij( i, j, location )
 
 
-    CHARACTER (LEN=*) ::  location
-
-    INTEGER(iwp) ::  i
-    INTEGER(iwp) ::  j
+    CHARACTER(LEN=*) ::  location  !<
+
+    INTEGER(iwp) ::  i  !<
+    INTEGER(iwp) ::  j  !<
 
 !
@@ -782,19 +770,19 @@
 
 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Sum up and time-average user-defined output quantities as well as allocate
-!> the array necessary for storing the average.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Sum up and time-average user-defined output quantities as well as allocate the array necessary
+!> for storing the average.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_3d_data_averaging( mode, variable )
 
 
-    CHARACTER (LEN=*) ::  mode    !< 
-    CHARACTER (LEN=*) :: variable !< 
-
-    INTEGER(iwp) ::  i !< 
-    INTEGER(iwp) ::  j !< 
-    INTEGER(iwp) ::  k !< 
+    CHARACTER(LEN=*) ::  mode      !<
+    CHARACTER(LEN=*) ::  variable  !<
+
+    INTEGER(iwp) ::  i  !<
+    INTEGER(iwp) ::  j  !<
+    INTEGER(iwp) ::  k  !<
 
     IF ( mode == 'allocate' )  THEN
@@ -804,6 +792,6 @@
 !
 !--       Uncomment and extend the following lines, if necessary.
-!--       The arrays for storing the user defined quantities (here u2_av) have
-!--       to be declared and defined by the user!
+!--       The arrays for storing the user defined quantities (here u2_av) have to be declared and
+!--       defined by the user!
 !--       Sample for user-defined output:
 !          CASE ( 'u2' )
@@ -830,9 +818,9 @@
 !
 !--       Uncomment and extend the following lines, if necessary.
-!--       The arrays for storing the user defined quantities (here u2 and
-!--       u2_av) have to be declared and defined by the user!
+!--       The arrays for storing the user defined quantities (here u2 and u2_av) have to be declared
+!--       and defined by the user!
 !--       Sample for user-defined output:
 !          CASE ( 'u2' )
-!             IF ( ALLOCATED( u2_av ) ) THEN
+!             IF ( ALLOCATED( u2_av ) )  THEN
 !                DO  i = nxlg, nxrg
 !                   DO  j = nysg, nyng
@@ -845,4 +833,5 @@
 
           CASE ( 'v_h' )
+
              IF ( ALLOCATED( v_h_av ) ) THEN
                 DO  i = nxlg, nxrg
@@ -855,4 +844,5 @@
              ENDIF
 
+
           CASE DEFAULT
              CONTINUE
@@ -866,9 +856,9 @@
 !
 !--       Uncomment and extend the following lines, if necessary.
-!--       The arrays for storing the user defined quantities (here u2_av) have
-!--       to be declared and defined by the user!
+!--       The arrays for storing the user defined quantities (here u2_av) have to be declared and
+!--       defined by the user!
 !--       Sample for user-defined output:
 !          CASE ( 'u2' )
-!             IF ( ALLOCATED( u2_av ) ) THEN
+!             IF ( ALLOCATED( u2_av ) )  THEN
 !                DO  i = nxlg, nxrg
 !                   DO  j = nysg, nyng
@@ -881,4 +871,5 @@
 
           CASE ( 'v_h' )
+
              IF ( ALLOCATED( v_h_av ) ) THEN
                 DO  i = nxlg, nxrg
@@ -891,4 +882,5 @@
              ENDIF
 
+
        END SELECT
 
@@ -899,31 +891,30 @@
 
 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Resorts the user-defined output quantity with indices (k,j,i) to a
-!> temporary array with indices (i,j,k) and sets the grid on which it is defined.
-!> Allowed values for grid are "zu" and "zw".
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Resorts the user-defined output quantity with indices (k,j,i) to a temporary array with indices
+!> (i,j,k) and sets the grid on which it is defined. Allowed values for grid are "zu" and "zw".
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_data_output_2d( av, variable, found, grid, local_pf, two_d, nzb_do, nzt_do )
 
 
-    CHARACTER (LEN=*) ::  grid     !< 
-    CHARACTER (LEN=*) ::  variable !< 
-
-    INTEGER(iwp) ::  av     !< flag to control data output of instantaneous or time-averaged data
-    INTEGER(iwp) ::  i      !< grid index along x-direction
-    INTEGER(iwp) ::  j      !< grid index along y-direction
-    INTEGER(iwp) ::  k      !< grid index along z-direction
-!    INTEGER(iwp) ::  m      !< running index surface elements
-    INTEGER(iwp) ::  nzb_do !< lower limit of the domain (usually nzb)
-    INTEGER(iwp) ::  nzt_do !< upper limit of the domain (usually nzt+1)
-
-    LOGICAL      ::  found !< 
-    LOGICAL      ::  two_d !< flag parameter that indicates 2D variables (horizontal cross sections)
-
-    REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
-
-    REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !< 
+    CHARACTER(LEN=*) ::  grid      !<
+    CHARACTER(LEN=*) ::  variable  !<
+
+    INTEGER(iwp) ::  av      !< flag to control data output of instantaneous or time-averaged data
+    INTEGER(iwp) ::  i       !< grid index along x-direction
+    INTEGER(iwp) ::  j       !< grid index along y-direction
+    INTEGER(iwp) ::  k       !< grid index along z-direction
+!    INTEGER(iwp) ::  m       !< running index surface elements
+    INTEGER(iwp) ::  nzb_do  !< lower limit of the domain (usually nzb)
+    INTEGER(iwp) ::  nzt_do  !< upper limit of the domain (usually nzt+1)
+
+    LOGICAL      ::  found  !<
+    LOGICAL      ::  two_d  !< flag parameter that indicates 2D variables (horizontal cross sections)
+
+   REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
+
+    REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf  !<
 
 !
@@ -931,4 +922,5 @@
     IF ( av == 0  .OR.  local_pf(nxl,nys,nzb_do) == 0.0_wp  .OR.  two_d )  CONTINUE
 
+
     found = .TRUE.
 
@@ -937,6 +929,6 @@
 !
 !--    Uncomment and extend the following lines, if necessary.
-!--    The arrays for storing the user defined quantities (here u2 and u2_av)
-!--    have to be declared and defined by the user!
+!--    The arrays for storing the user defined quantities (here u2 and u2_av) have to be declared
+!--    and defined by the user!
 !--    Sample for user-defined output:
 !       CASE ( 'u2_xy', 'u2_xz', 'u2_yz' )
@@ -950,5 +942,5 @@
 !             ENDDO
 !          ELSE
-!             IF ( .NOT. ALLOCATED( u2_av ) ) THEN
+!             IF ( .NOT. ALLOCATED( u2_av ) )  THEN
 !                ALLOCATE( u2_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 !                u2_av = REAL( fill_value, KIND = wp )
@@ -989,10 +981,10 @@
 
           grid = 'zu'
-!
-!--    In case two-dimensional surface variables are output, the user
-!--    has to access related surface-type. Uncomment and extend following lines
-!--    appropriately (example output of vertical surface momentum flux of u-
-!--    component). Please note, surface elements can be distributed over 
-!--    several data type, depending on their respective surface properties.
+
+!
+!--    In case two-dimensional surface variables are output, the user has to access related
+!--    surface-type. Uncomment and extend following lines appropriately (example output of vertical
+!--    surface momentum flux of u-component). Please note, surface elements can be distributed over
+!--    several data types, depending on their respective surface properties.
 !       CASE ( 'usws_xy' )
 !          IF ( av == 0 )  THEN
@@ -1021,5 +1013,5 @@
 !
 !          grid = 'zu'
-!--       
+!--
 
 
@@ -1034,27 +1026,31 @@
 
 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Resorts the user-defined output quantity with indices (k,j,i) to a
-!> temporary array with indices (i,j,k).
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Resorts the user-defined output quantity with indices (k,j,i) to a temporary array with indices
+!> (i,j,k).
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
 
 
-    CHARACTER (LEN=*) ::  variable !< 
-
-    INTEGER(iwp) ::  av    !< 
-    INTEGER(iwp) ::  i     !< 
-    INTEGER(iwp) ::  j     !< 
-    INTEGER(iwp) ::  k     !< 
+    CHARACTER(LEN=*) ::  variable  !<
+
+    INTEGER(iwp) ::  av     !<
+    INTEGER(iwp) ::  i      !<
+    INTEGER(iwp) ::  j      !<
+    INTEGER(iwp) ::  k      !<
     INTEGER(iwp) ::  nzb_do !< lower limit of the data output (usually 0)
     INTEGER(iwp) ::  nzt_do !< vertical upper limit of the data output (usually nz_do3d)
 
-    LOGICAL      ::  found !< 
-
-    REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
-
-    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !< 
+    LOGICAL      ::  found  !<
+
+   REAL(wp) ::  fill_value = -999.0_wp  !< value for the _FillValue attribute
+
+    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf  !<
+
+!
+!-- Next line is to avoid compiler warning about unused variables. Please remove.
+    IF ( av == 0  .OR.  local_pf(nxl,nys,nzb_do) == 0.0_wp )  CONTINUE
 
 
@@ -1065,6 +1061,6 @@
 !
 !--    Uncomment and extend the following lines, if necessary.
-!--    The arrays for storing the user defined quantities (here u2 and u2_av)
-!--    have to be declared and defined by the user!
+!--    The arrays for storing the user defined quantities (here u2 and u2_av) have to be declared
+!--    and defined by the user!
 !--    Sample for user-defined output:
 !       CASE ( 'u2' )
@@ -1078,5 +1074,5 @@
 !             ENDDO
 !          ELSE
-!             IF ( .NOT. ALLOCATED( u2_av ) ) THEN
+!             IF ( .NOT. ALLOCATED( u2_av ) )  THEN
 !                ALLOCATE( u2_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 !                u2_av = REAL( fill_value, KIND = wp )
@@ -1090,5 +1086,4 @@
 !             ENDDO
 !          ENDIF
-
 
        CASE ( 'v_h' )
@@ -1114,5 +1109,5 @@
              ENDDO
           ENDIF
-!
+
 
        CASE DEFAULT
@@ -1125,25 +1120,23 @@
 
 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Calculation of user-defined statistics, i.e. horizontally averaged profiles
-!> and time series.
-!> This routine is called for every statistic region sr defined by the user,
-!> but at least for the region "total domain" (sr=0).
-!> See section 3.5.4 on how to define, calculate, and output user defined
-!> quantities.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Calculation of user-defined statistics, i.e. horizontally averaged profiles and time series.
+!> This routine is called for every statistic region sr defined by the user, but at least for the
+!> region "total domain" (sr=0). See section 3.5.4 on how to define, calculate, and output user
+!> defined quantities.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_statistics( mode, sr, tn )
 
 
-    CHARACTER (LEN=*) ::  mode   !< 
-!    INTEGER(iwp) ::  i    !<
-!    INTEGER(iwp) ::  j    !<
-!    INTEGER(iwp) ::  k    !<
-    INTEGER(iwp) ::  sr   !< 
-    INTEGER(iwp) ::  tn   !< 
-
-!    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ts_value_l   !<
+    CHARACTER(LEN=*) ::  mode  !<
+!    INTEGER(iwp) ::  i   !<
+!    INTEGER(iwp) ::  j   !<
+!    INTEGER(iwp) ::  k   !<
+    INTEGER(iwp) ::  sr  !<
+    INTEGER(iwp) ::  tn  !<
+
+!    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ts_value_l  !<
 
 !
@@ -1154,9 +1147,8 @@
 
 !
-!--    Sample on how to calculate horizontally averaged profiles of user-
-!--    defined quantities. Each quantity is identified by the index
-!--    "pr_palm+#" where "#" is an integer starting from 1. These
-!--    user-profile-numbers must also be assigned to the respective strings
-!--    given by data_output_pr_user in routine user_check_data_output_pr.
+!--    Sample on how to calculate horizontally averaged profiles of user-defined quantities. Each
+!--    quantity is identified by the index "pr_palm+#" where "#" is an integer starting from 1.
+!--    These user-profile-numbers must also be assigned to the respective strings given by
+!--    data_output_pr_user in routine user_check_data_output_pr.
 !       !$OMP DO
 !       DO  i = nxl, nxr
@@ -1164,17 +1156,15 @@
 !             DO  k = nzb+1, nzt
 !!
-!!--             Sample on how to calculate the profile of the resolved-scale
-!!--             horizontal momentum flux u*v*
-!                sums_l(k,pr_palm+1,tn) = sums_l(k,pr_palm+1,tn) +             &
-!                      ( 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) - hom(k,1,1,sr) ) *&
-!                      ( 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) - hom(k,1,2,sr) )  &
-!                                     * rmask(j,i,sr)                          &
-!                                     * MERGE( 1.0_wp, 0.0_wp,                 &
-!                                              BTEST( wall_flags_0(k,j,i), 0 ) )
+!!--             Sample on how to calculate the profile of the resolved-scale horizontal momentum
+!!--             flux u*v*
+!                sums_l(k,pr_palm+1,tn) = sums_l(k,pr_palm+1,tn) +                                  &
+!                                         ( 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) - hom(k,1,1,sr) ) *  &
+!                                         ( 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) - hom(k,1,2,sr) ) *  &
+!                                         rmask(j,i,sr) * MERGE( 1.0_wp, 0.0_wp,                    &
+!                                         BTEST( wall_flags_total_0(k,j,i), 0 ) )
 !!
-!!--             Further profiles can be defined and calculated by increasing
-!!--             the second index of array sums_l (replace ... appropriately)
-!                sums_l(k,pr_palm+2,tn) = sums_l(k,pr_palm+2,tn) + ...           &
-!                                         * rmask(j,i,sr)
+!!--             Further profiles can be defined and calculated by increasing the second index of
+!!--             array sums_l (replace ... appropriately)
+!                sums_l(k,pr_palm+2,tn) = sums_l(k,pr_palm+2,tn) + ...   * rmask(j,i,sr)
 !             ENDDO
 !          ENDDO
@@ -1187,7 +1177,6 @@
 !
 !--    Sample on how to add values for the user-defined time series quantities.
-!--    These have to be defined before in routine user_init. This sample
-!--    creates two time series for the absolut values of the horizontal
-!--    velocities u and v.
+!--    These have to be defined before in routine user_init. This sample creates two time series for
+!--    the absolut values of the horizontal velocities u and v.
 !       ts_value_l = 0.0_wp
 !       ts_value_l(1) = ABS( u_max )
@@ -1195,17 +1184,13 @@
 !
 !--     Collect / send values to PE0, because only PE0 outputs the time series.
-!--     CAUTION: Collection is done by taking the sum over all processors.
-!--              You may have to normalize this sum, depending on the quantity
-!--              that you like to calculate. For serial runs, nothing has to be
-!--              done.
-!--     HINT: If the time series value that you are calculating has the same
-!--           value on all PEs, you can omit the MPI_ALLREDUCE call and
-!--           assign ts_value(dots_num_palm+1:,sr) = ts_value_l directly.
+!--     CAUTION: Collection is done by taking the sum over all processors. You may have to normalize
+!--              this sum, depending on the quantity that you like to calculate. For serial runs,
+!--              nothing has to be done.
+!--     HINT: If the time series value that you are calculating has the same value on all PEs, you
+!--           can omit the MPI_ALLREDUCE call and assign ts_value(dots_num_palm+1:,sr) = ts_value_l directly.
 !#if defined( __parallel )
 !       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-!       CALL MPI_ALLREDUCE( ts_value_l(1),                         &
-!                           ts_value(dots_num_palm+1,sr),                        &
-!                           dots_num_user, MPI_REAL, MPI_MAX, comm2d,   &
-!                           ierr )
+!       CALL MPI_ALLREDUCE( ts_value_l(1), ts_value(dots_num_palm+1,sr), dots_num_user, MPI_REAL,   &
+!                           MPI_MAX, comm2d, ierr )
 !#else
 !       ts_value(dots_num_palm+1:dots_num_palm+dots_num_user,sr) = ts_value_l
@@ -1217,13 +1202,13 @@
 
 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Reading global restart data that has been defined by the user.
-!------------------------------------------------------------------------------!
- SUBROUTINE user_rrd_global( found )
-
-
-    LOGICAL, INTENT(OUT)  ::  found
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Read module-specific global restart data (Fortran binary format).
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE user_rrd_global_ftn( found )
+
+
+    LOGICAL, INTENT(OUT)  ::  found  !<
 
 
@@ -1237,5 +1222,5 @@
 
        CASE DEFAULT
- 
+
           found = .FALSE.
 
@@ -1243,20 +1228,34 @@
 
 
- END SUBROUTINE user_rrd_global
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Reading processor specific restart data from file(s) that has been defined 
-!> by the user.
-!> Subdomain index limits on file are given by nxl_on_file, etc.
-!> Indices nxlc, etc. indicate the range of gridpoints to be mapped from the
-!> subdomain on file (f) to the subdomain of the current PE (c). They have been
-!> calculated in routine rrd_local.
-!------------------------------------------------------------------------------!
- SUBROUTINE user_rrd_local( k, nxlf, nxlc, nxl_on_file, nxrf, nxrc,         &
-                            nxr_on_file, nynf, nync, nyn_on_file, nysf,     &
-                            nysc, nys_on_file, tmp_3d, found )
+ END SUBROUTINE user_rrd_global_ftn
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Read module-specific global restart data (MPI-IO).
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE user_rrd_global_mpi
+
+!    USE restart_data_mpi_io_mod,                                                                   &
+!        ONLY:  rrd_mpi_io
+
+!    CALL rrd_mpi_io( 'global_parameter', global_parameter )
+    CONTINUE
+
+ END SUBROUTINE user_rrd_global_mpi
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Read module-specific local restart data arrays (Fortran binary format).
+!> Subdomain
+!> index limits on file are given by nxl_on_file, etc. Indices nxlc, etc. indicate the range of
+!> gridpoints to be mapped from the subdomain on file (f) to the subdomain of the current PE (c).
+!> They have been calculated in routine rrd_local.
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE user_rrd_local_ftn( k, nxlf, nxlc, nxl_on_file, nxrf, nxrc, nxr_on_file, nynf, nync,   &
+                                nyn_on_file, nysf, nysc, nys_on_file, tmp_3d, found )
 
 
@@ -1276,7 +1275,7 @@
     INTEGER(iwp) ::  nys_on_file     !<
 
-    LOGICAL, INTENT(OUT)  ::  found
-
-    REAL(wp), DIMENSION(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp,nxl_on_file-nbgp:nxr_on_file+nbgp) :: tmp_3d   !<
+    LOGICAL, INTENT(OUT)  ::  found  !<
+
+    REAL(wp), DIMENSION(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp,nxl_on_file-nbgp:nxr_on_file+nbgp) :: tmp_3d  !<
 
 !
@@ -1294,10 +1293,10 @@
 
        CASE ( 'u2_av' )
-!          IF ( .NOT. ALLOCATED( u2_av ) ) THEN
+!          IF ( .NOT. ALLOCATED( u2_av ) )  THEN
 !               ALLOCATE( u2_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
 !          ENDIF
 !          IF ( k == 1 )  READ ( 13 )  tmp_3d
-!             u2_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =         &
-!                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+!             u2_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =                                    &
+!             tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 !
        CASE DEFAULT
@@ -1307,45 +1306,86 @@
     END SELECT
 
- END SUBROUTINE user_rrd_local
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Writes global and user-defined restart data into binary file(s) for restart
-!> runs.
-!------------------------------------------------------------------------------!
+ END SUBROUTINE user_rrd_local_ftn
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Read module-specific local restart data arrays (MPI-IO).
+!--------------------------------------------------------------------------------------------------!
+ SUBROUTINE user_rrd_local_mpi
+
+!    USE restart_data_mpi_io_mod,                                                                   &
+!        ONLY:  rd_mpi_io_check_array, rrd_mpi_io
+
+!    CALL rd_mpi_io_check_array( 'u2_av' , found = array_found )
+!    IF ( array_found )  THEN
+!       IF ( .NOT. ALLOCATED( u2_av ) )  ALLOCATE( u2_av(nysg:nyng,nxlg:nxrg) )
+!       CALL rrd_mpi_io( 'rad_u2_av', rad_u2_av )
+!    ENDIF
+
+    CONTINUE
+
+ END SUBROUTINE user_rrd_local_mpi
+
+
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Writes global and user-defined restart data into binary file(s) for restart runs.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_wrd_global
 
-!    CALL wrd_write_string( 'global_parameter' )
-!    WRITE ( 14 )  global_parameter
+!    USE restart_data_mpi_io_mod,                                                                   &
+!        ONLY:  wrd_mpi_io
+
+    IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
+
+!       CALL wrd_write_string( 'global_parameter' )
+!       WRITE ( 14 )  global_parameter
+
+    ELSEIF ( restart_data_format_output(1:3) == 'mpi' )  THEN
+
+!    CALL rrd_mpi_io( 'global_parameter', global_parameter )
+
+    ENDIF
 
  END SUBROUTINE user_wrd_global
 
 
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Writes processor specific and user-defined restart data into binary file(s) 
-!> for restart runs.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Writes processor specific and user-defined restart data into binary file(s) for restart runs.
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_wrd_local
+
+!    USE restart_data_mpi_io_mod,                                                                   &
+!        ONLY:  wrd_mpi_io
 
 !
 !-- Here the user-defined actions at the end of a job follow.
 !-- Sample for user-defined output:
-!    IF ( ALLOCATED( u2_av ) )  THEN
-!       CALL wrd_write_string( 'u2_av' )
-!       WRITE ( 14 )  u2_av
-!    ENDIF
+    IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
+
+!       IF ( ALLOCATED( u2_av ) )  THEN
+!          CALL wrd_write_string( 'u2_av' )
+!          WRITE ( 14 )  u2_av
+!       ENDIF
+
+    ELSEIF ( restart_data_format_output(1:3) == 'mpi' )  THEN
+
+!       IF ( ALLOCATED( u2_av ) )  CALL wrd_mpi_io( 'u2_av', u2_av )
+
+    ENDIF
 
  END SUBROUTINE user_wrd_local
 
 
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! Description:
 ! ------------
 !> Execution of user-defined actions at the end of a job.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
  SUBROUTINE user_last_actions
 
