Index: palm/trunk/SOURCE/sum_up_3d_data.f90
===================================================================
--- palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 2963)
+++ 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) )
