Index: palm/trunk/SOURCE/data_output_2d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_2d.f90	(revision 623)
+++ palm/trunk/SOURCE/data_output_2d.f90	(revision 667)
@@ -4,5 +4,7 @@
 ! Current revisions:
 ! -----------------
-! 
+! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng in loops and 
+! allocation of arrays local_2d and total_2d.
+! Calls of exchange_horiz are modiefied.
 !
 ! Former revisions:
@@ -112,7 +114,6 @@
 
        CASE ( 'xy' )
-
           s = 1
-          ALLOCATE( level_z(0:nzt+1), local_2d(nxl-1:nxr+1,nys-1:nyn+1) )
+          ALLOCATE( level_z(nzb:nzt+1), local_2d(nxlg:nxrg,nysg:nyng) )
 
 !
@@ -130,5 +131,5 @@
                 IF ( iso2d_output )  CALL check_open( 21 )
 #if defined( __parallel )
-                ALLOCATE( total_2d(-1:nx+1,-1:ny+1) )
+                ALLOCATE( total_2d(-nbgp:nx+nbgp,-nbgp:ny+nbgp) )
 #endif
              ENDIF
@@ -136,7 +137,6 @@
 
        CASE ( 'xz' )
-
           s = 2
-          ALLOCATE( local_2d(nxl-1:nxr+1,nzb:nzt+1) )
+          ALLOCATE( local_2d(nxlg:nxrg,nzb:nzt+1) )
 
 !
@@ -154,5 +154,5 @@
                 IF ( iso2d_output )  CALL check_open( 22 )
 #if defined( __parallel )
-                ALLOCATE( total_2d(-1:nx+1,nzb:nzt+1) )
+                ALLOCATE( total_2d(-nbgp:nx+nbgp,nzb:nzt+1) )
 #endif
              ENDIF
@@ -162,5 +162,5 @@
 
           s = 3
-          ALLOCATE( local_2d(nys-1:nyn+1,nzb:nzt+1) )
+          ALLOCATE( local_2d(nysg:nyng,nzb:nzt+1) )
 
 !
@@ -178,5 +178,5 @@
                 IF ( iso2d_output )  CALL check_open( 23 )
 #if defined( __parallel )
-                ALLOCATE( total_2d(-1:ny+1,nzb:nzt+1) )
+                ALLOCATE( total_2d(-nbgp:ny+nbgp,nzb:nzt+1) )
 #endif
              ENDIF
@@ -192,5 +192,5 @@
 !
 !-- Allocate a temporary array for resorting (kji -> ijk).
-    ALLOCATE( local_pf(nxl-1:nxr+1,nys-1:nyn+1,nzb:nzt+1) )
+    ALLOCATE( local_pf(nxlg:nxrg,nysg:nyng,nzb:nzt+1) )
 
 !
@@ -219,6 +219,6 @@
              CASE ( 'lwp*_xy' )        ! 2d-array
                 IF ( av == 0 )  THEN
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) = SUM( ql(nzb:nzt,j,i) * &
                                                     dzw(1:nzt+1) )
@@ -226,6 +226,6 @@
                    ENDDO
                 ELSE
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) = lwp_av(j,i)
                       ENDDO
@@ -248,10 +248,10 @@
                    IF ( simulated_time >= particle_advection_start )  THEN
                       tend = prt_count
-                      CALL exchange_horiz( tend )
+                      CALL exchange_horiz( tend, nbgp )
                    ELSE
                       tend = 0.0
                    ENDIF
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          DO  k = nzb, nzt+1
                             local_pf(i,j,k) = tend(k,j,i)
@@ -261,5 +261,5 @@
                    resorted = .TRUE.
                 ELSE
-                   CALL exchange_horiz( pc_av )
+                   CALL exchange_horiz( pc_av, nbgp )
                    to_be_resorted => pc_av
                 ENDIF
@@ -287,10 +287,10 @@
                          ENDDO
                       ENDDO
-                      CALL exchange_horiz( tend )
+                      CALL exchange_horiz( tend, nbgp )
                    ELSE
                       tend = 0.0
-                   ENDIF
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1
+                   END IF
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          DO  k = nzb, nzt+1
                             local_pf(i,j,k) = tend(k,j,i)
@@ -300,5 +300,5 @@
                    resorted = .TRUE.
                 ELSE
-                   CALL exchange_horiz( pr_av )
+                   CALL exchange_horiz( pr_av, nbgp )
                    to_be_resorted => pr_av
                 ENDIF
@@ -306,6 +306,6 @@
              CASE ( 'pra*_xy' )        ! 2d-array / integral quantity => no av
                 CALL exchange_horiz_2d( precipitation_amount )
-                DO  i = nxl-1, nxr+1
-                   DO  j = nys-1, nyn+1
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                       local_pf(i,j,nzb+1) =  precipitation_amount(j,i)
                    ENDDO
@@ -319,6 +319,6 @@
                 IF ( av == 0 )  THEN
                    CALL exchange_horiz_2d( precipitation_rate )
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1 
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) =  precipitation_rate(j,i)
                       ENDDO
@@ -326,6 +326,6 @@
                 ELSE
                    CALL exchange_horiz_2d( precipitation_rate_av )
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1 
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) =  precipitation_rate_av(j,i)
                       ENDDO
@@ -341,6 +341,6 @@
                       to_be_resorted => pt
                    ELSE
-                      DO  i = nxl-1, nxr+1
-                         DO  j = nys-1, nyn+1
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                             DO  k = nzb, nzt+1
                                local_pf(i,j,k) = pt(k,j,i) + l_d_cp *    &
@@ -399,12 +399,12 @@
              CASE ( 'qsws*_xy' )        ! 2d-array
                 IF ( av == 0 ) THEN
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1 
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) =  qsws(j,i)
                       ENDDO
                    ENDDO
                 ELSE
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1 
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng 
                          local_pf(i,j,nzb+1) =  qsws_av(j,i)
                       ENDDO
@@ -417,6 +417,6 @@
              CASE ( 'qv_xy', 'qv_xz', 'qv_yz' )
                 IF ( av == 0 )  THEN
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          DO  k = nzb, nzt+1
                             local_pf(i,j,k) = q(k,j,i) - ql(k,j,i)
@@ -453,12 +453,12 @@
              CASE ( 'shf*_xy' )        ! 2d-array
                 IF ( av == 0 ) THEN
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1 
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) =  shf(j,i)
                       ENDDO
                    ENDDO
                 ELSE
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1 
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) =  shf_av(j,i)
                       ENDDO
@@ -471,12 +471,12 @@
              CASE ( 't*_xy' )        ! 2d-array
                 IF ( av == 0 )  THEN
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) = ts(j,i)
                       ENDDO
                    ENDDO
                 ELSE
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) = ts_av(j,i)
                       ENDDO
@@ -503,12 +503,12 @@
              CASE ( 'u*_xy' )        ! 2d-array
                 IF ( av == 0 )  THEN
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) = us(j,i)
                       ENDDO
                    ENDDO
                 ELSE
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) = us_av(j,i)
                       ENDDO
@@ -551,12 +551,12 @@
              CASE ( 'z0*_xy' )        ! 2d-array
                 IF ( av == 0 ) THEN
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1 
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) =  z0(j,i)
                       ENDDO
                    ENDDO
                 ELSE
-                   DO  i = nxl-1, nxr+1
-                      DO  j = nys-1, nyn+1 
+                   DO  i = nxlg, nxrg
+                      DO  j = nysg, nyng
                          local_pf(i,j,nzb+1) =  z0_av(j,i)
                       ENDDO
@@ -593,6 +593,6 @@
 !--       Resort the array to be output, if not done above
           IF ( .NOT. resorted )  THEN
-             DO  i = nxl-1, nxr+1
-                DO  j = nys-1, nyn+1
+             DO  i = nxlg, nxrg
+                DO  j = nysg, nyng
                    DO  k = nzb, nzt+1
                       local_pf(i,j,k) = to_be_resorted(k,j,i)
@@ -647,6 +647,6 @@
 !--                   Carry out the averaging (all data are on the PE)
                       DO  k = nzb, nzt+1
-                         DO  j = nys-1, nyn+1
-                            DO  i = nxl-1, nxr+1
+                         DO  j = nysg, nyng
+                            DO  i = nxlg, nxrg
                                local_2d(i,j) = local_2d(i,j) + local_pf(i,j,k)
                             ENDDO
@@ -654,5 +654,5 @@
                       ENDDO
 
-                      local_2d = local_2d / ( nzt -nzb + 2.0 )
+                      local_2d = local_2d / ( nzt -nzb + 2.0)
 
                    ELSE
@@ -723,5 +723,5 @@
                          ENDIF
 #endif
-                         WRITE ( 21 )  nxl-1, nxr+1, nys-1, nyn+1
+                         WRITE ( 21 )  nxlg, nxrg, nysg, nyng
                          WRITE ( 21 )  local_2d
 
@@ -734,9 +734,9 @@
                          CALL MPI_BARRIER( comm2d, ierr )
 
-                         ngp = ( nxr-nxl+3 ) * ( nyn-nys+3 )
+                         ngp = ( nxrg-nxlg+1 ) * ( nyng-nysg+1 )
                          IF ( myid == 0 )  THEN
 !
 !--                         Local array can be relocated directly.
-                            total_2d(nxl-1:nxr+1,nys-1:nyn+1) = local_2d
+                            total_2d(nxlg:nxrg,nysg:nyng) = local_2d
 !
 !--                         Receive data from all other PEs.
@@ -760,10 +760,10 @@
 !--                         Output of the total cross-section.
                             IF ( iso2d_output )  THEN
-                               WRITE (21)  total_2d(0:nx+1,0:ny+1)
+                               WRITE (21)  total_2d(-nbgp:nx+nbgp,-nbgp:ny+nbgp)
                             ENDIF
 !
 !--                         Relocate the local array for the next loop increment
                             DEALLOCATE( local_2d )
-                            ALLOCATE( local_2d(nxl-1:nxr+1,nys-1:nyn+1) )
+                            ALLOCATE( local_2d(nxlg:nxrg,nysg:nyng) )
 
 #if defined( __netcdf )
@@ -789,11 +789,11 @@
 !
 !--                         First send the local index limits to PE0
-                            ind(1) = nxl-1; ind(2) = nxr+1
-                            ind(3) = nys-1; ind(4) = nyn+1
+                            ind(1) = nxlg; ind(2) = nxrg
+                            ind(3) = nysg; ind(4) = nyng
                             CALL MPI_SEND( ind(1), 4, MPI_INTEGER, 0, 0, &
                                            comm2d, ierr )
 !
 !--                         Send data to PE0
-                            CALL MPI_SEND( local_2d(nxl-1,nys-1), ngp, &
+                            CALL MPI_SEND( local_2d(nxlg,nysg), ngp, &
                                            MPI_REAL, 0, 1, comm2d, ierr )
                          ENDIF
@@ -882,16 +882,17 @@
 
                    ENDIF
+
 !
 !--                If required, carry out averaging along y
                    IF ( section(is,s) == -1 )  THEN
 
-                      ALLOCATE( local_2d_l(nxl-1:nxr+1,nzb:nzt+1) )
+                      ALLOCATE( local_2d_l(nxlg:nxrg,nzb:nzt+1) )
                       local_2d_l = 0.0
-                      ngp = ( nxr-nxl+3 ) * ( nzt-nzb+2 )
+                      ngp = ( nxrg-nxlg+1 ) * ( nzt-nzb+2 )
 !
 !--                   First local averaging on the PE
                       DO  k = nzb, nzt+1
                          DO  j = nys, nyn
-                            DO  i = nxl-1, nxr+1
+                            DO  i = nxlg, nxrg
                                local_2d_l(i,k) = local_2d_l(i,k) + &
                                                  local_pf(i,j,k)
@@ -903,6 +904,6 @@
 !--                   Now do the averaging over all PEs along y
                       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-                      CALL MPI_ALLREDUCE( local_2d_l(nxl-1,nzb),              &
-                                          local_2d(nxl-1,nzb), ngp, MPI_REAL, &
+                      CALL MPI_ALLREDUCE( local_2d_l(nxlg,nzb),              &
+                                          local_2d(nxlg,nzb), ngp, MPI_REAL, &
                                           MPI_SUM, comm1dy, ierr )
 #else
@@ -936,5 +937,5 @@
 !--                   BEGIN WORKAROUND---------------------------------------
                       IF ( npey /= 1  .AND.  section(is,s) /= -1)  THEN
-                         ALLOCATE( local_2d_l(nxl-1:nxr+1,nzb:nzt+1) )
+                         ALLOCATE( local_2d_l(nxlg:nxrg,nzb:nzt+1) )
                          local_2d_l = 0.0
                          IF ( section(is,s) >= nys .AND. section(is,s) <= nyn )&
@@ -945,8 +946,8 @@
 !
 !--                      Distribute data over all PEs along y
-                         ngp = ( nxr-nxl+3 ) * ( nzt-nzb+2 )
+                         ngp = ( nxrg-nxlg+1 ) * ( nzt-nzb+2 )
                          IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr )
-                         CALL MPI_ALLREDUCE( local_2d_l(nxl-1,nzb),            &
-                                             local_2d(nxl-1,nzb), ngp,         &
+                         CALL MPI_ALLREDUCE( local_2d_l(nxlg,nzb),            &
+                                             local_2d(nxlg,nzb), ngp,         &
                                              MPI_REAL, MPI_SUM, comm1dy, ierr )
 #else
@@ -1022,5 +1023,5 @@
                               ( section(is,s) == -1  .AND.  nys-1 == -1 ) )  &
                          THEN
-                            WRITE (22)  nxl-1, nxr+1, nzb, nzt+1
+                            WRITE (22)  nxlg, nxrg, nzb, nzt+1
                             WRITE (22)  local_2d
                          ELSE
@@ -1036,5 +1037,5 @@
                          CALL MPI_BARRIER( comm2d, ierr )
 
-                         ngp = ( nxr-nxl+3 ) * ( nzt-nzb+2 )
+                         ngp = ( nxrg-nxlg+1 ) * ( nzt-nzb+2 )
                          IF ( myid == 0 )  THEN
 !
@@ -1044,5 +1045,5 @@
                                  ( section(is,s) == -1  .AND.  nys-1 == -1 ) ) &
                             THEN
-                               total_2d(nxl-1:nxr+1,nzb:nzt+1) = local_2d
+                               total_2d(nxlg:nxrg,nzb:nzt+1) = local_2d
                             ENDIF
 !
@@ -1073,10 +1074,10 @@
 !--                         Output of the total cross-section.
                             IF ( iso2d_output )  THEN
-                               WRITE (22)  total_2d(0:nx+1,nzb:nzt+1)
+                               WRITE (22)  total_2d(-nbgp:nx+nbgp,nzb:nzt+1)
                             ENDIF
 !
 !--                         Relocate the local array for the next loop increment
                             DEALLOCATE( local_2d )
-                            ALLOCATE( local_2d(nxl-1:nxr+1,nzb:nzt+1) )
+                            ALLOCATE( local_2d(nxlg:nxrg,nzb:nzt+1) )
 
 #if defined( __netcdf )
@@ -1099,5 +1100,5 @@
                                  ( section(is,s) == -1  .AND.  nys-1 == -1 ) ) &
                             THEN
-                               ind(1) = nxl-1; ind(2) = nxr+1
+                               ind(1) = nxlg; ind(2) = nxrg
                                ind(3) = nzb;   ind(4) = nzt+1
                             ELSE
@@ -1110,5 +1111,5 @@
 !--                         If applicable, send data to PE0.
                             IF ( ind(1) /= -9999 )  THEN
-                               CALL MPI_SEND( local_2d(nxl-1,nzb), ngp, &
+                               CALL MPI_SEND( local_2d(nxlg,nzb), ngp, &
                                               MPI_REAL, 0, 1, comm2d, ierr )
                             ENDIF
@@ -1187,11 +1188,11 @@
                    IF ( section(is,s) == -1 )  THEN
 
-                      ALLOCATE( local_2d_l(nys-1:nyn+1,nzb:nzt+1) )
+                      ALLOCATE( local_2d_l(nysg:nyng,nzb:nzt+1) )
                       local_2d_l = 0.0
-                      ngp = ( nyn-nys+3 ) * ( nzt-nzb+2 )
+                      ngp = ( nyng-nysg+1 ) * ( nzt-nzb+2 )
 !
 !--                   First local averaging on the PE
                       DO  k = nzb, nzt+1
-                         DO  j = nys-1, nyn+1
+                         DO  j = nysg, nyng
                             DO  i = nxl, nxr
                                local_2d_l(j,k) = local_2d_l(j,k) + &
@@ -1204,6 +1205,6 @@
 !--                   Now do the averaging over all PEs along x
                       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-                      CALL MPI_ALLREDUCE( local_2d_l(nys-1,nzb),              &
-                                          local_2d(nys-1,nzb), ngp, MPI_REAL, &
+                      CALL MPI_ALLREDUCE( local_2d_l(nysg,nzb),              &
+                                          local_2d(nysg,nzb), ngp, MPI_REAL, &
                                           MPI_SUM, comm1dx, ierr )
 #else
@@ -1237,5 +1238,5 @@
 !--                   BEGIN WORKAROUND---------------------------------------
                       IF ( npex /= 1  .AND.  section(is,s) /= -1)  THEN
-                         ALLOCATE( local_2d_l(nys-1:nyn+1,nzb:nzt+1) )
+                         ALLOCATE( local_2d_l(nysg:nyng,nzb:nzt+1) )
                          local_2d_l = 0.0
                          IF ( section(is,s) >= nxl .AND. section(is,s) <= nxr )&
@@ -1246,8 +1247,8 @@
 !
 !--                      Distribute data over all PEs along x
-                         ngp = ( nyn-nys+3 ) * ( nzt-nzb+2 )
+                         ngp = ( nyng-nysg+1 ) * ( nzt-nzb + 2 )
                          IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr )
-                         CALL MPI_ALLREDUCE( local_2d_l(nys-1,nzb),            &
-                                             local_2d(nys-1,nzb), ngp,         &
+                         CALL MPI_ALLREDUCE( local_2d_l(nysg,nzb),            &
+                                             local_2d(nysg,nzb), ngp,         &
                                              MPI_REAL, MPI_SUM, comm1dx, ierr )
 #else
@@ -1323,5 +1324,5 @@
                               ( section(is,s) == -1  .AND.  nxl-1 == -1 ) )  &
                          THEN
-                            WRITE (23)  nys-1, nyn+1, nzb, nzt+1
+                            WRITE (23)  nysg, nyng, nzb, nzt+1
                             WRITE (23)  local_2d
                          ELSE
@@ -1337,5 +1338,5 @@
                          CALL MPI_BARRIER( comm2d, ierr )
 
-                         ngp = ( nyn-nys+3 ) * ( nzt-nzb+2 )
+                         ngp = ( nyng-nysg+1 ) * ( nzt-nzb+2 )
                          IF ( myid == 0 )  THEN
 !
@@ -1345,5 +1346,5 @@
                                  ( section(is,s) == -1  .AND.  nxl-1 == -1 ) ) &
                             THEN
-                               total_2d(nys-1:nyn+1,nzb:nzt+1) = local_2d
+                               total_2d(nysg:nyng,nzb:nzt+1) = local_2d
                             ENDIF
 !
@@ -1379,5 +1380,5 @@
 !--                         Relocate the local array for the next loop increment
                             DEALLOCATE( local_2d )
-                            ALLOCATE( local_2d(nys-1:nyn+1,nzb:nzt+1) )
+                            ALLOCATE( local_2d(nysg:nyng,nzb:nzt+1) )
 
 #if defined( __netcdf )
@@ -1400,5 +1401,5 @@
                                  ( section(is,s) == -1  .AND.  nxl-1 == -1 ) ) &
                             THEN
-                               ind(1) = nys-1; ind(2) = nyn+1
+                               ind(1) = nysg; ind(2) = nyng
                                ind(3) = nzb;   ind(4) = nzt+1
                             ELSE
@@ -1411,5 +1412,5 @@
 !--                         If applicable, send data to PE0.
                             IF ( ind(1) /= -9999 )  THEN
-                               CALL MPI_SEND( local_2d(nys-1,nzb), ngp, &
+                               CALL MPI_SEND( local_2d(nysg,nzb), ngp, &
                                               MPI_REAL, 0, 1, comm2d, ierr )
                             ENDIF
