Index: palm/trunk/SOURCE/surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/surface_mod.f90	(revision 2812)
+++ palm/trunk/SOURCE/surface_mod.f90	(revision 2813)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Some more bugfixes concerning restart runs 
+! 
+! 2812 2018-02-16 13:40:25Z hellstea
 ! Entries 'u_out', 'v_out' and 'w_out' removed from the functions
 ! get_topography_top_index and get_topography_top_index_ji  
@@ -2183,5 +2186,5 @@
        INTEGER(iwp)                 ::  lsp           !< running index chemical species
        INTEGER(iwp)                 ::  m             !< running index for surface elements on individual surface array
-       INTEGER(iwp)                 ::  start_index_h !< start index for horizontal surface elements on gathered surface array
+       INTEGER(iwp), DIMENSION(0:2) ::  start_index_h !< start index for horizontal surface elements on gathered surface array
        INTEGER(iwp), DIMENSION(0:3) ::  mm            !< running index for surface elements on gathered surface array
        INTEGER(iwp), DIMENSION(0:3) ::  start_index_v !< start index for vertical surface elements on gathered surface array
@@ -2394,23 +2397,28 @@
 !
 !--       Gather start- and end indices
-          start_index_h = 1                                        
+          start_index_h(l) = 1                                        
           DO  i = nxl, nxr
              DO  j = nys, nyn
 
-                surf_h(l)%start_index(j,i) = start_index_h
+                surf_h(l)%start_index(j,i) = start_index_h(l)
                 surf_h(l)%end_index(j,i)   = surf_h(l)%start_index(j,i) -1
 
-                IF ( 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)
                    surf_h(l)%end_index(j,i) = surf_h(l)%end_index(j,i) + 1
+                ENDDO
                 IF ( l == 0 )  THEN
-                   IF ( surf_lsm_h%start_index(j,i) <=                         &
-                        surf_lsm_h%end_index(j,i) )                            &
+                   DO  m = surf_lsm_h%start_index(j,i),                        &
+                           surf_lsm_h%end_index(j,i)
                       surf_h(l)%end_index(j,i) = surf_h(l)%end_index(j,i) + 1
-                   IF ( surf_usm_h%start_index(j,i) <=                         &
-                        surf_usm_h%end_index(j,i) )                            &
+                   ENDDO
+                   DO  m = surf_usm_h%start_index(j,i),                        &
+                           surf_usm_h%end_index(j,i)
                       surf_h(l)%end_index(j,i) = surf_h(l)%end_index(j,i) + 1
+                   ENDDO
                 ENDIF
-                start_index_h = surf_h(l)%start_index(j,i) + 1
+
+                start_index_h(l) = surf_h(l)%end_index(j,i) + 1
+
              ENDDO
           ENDDO
@@ -2601,13 +2609,4 @@
           ENDDO
 !
-!--       Finally, determine start- and end-index for the respective surface
-          surf_v(l)%start_index = MAX( surf_def_v(l)%start_index,              &
-                                       surf_lsm_v(l)%start_index,              &
-                                       surf_usm_v(l)%start_index )
-          surf_v(l)%end_index   = MAX( surf_def_v(l)%end_index,                &
-                                       surf_lsm_v(l)%end_index,                &
-                                       surf_usm_v(l)%end_index   )
-
-!
 !--       Gather start- and end indices
           start_index_v(l) = 1                                        
@@ -2618,19 +2617,23 @@
                 surf_v(l)%end_index(j,i)   = surf_v(l)%start_index(j,i) -1
 
-                IF ( surf_def_v(l)%start_index(j,i) <=                         &
-                     surf_def_v(l)%end_index(j,i) )                            &
+                DO  m = surf_def_v(l)%start_index(j,i),                        &
+                        surf_def_v(l)%end_index(j,i)
                    surf_v(l)%end_index(j,i) = surf_v(l)%end_index(j,i) + 1
-                IF ( l == 0 )  THEN
-                   IF ( surf_lsm_v(l)%start_index(j,i) <=                      &
-                        surf_lsm_v(l)%end_index(j,i) )                         &
-                      surf_v(l)%end_index(j,i) = surf_v(l)%end_index(j,i) + 1
-                   IF ( surf_usm_v(l)%start_index(j,i) <=                      &
-                        surf_usm_v(l)%end_index(j,i) )                         &
-                      surf_v(l)%end_index(j,i) = surf_v(l)%end_index(j,i) + 1
-                ENDIF
-                start_index_v(l) = surf_v(l)%start_index(j,i) + 1
+                ENDDO
+                DO  m = surf_lsm_v(l)%start_index(j,i),                        &
+                        surf_lsm_v(l)%end_index(j,i)
+                   surf_v(l)%end_index(j,i) = surf_v(l)%end_index(j,i) + 1
+                ENDDO
+                DO  m = surf_usm_v(l)%start_index(j,i),                        &
+                        surf_usm_v(l)%end_index(j,i)
+                   surf_v(l)%end_index(j,i) = surf_v(l)%end_index(j,i) + 1
+                ENDDO
+
+                start_index_v(l) = surf_v(l)%end_index(j,i) + 1
              ENDDO
           ENDDO
+
        ENDDO
+
 
        WRITE ( 14 )  'ns_h_on_file                  '
