Index: palm/trunk/SOURCE/check_open.f90
===================================================================
--- palm/trunk/SOURCE/check_open.f90	(revision 4545)
+++ palm/trunk/SOURCE/check_open.f90	(revision 4546)
@@ -1,20 +1,20 @@
 !> @file check_open.f90
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 ! This file is part of the PALM model system.
 !
-! PALM is free software: you can redistribute it and/or modify it under the
-! terms of the GNU General Public License as published by the Free Software
-! Foundation, either version 3 of the License, or (at your option) any later
-! version.
-!
-! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
-! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-!
-! You should have received a copy of the GNU General Public License along with
-! PALM. If not, see <http://www.gnu.org/licenses/>.
+! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
+! Public License as published by the Free Software Foundation, either version 3 of the License, or
+! (at your option) any later version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
+! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+! Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with PALM. If not, see
+! <http://www.gnu.org/licenses/>.
+!
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 !
 ! Current revisions:
@@ -25,33 +25,36 @@
 ! -----------------
 ! $Id$
+! file re-formatted to follow the PALM coding standard
+!
+! 4444 2020-03-05 15:59:50Z raasch
 ! bugfix: cpp-directives for serial mode added
-! 
+!
 ! 4400 2020-02-10 20:32:41Z suehring
 ! Remove binary output for virtual measurements
-! 
+!
 ! 4360 2020-01-07 11:25:50Z suehring
 ! Corrected "Former revisions" section
-! 
+!
 ! 4128 2019-07-30 16:28:58Z gronemeier
 ! Bugfix for opening the parameter file (unit 11): return error message if file
 ! was not found.
-! 
+!
 ! 4099 2019-07-15 15:29:37Z suehring
 ! Bugfix in opening the parameter file (unit 11) in case of ocean precursor
-! runs. 
-! 
+! runs.
+!
 ! 4069 2019-07-01 14:05:51Z Giersch
-! Masked output running index mid has been introduced as a local variable to 
+! Masked output running index mid has been introduced as a local variable to
 ! avoid runtime error (Loop variable has been modified) in time_integration
-! 
+!
 ! 3967 2019-05-09 16:04:34Z gronemeier
 ! Save binary data of virtual measurements within separate folder
-! 
+!
 ! 3812 2019-03-25 07:10:12Z gronemeier
 ! Open binary surface output data within separate folder
-! 
+!
 ! 3705 2019-01-29 19:56:39Z suehring
 ! Open binary files for virtual measurements
-! 
+!
 ! 3704 2019-01-29 19:51:41Z suehring
 ! Open files for surface data
@@ -65,7 +68,7 @@
 !> Check if file unit is open. If not, open file and, if necessary, write a
 !> header or start other initializing actions, respectively.
-!------------------------------------------------------------------------------!
+!--------------------------------------------------------------------------------------------------!
 SUBROUTINE check_open( file_id )
- 
+
 
     USE control_parameters,                                                                        &
@@ -74,9 +77,9 @@
 
 #if defined( __parallel )
-    USE control_parameters,                                                    &
+    USE control_parameters,                                                                        &
         ONLY:  nz_do3d
 #endif
 
-    USE indices,                                                               &
+    USE indices,                                                                                   &
         ONLY:  nbgp, nx, nxl, nxr, ny, nyn, nys, nz, nzb, nzt
 
@@ -87,18 +90,17 @@
 #endif
 
-    USE netcdf_interface,                                                      &
-        ONLY:  id_set_agt, id_set_fl, id_set_mask, id_set_pr,                  &
-               id_set_pts, id_set_sp, id_set_ts, id_set_xy, id_set_xz,         &
-               id_set_yz, id_set_3d, nc_stat, netcdf_create_file,              &
-               netcdf_data_format, netcdf_define_header, netcdf_handle_error,  &
+    USE netcdf_interface,                                                                          &
+        ONLY:  id_set_agt, id_set_fl, id_set_mask, id_set_pr,                                      &
+               id_set_pts, id_set_sp, id_set_ts, id_set_xy, id_set_xz,                             &
+               id_set_yz, id_set_3d, nc_stat, netcdf_create_file,                                  &
+               netcdf_data_format, netcdf_define_header, netcdf_handle_error,                      &
                netcdf_open_write_file
 
-    USE particle_attributes,                                                   &
-        ONLY:  max_number_of_particle_groups, number_of_particle_groups,       &
-               particle_groups
+    USE particle_attributes,                                                                       &
+        ONLY:  max_number_of_particle_groups, number_of_particle_groups, particle_groups
 
     USE pegrid
 
-    USE posix_calls_from_fortran,                                              &
+    USE posix_calls_from_fortran,                                                                  &
         ONLY:  fortran_sleep
 
@@ -106,6 +108,6 @@
     IMPLICIT NONE
 
+    CHARACTER (LEN=30)  ::  filename                !<
     CHARACTER (LEN=4)   ::  mask_char               !<
-    CHARACTER (LEN=30)  ::  filename                !<
     CHARACTER (LEN=80)  ::  rtext                   !<
 
@@ -114,5 +116,5 @@
     INTEGER(iwp) ::  ioerr       !< IOSTAT flag for IO-commands ( 0 = no error )
     INTEGER(iwp) ::  mid         !< masked output running index
-    
+
     LOGICAL ::  file_exist       !< file check
     LOGICAL ::  netcdf_extend    !<
@@ -124,20 +126,18 @@
 !
 !-- Only certain files are allowed to be re-opened
-!-- NOTE: some of the other files perhaps also could be re-opened, but it
-!--       has not been checked so far, if it works!
+!-- NOTE: some of the other files perhaps also could be re-opened, but it has not been checked so
+!-- far, if it works!
     IF ( openfile(file_id)%opened_before )  THEN
        SELECT CASE ( file_id )
           CASE ( 13, 14, 21, 22, 23, 80, 85, 117 )
-             IF ( file_id == 14 .AND. openfile(file_id)%opened_before )  THEN
-                message_string = 're-open of unit ' //                         &
-                                 '14 is not verified. Please check results!'
-                CALL message( 'check_open', 'PA0165', 0, 1, 0, 6, 0 )       
+             IF ( file_id == 14  .AND.  openfile(file_id)%opened_before )  THEN
+                message_string = 're-open of unit ' // '14 is not verified. Please check results!'
+                CALL message( 'check_open', 'PA0165', 0, 1, 0, 6, 0 )
              ENDIF
 
           CASE DEFAULT
-             WRITE( message_string, * ) 're-opening of file-id ', file_id,     &
-                                        ' is not allowed'
-             CALL message( 'check_open', 'PA0166', 0, 1, 0, 6, 0 )    
-               
+             WRITE( message_string, * ) 're-opening of file-id ', file_id, ' is not allowed'
+             CALL message( 'check_open', 'PA0166', 0, 1, 0, 6, 0 )
+
              RETURN
 
@@ -150,8 +150,7 @@
 
        CASE ( 15, 16, 17, 18, 19, 50:59, 104:105, 107, 109, 117 )
-      
+
           IF ( myid /= 0 )  THEN
-             WRITE( message_string, * ) 'opening file-id ',file_id,            &
-                                        ' not allowed for PE ',myid
+             WRITE( message_string, * ) 'opening file-id ', file_id, ' not allowed for PE ', myid
              CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
           ENDIF
@@ -160,19 +159,17 @@
 
           IF ( netcdf_data_format < 5 )  THEN
-          
+
              IF ( myid /= 0 )  THEN
-                WRITE( message_string, * ) 'opening file-id ',file_id,         &
-                                           ' not allowed for PE ',myid
+                WRITE( message_string, * ) 'opening file-id ', file_id, ' not allowed for PE ', myid
                 CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
              ENDIF
-     
+
           ENDIF
 
        CASE ( 21, 22, 23 )
 
-          IF ( .NOT.  data_output_2d_on_each_pe )  THEN
+          IF ( .NOT. data_output_2d_on_each_pe )  THEN
              IF ( myid /= 0 )  THEN
-                WRITE( message_string, * ) 'opening file-id ',file_id,         &
-                                           ' not allowed for PE ',myid
+                WRITE( message_string, * ) 'opening file-id ', file_id, ' not allowed for PE ', myid
                 CALL message( 'check_open', 'PA0167', 2, 2, -1, 6, 1 )
              END IF
@@ -183,8 +180,8 @@
 !
 !--       File-ids that are used temporarily in other routines
-          WRITE( message_string, * ) 'opening file-id ',file_id,               &
-                                    ' is not allowed since it is used otherwise'
-          CALL message( 'check_open', 'PA0168', 0, 1, 0, 6, 0 ) 
-          
+          WRITE( message_string, * ) 'opening file-id ', file_id,                                  &
+                                     ' is not allowed since it is used otherwise'
+          CALL message( 'check_open', 'PA0168', 0, 1, 0, 6, 0 )
+
     END SELECT
 
@@ -195,19 +192,15 @@
        CASE ( 11 )
 !
-!--       Read the parameter file. Therefore, inquire whether the file exist or 
-!--       not. This is required for the ocean-atmoshere coupling. For an ocean
-!--       precursor run palmrun provides a PARIN_O file instead of a PARIN 
-!--       file. Actually this should be considered in coupling_char, however,
-!--       in pmc_init the parameter file is already opened to read the 
-!--       nesting parameters and decide whether it is a nested run or not, 
-!--       but coupling_char is still not set at that moment (must be set after
-!-        the nesting setup is read).
-!--       This, however, leads to the situation that for ocean
-!--       precursor runs PARIN is not available and the run crashes. Thus, 
-!--       if the file is not there, PARIN_O will be read. An ocean precursor 
-!--       run will be the only situation where this can happen. 
-          INQUIRE( FILE = 'PARIN' // TRIM( coupling_char ),                    &
-                   EXIST = file_exist )
-                   
+!--       Read the parameter file. Therefore, inquire whether the file exist or not. This is
+!--       required for the ocean-atmoshere coupling. For an ocean precursor run palmrun provides a
+!--       PARIN_O file instead of a PARIN file. Actually this should be considered in coupling_char,
+!--       however, in pmc_init the parameter file is already opened to read the nesting parameters
+!--       and decide whether it is a nested run or not, but coupling_char is still not set at that
+!--       moment (must be set after the nesting setup is read).
+!--       This, however, leads to the situation that for ocean precursor runs PARIN is not available
+!--       and the run crashes. Thus, if the file is not there, PARIN_O will be read. An ocean
+!--       precursor run will be the only situation where this can happen.
+          INQUIRE( FILE = 'PARIN' // TRIM( coupling_char ), EXIST = file_exist )
+
           IF ( file_exist )  THEN
              filename = 'PARIN' // TRIM( coupling_char )
@@ -216,10 +209,10 @@
           ENDIF
 
-          OPEN ( 11, FILE= TRIM( filename ), FORM='FORMATTED', STATUS='OLD', IOSTAT=ioerr )
+          OPEN ( 11, FILE= TRIM( filename ), FORM = 'FORMATTED', STATUS = 'OLD', IOSTAT = ioerr )
 
           IF ( ioerr /= 0 )  THEN
-             message_string = 'namelist file "PARIN' // TRIM( coupling_char ) //         &
-                              '"  or "PARIN_O" not found!' //                            &
-                              '&Please have a look at the online description of the ' // &
+             message_string = 'namelist file "PARIN' // TRIM( coupling_char ) //                   &
+                              '"  or "PARIN_O" not found!' //                                      &
+                              '&Please have a look at the online description of the ' //           &
                               'error message for further hints.'
              CALL message( 'check_open', 'PA0661', 3, 2, 0, 6, 1 )
@@ -229,16 +222,16 @@
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 13, FILE='BININ'//TRIM( coupling_char )//myid_char,        &
-                        FORM='UNFORMATTED', STATUS='OLD' )
-          ELSE
-!
-!--          First opening of unit 13 openes file _000000 on all PEs because
-!--          only this file contains the global variables
+             OPEN ( 13, FILE = 'BININ' // TRIM( coupling_char ) // myid_char, FORM = 'UNFORMATTED',&
+                        STATUS = 'OLD' )
+          ELSE
+!
+!--          First opening of unit 13 openes file _000000 on all PEs because only this file contains
+!--          the global variables.
              IF ( .NOT. openfile(file_id)%opened_before )  THEN
-                OPEN ( 13, FILE='BININ'//TRIM( coupling_char )//'/_000000',    &
-                           FORM='UNFORMATTED', STATUS='OLD' )
+                OPEN ( 13, FILE = 'BININ' // TRIM( coupling_char ) // '/_000000',                  &
+                           FORM = 'UNFORMATTED', STATUS = 'OLD' )
              ELSE
-                OPEN ( 13, FILE='BININ'//TRIM( coupling_char )//'/'//          &
-                           myid_char, FORM='UNFORMATTED', STATUS='OLD' )
+                OPEN ( 13, FILE = 'BININ' // TRIM( coupling_char ) // '/' // myid_char,            &
+                           FORM = 'UNFORMATTED', STATUS = 'OLD' )
              ENDIF
           ENDIF
@@ -247,6 +240,6 @@
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 14, FILE='BINOUT'//TRIM( coupling_char )//myid_char,       &
-                        FORM='UNFORMATTED', POSITION='APPEND' )
+             OPEN ( 14, FILE = 'BINOUT' // TRIM( coupling_char ) // myid_char,                     &
+                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
           ELSE
              IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
@@ -255,15 +248,15 @@
 #if defined( __parallel )
 !
-!--          Set a barrier in order to allow that all other processors in the 
-!--          directory created by PE0 can open their file
+!--          Set a barrier in order to allow that all other processors in the directory created by
+!--          PE0 can open their file
              CALL MPI_BARRIER( comm2d, ierr )
 #endif
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 14, FILE='BINOUT'//TRIM(coupling_char)//'/'//myid_char, &
-                           FORM='UNFORMATTED', IOSTAT=ioerr )
+                OPEN ( 14, FILE = 'BINOUT' // TRIM(coupling_char)// '/' // myid_char,              &
+                           FORM = 'UNFORMATTED', IOSTAT = ioerr )
                 IF ( ioerr /= 0 )  THEN
-                   WRITE( 9, * )  '*** could not open "BINOUT'//         &
-                                  TRIM(coupling_char)//'/'//myid_char//  &
+                   WRITE( 9, * )  '*** could not open "BINOUT' //                                  &
+                                  TRIM(coupling_char) // '/' // myid_char //                       &
                                   '"! Trying again in 1 sec.'
                    CALL fortran_sleep( 1 )
@@ -275,25 +268,21 @@
        CASE ( 15 )
 
-          OPEN ( 15, FILE='RUN_CONTROL'//TRIM( coupling_char ),                &
-                     FORM='FORMATTED' )
+          OPEN ( 15, FILE = 'RUN_CONTROL' // TRIM( coupling_char ), FORM = 'FORMATTED' )
 
        CASE ( 16 )
 
-          OPEN ( 16, FILE='LIST_PROFIL'//TRIM( coupling_char ),                &
-                     FORM='FORMATTED' )
+          OPEN ( 16, FILE = 'LIST_PROFIL' // TRIM( coupling_char ), FORM = 'FORMATTED' )
 
        CASE ( 17 )
 
-          OPEN ( 17, FILE='LIST_PROFIL_1D'//TRIM( coupling_char ),             &
-                     FORM='FORMATTED' )
+          OPEN ( 17, FILE = 'LIST_PROFIL_1D' // TRIM( coupling_char ), FORM = 'FORMATTED' )
 
        CASE ( 18 )
 
-          OPEN ( 18, FILE='CPU_MEASURES'//TRIM( coupling_char ),               &
-                     FORM='FORMATTED' )
+          OPEN ( 18, FILE = 'CPU_MEASURES' // TRIM( coupling_char ), FORM = 'FORMATTED' )
 
        CASE ( 19 )
 
-          OPEN ( 19, FILE='HEADER'//TRIM( coupling_char ), FORM='FORMATTED' )
+          OPEN ( 19, FILE = 'HEADER' // TRIM( coupling_char ), FORM = 'FORMATTED' )
 
        CASE ( 20 )
@@ -303,22 +292,20 @@
           ENDIF
           IF ( myid_char == '' )  THEN
-             OPEN ( 20, FILE='DATA_LOG'//TRIM( coupling_char )//'/_000000',    &
-                        FORM='UNFORMATTED', POSITION='APPEND' )
-          ELSE
-#if defined( __parallel )
-!
-!--          Set a barrier in order to allow that all other processors in the 
-!--          directory created by PE0 can open their file
+             OPEN ( 20, FILE = 'DATA_LOG' // TRIM( coupling_char ) // '/_000000',                  &
+                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
+          ELSE
+#if defined( __parallel )
+!
+!--          Set a barrier in order to allow that all other processors in the directory created by
+!--          PE0 can open their file
              CALL MPI_BARRIER( comm2d, ierr )
 #endif
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 20, FILE='DATA_LOG'//TRIM( coupling_char )//'/'//       &
-                           myid_char, FORM='UNFORMATTED', POSITION='APPEND',   &
-                           IOSTAT=ioerr )
+                OPEN ( 20, FILE = 'DATA_LOG' // TRIM( coupling_char ) // '/' // myid_char,         &
+                           FORM = 'UNFORMATTED', POSITION = 'APPEND', IOSTAT = ioerr )
                 IF ( ioerr /= 0 )  THEN
-                   WRITE( 9, * )  '*** could not open "DATA_LOG'//         &
-                                  TRIM( coupling_char )//'/'//myid_char//  &
-                                  '"! Trying again in 1 sec.'
+                   WRITE( 9, * )  '*** could not open "DATA_LOG' // TRIM( coupling_char ) // '/' //&
+                                   myid_char // '"! Trying again in 1 sec.'
                    CALL fortran_sleep( 1 )
                 ENDIF
@@ -330,9 +317,9 @@
 
           IF ( data_output_2d_on_each_pe )  THEN
-             OPEN ( 21, FILE='PLOT2D_XY'//TRIM( coupling_char )//myid_char,    &
-                        FORM='UNFORMATTED', POSITION='APPEND' )
-          ELSE
-             OPEN ( 21, FILE='PLOT2D_XY'//TRIM( coupling_char ),                       &
-                        FORM='UNFORMATTED', POSITION='APPEND' )
+             OPEN ( 21, FILE = 'PLOT2D_XY' // TRIM( coupling_char ) // myid_char,                  &
+                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
+          ELSE
+             OPEN ( 21, FILE = 'PLOT2D_XY' // TRIM( coupling_char ),                               &
+                        FORM ='UNFORMATTED', POSITION = 'APPEND' )
           ENDIF
 
@@ -349,9 +336,9 @@
 
           IF ( data_output_2d_on_each_pe )  THEN
-             OPEN ( 22, FILE='PLOT2D_XZ'//TRIM( coupling_char )//myid_char,    &
-                        FORM='UNFORMATTED', POSITION='APPEND' )
-          ELSE
-             OPEN ( 22, FILE='PLOT2D_XZ'//TRIM( coupling_char ),               &
-                        FORM='UNFORMATTED', POSITION='APPEND' )
+             OPEN ( 22, FILE = 'PLOT2D_XZ' // TRIM( coupling_char ) // myid_char,                  &
+                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
+          ELSE
+             OPEN ( 22, FILE = 'PLOT2D_XZ' // TRIM( coupling_char ), FORM = 'UNFORMATTED',         &
+                        POSITION = 'APPEND' )
           ENDIF
 
@@ -368,9 +355,9 @@
 
           IF ( data_output_2d_on_each_pe )  THEN
-             OPEN ( 23, FILE='PLOT2D_YZ'//TRIM( coupling_char )//myid_char,    &
-                        FORM='UNFORMATTED', POSITION='APPEND' )
-          ELSE
-             OPEN ( 23, FILE='PLOT2D_YZ'//TRIM( coupling_char ),               &
-                        FORM='UNFORMATTED', POSITION='APPEND' )
+             OPEN ( 23, FILE = 'PLOT2D_YZ' // TRIM( coupling_char ) // myid_char,                  &
+                        FORM = 'UNFORMATTED', POSITION='APPEND' )
+          ELSE
+             OPEN ( 23, FILE = 'PLOT2D_YZ' // TRIM( coupling_char ), FORM = 'UNFORMATTED',         &
+                        POSITION = 'APPEND' )
           ENDIF
 
@@ -383,34 +370,31 @@
 
           ENDIF
-          
+
        CASE ( 25 )
 !
 !--       Binary files for surface data
-          ! OPEN ( 25, FILE='SURFACE_DATA_BIN'//TRIM( coupling_char )//          &
-          !                 myid_char, FORM='UNFORMATTED', POSITION='APPEND' )
+          ! OPEN ( 25, FILE = 'SURFACE_DATA_BIN' // TRIM( coupling_char ) // myid_char,            &
+          !            FORM = 'UNFORMATTED', POSITION = 'APPEND' )
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 25, FILE='SURFACE_DATA_BIN'//TRIM( coupling_char )//       &
-                             myid_char, FORM='UNFORMATTED', POSITION='APPEND' )
+             OPEN ( 25, FILE = 'SURFACE_DATA_BIN' // TRIM( coupling_char ) // myid_char,           &
+                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
           ELSE
              IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
-                CALL local_system( 'mkdir  SURFACE_DATA_BIN' //                &
-                                   TRIM( coupling_char ) )
-             ENDIF
-#if defined( __parallel )
-!
-!--          Set a barrier in order to allow that all other processors in the 
-!--          directory created by PE0 can open their file
+                CALL local_system( 'mkdir  SURFACE_DATA_BIN' // TRIM( coupling_char ) )
+             ENDIF
+#if defined( __parallel )
+!
+!--          Set a barrier in order to allow that all other processors in the directory created by
+!--          PE0 can open their file
              CALL MPI_BARRIER( comm2d, ierr )
 #endif
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 25, FILE='SURFACE_DATA_BIN'//TRIM(coupling_char)//      &
-                                '/'//myid_char,                                &
-                           FORM='UNFORMATTED', IOSTAT=ioerr )
+                OPEN ( 25, FILE = 'SURFACE_DATA_BIN' // TRIM(coupling_char) //  '/' // myid_char,  &
+                           FORM = 'UNFORMATTED', IOSTAT = ioerr )
                 IF ( ioerr /= 0 )  THEN
-                   WRITE( 9, * )  '*** could not open "SURFACE_DATA_BIN'//     &
-                                  TRIM(coupling_char)//'/'//myid_char//        &
-                                  '"! Trying again in 1 sec.'
+                   WRITE( 9, * )  '*** could not open "SURFACE_DATA_BIN'// TRIM(coupling_char) //  &
+                                  '/' // myid_char // '"! Trying again in 1 sec.'
                    CALL fortran_sleep( 1 )
                 ENDIF
@@ -422,30 +406,27 @@
 !
 !--       Binary files for averaged surface data
-          ! OPEN ( 26, FILE='SURFACE_DATA_AV_BIN'//TRIM( coupling_char )//myid_char,  &
-          !        FORM='UNFORMATTED', POSITION='APPEND' )
+          ! OPEN ( 26, FILE = 'SURFACE_DATA_AV_BIN' // TRIM( coupling_char ) // myid_char,         &
+          !        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 26, FILE='SURFACE_DATA_AV_BIN'//TRIM( coupling_char )//    &
-                             myid_char, FORM='UNFORMATTED', POSITION='APPEND' )
+             OPEN ( 26, FILE = 'SURFACE_DATA_AV_BIN' // TRIM( coupling_char ) // myid_char,        &
+                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
           ELSE
              IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
-                CALL local_system( 'mkdir  SURFACE_DATA_AV_BIN' //             &
-                                   TRIM( coupling_char ) )
-             ENDIF
-#if defined( __parallel )
-!
-!--          Set a barrier in order to allow that all other processors in the 
-!--          directory created by PE0 can open their file
+                CALL local_system( 'mkdir  SURFACE_DATA_AV_BIN' // TRIM( coupling_char ) )
+             ENDIF
+#if defined( __parallel )
+!
+!--          Set a barrier in order to allow that all other processors in the directory created by
+!--          PE0 can open their file
              CALL MPI_BARRIER( comm2d, ierr )
 #endif
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 26, FILE='SURFACE_DATA_AV_BIN'//TRIM(coupling_char)//   &
-                                '/'//myid_char,                                &
-                           FORM='UNFORMATTED', IOSTAT=ioerr )
+                OPEN ( 26, FILE = 'SURFACE_DATA_AV_BIN' // TRIM(coupling_char) // '/' // myid_char,&
+                           FORM = 'UNFORMATTED', IOSTAT = ioerr )
                 IF ( ioerr /= 0 )  THEN
-                   WRITE( 9, * )  '*** could not open "SURFACE_DATA_AV_BIN'//  &
-                                  TRIM(coupling_char)//'/'//myid_char//        &
-                                  '"! Trying again in 1 sec.'
+                   WRITE( 9, * )  '*** could not open "SURFACE_DATA_AV_BIN' // TRIM(coupling_char) &
+                                  // '/' // myid_char // '"! Trying again in 1 sec.'
                    CALL fortran_sleep( 1 )
                 ENDIF
@@ -456,6 +437,6 @@
        CASE ( 30 )
 
-          OPEN ( 30, FILE='PLOT3D_DATA'//TRIM( coupling_char )//myid_char,     &
-                     FORM='UNFORMATTED' )
+          OPEN ( 30, FILE = 'PLOT3D_DATA' // TRIM( coupling_char ) // myid_char,                   &
+                     FORM = 'UNFORMATTED' )
 !
 !--       Specifications for combine_plot_fields
@@ -469,25 +450,22 @@
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 80, FILE='PARTICLE_INFOS'//TRIM(coupling_char)//myid_char, &
-                        FORM='FORMATTED', POSITION='APPEND' )
+             OPEN ( 80, FILE = 'PARTICLE_INFOS'//TRIM(coupling_char)//myid_char, &
+                        FORM = 'FORMATTED', POSITION='APPEND' )
           ELSE
              IF ( myid == 0  .AND.  .NOT. openfile(80)%opened_before )  THEN
-                CALL local_system( 'mkdir  PARTICLE_INFOS' //                  &
-                                   TRIM( coupling_char ) )
-             ENDIF
-#if defined( __parallel )
-!
-!--          Set a barrier in order to allow that thereafter all other
-!--          processors in the directory created by PE0 can open their file.
-!--          WARNING: The following barrier will lead to hanging jobs, if
-!--                   check_open is first called from routine
-!--                   allocate_prt_memory!
+                CALL local_system( 'mkdir  PARTICLE_INFOS' // TRIM( coupling_char ) )
+             ENDIF
+#if defined( __parallel )
+!
+!--          Set a barrier in order to allow that thereafter all other processors in the directory
+!--          created by PE0 can open their file.
+!--          WARNING: The following barrier will lead to hanging jobs, if check_open is first called
+!--                   from routine allocate_prt_memory!
              IF ( .NOT. openfile(80)%opened_before )  THEN
                 CALL MPI_BARRIER( comm2d, ierr )
              ENDIF
 #endif
-             OPEN ( 80, FILE='PARTICLE_INFOS'//TRIM( coupling_char )//'/'//    &
-                             myid_char,                                        &
-                        FORM='FORMATTED', POSITION='APPEND' )
+             OPEN ( 80, FILE = 'PARTICLE_INFOS' // TRIM( coupling_char ) // '/' // myid_char,      &
+                        FORM = 'FORMATTED', POSITION = 'APPEND' )
           ENDIF
 
@@ -499,26 +477,23 @@
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 85, FILE='PARTICLE_DATA'//TRIM(coupling_char)//myid_char,  &
-                        FORM='UNFORMATTED', POSITION='APPEND' )
+             OPEN ( 85, FILE = 'PARTICLE_DATA' // TRIM(coupling_char) // myid_char,                &
+                        FORM = 'UNFORMATTED', POSITION = 'APPEND' )
           ELSE
              IF ( myid == 0  .AND.  .NOT. openfile(85)%opened_before )  THEN
-                CALL local_system( 'mkdir  PARTICLE_DATA' //                   &
-                                   TRIM( coupling_char ) )
-             ENDIF
-#if defined( __parallel )
-!
-!--          Set a barrier in order to allow that thereafter all other
-!--          processors in the directory created by PE0 can open their file
+                CALL local_system( 'mkdir  PARTICLE_DATA' // TRIM( coupling_char ) )
+             ENDIF
+#if defined( __parallel )
+!
+!--          Set a barrier in order to allow that thereafter all other processors in the directory
+!--          created by PE0 can open their file
              CALL MPI_BARRIER( comm2d, ierr )
 #endif
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 85, FILE='PARTICLE_DATA'//TRIM( coupling_char )//'/'//  &
-                           myid_char,                                          &
-                           FORM='UNFORMATTED', POSITION='APPEND', IOSTAT=ioerr )
+                OPEN ( 85, FILE = 'PARTICLE_DATA' // TRIM( coupling_char ) // '/' // myid_char,    &
+                           FORM = 'UNFORMATTED', POSITION = 'APPEND', IOSTAT = ioerr )
                 IF ( ioerr /= 0 )  THEN
-                   WRITE( 9, * )  '*** could not open "PARTICLE_DATA'//        &
-                                  TRIM( coupling_char )//'/'//myid_char//      &
-                                  '"! Trying again in 1 sec.'
+                   WRITE( 9, * )  '*** could not open "PARTICLE_DATA' // TRIM( coupling_char ) //  &
+                                  '/' // myid_char // '"! Trying again in 1 sec.'
                    CALL fortran_sleep( 1 )
                 ENDIF
@@ -530,11 +505,9 @@
              WRITE ( 85 )  run_description_header
 !
-!--          Attention: change version number whenever the output format on
-!--                     unit 85 is changed (see also in routine
-!--                     lpm_data_output_particles)
+!--          Attention: change version number whenever the output format on unit 85 is changed (see
+!--                     also in routine lpm_data_output_particles)
              rtext = 'data format version 3.1'
              WRITE ( 85 )  rtext
-             WRITE ( 85 )  number_of_particle_groups,                          &
-                           max_number_of_particle_groups
+             WRITE ( 85 )  number_of_particle_groups, max_number_of_particle_groups
              WRITE ( 85 )  particle_groups
              WRITE ( 85 )  nxl, nxr, nys, nyn, nzb, nzt, nbgp
@@ -542,43 +515,40 @@
 
 !
-!--    File where sky-view factors and further required data is stored will be 
-!--    read
+!--    File where sky-view factors and further required data is stored will be read
        CASE ( 88 )
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 88, FILE='SVFIN'//TRIM( coupling_char )//myid_char,        &
-                        FORM='UNFORMATTED', STATUS='OLD', IOSTAT=ioerr )
-          ELSE
-
-             OPEN ( 88, FILE='SVFIN'//TRIM( coupling_char )//'/'//myid_char,   &
-                        FORM='UNFORMATTED', STATUS='OLD', IOSTAT=ioerr )
-          ENDIF
-
-!
-!--    File where sky-view factors and further required data is stored will be
-!--    created
+             OPEN ( 88, FILE = 'SVFIN' // TRIM( coupling_char ) // myid_char, FORM = 'UNFORMATTED',&
+                        STATUS = 'OLD', IOSTAT = ioerr )
+          ELSE
+
+             OPEN ( 88, FILE = 'SVFIN' // TRIM( coupling_char ) // '/' // myid_char,               &
+                        FORM = 'UNFORMATTED', STATUS = 'OLD', IOSTAT = ioerr )
+          ENDIF
+
+!
+!--    File where sky-view factors and further required data is stored will be created
        CASE ( 89 )
 
           IF ( myid_char == '' )  THEN
-             OPEN ( 89, FILE='SVFOUT'//TRIM( coupling_char )//myid_char,       &
-                        FORM='UNFORMATTED', STATUS='NEW' )
-          ELSE
-             IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
+             OPEN ( 89, FILE = 'SVFOUT' // TRIM( coupling_char ) // myid_char,                     &
+                        FORM = 'UNFORMATTED', STATUS = 'NEW' )
+          ELSE
+             IF ( myid == 0  .AND.  .NOT. openfile(file_id)%opened_before )  THEN
                 CALL local_system( 'mkdir  SVFOUT' // TRIM( coupling_char ) )
              ENDIF
 #if defined( __parallel )
 !
-!--          Set a barrier in order to allow that all other processors in the 
-!--          directory created by PE0 can open their file
+!--          Set a barrier in order to allow that all other processors in the directory created by
+!--          PE0 can open their file
              CALL MPI_BARRIER( comm2d, ierr )
 #endif
              ioerr = 1
              DO WHILE ( ioerr /= 0 )
-                OPEN ( 89, FILE='SVFOUT'//TRIM(coupling_char)//'/'//myid_char, &
-                           FORM='UNFORMATTED', STATUS='NEW', IOSTAT=ioerr )
+                OPEN ( 89, FILE = 'SVFOUT' // TRIM(coupling_char) // '/' // myid_char,             &
+                           FORM = 'UNFORMATTED', STATUS = 'NEW', IOSTAT = ioerr )
                 IF ( ioerr /= 0 )  THEN
-                   WRITE( 9, * )  '*** could not open "SVFOUT'//               &
-                                  TRIM(coupling_char)//'/'//myid_char//        &
-                                  '"! Trying again in 1 sec.'
+                   WRITE( 9, * )  '*** could not open "SVFOUT' // TRIM(coupling_char) // '/' //    &
+                                  myid_char // '"! Trying again in 1 sec.'
                    CALL fortran_sleep( 1 )
                 ENDIF
@@ -591,6 +561,6 @@
        CASE ( 117 )
 
-          OPEN ( 117, FILE='PROGRESS'//TRIM( coupling_char ),                  &
-                      STATUS='REPLACE', FORM='FORMATTED' )
+          OPEN ( 117, FILE = 'PROGRESS' // TRIM( coupling_char ), STATUS = 'REPLACE',              &
+                      FORM = 'FORMATTED' )
 
 #if defined( __netcdf )
@@ -606,8 +576,7 @@
           ENDIF
 !
-!--       Inquire, if there is a netCDF file from a previuos run. This should
-!--       be opened for extension, if its dimensions and variables match the
-!--       actual run.
-          INQUIRE( FILE=filename, EXIST=netcdf_extend )
+!--       Inquire, if there is a netCDF file from a previous run. This should be opened for
+!--       extension, if its dimensions and variables match the actual run.
+          INQUIRE( FILE = filename, EXIST = netcdf_extend )
           IF ( netcdf_extend )  THEN
 !
@@ -615,7 +584,6 @@
              CALL netcdf_open_write_file( filename, id_set_xy(av), .TRUE., 20 )
 !
-!--          Read header information and set all ids. If there is a mismatch
-!--          between the previuos and the actual run, netcdf_extend is returned
-!--          as .FALSE.
+!--          Read header information and set all ids. If there is a mismatch between the previous
+!--          and the actual run, netcdf_extend is returned as .FALSE.
              CALL netcdf_define_header( 'xy', netcdf_extend, av )
 
@@ -628,6 +596,6 @@
 #if defined( __parallel )
 !
-!--             Set a barrier in order to assure that PE0 deleted the old file
-!--             before any other processor tries to open a new file.
+!--             Set a barrier in order to assure that PE0 deleted the old file before any other
+!--             processor tries to open a new file.
 !--             Barrier is only needed in case of parallel I/O
                 IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
@@ -647,8 +615,8 @@
 
 !
-!--          In case of parallel netCDF output, create flag file which tells
-!--          combine_plot_fields that nothing is to do.
+!--          In case of parallel netCDF output, create flag file which tells combine_plot_fields
+!--          that nothing is to do.
              IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
-                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XY' )
+                OPEN( 99, FILE = 'NO_COMBINE_PLOT_FIELDS_XY' )
                 WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
                 CLOSE( 99 )
@@ -668,8 +636,7 @@
           ENDIF
 !
-!--       Inquire, if there is a netCDF file from a previuos run. This should
-!--       be opened for extension, if its dimensions and variables match the
-!--       actual run.
-          INQUIRE( FILE=filename, EXIST=netcdf_extend )
+!--       Inquire, if there is a netCDF file from a previous run. This should be opened for
+!--       extension, if its dimensions and variables match the actual run.
+          INQUIRE( FILE = filename, EXIST = netcdf_extend )
 
           IF ( netcdf_extend )  THEN
@@ -678,7 +645,6 @@
              CALL netcdf_open_write_file( filename, id_set_xz(av), .TRUE., 23 )
 !
-!--          Read header information and set all ids. If there is a mismatch
-!--          between the previuos and the actual run, netcdf_extend is returned
-!--          as .FALSE.
+!--          Read header information and set all ids. If there is a mismatch between the previous
+!--          and the actual run, netcdf_extend is returned as .FALSE.
              CALL netcdf_define_header( 'xz', netcdf_extend, av )
 
@@ -691,6 +657,6 @@
 #if defined( __parallel )
 !
-!--             Set a barrier in order to assure that PE0 deleted the old file
-!--             before any other processor tries to open a new file
+!--             Set a barrier in order to assure that PE0 deleted the old file before any other
+!--             processor tries to open a new file.
 !--             Barrier is only needed in case of parallel I/O
                 IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
@@ -710,8 +676,8 @@
 
 !
-!--          In case of parallel netCDF output, create flag file which tells
-!--          combine_plot_fields that nothing is to do.
+!--          In case of parallel netCDF output, create flag file which tells combine_plot_fields
+!--          that nothing is to do.
              IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
-                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_XZ' )
+                OPEN( 99, FILE = 'NO_COMBINE_PLOT_FIELDS_XZ' )
                 WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
                 CLOSE( 99 )
@@ -731,8 +697,7 @@
           ENDIF
 !
-!--       Inquire, if there is a netCDF file from a previuos run. This should
-!--       be opened for extension, if its dimensions and variables match the
-!--       actual run.
-          INQUIRE( FILE=filename, EXIST=netcdf_extend )
+!--       Inquire, if there is a netCDF file from a previous run. This should be opened for
+!--       extension, if its dimensions and variables match the actual run.
+          INQUIRE( FILE = filename, EXIST=netcdf_extend )
 
           IF ( netcdf_extend )  THEN
@@ -741,7 +706,6 @@
              CALL netcdf_open_write_file( filename, id_set_yz(av), .TRUE., 26 )
 !
-!--          Read header information and set all ids. If there is a mismatch
-!--          between the previuos and the actual run, netcdf_extend is returned
-!--          as .FALSE.
+!--          Read header information and set all ids. If there is a mismatch between the previous
+!--          and the actual run, netcdf_extend is returned as .FALSE.
              CALL netcdf_define_header( 'yz', netcdf_extend, av )
 
@@ -754,6 +718,6 @@
 #if defined( __parallel )
 !
-!--             Set a barrier in order to assure that PE0 deleted the old file
-!--             before any other processor tries to open a new file
+!--             Set a barrier in order to assure that PE0 deleted the old file before any other
+!--             processor tries to open a new file.
 !--             Barrier is only needed in case of parallel I/O
                 IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
@@ -773,8 +737,8 @@
 
 !
-!--          In case of parallel netCDF output, create flag file which tells
-!--          combine_plot_fields that nothing is to do.
+!--          In case of parallel netCDF output, create flag file which tells combine_plot_fields
+!--          that nothing is to do.
              IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
-                OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_YZ' )
+                OPEN( 99, FILE = 'NO_COMBINE_PLOT_FIELDS_YZ' )
                 WRITE ( 99, '(A)' )  'no combine_plot_fields.x neccessary'
                 CLOSE( 99 )
@@ -789,7 +753,7 @@
 
 !
-!--       Inquire, if there is a netCDF file from a previuos run. This should
-!--       be opened for extension, if its variables match the actual run.
-          INQUIRE( FILE=filename, EXIST=netcdf_extend )
+!--       Inquire, if there is a netCDF file from a previous run. This should be opened for
+!--       extension, if its variables match the actual run.
+          INQUIRE( FILE = filename, EXIST = netcdf_extend )
 
           IF ( netcdf_extend )  THEN
@@ -798,7 +762,6 @@
              CALL netcdf_open_write_file( filename, id_set_pr, .FALSE., 29 )
 !
-!--          Read header information and set all ids. If there is a mismatch
-!--          between the previuos and the actual run, netcdf_extend is returned
-!--          as .FALSE.
+!--          Read header information and set all ids. If there is a mismatch between the previous
+!--          and the actual run, netcdf_extend is returned as .FALSE.
              CALL netcdf_define_header( 'pr', netcdf_extend, 0 )
 
@@ -811,5 +774,5 @@
              ENDIF
 
-          ENDIF          
+          ENDIF
 
           IF ( .NOT. netcdf_extend )  THEN
@@ -829,7 +792,7 @@
 
 !
-!--       Inquire, if there is a netCDF file from a previuos run. This should
-!--       be opened for extension, if its variables match the actual run.
-          INQUIRE( FILE=filename, EXIST=netcdf_extend )
+!--       Inquire, if there is a netCDF file from a previous run. This should be opened for
+!--       extension, if its variables match the actual run.
+          INQUIRE( FILE = filename, EXIST = netcdf_extend )
 
           IF ( netcdf_extend )  THEN
@@ -838,7 +801,6 @@
              CALL netcdf_open_write_file( filename, id_set_ts, .FALSE., 32 )
 !
-!--          Read header information and set all ids. If there is a mismatch
-!--          between the previuos and the actual run, netcdf_extend is returned
-!--          as .FALSE.
+!--          Read header information and set all ids. If there is a mismatch between the previous
+!--          and the actual run, netcdf_extend is returned as .FALSE.
              CALL netcdf_define_header( 'ts', netcdf_extend, 0 )
 
@@ -851,5 +813,5 @@
              ENDIF
 
-          ENDIF          
+          ENDIF
 
           IF ( .NOT. netcdf_extend )  THEN
@@ -875,8 +837,7 @@
           ENDIF
 !
-!--       Inquire, if there is a netCDF file from a previous run. This should
-!--       be opened for extension, if its dimensions and variables match the
-!--       actual run.
-          INQUIRE( FILE=filename, EXIST=netcdf_extend )
+!--       Inquire, if there is a netCDF file from a previous run. This should be opened for
+!--       extension, if its dimensions and variables match the actual run.
+          INQUIRE( FILE = filename, EXIST = netcdf_extend )
           IF ( netcdf_extend )  THEN
 !
@@ -884,7 +845,6 @@
              CALL netcdf_open_write_file( filename, id_set_3d(av), .TRUE., 35 )
 !
-!--          Read header information and set all ids. If there is a mismatch
-!--          between the previuos and the actual run, netcdf_extend is returned
-!--          as .FALSE.
+!--          Read header information and set all ids. If there is a mismatch between the previous
+!--          and the actual run, netcdf_extend is returned as .FALSE.
              CALL netcdf_define_header( '3d', netcdf_extend, av )
 
@@ -897,6 +857,6 @@
 #if defined( __parallel )
 !
-!--             Set a barrier in order to assure that PE0 deleted the old file
-!--             before any other processor tries to open a new file
+!--             Set a barrier in order to assure that PE0 deleted the old file before any other
+!--             processor tries to open a new file.
 !--             Barrier is only needed in case of parallel I/O
                 IF ( netcdf_data_format > 4 )  CALL MPI_BARRIER( comm2d, ierr )
@@ -916,6 +876,6 @@
 
 !
-!--          In case of parallel netCDF output, create flag file which tells
-!--          combine_plot_fields that nothing is to do.
+!--          In case of parallel netCDF output, create flag file which tells combine_plot_fields
+!--          that nothing is to do.
              IF ( myid == 0  .AND.  netcdf_data_format > 4 )  THEN
                 OPEN( 99, FILE='NO_COMBINE_PLOT_FIELDS_3D' )
@@ -933,6 +893,6 @@
 
 !
-!--       Inquire, if there is a netCDF file from a previuos run. This should
-!--       be opened for extension, if its variables match the actual run.
+!--       Inquire, if there is a netCDF file from a previous run. This should be opened for
+!--       extension, if its variables match the actual run.
           INQUIRE( FILE=filename, EXIST=netcdf_extend )
 
@@ -943,7 +903,6 @@
 
 !
-!--          Read header information and set all ids. If there is a mismatch
-!--          between the previuos and the actual run, netcdf_extend is returned
-!--          as .FALSE.
+!--          Read header information and set all ids. If there is a mismatch between the previous
+!--          and the actual run, netcdf_extend is returned as .FALSE.
              CALL netcdf_define_header( 'sp', netcdf_extend, 0 )
 
@@ -956,5 +915,5 @@
              ENDIF
 
-          ENDIF          
+          ENDIF
 
           IF ( .NOT. netcdf_extend )  THEN
@@ -979,5 +938,5 @@
 !          ENDIF
 !
-!--       Inquire, if there is a netCDF file from a previuos run. This should
+!--       Inquire, if there is a netCDF file from a previous run. This should
 !--       be opened for extension, if its variables match the actual run.
 !          INQUIRE( FILE=filename, EXIST=netcdf_extend )
@@ -989,5 +948,5 @@
 !
 !--          Read header information and set all ids. If there is a mismatch
-!--          between the previuos and the actual run, netcdf_extend is returned
+!--          between the previous and the actual run, netcdf_extend is returned
 !--          as .FALSE.
 !             CALL netcdf_define_header( 'pt', netcdf_extend, 0 )
@@ -1001,5 +960,5 @@
 !             ENDIF
 
-!          ENDIF          
+!          ENDIF
 
 !          IF ( .NOT. netcdf_extend )  THEN
@@ -1014,5 +973,5 @@
 !                ENDIF
 #if defined( __parallel )
-! 
+!
 !--             Set a barrier in order to allow that all other processors in the
 !--             directory created by PE0 can open their file
@@ -1037,7 +996,7 @@
 
 !
-!--       Inquire, if there is a netCDF file from a previuos run. This should
-!--       be opened for extension, if its variables match the actual run.
-          INQUIRE( FILE=filename, EXIST=netcdf_extend )
+!--       Inquire, if there is a netCDF file from a previous run. This should be opened for
+!--       extension, if its variables match the actual run.
+          INQUIRE( FILE = filename, EXIST = netcdf_extend )
 
           IF ( netcdf_extend )  THEN
@@ -1046,7 +1005,6 @@
              CALL netcdf_open_write_file( filename, id_set_pts, .FALSE., 393 )
 !
-!--          Read header information and set all ids. If there is a mismatch
-!--          between the previuos and the actual run, netcdf_extend is returned
-!--          as .FALSE.
+!--          Read header information and set all ids. If there is a mismatch between the previous
+!--          and the actual run, netcdf_extend is returned as .FALSE.
              CALL netcdf_define_header( 'ps', netcdf_extend, 0 )
 
@@ -1059,5 +1017,5 @@
              ENDIF
 
-          ENDIF          
+          ENDIF
 
           IF ( .NOT. netcdf_extend )  THEN
@@ -1076,6 +1034,6 @@
              filename = 'DATA_AGT_NETCDF'
 !
-!--       Inquire, if there is a netCDF file from a previuos run. This should
-!--       be opened for extension, if its variables match the actual run.
+!--       Inquire, if there is a netCDF file from a previous run. This should be opened for
+!--       extension, if its variables match the actual run.
           INQUIRE( FILE=filename, EXIST=netcdf_extend )
 
@@ -1095,8 +1053,8 @@
 ! !
 ! !--          Read header information and set all ids. If there is a mismatch
-! !--          between the previuos and the actual run, netcdf_extend is returned
+! !--          between the previous and the actual run, netcdf_extend is returned
 ! !--          as .FALSE.
 !              CALL netcdf_define_header( 'ag', netcdf_extend, 0 )
-! 
+!
 ! !
 ! !--          Remove the local file, if it can not be extended
@@ -1106,5 +1064,5 @@
 !                 CALL local_system( 'rm ' // TRIM( filename ) )
 !              ENDIF
-! 
+!
 !           ENDIF
 
@@ -1120,5 +1078,5 @@
 !                 ENDIF
 ! #if defined( __parallel )
-! ! 
+! !
 ! !--             Set a barrier in order to allow that all other processors in the
 ! !--             directory created by PE0 can open their file
@@ -1138,7 +1096,7 @@
 
 !
-!--       Inquire, if there is a netCDF file from a previuos run. This should
-!--       be opened for extension, if its variables match the actual run.
-          INQUIRE( FILE=filename, EXIST=netcdf_extend )
+!--       Inquire, if there is a netCDF file from a previous run. This should be opened for
+!--       extension, if its variables match the actual run.
+          INQUIRE( FILE = filename, EXIST = netcdf_extend )
 
           IF ( netcdf_extend )  THEN
@@ -1147,7 +1105,6 @@
              CALL netcdf_open_write_file( filename, id_set_fl, .FALSE., 532 )
 !
-!--          Read header information and set all ids. If there is a mismatch
-!--          between the previuos and the actual run, netcdf_extend is returned
-!--          as .FALSE.
+!--          Read header information and set all ids. If there is a mismatch between the previous
+!--          and the actual run, netcdf_extend is returned as .FALSE.
              CALL netcdf_define_header( 'fl', netcdf_extend, 0 )
 
@@ -1160,5 +1117,5 @@
              ENDIF
 
-          ENDIF          
+          ENDIF
 
           IF ( .NOT. netcdf_extend )  THEN
@@ -1179,18 +1136,15 @@
              mid = file_id - 200
              WRITE ( mask_char,'(A2,I2.2)')  '_M', mid
-             filename = 'DATA_MASK_NETCDF' // TRIM( coupling_char ) //         &
-                        mask_char
+             filename = 'DATA_MASK_NETCDF' // TRIM( coupling_char ) // mask_char
              av = 0
           ELSE
              mid = file_id - (200+max_masks)
              WRITE ( mask_char,'(A2,I2.2)')  '_M', mid
-             filename = 'DATA_MASK_AV_NETCDF' // TRIM( coupling_char ) //      &
-                        mask_char
+             filename = 'DATA_MASK_AV_NETCDF' // TRIM( coupling_char ) // mask_char
              av = 1
           ENDIF
 !
-!--       Inquire, if there is a netCDF file from a previuos run. This should
-!--       be opened for extension, if its dimensions and variables match the
-!--       actual run.
+!--       Inquire, if there is a netCDF file from a previous run. This should be opened for
+!--       extension, if its dimensions and variables match the actual run.
           INQUIRE( FILE=filename, EXIST=netcdf_extend )
 
@@ -1198,10 +1152,8 @@
 !
 !--          Open an existing netCDF file for output
-             CALL netcdf_open_write_file( filename, id_set_mask(mid,av),       &
-                                          .TRUE., 456 )
-!
-!--          Read header information and set all ids. If there is a mismatch
-!--          between the previuos and the actual run, netcdf_extend is returned
-!--          as .FALSE.
+             CALL netcdf_open_write_file( filename, id_set_mask(mid,av), .TRUE., 456 )
+!
+!--          Read header information and set all ids. If there is a mismatch between the previous
+!--          and the actual run, netcdf_extend is returned as .FALSE.
              CALL netcdf_define_header( 'ma', netcdf_extend, file_id )
 
@@ -1214,10 +1166,10 @@
              ENDIF
 
-          ENDIF          
+          ENDIF
 
           IF ( .NOT. netcdf_extend )  THEN
 !
 !--          Create a new netCDF output file with requested netCDF format
-             CALL netcdf_create_file( filename, id_set_mask(mid,av), .TRUE., 458 )
+             CALL netcdf_create_file( filename, id_set_mask(mid,av), .TRUE. , 458 )
 !
 !--          Define the header
@@ -1239,5 +1191,5 @@
        CASE DEFAULT
 
-          WRITE( message_string, * ) 'no OPEN-statement for file-id ',file_id
+          WRITE( message_string, * ) 'no OPEN-statement for file-id ', file_id
           CALL message( 'check_open', 'PA0172', 2, 2, -1, 6, 1 )
 
@@ -1250,7 +1202,7 @@
 !
 !-- Formats
-8000 FORMAT (A/                                                                &
-             '  step    time    # of parts     lPE sent/recv  rPE sent/recv  ',&
-             'sPE sent/recv  nPE sent/recv    max # of parts  '/               &
+8000 FORMAT (A/                                                                                    &
+             '  step    time    # of parts     lPE sent/recv  rPE sent/recv  ',                    &
+             'sPE sent/recv  nPE sent/recv    max # of parts  '/                                   &
              109('-'))
 
Index: palm/trunk/SOURCE/lagrangian_particle_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/lagrangian_particle_model_mod.f90	(revision 4545)
+++ palm/trunk/SOURCE/lagrangian_particle_model_mod.f90	(revision 4546)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Variables iran and iran_part completely removed, added I/O of parallel random numbers to restart
+! file
+! 
+! 4545 2020-05-22 13:17:57Z schwenkel
 ! Using parallel random generator, thus preventing dependency of PE number
 ! 
@@ -176,5 +180,5 @@
                intermediate_timestep_count, intermediate_timestep_count_max,   &
                message_string, molecular_viscosity, ocean_mode,                &
-               particle_maximum_age, iran, restart_data_format_output,         &
+               particle_maximum_age, restart_data_format_output,               &
                simulated_time, topography, dopts_time_count,                   &
                time_since_reference_point, rho_surface, u_gtrans, v_gtrans,    &
@@ -260,5 +264,4 @@
     INTEGER(iwp) ::  deleted_particles = 0                        !< number of deleted particles per time step    
     INTEGER(iwp) ::  i_splitting_mode                             !< dummy for splitting mode
-    INTEGER(iwp) ::  iran_part = -1234567                         !< number for random generator    
     INTEGER(iwp) ::  max_number_particles_per_gridbox = 100       !< namelist parameter (see documentation)
     INTEGER(iwp) ::  isf                                          !< dummy for splitting function
@@ -282,5 +285,5 @@
     INTEGER(iwp) ::  trnp_count_recv_sum                          !< parameter for particle exchange of PEs
 
-    INTEGER(isp), DIMENSION(:,:,:), ALLOCATABLE ::  seq_random_array_particle   !< sequence of random array for particle
+    INTEGER(isp), DIMENSION(:,:,:), ALLOCATABLE ::  seq_random_array_particles   !< sequence of random array for particle
 
     LOGICAL ::  lagrangian_particle_model = .FALSE.       !< namelist parameter (see documentation) 
@@ -1249,16 +1252,11 @@
           particle_groups(i)%radius        = radius(i)
        ENDDO
-!
-!--    Set a seed value for the random number generator to be exclusively
-!--    used for the particle code. The generated random numbers should be
-!--    different on the different PEs.
-       iran_part = iran_part + myid
 
 !
 !--    Initialize parallel random number sequence seed for particles
-!--    This is done individually, as thus particle random numbers does
-!--    not affect random numbers used for the flow field.
-       ALLOCATE ( seq_random_array_particle(5,nys:nyn,nxl:nxr) )
-       seq_random_array_particle = 0
+!--    This is done separately here, as thus particle random numbers do not affect the random
+!--    numbers used for the flow field (e.g. for generating flow disturbances).
+       ALLOCATE ( seq_random_array_particles(5,nys:nyn,nxl:nxr) )
+       seq_random_array_particles = 0
 
 !--    Initializing with random_seed_parallel for every vertical
@@ -1269,5 +1267,5 @@
              CALL random_seed_parallel (random_sequence=id_random_array(j, i))
              CALL random_number_parallel (random_dummy)
-             CALL random_seed_parallel (get=seq_random_array_particle(:, j, i))
+             CALL random_seed_parallel (get=seq_random_array_particles(:, j, i))
           ENDDO
        ENDDO
@@ -1537,5 +1535,5 @@
 !
 !--          Put the random seeds at grid point jp, ip
-             CALL random_seed_parallel( put=seq_random_array_particle(:,jp,ip) )
+             CALL random_seed_parallel( put=seq_random_array_particles(:,jp,ip) )
              DO  kp = nzb+1, nzt
                 number_of_particles = prt_count(kp,jp,ip)
@@ -1607,6 +1605,6 @@
              ENDDO
 !
-!--       Get the new random seeds from last call at grid point jp, ip
-          CALL random_seed_parallel( get=seq_random_array_particle(:,jp,ip) )
+!--          Get the new random seeds from last call at grid point jp, ip
+             CALL random_seed_parallel( get=seq_random_array_particles(:,jp,ip) )
           ENDDO
        ENDDO
@@ -1738,5 +1736,5 @@
 !
 !--       Put the random seeds at grid point jp, ip
-          CALL random_seed_parallel( put=seq_random_array_particle(:,jp,ip) )
+          CALL random_seed_parallel( put=seq_random_array_particles(:,jp,ip) )
           DO  kp = nzb+1, nzt
 
@@ -1771,5 +1769,5 @@
                 particles(n)%weight_factor = particles(n)%weight_factor * aero_weight
 !
-!--             create random numver with parallel number generator
+!--             Create random numver with parallel number generator
                 CALL random_number_parallel( random_dummy )
                 IF ( particles(n)%weight_factor - FLOOR(particles(n)%weight_factor,KIND=wp) &
@@ -1819,6 +1817,6 @@
           ENDDO
 !
-!--    Get the new random seeds from last call at grid point j
-       CALL random_seed_parallel( get=seq_random_array_particle(:,jp,ip) )
+!--       Get the new random seeds from last call at grid point j
+          CALL random_seed_parallel( get=seq_random_array_particles(:,jp,ip) )
        ENDDO
     ENDDO
@@ -2215,5 +2213,5 @@
 !
 !--                   Put the random seeds at grid point j, i
-                      CALL random_seed_parallel( put=seq_random_array_particle(:,j,i) )
+                      CALL random_seed_parallel( put=seq_random_array_particles(:,j,i) )
 
                       DO  k = nzb+1, nzt
@@ -2301,5 +2299,5 @@
 !
 !--                   Get the new random seeds from last call at grid point jp, ip
-                      CALL random_seed_parallel( get=seq_random_array_particle(:,j,i) )
+                      CALL random_seed_parallel( get=seq_random_array_particles(:,j,i) )
 
                    ENDDO
@@ -3110,4 +3108,6 @@
     LOGICAL, INTENT(OUT)  ::  found
 
+    INTEGER(isp), DIMENSION(:,:,:), ALLOCATABLE ::  tmp_2d_seq_random_particles  !< temporary array for storing random generator data for the lpm
+
     REAL(wp), DIMENSION(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp,nxl_on_file-nbgp:nxr_on_file+nbgp) ::  tmp_3d   !<
 
@@ -3116,7 +3116,4 @@
 
     SELECT CASE ( restart_string(1:length) )
-
-       CASE ( 'iran' ) ! matching random numbers is still unresolved issue
-          IF ( k == 1 )  READ ( 13 )  iran, iran_part
 
         CASE ( 'pc_av' )
@@ -3160,4 +3157,14 @@
                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
+         CASE ( 'seq_random_array_particles' )
+             ALLOCATE( tmp_2d_seq_random_particles(5,nys_on_file:nyn_on_file,nxl_on_file:nxr_on_file) )
+             IF ( .NOT. ALLOCATED( seq_random_array_particles ) )  THEN
+                ALLOCATE( seq_random_array_particles(5,nys:nyn,nxl:nxr) )
+             ENDIF
+             IF ( k == 1 )  READ ( 13 )  tmp_2d_seq_random_particles
+             seq_random_array_particles(:,nysc:nync,nxlc:nxrc) =                                   &
+                                                  tmp_2d_seq_random_particles(:,nysf:nynf,nxlf:nxrf)
+             DEALLOCATE( tmp_2d_seq_random_particles )
+
           CASE DEFAULT
 
@@ -3178,8 +3185,9 @@
     IMPLICIT NONE
 
+    CHARACTER (LEN=20) ::  tmp_name  !< temporary variable
+
+    INTEGER(iwp) ::  i  !< loop index
+
     LOGICAL ::  array_found  !<
-
-    CALL rrd_mpi_io( 'iran', iran ) ! matching random numbers is still unresolved issue
-    CALL rrd_mpi_io( 'iran_part', iran_part )
 
     CALL rd_mpi_io_check_array( 'pc_av' , found = array_found )
@@ -3211,4 +3219,15 @@
        IF ( .NOT. ALLOCATED( ql_vp_av ) )  ALLOCATE( ql_vp_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
        CALL rrd_mpi_io( 'ql_vp_av', ql_vp_av )
+    ENDIF
+
+    CALL rd_mpi_io_check_array( 'seq_random_array_particles' , found = array_found )
+    IF ( array_found )  THEN
+       IF ( .NOT. ALLOCATED( seq_random_array_particles ) )  THEN
+          ALLOCATE( seq_random_array_particles(5,nys:nyn,nxl:nxr) )
+       ENDIF
+       DO  i = 1, SIZE( seq_random_array_particles, 1 )
+          WRITE( tmp_name, '(A,I2.2)' )  'seq_random_array_particles', i
+          CALL rrd_mpi_io( TRIM(tmp_name), seq_random_array_particles(i,:,:) )
+       ENDDO
     ENDIF
 
@@ -3224,5 +3243,7 @@
  
     CHARACTER (LEN=10) ::  particle_binary_version   !<
-
+    CHARACTER (LEN=20) ::  tmp_name                  !< temporary variable
+
+    INTEGER(iwp) ::  i                               !< loop index
     INTEGER(iwp) ::  ip                              !<
     INTEGER(iwp) ::  jp                              !<
@@ -3282,11 +3303,17 @@
     IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
 
-       CALL wrd_write_string( 'iran' )  ! matching random numbers is still unresolved issue
-       WRITE ( 14 )  iran, iran_part
+       IF ( ALLOCATED( seq_random_array_particles ) )  THEN
+          CALL wrd_write_string( 'seq_random_array_particles' )
+          WRITE ( 14 )  seq_random_array_particles
+       ENDIF
 
     ELSEIF ( restart_data_format_output(1:3) == 'mpi' )  THEN
 
-       CALL wrd_mpi_io( 'iran', iran )  ! matching random numbers is still unresolved issue
-       CALL wrd_mpi_io( 'iran_part', iran_part )
+       IF ( ALLOCATED( seq_random_array_particles ) )  THEN
+          DO  i = 1, SIZE( seq_random_array_particles, 1 )
+             WRITE( tmp_name, '(A,I2.2)' )  'seq_random_array_particles', i
+             CALL wrd_mpi_io( TRIM( tmp_name ), seq_random_array_particles(i,:,:) )
+          ENDDO
+       ENDIF
 
     ENDIF
