Index: /palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- /palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4361)
+++ /palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4362)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Input of plant canopy variables from static driver moved to plant-canopy 
+! model
+! 
+! 4360 2020-01-07 11:25:50Z suehring
 ! Correct single message calls, local checks must be given by the respective
 ! mpi rank.
@@ -576,7 +580,4 @@
 !
 !-- Define 3D variables of type NC_FLOAT
-    TYPE(real_3d) ::  basal_area_density_f    !< input variable for basal area density - resolved vegetation
-    TYPE(real_3d) ::  leaf_area_density_f     !< input variable for leaf area density - resolved vegetation
-    TYPE(real_3d) ::  root_area_density_lad_f !< input variable for root area density - resolved vegetation
     TYPE(real_3d) ::  root_area_density_lsm_f !< input variable for root area density - parametrized vegetation
     TYPE(real_3d) ::  uvem_radiance_f         !< input variable for uvem radiance lookup table
@@ -718,8 +719,9 @@
 !-- Public data structures
     PUBLIC real_1d_3d,                                                         &
-           real_2d
+           real_2d,                                                            &
+           real_3d
 !
 !-- Public variables
-    PUBLIC albedo_pars_f, albedo_type_f, basal_area_density_f, buildings_f,    &
+    PUBLIC albedo_pars_f, albedo_type_f, buildings_f,                          &
            building_id_f, building_pars_f, building_surface_pars_f,            &
            building_type_f,                                                    &
@@ -733,9 +735,8 @@
            input_pids_static,                                                  &
            input_pids_dynamic, input_pids_vm, input_file_vm,                   &
-           leaf_area_density_f,                                                &
            num_var_pids,                                                       &
            pavement_pars_f, pavement_subsurface_pars_f, pavement_type_f,       &
            pids_id,                                                            &
-           root_area_density_lad_f, root_area_density_lsm_f, soil_pars_f,      &
+           root_area_density_lsm_f, soil_pars_f,                               &
            soil_type_f, street_crossing_f, street_type_f, surface_fraction_f,  &
            terrain_height_f, vegetation_pars_f, vegetation_type_f,             &
@@ -1720,5 +1721,5 @@
 
        USE control_parameters,                                                 &
-           ONLY:  land_surface, plant_canopy, urban_surface
+           ONLY:  land_surface, urban_surface
 
        USE indices,                                                            &
@@ -1742,104 +1743,4 @@
 !--    Measure CPU time
        CALL cpu_log( log_point_s(82), 'NetCDF input', 'start' )
-!
-!--    Read plant canopy variables.
-       IF ( plant_canopy )  THEN
-#if defined ( __netcdf )
-!
-!--       Open file in read-only mode
-          CALL open_read_file( TRIM( input_file_static ) //                    &
-                               TRIM( coupling_char ) , id_surf )
-!
-!--       At first, inquire all variable names.
-!--       This will be used to check whether an optional input variable
-!--       exist or not.
-          CALL inquire_num_variables( id_surf, num_vars )
-
-          ALLOCATE( var_names(1:num_vars) )
-          CALL inquire_variable_names( id_surf, var_names )
-
-!
-!--       Read leaf area density - resolved vegetation
-          IF ( check_existence( var_names, 'lad' ) )  THEN
-             leaf_area_density_f%from_file = .TRUE.
-             CALL get_attribute( id_surf, char_fill,                           &
-                                 leaf_area_density_f%fill,                     &
-                                 .FALSE., 'lad' )
-!
-!--          Inquire number of vertical vegetation layer
-             CALL get_dimension_length( id_surf,                               &
-                                        leaf_area_density_f%nz,                &
-                                        'zlad' )
-!
-!--          Allocate variable for leaf-area density
-             ALLOCATE( leaf_area_density_f%var( 0:leaf_area_density_f%nz-1,    &
-                                                nys:nyn,nxl:nxr) )
-
-             CALL get_variable( id_surf, 'lad', leaf_area_density_f%var,       &
-                                nxl, nxr, nys, nyn,                            &
-                                0, leaf_area_density_f%nz-1 )
-
-          ELSE
-             leaf_area_density_f%from_file = .FALSE.
-          ENDIF
-
-!
-!--       Read basal area density - resolved vegetation
-          IF ( check_existence( var_names, 'bad' ) )  THEN
-             basal_area_density_f%from_file = .TRUE.
-             CALL get_attribute( id_surf, char_fill,                           &
-                                 basal_area_density_f%fill,                    &
-                                 .FALSE., 'bad' )
-!
-!--          Inquire number of vertical vegetation layer
-             CALL get_dimension_length( id_surf,                               &
-                                        basal_area_density_f%nz,               & 
-                                        'zlad' )
-!
-!--          Allocate variable
-             ALLOCATE( basal_area_density_f%var(0:basal_area_density_f%nz-1,   &
-                                                nys:nyn,nxl:nxr) )
-
-             CALL get_variable( id_surf, 'bad', basal_area_density_f%var,      &
-                                nxl, nxr, nys, nyn,                            &
-                                0,  basal_area_density_f%nz-1 )
-          ELSE
-             basal_area_density_f%from_file = .FALSE.
-          ENDIF
-
-!
-!--       Read root area density - resolved vegetation
-          IF ( check_existence( var_names, 'root_area_dens_r' ) )  THEN
-             root_area_density_lad_f%from_file = .TRUE.
-             CALL get_attribute( id_surf, char_fill,                           &
-                                 root_area_density_lad_f%fill,                 &
-                                 .FALSE., 'root_area_dens_r' )
-!
-!--          Inquire number of vertical soil layers
-             CALL get_dimension_length( id_surf,             &
-                                                   root_area_density_lad_f%nz, &
-                                                  'zsoil' )
-!
-!--          Allocate variable
-             ALLOCATE( root_area_density_lad_f%var                             &
-                                         (0:root_area_density_lad_f%nz-1,      &
-                                          nys:nyn,nxl:nxr) )
-
-             CALL get_variable( id_surf, 'root_area_dens_r',                   &
-                                root_area_density_lad_f%var,                   &
-                                nxl, nxr, nys, nyn,                            &
-                                0,  root_area_density_lad_f%nz-1 )
-          ELSE
-             root_area_density_lad_f%from_file = .FALSE.
-          ENDIF
-!
-!--       Finally, close input file
-          CALL close_input_file( id_surf )
-#endif
-       ENDIF
-!
-!--    Deallocate variable list. Will be re-allocated in case further
-!--    variables are read from file.
-       IF ( ALLOCATED( var_names ) )  DEALLOCATE( var_names )
 !
 !--    Skip the following if no land-surface or urban-surface module are
@@ -1879,5 +1780,5 @@
 !--    Read soil type and required attributes
        IF ( check_existence( var_names, 'soil_type' ) )  THEN
-             soil_type_f%from_file = .TRUE.
+          soil_type_f%from_file = .TRUE.
 !
 !--       Note, lod is currently not on file; skip for the moment
Index: /palm/trunk/SOURCE/plant_canopy_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 4361)
+++ /palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 4362)
@@ -27,4 +27,8 @@
 ! -----------------
 ! $Id$
+! Input of plant canopy variables from static driver moved to plant-canopy 
+! model
+! 
+! 4361 2020-01-07 12:22:38Z suehring
 ! - Remove unused arrays in pmc_rrd_local
 ! - Remove one exchange of ghost points
@@ -183,5 +187,19 @@
 
     USE netcdf_data_input_mod,                                                 &
-        ONLY:  input_pids_static, leaf_area_density_f
+        ONLY:  input_pids_static,                                              &
+               char_fill,                                                      &
+               check_existence,                                                &
+               close_input_file,                                               &
+               get_attribute,                                                  &
+               get_dimension_length,                                           &
+               get_variable,                                                   &
+               inquire_num_variables,                                          &
+               inquire_variable_names,                                         &
+               input_file_static,                                              &
+               num_var_pids,                                                   &
+               open_read_file,                                                 &
+               pids_id,                                                        &
+               real_3d,                                                        &
+               vars_pids
 
     USE pegrid
@@ -234,4 +252,8 @@
     REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pcm_latentrate_av        !< array for averaging plant canopy latent heating rate
     REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pcm_transpirationrate_av !< array for averaging plant canopy transpiration rate
+
+    TYPE(real_3d) ::  basal_area_density_f    !< input variable for basal area density - resolved vegetation
+    TYPE(real_3d) ::  leaf_area_density_f     !< input variable for leaf area density - resolved vegetation
+    TYPE(real_3d) ::  root_area_density_lad_f !< input variable for root area density - resolved vegetation
 
     SAVE
@@ -831,100 +853,100 @@
 !> Header output for plant canopy model
 !------------------------------------------------------------------------------!
-    SUBROUTINE pcm_header ( io )
+ SUBROUTINE pcm_header ( io )
  
-       CHARACTER (LEN=10) ::  coor_chr            !<
-
-       CHARACTER (LEN=86) ::  coordinates         !<
-       CHARACTER (LEN=86) ::  gradients           !<
-       CHARACTER (LEN=86) ::  leaf_area_density   !<
-       CHARACTER (LEN=86) ::  slices              !<
+    CHARACTER (LEN=10) ::  coor_chr            !<
+
+    CHARACTER (LEN=86) ::  coordinates         !<
+    CHARACTER (LEN=86) ::  gradients           !<
+    CHARACTER (LEN=86) ::  leaf_area_density   !<
+    CHARACTER (LEN=86) ::  slices              !<
  
-       INTEGER(iwp) :: i                !< 
-       INTEGER(iwp),  INTENT(IN) ::  io !< Unit of the output file
-       INTEGER(iwp) :: k                !<       
-   
-       REAL(wp) ::  canopy_height       !< canopy height (in m)
+    INTEGER(iwp) :: i                !< 
+    INTEGER(iwp),  INTENT(IN) ::  io !< Unit of the output file
+    INTEGER(iwp) :: k                !<       
+ 
+    REAL(wp) ::  canopy_height       !< canopy height (in m)
+    
+    canopy_height = zw(pch_index)
+
+    WRITE ( io, 1 )  canopy_mode, canopy_height, pch_index,                    &
+                       canopy_drag_coeff                                       
+    IF ( passive_scalar )  THEN                                                
+       WRITE ( io, 2 )  leaf_scalar_exch_coeff,                                &
+                          leaf_surface_conc
+    ENDIF
+
+!
+!   Heat flux at the top of vegetation
+    WRITE ( io, 3 )  cthf
+
+!
+!   Leaf area density profile, calculated either from given vertical 
+!   gradients or from beta probability density function.
+    IF (  .NOT.  calc_beta_lad_profile )  THEN
+
+!      Building output strings, starting with surface value
+       WRITE ( leaf_area_density, '(F7.4)' )  lad_surface
+       gradients = '------'
+       slices = '     0'
+       coordinates = '   0.0'
+       DO i = 1, UBOUND(lad_vertical_gradient_level_ind, DIM=1)
+          IF  ( lad_vertical_gradient_level_ind(i) /= -9999 ) THEN
+
+             WRITE (coor_chr,'(F7.2)') lad(lad_vertical_gradient_level_ind(i))
+             leaf_area_density = TRIM( leaf_area_density ) // ' ' // TRIM( coor_chr )
+
+             WRITE (coor_chr,'(F7.2)') lad_vertical_gradient(i)
+             gradients = TRIM( gradients ) // ' ' // TRIM( coor_chr )
+
+             WRITE (coor_chr,'(I7)') lad_vertical_gradient_level_ind(i)
+             slices = TRIM( slices ) // ' ' // TRIM( coor_chr )
+
+             WRITE (coor_chr,'(F7.1)') lad_vertical_gradient_level(i)
+             coordinates = TRIM( coordinates ) // ' '  // TRIM( coor_chr )
+          ELSE
+             EXIT
+          ENDIF
+       ENDDO
+
+       WRITE ( io, 4 )  TRIM( coordinates ), TRIM( leaf_area_density ),        &
+                          TRIM( gradients ), TRIM( slices )
+
+    ELSE
+    
+       WRITE ( leaf_area_density, '(F7.4)' )  lad_surface
+       coordinates = '   0.0'
        
-       canopy_height = zw(pch_index)
-
-       WRITE ( io, 1 )  canopy_mode, canopy_height, pch_index,                 &
-                          canopy_drag_coeff
-       IF ( passive_scalar )  THEN
-          WRITE ( io, 2 )  leaf_scalar_exch_coeff,                             &
-                             leaf_surface_conc
-       ENDIF
-
-!
-!--    Heat flux at the top of vegetation
-       WRITE ( io, 3 )  cthf
-
-!
-!--    Leaf area density profile, calculated either from given vertical 
-!--    gradients or from beta probability density function.
-       IF (  .NOT.  calc_beta_lad_profile )  THEN
-
-!--       Building output strings, starting with surface value
-          WRITE ( leaf_area_density, '(F7.4)' )  lad_surface
-          gradients = '------'
-          slices = '     0'
-          coordinates = '   0.0'
-          DO i = 1, UBOUND(lad_vertical_gradient_level_ind, DIM=1)
-             IF  ( lad_vertical_gradient_level_ind(i) /= -9999 ) THEN
-
-                WRITE (coor_chr,'(F7.2)') lad(lad_vertical_gradient_level_ind(i))
-                leaf_area_density = TRIM( leaf_area_density ) // ' ' // TRIM( coor_chr )
-
-                WRITE (coor_chr,'(F7.2)') lad_vertical_gradient(i)
-                gradients = TRIM( gradients ) // ' ' // TRIM( coor_chr )
-
-                WRITE (coor_chr,'(I7)') lad_vertical_gradient_level_ind(i)
-                slices = TRIM( slices ) // ' ' // TRIM( coor_chr )
-
-                WRITE (coor_chr,'(F7.1)') lad_vertical_gradient_level(i)
-                coordinates = TRIM( coordinates ) // ' '  // TRIM( coor_chr )
-             ELSE
-                EXIT
-             ENDIF
-          ENDDO
-
-          WRITE ( io, 4 )  TRIM( coordinates ), TRIM( leaf_area_density ),     &
-                             TRIM( gradients ), TRIM( slices )
-
-       ELSE
-       
-          WRITE ( leaf_area_density, '(F7.4)' )  lad_surface
-          coordinates = '   0.0'
-          
-          DO  k = 1, pch_index
-
-             WRITE (coor_chr,'(F7.2)')  lad(k)
-             leaf_area_density = TRIM( leaf_area_density ) // ' ' //           &
-                                 TRIM( coor_chr )
- 
-             WRITE (coor_chr,'(F7.1)')  zu(k)
-             coordinates = TRIM( coordinates ) // ' '  // TRIM( coor_chr )
-
-          ENDDO       
-
-          WRITE ( io, 5 ) TRIM( coordinates ), TRIM( leaf_area_density ),      &
-                          alpha_lad, beta_lad, lai_beta
-
-       ENDIF  
-
-1 FORMAT (//' Vegetation canopy (drag) model:'/                                &
+       DO  k = 1, pch_index
+
+          WRITE (coor_chr,'(F7.2)')  lad(k)
+          leaf_area_density = TRIM( leaf_area_density ) // ' ' //              &
+                              TRIM( coor_chr )                                 
+                                                                               
+          WRITE (coor_chr,'(F7.1)')  zu(k)                                     
+          coordinates = TRIM( coordinates ) // ' '  // TRIM( coor_chr )        
+                                                                               
+       ENDDO                                                                   
+                                                                               
+       WRITE ( io, 5 ) TRIM( coordinates ), TRIM( leaf_area_density ),         &
+                       alpha_lad, beta_lad, lai_beta
+
+    ENDIF  
+
+1   FORMAT (//' Vegetation canopy (drag) model:'/                              &
               ' ------------------------------'//                              &
               ' Canopy mode: ', A /                                            &
               ' Canopy height: ',F6.2,'m (',I4,' grid points)' /               &
               ' Leaf drag coefficient: ',F6.2 /)
-2 FORMAT (/ ' Scalar exchange coefficient: ',F6.2 /                            &
+2   FORMAT (/ ' Scalar exchange coefficient: ',F6.2 /                          &
               ' Scalar concentration at leaf surfaces in kg/m**3: ',F6.2 /)
-3 FORMAT (' Predefined constant heatflux at the top of the vegetation: ',F6.2, &
-          ' K m/s')
-4 FORMAT (/ ' Characteristic levels of the leaf area density:'//               &
+3   FORMAT (' Predefined constant heatflux at the top of the vegetation: ',    &
+             F6.2, ' K m/s')
+4   FORMAT (/ ' Characteristic levels of the leaf area density:'//             &
               ' Height:              ',A,'  m'/                                &
               ' Leaf area density:   ',A,'  m**2/m**3'/                        &
               ' Gradient:            ',A,'  m**2/m**4'/                        &
               ' Gridpoint:           ',A)
-5 FORMAT (//' Characteristic levels of the leaf area density and coefficients:'&
+5   FORMAT (//' Characteristic levels of the leaf area density and coefficients:'&
           //  ' Height:              ',A,'  m'/                                &
               ' Leaf area density:   ',A,'  m**2/m**3'/                        &
@@ -1068,4 +1090,101 @@
 
           CASE ( 'read_from_file' )
+!
+!--          Read plant canopy
+             IF ( input_pids_static )  THEN
+!
+!--             Open the static input file
+#if defined( __netcdf )
+                CALL open_read_file( TRIM( input_file_static ) //              &
+                                     TRIM( coupling_char ),                    &
+                                     pids_id )
+
+                CALL inquire_num_variables( pids_id, num_var_pids )
+!
+!--             Allocate memory to store variable names and read them
+                ALLOCATE( vars_pids(1:num_var_pids) )
+                CALL inquire_variable_names( pids_id, vars_pids )
+!
+!--             Read leaf area density - resolved vegetation
+                IF ( check_existence( vars_pids, 'lad' ) )  THEN
+                   leaf_area_density_f%from_file = .TRUE.
+                   CALL get_attribute( pids_id, char_fill,                     &
+                                       leaf_area_density_f%fill,               &
+                                       .FALSE., 'lad' )
+!
+!--                Inquire number of vertical vegetation layer
+                   CALL get_dimension_length( pids_id,                         &
+                                              leaf_area_density_f%nz,          &
+                                              'zlad' )
+!
+!--                Allocate variable for leaf-area density
+                   ALLOCATE( leaf_area_density_f%var                           &
+                                                (0:leaf_area_density_f%nz-1,   &
+                                                 nys:nyn,nxl:nxr) )
+
+                   CALL get_variable( pids_id, 'lad', leaf_area_density_f%var, &
+                                      nxl, nxr, nys, nyn,                      &
+                                      0, leaf_area_density_f%nz-1 )
+
+                ELSE
+                   leaf_area_density_f%from_file = .FALSE.
+                ENDIF
+!
+!--             Read basal area density - resolved vegetation
+                IF ( check_existence( vars_pids, 'bad' ) )  THEN
+                   basal_area_density_f%from_file = .TRUE.
+                   CALL get_attribute( pids_id, char_fill,                     &
+                                       basal_area_density_f%fill,              &
+                                       .FALSE., 'bad' )
+!
+!--                Inquire number of vertical vegetation layer
+                   CALL get_dimension_length( pids_id,                         &
+                                              basal_area_density_f%nz,         & 
+                                              'zlad' )
+!
+!--                Allocate variable
+                   ALLOCATE( basal_area_density_f%var                          &
+                                              (0:basal_area_density_f%nz-1,    &
+                                               nys:nyn,nxl:nxr) )
+
+                   CALL get_variable( pids_id, 'bad', basal_area_density_f%var,&
+                                      nxl, nxr, nys, nyn,                      &
+                                      0,  basal_area_density_f%nz-1 )
+                ELSE
+                   basal_area_density_f%from_file = .FALSE.
+                ENDIF
+!
+!--             Read root area density - resolved vegetation
+                IF ( check_existence( vars_pids, 'root_area_dens_r' ) )  THEN
+                   root_area_density_lad_f%from_file = .TRUE.
+                   CALL get_attribute( pids_id, char_fill,                     &
+                                       root_area_density_lad_f%fill,           &
+                                       .FALSE., 'root_area_dens_r' )
+!
+!--                Inquire number of vertical soil layers
+                   CALL get_dimension_length( pids_id,                         &
+                                              root_area_density_lad_f%nz,      &
+                                              'zsoil' )
+!
+!--                Allocate variable
+                   ALLOCATE( root_area_density_lad_f%var                       &
+                                               (0:root_area_density_lad_f%nz-1,&
+                                                nys:nyn,nxl:nxr) )
+
+                   CALL get_variable( pids_id, 'root_area_dens_r',             &
+                                      root_area_density_lad_f%var,             &
+                                      nxl, nxr, nys, nyn,                      &
+                                      0,  root_area_density_lad_f%nz-1 )
+                ELSE
+                   root_area_density_lad_f%from_file = .FALSE.
+                ENDIF
+
+                DEALLOCATE( vars_pids )
+
+             ENDIF
+!
+!--          Finally, close the input file and deallocate temporary arrays
+             CALL close_input_file( pids_id )
+#endif
 !
 !--          Initialize LAD with data from file. If LAD is given in NetCDF file,
