Index: palm/trunk/SOURCE/data_output_3d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_3d.f90	(revision 2967)
+++ palm/trunk/SOURCE/data_output_3d.f90	(revision 3004)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Allocation checks implemented (averaged data will be assigned to fill values 
+! if no allocation happened so far) 
+! 
+! 2967 2018-04-13 11:22:08Z raasch
 ! bugfix: missing parallel cpp-directives added
 ! 
@@ -214,5 +218,6 @@
         
     USE indices,                                                               &
-        ONLY:  nbgp, nx, nxl, nxr, ny, nyn, nys, nzb, wall_flags_0
+        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb,  &
+               nzt, wall_flags_0
         
     USE kinds
@@ -366,4 +371,8 @@
                 to_be_resorted => e
              ELSE
+                IF ( .NOT. ALLOCATED( e_av ) ) THEN
+                   ALLOCATE( e_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   e_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => e_av
              ENDIF
@@ -373,4 +382,8 @@
                 to_be_resorted => pt
              ELSE
+                IF ( .NOT. ALLOCATED( lpt_av ) ) THEN
+                   ALLOCATE( lpt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   lpt_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => lpt_av
              ENDIF
@@ -380,4 +393,8 @@
                 to_be_resorted => nc
              ELSE
+                IF ( .NOT. ALLOCATED( nc_av ) ) THEN
+                   ALLOCATE( nc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   nc_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => nc_av
              ENDIF
@@ -387,4 +404,8 @@
                 to_be_resorted => nr
              ELSE
+                IF ( .NOT. ALLOCATED( nr_av ) ) THEN
+                   ALLOCATE( nr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   nr_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => nr_av
              ENDIF
@@ -395,4 +416,8 @@
                 to_be_resorted => p
              ELSE
+                IF ( .NOT. ALLOCATED( p_av ) ) THEN
+                   ALLOCATE( p_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   p_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 IF ( psolver /= 'sor' )  CALL exchange_horiz( p_av, nbgp )
                 to_be_resorted => p_av
@@ -415,4 +440,8 @@
                 resorted = .TRUE.
              ELSE
+                IF ( .NOT. ALLOCATED( pc_av ) ) THEN
+                   ALLOCATE( pc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   pc_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => pc_av
              ENDIF
@@ -458,4 +487,8 @@
                 resorted = .TRUE.
              ELSE
+                IF ( .NOT. ALLOCATED( pr_av ) ) THEN
+                   ALLOCATE( pr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   pr_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => pr_av
              ENDIF
@@ -471,4 +504,8 @@
                 ENDDO
              ELSE
+                IF ( .NOT. ALLOCATED( prr_av ) ) THEN
+                   ALLOCATE( prr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   prr_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 DO  i = nxl, nxr
                    DO  j = nys, nyn
@@ -498,4 +535,8 @@
                 ENDIF
              ELSE
+                IF ( .NOT. ALLOCATED( pt_av ) ) THEN
+                   ALLOCATE( pt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   pt_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => pt_av
              ENDIF
@@ -505,4 +546,8 @@
                 to_be_resorted => q
              ELSE
+                IF ( .NOT. ALLOCATED( q_av ) ) THEN
+                   ALLOCATE( q_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   q_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => q_av
              ENDIF
@@ -512,4 +557,8 @@
                 to_be_resorted => qc
              ELSE
+                IF ( .NOT. ALLOCATED( qc_av ) ) THEN
+                   ALLOCATE( qc_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   qc_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => qc_av
              ENDIF
@@ -519,4 +568,8 @@
                 to_be_resorted => ql
              ELSE
+                IF ( .NOT. ALLOCATED( ql_av ) ) THEN
+                   ALLOCATE( ql_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ql_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => ql_av
              ENDIF
@@ -526,4 +579,8 @@
                 to_be_resorted => ql_c
              ELSE
+                IF ( .NOT. ALLOCATED( ql_c_av ) ) THEN
+                   ALLOCATE( ql_c_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ql_c_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => ql_c_av
              ENDIF
@@ -533,4 +590,8 @@
                 to_be_resorted => ql_v
              ELSE
+                IF ( .NOT. ALLOCATED( ql_v_av ) ) THEN
+                   ALLOCATE( ql_v_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ql_v_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => ql_v_av
              ENDIF
@@ -567,4 +628,8 @@
                 resorted = .TRUE.
              ELSE
+                IF ( .NOT. ALLOCATED( ql_vp_av ) ) THEN
+                   ALLOCATE( ql_vp_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   ql_vp_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => ql_vp_av
              ENDIF
@@ -574,4 +639,8 @@
                 to_be_resorted => qr
              ELSE
+                IF ( .NOT. ALLOCATED( qr_av ) ) THEN
+                   ALLOCATE( qr_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   qr_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => qr_av
              ENDIF
@@ -588,4 +657,8 @@
                 resorted = .TRUE.
              ELSE
+                IF ( .NOT. ALLOCATED( qv_av ) ) THEN
+                   ALLOCATE( qv_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   qv_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => qv_av
              ENDIF
@@ -595,4 +668,8 @@
                 to_be_resorted => rho_ocean
              ELSE
+                IF ( .NOT. ALLOCATED( rho_ocean_av ) ) THEN
+                   ALLOCATE( u_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   u_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => rho_ocean_av
              ENDIF
@@ -602,4 +679,8 @@
                 to_be_resorted => s
              ELSE
+                IF ( .NOT. ALLOCATED( s_av ) ) THEN
+                   ALLOCATE( s_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   s_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => s_av
              ENDIF
@@ -609,4 +690,8 @@
                 to_be_resorted => sa
              ELSE
+                IF ( .NOT. ALLOCATED( sa_av ) ) THEN
+                   ALLOCATE( sa_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   sa_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => sa_av
              ENDIF
@@ -617,4 +702,8 @@
                 to_be_resorted => u
              ELSE
+                IF ( .NOT. ALLOCATED( u_av ) ) THEN
+                   ALLOCATE( u_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   u_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => u_av
              ENDIF
@@ -625,4 +714,8 @@
                 to_be_resorted => v
              ELSE
+                IF ( .NOT. ALLOCATED( v_av ) ) THEN
+                   ALLOCATE( v_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   v_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => v_av
              ENDIF
@@ -632,4 +725,8 @@
                 to_be_resorted => vpt
              ELSE
+                IF ( .NOT. ALLOCATED( vpt_av ) ) THEN
+                   ALLOCATE( vpt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   vpt_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => vpt_av
              ENDIF
@@ -640,4 +737,8 @@
                 to_be_resorted => w
              ELSE
+                IF ( .NOT. ALLOCATED( w_av ) ) THEN
+                   ALLOCATE( w_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                   w_av = REAL( fill_value, KIND = wp )
+                ENDIF
                 to_be_resorted => w_av
              ENDIF
