Index: palm/trunk/SOURCE/restart_data_mpi_io_mod.f90
===================================================================
--- palm/trunk/SOURCE/restart_data_mpi_io_mod.f90	(revision 4536)
+++ palm/trunk/SOURCE/restart_data_mpi_io_mod.f90	(revision 4539)
@@ -24,4 +24,8 @@
 ! -----------------
 ! $Id$
+! checks added, if index limits in header are exceeded
+! bugfix in rrd_mpi_io_int_2d
+! 
+! 4536 2020-05-17 17:24:13Z raasch
 ! messages and debug output converted to PALM routines
 ! 
@@ -178,6 +182,6 @@
 
     INTEGER(KIND=rd_offset_kind)                ::  header_char_index
-    INTEGER, PARAMETER                          ::  max_nr_text=128
-    CHARACTER(LEN=128), DIMENSION(max_nr_text)  ::  text_lines
+    INTEGER, PARAMETER                          ::  max_nr_char=128
+    CHARACTER(LEN=128), DIMENSION(max_nr_char)  ::  text_lines
 
     INTEGER(KIND=rd_offset_kind)                ::  header_real_index
@@ -186,5 +190,5 @@
     REAL(KIND=wp), DIMENSION(max_nr_real)       ::  real_values
 
-    INTEGER(KIND=rd_offset_kind)                ::  header_arr_index
+    INTEGER(KIND=rd_offset_kind)                ::  header_array_index
     INTEGER, PARAMETER                          ::  max_nr_arrays=600
     CHARACTER(LEN=32), DIMENSION(max_nr_arrays) ::  array_names
@@ -456,6 +460,6 @@
     header_int_index   = 1
     header_char_index  = 1
-    header_real_index   = 1
-    header_arr_index   = 1
+    header_real_index  = 1
+    header_array_index = 1
 
     int_names    = ' '
@@ -852,5 +856,5 @@
              CALL MPI_FILE_SET_VIEW( fh, array_position, MPI_INTEGER, ft_2di_nb, 'native',         &
                                      MPI_INFO_NULL, ierr )
-             CALL MPI_FILE_READ_ALL( fh, array_2d, SIZE( array_2d ), MPI_INTEGER, status, ierr )
+             CALL MPI_FILE_READ_ALL( fh, array_2di, SIZE( array_2di ), MPI_INTEGER, status, ierr )
           ENDIF
           CALL sm_io%sm_node_barrier()
@@ -1101,4 +1105,8 @@
 
 
+    IF ( header_int_index == max_nr_int )  THEN
+       STOP '+++ maximum number of INTEGER entries in restart file header exceeded'
+    ENDIF
+
     int_names(header_int_index)  = name
     int_values(header_int_index) = value
@@ -1118,4 +1126,8 @@
 
 
+    IF ( header_real_index == max_nr_real )  THEN
+       STOP '+++ maximum number of REAL entries in restart file header exceeded'
+    ENDIF
+
     real_names(header_real_index)  = name
     real_values(header_real_index) = value
@@ -1146,7 +1158,11 @@
 
 
-    array_names(header_arr_index)  = name
-    array_offset(header_arr_index) = array_position
-    header_arr_index = header_arr_index + 1
+    IF ( header_array_index == max_nr_arrays )  THEN
+       STOP '+++ maximum number of 2d/3d-array entries in restart file header exceeded'
+    ENDIF
+
+    array_names(header_array_index)  = name
+    array_offset(header_array_index) = array_position
+    header_array_index = header_array_index + 1
 
     IF ( include_total_domain_boundaries )  THEN
@@ -1207,7 +1223,11 @@
 
 
-    array_names(header_arr_index)  = name
-    array_offset(header_arr_index) = array_position
-    header_arr_index = header_arr_index + 1
+    IF ( header_array_index == max_nr_arrays )  THEN
+       STOP '+++ maximum number of 2d/3d-array entries in restart file header exceeded'
+    ENDIF
+
+    array_names(header_array_index)  = name
+    array_offset(header_array_index) = array_position
+    header_array_index = header_array_index + 1
 
     IF ( ( nxr-nxl + 1 + 2 * nbgp ) == SIZE( data, 2 ) )  THEN
@@ -1278,7 +1298,11 @@
 
 
-    array_names(header_arr_index)  = name
-    array_offset(header_arr_index) = array_position
-    header_arr_index = header_arr_index + 1
+    IF ( header_array_index == max_nr_arrays )  THEN
+       STOP '+++ maximum number of 2d/3d-array entries in restart file header exceeded'
+    ENDIF
+
+    array_names(header_array_index)  = name
+    array_offset(header_array_index) = array_position
+    header_array_index = header_array_index + 1
 
     IF ( include_total_domain_boundaries )  THEN
@@ -1347,7 +1371,11 @@
 
 
-    array_names(header_arr_index)  = name
-    array_offset(header_arr_index) = array_position
-    header_arr_index = header_arr_index + 1
+    IF ( header_array_index == max_nr_arrays )  THEN
+       STOP '+++ maximum number of 2d/3d-array entries in restart file header exceeded'
+    ENDIF
+
+    array_names(header_array_index)  = name
+    array_offset(header_array_index) = array_position
+    header_array_index = header_array_index + 1
 
 #if defined( __parallel )
@@ -1411,4 +1439,8 @@
 
 
+    IF ( header_char_index == max_nr_char )  THEN
+       STOP '+++ maximum number of CHARACTER entries in restart file header exceeded'
+    ENDIF
+
     lo_line      = name
     lo_line(33:) = text
@@ -1687,7 +1719,11 @@
     offset = 0
 
-    array_names(header_arr_index)  = name
-    array_offset(header_arr_index) = array_position
-    header_arr_index = header_arr_index + 1
+    IF ( header_array_index == max_nr_arrays )  THEN
+       STOP '+++ maximum number of 2d/3d-array entries in restart file header exceeded'
+    ENDIF
+
+    array_names(header_array_index)  = name
+    array_offset(header_array_index) = array_position
+    header_array_index = header_array_index + 1
 
 !
@@ -1822,8 +1858,12 @@
 #endif
 
+    IF ( header_array_index == max_nr_arrays )  THEN
+       STOP '+++ maximum number of 2d/3d-array entries in restart file header exceeded'
+    ENDIF
+
     offset = 0
-    array_names(header_arr_index)  = name
-    array_offset(header_arr_index) = array_position
-    header_arr_index = header_arr_index + 1
+    array_names(header_array_index)  = name
+    array_offset(header_array_index) = array_position
+    header_array_index = header_array_index + 1
 
 !
@@ -2052,10 +2092,17 @@
     ENDIF
 !
-!-- In case of 2d-data, name is writen only once
+!-- In case of 2d-data, name is written only once
     IF ( lo_first_index == 1 )  THEN
-       array_names(header_arr_index)  = name
-       array_offset(header_arr_index) = array_position
-       header_arr_index = header_arr_index + 1
-    ENDIF
+
+       IF ( header_array_index == max_nr_arrays )  THEN
+          STOP '+++ maximum number of 2d/3d-array entries in restart file header exceeded'
+       ENDIF
+
+       array_names(header_array_index)  = name
+       array_offset(header_array_index) = array_position
+       header_array_index = header_array_index + 1
+
+    ENDIF
+
 #if defined( __parallel )
     IF ( sm_io%is_sm_active() )  THEN
@@ -2155,5 +2202,5 @@
        tgh%nr_char   = header_char_index - 1
        tgh%nr_real   = header_real_index - 1
-       tgh%nr_arrays = header_arr_index - 1
+       tgh%nr_arrays = header_array_index - 1
        tgh%total_nx  = lb%nx + 1
        tgh%total_ny  = lb%ny + 1
