Index: /palm/trunk/SOURCE/average_3d_data.f90
===================================================================
--- /palm/trunk/SOURCE/average_3d_data.f90	(revision 3003)
+++ /palm/trunk/SOURCE/average_3d_data.f90	(revision 3004)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Further allocation checks implemented, case z0q* added
+! 
+! 2885 2018-03-14 11:02:46Z Giersch
 ! Preliminary gust module interface implemented
 ! 
@@ -201,314 +204,398 @@
 
           CASE ( 'e' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      e_av(k,j,i) = e_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( e_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         e_av(k,j,i) = e_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'ghf*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   ghf_av(j,i) = ghf_av(j,i)                                   &
-                                 / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-             CALL exchange_horiz_2d( ghf_av, nbgp )
+             IF ( ALLOCATED( ghf_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      ghf_av(j,i) = ghf_av(j,i)                                   &
+                                    / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( ghf_av, nbgp )
+             ENDIF
 
           CASE ( 'qsws*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   qsws_av(j,i) = qsws_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-             CALL exchange_horiz_2d( qsws_av, nbgp )
+             IF ( ALLOCATED( qsws_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      qsws_av(j,i) = qsws_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( qsws_av, nbgp )
+             ENDIF
 
           CASE ( 'lpt' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      lpt_av(k,j,i) = lpt_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( lpt_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         lpt_av(k,j,i) = lpt_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'lwp*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   lwp_av(j,i) = lwp_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( lwp_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      lwp_av(j,i) = lwp_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'nc' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      nc_av(k,j,i) = nc_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( nc_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         nc_av(k,j,i) = nc_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'nr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      nr_av(k,j,i) = nr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( nr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         nr_av(k,j,i) = nr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
          CASE ( 'ol*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   ol_av(j,i) = ol_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-             CALL exchange_horiz_2d( ol_av, nbgp )
+             IF ( ALLOCATED( ol_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      ol_av(j,i) = ol_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( ol_av, nbgp )
+             ENDIF
 
           CASE ( 'p' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      p_av(k,j,i) = p_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( p_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         p_av(k,j,i) = p_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'pc' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   DO  k = nzb, nzt+1
-                      pc_av(k,j,i) = pc_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( pc_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      DO  k = nzb, nzt+1
+                         pc_av(k,j,i) = pc_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'pr' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   DO  k = nzb, nzt+1
-                      pr_av(k,j,i) = pr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
-
-          CASE ( 'prr*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   precipitation_rate_av(j,i) = precipitation_rate_av(j,i) /   &
-                                                REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( pr_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      DO  k = nzb, nzt+1
+                         pr_av(k,j,i) = pr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
+
+          CASE ( 'prr' )
+             IF ( ALLOCATED( prr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         prr_av(k,j,i) = prr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'pt' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      pt_av(k,j,i) = pt_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( pt_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         pt_av(k,j,i) = pt_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'q' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      q_av(k,j,i) = q_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( q_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         q_av(k,j,i) = q_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'qc' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      qc_av(k,j,i) = qc_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( qc_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         qc_av(k,j,i) = qc_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'ql' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      ql_av(k,j,i) = ql_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( ql_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         ql_av(k,j,i) = ql_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'ql_c' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      ql_c_av(k,j,i) = ql_c_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( ql_c_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         ql_c_av(k,j,i) = ql_c_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'ql_v' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      ql_v_av(k,j,i) = ql_v_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( ql_v_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         ql_v_av(k,j,i) = ql_v_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'ql_vp' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      ql_vp_av(k,j,i) = ql_vp_av(k,j,i) /                      &
-                                        REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( ql_vp_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         ql_vp_av(k,j,i) = ql_vp_av(k,j,i) /                      &
+                                           REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'qr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      qr_av(k,j,i) = qr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( qr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         qr_av(k,j,i) = qr_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'qv' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      qv_av(k,j,i) = qv_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( qv_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         qv_av(k,j,i) = qv_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
          CASE ( 'r_a*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   r_a_av(j,i) = r_a_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-             CALL exchange_horiz_2d( r_a_av, nbgp )
+             IF ( ALLOCATED( r_a_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      r_a_av(j,i) = r_a_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( r_a_av, nbgp )
+             ENDIF
 
           CASE ( 'rho_ocean' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rho_ocean_av(k,j,i) = rho_ocean_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( rho_ocean_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rho_ocean_av(k,j,i) = rho_ocean_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 's' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      s_av(k,j,i) = s_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( s_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         s_av(k,j,i) = s_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'sa' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      sa_av(k,j,i) = sa_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( sa_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         sa_av(k,j,i) = sa_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
          CASE ( 'shf*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   shf_av(j,i) = shf_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-             CALL exchange_horiz_2d( shf_av, nbgp )
+             IF ( ALLOCATED( shf_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      shf_av(j,i) = shf_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( shf_av, nbgp )
+             ENDIF
 
           CASE ( 'ssws*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   ssws_av(j,i) = ssws_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-             CALL exchange_horiz_2d( ssws_av, nbgp )
+             IF ( ALLOCATED( ssws_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      ssws_av(j,i) = ssws_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( ssws_av, nbgp )
+             ENDIF
 
           CASE ( 't*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   ts_av(j,i) = ts_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-             CALL exchange_horiz_2d( ts_av, nbgp )
+             IF ( ALLOCATED( ts_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      ts_av(j,i) = ts_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( ts_av, nbgp )
+             ENDIF
 
          CASE ( 'tsurf*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   tsurf_av(j,i) = tsurf_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-             CALL exchange_horiz_2d( tsurf_av, nbgp )
+             IF ( ALLOCATED( tsurf_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      tsurf_av(j,i) = tsurf_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( tsurf_av, nbgp )
+             ENDIF
 
           CASE ( 'u' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      u_av(k,j,i) = u_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( u_av ) ) THEN 
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         u_av(k,j,i) = u_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'u*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   us_av(j,i) = us_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-             CALL exchange_horiz_2d( us_av, nbgp )
+             IF ( ALLOCATED( us_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      us_av(j,i) = us_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( us_av, nbgp )
+             ENDIF
 
           CASE ( 'v' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      v_av(k,j,i) = v_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( v_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         v_av(k,j,i) = v_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'vpt' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      vpt_av(k,j,i) = vpt_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( vpt_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         vpt_av(k,j,i) = vpt_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'w' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      w_av(k,j,i) = w_av(k,j,i) / REAL( average_count_3d, KIND=wp )
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( w_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         w_av(k,j,i) = w_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'z0*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   z0_av(j,i) = z0_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-             CALL exchange_horiz_2d( z0_av, nbgp )
+             IF ( ALLOCATED( z0_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      z0_av(j,i) = z0_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( z0_av, nbgp )
+             ENDIF
 
           CASE ( 'z0h*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   z0h_av(j,i) = z0h_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-             CALL exchange_horiz_2d( z0h_av, nbgp )
+             IF ( ALLOCATED( z0h_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      z0h_av(j,i) = z0h_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( z0h_av, nbgp )
+             ENDIF
+
+          CASE ( 'z0q*' )
+             IF ( ALLOCATED( z0q_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      z0q_av(j,i) = z0q_av(j,i) / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+                CALL exchange_horiz_2d( z0q_av, nbgp )
+             ENDIF
+
 !             
 !--       Block of urban surface model outputs   
Index: /palm/trunk/SOURCE/chemistry_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3003)
+++ /palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3004)
@@ -27,4 +27,7 @@
 ! -----------------
 ! $Id$
+! Comment concerning averaged data output added 
+! 
+! 2932 2018-03-26 09:39:22Z maronga
 ! renamed chemistry_par to chemistry_parameters
 ! 
@@ -1219,5 +1222,11 @@
 ! Description:
 ! ------------
-!> Subroutine for averaging 3D data of chemical species
+!> Subroutine for averaging 3D data of chemical species. Due to the fact that 
+!> the averaged chem arrays are allocated in chem_init, no if-query concerning
+!> the allocation is required (in any mode). Attention: If you just specify an 
+!> averaged output quantity in the _p3dr file during restarts the first output
+!> includes the time between the beginning of the restart run and the first
+!> output time (not necessarily the whole averaging_interval you have 
+!> specified in your _p3d/_p3dr file )
 !------------------------------------------------------------------------------!
 
Index: /palm/trunk/SOURCE/data_output_2d.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_2d.f90	(revision 3003)
+++ /palm/trunk/SOURCE/data_output_2d.f90	(revision 3004)
@@ -25,4 +25,9 @@
 ! -----------------
 ! $Id$
+! precipitation_rate removed, case prr*_xy removed, to_be_resorted have to point
+! to ql_vp_av and not to ql_vp, allocation checks implemented (averaged data 
+! will be assigned to fill values if no allocation happened so far)   
+! 
+! 2963 2018-04-12 14:47:44Z suehring
 ! Introduce index for vegetation/wall, pavement/green-wall and water/window 
 ! surfaces, for clearer access of surface fraction, albedo, emissivity, etc. .
@@ -211,7 +216,7 @@
     USE arrays_3d,                                                             &
         ONLY:  dzw, e, heatflux_output_conversion, nc, nr, p, pt,              &
-               precipitation_amount, precipitation_rate,                       &
-               prr, q, qc, ql, ql_c, ql_v, ql_vp, qr, rho_ocean, s, sa,        &
-               tend, u, v, vpt, w, zu, zw, waterflux_output_conversion
+               precipitation_amount, prr, q, qc, ql, ql_c, ql_v, ql_vp, qr,    &
+               rho_ocean, s, sa, tend, u, v, vpt, w, zu, zw,                   &
+               waterflux_output_conversion
         
     USE averaging
@@ -241,5 +246,6 @@
         
     USE indices,                                                               &
-        ONLY:  nbgp, nx, nxl, nxr, ny, nyn, nys, nz, nzb, nzt, wall_flags_0
+        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nz,   &
+               nzb, nzt, wall_flags_0
                
     USE kinds
@@ -516,4 +522,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
@@ -524,4 +534,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
@@ -537,4 +551,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( lwp_av ) ) THEN
+                      ALLOCATE( lwp_av(nysg:nyng,nxlg:nxrg) )
+                      lwp_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn
@@ -551,4 +569,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
@@ -559,4 +581,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
@@ -581,4 +607,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( ghf_av ) ) THEN
+                      ALLOCATE( ghf_av(nysg:nyng,nxlg:nxrg) )
+                      ghf_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn
@@ -610,4 +640,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( ol_av ) ) THEN
+                      ALLOCATE( ol_av(nysg:nyng,nxlg:nxrg) )
+                      ol_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn
@@ -625,4 +659,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
@@ -647,4 +685,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
 !                   CALL exchange_horiz( pc_av, nbgp )
                    to_be_resorted => pc_av
@@ -692,4 +734,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
 !                   CALL exchange_horiz( pr_av, nbgp )
                    to_be_resorted => pr_av
@@ -704,24 +750,4 @@
                 ENDDO
                 precipitation_amount = 0.0_wp   ! reset for next integ. interval
-                resorted = .TRUE.
-                two_d = .TRUE.
-                level_z(nzb+1) = zu(nzb+1)
-
-             CASE ( 'prr*_xy' )        ! 2d-array
-                IF ( av == 0 )  THEN
-!                   CALL exchange_horiz_2d( prr(nzb+1,:,:) )
-                   DO  i = nxl, nxr
-                      DO  j = nys, nyn
-                         local_pf(i,j,nzb+1) = prr(nzb+1,j,i) * hyrho(nzb+1)
-                      ENDDO
-                   ENDDO
-                ELSE
-!                   CALL exchange_horiz_2d( prr_av(nzb+1,:,:) )
-                   DO  i = nxl, nxr
-                      DO  j = nys, nyn
-                         local_pf(i,j,nzb+1) = prr_av(nzb+1,j,i) * hyrho(nzb+1)
-                      ENDDO
-                   ENDDO
-                ENDIF
                 resorted = .TRUE.
                 two_d = .TRUE.
@@ -739,4 +765,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
 !                   CALL exchange_horiz( prr_av, nbgp )
                    DO  i = nxl, nxr
@@ -768,4 +798,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
@@ -776,4 +810,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
@@ -784,4 +822,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
@@ -792,4 +834,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
@@ -800,4 +846,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
@@ -808,4 +858,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
@@ -844,6 +898,10 @@
                    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
 !                   CALL exchange_horiz( ql_vp_av, nbgp )
-                   to_be_resorted => ql_vp
+                   to_be_resorted => ql_vp_av
                 ENDIF
                 IF ( mode == 'xy' )  level_z = zu
@@ -853,4 +911,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
@@ -883,4 +945,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( qsws_av ) ) THEN
+                      ALLOCATE( qsws_av(nysg:nyng,nxlg:nxrg) )
+                      qsws_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn 
@@ -904,4 +970,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
@@ -928,4 +998,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( r_a_av ) ) THEN
+                      ALLOCATE( r_a_av(nysg:nyng,nxlg:nxrg) )
+                      r_a_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn
@@ -942,4 +1016,8 @@
                    to_be_resorted => rho_ocean
                 ELSE
+                   IF ( .NOT. ALLOCATED( rho_ocean_av ) ) THEN
+                      ALLOCATE( rho_ocean_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                      rho_ocean_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    to_be_resorted => rho_ocean_av
                 ENDIF
@@ -949,4 +1027,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
@@ -956,4 +1038,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
@@ -985,4 +1071,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( shf_av ) ) THEN
+                      ALLOCATE( shf_av(nysg:nyng,nxlg:nxrg) )
+                      shf_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn
@@ -1013,4 +1103,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( ssws_av ) ) THEN
+                      ALLOCATE( ssws_av(nysg:nyng,nxlg:nxrg) )
+                      ssws_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn 
@@ -1041,4 +1135,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( ts_av ) ) THEN
+                      ALLOCATE( ts_av(nysg:nyng,nxlg:nxrg) )
+                      ts_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn
@@ -1072,4 +1170,8 @@
 
                 ELSE
+                   IF ( .NOT. ALLOCATED( tsurf_av ) ) THEN
+                      ALLOCATE( tsurf_av(nysg:nyng,nxlg:nxrg) )
+                      tsurf_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn
@@ -1087,4 +1189,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
@@ -1115,4 +1221,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( us_av ) ) THEN
+                      ALLOCATE( us_av(nysg:nyng,nxlg:nxrg) )
+                      us_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn
@@ -1130,4 +1240,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
@@ -1144,4 +1258,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
@@ -1153,4 +1271,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
@@ -1175,4 +1297,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( z0_av ) ) THEN
+                      ALLOCATE( z0_av(nysg:nyng,nxlg:nxrg) )
+                      z0_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn
@@ -1203,4 +1329,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( z0h_av ) ) THEN
+                      ALLOCATE( z0h_av(nysg:nyng,nxlg:nxrg) )
+                      z0h_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn
@@ -1231,4 +1361,8 @@
                    ENDDO
                 ELSE
+                   IF ( .NOT. ALLOCATED( z0q_av ) ) THEN
+                      ALLOCATE( z0q_av(nysg:nyng,nxlg:nxrg) )
+                      z0q_av = REAL( fill_value, KIND = wp )
+                   ENDIF
                    DO  i = nxl, nxr
                       DO  j = nys, nyn
Index: /palm/trunk/SOURCE/data_output_3d.f90
===================================================================
--- /palm/trunk/SOURCE/data_output_3d.f90	(revision 3003)
+++ /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
Index: /palm/trunk/SOURCE/flow_statistics.f90
===================================================================
--- /palm/trunk/SOURCE/flow_statistics.f90	(revision 3003)
+++ /palm/trunk/SOURCE/flow_statistics.f90	(revision 3004)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Comments related to the calculation of the inversion height expanded
+! 
+! 3003 2018-04-23 10:22:58Z Giersch
 ! The inversion height will not be calcuated before the first timestep in 
 ! case of restarts.
@@ -2007,5 +2010,9 @@
 !--    The corresponding height is assumed as the boundary layer height, if it
 !--    is less than 1.5 times the height where the heat flux becomes negative
-!--    (positive) for the first time.
+!--    (positive) for the first time. Attention: the resolved vertical sensible 
+!--    heat flux (hom(:,1,17,sr) = w*pt*) is not known at the beginning because
+!--    the calculation happens in advec_s_ws which is called after 
+!--    flow_statistics. Therefore z_i is directly taken from restart data at 
+!--    the beginning of restart runs.  
        IF ( TRIM( initializing_actions ) /= 'read_restart_data' .OR.           &
             simulated_time_at_begin /= simulated_time ) THEN
Index: /palm/trunk/SOURCE/gust_mod.f90
===================================================================
--- /palm/trunk/SOURCE/gust_mod.f90	(revision 3003)
+++ /palm/trunk/SOURCE/gust_mod.f90	(revision 3004)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Interfaces concerning data output updated
+! 
+! 
 ! renamed gust_par to gust_parameters
 ! 
@@ -403,4 +406,6 @@
        LOGICAL      ::  two_d !< flag parameter that indicates 2D variables (horizontal cross sections)
 
+       REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
+
        REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb:nzt+1) ::  local_pf !<
 
@@ -427,4 +432,6 @@
 
        LOGICAL      ::  found !<
+
+       REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
 
        REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !<
Index: /palm/trunk/SOURCE/init_3d_model.f90
===================================================================
--- /palm/trunk/SOURCE/init_3d_model.f90	(revision 3003)
+++ /palm/trunk/SOURCE/init_3d_model.f90	(revision 3004)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! precipitation_rate removed
+! 
+! 2995 2018-04-19 12:13:16Z Giersch
 ! CALL radiation_control is not necessary during initialization because 
 ! calculation of radiative fluxes at model start is done in radiation_init 
@@ -724,6 +727,5 @@
 !
 !--          Precipitation amount and rate (only needed if output is switched)
-             ALLOCATE( precipitation_amount(nysg:nyng,nxlg:nxrg),              &
-                       precipitation_rate(nysg:nyng,nxlg:nxrg) )
+             ALLOCATE( precipitation_amount(nysg:nyng,nxlg:nxrg) )
 
 !
Index: /palm/trunk/SOURCE/land_surface_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 3003)
+++ /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 3004)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Further allocation checks implemented (averaged data will be assigned to fill
+! values if no allocation happened so far) 
+! 
+! 2968 2018-04-13 11:52:24Z suehring
 ! Bugfix in initialization in case of elevated model surface
 ! 
@@ -5322,86 +5326,108 @@
 
           CASE ( 'c_liq*' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                c_liq_av(j,i) = c_liq_av(j,i) + surf_lsm_h%c_liq(m)
-             ENDDO
+             IF ( ALLOCATED( c_liq_av ) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   c_liq_av(j,i) = c_liq_av(j,i) + surf_lsm_h%c_liq(m)
+                ENDDO
+             ENDIF   
 
           CASE ( 'c_soil*' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                c_soil_av(j,i) = c_soil_av(j,i) + (1.0 - surf_lsm_h%c_veg(m))
-             ENDDO
+             IF ( ALLOCATED( c_soil_av ) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   c_soil_av(j,i) = c_soil_av(j,i) + (1.0 - surf_lsm_h%c_veg(m))
+                ENDDO
+             ENDIF
 
           CASE ( 'c_veg*' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                c_veg_av(j,i) = c_veg_av(j,i) + surf_lsm_h%c_veg(m)
-             ENDDO
+             IF ( ALLOCATED( c_veg_av ) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   c_veg_av(j,i) = c_veg_av(j,i) + surf_lsm_h%c_veg(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'lai*' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                lai_av(j,i) = lai_av(j,i) + surf_lsm_h%lai(m)
-             ENDDO
+             IF ( ALLOCATED( lai_av ) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   lai_av(j,i) = lai_av(j,i) + surf_lsm_h%lai(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'm_liq*' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                m_liq_av(j,i) = m_liq_av(j,i) + m_liq_h%var_1d(m)
-             ENDDO
+             IF ( ALLOCATED( m_liq_av ) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   m_liq_av(j,i) = m_liq_av(j,i) + m_liq_h%var_1d(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'm_soil' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                DO  k = nzb_soil, nzt_soil
-                   m_soil_av(k,j,i) = m_soil_av(k,j,i) + m_soil_h%var_2d(k,m)
+             IF ( ALLOCATED( m_soil_av ) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   DO  k = nzb_soil, nzt_soil
+                      m_soil_av(k,j,i) = m_soil_av(k,j,i) + m_soil_h%var_2d(k,m)
+                   ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'qsws_liq*' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                qsws_liq_av(j,i) = qsws_liq_av(j,i) +                          &
-                                      surf_lsm_h%qsws_liq(m)
-             ENDDO
+             IF ( ALLOCATED( qsws_liq_av ) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   qsws_liq_av(j,i) = qsws_liq_av(j,i) +                       &
+                                         surf_lsm_h%qsws_liq(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'qsws_soil*' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                qsws_soil_av(j,i) = qsws_soil_av(j,i) +                        &
-                                       surf_lsm_h%qsws_soil(m)
-             ENDDO
+             IF ( ALLOCATED( qsws_soil_av ) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   qsws_soil_av(j,i) = qsws_soil_av(j,i) +                     &
+                                          surf_lsm_h%qsws_soil(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'qsws_veg*' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                qsws_veg_av(j,i) = qsws_veg_av(j,i) +                          &
-                                      surf_lsm_h%qsws_veg(m)
-             ENDDO
+             IF ( ALLOCATED(qsws_veg_av ) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   qsws_veg_av(j,i) = qsws_veg_av(j,i) +                       &
+                                         surf_lsm_h%qsws_veg(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'r_s*' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                r_s_av(j,i) = r_s_av(j,i) + surf_lsm_h%r_s(m)
-             ENDDO
+             IF ( ALLOCATED( r_s_av) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   r_s_av(j,i) = r_s_av(j,i) + surf_lsm_h%r_s(m)
+                ENDDO
+             ENDIF
 
           CASE ( 't_soil' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                DO  k = nzb_soil, nzt_soil
-                   t_soil_av(k,j,i) = t_soil_av(k,j,i) + t_soil_h%var_2d(k,m)
+             IF ( ALLOCATED( t_soil_av ) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   DO  k = nzb_soil, nzt_soil
+                      t_soil_av(k,j,i) = t_soil_av(k,j,i) + t_soil_h%var_2d(k,m)
+                   ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE DEFAULT
@@ -5415,94 +5441,116 @@
 
           CASE ( 'c_liq*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   c_liq_av(j,i) = c_liq_av(j,i)                               &
-                                   / REAL( average_count_3d, KIND=wp )
+             IF ( ALLOCATED( c_liq_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      c_liq_av(j,i) = c_liq_av(j,i)                            &
+                                      / REAL( average_count_3d, KIND=wp )
+                   ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'c_soil*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   c_soil_av(j,i) = c_soil_av(j,i)                             &
+             IF ( ALLOCATED( c_soil_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      c_soil_av(j,i) = c_soil_av(j,i)                          &
+                                       / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+             ENDIF
+
+          CASE ( 'c_veg*' )
+             IF ( ALLOCATED( c_veg_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      c_veg_av(j,i) = c_veg_av(j,i)                            &
+                                      / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+             ENDIF
+
+         CASE ( 'lai*' )
+             IF ( ALLOCATED( lai_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      lai_av(j,i) = lai_av(j,i)                                &
                                     / REAL( average_count_3d, KIND=wp )
+                   ENDDO
                 ENDDO
-             ENDDO
-
-          CASE ( 'c_veg*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   c_veg_av(j,i) = c_veg_av(j,i)                               &
-                                   / REAL( average_count_3d, KIND=wp )
+             ENDIF
+
+          CASE ( 'm_liq*' )
+             IF ( ALLOCATED( m_liq_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      m_liq_av(j,i) = m_liq_av(j,i)                            &
+                                      / REAL( average_count_3d, KIND=wp )
+                   ENDDO
                 ENDDO
-             ENDDO
-
-         CASE ( 'lai*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   lai_av(j,i) = lai_av(j,i)                                   &
-                                 / REAL( average_count_3d, KIND=wp )
+             ENDIF
+
+          CASE ( 'm_soil' )
+             IF ( ALLOCATED( m_soil_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      DO  k = nzb_soil, nzt_soil
+                         m_soil_av(k,j,i) = m_soil_av(k,j,i)                   &
+                                            / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
                 ENDDO
-             ENDDO
-
-          CASE ( 'm_liq*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   m_liq_av(j,i) = m_liq_av(j,i)                               &
-                                   / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-
-          CASE ( 'm_soil' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   DO  k = nzb_soil, nzt_soil
-                      m_soil_av(k,j,i) = m_soil_av(k,j,i)                      &
+             ENDIF
+
+          CASE ( 'qsws_liq*' )
+             IF ( ALLOCATED( qsws_liq_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      qsws_liq_av(j,i) = qsws_liq_av(j,i)                      &
                                          / REAL( average_count_3d, KIND=wp )
                    ENDDO
                 ENDDO
-             ENDDO
-
-          CASE ( 'qsws_liq*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   qsws_liq_av(j,i) = qsws_liq_av(j,i)                         &
-                                      / REAL( average_count_3d, KIND=wp )
+             ENDIF
+
+          CASE ( 'qsws_soil*' )
+             IF ( ALLOCATED( qsws_soil_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      qsws_soil_av(j,i) = qsws_soil_av(j,i)                    &
+                                          / REAL( average_count_3d, KIND=wp )
+                   ENDDO
                 ENDDO
-             ENDDO
-
-          CASE ( 'qsws_soil*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   qsws_soil_av(j,i) = qsws_soil_av(j,i)                       &
-                                       / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'qsws_veg*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   qsws_veg_av(j,i) = qsws_veg_av(j,i)                         &
-                                      / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-
-          CASE ( 'r_s*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   r_s_av(j,i) = r_s_av(j,i) / REAL( average_count_3d, KIND=wp )
-                ENDDO
-             ENDDO
-
-          CASE ( 't_soil' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   DO  k = nzb_soil, nzt_soil
-                      t_soil_av(k,j,i) = t_soil_av(k,j,i)                      &
+             IF ( ALLOCATED( qsws_veg_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      qsws_veg_av(j,i) = qsws_veg_av(j,i)                      &
                                          / REAL( average_count_3d, KIND=wp )
                    ENDDO
                 ENDDO
-             ENDDO
-
+             ENDIF
+
+          CASE ( 'r_s*' )
+             IF ( ALLOCATED( r_s_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      r_s_av(j,i) = r_s_av(j,i)                                & 
+                                    / REAL( average_count_3d, KIND=wp )
+                   ENDDO
+                ENDDO
+             ENDIF
+
+          CASE ( 't_soil' )
+             IF ( ALLOCATED( t_soil_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      DO  k = nzb_soil, nzt_soil
+                         t_soil_av(k,j,i) = t_soil_av(k,j,i)                   &
+                                            / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 !
 !-- 
@@ -5581,4 +5629,6 @@
     LOGICAL      ::  found !< 
     LOGICAL      ::  two_d !< flag parameter that indicates 2D variables (horizontal cross sections)
+
+    REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
 
     REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb:nzt+1) ::  local_pf !< 
@@ -5599,4 +5649,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( c_liq_av ) ) THEN
+               ALLOCATE( c_liq_av(nysg:nyng,nxlg:nxrg) )
+               c_liq_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -5617,4 +5671,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( c_soil_av ) ) THEN
+               ALLOCATE( c_soil_av(nysg:nyng,nxlg:nxrg) )
+               c_soil_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -5635,4 +5693,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( c_veg_av ) ) THEN
+               ALLOCATE( c_veg_av(nysg:nyng,nxlg:nxrg) )
+               c_veg_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -5653,4 +5715,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( lai_av ) ) THEN
+               ALLOCATE( lai_av(nysg:nyng,nxlg:nxrg) )
+               lai_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -5671,4 +5737,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( m_liq_av ) ) THEN
+               ALLOCATE( m_liq_av(nysg:nyng,nxlg:nxrg) )
+               m_liq_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -5691,4 +5761,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( m_soil_av ) ) THEN
+               ALLOCATE( m_soil_av(nzb_soil:nzt_soil,nysg:nyng,nxlg:nxrg) )
+               m_soil_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -5713,4 +5787,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( qsws_liq_av ) ) THEN
+               ALLOCATE( qsws_liq_av(nysg:nyng,nxlg:nxrg) )
+               qsws_liq_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -5731,4 +5809,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( qsws_soil_av ) ) THEN
+               ALLOCATE( qsws_soil_av(nysg:nyng,nxlg:nxrg) )
+               qsws_soil_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -5749,4 +5831,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( qsws_veg_av ) ) THEN
+               ALLOCATE( qsws_veg_av(nysg:nyng,nxlg:nxrg) )
+               qsws_veg_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -5768,4 +5854,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( r_s_av ) ) THEN
+               ALLOCATE( r_s_av(nysg:nyng,nxlg:nxrg) )
+               r_s_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -5788,4 +5878,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( t_soil_av ) ) THEN
+               ALLOCATE( t_soil_av(nzb_soil:nzt_soil,nysg:nyng,nxlg:nxrg) )
+               t_soil_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -5834,4 +5928,6 @@
 
     LOGICAL      ::  found !< 
+
+    REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
 
     REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_soil:nzt_soil) ::  local_pf !< 
@@ -5856,4 +5952,8 @@
             ENDDO
          ELSE
+            IF ( .NOT. ALLOCATED( m_soil_av ) ) THEN
+               ALLOCATE( m_soil_av(nzb_soil:nzt_soil,nysg:nyng,nxlg:nxrg) )
+               m_soil_av = REAL( fill_value, KIND = wp )
+            ENDIF
             DO  i = nxl, nxr
                DO  j = nys, nyn
@@ -5876,4 +5976,8 @@
             ENDDO
          ELSE
+            IF ( .NOT. ALLOCATED( t_soil_av ) ) THEN
+               ALLOCATE( t_soil_av(nzb_soil:nzt_soil,nysg:nyng,nxlg:nxrg) )
+               t_soil_av = REAL( fill_value, KIND = wp )
+            ENDIF
             DO  i = nxl, nxr
                DO  j = nys, nyn
Index: /palm/trunk/SOURCE/modules.f90
===================================================================
--- /palm/trunk/SOURCE/modules.f90	(revision 3003)
+++ /palm/trunk/SOURCE/modules.f90	(revision 3004)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! precipitation_rate removed
+! 
+! 3003 2018-04-23 10:22:58Z Giersch
 ! The inversion height is defined as a global variable now which belongs to the 
 ! module statistics 
@@ -689,5 +692,4 @@
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  mean_inflow_profiles  !< used for turbulent inflow (non-cyclic boundary conditions)
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  precipitation_amount  !< precipitation amount due to gravitational settling (bulk microphysics)
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  precipitation_rate    !< precipitation rate (bulk microphysics)
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  pt_slope_ref          !< potential temperature in rotated coordinate system 
                                                                     !< (in case of sloped surface) 
@@ -923,5 +925,4 @@
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ghf_av                 !< avg. ground heat flux
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  lwp_av                 !< avg. liquid water path
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  precipitation_rate_av  !< avg. precipitation rate
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ol_av                  !< avg. Obukhov length
     REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  qsws_av                !< avg. surface moisture flux
Index: /palm/trunk/SOURCE/netcdf_interface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 3003)
+++ /palm/trunk/SOURCE/netcdf_interface_mod.f90	(revision 3004)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! .NOT. found in if-query added to account for variables found in tcm
+! 
+! 2964 2018-04-12 16:04:03Z Giersch
 ! Calculation of fixed number of output time levels for parallel netcdf output
 ! has been moved completely to check_parameters
@@ -1476,5 +1479,5 @@
 !
 !--                Check for land surface quantities
-                   IF ( land_surface )  THEN
+                   IF ( .NOT. found .AND. land_surface )  THEN
                       CALL lsm_define_netcdf_grid( do3d(av,i), found, grid_x,  &
                                                    grid_y, grid_z )
Index: /palm/trunk/SOURCE/radiation_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3003)
+++ /palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3004)
@@ -28,4 +28,8 @@
 ! -----------------
 ! $Id$
+! Further allocation checks implemented (averaged data will be assigned to fill
+! values if no allocation happened so far) 
+! 
+! 2995 2018-04-19 12:13:16Z Giersch
 ! IF-statement in radiation_init removed so that the calculation of radiative 
 ! fluxes at model start is done in any case, bugfix in 
@@ -7323,93 +7327,112 @@
 
           CASE ( 'rad_net*' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   DO m = surf_lsm_h%start_index(j,i), surf_lsm_h%end_index(j,i)
-                      rad_net_av(j,i) = rad_net_av(j,i) + surf_lsm_h%rad_net(m)
-                   ENDDO
-                   DO m = surf_usm_h%start_index(j,i), surf_usm_h%end_index(j,i)
-                      rad_net_av(j,i) = rad_net_av(j,i) + surf_usm_h%rad_net(m)
+             IF ( ALLOCATED( rad_net_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      DO m = surf_lsm_h%start_index(j,i), surf_lsm_h%end_index(j,i)
+                         rad_net_av(j,i) = rad_net_av(j,i) + surf_lsm_h%rad_net(m)
+                      ENDDO
+                      DO m = surf_usm_h%start_index(j,i), surf_usm_h%end_index(j,i)
+                         rad_net_av(j,i) = rad_net_av(j,i) + surf_usm_h%rad_net(m)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'rad_lw_in' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_lw_in_av(k,j,i) = rad_lw_in_av(k,j,i) + rad_lw_in(k,j,i)
+             IF ( ALLOCATED( rad_lw_in_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_lw_in_av(k,j,i) = rad_lw_in_av(k,j,i)             &
+                                               + rad_lw_in(k,j,i)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'rad_lw_out' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_lw_out_av(k,j,i) = rad_lw_out_av(k,j,i)              &
-                                             + rad_lw_out(k,j,i)
+             IF ( ALLOCATED( rad_lw_out_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_lw_out_av(k,j,i) = rad_lw_out_av(k,j,i)           &
+                                                + rad_lw_out(k,j,i)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'rad_lw_cs_hr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_lw_cs_hr_av(k,j,i) = rad_lw_cs_hr_av(k,j,i)          &
-                                               + rad_lw_cs_hr(k,j,i)
+             IF ( ALLOCATED( rad_lw_cs_hr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_lw_cs_hr_av(k,j,i) = rad_lw_cs_hr_av(k,j,i)       &
+                                                  + rad_lw_cs_hr(k,j,i)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'rad_lw_hr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_lw_hr_av(k,j,i) = rad_lw_hr_av(k,j,i)                &
-                                            + rad_lw_hr(k,j,i)
+             IF ( ALLOCATED( rad_lw_hr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_lw_hr_av(k,j,i) = rad_lw_hr_av(k,j,i)             &
+                                               + rad_lw_hr(k,j,i)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'rad_sw_in' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_sw_in_av(k,j,i) = rad_sw_in_av(k,j,i)                &
-                                            + rad_sw_in(k,j,i)
+             IF ( ALLOCATED( rad_sw_in_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_sw_in_av(k,j,i) = rad_sw_in_av(k,j,i)             &
+                                               + rad_sw_in(k,j,i)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'rad_sw_out' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_sw_out_av(k,j,i) = rad_sw_out_av(k,j,i)              &
-                                             + rad_sw_out(k,j,i)
+             IF ( ALLOCATED( rad_sw_out_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_sw_out_av(k,j,i) = rad_sw_out_av(k,j,i)           &
+                                                + rad_sw_out(k,j,i)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'rad_sw_cs_hr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_sw_cs_hr_av(k,j,i) = rad_sw_cs_hr_av(k,j,i)          &
-                                               + rad_sw_cs_hr(k,j,i)
+             IF ( ALLOCATED( rad_sw_cs_hr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_sw_cs_hr_av(k,j,i) = rad_sw_cs_hr_av(k,j,i)       &
+                                                  + rad_sw_cs_hr(k,j,i)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'rad_sw_hr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_sw_hr_av(k,j,i) = rad_sw_hr_av(k,j,i)                &
-                                            + rad_sw_hr(k,j,i)
+             IF ( ALLOCATED( rad_sw_hr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_sw_hr_av(k,j,i) = rad_sw_hr_av(k,j,i)             &
+                                               + rad_sw_hr(k,j,i)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE DEFAULT
@@ -7423,90 +7446,108 @@
 
          CASE ( 'rad_net*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   rad_net_av(j,i) = rad_net_av(j,i) / REAL( average_count_3d, &
-                                     KIND=wp )
-                ENDDO
-             ENDDO
-
-          CASE ( 'rad_lw_in' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_lw_in_av(k,j,i) = rad_lw_in_av(k,j,i)                &
-                                            / REAL( average_count_3d, KIND=wp )
+             IF ( ALLOCATED( rad_net_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      rad_net_av(j,i) = rad_net_av(j,i)                        &
+                                        / REAL( average_count_3d, KIND=wp )
                    ENDDO
                 ENDDO
-             ENDDO
-
-          CASE ( 'rad_lw_out' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_lw_out_av(k,j,i) = rad_lw_out_av(k,j,i)              &
-                                             / REAL( average_count_3d, KIND=wp )
+             ENDIF
+
+          CASE ( 'rad_lw_in' )
+             IF ( ALLOCATED( rad_lw_in_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_lw_in_av(k,j,i) = rad_lw_in_av(k,j,i)             &
+                                               / REAL( average_count_3d, KIND=wp )
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
-
-          CASE ( 'rad_lw_cs_hr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_lw_cs_hr_av(k,j,i) = rad_lw_cs_hr_av(k,j,i)          &
-                                             / REAL( average_count_3d, KIND=wp )
+             ENDIF
+
+          CASE ( 'rad_lw_out' )
+             IF ( ALLOCATED( rad_lw_out_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_lw_out_av(k,j,i) = rad_lw_out_av(k,j,i)           &
+                                                / REAL( average_count_3d, KIND=wp )
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
-
-          CASE ( 'rad_lw_hr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_lw_hr_av(k,j,i) = rad_lw_hr_av(k,j,i)                &
-                                            / REAL( average_count_3d, KIND=wp )
+             ENDIF
+
+          CASE ( 'rad_lw_cs_hr' )
+             IF ( ALLOCATED( rad_lw_cs_hr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_lw_cs_hr_av(k,j,i) = rad_lw_cs_hr_av(k,j,i)       &
+                                                / REAL( average_count_3d, KIND=wp )
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
-
-          CASE ( 'rad_sw_in' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_sw_in_av(k,j,i) = rad_sw_in_av(k,j,i)                &
-                                            / REAL( average_count_3d, KIND=wp )
+             ENDIF
+
+          CASE ( 'rad_lw_hr' )
+             IF ( ALLOCATED( rad_lw_hr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_lw_hr_av(k,j,i) = rad_lw_hr_av(k,j,i)             &
+                                               / REAL( average_count_3d, KIND=wp )
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
-
-          CASE ( 'rad_sw_out' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_sw_out_av(k,j,i) = rad_sw_out_av(k,j,i)              &
-                                             / REAL( average_count_3d, KIND=wp )
+             ENDIF
+
+          CASE ( 'rad_sw_in' )
+             IF ( ALLOCATED( rad_sw_in_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_sw_in_av(k,j,i) = rad_sw_in_av(k,j,i)             &
+                                               / REAL( average_count_3d, KIND=wp )
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
-
-          CASE ( 'rad_sw_cs_hr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_sw_cs_hr_av(k,j,i) = rad_sw_cs_hr_av(k,j,i)          &
-                                             / REAL( average_count_3d, KIND=wp )
+             ENDIF
+
+          CASE ( 'rad_sw_out' )
+             IF ( ALLOCATED( rad_sw_out_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_sw_out_av(k,j,i) = rad_sw_out_av(k,j,i)           &
+                                                / REAL( average_count_3d, KIND=wp )
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
-
-          CASE ( 'rad_sw_hr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rad_sw_hr_av(k,j,i) = rad_sw_hr_av(k,j,i)                &
-                                            / REAL( average_count_3d, KIND=wp )
+             ENDIF
+
+          CASE ( 'rad_sw_cs_hr' )
+             IF ( ALLOCATED( rad_sw_cs_hr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_sw_cs_hr_av(k,j,i) = rad_sw_cs_hr_av(k,j,i)       &
+                                                / REAL( average_count_3d, KIND=wp )
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
+
+          CASE ( 'rad_sw_hr' )
+             IF ( ALLOCATED( rad_sw_hr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rad_sw_hr_av(k,j,i) = rad_sw_hr_av(k,j,i)             &
+                                               / REAL( average_count_3d, KIND=wp )
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
        END SELECT
@@ -7598,4 +7639,6 @@
     LOGICAL      ::  two_d !< flag parameter that indicates 2D variables (horizontal cross sections)
 
+    REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
+
     REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb:nzt+1) ::  local_pf !< 
 
@@ -7624,4 +7667,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( rad_net_av ) ) THEN
+               ALLOCATE( rad_net_av(nysg:nyng,nxlg:nxrg) )
+               rad_net_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -7644,4 +7691,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( rad_lw_in_av ) ) THEN
+               ALLOCATE( rad_lw_in_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_lw_in_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -7664,4 +7715,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( rad_lw_out_av ) ) THEN
+               ALLOCATE( rad_lw_out_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_lw_out_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -7684,4 +7739,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( rad_lw_cs_hr_av ) ) THEN
+               ALLOCATE( rad_lw_cs_hr_av(nzb+1:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_lw_cs_hr_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -7704,4 +7763,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( rad_lw_hr_av ) ) THEN
+               ALLOCATE( rad_lw_hr_av(nzb+1:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_lw_hr_av= REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -7724,4 +7787,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( rad_sw_in_av ) ) THEN
+               ALLOCATE( rad_sw_in_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_sw_in_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -7744,4 +7811,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( rad_sw_out_av ) ) THEN
+               ALLOCATE( rad_sw_out_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_sw_out_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -7764,4 +7835,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( rad_sw_cs_hr_av ) ) THEN
+               ALLOCATE( rad_sw_cs_hr_av(nzb+1:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_sw_cs_hr_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -7784,4 +7859,8 @@
              ENDDO
           ELSE
+            IF ( .NOT. ALLOCATED( rad_sw_hr_av ) ) THEN
+               ALLOCATE( rad_sw_hr_av(nzb+1:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_sw_hr_av = REAL( fill_value, KIND = wp )
+            ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn 
@@ -7827,4 +7906,6 @@
 
     LOGICAL      ::  found !< 
+
+    REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
 
     REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb:nzt+1) ::  local_pf !< 
@@ -7846,4 +7927,8 @@
             ENDDO
          ELSE
+            IF ( .NOT. ALLOCATED( rad_sw_in_av ) ) THEN
+               ALLOCATE( rad_sw_in_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_sw_in_av = REAL( fill_value, KIND = wp )
+            ENDIF
             DO  i = nxl, nxr
                DO  j = nys, nyn
@@ -7865,4 +7950,8 @@
             ENDDO
          ELSE
+            IF ( .NOT. ALLOCATED( rad_sw_out_av ) ) THEN
+               ALLOCATE( rad_sw_out_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_sw_out_av = REAL( fill_value, KIND = wp )
+            ENDIF
             DO  i = nxl, nxr
                DO  j = nys, nyn
@@ -7884,4 +7973,8 @@
             ENDDO
          ELSE
+            IF ( .NOT. ALLOCATED( rad_sw_cs_hr_av ) ) THEN
+               ALLOCATE( rad_sw_cs_hr_av(nzb+1:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_sw_cs_hr_av = REAL( fill_value, KIND = wp )
+            ENDIF
             DO  i = nxl, nxr
                DO  j = nys, nyn
@@ -7903,4 +7996,8 @@
             ENDDO
          ELSE
+            IF ( .NOT. ALLOCATED( rad_sw_hr_av ) ) THEN
+               ALLOCATE( rad_sw_hr_av(nzb+1:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_sw_hr_av = REAL( fill_value, KIND = wp )
+            ENDIF
             DO  i = nxl, nxr
                DO  j = nys, nyn
@@ -7922,4 +8019,8 @@
             ENDDO
          ELSE
+            IF ( .NOT. ALLOCATED( rad_lw_in_av ) ) THEN
+               ALLOCATE( rad_lw_in_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_lw_in_av = REAL( fill_value, KIND = wp )
+            ENDIF
             DO  i = nxl, nxr
                DO  j = nys, nyn
@@ -7941,4 +8042,8 @@
             ENDDO
          ELSE
+            IF ( .NOT. ALLOCATED( rad_lw_out_av ) ) THEN
+               ALLOCATE( rad_lw_out_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_lw_out_av = REAL( fill_value, KIND = wp )
+            ENDIF
             DO  i = nxl, nxr
                DO  j = nys, nyn
@@ -7960,4 +8065,8 @@
             ENDDO
          ELSE
+            IF ( .NOT. ALLOCATED( rad_lw_cs_hr_av ) ) THEN
+               ALLOCATE( rad_lw_cs_hr_av(nzb+1:nzt+1,nysg:nyng,nxlg:nxrg) )
+               rad_lw_cs_hr_av = REAL( fill_value, KIND = wp )
+            ENDIF
             DO  i = nxl, nxr
                DO  j = nys, nyn
@@ -7979,4 +8088,8 @@
             ENDDO
          ELSE
+            IF ( .NOT. ALLOCATED( rad_lw_hr_av ) ) THEN
+               ALLOCATE( rad_lw_hr_av(nzb+1:nzt+1,nysg:nyng,nxlg:nxrg) )
+              rad_lw_hr_av = REAL( fill_value, KIND = wp )
+            ENDIF
             DO  i = nxl, nxr
                DO  j = nys, nyn
Index: /palm/trunk/SOURCE/read_restart_data_mod.f90
===================================================================
--- /palm/trunk/SOURCE/read_restart_data_mod.f90	(revision 3003)
+++ /palm/trunk/SOURCE/read_restart_data_mod.f90	(revision 3004)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! precipitation_rate_av removed
+! 
+! 3003 2018-04-23 10:22:58Z Giersch
 ! z_i is also read to use the last known inversion height from the 
 ! initial run as the first inversion height which is written into the
@@ -1522,13 +1525,4 @@
                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
-                CASE ( 'precipitation_rate_av' )
-                   IF ( .NOT. ALLOCATED( precipitation_rate_av ) )  THEN
-                      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
Index: /palm/trunk/SOURCE/sum_up_3d_data.f90
===================================================================
--- /palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3003)
+++ /palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 3004)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! prr field added to ONLY-list, prr* case/pr* case/precipitation_rate_av 
+! removed, further allocation checks implemented
+! 
+! 2963 2018-04-12 14:47:44Z suehring
 ! Introduce index for vegetation/wall, pavement/green-wall and water/window 
 ! surfaces, for clearer access of surface fraction, albedo, emissivity, etc. .
@@ -182,7 +186,6 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  dzw, e, heatflux_output_conversion, nc, nr, p, pt,              &
-               precipitation_rate, q, qc, ql, ql_c,                            &
-               ql_v, qr, rho_ocean, s, sa, u, v, vpt, w,                       &
+        ONLY:  dzw, e, heatflux_output_conversion, nc, nr, p, prr, pt,         &
+               q, qc, ql, ql_c, ql_v, qr, rho_ocean, s, sa, u, v, vpt, w,      &
                waterflux_output_conversion
 
@@ -190,9 +193,8 @@
         ONLY:  diss_av, e_av, ghf_av, kh_av, km_av, lpt_av, lwp_av, nc_av,     &
                nr_av,                                                          &
-               ol_av, p_av, pc_av, pr_av, prr_av, precipitation_rate_av, pt_av,&
-               q_av, qc_av, ql_av, ql_c_av, ql_v_av, ql_vp_av, qr_av, qsws_av, &
-               qv_av, r_a_av, rho_ocean_av, s_av, sa_av, shf_av, ssws_av,      &
-               ts_av, tsurf_av, u_av, us_av, v_av, vpt_av, w_av, z0_av, z0h_av,&
-               z0q_av
+               ol_av, p_av, pc_av, pr_av, prr_av, pt_av, q_av, qc_av, ql_av,   &
+               ql_c_av, ql_v_av, ql_vp_av, qr_av, qsws_av, qv_av, r_a_av,      &
+               rho_ocean_av, s_av, sa_av, shf_av, ssws_av, ts_av, tsurf_av,    &
+               u_av, us_av, v_av, vpt_av, w_av, z0_av, z0h_av, z0q_av
     USE chemistry_model_mod,                                                   &
         ONLY:  chem_3d_data_averaging, chem_integrate, chem_species, nspec                                   
@@ -342,10 +344,4 @@
                 prr_av = 0.0_wp
 
-             CASE ( 'prr*' )
-                IF ( .NOT. ALLOCATED( precipitation_rate_av ) )  THEN
-                   ALLOCATE( precipitation_rate_av(nysg:nyng,nxlg:nxrg) )
-                ENDIF
-                precipitation_rate_av = 0.0_wp
-
              CASE ( 'pt' )
                 IF ( .NOT. ALLOCATED( pt_av ) )  THEN
@@ -573,229 +569,269 @@
 
           CASE ( 'ghf*' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                ghf_av(j,i) = ghf_av(j,i) + surf_lsm_h%ghf(m)
-             ENDDO
-
-             DO  m = 1, surf_usm_h%ns
-                i   = surf_usm_h%i(m)            
-                j   = surf_usm_h%j(m)
-                ghf_av(j,i) = ghf_av(j,i) + surf_usm_h%frac(ind_veg_wall,m)  * &
-                                            surf_usm_h%wghf_eb(m)        +     &
-                                            surf_usm_h%frac(ind_pav_green,m) * &
-                                            surf_usm_h%wghf_eb_green(m)  +     &
-                                            surf_usm_h%frac(ind_wat_win,m)   * &
-                                            surf_usm_h%wghf_eb_window(m)
-             ENDDO
+             IF ( ALLOCATED( ghf_av ) ) THEN
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   ghf_av(j,i) = ghf_av(j,i) + surf_lsm_h%ghf(m)
+                ENDDO
+
+                DO  m = 1, surf_usm_h%ns
+                   i   = surf_usm_h%i(m)            
+                   j   = surf_usm_h%j(m)
+                   ghf_av(j,i) = ghf_av(j,i) + surf_usm_h%frac(ind_veg_wall,m)  * &
+                                               surf_usm_h%wghf_eb(m)        +     &
+                                               surf_usm_h%frac(ind_pav_green,m) * &
+                                               surf_usm_h%wghf_eb_green(m)  +     &
+                                               surf_usm_h%frac(ind_wat_win,m)   * &
+                                               surf_usm_h%wghf_eb_window(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'e' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      e_av(k,j,i) = e_av(k,j,i) + e(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( e_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         e_av(k,j,i) = e_av(k,j,i) + e(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'lpt' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      lpt_av(k,j,i) = lpt_av(k,j,i) + pt(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( lpt_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         lpt_av(k,j,i) = lpt_av(k,j,i) + pt(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'lwp*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   lwp_av(j,i) = lwp_av(j,i) + SUM( ql(nzb:nzt,j,i)            &
-                                               * dzw(1:nzt+1) ) * rho_surface
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( lwp_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      lwp_av(j,i) = lwp_av(j,i) + SUM( ql(nzb:nzt,j,i)            &
+                                                  * dzw(1:nzt+1) ) * rho_surface
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'nc' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      nc_av(k,j,i) = nc_av(k,j,i) + nc(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( nc_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         nc_av(k,j,i) = nc_av(k,j,i) + nc(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'nr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      nr_av(k,j,i) = nr_av(k,j,i) + nr(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( nr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         nr_av(k,j,i) = nr_av(k,j,i) + nr(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'ol*' )
-             DO  m = 1, surf_def_h(0)%ns
-                i = surf_def_h(0)%i(m)
-                j = surf_def_h(0)%j(m)
-                ol_av(j,i) = ol_av(j,i) + surf_def_h(0)%ol(m)
-             ENDDO
-             DO  m = 1, surf_lsm_h%ns
-                i = surf_lsm_h%i(m)
-                j = surf_lsm_h%j(m)
-                ol_av(j,i) = ol_av(j,i) + surf_lsm_h%ol(m)
-             ENDDO
-             DO  m = 1, surf_usm_h%ns
-                i = surf_usm_h%i(m)
-                j = surf_usm_h%j(m)
-                ol_av(j,i) = ol_av(j,i) + surf_usm_h%ol(m)
-             ENDDO
+             IF ( ALLOCATED( ol_av ) ) THEN
+                DO  m = 1, surf_def_h(0)%ns
+                   i = surf_def_h(0)%i(m)
+                   j = surf_def_h(0)%j(m)
+                   ol_av(j,i) = ol_av(j,i) + surf_def_h(0)%ol(m)
+                ENDDO
+                DO  m = 1, surf_lsm_h%ns
+                   i = surf_lsm_h%i(m)
+                   j = surf_lsm_h%j(m)
+                   ol_av(j,i) = ol_av(j,i) + surf_lsm_h%ol(m)
+                ENDDO
+                DO  m = 1, surf_usm_h%ns
+                   i = surf_usm_h%i(m)
+                   j = surf_usm_h%j(m)
+                   ol_av(j,i) = ol_av(j,i) + surf_usm_h%ol(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'p' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      p_av(k,j,i) = p_av(k,j,i) + p(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( p_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         p_av(k,j,i) = p_av(k,j,i) + p(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'pc' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   DO  k = nzb, nzt+1
-                      pc_av(k,j,i) = pc_av(k,j,i) + prt_count(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( pc_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      DO  k = nzb, nzt+1
+                         pc_av(k,j,i) = pc_av(k,j,i) + prt_count(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'pr' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   DO  k = nzb, nzt+1
-                      number_of_particles = prt_count(k,j,i)
-                      IF ( number_of_particles <= 0 )  CYCLE
-                      particles => grid_particles(k,j,i)%particles(1:number_of_particles)
-                      s_r2 = 0.0_wp
-                      s_r3 = 0.0_wp
-
-                      DO  n = 1, number_of_particles
-                         IF ( particles(n)%particle_mask )  THEN
-                            s_r2 = s_r2 + particles(n)%radius**2 * &
-                                particles(n)%weight_factor
-                            s_r3 = s_r3 + particles(n)%radius**3 * &
-                                particles(n)%weight_factor
+             IF ( ALLOCATED( pr_av ) ) THEN
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      DO  k = nzb, nzt+1
+                         number_of_particles = prt_count(k,j,i)
+                         IF ( number_of_particles <= 0 )  CYCLE
+                         particles =>                                          &
+                         grid_particles(k,j,i)%particles(1:number_of_particles)
+                         s_r2 = 0.0_wp
+                         s_r3 = 0.0_wp
+
+                         DO  n = 1, number_of_particles
+                            IF ( particles(n)%particle_mask )  THEN
+                               s_r2 = s_r2 + particles(n)%radius**2 *          &
+                                   particles(n)%weight_factor
+                               s_r3 = s_r3 + particles(n)%radius**3 *          &
+                                   particles(n)%weight_factor
+                            ENDIF
+                         ENDDO
+
+                         IF ( s_r2 > 0.0_wp )  THEN
+                            mean_r = s_r3 / s_r2
+                         ELSE
+                            mean_r = 0.0_wp
                          ENDIF
-                      ENDDO
-
-                      IF ( s_r2 > 0.0_wp )  THEN
-                         mean_r = s_r3 / s_r2
-                      ELSE
-                         mean_r = 0.0_wp
-                      ENDIF
-                      pr_av(k,j,i) = pr_av(k,j,i) + mean_r
-                   ENDDO
-                ENDDO
-             ENDDO
-
-
-          CASE ( 'pr*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   precipitation_rate_av(j,i) = precipitation_rate_av(j,i) + &
-                                                precipitation_rate(j,i)
-                ENDDO
-             ENDDO
+                         pr_av(k,j,i) = pr_av(k,j,i) + mean_r
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
+
+          CASE ( 'prr' )
+             IF ( ALLOCATED( prr_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         prr_av(k,j,i) = prr_av(k,j,i) + prr(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'pt' )
-             IF ( .NOT. cloud_physics ) THEN
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                         pt_av(k,j,i) = pt_av(k,j,i) + pt(k,j,i)
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ELSE
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                         pt_av(k,j,i) = pt_av(k,j,i) + pt(k,j,i) + l_d_cp * &
-                                                       pt_d_t(k) * ql(k,j,i)
-                      ENDDO
-                   ENDDO
-                ENDDO
+             IF ( ALLOCATED( pt_av ) ) THEN
+                IF ( .NOT. cloud_physics ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                            pt_av(k,j,i) = pt_av(k,j,i) + pt(k,j,i)
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ELSE
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                            pt_av(k,j,i) = pt_av(k,j,i) + pt(k,j,i) + l_d_cp * &
+                                                          pt_d_t(k) * ql(k,j,i)
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDIF
              ENDIF
 
           CASE ( 'q' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      q_av(k,j,i) = q_av(k,j,i) + q(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( q_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         q_av(k,j,i) = q_av(k,j,i) + q(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'qc' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      qc_av(k,j,i) = qc_av(k,j,i) + qc(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( qc_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         qc_av(k,j,i) = qc_av(k,j,i) + qc(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'ql' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      ql_av(k,j,i) = ql_av(k,j,i) + ql(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( ql_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         ql_av(k,j,i) = ql_av(k,j,i) + ql(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'ql_c' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      ql_c_av(k,j,i) = ql_c_av(k,j,i) + ql_c(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( ql_c_av ) ) THEN 
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         ql_c_av(k,j,i) = ql_c_av(k,j,i) + ql_c(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'ql_v' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      ql_v_av(k,j,i) = ql_v_av(k,j,i) + ql_v(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( ql_v_av ) ) THEN 
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         ql_v_av(k,j,i) = ql_v_av(k,j,i) + ql_v(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'ql_vp' )
-             DO  i = nxl, nxr
-                DO  j = nys, nyn
-                   DO  k = nzb, nzt+1
-                      number_of_particles = prt_count(k,j,i)
-                      IF ( number_of_particles <= 0 )  CYCLE
-                      particles => grid_particles(k,j,i)%particles(1:number_of_particles)
-                      DO  n = 1, number_of_particles
-                         IF ( particles(n)%particle_mask )  THEN
-                            ql_vp_av(k,j,i) = ql_vp_av(k,j,i) + &
-                                              particles(n)%weight_factor / &
-                                              number_of_particles
-                         ENDIF
-                      ENDDO
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( ql_vp_av ) ) THEN 
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      DO  k = nzb, nzt+1
+                         number_of_particles = prt_count(k,j,i)
+                         IF ( number_of_particles <= 0 )  CYCLE
+                         particles =>                                          & 
+                         grid_particles(k,j,i)%particles(1:number_of_particles)
+                         DO  n = 1, number_of_particles
+                            IF ( particles(n)%particle_mask )  THEN
+                               ql_vp_av(k,j,i) = ql_vp_av(k,j,i) + &
+                                                 particles(n)%weight_factor /  &
+                                                 number_of_particles
+                            ENDIF
+                         ENDDO
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'qr' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      qr_av(k,j,i) = qr_av(k,j,i) + qr(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( qr_av ) ) THEN 
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         qr_av(k,j,i) = qr_av(k,j,i) + qr(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'qsws*' )
@@ -804,80 +840,92 @@
 !--          In case of land- and urban-surfaces, convert fluxes into
 !--          dynamic units.
-             DO  m = 1, surf_def_h(0)%ns
-                i = surf_def_h(0)%i(m)
-                j = surf_def_h(0)%j(m)
-                k = surf_def_h(0)%k(m)
-                qsws_av(j,i) = qsws_av(j,i) + surf_def_h(0)%qsws(m) *          &
-                                              waterflux_output_conversion(k)
-             ENDDO
-             DO  m = 1, surf_lsm_h%ns
-                i = surf_lsm_h%i(m)
-                j = surf_lsm_h%j(m)
-                qsws_av(j,i) = qsws_av(j,i) + surf_lsm_h%qsws(m) * l_v
-             ENDDO
-             DO  m = 1, surf_usm_h%ns
-                i = surf_usm_h%i(m)
-                j = surf_usm_h%j(m)
-                qsws_av(j,i) = qsws_av(j,i) + surf_usm_h%qsws(m) * l_v
-             ENDDO
+             IF ( ALLOCATED( qsws_av ) ) THEN 
+                DO  m = 1, surf_def_h(0)%ns
+                   i = surf_def_h(0)%i(m)
+                   j = surf_def_h(0)%j(m)
+                   k = surf_def_h(0)%k(m)
+                   qsws_av(j,i) = qsws_av(j,i) + surf_def_h(0)%qsws(m) *          &
+                                                 waterflux_output_conversion(k)
+                ENDDO
+                DO  m = 1, surf_lsm_h%ns
+                   i = surf_lsm_h%i(m)
+                   j = surf_lsm_h%j(m)
+                   qsws_av(j,i) = qsws_av(j,i) + surf_lsm_h%qsws(m) * l_v
+                ENDDO
+                DO  m = 1, surf_usm_h%ns
+                   i = surf_usm_h%i(m)
+                   j = surf_usm_h%j(m)
+                   qsws_av(j,i) = qsws_av(j,i) + surf_usm_h%qsws(m) * l_v
+                ENDDO
+             ENDIF
 
           CASE ( 'qv' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      qv_av(k,j,i) = qv_av(k,j,i) + q(k,j,i) - ql(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( qv_av ) ) THEN 
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         qv_av(k,j,i) = qv_av(k,j,i) + q(k,j,i) - ql(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'r_a*' )
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                r_a_av(j,i) = r_a_av(j,i) + surf_lsm_h%r_a(m)
-             ENDDO
-!
-!--          Please note, resistance is also applied at urban-type surfaces, 
-!--          and is output only as a single variable. Here, tile approach is
-!--          already implemented, so for each surface fraction resistance 
-!--          need to be summed-up.
-             DO  m = 1, surf_usm_h%ns
-                i   = surf_usm_h%i(m)            
-                j   = surf_usm_h%j(m)
-                r_a_av(j,i) = r_a_av(j,i) +                                    &
-                           ( surf_usm_h%frac(ind_veg_wall,m)  *                &
-                             surf_usm_h%r_a(m)       +                         & 
-                             surf_usm_h%frac(ind_pav_green,m) *                &
-                             surf_usm_h%r_a_green(m) +                         & 
-                             surf_usm_h%frac(ind_wat_win,m)   *                &
-                             surf_usm_h%r_a_window(m) )
-             ENDDO
+             IF ( ALLOCATED( r_a_av ) ) THEN 
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   r_a_av(j,i) = r_a_av(j,i) + surf_lsm_h%r_a(m)
+                ENDDO
+!
+!--             Please note, resistance is also applied at urban-type surfaces, 
+!--             and is output only as a single variable. Here, tile approach is
+!--             already implemented, so for each surface fraction resistance 
+!--             need to be summed-up.
+                DO  m = 1, surf_usm_h%ns
+                   i   = surf_usm_h%i(m)            
+                   j   = surf_usm_h%j(m)
+                   r_a_av(j,i) = r_a_av(j,i) +                                    &
+                              ( surf_usm_h%frac(ind_veg_wall,m)  *                &
+                                surf_usm_h%r_a(m)       +                         & 
+                                surf_usm_h%frac(ind_pav_green,m) *                &
+                                surf_usm_h%r_a_green(m) +                         & 
+                                surf_usm_h%frac(ind_wat_win,m)   *                &
+                                surf_usm_h%r_a_window(m) )
+                ENDDO
+             ENDIF
 
           CASE ( 'rho_ocean' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      rho_ocean_av(k,j,i) = rho_ocean_av(k,j,i) + rho_ocean(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( rho_ocean_av ) ) THEN 
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         rho_ocean_av(k,j,i) = rho_ocean_av(k,j,i) + rho_ocean(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF  
 
           CASE ( 's' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      s_av(k,j,i) = s_av(k,j,i) + s(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( s_av ) ) THEN 
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         s_av(k,j,i) = s_av(k,j,i) + s(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'sa' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      sa_av(k,j,i) = sa_av(k,j,i) + sa(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( sa_av ) ) THEN 
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         sa_av(k,j,i) = sa_av(k,j,i) + sa(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'shf*' )
@@ -886,183 +934,207 @@
 !--          In case of land- and urban-surfaces, convert fluxes into
 !--          dynamic units.
-             DO  m = 1, surf_def_h(0)%ns
-                i = surf_def_h(0)%i(m)
-                j = surf_def_h(0)%j(m)
-                k = surf_def_h(0)%k(m)
-                shf_av(j,i) = shf_av(j,i) + surf_def_h(0)%shf(m)  *            &
-                                            heatflux_output_conversion(k)
-             ENDDO
-             DO  m = 1, surf_lsm_h%ns
-                i = surf_lsm_h%i(m)
-                j = surf_lsm_h%j(m)
-                shf_av(j,i) = shf_av(j,i) + surf_lsm_h%shf(m) * cp
-             ENDDO
-             DO  m = 1, surf_usm_h%ns
-                i = surf_usm_h%i(m)
-                j = surf_usm_h%j(m)
-                shf_av(j,i) = shf_av(j,i) + surf_usm_h%shf(m) * cp
-             ENDDO
+             IF ( ALLOCATED( shf_av ) ) THEN 
+                DO  m = 1, surf_def_h(0)%ns
+                   i = surf_def_h(0)%i(m)
+                   j = surf_def_h(0)%j(m)
+                   k = surf_def_h(0)%k(m)
+                   shf_av(j,i) = shf_av(j,i) + surf_def_h(0)%shf(m)  *            &
+                                               heatflux_output_conversion(k)
+                ENDDO
+                DO  m = 1, surf_lsm_h%ns
+                   i = surf_lsm_h%i(m)
+                   j = surf_lsm_h%j(m)
+                   shf_av(j,i) = shf_av(j,i) + surf_lsm_h%shf(m) * cp
+                ENDDO
+                DO  m = 1, surf_usm_h%ns
+                   i = surf_usm_h%i(m)
+                   j = surf_usm_h%j(m)
+                   shf_av(j,i) = shf_av(j,i) + surf_usm_h%shf(m) * cp
+                ENDDO
+             ENDIF
 
           CASE ( 'ssws*' )
-             DO  m = 1, surf_def_h(0)%ns
-                i = surf_def_h(0)%i(m)
-                j = surf_def_h(0)%j(m)
-                ssws_av(j,i) = ssws_av(j,i) + surf_def_h(0)%ssws(m)
-             ENDDO
-             DO  m = 1, surf_lsm_h%ns
-                i = surf_lsm_h%i(m)
-                j = surf_lsm_h%j(m)
-                ssws_av(j,i) = ssws_av(j,i) + surf_lsm_h%ssws(m)
-             ENDDO
-             DO  m = 1, surf_usm_h%ns
-                i = surf_usm_h%i(m)
-                j = surf_usm_h%j(m)
-                ssws_av(j,i) = ssws_av(j,i) + surf_usm_h%ssws(m)
-             ENDDO
+             IF ( ALLOCATED( ssws_av ) ) THEN 
+                DO  m = 1, surf_def_h(0)%ns
+                   i = surf_def_h(0)%i(m)
+                   j = surf_def_h(0)%j(m)
+                   ssws_av(j,i) = ssws_av(j,i) + surf_def_h(0)%ssws(m)
+                ENDDO
+                DO  m = 1, surf_lsm_h%ns
+                   i = surf_lsm_h%i(m)
+                   j = surf_lsm_h%j(m)
+                   ssws_av(j,i) = ssws_av(j,i) + surf_lsm_h%ssws(m)
+                ENDDO
+                DO  m = 1, surf_usm_h%ns
+                   i = surf_usm_h%i(m)
+                   j = surf_usm_h%j(m)
+                   ssws_av(j,i) = ssws_av(j,i) + surf_usm_h%ssws(m)
+                ENDDO
+             ENDIF
 
           CASE ( 't*' )
-             DO  m = 1, surf_def_h(0)%ns
-                i = surf_def_h(0)%i(m)
-                j = surf_def_h(0)%j(m)
-                ts_av(j,i) = ts_av(j,i) + surf_def_h(0)%ts(m)
-             ENDDO
-             DO  m = 1, surf_lsm_h%ns
-                i = surf_lsm_h%i(m)
-                j = surf_lsm_h%j(m)
-                ts_av(j,i) = ts_av(j,i) + surf_lsm_h%ts(m)
-             ENDDO
-             DO  m = 1, surf_usm_h%ns
-                i = surf_usm_h%i(m)
-                j = surf_usm_h%j(m)
-                ts_av(j,i) = ts_av(j,i) + surf_usm_h%ts(m)
-             ENDDO
+             IF ( ALLOCATED( ts_av ) ) THEN 
+                DO  m = 1, surf_def_h(0)%ns
+                   i = surf_def_h(0)%i(m)
+                   j = surf_def_h(0)%j(m)
+                   ts_av(j,i) = ts_av(j,i) + surf_def_h(0)%ts(m)
+                ENDDO
+                DO  m = 1, surf_lsm_h%ns
+                   i = surf_lsm_h%i(m)
+                   j = surf_lsm_h%j(m)
+                   ts_av(j,i) = ts_av(j,i) + surf_lsm_h%ts(m)
+                ENDDO
+                DO  m = 1, surf_usm_h%ns
+                   i = surf_usm_h%i(m)
+                   j = surf_usm_h%j(m)
+                   ts_av(j,i) = ts_av(j,i) + surf_usm_h%ts(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'tsurf*' )
-             DO  m = 1, surf_def_h(0)%ns
-                i   = surf_def_h(0)%i(m)            
-                j   = surf_def_h(0)%j(m)
-                tsurf_av(j,i) = tsurf_av(j,i) + surf_def_h(0)%pt_surface(m)
-             ENDDO
-
-             DO  m = 1, surf_lsm_h%ns
-                i   = surf_lsm_h%i(m)            
-                j   = surf_lsm_h%j(m)
-                tsurf_av(j,i) = tsurf_av(j,i) + surf_lsm_h%pt_surface(m)
-             ENDDO
-
-             DO  m = 1, surf_usm_h%ns
-                i   = surf_usm_h%i(m)            
-                j   = surf_usm_h%j(m)
-                tsurf_av(j,i) = tsurf_av(j,i) + surf_usm_h%pt_surface(m)
-             ENDDO
+             IF ( ALLOCATED( tsurf_av ) ) THEN             
+                DO  m = 1, surf_def_h(0)%ns
+                   i   = surf_def_h(0)%i(m)            
+                   j   = surf_def_h(0)%j(m)
+                   tsurf_av(j,i) = tsurf_av(j,i) + surf_def_h(0)%pt_surface(m)
+                ENDDO
+
+                DO  m = 1, surf_lsm_h%ns
+                   i   = surf_lsm_h%i(m)            
+                   j   = surf_lsm_h%j(m)
+                   tsurf_av(j,i) = tsurf_av(j,i) + surf_lsm_h%pt_surface(m)
+                ENDDO
+
+                DO  m = 1, surf_usm_h%ns
+                   i   = surf_usm_h%i(m)            
+                   j   = surf_usm_h%j(m)
+                   tsurf_av(j,i) = tsurf_av(j,i) + surf_usm_h%pt_surface(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'u' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      u_av(k,j,i) = u_av(k,j,i) + u(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( u_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         u_av(k,j,i) = u_av(k,j,i) + u(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'u*' )
-             DO  m = 1, surf_def_h(0)%ns
-                i = surf_def_h(0)%i(m)
-                j = surf_def_h(0)%j(m)
-                us_av(j,i) = us_av(j,i) + surf_def_h(0)%us(m)
-             ENDDO
-             DO  m = 1, surf_lsm_h%ns
-                i = surf_lsm_h%i(m)
-                j = surf_lsm_h%j(m)
-                us_av(j,i) = us_av(j,i) + surf_lsm_h%us(m)
-             ENDDO
-             DO  m = 1, surf_usm_h%ns
-                i = surf_usm_h%i(m)
-                j = surf_usm_h%j(m)
-                us_av(j,i) = us_av(j,i) + surf_usm_h%us(m)
-             ENDDO
+             IF ( ALLOCATED( us_av ) ) THEN   
+                DO  m = 1, surf_def_h(0)%ns
+                   i = surf_def_h(0)%i(m)
+                   j = surf_def_h(0)%j(m)
+                   us_av(j,i) = us_av(j,i) + surf_def_h(0)%us(m)
+                ENDDO
+                DO  m = 1, surf_lsm_h%ns
+                   i = surf_lsm_h%i(m)
+                   j = surf_lsm_h%j(m)
+                   us_av(j,i) = us_av(j,i) + surf_lsm_h%us(m)
+                ENDDO
+                DO  m = 1, surf_usm_h%ns
+                   i = surf_usm_h%i(m)
+                   j = surf_usm_h%j(m)
+                   us_av(j,i) = us_av(j,i) + surf_usm_h%us(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'v' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      v_av(k,j,i) = v_av(k,j,i) + v(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( v_av ) ) THEN 
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         v_av(k,j,i) = v_av(k,j,i) + v(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'vpt' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      vpt_av(k,j,i) = vpt_av(k,j,i) + vpt(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( vpt_av ) ) THEN 
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         vpt_av(k,j,i) = vpt_av(k,j,i) + vpt(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'w' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      w_av(k,j,i) = w_av(k,j,i) + w(k,j,i)
-                   ENDDO
-                ENDDO
-             ENDDO
+             IF ( ALLOCATED( w_av ) ) THEN 
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         w_av(k,j,i) = w_av(k,j,i) + w(k,j,i)
+                      ENDDO
+                   ENDDO
+                ENDDO
+             ENDIF
 
           CASE ( 'z0*' )
-             DO  m = 1, surf_def_h(0)%ns
-                i = surf_def_h(0)%i(m)
-                j = surf_def_h(0)%j(m)
-                z0_av(j,i) = z0_av(j,i) + surf_def_h(0)%z0(m)
-             ENDDO
-             DO  m = 1, surf_lsm_h%ns
-                i = surf_lsm_h%i(m)
-                j = surf_lsm_h%j(m)
-                z0_av(j,i) = z0_av(j,i) + surf_lsm_h%z0(m)
-             ENDDO
-             DO  m = 1, surf_usm_h%ns
-                i = surf_usm_h%i(m)
-                j = surf_usm_h%j(m)
-                z0_av(j,i) = z0_av(j,i) + surf_usm_h%z0(m)
-             ENDDO
+             IF ( ALLOCATED( z0_av ) ) THEN 
+                DO  m = 1, surf_def_h(0)%ns
+                   i = surf_def_h(0)%i(m)
+                   j = surf_def_h(0)%j(m)
+                   z0_av(j,i) = z0_av(j,i) + surf_def_h(0)%z0(m)
+                ENDDO
+                DO  m = 1, surf_lsm_h%ns
+                   i = surf_lsm_h%i(m)
+                   j = surf_lsm_h%j(m)
+                   z0_av(j,i) = z0_av(j,i) + surf_lsm_h%z0(m)
+                ENDDO
+                DO  m = 1, surf_usm_h%ns
+                   i = surf_usm_h%i(m)
+                   j = surf_usm_h%j(m)
+                   z0_av(j,i) = z0_av(j,i) + surf_usm_h%z0(m)
+                ENDDO
+             ENDIF
 
           CASE ( 'z0h*' )
-             DO  m = 1, surf_def_h(0)%ns
-                i = surf_def_h(0)%i(m)
-                j = surf_def_h(0)%j(m)
-                z0h_av(j,i) = z0h_av(j,i) + surf_def_h(0)%z0h(m)
-             ENDDO
-             DO  m = 1, surf_lsm_h%ns
-                i = surf_lsm_h%i(m)
-                j = surf_lsm_h%j(m)
-                z0h_av(j,i) = z0h_av(j,i) + surf_lsm_h%z0h(m)
-             ENDDO
-             DO  m = 1, surf_usm_h%ns
-                i = surf_usm_h%i(m)
-                j = surf_usm_h%j(m)
-                z0h_av(j,i) = z0h_av(j,i) + surf_usm_h%z0h(m)
-             ENDDO
-
+             IF ( ALLOCATED( z0h_av ) ) THEN 
+                DO  m = 1, surf_def_h(0)%ns
+                   i = surf_def_h(0)%i(m)
+                   j = surf_def_h(0)%j(m)
+                   z0h_av(j,i) = z0h_av(j,i) + surf_def_h(0)%z0h(m)
+                ENDDO
+                DO  m = 1, surf_lsm_h%ns
+                   i = surf_lsm_h%i(m)
+                   j = surf_lsm_h%j(m)
+                   z0h_av(j,i) = z0h_av(j,i) + surf_lsm_h%z0h(m)
+                ENDDO
+                DO  m = 1, surf_usm_h%ns
+                   i = surf_usm_h%i(m)
+                   j = surf_usm_h%j(m)
+                   z0h_av(j,i) = z0h_av(j,i) + surf_usm_h%z0h(m)
+                ENDDO
+             ENDIF
+   
           CASE ( 'z0q*' )
-             DO  m = 1, surf_def_h(0)%ns
-                i = surf_def_h(0)%i(m)
-                j = surf_def_h(0)%j(m)
-                z0q_av(j,i) = z0q_av(j,i) + surf_def_h(0)%z0q(m)
-             ENDDO
-             DO  m = 1, surf_lsm_h%ns
-                i = surf_lsm_h%i(m)
-                j = surf_lsm_h%j(m)
-                z0q_av(j,i) = z0q_av(j,i) + surf_lsm_h%z0q(m)
-             ENDDO
-             DO  m = 1, surf_usm_h%ns
-                i = surf_usm_h%i(m)
-                j = surf_usm_h%j(m)
-                z0q_av(j,i) = z0q_av(j,i) + surf_usm_h%z0q(m)
-             ENDDO
+             IF ( ALLOCATED( z0q_av ) ) THEN 
+                DO  m = 1, surf_def_h(0)%ns
+                   i = surf_def_h(0)%i(m)
+                   j = surf_def_h(0)%j(m)
+                   z0q_av(j,i) = z0q_av(j,i) + surf_def_h(0)%z0q(m)
+                ENDDO
+                DO  m = 1, surf_lsm_h%ns
+                   i = surf_lsm_h%i(m)
+                   j = surf_lsm_h%j(m)
+                   z0q_av(j,i) = z0q_av(j,i) + surf_lsm_h%z0q(m)
+                ENDDO
+                DO  m = 1, surf_usm_h%ns
+                   i = surf_usm_h%i(m)
+                   j = surf_usm_h%j(m)
+                   z0q_av(j,i) = z0q_av(j,i) + surf_usm_h%z0q(m)
+                ENDDO
+             ENDIF
 !             
 !--       Block of urban surface model outputs. 
 !--       In case of urban surface variables it should be always checked
 !--       if respective arrays are allocated, at least in case of a restart 
-!--       run, as usm arrays are not read from file at the moment. 
+!--       run, as averaged usm arrays are not read from file at the moment. 
           CASE ( 'usm_output' )
              CALL usm_average_3d_data( 'allocate', doav(ii) )
Index: /palm/trunk/SOURCE/time_integration.f90
===================================================================
--- /palm/trunk/SOURCE/time_integration.f90	(revision 3003)
+++ /palm/trunk/SOURCE/time_integration.f90	(revision 3004)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! First call of flow_statistics has been removed. It is already called in 
+! run_control itself
+! 
+! 2984 2018-04-18 11:51:30Z hellstea
 ! CALL pmci_ensure_nest_mass_conservation is removed (so far only commented out)
 ! as seemingly unnecessary.
@@ -507,6 +511,6 @@
 !-- Determine and print out the run control quantities before the first time
 !-- step of this run. For the initial run, some statistics (e.g. divergence)
-!-- need to be determined first.
-    IF ( simulated_time == 0.0_wp )  CALL flow_statistics
+!-- need to be determined first --> CALL flow_statistics at the beginning of
+!-- run_control
     CALL run_control
 !
Index: /palm/trunk/SOURCE/turbulence_closure_mod.f90
===================================================================
--- /palm/trunk/SOURCE/turbulence_closure_mod.f90	(revision 3003)
+++ /palm/trunk/SOURCE/turbulence_closure_mod.f90	(revision 3004)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Further allocation checks implemented
+! 
+! 2938 2018-03-27 15:52:42Z suehring
 ! Further todo's
 ! 
@@ -510,29 +513,35 @@
 
           CASE ( 'diss' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      diss_av(k,j,i) = diss_av(k,j,i) + diss(k,j,i)
+             IF ( ALLOCATED( diss_av ) ) THEN             
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         diss_av(k,j,i) = diss_av(k,j,i) + diss(k,j,i)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'kh' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      kh_av(k,j,i) = kh_av(k,j,i) + kh(k,j,i)
+             IF ( ALLOCATED( kh_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         kh_av(k,j,i) = kh_av(k,j,i) + kh(k,j,i)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'km' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      km_av(k,j,i) = km_av(k,j,i) + km(k,j,i)
+             IF ( ALLOCATED( km_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         km_av(k,j,i) = km_av(k,j,i) + km(k,j,i)
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE DEFAULT
@@ -546,32 +555,38 @@
 
           CASE ( 'diss' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      diss_av(k,j,i) = diss_av(k,j,i)                          & 
-                                     / REAL( average_count_3d, KIND=wp )
+             IF ( ALLOCATED( diss_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         diss_av(k,j,i) = diss_av(k,j,i)                       & 
+                                        / REAL( average_count_3d, KIND=wp )
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'kh' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      kh_av(k,j,i) = kh_av(k,j,i)                              & 
-                                     / REAL( average_count_3d, KIND=wp )
+             IF ( ALLOCATED( kh_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         kh_av(k,j,i) = kh_av(k,j,i)                           & 
+                                        / REAL( average_count_3d, KIND=wp )
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
           CASE ( 'km' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   DO  k = nzb, nzt+1
-                      km_av(k,j,i) = km_av(k,j,i)                              & 
-                                     / REAL( average_count_3d, KIND=wp )
+             IF ( ALLOCATED( km_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      DO  k = nzb, nzt+1
+                         km_av(k,j,i) = km_av(k,j,i)                           & 
+                                        / REAL( average_count_3d, KIND=wp )
+                      ENDDO
                    ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
        END SELECT
@@ -608,4 +623,6 @@
     LOGICAL ::  found   !< 
     LOGICAL ::  two_d   !< flag parameter that indicates 2D variables (horizontal cross sections)
+
+    REAL(wp) ::  fill_value = -999.0_wp  !< value for the _FillValue attribute
 
     REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb:nzt+1) ::  local_pf !< local
@@ -627,4 +644,8 @@
              ENDDO
           ELSE
+             IF ( .NOT. ALLOCATED( diss_av ) ) THEN
+                ALLOCATE( diss_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                diss_av = REAL( fill_value, KIND = wp )
+             ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -648,4 +669,8 @@
              ENDDO
           ELSE
+             IF ( .NOT. ALLOCATED( diss_av ) ) THEN
+                ALLOCATE( diss_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                diss_av = REAL( fill_value, KIND = wp )
+             ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -669,4 +694,8 @@
              ENDDO
           ELSE
+             IF ( .NOT. ALLOCATED( diss_av ) ) THEN
+                ALLOCATE( diss_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                diss_av = REAL( fill_value, KIND = wp )
+             ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -710,4 +739,6 @@
 
     LOGICAL ::  found   !< 
+
+    REAL(wp) ::  fill_value = -999.0_wp  !< value for the _FillValue attribute
 
     REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb:nzt+1) ::  local_pf   !< local
@@ -731,4 +762,8 @@
              ENDDO
           ELSE
+             IF ( .NOT. ALLOCATED( diss_av ) ) THEN
+                ALLOCATE( diss_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                diss_av = REAL( fill_value, KIND = wp )
+             ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -750,4 +785,8 @@
              ENDDO
           ELSE
+             IF ( .NOT. ALLOCATED( kh_av ) ) THEN
+                ALLOCATE( kh_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                kh_av = REAL( fill_value, KIND = wp )
+             ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
@@ -769,4 +808,8 @@
              ENDDO
           ELSE
+             IF ( .NOT. ALLOCATED( km_av ) ) THEN
+                ALLOCATE( km_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+                km_av = REAL( fill_value, KIND = wp )
+             ENDIF
              DO  i = nxl, nxr
                 DO  j = nys, nyn
Index: /palm/trunk/SOURCE/user_3d_data_averaging.f90
===================================================================
--- /palm/trunk/SOURCE/user_3d_data_averaging.f90	(revision 3003)
+++ /palm/trunk/SOURCE/user_3d_data_averaging.f90	(revision 3004)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Further allocation checks implemented
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -112,11 +115,13 @@
 !--       Sample for user-defined output:
 !          CASE ( 'u2' )
-!             DO  i = nxlg, nxrg
-!                DO  j = nysg, nyng
-!                   DO  k = nzb, nzt+1
-!                      u2_av(k,j,i) = u2_av(k,j,i) + u2(k,j,i)
+!             IF ( ALLOCATED( u2_av ) ) THEN
+!                DO  i = nxlg, nxrg
+!                   DO  j = nysg, nyng
+!                      DO  k = nzb, nzt+1
+!                         u2_av(k,j,i) = u2_av(k,j,i) + u2(k,j,i)
+!                      ENDDO
 !                   ENDDO
 !                ENDDO
-!             ENDDO
+!             ENDIF
 
           CASE DEFAULT
@@ -135,11 +140,13 @@
 !--       Sample for user-defined output:
 !          CASE ( 'u2' )
-!             DO  i = nxlg, nxrg
-!                DO  j = nysg, nyng
-!                   DO  k = nzb, nzt+1
-!                      u2_av(k,j,i) = u2_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+!             IF ( ALLOCATED( u2_av ) ) THEN
+!                DO  i = nxlg, nxrg
+!                   DO  j = nysg, nyng
+!                      DO  k = nzb, nzt+1
+!                         u2_av(k,j,i) = u2_av(k,j,i) / REAL( average_count_3d, KIND=wp )
+!                      ENDDO
 !                   ENDDO
 !                ENDDO
-!             ENDDO
+!             ENDIF
 
        END SELECT
Index: /palm/trunk/SOURCE/user_data_output_2d.f90
===================================================================
--- /palm/trunk/SOURCE/user_data_output_2d.f90	(revision 3003)
+++ /palm/trunk/SOURCE/user_data_output_2d.f90	(revision 3004)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Further allocation checks implemented (averaged data will be assigned to fill
+! values if no allocation happened so far)
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -94,4 +98,6 @@
     LOGICAL      ::  two_d !< flag parameter that indicates 2D variables (horizontal cross sections)
 
+    REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
+
     REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb:nzt+1) ::  local_pf !< 
 
@@ -116,4 +122,8 @@
 !             ENDDO
 !          ELSE
+!             IF ( .NOT. ALLOCATED( u2_av ) ) THEN
+!                ALLOCATE( u2_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+!                u2_av = REAL( fill_value, KIND = wp )
+!             ENDIF
 !             DO  i = nxl, nxr
 !                DO  j = nys, nyn
Index: /palm/trunk/SOURCE/user_data_output_3d.f90
===================================================================
--- /palm/trunk/SOURCE/user_data_output_3d.f90	(revision 3003)
+++ /palm/trunk/SOURCE/user_data_output_3d.f90	(revision 3004)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Further allocation checks implemented (averaged data will be assigned to fill
+! values if no allocation happened so far)
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -87,5 +91,7 @@
     LOGICAL      ::  found !< 
 
-   REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !< 
+    REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
+
+    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !< 
 
 
@@ -109,4 +115,8 @@
 !             ENDDO
 !          ELSE
+!             IF ( .NOT. ALLOCATED( u2_av ) ) THEN
+!                ALLOCATE( u2_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+!                u2_av = REAL( fill_value, KIND = wp )
+!             ENDIF
 !             DO  i = nxl, nxr
 !                DO  j = nys, nyn
Index: /palm/trunk/SOURCE/uv_exposure_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/uv_exposure_model_mod.f90	(revision 3003)
+++ /palm/trunk/SOURCE/uv_exposure_model_mod.f90	(revision 3004)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Further allocation checks implemented (averaged data will be assigned to fill
+! values if no allocation happened so far) 
+! 
+! 2932 2018-03-26 09:39:22Z maronga
 ! renamed uvexposure_par to biometeorology_parameters
 ! 
@@ -331,4 +335,6 @@
     LOGICAL      ::  two_d !< flag parameter that indicates 2D variables (horizontal cross sections)
 
+    REAL(wp) ::  fill_value = -999.0_wp    !< value for the _FillValue attribute
+
     REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb:nzt+1) ::  local_pf !< 
 
@@ -353,4 +359,8 @@
 
        CASE ( 'uvem_vitd3dose*_xy' )        ! 2d-array
+          IF ( .NOT. ALLOCATED( vitd3_exposure_av ) ) THEN
+             ALLOCATE( vitd3_exposure_av(nysg:nyng,nxlg:nxrg) )
+             vitd3_exposure_av = REAL( fill_value, KIND = wp )
+          ENDIF
           IF ( av == 1 )  THEN
              DO  i = nxl, nxr
@@ -502,9 +512,11 @@
 
           CASE ( 'uvem_vitd3dose*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   vitd3_exposure_av(j,i) = vitd3_exposure_av(j,i) + vitd3_exposure(j,i)
+             IF ( ALLOCATED( vitd3_exposure_av ) ) THEN
+                DO  i = nxlg, nxrg
+                   DO  j = nysg, nyng
+                      vitd3_exposure_av(j,i) = vitd3_exposure_av(j,i) + vitd3_exposure(j,i)
+                   ENDDO
                 ENDDO
-             ENDDO
+             ENDIF
 
 
Index: /palm/trunk/SOURCE/write_restart_data_mod.f90
===================================================================
--- /palm/trunk/SOURCE/write_restart_data_mod.f90	(revision 3003)
+++ /palm/trunk/SOURCE/write_restart_data_mod.f90	(revision 3004)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! precipitation_rate_av removed
+! 
+! 3003 2018-04-23 10:22:58Z Giersch
 ! z_i is also written out to use the last known inversion height from the 
 ! initial run as the first inversion height which is written into the
@@ -1078,9 +1081,4 @@
        ENDIF
 
-       IF ( ALLOCATED( precipitation_rate_av ) )  THEN
-          CALL wrd_write_string( 'precipitation_rate_av' ) 
-          WRITE ( 14 )  precipitation_rate_av
-       ENDIF
-
        CALL wrd_write_string( 'pt' ) 
        WRITE ( 14 )  pt
