Index: palm/trunk/SOURCE/plant_canopy_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 4517)
+++ palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 4525)
@@ -27,4 +27,7 @@
 ! -----------------
 ! $Id$
+! bugfix for reading/writing pcm_...rate_av with MPI-IO
+! 
+! 4517 2020-05-03 14:29:30Z raasch
 ! added restart with MPI-IO for reading local arrays
 ! 
@@ -1771,22 +1774,41 @@
        LOGICAL ::  array_found  !<
 
-
-!>     TODO: following code does not work because arrays are sized 0:pch_index along k!!!!!
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  tmp_3d  !< temporary array to store pcm data with
+                                                           !< non-standard vertical index bounds
+
+!
+!--    Plant canopy arrays have non standard reduced vertical index bounds. They are stored with
+!--    full vertical bounds (bzb:nzt+1) in the restart file and must be re-stored after reading.
        CALL rd_mpi_io_check_array( 'pcm_heatrate_av' , found = array_found )
        IF ( array_found )  THEN
-          IF ( .NOT. ALLOCATED( pcm_heatrate_av ) )  ALLOCATE( pcm_heatrate_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-          CALL rrd_mpi_io( 'pcm_heatrate_av', pcm_heatrate_av )
+          IF ( .NOT. ALLOCATED( pcm_heatrate_av ) )  THEN
+             ALLOCATE( pcm_heatrate_av(nzb:pch_index,nysg:nyng,nxlg:nxrg) )
+          ENDIF
+          ALLOCATE( tmp_3d(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+          CALL rrd_mpi_io( 'pcm_heatrate_av', tmp_3d )
+          pcm_heatrate_av = tmp_3d(nzb:pch_index,:,:)
+          DEALLOCATE( tmp_3d )
        ENDIF
 
        CALL rd_mpi_io_check_array( 'pcm_latentrate_av' , found = array_found )
        IF ( array_found )  THEN
-          IF ( .NOT. ALLOCATED( pcm_latentrate_av ) )  ALLOCATE( pcm_latentrate_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-          CALL rrd_mpi_io( 'pcm_latentrate_av', pcm_latentrate_av )
+          IF ( .NOT. ALLOCATED( pcm_latentrate_av ) )  THEN
+             ALLOCATE( pcm_latentrate_av(nzb:pch_index,nysg:nyng,nxlg:nxrg) )
+          ENDIF
+          ALLOCATE( tmp_3d(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+          CALL rrd_mpi_io( 'pcm_latentrate_av', tmp_3d )
+          pcm_latentrate_av = tmp_3d(nzb:pch_index,:,:)
+          DEALLOCATE( tmp_3d )
        ENDIF
 
        CALL rd_mpi_io_check_array( 'pcm_transpirationrate_av' , found = array_found )
        IF ( array_found )  THEN
-          IF ( .NOT. ALLOCATED( pcm_transpirationrate_av ) )  ALLOCATE( pcm_transpirationrate_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
-          CALL rrd_mpi_io( 'pcm_transpirationrate_av', pcm_transpirationrate_av )
+          IF ( .NOT. ALLOCATED( pcm_transpirationrate_av ) )  THEN
+             ALLOCATE( pcm_transpirationrate_av(nzb:pch_index,nysg:nyng,nxlg:nxrg) )
+          ENDIF
+          ALLOCATE( tmp_3d(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+          CALL rrd_mpi_io( 'pcm_transpirationrate_av', tmp_3d )
+          pcm_transpirationrate_av = tmp_3d(nzb:pch_index,:,:)
+          DEALLOCATE( tmp_3d )
        ENDIF
 
@@ -2570,4 +2592,7 @@
     SUBROUTINE pcm_wrd_local
 
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  tmp_3d  !< temporary array to store pcm data with
+                                                           !< non-standard vertical index bounds
+
        IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
 
@@ -2589,10 +2614,27 @@
        ELSEIF ( TRIM( restart_data_format_output ) == 'mpi' )  THEN
 
-          IF ( ALLOCATED( pcm_heatrate_av ) )  CALL wrd_mpi_io( 'pcm_heatrate_av', pcm_heatrate_av )
+!
+!--       Plant canopy arrays have non standard reduced vertical index bounds. They are stored with
+!--       full vertical bounds (bzb:nzt+1) in the restart file and must be re-stored before writing.
+          IF ( ALLOCATED( pcm_heatrate_av ) )  THEN
+             ALLOCATE( tmp_3d(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+             tmp_3d(nzb:pch_index,:,:)     = pcm_heatrate_av
+             tmp_3d(pch_index+1:nzt+1,:,:) = 0.0_wp
+             CALL wrd_mpi_io( 'pcm_heatrate_av', tmp_3d )
+             DEALLOCATE( tmp_3d )
+          ENDIF
           IF ( ALLOCATED( pcm_latentrate_av ) )  THEN
-             CALL wrd_mpi_io( 'pcm_latentrate_av', pcm_latentrate_av )
+             ALLOCATE( tmp_3d(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+             tmp_3d(nzb:pch_index,:,:)     = pcm_latentrate_av
+             tmp_3d(pch_index+1:nzt+1,:,:) = 0.0_wp
+             CALL wrd_mpi_io( 'pcm_latentrate_av', tmp_3d )
+             DEALLOCATE( tmp_3d )
           ENDIF
           IF ( ALLOCATED( pcm_transpirationrate_av ) )  THEN
-             CALL wrd_write_string( 'pcm_transpirationrate_av', pcm_transpirationrate_av )
+             ALLOCATE( tmp_3d(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+             tmp_3d(nzb:pch_index,:,:)     = pcm_transpirationrate_av
+             tmp_3d(pch_index+1:nzt+1,:,:) = 0.0_wp
+             CALL wrd_mpi_io( 'pcm_transpirationrate_av', tmp_3d )
+             DEALLOCATE( tmp_3d )
           ENDIF
 
