Index: palm/trunk/SOURCE/read_3d_binary.f90
===================================================================
--- palm/trunk/SOURCE/read_3d_binary.f90	(revision 449)
+++ palm/trunk/SOURCE/read_3d_binary.f90	(revision 667)
@@ -4,5 +4,7 @@
 ! Current revisions:
 ! -----------------
-! 
+! +/- 1 replaced with +/- nbgp when swapping and allocating variables.
+! Bugfix: When using initializing_actions = 'cyclic_fill' in some cases
+! not the whole model domain was filled with data of the prerun.
 !
 ! Former revisions:
@@ -128,50 +130,49 @@
 !--    matches another time(s) in the current subdomain by shifting it
 !--    for nx_on_file+1, ny_on_file+1 respectively
-
+    
        shift_y = 0
-       j       = 0  ! counter for the number of files to be opened
-
-       DO WHILE ( nyspr+shift_y <= nyn-offset_y  .AND.  &
-                  nynpr+shift_y >= nys-offset_y )
-
-          shift_x = 0
-
-          DO WHILE ( nxlpr+shift_x <= nxr-offset_x  .AND. &
-                     nxrpr+shift_x >= nxl-offset_x )
-
-             j = j +1
-
-             IF ( j > 1000 )  THEN
-!
-!--             Array bound exceeded
-                message_string = 'data from subdomain of previous' // &
-                                 ' run mapped more than 1000 times'
-                CALL message( 'read_3d_binary', 'PA0284', 2, 2, -1, 6, 1 )
- 
-             ENDIF
-
-             IF ( j == 1 )  THEN
-                files_to_be_opened = files_to_be_opened + 1
-                file_list(files_to_be_opened) = i-1
-             ENDIF
-
-             offset_xa(files_to_be_opened,j) = offset_x + shift_x
-             offset_ya(files_to_be_opened,j) = offset_y + shift_y
-
-!
-!--          Index bounds of overlapping data
-             nxlfa(files_to_be_opened,j) = MAX( nxl-offset_x-shift_x, nxlpr )
-             nxrfa(files_to_be_opened,j) = MIN( nxr-offset_x-shift_x, nxrpr )
-             nysfa(files_to_be_opened,j) = MAX( nys-offset_y, nyspr )
-             nynfa(files_to_be_opened,j) = MIN( nyn-offset_y, nynpr )
-
-             shift_x = shift_x + ( nx_on_file + 1 )
-
-          ENDDO
-
-          shift_y = shift_y + ( ny_on_file + 1 )
-
+       j       = 0
+       DO WHILE (  nyspr+shift_y <= nyn-offset_y )
+          
+          IF ( nynpr+shift_y >= nys-offset_y ) THEN 
+
+             shift_x = 0
+             DO WHILE ( nxlpr+shift_x <= nxr-offset_x )
+                
+                IF ( nxrpr+shift_x >= nxl-offset_x ) THEN
+                   j = j +1
+                   IF ( j > 1000 )  THEN
+!
+!--                   Array bound exceeded
+                      message_string = 'data from subdomain of previous' // &
+                                       ' run mapped more than 1000 times'
+                      CALL message( 'read_3d_binary', 'PA0284', 2, 2, -1,   &
+                                       6, 1 )
+                   ENDIF
+
+                   IF ( j == 1 )  THEN
+                      files_to_be_opened = files_to_be_opened + 1
+                      file_list(files_to_be_opened) = i-1
+                   ENDIF
+                      
+                   offset_xa(files_to_be_opened,j) = offset_x + shift_x
+                   offset_ya(files_to_be_opened,j) = offset_y + shift_y
+!
+!--                Index bounds of overlapping data
+                   nxlfa(files_to_be_opened,j) = MAX( nxl-offset_x-shift_x, nxlpr )
+                   nxrfa(files_to_be_opened,j) = MIN( nxr-offset_x-shift_x, nxrpr )
+                   nysfa(files_to_be_opened,j) = MAX( nys-offset_y-shift_y, nyspr )
+                   nynfa(files_to_be_opened,j) = MIN( nyn-offset_y-shift_y, nynpr )
+
+                ENDIF
+
+                shift_x = shift_x + ( nx_on_file + 1 )
+             ENDDO
+       
+          ENDIF
+             
+          shift_y = shift_y + ( ny_on_file + 1 )             
        ENDDO
-
+          
        IF ( j > 0 )  overlap_count(files_to_be_opened) = j
 
@@ -180,27 +181,30 @@
        IF ( j > 0 )  THEN
           WRITE (9,*) '*** reading from file: ', i, j, ' times'
-          WRITE (9,*) '    nxl = ', nxl, ' nxr = ', nxr, ' nys = ', nys, ' nyn = ', nyn
+          WRITE (9,*) '    nxl = ', nxl, ' nxr = ', nxr, ' nys = ', & 
+                                    nys, ' nyn = ', nyn
           WRITE (9,*) ' '
           DO  k = 1, j
              WRITE (9,*) 'k = ', k
-             WRITE (9,'(6(A,I4))')  'nxlfa = ', nxlfa(files_to_be_opened,k), &
-                         ' nxrfa = ', nxrfa(files_to_be_opened,k), &
-                         ' offset_xa = ', offset_xa(files_to_be_opened,k), &
-                         ' nysfa = ', nysfa(files_to_be_opened,k), &
-                         ' nynfa = ', nynfa(files_to_be_opened,k), &
-                         ' offset_ya = ', offset_ya(files_to_be_opened,k)
+             WRITE (9,'(6(A,I4))') 'nxlfa = ', nxlfa(files_to_be_opened,k),&
+                     ' nxrfa = ', nxrfa(files_to_be_opened,k), &
+                     ' offset_xa = ', offset_xa(files_to_be_opened,k), &
+                     ' nysfa = ', nysfa(files_to_be_opened,k), &
+                     ' nynfa = ', nynfa(files_to_be_opened,k), &
+                     ' offset_ya = ', offset_ya(files_to_be_opened,k)
           ENDDO
           CALL local_flush( 9 )
        ENDIF
 
+          
     ENDDO
-
+   
 !
 !-- Save the id-string of the current process, since myid_char may now be used
 !-- to open files created by PEs with other id.
-    myid_char_save = myid_char
+          myid_char_save = myid_char
 
 !
 !-- Test output (remove later)
+         
     DO i = 1, numprocs_previous_run
        WRITE (9,*) 'i=',i-1, ' ibs= ',hor_index_bounds_previous_run(1:4,i-1)
@@ -311,8 +315,8 @@
 !
 !--    Allocate temporary arrays sized as the arrays on the restart file
-       ALLOCATE( tmp_2d(nys_on_file-1:nyn_on_file+1,           &
-                        nxl_on_file-1:nxr_on_file+1),          &
-                 tmp_3d(nzb:nzt+1,nys_on_file-1:nyn_on_file+1, &
-                        nxl_on_file-1:nxr_on_file+1) )
+       ALLOCATE( tmp_2d(nys_on_file-nbgp:nyn_on_file+nbgp,           &
+                        nxl_on_file-nbgp:nxr_on_file+nbgp),          &
+                 tmp_3d(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp, &
+                        nxl_on_file-nbgp:nxr_on_file+nbgp) )
 
 !
@@ -349,19 +353,19 @@
                 CASE ( 'e' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   e(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   e(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                           tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'e_av' )
                    IF ( .NOT. ALLOCATED( e_av ) )  THEN
-                      ALLOCATE( e_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   e_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( e_av(nzb:nzt+1,nys-nbgp:nyn+nbgp,nxl-nbgp:nxr+nbgp) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   e_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                            tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'e_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   e_m(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   e_m(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                             tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'iran' ) ! matching random numbers is still unresolved
@@ -371,185 +375,185 @@
                 CASE ( 'kh' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   kh(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   kh(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                             tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'kh_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   kh_m(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   kh_m(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                              tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'km' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   km(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   km(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                               tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'km_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   km_m(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   km_m(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'lwp_av' )
                    IF ( .NOT. ALLOCATED( lwp_av ) )  THEN
-                      ALLOCATE( lwp_av(nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   lwp_av(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( lwp_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   lwp_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                  tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'p' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   p(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   p(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                 tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'p_av' )
                    IF ( .NOT. ALLOCATED( p_av ) )  THEN
-                      ALLOCATE( p_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   p_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( p_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   p_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                  tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'pc_av' )
                    IF ( .NOT. ALLOCATED( pc_av ) )  THEN
-                      ALLOCATE( pc_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   pc_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( pc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   pc_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                  tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'pr_av' )
                    IF ( .NOT. ALLOCATED( pr_av ) )  THEN
-                      ALLOCATE( pr_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   pr_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( pr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   pr_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                   tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'precipitation_amount' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   precipitation_amount(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   precipitation_amount(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'precipitation_rate_a' )
                    IF ( .NOT. ALLOCATED( precipitation_rate_av ) )  THEN
-                      ALLOCATE( precipitation_rate_av(nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   precipitation_rate_av(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( precipitation_rate_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   precipitation_rate_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'pt' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   pt(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   pt(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                   tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'pt_av' )
                    IF ( .NOT. ALLOCATED( pt_av ) )  THEN
-                      ALLOCATE( pt_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   pt_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( pt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   pt_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                    tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'pt_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   pt_m(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   pt_m(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                    tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'q' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   q(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   q(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                    tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'q_av' )
                    IF ( .NOT. ALLOCATED( q_av ) )  THEN
-                      ALLOCATE( q_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   q_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( q_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg ))
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   q_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                     tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'q_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   q_m(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   q_m(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                      tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'ql' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   ql(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   ql(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                       tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'ql_av' )
                    IF ( .NOT. ALLOCATED( ql_av ) )  THEN
-                      ALLOCATE( ql_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   ql_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( ql_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   ql_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                       tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'ql_c_av' )
                    IF ( .NOT. ALLOCATED( ql_c_av ) )  THEN
-                      ALLOCATE( ql_c_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   ql_c_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( ql_c_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   ql_c_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                        tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'ql_v_av' )
                    IF ( .NOT. ALLOCATED( ql_v_av ) )  THEN
-                      ALLOCATE( ql_v_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   ql_v_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( ql_v_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   ql_v_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                        tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'ql_vp_av' )
                    IF ( .NOT. ALLOCATED( ql_vp_av ) )  THEN
-                      ALLOCATE( ql_vp_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   ql_vp_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( ql_vp_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   ql_vp_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                        tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'qs' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   qs(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   qs(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'qsws' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   qsws(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   qsws(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'qsws_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   qsws_m(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   qsws_m(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'qsws_av' )
                    IF ( .NOT. ALLOCATED( qsws_av ) )  THEN
-                      ALLOCATE( qsws_av(nys-1:nyn+1,nxl-1:nxr+1) )
+                      ALLOCATE( qsws_av(nysg:nyng,nxlg:nxrg) )
                    ENDIF  
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   qsws_av(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   qsws_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'qswst' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   qswst(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   qswst(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'qswst_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   qswst_m(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   qswst_m(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'qv_av' )
                    IF ( .NOT. ALLOCATED( qv_av ) )  THEN
-                      ALLOCATE( qv_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   qv_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( qv_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   qv_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                             tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'random_iv' )  ! still unresolved issue
@@ -559,76 +563,76 @@
                 CASE ( 'rho_av' )
                    IF ( .NOT. ALLOCATED( rho_av ) )  THEN
-                      ALLOCATE( rho_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   rho_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( rho_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   rho_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'rif' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   rif(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   rif(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'rif_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   rif_m(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   rif_m(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                        tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'rif_wall' )
                    IF ( k == 1 )  THEN
-                      ALLOCATE( tmp_4d(nzb:nzt+1,nys_on_file-1:nyn_on_file+1, &
-                                       nxl_on_file-1:nxr_on_file+1,1:4) )
+                      ALLOCATE( tmp_4d(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp, &
+                                       nxl_on_file-nbgp:nxr_on_file+nbgp,1:4) )
                       READ ( 13 )  tmp_4d
                    ENDIF
-                   rif_wall(:,nysc-1:nync+1,nxlc-1:nxrc+1,:) = &
-                                         tmp_4d(:,nysf-1:nynf+1,nxlf-1:nxrf+1,:)
+                   rif_wall(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp,:) = &
+                            tmp_4d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp,:)
 
                 CASE ( 's_av' )
                    IF ( .NOT. ALLOCATED( s_av ) )  THEN
-                      ALLOCATE( s_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   s_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( s_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg))
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   s_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                 tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'sa' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   sa(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   sa(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                  tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'sa_av' )
                    IF ( .NOT. ALLOCATED( sa_av ) )  THEN
-                      ALLOCATE( sa_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   sa_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( sa_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   sa_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                    tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'saswsb' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   saswsb(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   saswsb(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'saswst' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   saswst(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   saswst(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'shf' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   shf(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   shf(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                      tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'shf_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   shf_m(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   shf_m(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                        tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
                 CASE ( 'shf_av' )
                    IF ( .NOT. ALLOCATED( shf_av ) )  THEN
-                      ALLOCATE( shf_av(nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   shf_av(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( shf_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   shf_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
                 CASE ( 'spectrum_x' )
                    IF ( k == 1 )  THEN
@@ -663,51 +667,51 @@
                 CASE ( 'ts' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   ts(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   ts(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                     tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'ts_av' )
                    IF ( .NOT. ALLOCATED( ts_av ) )  THEN
-                      ALLOCATE( ts_av(nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   ts_av(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( ts_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   ts_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                        tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'tswst' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   tswst(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   tswst(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'tswst_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   tswst_m(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   tswst_m(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'u' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   u(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   u(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                             tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'u_av' )
                    IF ( .NOT. ALLOCATED( u_av ) )  THEN
-                      ALLOCATE( u_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   u_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( u_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   u_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                               tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'u_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   u_m(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   u_m(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                 tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'u_m_l' )
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwul(nzb:nzt+1, &
-                                          nys_on_file-1:nyn_on_file+1,1:2) )
+                                          nys_on_file-nbgp:nyn_on_file+nbgp,1:2) )
                       READ ( 13 )  tmp_3dwul
                    ENDIF
                    IF ( outflow_l )  THEN
-                      u_m_l(:,nysc-1:nync+1,:) = tmp_3dwul(:,nysf-1:nynf+1,:)
+                      u_m_l(:,nysc-nbgp:nync+nbgp,:) = tmp_3dwul(:,nysf-nbgp:nynf+nbgp,:)
                    ENDIF
 
@@ -715,9 +719,9 @@
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwun(nzb:nzt+1,ny-1:ny, &
-                                          nxl_on_file-1:nxr_on_file+1) )
+                                          nxl_on_file-nbgp:nxr_on_file+nbgp) )
                       READ ( 13 )  tmp_3dwun
                    ENDIF
                    IF ( outflow_n )  THEN
-                      u_m_n(:,:,nxlc-1:nxrc+1) = tmp_3dwun(:,:,nxlf-1:nxrf+1)
+                      u_m_n(:,:,nxlc-nbgp:nxrc+nbgp) = tmp_3dwun(:,:,nxlf-nbgp:nxrf+nbgp)
                    ENDIF
 
@@ -725,9 +729,9 @@
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwur(nzb:nzt+1,&
-                                          nys_on_file-1:nyn_on_file+1,nx-1:nx) )
+                                          nys_on_file-nbgp:nyn_on_file+nbgp,nx-1:nx) )
                       READ ( 13 )  tmp_3dwur
                    ENDIF
                    IF ( outflow_r )  THEN
-                      u_m_r(:,nysc-1:nync+1,:) = tmp_3dwur(:,nysf-1:nynf+1,:)
+                      u_m_r(:,nysc-nbgp:nync+nbgp,:) = tmp_3dwur(:,nysf-nbgp:nynf+nbgp,:)
                    ENDIF
 
@@ -735,70 +739,70 @@
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwus(nzb:nzt+1,0:1, &
-                                          nxl_on_file-1:nxr_on_file+1) )
+                                          nxl_on_file-nbgp:nxr_on_file+nbgp) )
                       READ ( 13 )  tmp_3dwus
                    ENDIF
                    IF ( outflow_s )  THEN
-                      u_m_s(:,:,nxlc-1:nxrc+1) = tmp_3dwus(:,:,nxlf-1:nxrf+1)
+                      u_m_s(:,:,nxlc-nbgp:nxrc+nbgp) = tmp_3dwus(:,:,nxlf-nbgp:nxrf+nbgp)
                    ENDIF
 
                 CASE ( 'us' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   us(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   us(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                     tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'usws' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   usws(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   usws(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                       tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'uswst' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   uswst(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   uswst(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                        tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'usws_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   usws_m(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   usws_m(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'uswst_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   uswst_m(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   uswst_m(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'us_av' )
                    IF ( .NOT. ALLOCATED( us_av ) )  THEN
-                      ALLOCATE( us_av(nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   us_av(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( us_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   us_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                        tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'v' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   v(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   v(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                              tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'v_av' )
                    IF ( .NOT. ALLOCATED( v_av ) )  THEN
-                      ALLOCATE( v_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   v_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( v_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   v_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                               tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'v_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   v_m(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   v_m(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'v_m_l' )
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwvl(nzb:nzt+1,&
-                                          nys_on_file-1:nyn_on_file+1,0:1) )
+                                          nys_on_file-nbgp:nyn_on_file+nbgp,0:1) )
                       READ ( 13 )  tmp_3dwvl
                    ENDIF
                    IF ( outflow_l )  THEN
-                      v_m_l(:,nysc-1:nync+1,:) = tmp_3dwvl(:,nysf-1:nynf+1,:)
+                      v_m_l(:,nysc-nbgp:nync+nbgp,:) = tmp_3dwvl(:,nysf-nbgp:nynf+nbgp,:)
                    ENDIF
 
@@ -806,9 +810,9 @@
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwvn(nzb:nzt+1,ny-1:ny, &
-                                          nxl_on_file-1:nxr_on_file+1) )
+                                          nxl_on_file-nbgp:nxr_on_file+nbgp) )
                       READ ( 13 )  tmp_3dwvn
                    ENDIF
                    IF ( outflow_n )  THEN
-                      v_m_n(:,:,nxlc-1:nxrc+1) = tmp_3dwvn(:,:,nxlf-1:nxrf+1)
+                      v_m_n(:,:,nxlc-nbgp:nxrc+nbgp) = tmp_3dwvn(:,:,nxlf-nbgp:nxrf+nbgp)
                    ENDIF
 
@@ -816,9 +820,9 @@
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwvr(nzb:nzt+1,&
-                                          nys_on_file-1:nyn_on_file+1,nx-1:nx) )
+                                          nys_on_file-nbgp:nyn_on_file+nbgp,nx-1:nx) )
                       READ ( 13 )  tmp_3dwvr
                    ENDIF
                    IF ( outflow_r )  THEN
-                      v_m_r(:,nysc-1:nync+1,:) = tmp_3dwvr(:,nysf-1:nynf+1,:)
+                      v_m_r(:,nysc-nbgp:nync+nbgp,:) = tmp_3dwvr(:,nysf-nbgp:nynf+nbgp,:)
                    ENDIF
 
@@ -826,75 +830,75 @@
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwvs(nzb:nzt+1,1:2, &
-                                          nxl_on_file-1:nxr_on_file+1) )
+                                          nxl_on_file-nbgp:nxr_on_file+nbgp) )
                       READ ( 13 )  tmp_3dwvs
                    ENDIF
                    IF ( outflow_s )  THEN
-                      v_m_s(:,:,nxlc-1:nxrc+1) = tmp_3dwvs(:,:,nxlf-1:nxrf+1)
+                      v_m_s(:,:,nxlc-nbgp:nxrc+nbgp) = tmp_3dwvs(:,:,nxlf-nbgp:nxrf+nbgp)
                    ENDIF
 
                 CASE ( 'vpt' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   vpt(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   vpt(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                               tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'vpt_av' )
                    IF ( .NOT. ALLOCATED( vpt_av ) )  THEN
-                      ALLOCATE( vpt_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   vpt_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( vpt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   vpt_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                               tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'vpt_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   vpt_m(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   vpt_m(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'vsws' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   vsws(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   vsws(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                       tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'vswst' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   vswst(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   vswst(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                        tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'vsws_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   vsws_m(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   vsws_m(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'vswst_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   vswst_m(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   vswst_m(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'w' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   w(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   w(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                             tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'w_av' )
                    IF ( .NOT. ALLOCATED( w_av ) )  THEN
-                      ALLOCATE( w_av(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   w_av(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( w_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d
+                   w_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                               tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'w_m' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
-                   w_m(:,nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_3d(:,nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   w_m(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'w_m_l' )
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwwl(nzb:nzt+1,&
-                                          nys_on_file-1:nyn_on_file+1,0:1) )
+                                          nys_on_file-nbgp:nyn_on_file+nbgp,0:1) )
                       READ ( 13 )  tmp_3dwwl
                    ENDIF
                    IF ( outflow_l )  THEN
-                      w_m_l(:,nysc-1:nync+1,:) = tmp_3dwwl(:,nysf-1:nynf+1,:)
+                      w_m_l(:,nysc-nbgp:nync+nbgp,:) = tmp_3dwwl(:,nysf-nbgp:nynf+nbgp,:)
                    ENDIF
 
@@ -902,9 +906,9 @@
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwwn(nzb:nzt+1,ny-1:ny, &
-                                          nxl_on_file-1:nxr_on_file+1) )
+                                          nxl_on_file-nbgp:nxr_on_file+nbgp) )
                       READ ( 13 )  tmp_3dwwn
                    ENDIF
                    IF ( outflow_n )  THEN
-                      w_m_n(:,:,nxlc-1:nxrc+1) = tmp_3dwwn(:,:,nxlf-1:nxrf+1)
+                      w_m_n(:,:,nxlc-nbgp:nxrc+nbgp) = tmp_3dwwn(:,:,nxlf-nbgp:nxrf+nbgp)
                    ENDIF
 
@@ -912,9 +916,9 @@
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwwr(nzb:nzt+1,&
-                                          nys_on_file-1:nyn_on_file+1,nx-1:nx) )
+                                          nys_on_file-nbgp:nyn_on_file+nbgp,nx-1:nx) )
                       READ ( 13 )  tmp_3dwwr
                    ENDIF
                    IF ( outflow_r )  THEN
-                      w_m_r(:,nysc-1:nync+1,:) = tmp_3dwwr(:,nysf-1:nynf+1,:)
+                      w_m_r(:,nysc-nbgp:nync+nbgp,:) = tmp_3dwwr(:,nysf-nbgp:nynf+nbgp,:)
                    ENDIF
 
@@ -922,9 +926,9 @@
                    IF ( k == 1 )  THEN
                       ALLOCATE( tmp_3dwws(nzb:nzt+1,0:1, &
-                                          nxl_on_file-1:nxr_on_file+1) )
+                                          nxl_on_file-nbgp:nxr_on_file+nbgp) )
                       READ ( 13 )  tmp_3dwws
                    ENDIF
                    IF ( outflow_s )  THEN
-                      w_m_s(:,:,nxlc-1:nxrc+1) = tmp_3dwws(:,:,nxlf-1:nxrf+1)
+                      w_m_s(:,:,nxlc-nbgp:nxrc+nbgp) = tmp_3dwws(:,:,nxlf-nbgp:nxrf+nbgp)
                    ENDIF
                    DEALLOCATE( tmp_3dwws )
@@ -932,14 +936,14 @@
                 CASE ( 'z0' )
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   z0(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                   z0(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                     tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'z0_av' )
                    IF ( .NOT. ALLOCATED( z0_av ) )  THEN
-                      ALLOCATE( z0_av(nys-1:nyn+1,nxl-1:nxr+1) )
-                   ENDIF
-                   IF ( k == 1 )  READ ( 13 )  tmp_2d
-                   z0_av(nysc-1:nync+1,nxlc-1:nxrc+1) = &
-                                          tmp_2d(nysf-1:nynf+1,nxlf-1:nxrf+1)
+                      ALLOCATE( z0_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   z0_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                       tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE DEFAULT
