Index: palm/trunk/SOURCE/data_output_3d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_3d.f90	(revision 647)
+++ palm/trunk/SOURCE/data_output_3d.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.  Calls of exchange_horiz are modified.
+! Skip-value skip_do_avs changed to a dynamic adaption of ghost points.
 !
 ! Former revisions:
@@ -102,5 +104,5 @@
 !
 !-- Allocate a temporary array with the desired output dimensions.
-    ALLOCATE( local_pf(nxl-1:nxr+1,nys-1:nyn+1,nzb:nz_do3d) )
+    ALLOCATE( local_pf(nxlg:nxrg,nysg:nyng,nzb:nz_do3d) )
 
 !
@@ -157,7 +159,7 @@
              IF ( av == 0 )  THEN
                 tend = prt_count
-                CALL exchange_horiz( tend )
-                DO  i = nxl-1, nxr+1
-                   DO  j = nys-1, nyn+1
+                CALL exchange_horiz( tend, nbgp )
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
                       DO  k = nzb, nz_do3d
                          local_pf(i,j,k) = tend(k,j,i)
@@ -167,5 +169,5 @@
                 resorted = .TRUE.
              ELSE
-                CALL exchange_horiz( pc_av )
+                CALL exchange_horiz( pc_av, nbgp )
                 to_be_resorted => pc_av
              ENDIF
@@ -192,7 +194,7 @@
                    ENDDO
                 ENDDO
-                CALL exchange_horiz( tend )
-                DO  i = nxl-1, nxr+1
-                   DO  j = nys-1, nyn+1
+                CALL exchange_horiz( tend, nbgp )
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
                       DO  k = nzb, nzt+1
                          local_pf(i,j,k) = tend(k,j,i)
@@ -202,5 +204,5 @@
                 resorted = .TRUE.
              ELSE
-                CALL exchange_horiz( pr_av )
+                CALL exchange_horiz( pr_av, nbgp )
                 to_be_resorted => pr_av
              ENDIF
@@ -211,6 +213,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, nz_do3d
                             local_pf(i,j,k) = pt(k,j,i) + l_d_cp *    &
@@ -263,6 +265,6 @@
           CASE ( 'qv' )
              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, nz_do3d
                          local_pf(i,j,k) = q(k,j,i) - ql(k,j,i)
@@ -342,6 +344,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, nz_do3d
                    local_pf(i,j,k) = to_be_resorted(k,j,i)
@@ -376,5 +378,5 @@
 !--       Determine the Skip-value for the next array. Record end and start 
 !--       require 4 byte each.
-          skip_do_avs = skip_do_avs + ( ((nx+2)*(ny+2)*(nz_do3d+1)) * 4 + 8 )
+          skip_do_avs = skip_do_avs + ( ((nx+2*nbgp)*(ny+2*nbgp)*(nz_do3d+1)) * 4 + 8 )
        ENDIF
 
@@ -386,5 +388,5 @@
 !--       of compressed data.
           CALL write_compressed( local_pf, 30, 33, myid, nxl, nxr, nyn, nys, &
-                                 nzb, nz_do3d, prec )
+                                 nzb, nz_do3d, prec, nbgp )
        ELSE
 !
@@ -400,5 +402,5 @@
                    WRITE ( 30 )  simulated_time, do3d_time_count(av), av
                 ENDIF
-                WRITE ( 30 )  nxl-1, nxr+1, nys-1, nyn+1, nzb, nz_do3d
+                WRITE ( 30 )  nxlg, nxrg, nysg, nyng, nzb, nz_do3d
                 WRITE ( 30 )  local_pf
 
@@ -411,17 +413,17 @@
                 IF ( nxr == nx  .AND.  nyn /= ny )  THEN
                    nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if), &
-                                  local_pf(nxl:nxr+1,nys:nyn,nzb:nz_do3d),    &
+                                  local_pf(nxl:nxrg,nys:nyn,nzb:nz_do3d),    &
                       start = (/ nxl+1, nys+1, nzb+1, do3d_time_count(av) /), &
-                      count = (/ nxr-nxl+2, nyn-nys+1, nz_do3d-nzb+1, 1 /) )
+                      count = (/ nxr-nxl+1+nbgp, nyn-nys+1, nz_do3d-nzb+1, 1 /) )
                 ELSEIF ( nxr /= nx  .AND.  nyn == ny )  THEN
                    nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if), &
-                                  local_pf(nxl:nxr,nys:nyn+1,nzb:nz_do3d),    &
+                                  local_pf(nxl:nxr,nys:nyng,nzb:nz_do3d),    &
                       start = (/ nxl+1, nys+1, nzb+1, do3d_time_count(av) /), &
-                      count = (/ nxr-nxl+1, nyn-nys+2, nz_do3d-nzb+1, 1 /) )
+                      count = (/ nxr-nxl+1, nyn-nys+1+nbgp, nz_do3d-nzb+1, 1 /) )
                 ELSEIF ( nxr == nx  .AND.  nyn == ny )  THEN
                    nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if), &
-                                  local_pf(nxl:nxr+1,nys:nyn+1,nzb:nz_do3d),  &
+                                  local_pf(nxl:nxrg,nys:nyng,nzb:nz_do3d),  &
                       start = (/ nxl+1, nys+1, nzb+1, do3d_time_count(av) /), &
-                      count = (/ nxr-nxl+2, nyn-nys+2, nz_do3d-nzb+1, 1 /) )
+                      count = (/ nxr-nxl+1+nbgp, nyn-nys+1+nbgp, nz_do3d-nzb+1, 1 /) )
                 ELSE
                    nc_stat = NF90_PUT_VAR( id_set_3d(av), id_var_do3d(av,if), &
