Index: palm/trunk/SOURCE/surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/surface_mod.f90	(revision 4671)
+++ palm/trunk/SOURCE/surface_mod.f90	(revision 4682)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Fix indexing of horizontal surfaces in write restart for full-3D cases
+!
+! 4671 2020-09-09 20:27:58Z pavelkrc
 ! Implementation of downward facing USM and LSM surfaces
 !
@@ -3175,16 +3178,16 @@
              IF ( l < 2 )  THEN
                 DO  m = surf_lsm_h(l)%start_index(j,i), surf_lsm_h(l)%end_index(j,i)
-                   IF ( ALLOCATED( surf_lsm_h(l)%us ) )  surf_h(0)%us(mm(0)) = surf_lsm_h(l)%us(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%ts ) )  surf_h(0)%ts(mm(0)) = surf_lsm_h(l)%ts(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%qs ) )  surf_h(0)%qs(mm(0)) = surf_lsm_h(l)%qs(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%ss ) )  surf_h(0)%ss(mm(0)) = surf_lsm_h(l)%ss(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%qcs ) )  surf_h(0)%qcs(mm(0)) = surf_lsm_h(l)%qcs(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%ncs ) )  surf_h(0)%ncs(mm(0)) = surf_lsm_h(l)%ncs(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%qis ) )  surf_h(0)%qis(mm(0)) = surf_lsm_h(l)%qis(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%nis ) )  surf_h(0)%nis(mm(0)) = surf_lsm_h(l)%nis(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%qrs ) )  surf_h(0)%qrs(mm(0)) = surf_lsm_h(l)%qrs(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%nrs ) )  surf_h(0)%nrs(mm(0)) = surf_lsm_h(l)%nrs(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%ol ) )  surf_h(0)%ol(mm(0)) = surf_lsm_h(l)%ol(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%rib ) )  surf_h(0)%rib(mm(0)) = surf_lsm_h(l)%rib(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%us ) )  surf_h(l)%us(mm(l)) = surf_lsm_h(l)%us(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%ts ) )  surf_h(l)%ts(mm(l)) = surf_lsm_h(l)%ts(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%qs ) )  surf_h(l)%qs(mm(l)) = surf_lsm_h(l)%qs(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%ss ) )  surf_h(l)%ss(mm(l)) = surf_lsm_h(l)%ss(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%qcs ) )  surf_h(l)%qcs(mm(l)) = surf_lsm_h(l)%qcs(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%ncs ) )  surf_h(l)%ncs(mm(l)) = surf_lsm_h(l)%ncs(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%qis ) )  surf_h(l)%qis(mm(l)) = surf_lsm_h(l)%qis(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%nis ) )  surf_h(l)%nis(mm(l)) = surf_lsm_h(l)%nis(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%qrs ) )  surf_h(l)%qrs(mm(l)) = surf_lsm_h(l)%qrs(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%nrs ) )  surf_h(l)%nrs(mm(l)) = surf_lsm_h(l)%nrs(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%ol ) )  surf_h(l)%ol(mm(l)) = surf_lsm_h(l)%ol(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%rib ) )  surf_h(l)%rib(mm(l)) = surf_lsm_h(l)%rib(m)
                    IF ( ALLOCATED( surf_lsm_h(l)%pt_surface ) )                                       &
                       surf_h(l)%pt_surface(mm(l)) = surf_lsm_h(l)%pt_surface(m)
@@ -3193,33 +3196,33 @@
                    IF ( ALLOCATED( surf_def_h(l)%vpt_surface ) )                                      &
                       surf_h(l)%vpt_surface(mm(l)) = surf_lsm_h(l)%vpt_surface(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%usws ) )  surf_h(0)%usws(mm(0)) = surf_lsm_h(l)%usws(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%vsws ) )  surf_h(0)%vsws(mm(0)) = surf_lsm_h(l)%vsws(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%shf ) )  surf_h(0)%shf(mm(0)) = surf_lsm_h(l)%shf(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%qsws ) )  surf_h(0)%qsws(mm(0)) = surf_lsm_h(l)%qsws(m)
-                   IF ( ALLOCATED( surf_lsm_h(l)%ssws ) )  surf_h(0)%ssws(mm(0)) = surf_lsm_h(l)%ssws(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%usws ) )  surf_h(l)%usws(mm(l)) = surf_lsm_h(l)%usws(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%vsws ) )  surf_h(l)%vsws(mm(l)) = surf_lsm_h(l)%vsws(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%shf ) )  surf_h(l)%shf(mm(l)) = surf_lsm_h(l)%shf(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%qsws ) )  surf_h(l)%qsws(mm(l)) = surf_lsm_h(l)%qsws(m)
+                   IF ( ALLOCATED( surf_lsm_h(l)%ssws ) )  surf_h(l)%ssws(mm(l)) = surf_lsm_h(l)%ssws(m)
                    IF ( ALLOCATED( surf_lsm_h(l)%css ) )  THEN
                       DO  lsp = 1, nvar
-                         surf_h(0)%css(lsp,mm(0)) = surf_lsm_h(l)%css(lsp,m)
+                         surf_h(l)%css(lsp,mm(l)) = surf_lsm_h(l)%css(lsp,m)
                       ENDDO
                    ENDIF
                    IF ( ALLOCATED( surf_lsm_h(l)%cssws ) )  THEN
                       DO  lsp = 1, nvar
-                         surf_h(0)%cssws(lsp,mm(0)) = surf_lsm_h(l)%cssws(lsp,m)
+                         surf_h(l)%cssws(lsp,mm(l)) = surf_lsm_h(l)%cssws(lsp,m)
                       ENDDO
                    ENDIF
                    IF ( ALLOCATED( surf_lsm_h(l)%qcsws ) )                                            &
-                      surf_h(0)%qcsws(mm(0)) = surf_lsm_h(l)%qcsws(m)
+                      surf_h(l)%qcsws(mm(l)) = surf_lsm_h(l)%qcsws(m)
                    IF ( ALLOCATED( surf_lsm_h(l)%qisws ) )                                            &
-                      surf_h(0)%qisws(mm(0)) = surf_lsm_h(l)%qisws(m)
+                      surf_h(l)%qisws(mm(l)) = surf_lsm_h(l)%qisws(m)
                    IF ( ALLOCATED( surf_lsm_h(l)%qrsws ) )                                            &
-                      surf_h(0)%qrsws(mm(0)) = surf_lsm_h(l)%qrsws(m)
+                      surf_h(l)%qrsws(mm(l)) = surf_lsm_h(l)%qrsws(m)
                    IF ( ALLOCATED( surf_lsm_h(l)%ncsws ) )                                            &
-                      surf_h(0)%ncsws(mm(0)) = surf_lsm_h(l)%ncsws(m)
+                      surf_h(l)%ncsws(mm(l)) = surf_lsm_h(l)%ncsws(m)
                    IF ( ALLOCATED( surf_lsm_h(l)%nisws ) )                                            &
-                      surf_h(0)%nisws(mm(0)) = surf_lsm_h(l)%nisws(m)
+                      surf_h(l)%nisws(mm(l)) = surf_lsm_h(l)%nisws(m)
                    IF ( ALLOCATED( surf_lsm_h(l)%nrsws ) )                                            &
-                      surf_h(0)%nrsws(mm(0)) = surf_lsm_h(l)%nrsws(m)
+                      surf_h(l)%nrsws(mm(l)) = surf_lsm_h(l)%nrsws(m)
                    IF ( ALLOCATED( surf_lsm_h(l)%sasws ) )                                            &
-                     surf_h(0)%sasws(mm(0)) = surf_lsm_h(l)%sasws(m)
+                     surf_h(l)%sasws(mm(l)) = surf_lsm_h(l)%sasws(m)
 
                    mm(l) = mm(l) + 1
@@ -3229,27 +3232,27 @@
                 DO  m = surf_usm_h(l)%start_index(j,i), surf_usm_h(l)%end_index(j,i)
                    IF ( ALLOCATED( surf_usm_h(l)%us ) )                                               &
-                      surf_h(0)%us(mm(0)) = surf_usm_h(l)%us(m)
+                      surf_h(l)%us(mm(l)) = surf_usm_h(l)%us(m)
                    IF ( ALLOCATED( surf_usm_h(l)%ts ) )                                               &
-                      surf_h(0)%ts(mm(0)) = surf_usm_h(l)%ts(m)
+                      surf_h(l)%ts(mm(l)) = surf_usm_h(l)%ts(m)
                    IF ( ALLOCATED( surf_usm_h(l)%qs ) )                                               &
-                      surf_h(0)%qs(mm(0)) = surf_usm_h(l)%qs(m)
+                      surf_h(l)%qs(mm(l)) = surf_usm_h(l)%qs(m)
                    IF ( ALLOCATED( surf_usm_h(l)%ss ) )                                               &
-                      surf_h(0)%ss(mm(0)) = surf_usm_h(l)%ss(m)
+                      surf_h(l)%ss(mm(l)) = surf_usm_h(l)%ss(m)
                    IF ( ALLOCATED( surf_usm_h(l)%qcs ) )                                              &
-                      surf_h(0)%qcs(mm(0)) = surf_usm_h(l)%qcs(m)
+                      surf_h(l)%qcs(mm(l)) = surf_usm_h(l)%qcs(m)
                    IF ( ALLOCATED( surf_usm_h(l)%ncs ) )                                              &
-                      surf_h(0)%ncs(mm(0)) = surf_usm_h(l)%ncs(m)
+                      surf_h(l)%ncs(mm(l)) = surf_usm_h(l)%ncs(m)
                    IF ( ALLOCATED( surf_usm_h(l)%qis ) )                                              &
-                      surf_h(0)%qis(mm(0)) = surf_usm_h(l)%qis(m)
+                      surf_h(l)%qis(mm(l)) = surf_usm_h(l)%qis(m)
                    IF ( ALLOCATED( surf_usm_h(l)%nis ) )                                              &
-                      surf_h(0)%nis(mm(0)) = surf_usm_h(l)%nis(m)
+                      surf_h(l)%nis(mm(l)) = surf_usm_h(l)%nis(m)
                    IF ( ALLOCATED( surf_usm_h(l)%qrs ) )                                              &
-                      surf_h(0)%qrs(mm(0)) = surf_usm_h(l)%qrs(m)
+                      surf_h(l)%qrs(mm(l)) = surf_usm_h(l)%qrs(m)
                    IF ( ALLOCATED( surf_usm_h(l)%nrs ) )                                              &
-                      surf_h(0)%nrs(mm(0)) = surf_usm_h(l)%nrs(m)
+                      surf_h(l)%nrs(mm(l)) = surf_usm_h(l)%nrs(m)
                    IF ( ALLOCATED( surf_usm_h(l)%ol ) )                                               &
-                      surf_h(0)%ol(mm(0)) = surf_usm_h(l)%ol(m)
+                      surf_h(l)%ol(mm(l)) = surf_usm_h(l)%ol(m)
                    IF ( ALLOCATED( surf_usm_h(l)%rib ) )                                              &
-                      surf_h(0)%rib(mm(0)) = surf_usm_h(l)%rib(m)
+                      surf_h(l)%rib(mm(l)) = surf_usm_h(l)%rib(m)
                    IF ( ALLOCATED( surf_usm_h(l)%pt_surface ) )                                       &
                       surf_h(l)%pt_surface(mm(l)) = surf_usm_h(l)%pt_surface(m)
@@ -3259,37 +3262,37 @@
                       surf_h(l)%vpt_surface(mm(l)) = surf_usm_h(l)%vpt_surface(m)
                    IF ( ALLOCATED( surf_usm_h(l)%usws ) )                                             &
-                      surf_h(0)%usws(mm(0)) = surf_usm_h(l)%usws(m)
+                      surf_h(l)%usws(mm(l)) = surf_usm_h(l)%usws(m)
                    IF ( ALLOCATED( surf_usm_h(l)%vsws ) )                                             &
-                      surf_h(0)%vsws(mm(0)) = surf_usm_h(l)%vsws(m)
+                      surf_h(l)%vsws(mm(l)) = surf_usm_h(l)%vsws(m)
                    IF ( ALLOCATED( surf_usm_h(l)%shf ) )                                              &
-                      surf_h(0)%shf(mm(0)) = surf_usm_h(l)%shf(m)
+                      surf_h(l)%shf(mm(l)) = surf_usm_h(l)%shf(m)
                    IF ( ALLOCATED( surf_usm_h(l)%qsws ) )                                             &
-                      surf_h(0)%qsws(mm(0)) = surf_usm_h(l)%qsws(m)
+                      surf_h(l)%qsws(mm(l)) = surf_usm_h(l)%qsws(m)
                    IF ( ALLOCATED( surf_usm_h(l)%ssws ) )                                             &
-                      surf_h(0)%ssws(mm(0)) = surf_usm_h(l)%ssws(m)
+                      surf_h(l)%ssws(mm(l)) = surf_usm_h(l)%ssws(m)
                    IF ( ALLOCATED( surf_usm_h(l)%css ) )  THEN
                       DO lsp = 1, nvar
-                         surf_h(0)%css(lsp,mm(0)) = surf_usm_h(l)%css(lsp,m)
+                         surf_h(l)%css(lsp,mm(l)) = surf_usm_h(l)%css(lsp,m)
                       ENDDO
                    ENDIF
                    IF ( ALLOCATED( surf_usm_h(l)%cssws ) )  THEN
                       DO lsp = 1, nvar
-                         surf_h(0)%cssws(lsp,mm(0)) = surf_usm_h(l)%cssws(lsp,m)
+                         surf_h(l)%cssws(lsp,mm(l)) = surf_usm_h(l)%cssws(lsp,m)
                       ENDDO
                    ENDIF
                    IF ( ALLOCATED( surf_usm_h(l)%qcsws ) )                                            &
-                      surf_h(0)%qcsws(mm(0)) = surf_usm_h(l)%qcsws(m)
+                      surf_h(l)%qcsws(mm(l)) = surf_usm_h(l)%qcsws(m)
                    IF ( ALLOCATED( surf_usm_h(l)%qisws ) )                                            &
-                      surf_h(0)%qisws(mm(0)) = surf_usm_h(l)%qisws(m)
+                      surf_h(l)%qisws(mm(l)) = surf_usm_h(l)%qisws(m)
                    IF ( ALLOCATED( surf_usm_h(l)%qrsws ) )                                            &
-                      surf_h(0)%qrsws(mm(0)) = surf_usm_h(l)%qrsws(m)
+                      surf_h(l)%qrsws(mm(l)) = surf_usm_h(l)%qrsws(m)
                    IF ( ALLOCATED( surf_usm_h(l)%ncsws ) )                                            &
-                      surf_h(0)%ncsws(mm(0))   = surf_usm_h(l)%ncsws(m)
+                      surf_h(l)%ncsws(mm(l))   = surf_usm_h(l)%ncsws(m)
                    IF ( ALLOCATED( surf_usm_h(l)%nrsws ) )                                            &
-                      surf_h(0)%nrsws(mm(0)) = surf_usm_h(l)%nrsws(m)
+                      surf_h(l)%nrsws(mm(l)) = surf_usm_h(l)%nrsws(m)
                    IF ( ALLOCATED( surf_usm_h(l)%nisws ) )                                            &
-                      surf_h(0)%nisws(mm(0)) = surf_usm_h(l)%nisws(m)
+                      surf_h(l)%nisws(mm(l)) = surf_usm_h(l)%nisws(m)
                    IF ( ALLOCATED( surf_usm_h(l)%sasws ) )                                            &
-                     surf_h(0)%sasws(mm(0)) = surf_usm_h(l)%sasws(m)
+                     surf_h(l)%sasws(mm(l)) = surf_usm_h(l)%sasws(m)
 
                    mm(l) = mm(l) + 1
