Index: palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3529)
+++ palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3542)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Revise ghost point exchange and resizing of input variables
 ! 
 ! Former revisions:
@@ -267,4 +267,7 @@
         ONLY:  cpu_log, log_point_s
 
+    USE indices,                                                               &
+        ONLY:  nbgp
+
     USE kinds
 
@@ -1543,5 +1546,5 @@
 
        USE indices,                                                            &
-           ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg
+           ONLY:  nbgp, nx, nxl, nxr,ny, nyn, nys
 
 
@@ -1555,12 +1558,4 @@
        INTEGER(iwp) ::  num_vars  !< number of variables in input file
        INTEGER(iwp) ::  nz_soil   !< number of soil layers in file
-
-       INTEGER(iwp), DIMENSION(nysg:nyng,nxlg:nxrg) ::  var_exchange_int !< dummy variables used to exchange 32-bit Integer arrays
-       INTEGER(iwp), DIMENSION(:,:,:), ALLOCATABLE  ::  var_dum_int_3d !< dummy variables used to exchange real arrays
-
-       REAL(wp), DIMENSION(nysg:nyng,nxlg:nxrg) ::  var_exchange_real !< dummy variables used to exchange real arrays
-
-       REAL(wp), DIMENSION(:,:,:),   ALLOCATABLE ::  var_dum_real_3d !< dummy variables used to exchange real arrays
-       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  var_dum_real_4d !< dummy variables used to exchange real arrays
 
 !
@@ -1674,8 +1669,4 @@
 !--    applied. This case, no one of the following variables is used anyway.
        IF (  .NOT. land_surface  .AND.  .NOT. urban_surface )  RETURN
-!
-!--    Initialize dummy arrays used for ghost-point exchange
-       var_exchange_int  = 0
-       var_exchange_real = 0.0_wp
 
 #if defined ( __netcdf )
@@ -2125,443 +2116,146 @@
        CALL cpu_log( log_point_s(82), 'NetCDF input', 'stop' )
 !
-!--    Exchange 1 ghost points for surface variables. Please note, ghost point
-!--    exchange for 3D parameter lists should be revised by using additional
-!--    MPI datatypes or rewriting exchange_horiz.
-!--    Moreover, varialbes will be resized in the following, including ghost
-!--    points.
-!--    Start with 2D Integer variables. Please note, for 8-bit integer
-!--    variables must be swapt to 32-bit integer before calling exchange_horiz.
+!--    Exchange ghost points for surface variables. Therefore, resize 
+!--    variables. 
        IF ( albedo_type_f%from_file )  THEN
-          var_exchange_int                  = INT( albedo_type_f%fill, KIND = 1 )
-          var_exchange_int(nys:nyn,nxl:nxr) =                                  &
-                            INT( albedo_type_f%var(nys:nyn,nxl:nxr), KIND = 4 )
-          CALL exchange_horiz_2d_int( var_exchange_int, nys, nyn, nxl, nxr, nbgp )
-          DEALLOCATE( albedo_type_f%var )
-          ALLOCATE( albedo_type_f%var(nysg:nyng,nxlg:nxrg) )
-          albedo_type_f%var = INT( var_exchange_int, KIND = 1 )
+          CALL resize_array_2d_int8( albedo_type_f%var, nys, nyn, nxl, nxr )
+          CALL exchange_horiz_2d_byte( albedo_type_f%var, nys, nyn, nxl, nxr,  &
+                                       nbgp )
        ENDIF
        IF ( pavement_type_f%from_file )  THEN
-          var_exchange_int                  = INT( pavement_type_f%fill, KIND = 1 )
-          var_exchange_int(nys:nyn,nxl:nxr) =                                  &
-                          INT( pavement_type_f%var(nys:nyn,nxl:nxr), KIND = 4 )
-          CALL exchange_horiz_2d_int( var_exchange_int, nys, nyn, nxl, nxr, nbgp )
-          DEALLOCATE( pavement_type_f%var )
-          ALLOCATE( pavement_type_f%var(nysg:nyng,nxlg:nxrg) )
-          pavement_type_f%var = INT( var_exchange_int, KIND = 1 )
+          CALL resize_array_2d_int8( pavement_type_f%var, nys, nyn, nxl, nxr )
+          CALL exchange_horiz_2d_byte( pavement_type_f%var, nys, nyn, nxl, nxr,&
+                                       nbgp )
        ENDIF
        IF ( soil_type_f%from_file  .AND.  ALLOCATED( soil_type_f%var_2d ) )  THEN
-          var_exchange_int                  = INT( soil_type_f%fill, KIND = 1 )
-          var_exchange_int(nys:nyn,nxl:nxr) =                                  &
-                            INT( soil_type_f%var_2d(nys:nyn,nxl:nxr), KIND = 4 )
-          CALL exchange_horiz_2d_int( var_exchange_int, nys, nyn, nxl, nxr, nbgp )
-          DEALLOCATE( soil_type_f%var_2d )
-          ALLOCATE( soil_type_f%var_2d(nysg:nyng,nxlg:nxrg) )
-          soil_type_f%var_2d = INT( var_exchange_int, KIND = 1 )
+          CALL resize_array_2d_int8( soil_type_f%var_2d, nys, nyn, nxl, nxr )
+          CALL exchange_horiz_2d_byte( soil_type_f%var_2d, nys, nyn, nxl, nxr, &
+                                       nbgp )
        ENDIF
        IF ( vegetation_type_f%from_file )  THEN
-          var_exchange_int                  = INT( vegetation_type_f%fill, KIND = 1 )
-          var_exchange_int(nys:nyn,nxl:nxr) =                                  &
-                        INT( vegetation_type_f%var(nys:nyn,nxl:nxr), KIND = 4 )
-          CALL exchange_horiz_2d_int( var_exchange_int, nys, nyn, nxl, nxr, nbgp )
-          DEALLOCATE( vegetation_type_f%var )
-          ALLOCATE( vegetation_type_f%var(nysg:nyng,nxlg:nxrg) )
-          vegetation_type_f%var = INT( var_exchange_int, KIND = 1 )
+          CALL resize_array_2d_int8( vegetation_type_f%var, nys, nyn, nxl, nxr )
+          CALL exchange_horiz_2d_byte( vegetation_type_f%var, nys, nyn, nxl,   &
+                                       nxr, nbgp )
        ENDIF
        IF ( water_type_f%from_file )  THEN
-          var_exchange_int                  = INT( water_type_f%fill, KIND = 1 )
-          var_exchange_int(nys:nyn,nxl:nxr) =                                  &
-                         INT( water_type_f%var(nys:nyn,nxl:nxr), KIND = 4 )
-          CALL exchange_horiz_2d_int( var_exchange_int, nys, nyn, nxl, nxr, nbgp )
-          DEALLOCATE( water_type_f%var )
-          ALLOCATE( water_type_f%var(nysg:nyng,nxlg:nxrg) )
-          water_type_f%var = INT( var_exchange_int, KIND = 1 )
-       ENDIF
-!
-!--    Exchange 1 ghost point for 3/4-D variables. For the sake of simplicity,
-!--    loop further dimensions to use 2D exchange routines.
-!--    This should be revised later by introducing new MPI datatypes.
+          CALL resize_array_2d_int8( water_type_f%var, nys, nyn, nxl, nxr )
+          CALL exchange_horiz_2d_byte( water_type_f%var, nys, nyn, nxl, nxr,   &
+                                       nbgp )
+       ENDIF
+!
+!--    Exchange ghost points for 3/4-D variables. For the sake of simplicity,
+!--    loop further dimensions to use 2D exchange routines. Unfortunately this
+!--    is necessary, else new MPI-data types need to be introduced just for 
+!--    2 variables. 
        IF ( soil_type_f%from_file  .AND.  ALLOCATED( soil_type_f%var_3d ) )    &
        THEN
-          ALLOCATE( var_dum_int_3d(0:nz_soil,nys:nyn,nxl:nxr) )
-          var_dum_int_3d = soil_type_f%var_3d
-          DEALLOCATE( soil_type_f%var_3d )
-          ALLOCATE( soil_type_f%var_3d(0:nz_soil,nysg:nyng,nxlg:nxrg) )
-          soil_type_f%var_3d = soil_type_f%fill
-
+          CALL resize_array_3d_int8( soil_type_f%var_3d, 0, nz_soil,           &
+                                     nys, nyn, nxl, nxr )
           DO  k = 0, nz_soil
-             var_exchange_int(nys:nyn,nxl:nxr) = var_dum_int_3d(k,nys:nyn,nxl:nxr)
-             CALL exchange_horiz_2d_int( var_exchange_int, nys, nyn, nxl, nxr, nbgp )
-             soil_type_f%var_3d(k,:,:) = INT( var_exchange_int(:,:), KIND = 1 )
+             CALL exchange_horiz_2d_int(                                       &  
+                        soil_type_f%var_3d(k,:,:), nys, nyn, nxl, nxr, nbgp )
           ENDDO
-          DEALLOCATE( var_dum_int_3d )
        ENDIF
 
        IF ( surface_fraction_f%from_file )  THEN
-          ALLOCATE( var_dum_real_3d(0:surface_fraction_f%nf-1,nys:nyn,nxl:nxr) )
-          var_dum_real_3d = surface_fraction_f%frac
-          DEALLOCATE( surface_fraction_f%frac )
-          ALLOCATE( surface_fraction_f%frac(0:surface_fraction_f%nf-1,         &
-                                            nysg:nyng,nxlg:nxrg) )
-          surface_fraction_f%frac = surface_fraction_f%fill
-
+          CALL resize_array_3d_real( surface_fraction_f%frac,                  &
+                                     0, surface_fraction_f%nf-1,               &
+                                     nys, nyn, nxl, nxr )
           DO  k = 0, surface_fraction_f%nf-1
-             var_exchange_real(nys:nyn,nxl:nxr) = var_dum_real_3d(k,nys:nyn,nxl:nxr)
-             CALL exchange_horiz_2d( var_exchange_real, nbgp )
-             surface_fraction_f%frac(k,:,:) = var_exchange_real(:,:)
+             CALL exchange_horiz_2d( surface_fraction_f%frac(k,:,:), nbgp )
           ENDDO
-          DEALLOCATE( var_dum_real_3d )
-       ENDIF
-
-       IF ( building_pars_f%from_file )  THEN
-          ALLOCATE( var_dum_real_3d(0:building_pars_f%np-1,nys:nyn,nxl:nxr) )
-          var_dum_real_3d = building_pars_f%pars_xy
-          DEALLOCATE( building_pars_f%pars_xy )
-          ALLOCATE( building_pars_f%pars_xy(0:building_pars_f%np-1,            &
-                                            nysg:nyng,nxlg:nxrg) )
-          building_pars_f%pars_xy = building_pars_f%fill
+       ENDIF
+
+       IF ( building_pars_f%from_file )  THEN         
+          CALL resize_array_3d_real( building_pars_f%pars_xy,                  &
+                                     0, building_pars_f%np-1,                  &
+                                     nys, nyn, nxl, nxr )
           DO  k = 0, building_pars_f%np-1
-             var_exchange_real(nys:nyn,nxl:nxr) =                              &
-                                              var_dum_real_3d(k,nys:nyn,nxl:nxr)
-             CALL exchange_horiz_2d( var_exchange_real, nbgp )
-             building_pars_f%pars_xy(k,:,:) = var_exchange_real(:,:)
+             CALL exchange_horiz_2d( building_pars_f%pars_xy(k,:,:), nbgp )
           ENDDO
-          DEALLOCATE( var_dum_real_3d )
-       ENDIF
-
-       IF ( albedo_pars_f%from_file )  THEN
-          ALLOCATE( var_dum_real_3d(0:albedo_pars_f%np-1,nys:nyn,nxl:nxr) )
-          var_dum_real_3d = albedo_pars_f%pars_xy
-          DEALLOCATE( albedo_pars_f%pars_xy )
-          ALLOCATE( albedo_pars_f%pars_xy(0:albedo_pars_f%np-1,                &
-                                          nysg:nyng,nxlg:nxrg) )
-          albedo_pars_f%pars_xy = albedo_pars_f%fill
+       ENDIF
+
+       IF ( albedo_pars_f%from_file )  THEN          
+          CALL resize_array_3d_real( albedo_pars_f%pars_xy,                    &
+                                     0, albedo_pars_f%np-1,                    &
+                                     nys, nyn, nxl, nxr )
           DO  k = 0, albedo_pars_f%np-1
-             var_exchange_real(nys:nyn,nxl:nxr) =                              &
-                                              var_dum_real_3d(k,nys:nyn,nxl:nxr)
-             CALL exchange_horiz_2d( var_exchange_real, nbgp )
-             albedo_pars_f%pars_xy(k,:,:) = var_exchange_real(:,:)
+             CALL exchange_horiz_2d( albedo_pars_f%pars_xy(k,:,:), nbgp )
           ENDDO
-          DEALLOCATE( var_dum_real_3d )
-       ENDIF
-
-       IF ( pavement_pars_f%from_file )  THEN
-          ALLOCATE( var_dum_real_3d(0:pavement_pars_f%np-1,nys:nyn,nxl:nxr) )
-          var_dum_real_3d = pavement_pars_f%pars_xy
-          DEALLOCATE( pavement_pars_f%pars_xy )
-          ALLOCATE( pavement_pars_f%pars_xy(0:pavement_pars_f%np-1,            &
-                                            nysg:nyng,nxlg:nxrg) )
-          pavement_pars_f%pars_xy = pavement_pars_f%fill
+       ENDIF
+
+       IF ( pavement_pars_f%from_file )  THEN          
+          CALL resize_array_3d_real( pavement_pars_f%pars_xy,                  &
+                                     0, pavement_pars_f%np-1,                  &
+                                     nys, nyn, nxl, nxr )
           DO  k = 0, pavement_pars_f%np-1
-             var_exchange_real(nys:nyn,nxl:nxr) =                              &
-                                              var_dum_real_3d(k,nys:nyn,nxl:nxr)
-             CALL exchange_horiz_2d( var_exchange_real, nbgp )
-             pavement_pars_f%pars_xy(k,:,:) = var_exchange_real(:,:)
+             CALL exchange_horiz_2d( pavement_pars_f%pars_xy(k,:,:), nbgp )
           ENDDO
-          DEALLOCATE( var_dum_real_3d )
        ENDIF
 
        IF ( vegetation_pars_f%from_file )  THEN
-          ALLOCATE( var_dum_real_3d(0:vegetation_pars_f%np-1,nys:nyn,nxl:nxr) )
-          var_dum_real_3d = vegetation_pars_f%pars_xy
-          DEALLOCATE( vegetation_pars_f%pars_xy )
-          ALLOCATE( vegetation_pars_f%pars_xy(0:vegetation_pars_f%np-1,        &
-                                            nysg:nyng,nxlg:nxrg) )
-          vegetation_pars_f%pars_xy = vegetation_pars_f%fill
+          CALL resize_array_3d_real( vegetation_pars_f%pars_xy,                &
+                                     0, vegetation_pars_f%np-1,                &
+                                     nys, nyn, nxl, nxr )
           DO  k = 0, vegetation_pars_f%np-1
-             var_exchange_real(nys:nyn,nxl:nxr) =                              &
-                                              var_dum_real_3d(k,nys:nyn,nxl:nxr)
-             CALL exchange_horiz_2d( var_exchange_real, nbgp )
-             vegetation_pars_f%pars_xy(k,:,:) = var_exchange_real(:,:)
+             CALL exchange_horiz_2d( vegetation_pars_f%pars_xy(k,:,:), nbgp )
           ENDDO
-          DEALLOCATE( var_dum_real_3d )
        ENDIF
 
        IF ( water_pars_f%from_file )  THEN
-          ALLOCATE( var_dum_real_3d(0:water_pars_f%np-1,nys:nyn,nxl:nxr) )
-          var_dum_real_3d = water_pars_f%pars_xy
-          DEALLOCATE( water_pars_f%pars_xy )
-          ALLOCATE( water_pars_f%pars_xy(0:water_pars_f%np-1,                  &
-                                         nysg:nyng,nxlg:nxrg) )
-          water_pars_f%pars_xy = water_pars_f%fill
+          CALL resize_array_3d_real( water_pars_f%pars_xy,                     &
+                                     0, water_pars_f%np-1,                     &
+                                     nys, nyn, nxl, nxr )
           DO  k = 0, water_pars_f%np-1
-             var_exchange_real(nys:nyn,nxl:nxr) =                              &
-                                              var_dum_real_3d(k,nys:nyn,nxl:nxr)
-             CALL exchange_horiz_2d( var_exchange_real, nbgp )
-             water_pars_f%pars_xy(k,:,:) = var_exchange_real(:,:)
+             CALL exchange_horiz_2d( water_pars_f%pars_xy(k,:,:), nbgp )
           ENDDO
-          DEALLOCATE( var_dum_real_3d )
        ENDIF
 
        IF ( root_area_density_lsm_f%from_file )  THEN
-          ALLOCATE( var_dum_real_3d(0:root_area_density_lsm_f%nz-1,nys:nyn,nxl:nxr) )
-          var_dum_real_3d = root_area_density_lsm_f%var
-          DEALLOCATE( root_area_density_lsm_f%var )
-          ALLOCATE( root_area_density_lsm_f%var(0:root_area_density_lsm_f%nz-1,&
-                                                nysg:nyng,nxlg:nxrg) )
-          root_area_density_lsm_f%var = root_area_density_lsm_f%fill
-
+          CALL resize_array_3d_real( root_area_density_lsm_f%var,              &
+                                     0, root_area_density_lsm_f%nz-1,          &
+                                     nys, nyn, nxl, nxr )
           DO  k = 0, root_area_density_lsm_f%nz-1
-             var_exchange_real(nys:nyn,nxl:nxr) =                              &
-                                              var_dum_real_3d(k,nys:nyn,nxl:nxr)
-             CALL exchange_horiz_2d( var_exchange_real, nbgp )
-             root_area_density_lsm_f%var(k,:,:) = var_exchange_real(:,:)
+             CALL exchange_horiz_2d( root_area_density_lsm_f%var(k,:,:), nbgp )
           ENDDO
-          DEALLOCATE( var_dum_real_3d )
        ENDIF
 
        IF ( soil_pars_f%from_file )  THEN
           IF ( soil_pars_f%lod == 1 )  THEN
-
-             ALLOCATE( var_dum_real_3d(0:soil_pars_f%np-1,nys:nyn,nxl:nxr) )
-             var_dum_real_3d = soil_pars_f%pars_xy
-             DEALLOCATE( soil_pars_f%pars_xy )
-             ALLOCATE( soil_pars_f%pars_xy(0:soil_pars_f%np-1,                 &
-                                            nysg:nyng,nxlg:nxrg) )
-             soil_pars_f%pars_xy = soil_pars_f%fill
-
+          
+             CALL resize_array_3d_real( soil_pars_f%pars_xy,                   &
+                                        0, soil_pars_f%np-1,                   &
+                                        nys, nyn, nxl, nxr )
              DO  k = 0, soil_pars_f%np-1
-                var_exchange_real(nys:nyn,nxl:nxr) =                           &
-                                              var_dum_real_3d(k,nys:nyn,nxl:nxr)
-                CALL exchange_horiz_2d( var_exchange_real, nbgp )
-                soil_pars_f%pars_xy(k,:,:) = var_exchange_real(:,:)
+                CALL exchange_horiz_2d( soil_pars_f%pars_xy(k,:,:), nbgp )
              ENDDO
-             DEALLOCATE( var_dum_real_3d )
+             
           ELSEIF ( soil_pars_f%lod == 2 )  THEN
-             ALLOCATE( var_dum_real_4d(0:soil_pars_f%np-1,                     &
-                                       0:soil_pars_f%nz-1,                     &
-                                       nys:nyn,nxl:nxr) )
-             var_dum_real_4d = soil_pars_f%pars_xyz
-             DEALLOCATE( soil_pars_f%pars_xyz )
-             ALLOCATE( soil_pars_f%pars_xyz(0:soil_pars_f%np-1,                &
-                                            0:soil_pars_f%nz-1,                &
-                                            nysg:nyng,nxlg:nxrg) )
-             soil_pars_f%pars_xyz = soil_pars_f%fill
+             CALL resize_array_4d_real( soil_pars_f%pars_xyz,                  &
+                                        0, soil_pars_f%np-1,                   &
+                                        0, soil_pars_f%nz-1,                   &
+                                        nys, nyn, nxl, nxr )
 
              DO  k2 = 0, soil_pars_f%nz-1
                 DO  k = 0, soil_pars_f%np-1
-                   var_exchange_real(nys:nyn,nxl:nxr) =                        &
-                                           var_dum_real_4d(k,k2,nys:nyn,nxl:nxr)
-                   CALL exchange_horiz_2d( var_exchange_real, nbgp )
-
-                   soil_pars_f%pars_xyz(k,k2,:,:) = var_exchange_real(:,:)
+                   CALL exchange_horiz_2d( soil_pars_f%pars_xyz(k,k2,:,:),     &
+                                           nbgp )
                 ENDDO
              ENDDO
-             DEALLOCATE( var_dum_real_4d )
-          ENDIF
-       ENDIF
-
-       IF ( pavement_subsurface_pars_f%from_file )  THEN
-          ALLOCATE( var_dum_real_4d(0:pavement_subsurface_pars_f%np-1,         &
-                                    0:pavement_subsurface_pars_f%nz-1,         &
-                                    nys:nyn,nxl:nxr) )
-          var_dum_real_4d = pavement_subsurface_pars_f%pars_xyz
-          DEALLOCATE( pavement_subsurface_pars_f%pars_xyz )
-          ALLOCATE( pavement_subsurface_pars_f%pars_xyz                        &
-                                          (0:pavement_subsurface_pars_f%np-1,  &
-                                           0:pavement_subsurface_pars_f%nz-1,  &
-                                           nysg:nyng,nxlg:nxrg) )
-          pavement_subsurface_pars_f%pars_xyz = pavement_subsurface_pars_f%fill
+          ENDIF
+       ENDIF
+
+       IF ( pavement_subsurface_pars_f%from_file )  THEN          
+          CALL resize_array_4d_real( pavement_subsurface_pars_f%pars_xyz,      &
+                                     0, pavement_subsurface_pars_f%np-1,       &
+                                     0, pavement_subsurface_pars_f%nz-1,       &
+                                     nys, nyn, nxl, nxr )
 
           DO  k2 = 0, pavement_subsurface_pars_f%nz-1
              DO  k = 0, pavement_subsurface_pars_f%np-1
-                var_exchange_real(nys:nyn,nxl:nxr) =                           &
-                                          var_dum_real_4d(k,k2,nys:nyn,nxl:nxr)
-                CALL exchange_horiz_2d( var_exchange_real, nbgp )
-                pavement_subsurface_pars_f%pars_xyz(k,k2,:,:) =                &
-                                                        var_exchange_real(:,:)
+                CALL exchange_horiz_2d(                                        &
+                           pavement_subsurface_pars_f%pars_xyz(k,k2,:,:), nbgp )
              ENDDO
           ENDDO
-          DEALLOCATE( var_dum_real_4d )
-       ENDIF
-
-!
-!--    In case of non-cyclic boundary conditions, set Neumann conditions at the
-!--    lateral boundaries.
-       IF ( .NOT. bc_ns_cyc )  THEN
-          IF ( nys == 0  )  THEN
-             IF ( albedo_type_f%from_file )                                    &
-                albedo_type_f%var(-1,:) = albedo_type_f%var(0,:)
-             IF ( pavement_type_f%from_file )                                  &
-                pavement_type_f%var(-1,:) = pavement_type_f%var(0,:)
-             IF ( soil_type_f%from_file )  THEN
-                IF ( ALLOCATED( soil_type_f%var_2d ) )  THEN
-                   soil_type_f%var_2d(-1,:) = soil_type_f%var_2d(0,:)
-                ELSE
-                   soil_type_f%var_3d(:,-1,:) = soil_type_f%var_3d(:,0,:)
-                ENDIF
-             ENDIF
-             IF ( vegetation_type_f%from_file )                                &
-                vegetation_type_f%var(-1,:) = vegetation_type_f%var(0,:)
-             IF ( water_type_f%from_file )                                     &
-                water_type_f%var(-1,:) = water_type_f%var(0,:)
-             IF ( surface_fraction_f%from_file )                               &
-                surface_fraction_f%frac(:,-1,:) = surface_fraction_f%frac(:,0,:)
-             IF ( building_pars_f%from_file )                                  &
-                building_pars_f%pars_xy(:,-1,:) = building_pars_f%pars_xy(:,0,:)
-             IF ( albedo_pars_f%from_file )                                    &
-                albedo_pars_f%pars_xy(:,-1,:) = albedo_pars_f%pars_xy(:,0,:)
-             IF ( pavement_pars_f%from_file )                                  &
-                pavement_pars_f%pars_xy(:,-1,:) = pavement_pars_f%pars_xy(:,0,:)
-             IF ( vegetation_pars_f%from_file )                                &
-                vegetation_pars_f%pars_xy(:,-1,:) =                            &
-                                               vegetation_pars_f%pars_xy(:,0,:)
-             IF ( water_pars_f%from_file )                                     &
-                water_pars_f%pars_xy(:,-1,:) = water_pars_f%pars_xy(:,0,:)
-             IF ( root_area_density_lsm_f%from_file )                          &
-                root_area_density_lsm_f%var(:,-1,:) =                          &
-                                            root_area_density_lsm_f%var(:,0,:)
-             IF ( soil_pars_f%from_file )  THEN
-                IF ( soil_pars_f%lod == 1 )  THEN
-                   soil_pars_f%pars_xy(:,-1,:) = soil_pars_f%pars_xy(:,0,:)
-                ELSE
-                   soil_pars_f%pars_xyz(:,:,-1,:) = soil_pars_f%pars_xyz(:,:,0,:)
-                ENDIF
-             ENDIF
-             IF ( pavement_subsurface_pars_f%from_file )                       &
-                pavement_subsurface_pars_f%pars_xyz(:,:,-1,:) =                &
-                                   pavement_subsurface_pars_f%pars_xyz(:,:,0,:)
-          ENDIF
-
-          IF ( nyn == ny )  THEN
-             IF ( albedo_type_f%from_file )                                    &
-                albedo_type_f%var(ny+1,:) = albedo_type_f%var(ny,:)
-             IF ( pavement_type_f%from_file )                                  &
-                pavement_type_f%var(ny+1,:) = pavement_type_f%var(ny,:)
-             IF ( soil_type_f%from_file )  THEN
-                IF ( ALLOCATED( soil_type_f%var_2d ) )  THEN
-                   soil_type_f%var_2d(ny+1,:) = soil_type_f%var_2d(ny,:)
-                ELSE
-                   soil_type_f%var_3d(:,ny+1,:) = soil_type_f%var_3d(:,ny,:)
-                ENDIF
-             ENDIF
-             IF ( vegetation_type_f%from_file )                                &
-                vegetation_type_f%var(ny+1,:) = vegetation_type_f%var(ny,:)
-             IF ( water_type_f%from_file )                                     &
-                water_type_f%var(ny+1,:) = water_type_f%var(ny,:)
-             IF ( surface_fraction_f%from_file )                               &
-                surface_fraction_f%frac(:,ny+1,:) =                            &
-                                             surface_fraction_f%frac(:,ny,:)
-             IF ( building_pars_f%from_file )                                  &
-                building_pars_f%pars_xy(:,ny+1,:) =                            &
-                                             building_pars_f%pars_xy(:,ny,:)
-             IF ( albedo_pars_f%from_file )                                    &
-                albedo_pars_f%pars_xy(:,ny+1,:) = albedo_pars_f%pars_xy(:,ny,:)
-             IF ( pavement_pars_f%from_file )                                  &
-                pavement_pars_f%pars_xy(:,ny+1,:) =                            &
-                                             pavement_pars_f%pars_xy(:,ny,:)
-             IF ( vegetation_pars_f%from_file )                                &
-                vegetation_pars_f%pars_xy(:,ny+1,:) =                          &
-                                               vegetation_pars_f%pars_xy(:,ny,:)
-             IF ( water_pars_f%from_file )                                     &
-                water_pars_f%pars_xy(:,ny+1,:) = water_pars_f%pars_xy(:,ny,:)
-             IF ( root_area_density_lsm_f%from_file )                          &
-                root_area_density_lsm_f%var(:,ny+1,:) =                        &
-                                            root_area_density_lsm_f%var(:,ny,:)
-             IF ( soil_pars_f%from_file )  THEN
-                IF ( soil_pars_f%lod == 1 )  THEN
-                   soil_pars_f%pars_xy(:,ny+1,:) = soil_pars_f%pars_xy(:,ny,:)
-                ELSE
-                   soil_pars_f%pars_xyz(:,:,ny+1,:) =                          &
-                                              soil_pars_f%pars_xyz(:,:,ny,:)
-                ENDIF
-             ENDIF
-             IF ( pavement_subsurface_pars_f%from_file )                       &
-                pavement_subsurface_pars_f%pars_xyz(:,:,ny+1,:) =              &
-                                   pavement_subsurface_pars_f%pars_xyz(:,:,ny,:)
-          ENDIF
-       ENDIF
-
-       IF ( .NOT. bc_lr_cyc )  THEN
-          IF ( nxl == 0 )  THEN
-            IF ( albedo_type_f%from_file )                                     &
-                albedo_type_f%var(:,-1) = albedo_type_f%var(:,0)
-             IF ( pavement_type_f%from_file )                                  &
-                pavement_type_f%var(:,-1) = pavement_type_f%var(:,0)
-             IF ( soil_type_f%from_file )  THEN
-                IF ( ALLOCATED( soil_type_f%var_2d ) )  THEN
-                   soil_type_f%var_2d(:,-1) = soil_type_f%var_2d(:,0)
-                ELSE
-                   soil_type_f%var_3d(:,:,-1) = soil_type_f%var_3d(:,:,0)
-                ENDIF
-             ENDIF
-             IF ( vegetation_type_f%from_file )                                &
-                vegetation_type_f%var(:,-1) = vegetation_type_f%var(:,0)
-             IF ( water_type_f%from_file )                                     &
-                water_type_f%var(:,-1) = water_type_f%var(:,0)
-             IF ( surface_fraction_f%from_file )                               &
-                surface_fraction_f%frac(:,:,-1) = surface_fraction_f%frac(:,:,0)
-             IF ( building_pars_f%from_file )                                  &
-                building_pars_f%pars_xy(:,:,-1) = building_pars_f%pars_xy(:,:,0)
-             IF ( albedo_pars_f%from_file )                                    &
-                albedo_pars_f%pars_xy(:,:,-1) = albedo_pars_f%pars_xy(:,:,0)
-             IF ( pavement_pars_f%from_file )                                  &
-                pavement_pars_f%pars_xy(:,:,-1) = pavement_pars_f%pars_xy(:,:,0)
-             IF ( vegetation_pars_f%from_file )                                &
-                vegetation_pars_f%pars_xy(:,:,-1) =                            &
-                                               vegetation_pars_f%pars_xy(:,:,0)
-             IF ( water_pars_f%from_file )                                     &
-                water_pars_f%pars_xy(:,:,-1) = water_pars_f%pars_xy(:,:,0)
-             IF ( root_area_density_lsm_f%from_file )                          &
-                root_area_density_lsm_f%var(:,:,-1) =                          &
-                                            root_area_density_lsm_f%var(:,:,0)
-             IF ( soil_pars_f%from_file )  THEN
-                IF ( soil_pars_f%lod == 1 )  THEN
-                   soil_pars_f%pars_xy(:,:,-1) = soil_pars_f%pars_xy(:,:,0)
-                ELSE
-                   soil_pars_f%pars_xyz(:,:,:,-1) = soil_pars_f%pars_xyz(:,:,:,0)
-                ENDIF
-             ENDIF
-             IF ( pavement_subsurface_pars_f%from_file )                       &
-                pavement_subsurface_pars_f%pars_xyz(:,:,:,-1) =                &
-                                    pavement_subsurface_pars_f%pars_xyz(:,:,:,0)
-          ENDIF
-
-          IF ( nxr == nx )  THEN
-             IF ( albedo_type_f%from_file )                                    &
-                albedo_type_f%var(:,nx+1) = albedo_type_f%var(:,nx)
-             IF ( pavement_type_f%from_file )                                  &
-                pavement_type_f%var(:,nx+1) = pavement_type_f%var(:,nx)
-             IF ( soil_type_f%from_file )  THEN
-                IF ( ALLOCATED( soil_type_f%var_2d ) )  THEN
-                   soil_type_f%var_2d(:,nx+1) = soil_type_f%var_2d(:,nx)
-                ELSE
-                   soil_type_f%var_3d(:,:,nx+1) = soil_type_f%var_3d(:,:,nx)
-                ENDIF
-             ENDIF
-             IF ( vegetation_type_f%from_file )                                &
-                vegetation_type_f%var(:,nx+1) = vegetation_type_f%var(:,nx)
-             IF ( water_type_f%from_file )                                     &
-                water_type_f%var(:,nx+1) = water_type_f%var(:,nx)
-             IF ( surface_fraction_f%from_file )                               &
-                surface_fraction_f%frac(:,:,nx+1) =                            &
-                                             surface_fraction_f%frac(:,:,nx)
-             IF ( building_pars_f%from_file )                                  &
-                building_pars_f%pars_xy(:,:,nx+1) =                            &
-                                             building_pars_f%pars_xy(:,:,nx)
-             IF ( albedo_pars_f%from_file )                                    &
-                albedo_pars_f%pars_xy(:,:,nx+1) = albedo_pars_f%pars_xy(:,:,nx)
-             IF ( pavement_pars_f%from_file )                                  &
-                pavement_pars_f%pars_xy(:,:,nx+1) =                            &
-                                             pavement_pars_f%pars_xy(:,:,nx)
-             IF ( vegetation_pars_f%from_file )                                &
-                vegetation_pars_f%pars_xy(:,:,nx+1) =                          &
-                                               vegetation_pars_f%pars_xy(:,:,nx)
-             IF ( water_pars_f%from_file )                                     &
-                water_pars_f%pars_xy(:,:,nx+1) = water_pars_f%pars_xy(:,:,nx)
-             IF ( root_area_density_lsm_f%from_file )                          &
-                root_area_density_lsm_f%var(:,:,nx+1) =                        &
-                                            root_area_density_lsm_f%var(:,:,nx)
-             IF ( soil_pars_f%from_file )  THEN
-                IF ( soil_pars_f%lod == 1 )  THEN
-                   soil_pars_f%pars_xy(:,:,nx+1) = soil_pars_f%pars_xy(:,:,nx)
-                ELSE
-                   soil_pars_f%pars_xyz(:,:,:,nx+1) =                          &
-                                              soil_pars_f%pars_xyz(:,:,:,nx)
-                ENDIF
-             ENDIF
-             IF ( pavement_subsurface_pars_f%from_file )                       &
-                pavement_subsurface_pars_f%pars_xyz(:,:,:,nx+1) =              &
-                                   pavement_subsurface_pars_f%pars_xyz(:,:,:,nx)
-          ENDIF
        ENDIF
 
@@ -2709,6 +2403,4 @@
        INTEGER(iwp) ::  num_vars      !< number of variables in netcdf input file
        INTEGER(iwp) ::  skip_n_rows   !< counting variable to skip rows while reading topography file
-
-       INTEGER(iwp), DIMENSION(nys-nbgp:nyn+nbgp,nxl-nbgp:nxr+nbgp) ::  var_exchange_int !< dummy variables used to exchange 32-bit Integer arrays
 
        REAL(wp) ::  dum           !< dummy variable to skip columns while reading topography file
@@ -2935,38 +2627,13 @@
 !--    lateral boundaries.
        IF ( building_id_f%from_file )  THEN
-          var_exchange_int                  = building_id_f%fill
-          var_exchange_int(nys:nyn,nxl:nxr) = building_id_f%var(nys:nyn,nxl:nxr)
-          CALL exchange_horiz_2d_int( var_exchange_int, nys, nyn, nxl, nxr, nbgp )
-          DEALLOCATE( building_id_f%var )
-          ALLOCATE( building_id_f%var(nys-nbgp:nyn+nbgp,nxl-nbgp:nxr+nbgp) )
-          building_id_f%var = var_exchange_int
-
-          IF ( .NOT. bc_ns_cyc )  THEN
-             IF ( nys == 0  )  building_id_f%var(-1,:)   = building_id_f%var(0,:)
-             IF ( nyn == ny )  building_id_f%var(ny+1,:) = building_id_f%var(ny,:)
-          ENDIF
-          IF ( .NOT. bc_lr_cyc )  THEN
-             IF ( nxl == 0  )  building_id_f%var(:,-1)   = building_id_f%var(:,0)
-             IF ( nxr == nx )  building_id_f%var(:,nx+1) = building_id_f%var(:,nx)
-          ENDIF
+          CALL resize_array_2d_int32( building_id_f%var, nys, nyn, nxl, nxr )
+          CALL exchange_horiz_2d_int( building_id_f%var, nys, nyn, nxl, nxr,   &
+                                      nbgp )
        ENDIF
 
        IF ( building_type_f%from_file )  THEN
-          var_exchange_int                  = INT( building_type_f%fill, KIND = 4 )
-          var_exchange_int(nys:nyn,nxl:nxr) =                                  &
-                          INT( building_type_f%var(nys:nyn,nxl:nxr), KIND = 4 )
-          CALL exchange_horiz_2d_int( var_exchange_int, nys, nyn, nxl, nxr, nbgp )
-          DEALLOCATE( building_type_f%var )
-          ALLOCATE( building_type_f%var(nys-nbgp:nyn+nbgp,nxl-nbgp:nxr+nbgp) )
-          building_type_f%var = INT( var_exchange_int, KIND = 1 )
-
-          IF ( .NOT. bc_ns_cyc )  THEN
-             IF ( nys == 0  )  building_type_f%var(-1,:)   = building_type_f%var(0,:)
-             IF ( nyn == ny )  building_type_f%var(ny+1,:) = building_type_f%var(ny,:)
-          ENDIF
-          IF ( .NOT. bc_lr_cyc )  THEN
-             IF ( nxl == 0  )  building_type_f%var(:,-1)   = building_type_f%var(:,0)
-             IF ( nxr == nx )  building_type_f%var(:,nx+1) = building_type_f%var(:,nx)
-          ENDIF
+          CALL resize_array_2d_int8( building_type_f%var, nys, nyn, nxl, nxr )
+          CALL exchange_horiz_2d_byte( building_type_f%var, nys, nyn, nxl, nxr,   &
+                                       nbgp )
        ENDIF
 
@@ -4477,4 +4144,172 @@
 ! Description:
 ! ------------
+!> Resize 8-bit 2D Integer array: (nys:nyn,nxl:nxr) -> (nysg:nyng,nxlg:nxrg)
+!------------------------------------------------------------------------------!
+    SUBROUTINE resize_array_2d_int8( var, js, je, is, ie )
+    
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  je !< upper index bound along y direction
+       INTEGER(iwp) ::  js !< lower index bound along y direction
+       INTEGER(iwp) ::  ie !< upper index bound along x direction
+       INTEGER(iwp) ::  is !< lower index bound along x direction
+       
+       INTEGER(KIND=1), DIMENSION(:,:), ALLOCATABLE ::  var     !< treated variable
+       INTEGER(KIND=1), DIMENSION(:,:), ALLOCATABLE ::  var_tmp !< temporary copy
+!
+!--    Allocate temporary variable
+       ALLOCATE( var_tmp(js-nbgp:je+nbgp,is-nbgp:ie+nbgp) )
+!
+!--    Temporary copy of the variable
+       var_tmp(js:je,is:ie) = var(js:je,is:ie)
+!
+!--    Resize the array
+       DEALLOCATE( var )
+       ALLOCATE( var(js-nbgp:je+nbgp,is-nbgp:ie+nbgp) )
+!
+!--    Transfer temporary copy back to original array
+       var(js:je,is:ie) = var_tmp(js:je,is:ie)
+
+    END SUBROUTINE resize_array_2d_int8
+    
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Resize 32-bit 2D Integer array: (nys:nyn,nxl:nxr) -> (nysg:nyng,nxlg:nxrg)
+!------------------------------------------------------------------------------!
+    SUBROUTINE resize_array_2d_int32( var, js, je, is, ie )
+
+       IMPLICIT NONE
+       
+       INTEGER(iwp) ::  je !< upper index bound along y direction
+       INTEGER(iwp) ::  js !< lower index bound along y direction
+       INTEGER(iwp) ::  ie !< upper index bound along x direction
+       INTEGER(iwp) ::  is !< lower index bound along x direction
+
+       INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  var     !< treated variable
+       INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  var_tmp !< temporary copy
+!
+!--    Allocate temporary variable
+       ALLOCATE( var_tmp(js-nbgp:je+nbgp,is-nbgp:ie+nbgp) )
+!
+!--    Temporary copy of the variable
+       var_tmp(js:je,is:ie) = var(js:je,is:ie)
+!
+!--    Resize the array
+       DEALLOCATE( var )
+       ALLOCATE( var(js-nbgp:je+nbgp,is-nbgp:ie+nbgp) )
+!
+!--    Transfer temporary copy back to original array
+       var(js:je,is:ie) = var_tmp(js:je,is:ie)
+
+    END SUBROUTINE resize_array_2d_int32
+    
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Resize 8-bit 3D Integer array: (:,nys:nyn,nxl:nxr) -> (:,nysg:nyng,nxlg:nxrg)
+!------------------------------------------------------------------------------!
+    SUBROUTINE resize_array_3d_int8( var, ks, ke, js, je, is, ie )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  je !< upper index bound along y direction
+       INTEGER(iwp) ::  js !< lower index bound along y direction
+       INTEGER(iwp) ::  ie !< upper index bound along x direction
+       INTEGER(iwp) ::  is !< lower index bound along x direction
+       INTEGER(iwp) ::  ke !< upper bound of treated array in z-direction  
+       INTEGER(iwp) ::  ks !< lower bound of treated array in z-direction  
+       
+       INTEGER(KIND=1), DIMENSION(:,:,:), ALLOCATABLE ::  var     !< treated variable
+       INTEGER(KIND=1), DIMENSION(:,:,:), ALLOCATABLE ::  var_tmp !< temporary copy
+!
+!--    Allocate temporary variable
+       ALLOCATE( var_tmp(ks:ke,js-nbgp:je+nbgp,is-nbgp:ie+nbgp) )
+!
+!--    Temporary copy of the variable
+       var_tmp(ks:ke,js:je,is:ie) = var(ks:ke,js:je,is:ie)
+!
+!--    Resize the array
+       DEALLOCATE( var )
+       ALLOCATE( var(ks:ke,js-nbgp:je+nbgp,is-nbgp:ie+nbgp) )
+!
+!--    Transfer temporary copy back to original array
+       var(ks:ke,js:je,is:ie) = var_tmp(ks:ke,js:je,is:ie)
+
+    END SUBROUTINE resize_array_3d_int8
+    
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Resize 3D Real array: (:,nys:nyn,nxl:nxr) -> (:,nysg:nyng,nxlg:nxrg)
+!------------------------------------------------------------------------------!
+    SUBROUTINE resize_array_3d_real( var, ks, ke, js, je, is, ie )
+
+       IMPLICIT NONE
+
+       INTEGER(iwp) ::  je !< upper index bound along y direction
+       INTEGER(iwp) ::  js !< lower index bound along y direction
+       INTEGER(iwp) ::  ie !< upper index bound along x direction
+       INTEGER(iwp) ::  is !< lower index bound along x direction
+       INTEGER(iwp) ::  ke !< upper bound of treated array in z-direction  
+       INTEGER(iwp) ::  ks !< lower bound of treated array in z-direction  
+       
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  var     !< treated variable
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  var_tmp !< temporary copy
+!
+!--    Allocate temporary variable
+       ALLOCATE( var_tmp(ks:ke,js-nbgp:je+nbgp,is-nbgp:ie+nbgp) )
+!
+!--    Temporary copy of the variable
+       var_tmp(ks:ke,js:je,is:ie) = var(ks:ke,js:je,is:ie)
+!
+!--    Resize the array
+       DEALLOCATE( var )
+       ALLOCATE( var(ks:ke,js-nbgp:je+nbgp,is-nbgp:ie+nbgp) )
+!
+!--    Transfer temporary copy back to original array
+       var(ks:ke,js:je,is:ie) = var_tmp(ks:ke,js:je,is:ie)
+
+    END SUBROUTINE resize_array_3d_real
+    
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Resize 4D Real array: (:,:,nys:nyn,nxl:nxr) -> (:,nysg:nyng,nxlg:nxrg)
+!------------------------------------------------------------------------------!
+    SUBROUTINE resize_array_4d_real( var, k1s, k1e, k2s, k2e, js, je, is, ie )
+
+       IMPLICIT NONE
+       
+       INTEGER(iwp) ::  je  !< upper index bound along y direction
+       INTEGER(iwp) ::  js  !< lower index bound along y direction
+       INTEGER(iwp) ::  ie  !< upper index bound along x direction
+       INTEGER(iwp) ::  is  !< lower index bound along x direction
+       INTEGER(iwp) ::  k1e !< upper bound of treated array in z-direction  
+       INTEGER(iwp) ::  k1s !< lower bound of treated array in z-direction
+       INTEGER(iwp) ::  k2e !< upper bound of treated array along parameter space  
+       INTEGER(iwp) ::  k2s !< lower bound of treated array along parameter space  
+       
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  var     !< treated variable
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  var_tmp !< temporary copy
+!
+!--    Allocate temporary variable
+       ALLOCATE( var_tmp(k1s:k1e,k2s:k2e,js-nbgp:je+nbgp,is-nbgp:ie+nbgp) )
+!
+!--    Temporary copy of the variable
+       var_tmp(k1s:k1e,k2s:k2e,js:je,is:ie) = var(k1s:k1e,k2s:k2e,js:je,is:ie)
+!
+!--    Resize the array
+       DEALLOCATE( var )
+       ALLOCATE( var(k1s:k1e,k2s:k2e,js-nbgp:je+nbgp,is-nbgp:ie+nbgp) )
+!
+!--    Transfer temporary copy back to original array
+       var(k1s:k1e,k2s:k2e,js:je,is:ie) = var_tmp(k1s:k1e,k2s:k2e,js:je,is:ie)
+
+    END SUBROUTINE resize_array_4d_real
+    
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
 !> Vertical interpolation and extrapolation of 1D variables.
 !------------------------------------------------------------------------------!
