Index: palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/urban_surface_mod.f90	(revision 4872)
+++ palm/trunk/SOURCE/urban_surface_mod.f90	(revision 4893)
@@ -27,4 +27,7 @@
 ! -----------------
 ! $Id$
+! revised output of surface data via MPI-IO for better performance
+!
+! 4872 2021-02-12 15:49:02Z raasch
 ! internal switch removed from namelist
 !
@@ -6608,12 +6611,13 @@
  SUBROUTINE usm_rrd_local_mpi
 
-
     CHARACTER(LEN=1) ::  dum  !< dummy string to create input-variable name
 
     INTEGER(iwp) ::  l  !< loop index for surface types
 
-    INTEGER(iwp), DIMENSION(nys:nyn,nxl:nxr) ::  global_start
-
-    LOGICAL ::  ldum  !< dummy variable
+    INTEGER(iwp), DIMENSION(nys:nyn,nxl:nxr) ::  global_end_index
+    INTEGER(iwp), DIMENSION(nys:nyn,nxl:nxr) ::  global_start_index
+
+    LOGICAL ::  data_to_read  !< dummy variable
+
 
     DO  l = 0, 1
@@ -6621,34 +6625,32 @@
        WRITE( dum, '(I1)' )  l
 
-       CALL rrd_mpi_io( 'usm_start_index_h_' //dum,  surf_usm_h(l)%start_index )
-       CALL rrd_mpi_io( 'usm_end_index_h_' //dum, surf_usm_h(l)%end_index )
-       CALL rrd_mpi_io( 'usm_global_start_h_' //dum, global_start )
-
-       CALL rd_mpi_io_surface_filetypes( surf_usm_h(l)%start_index, surf_usm_h(l)%end_index, ldum, &
-                                         global_start )
-
-       IF ( MAXVAL( surf_usm_h(l)%end_index ) <= 0 )  CYCLE
-
-       IF ( .NOT.  ALLOCATED( t_surf_wall_h_1(l)%val ) )                                             &
+       CALL rrd_mpi_io( 'usm_global_start_h_' //dum, global_start_index )
+       CALL rrd_mpi_io( 'usm_global_end_h_' //dum, global_end_index )
+
+       CALL rd_mpi_io_surface_filetypes( surf_usm_h(l)%start_index, surf_usm_h(l)%end_index,       &
+                                         data_to_read, global_start_index, global_end_index )
+       IF ( .NOT. data_to_read )  CYCLE
+
+       IF ( .NOT. ALLOCATED( t_surf_wall_h_1(l)%val ) )                                            &
           ALLOCATE( t_surf_wall_h_1(l)%val(1:surf_usm_h(l)%ns) )
        CALL rrd_mpi_io_surface( 't_surf_wall_h(' // dum // ')', t_surf_wall_h_1(l)%val )
 
-       IF ( .NOT.  ALLOCATED( t_surf_window_h_1(l)%val ) )                                           &
+       IF ( .NOT. ALLOCATED( t_surf_window_h_1(l)%val ) )                                          &
           ALLOCATE( t_surf_window_h_1(l)%val(1:surf_usm_h(l)%ns) )
        CALL rrd_mpi_io_surface( 't_surf_window_h(' // dum // ')', t_surf_window_h_1(l)%val )
 
-       IF ( .NOT.  ALLOCATED( t_surf_green_h_1(l)%val ) )                                            &
+       IF ( .NOT. ALLOCATED( t_surf_green_h_1(l)%val ) )                                           &
           ALLOCATE( t_surf_green_h_1(l)%val(1:surf_usm_h(l)%ns) )
        CALL rrd_mpi_io_surface( 't_surf_green_h(' // dum // ')', t_surf_green_h_1(l)%val )
 
-       IF ( .NOT.  ALLOCATED( m_liq_usm_h_1(l)%val ) )                                             &
+       IF ( .NOT. ALLOCATED( m_liq_usm_h_1(l)%val ) )                                              &
           ALLOCATE( m_liq_usm_h_1(l)%val(1:surf_usm_h(l)%ns) )
        CALL rrd_mpi_io_surface( 'm_liq_usm_h(' // dum // ')', m_liq_usm_h_1(l)%val )
 
        IF ( indoor_model )  THEN
-          IF ( .NOT.  ALLOCATED( surf_usm_h(l)%waste_heat ) )                                      &
+          IF ( .NOT. ALLOCATED( surf_usm_h(l)%waste_heat ) )                                       &
              ALLOCATE( surf_usm_h(l)%waste_heat(1:surf_usm_h(l)%ns) )
           CALL rrd_mpi_io_surface( 'waste_heat_h(' // dum // ')', surf_usm_h(l)%waste_heat )
-          IF ( .NOT.  ALLOCATED( surf_usm_h(l)%t_prev ) )                                          &
+          IF ( .NOT. ALLOCATED( surf_usm_h(l)%t_prev ) )                                           &
              ALLOCATE( surf_usm_h(l)%t_prev(1:surf_usm_h(l)%ns) )
           CALL rrd_mpi_io_surface( 't_prev_h(' // dum // ')', surf_usm_h(l)%t_prev )
@@ -6660,30 +6662,28 @@
        WRITE( dum, '(I1)' )  l
 
-       CALL rrd_mpi_io( 'usm_start_index_v_' //dum, surf_usm_v(l)%start_index )
-       CALL rrd_mpi_io( 'usm_end_index_v_' // dum, surf_usm_v(l)%end_index )
-       CALL rrd_mpi_io( 'usm_global_start_v_' // dum, global_start )
-
-       CALL rd_mpi_io_surface_filetypes( surf_usm_v(l)%start_index, surf_usm_v(l)%end_index, ldum, &
-                                         global_start )
-
-       IF ( MAXVAL( surf_usm_v(l)%end_index ) <= 0 )  CYCLE
-
-       IF ( .NOT.  ALLOCATED( t_surf_wall_v_1(l)%val ) )                                             &
+       CALL rrd_mpi_io( 'usm_global_start_v_' // dum, global_start_index )
+       CALL rrd_mpi_io( 'usm_global_end_v_' // dum, global_end_index )
+
+       CALL rd_mpi_io_surface_filetypes( surf_usm_v(l)%start_index, surf_usm_v(l)%end_index,       &
+                                         data_to_read, global_start_index, global_end_index )
+       IF ( .NOT. data_to_read )  CYCLE
+
+       IF ( .NOT. ALLOCATED( t_surf_wall_v_1(l)%val ) )                                            &
           ALLOCATE( t_surf_wall_v_1(l)%val(1:surf_usm_v(l)%ns) )
        CALL rrd_mpi_io_surface( 't_surf_wall_v(' // dum // ')', t_surf_wall_v_1(l)%val )
 
-       IF ( .NOT.  ALLOCATED( t_surf_window_v_1(l)%val ) )                                           &
+       IF ( .NOT. ALLOCATED( t_surf_window_v_1(l)%val ) )                                          &
           ALLOCATE( t_surf_window_v_1(l)%val(1:surf_usm_v(l)%ns) )
        CALL rrd_mpi_io_surface( 't_surf_window_v(' // dum // ')', t_surf_window_v_1(l)%val )
 
-       IF ( .NOT.  ALLOCATED( t_surf_green_v_1(l)%val ) )                                            &
+       IF ( .NOT. ALLOCATED( t_surf_green_v_1(l)%val ) )                                           &
           ALLOCATE( t_surf_green_v_1(l)%val(1:surf_usm_v(l)%ns) )
        CALL rrd_mpi_io_surface( 't_surf_green_v(' // dum // ')', t_surf_green_v_1(l)%val)
 
        IF ( indoor_model )  THEN
-          IF ( .NOT.  ALLOCATED( surf_usm_v(l)%waste_heat ) )                                      &
+          IF ( .NOT. ALLOCATED( surf_usm_v(l)%waste_heat ) )                                       &
              ALLOCATE( surf_usm_v(l)%waste_heat(1:surf_usm_v(l)%ns) )
           CALL rrd_mpi_io_surface( 'waste_heat_v(' // dum // ')', surf_usm_v(l)%waste_heat )
-          IF ( .NOT.  ALLOCATED( surf_usm_v(l)%t_prev ) )                                          &
+          IF ( .NOT. ALLOCATED( surf_usm_v(l)%t_prev ) )                                           &
              ALLOCATE( surf_usm_v(l)%t_prev(1:surf_usm_v(l)%ns) )
           CALL rrd_mpi_io_surface( 't_prev_v(' // dum // ')', surf_usm_v(l)%t_prev )
@@ -6696,22 +6696,20 @@
        WRITE( dum, '(I1)' )  l
 
-       CALL rrd_mpi_io( 'usm_start_index_h_2_' //dum,  surf_usm_h(l)%start_index )
-       CALL rrd_mpi_io( 'usm_end_index_h_2_' //dum, surf_usm_h(l)%end_index )
-       CALL rrd_mpi_io( 'usm_global_start_h_2_' //dum, global_start )
-
-       CALL rd_mpi_io_surface_filetypes( surf_usm_h(l)%start_index, surf_usm_h(l)%end_index, ldum,          &
-                                         global_start )
-
-       IF ( MAXVAL( surf_usm_h(l)%end_index ) <= 0 )  CYCLE
-
-       IF ( .NOT.  ALLOCATED( t_wall_h_1(l)%val ) )                                                          &
+       CALL rrd_mpi_io( 'usm_global_start_h_2_' //dum, global_start_index )
+       CALL rrd_mpi_io( 'usm_global_end_h_2_' //dum, global_end_index )
+
+       CALL rd_mpi_io_surface_filetypes( surf_usm_h(l)%start_index, surf_usm_h(l)%end_index,       &
+                                         data_to_read, global_start_index, global_end_index )
+       IF ( .NOT. data_to_read )  CYCLE
+
+       IF ( .NOT. ALLOCATED( t_wall_h_1(l)%val ) )                                                 &
           ALLOCATE( t_wall_h_1(l)%val(nzb_wall:nzt_wall+1,1:surf_usm_h(l)%ns) )
        CALL rrd_mpi_io_surface( 't_wall_h(' // dum // ')', t_wall_h_1(l)%val )
 
-       IF ( .NOT.  ALLOCATED( t_window_h_1(l)%val ) )                                                        &
+       IF ( .NOT. ALLOCATED( t_window_h_1(l)%val ) )                                               &
           ALLOCATE( t_window_h_1(l)%val(nzb_wall:nzt_wall+1,1:surf_usm_h(l)%ns) )
        CALL rrd_mpi_io_surface( 't_window_h(' // dum // ')', t_window_h_1(l)%val )
 
-       IF ( .NOT.  ALLOCATED( t_green_h_1(l)%val ) )                                                         &
+       IF ( .NOT. ALLOCATED( t_green_h_1(l)%val ) )                                                &
           ALLOCATE( t_green_h_1(l)%val(nzb_wall:nzt_wall+1,1:surf_usm_h(l)%ns) )
        CALL rrd_mpi_io_surface( 't_green_h(' // dum // ')', t_green_h_1(l)%val )
@@ -6723,22 +6721,20 @@
        WRITE( dum, '(I1)' )  l
 
-       CALL rrd_mpi_io( 'usm_start_index_v_2_' //dum, surf_usm_v(l)%start_index )
-       CALL rrd_mpi_io( 'usm_end_index_v_2_' // dum, surf_usm_v(l)%end_index )
-       CALL rrd_mpi_io( 'usm_global_start_v_2_' // dum, global_start )
-
-       CALL rd_mpi_io_surface_filetypes( surf_usm_v(l)%start_index, surf_usm_v(l)%end_index, ldum, &
-                                         global_start )
-
-       IF ( MAXVAL( surf_usm_v(l)%end_index ) <= 0 )  CYCLE
-
-       IF ( .NOT. ALLOCATED( t_wall_v_1(l)%val ) )                                                   &
+       CALL rrd_mpi_io( 'usm_global_start_v_2_' // dum, global_start_index )
+       CALL rrd_mpi_io( 'usm_global_end_v_2_' // dum, global_end_index )
+
+       CALL rd_mpi_io_surface_filetypes( surf_usm_v(l)%start_index, surf_usm_v(l)%end_index,       &
+                                         data_to_read, global_start_index, global_end_index )
+       IF ( .NOT. data_to_read )  CYCLE
+
+       IF ( .NOT. ALLOCATED( t_wall_v_1(l)%val ) )                                                 &
           ALLOCATE ( t_wall_v_1(l)%val(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) )
        CALL rrd_mpi_io_surface( 't_wall_v(' // dum // ')', t_wall_v_1(l)%val )
 
-       IF ( .NOT. ALLOCATED( t_window_v_1(l)%val ) )                                                 &
+       IF ( .NOT. ALLOCATED( t_window_v_1(l)%val ) )                                               &
           ALLOCATE ( t_window_v_1(l)%val(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) )
        CALL rrd_mpi_io_surface( 't_window_v(' // dum // ')', t_window_v_1(l)%val )
 
-       IF ( .NOT. ALLOCATED( t_green_v_1(l)%val ) )                                                  &
+       IF ( .NOT. ALLOCATED( t_green_v_1(l)%val ) )                                                &
           ALLOCATE ( t_green_v_1(l)%val(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) )
        CALL rrd_mpi_io_surface( 't_green_v(' // dum // ')', t_green_v_1(l)%val )
@@ -6747,4 +6743,5 @@
 
  END SUBROUTINE usm_rrd_local_mpi
+
 
 !--------------------------------------------------------------------------------------------------!
@@ -7422,5 +7419,6 @@
     INTEGER(iwp)  ::  l  !< index surface type orientation
 
-    INTEGER(iwp), DIMENSION(nys:nyn,nxl:nxr)  ::  global_start_index  !< index for surface data (MPI-IO)
+    INTEGER(iwp), DIMENSION(nys:nyn,nxl:nxr) ::  global_end_index    !< end index for surface data (MPI-IO)
+    INTEGER(iwp), DIMENSION(nys:nyn,nxl:nxr) ::  global_start_index  !< start index for surface data (MPI-IO)
 
     LOGICAL  ::  surface_data_to_write  !< switch for MPI-I/O if PE has surface data to write
@@ -7548,10 +7546,10 @@
           WRITE( dum, '(I1)')  l
 
-          CALL rd_mpi_io_surface_filetypes( surf_usm_h(l)%start_index, surf_usm_h(l)%end_index,             &
-                                            surface_data_to_write, global_start_index )
-
-          CALL wrd_mpi_io( 'usm_start_index_h_' // dum,  surf_usm_h(l)%start_index )
-          CALL wrd_mpi_io( 'usm_end_index_h_' // dum, surf_usm_h(l)%end_index )
+          CALL rd_mpi_io_surface_filetypes( surf_usm_h(l)%start_index, surf_usm_h(l)%end_index,    &
+                                            surface_data_to_write, global_start_index,             &
+                                            global_end_index )
+
           CALL wrd_mpi_io( 'usm_global_start_h_' // dum, global_start_index )
+          CALL wrd_mpi_io( 'usm_global_end_h_' // dum, global_end_index )
 
           IF ( .NOT. surface_data_to_write )  CYCLE
@@ -7574,9 +7572,9 @@
 
           CALL rd_mpi_io_surface_filetypes( surf_usm_v(l)%start_index, surf_usm_v(l)%end_index,    &
-                                            surface_data_to_write, global_start_index )
-
-          CALL wrd_mpi_io( 'usm_start_index_v_' // dum, surf_usm_v(l)%start_index )
-          CALL wrd_mpi_io( 'usm_end_index_v_' // dum, surf_usm_v(l)%end_index )
+                                            surface_data_to_write, global_start_index,             &
+                                            global_end_index )
+
           CALL wrd_mpi_io( 'usm_global_start_v_' // dum, global_start_index )
+          CALL wrd_mpi_io( 'usm_global_end_v_' // dum,   global_end_index )
 
           IF ( .NOT. surface_data_to_write )  CYCLE
@@ -7596,10 +7594,10 @@
           WRITE( dum, '(I1)')  l
 
-          CALL rd_mpi_io_surface_filetypes( surf_usm_h(l)%start_index, surf_usm_h(l)%end_index,             &
-                                            surface_data_to_write, global_start_index )
-
-          CALL wrd_mpi_io( 'usm_start_index_h_2_' // dum,  surf_usm_h(l)%start_index )
-          CALL wrd_mpi_io( 'usm_end_index_h_2_' // dum, surf_usm_h(l)%end_index )
+          CALL rd_mpi_io_surface_filetypes( surf_usm_h(l)%start_index, surf_usm_h(l)%end_index,    &
+                                            surface_data_to_write, global_start_index,             &
+                                            global_end_index )
+
           CALL wrd_mpi_io( 'usm_global_start_h_2_' // dum, global_start_index )
+          CALL wrd_mpi_io( 'usm_global_end_h_2_' // dum, global_end_index )
 
           IF ( .NOT. surface_data_to_write )  CYCLE
@@ -7616,9 +7614,9 @@
 
           CALL rd_mpi_io_surface_filetypes( surf_usm_v(l)%start_index, surf_usm_v(l)%end_index,    &
-                                            surface_data_to_write, global_start_index )
-
-          CALL wrd_mpi_io( 'usm_start_index_v_2_' //dum, surf_usm_v(l)%start_index )
-          CALL wrd_mpi_io( 'usm_end_index_v_2_' // dum, surf_usm_v(l)%end_index )
+                                            surface_data_to_write, global_start_index,             &
+                                            global_end_index )
+
           CALL wrd_mpi_io( 'usm_global_start_v_2_' // dum, global_start_index )
+          CALL wrd_mpi_io( 'usm_global_end_v_2_' // dum, global_end_index )
 
           IF ( .NOT. surface_data_to_write )  CYCLE
