Index: palm/trunk/SOURCE/sum_up_3d_data.f90
===================================================================
--- palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 2101)
+++ palm/trunk/SOURCE/sum_up_3d_data.f90	(revision 2232)
@@ -20,5 +20,5 @@
 ! Current revisions:
 ! -----------------
-! 
+! Adjustments to new surface concept
 ! 
 ! Former revisions:
@@ -132,7 +132,6 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  dzw, e, nr, ol, p, pt, precipitation_rate, q, qc, ql, ql_c,     &
-               ql_v, qr, qsws, rho_ocean, s, sa, shf, ssws, ts, u, us, v, vpt, w, z0,&
-               z0h, z0q
+        ONLY:  dzw, e, nr, p, pt, precipitation_rate, q, qc, ql, ql_c, ql_v,   &
+               qr, rho_ocean, s, sa, u, v, vpt, w
 
     USE averaging,                                                             &
@@ -147,6 +146,6 @@
 
     USE control_parameters,                                                    &
-        ONLY:  average_count_3d, cloud_physics, doav, doav_n, rho_surface,     &
-               urban_surface, varnamelength
+        ONLY:  average_count_3d, cloud_physics, doav, doav_n, land_surface,    &
+               rho_surface, urban_surface, varnamelength
 
     USE cpulog,                                                                &
@@ -159,5 +158,5 @@
 
     USE land_surface_model_mod,                                                &
-        ONLY:  land_surface, lsm_3d_data_averaging
+        ONLY:  lsm_3d_data_averaging
 
     USE particle_attributes,                                                   &
@@ -167,4 +166,7 @@
         ONLY:  radiation, radiation_3d_data_averaging
 
+    USE surface_mod,                                                           &
+        ONLY:  surf_def_h, surf_lsm_h, surf_usm_h
+
     USE urban_surface_mod,                                                     &
         ONLY:  usm_average_3d_data
@@ -173,8 +175,9 @@
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i   !< running index
+    INTEGER(iwp) ::  i   !< grid index x direction
     INTEGER(iwp) ::  ii  !< running index
-    INTEGER(iwp) ::  j   !< running index
-    INTEGER(iwp) ::  k   !< running index
+    INTEGER(iwp) ::  j   !< grid index y direction
+    INTEGER(iwp) ::  k   !< grid index x direction
+    INTEGER(iwp) ::  m   !< running index surface type
     INTEGER(iwp) ::  n   !< 
 
@@ -490,8 +493,18 @@
 
           CASE ( 'ol*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   ol_av(j,i) = ol_av(j,i) + ol(j,i)
-                ENDDO
+             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
 
@@ -645,8 +658,18 @@
 
           CASE ( 'qsws*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   qsws_av(j,i) = qsws_av(j,i) + qsws(j,i)
-                ENDDO
+             DO  m = 1, surf_def_h(0)%ns
+                i = surf_def_h(0)%i(m)
+                j = surf_def_h(0)%j(m)
+                qsws_av(j,i) = qsws_av(j,i) + surf_def_h(0)%qsws(m)
+             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)
+             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)
              ENDDO
 
@@ -688,22 +711,53 @@
 
           CASE ( 'shf*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   shf_av(j,i) = shf_av(j,i) + shf(j,i)
-                ENDDO
-             ENDDO
+             DO  m = 1, surf_def_h(0)%ns
+                i = surf_def_h(0)%i(m)
+                j = surf_def_h(0)%j(m)
+                shf_av(j,i) = shf_av(j,i) + surf_def_h(0)%shf(m)
+             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)
+             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)
+             ENDDO
+
 
           CASE ( 'ssws*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   ssws_av(j,i) = ssws_av(j,i) + ssws(j,i)
-                ENDDO
+             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
 
           CASE ( 't*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   ts_av(j,i) = ts_av(j,i) + ts(j,i)
-                ENDDO
+             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
 
@@ -718,8 +772,18 @@
 
           CASE ( 'u*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   us_av(j,i) = us_av(j,i) + us(j,i)
-                ENDDO
+             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
 
@@ -752,22 +816,52 @@
 
           CASE ( 'z0*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   z0_av(j,i) = z0_av(j,i) + z0(j,i)
-                ENDDO
+             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
 
           CASE ( 'z0h*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   z0h_av(j,i) = z0h_av(j,i) + z0h(j,i)
-                ENDDO
+             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
 
           CASE ( 'z0q*' )
-             DO  i = nxlg, nxrg
-                DO  j = nysg, nyng
-                   z0q_av(j,i) = z0q_av(j,i) + z0q(j,i)
-                ENDDO
+             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
 !             
