Index: palm/trunk/SOURCE/plant_canopy_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 4356)
+++ palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 4360)
@@ -15,5 +15,5 @@
 ! PALM. If not, see <http://www.gnu.org/licenses/>.
 !
-! Copyright 1997-2019 Leibniz Universitaet Hannover
+! Copyright 1997-2020 Leibniz Universitaet Hannover
 ! Copyright 2017-2019 Institute of Computer Science of the
 !                     Czech Academy of Sciences, Prague
@@ -27,4 +27,8 @@
 ! -----------------
 ! $Id$
+! - Bugfix, read restart data for time-averaged pcm output quantities
+! - Output of plant-canopy quantities will fill values
+! 
+! 4356 2019-12-20 17:09:33Z suehring
 ! Correct single message call, local check must be given by the respective
 ! mpi rank.
@@ -140,5 +144,5 @@
 !------------------------------------------------------------------------------!
  MODULE plant_canopy_model_mod
- 
+
     USE arrays_3d,                                                             &
         ONLY:  dzu, dzw, e, exner, hyp, pt, q, s, tend, u, v, w, zu, zw
@@ -146,13 +150,23 @@
     USE basic_constants_and_equations_mod,                                     &
         ONLY:  c_p, degc_to_k, l_v, lv_d_cp, r_d, rd_d_rv
-        
+
     USE bulk_cloud_model_mod,                                                  &
         ONLY: bulk_cloud_model, microphysics_seifert
 
     USE control_parameters,                                                    &
-        ONLY: average_count_3d, coupling_char, debug_output, dt_3d, dz,        &
-              humidity, message_string, ocean_mode, passive_scalar,            &
-              plant_canopy, urban_surface
-              
+        ONLY: average_count_3d,                                                &
+              coupling_char,                                                   &
+              debug_output,                                                    &
+              dt_3d,                                                           &
+              dz,                                                              &
+              humidity,                                                        &
+              length,                                                          &
+              message_string,                                                  &
+              ocean_mode,                                                      &
+              passive_scalar,                                                  &
+              plant_canopy,                                                    &
+              restart_string,                                                  &
+              urban_surface
+
     USE grid_variables,                                                        &
         ONLY:  dx, dy
@@ -163,10 +177,10 @@
 
     USE kinds
-    
+
     USE netcdf_data_input_mod,                                                 &
         ONLY:  input_pids_static, leaf_area_density_f
 
     USE pegrid
-        
+
     USE surface_mod,                                                           &
         ONLY: surf_def_h, surf_lsm_h, surf_usm_h
@@ -223,8 +237,16 @@
 !
 !-- Public functions
-    PUBLIC pcm_calc_transpiration_rate, pcm_check_data_output,                &
-           pcm_check_parameters, pcm_3d_data_averaging,                       &
-           pcm_data_output_3d, pcm_define_netcdf_grid,                        &
-           pcm_header, pcm_init, pcm_parin, pcm_tendency
+    PUBLIC pcm_calc_transpiration_rate,                                       &
+           pcm_check_data_output,                                             &
+           pcm_check_parameters,                                              &
+           pcm_3d_data_averaging,                                             &
+           pcm_data_output_3d,                                                &
+           pcm_define_netcdf_grid,                                            &
+           pcm_header,                                                        &
+           pcm_init,                                                          &
+           pcm_parin,                                                         &
+           pcm_rrd_local,                                                     &
+           pcm_tendency,                                                      &
+           pcm_wrd_local
 
 !
@@ -273,9 +295,17 @@
        MODULE PROCEDURE pcm_read_plant_canopy_3d
     END INTERFACE pcm_read_plant_canopy_3d
-    
+
+    INTERFACE pcm_rrd_local
+       MODULE PROCEDURE pcm_rrd_local
+    END INTERFACE pcm_rrd_local
+
     INTERFACE pcm_tendency
        MODULE PROCEDURE pcm_tendency
        MODULE PROCEDURE pcm_tendency_ij
     END INTERFACE pcm_tendency
+
+    INTERFACE pcm_wrd_local
+       MODULE PROCEDURE pcm_wrd_local
+    END INTERFACE pcm_wrd_local
 
 
@@ -685,5 +715,5 @@
              DO  i = nxl, nxr
                 DO  j = nys, nyn
-                   DO  k = MAX( 1, nzb_do ), MIN( pch_index, nzt_do )
+                   DO  k = MAX( 1, nzb_do ), MIN( pch_index_ji(j,i), nzt_do )
                       local_pf(i,j,k) = pcm_heating_rate(k,j,i)
                    ENDDO
@@ -693,5 +723,5 @@
              DO  i = nxl, nxr
                 DO  j = nys, nyn
-                   DO  k = MAX( 1, nzb_do ), MIN( pch_index, nzt_do )
+                   DO  k = MAX( 1, nzb_do ), MIN( pch_index_ji(j,i), nzt_do )
                       local_pf(i,j,k) = pcm_heatrate_av(k,j,i)
                    ENDDO
@@ -704,5 +734,5 @@
              DO  i = nxl, nxr
                 DO  j = nys, nyn
-                   DO  k = MAX( 1, nzb_do ), MIN( pch_index, nzt_do )
+                   DO  k = MAX( 1, nzb_do ), MIN( pch_index_ji(j,i), nzt_do )
                       local_pf(i,j,k) = pcm_latent_rate(k,j,i)
                    ENDDO
@@ -712,5 +742,5 @@
              DO  i = nxl, nxr
                 DO  j = nys, nyn
-                   DO  k = MAX( 1, nzb_do ), MIN( pch_index, nzt_do )
+                   DO  k = MAX( 1, nzb_do ), MIN( pch_index_ji(j,i), nzt_do )
                       local_pf(i,j,k) = pcm_latentrate_av(k,j,i)
                    ENDDO
@@ -723,5 +753,5 @@
              DO  i = nxl, nxr
                 DO  j = nys, nyn
-                   DO  k = MAX( 1, nzb_do ), MIN( pch_index, nzt_do )
+                   DO  k = MAX( 1, nzb_do ), MIN( pch_index_ji(j,i), nzt_do )
                       local_pf(i,j,k) = pcm_transpiration_rate(k,j,i)
                    ENDDO
@@ -731,5 +761,5 @@
              DO  i = nxl, nxr
                 DO  j = nys, nyn
-                   DO  k = MAX( 1, nzb_do ), MIN( pch_index, nzt_do )
+                   DO  k = MAX( 1, nzb_do ), MIN( pch_index_ji(j,i), nzt_do )
                       local_pf(i,j,k) = pcm_transpirationrate_av(k,j,i)
                    ENDDO
@@ -742,5 +772,5 @@
              DO  i = nxl, nxr
                 DO  j = nys, nyn
-                   DO  k = MAX( 1, nzb_do ), MIN( pch_index, nzt_do )
+                   DO  k = MAX( 1, nzb_do ), MIN( pch_index_ji(j,i), nzt_do )
                       local_pf(i,j,k) = lad_s(k,j,i)
                    ENDDO
@@ -1151,5 +1181,5 @@
                            MPI_MAX, comm2d, ierr)
 #endif
-
+!
 !--    Allocation of arrays pcm_heating_rate, pcm_transpiration_rate and pcm_latent_rate
        ALLOCATE( pcm_heating_rate(0:pch_index,nysg:nyng,nxlg:nxrg) )
@@ -1437,6 +1467,80 @@
         
     END SUBROUTINE pcm_read_plant_canopy_3d
-    
-    
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Subroutine reads local (subdomain) restart data
+!------------------------------------------------------------------------------!
+    SUBROUTINE pcm_rrd_local( k, nxlf, nxlc, nxl_on_file, nxrf, nxrc,          &
+                              nxr_on_file, nynf, nync, nyn_on_file, nysf,      &
+                              nysc, nys_on_file, tmp_2d, tmp_3d, found )
+
+       INTEGER(iwp) ::  k               !< 
+       INTEGER(iwp) ::  nxlc            !< 
+       INTEGER(iwp) ::  nxlf            !< 
+       INTEGER(iwp) ::  nxl_on_file     !< 
+       INTEGER(iwp) ::  nxrc            !< 
+       INTEGER(iwp) ::  nxrf            !< 
+       INTEGER(iwp) ::  nxr_on_file     !< 
+       INTEGER(iwp) ::  nync            !< 
+       INTEGER(iwp) ::  nynf            !< 
+       INTEGER(iwp) ::  nyn_on_file     !< 
+       INTEGER(iwp) ::  nysc            !< 
+       INTEGER(iwp) ::  nysf            !< 
+       INTEGER(iwp) ::  nys_on_file     !< 
+
+       LOGICAL, INTENT(OUT)  :: found
+
+       REAL(wp), DIMENSION(nys_on_file-nbgp:nyn_on_file+nbgp,                  &
+                           nxl_on_file-nbgp:nxr_on_file+nbgp) :: tmp_2d   !< temporary 2D array
+
+       REAL(wp), DIMENSION(nzb:nzt+1,                                          &
+                           nys_on_file-nbgp:nyn_on_file+nbgp,                  &
+                           nxl_on_file-nbgp:nxr_on_file+nbgp) :: tmp_3d   !< temporary 3D array with entire vertical dimension
+
+       REAL(wp), DIMENSION(0:pch_index,                                        &
+                           nys_on_file-nbgp:nyn_on_file+nbgp,                  &
+                           nxl_on_file-nbgp:nxr_on_file+nbgp) :: tmp_3d2  !< temporary 3D array for entire vertical 
+                                                                          !< extension of canopy layer
+       found = .TRUE.
+
+       SELECT CASE ( restart_string(1:length) )
+
+          CASE ( 'pcm_heatrate_av' )
+             IF ( .NOT. ALLOCATED( pcm_heatrate_av ) )  THEN
+                ALLOCATE( pcm_heatrate_av(0:pch_index,nysg:nyng,nxlg:nxrg) )
+                pcm_heatrate_av = 0.0_wp
+             ENDIF  
+             IF ( k == 1 )  READ ( 13 )  tmp_3d2
+             pcm_heatrate_av(0:pch_index,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                        tmp_3d2(0:pch_index,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'pcm_latentrate_av' )
+             IF ( .NOT. ALLOCATED( pcm_latentrate_av ) )  THEN
+                ALLOCATE( pcm_latentrate_av(0:pch_index,nysg:nyng,nxlg:nxrg) )
+                pcm_latentrate_av = 0.0_wp
+             ENDIF  
+             IF ( k == 1 )  READ ( 13 )  tmp_3d2
+             pcm_latentrate_av(0:pch_index,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                        tmp_3d2(0:pch_index,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE ( 'pcm_transpirationrate_av' )
+             IF ( .NOT. ALLOCATED( pcm_transpirationrate_av ) )  THEN
+                ALLOCATE( pcm_transpirationrate_av(0:pch_index,nysg:nyng,nxlg:nxrg) )
+                pcm_transpirationrate_av = 0.0_wp
+             ENDIF  
+             IF ( k == 1 )  READ ( 13 )  tmp_3d2
+             pcm_transpirationrate_av(0:pch_index,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                        tmp_3d2(0:pch_index,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+          CASE DEFAULT
+
+             found = .FALSE.
+
+       END SELECT
+
+    END SUBROUTINE pcm_rrd_local
+
 !------------------------------------------------------------------------------!
 ! Description:
@@ -2188,4 +2292,28 @@
     END SUBROUTINE pcm_tendency_ij
 
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Subroutine writes local (subdomain) restart data
+!------------------------------------------------------------------------------!
+    SUBROUTINE pcm_wrd_local
+
+       IF ( ALLOCATED( pcm_heatrate_av ) )  THEN
+          CALL wrd_write_string( 'pcm_heatrate_av' )
+          WRITE ( 14 )  pcm_heatrate_av
+       ENDIF
+
+       IF ( ALLOCATED( pcm_latentrate_av ) )  THEN
+          CALL wrd_write_string( 'pcm_latentrate_av' )
+          WRITE ( 14 )  pcm_latentrate_av
+       ENDIF
+
+       IF ( ALLOCATED( pcm_transpirationrate_av ) )  THEN
+          CALL wrd_write_string( 'pcm_transpirationrate_av' )
+          WRITE ( 14 )  pcm_transpirationrate_av
+       ENDIF
+
+    END SUBROUTINE pcm_wrd_local
+
 
  END MODULE plant_canopy_model_mod
