Index: palm/trunk/SOURCE/flow_statistics.f90
===================================================================
--- palm/trunk/SOURCE/flow_statistics.f90	(revision 2674)
+++ palm/trunk/SOURCE/flow_statistics.f90	(revision 2696)
@@ -1,5 +1,5 @@
 !> @file flow_statistics.f90
 !------------------------------------------------------------------------------!
-! This file is part of PALM.
+! This file is part of the PALM model system.
 !
 ! PALM is free software: you can redistribute it and/or modify it under the
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Bugfix in evaluation of surface quantities in case different surface types
+! are used (MS)
+! 
+! 2674 2017-12-07 11:49:21Z suehring
 ! Bugfix in output conversion of resolved-scale momentum fluxes in case of 
 ! PW advections scheme.
@@ -288,5 +292,5 @@
 
     USE radiation_model_mod,                                                   &
-        ONLY:  radiation, radiation_scheme, rad_net,                           &
+        ONLY:  radiation, radiation_scheme,                                    &
                rad_lw_in, rad_lw_out, rad_lw_cs_hr, rad_lw_hr,                 &
                rad_sw_in, rad_sw_out, rad_sw_cs_hr, rad_sw_hr
@@ -698,5 +702,6 @@
 !
 !--          2D-arrays (being collected in the last column of sums_l)
-             IF ( surf_def_h(0)%ns >= 1 )  THEN
+             IF ( surf_def_h(0)%end_index(j,i) >=                                 &
+                  surf_def_h(0)%start_index(j,i) )  THEN
                 m = surf_def_h(0)%start_index(j,i)
                 sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +               &
@@ -717,5 +722,5 @@
                 ENDIF
              ENDIF
-             IF ( surf_lsm_h%ns >= 1 )  THEN
+             IF ( surf_lsm_h%end_index(j,i) >= surf_lsm_h%start_index(j,i) )  THEN
                 m = surf_lsm_h%start_index(j,i)
                 sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +               &
@@ -736,6 +741,6 @@
                 ENDIF
              ENDIF
-             IF ( surf_usm_h%ns >= 1 )  THEN
-                m = surf_lsm_h%start_index(j,i)
+             IF ( surf_usm_h%end_index(j,i) >= surf_usm_h%start_index(j,i) )  THEN
+                m = surf_usm_h%start_index(j,i)
                 sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +               &
                                         surf_usm_h%us(m)   * rmask(j,i,sr)
@@ -925,5 +930,6 @@
                    ki = MERGE( -1, 0, l == 0 )
                    IF ( surf_def_h(l)%ns >= 1 )  THEN
-                      DO  m = surf_def_h(l)%start_index(j,i), surf_def_h(l)%end_index(j,i)
+                      DO  m = surf_def_h(l)%start_index(j,i),                  &
+                              surf_def_h(l)%end_index(j,i)
                          k = surf_def_h(l)%k(m)
 
@@ -978,5 +984,6 @@
                    ENDIF
                 ENDDO
-                IF ( surf_lsm_h%ns >= 1 )  THEN
+                IF ( surf_lsm_h%end_index(j,i) >=                              &
+                     surf_lsm_h%start_index(j,i) )  THEN
                    m = surf_lsm_h%start_index(j,i)
                    sums_l(nzb,12,tn) = sums_l(nzb,12,tn) + &
@@ -1028,5 +1035,6 @@
 
                 ENDIF
-                IF ( surf_usm_h%ns >= 1 )  THEN
+                IF ( surf_usm_h%end_index(j,i) >=                              &
+                     surf_usm_h%start_index(j,i) )  THEN
                    m = surf_usm_h%start_index(j,i)
                    sums_l(nzb,12,tn) = sums_l(nzb,12,tn) + &
@@ -1082,17 +1090,20 @@
 
              IF ( .NOT. neutral )  THEN
-                IF ( surf_def_h(0)%ns >= 1 )  THEN
+                IF ( surf_def_h(0)%end_index(j,i) >=                           &
+                     surf_def_h(0)%start_index(j,i) )  THEN
                    m = surf_def_h(0)%start_index(j,i)
-                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) +                      &
+                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) +                   &
                                         surf_def_h(0)%ol(m)  * rmask(j,i,sr) ! L
                 ENDIF
-                IF ( surf_lsm_h%ns >= 1 )  THEN
+                IF ( surf_lsm_h%end_index(j,i) >=                              &
+                     surf_lsm_h%start_index(j,i) )  THEN
                    m = surf_lsm_h%start_index(j,i)
-                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) +                      &
+                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) +                   &
                                         surf_lsm_h%ol(m)  * rmask(j,i,sr) ! L
                 ENDIF
-                IF ( surf_usm_h%ns >= 1 )  THEN
+                IF ( surf_usm_h%end_index(j,i) >=                              &
+                     surf_usm_h%start_index(j,i) )  THEN
                    m = surf_usm_h%start_index(j,i)
-                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) +                      &
+                   sums_l(nzb,112,tn) = sums_l(nzb,112,tn) +                   &
                                         surf_usm_h%ol(m)  * rmask(j,i,sr) ! L
                 ENDIF
@@ -1100,16 +1111,87 @@
 
              IF ( radiation )  THEN
-                sums_l(nzb,99,tn)  = sums_l(nzb,99,tn)  + rad_net(j,i)
-                sums_l(nzb,100,tn)  = sums_l(nzb,100,tn)  + rad_lw_in(nzb,j,i)
-                sums_l(nzb,101,tn)  = sums_l(nzb,101,tn)  + rad_lw_out(nzb,j,i)
-                sums_l(nzb,102,tn)  = sums_l(nzb,102,tn)  + rad_sw_in(nzb,j,i)
-                sums_l(nzb,103,tn)  = sums_l(nzb,103,tn)  + rad_sw_out(nzb,j,i)
+                IF ( surf_def_h(0)%end_index(j,i) >=                           &
+                     surf_def_h(0)%start_index(j,i) )  THEN
+                   m = surf_def_h(0)%start_index(j,i)
+                   sums_l(nzb,99,tn)  = sums_l(nzb,99,tn)  +                   &
+                                        surf_def_h(0)%rad_net(m) * rmask(j,i,sr)
+                   sums_l(nzb,100,tn) = sums_l(nzb,100,tn)  +                  &
+                                        surf_def_h(0)%rad_lw_in(m) * rmask(j,i,sr)
+                   sums_l(nzb,101,tn) = sums_l(nzb,101,tn)  +                  &
+                                        surf_def_h(0)%rad_lw_out(m) * rmask(j,i,sr)
+                   sums_l(nzb,102,tn) = sums_l(nzb,102,tn)  +                  &
+                                        surf_def_h(0)%rad_sw_in(m) * rmask(j,i,sr)
+                   sums_l(nzb,103,tn) = sums_l(nzb,103,tn)  +                  &
+                                        surf_def_h(0)%rad_sw_out(m) * rmask(j,i,sr)
+                ENDIF
+                IF ( surf_lsm_h%end_index(j,i) >=                              &
+                     surf_lsm_h%start_index(j,i) )  THEN
+                   m = surf_lsm_h%start_index(j,i)
+                   sums_l(nzb,99,tn)  = sums_l(nzb,99,tn)  +                   &
+                                        surf_lsm_h%rad_net(m) * rmask(j,i,sr)
+                   sums_l(nzb,100,tn) = sums_l(nzb,100,tn)  +                  &
+                                        surf_lsm_h%rad_lw_in(m) * rmask(j,i,sr)
+                   sums_l(nzb,101,tn) = sums_l(nzb,101,tn)  +                  &
+                                        surf_lsm_h%rad_lw_out(m) * rmask(j,i,sr)
+                   sums_l(nzb,102,tn) = sums_l(nzb,102,tn)  +                  &
+                                        surf_lsm_h%rad_sw_in(m) * rmask(j,i,sr)
+                   sums_l(nzb,103,tn) = sums_l(nzb,103,tn)  +                  &
+                                        surf_lsm_h%rad_sw_out(m) * rmask(j,i,sr)
+                ENDIF
+                IF ( surf_usm_h%end_index(j,i) >=                              &
+                     surf_usm_h%start_index(j,i) )  THEN
+                   m = surf_usm_h%start_index(j,i)
+                   sums_l(nzb,99,tn)  = sums_l(nzb,99,tn)  +                   &
+                                        surf_usm_h%rad_net(m) * rmask(j,i,sr)
+                   sums_l(nzb,100,tn) = sums_l(nzb,100,tn)  +                  &
+                                        surf_usm_h%rad_lw_in(m) * rmask(j,i,sr)
+                   sums_l(nzb,101,tn) = sums_l(nzb,101,tn)  +                  &
+                                        surf_usm_h%rad_lw_out(m) * rmask(j,i,sr)
+                   sums_l(nzb,102,tn) = sums_l(nzb,102,tn)  +                  &
+                                        surf_usm_h%rad_sw_in(m) * rmask(j,i,sr)
+                   sums_l(nzb,103,tn) = sums_l(nzb,103,tn)  +                  &
+                                        surf_usm_h%rad_sw_out(m) * rmask(j,i,sr)
+                ENDIF
 
 #if defined ( __rrtmg )
                 IF ( radiation_scheme == 'rrtmg' )  THEN
-                   sums_l(nzb,108,tn)  = sums_l(nzb,108,tn)  + rrtm_aldif(0,j,i)
-                   sums_l(nzb,109,tn)  = sums_l(nzb,109,tn)  + rrtm_aldir(0,j,i)
-                   sums_l(nzb,110,tn)  = sums_l(nzb,110,tn)  + rrtm_asdif(0,j,i)
-                   sums_l(nzb,111,tn)  = sums_l(nzb,111,tn)  + rrtm_asdir(0,j,i)
+
+                   IF ( surf_def_h(0)%end_index(j,i) >=                        &
+                        surf_def_h(0)%start_index(j,i) )  THEN
+                      m = surf_def_h(0)%start_index(j,i)
+                      sums_l(nzb,108,tn)  = sums_l(nzb,108,tn)  +              &
+                                           surf_def_h(0)%rrtm_aldif(m) * rmask(j,i,sr)
+                      sums_l(nzb,109,tn) = sums_l(nzb,109,tn)  +               &
+                                           surf_def_h(0)%rrtm_aldir(m) * rmask(j,i,sr)
+                      sums_l(nzb,110,tn) = sums_l(nzb,110,tn)  +               &
+                                           surf_def_h(0)%rrtm_asdif(m) * rmask(j,i,sr)
+                      sums_l(nzb,111,tn) = sums_l(nzb,111,tn)  +               &
+                                           surf_def_h(0)%rrtm_asdir(m) * rmask(j,i,sr)
+                   ENDIF
+                   IF ( surf_lsm_h%end_index(j,i) >=                           &
+                        surf_lsm_h%start_index(j,i) )  THEN
+                      m = surf_lsm_h%start_index(j,i)
+                      sums_l(nzb,108,tn)  = sums_l(nzb,108,tn)  +              &
+                                           surf_lsm_h%rrtm_aldif(m) * rmask(j,i,sr)
+                      sums_l(nzb,109,tn) = sums_l(nzb,109,tn)  +               &
+                                           surf_lsm_h%rrtm_aldir(m) * rmask(j,i,sr)
+                      sums_l(nzb,110,tn) = sums_l(nzb,110,tn)  +               &
+                                           surf_lsm_h%rrtm_asdif(m) * rmask(j,i,sr)
+                      sums_l(nzb,111,tn) = sums_l(nzb,111,tn)  +               &
+                                           surf_lsm_h%rrtm_asdir(m) * rmask(j,i,sr)
+                   ENDIF
+                   IF ( surf_usm_h%end_index(j,i) >=                           &
+                        surf_usm_h%start_index(j,i) )  THEN
+                      m = surf_usm_h%start_index(j,i)
+                      sums_l(nzb,108,tn)  = sums_l(nzb,108,tn)  +              &
+                                           surf_usm_h%rrtm_aldif(m) * rmask(j,i,sr)
+                      sums_l(nzb,109,tn) = sums_l(nzb,109,tn)  +               &
+                                           surf_usm_h%rrtm_aldir(m) * rmask(j,i,sr)
+                      sums_l(nzb,110,tn) = sums_l(nzb,110,tn)  +               &
+                                           surf_usm_h%rrtm_asdif(m) * rmask(j,i,sr)
+                      sums_l(nzb,111,tn) = sums_l(nzb,111,tn)  +               &
+                                           surf_usm_h%rrtm_asdir(m) * rmask(j,i,sr)
+                   ENDIF
+
                 ENDIF
 #endif
