Index: /palm/trunk/SOURCE/indoor_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/indoor_model_mod.f90	(revision 4849)
+++ /palm/trunk/SOURCE/indoor_model_mod.f90	(revision 4850)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Enable restart mechanism for previous indoor temperature
+!
+! 4843 2021-01-15 15:22:11Z raasch
 ! local namelist parameter added to switch off the module although the respective module namelist
 ! appears in the namelist file
@@ -590,4 +593,5 @@
     INTEGER(iwp) ::  bt          !< local building type
     INTEGER(iwp) ::  day_of_year !< day of the year
+    INTEGER(iwp) ::  fa          !< running index for facade elements of each building
     INTEGER(iwp) ::  i           !< running index along x-direction
     INTEGER(iwp) ::  j           !< running index along y-direction
@@ -1185,15 +1189,45 @@
 !
 !-- Initialize indoor temperature. Actually only for output at initial state.
-    DO  nb = 1, num_build
-       IF ( buildings(nb)%on_pe )  THEN
-          buildings(nb)%t_in(:) = initial_indoor_temperature
-
-!
-!--       (after first loop, use theta_m_t as theta_m_t_prev)
-          buildings(nb)%theta_m_t_prev_h(:) = initial_indoor_temperature
-          buildings(nb)%theta_m_t_prev_v(:) = initial_indoor_temperature
-
-       ENDIF
-    ENDDO
+    IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
+       DO  nb = 1, num_build
+          IF ( buildings(nb)%on_pe )  THEN
+             buildings(nb)%t_in(:) = initial_indoor_temperature
+
+!
+!--          (after first loop, use theta_m_t as theta_m_t_prev)
+             buildings(nb)%theta_m_t_prev_h(:) = initial_indoor_temperature
+             buildings(nb)%theta_m_t_prev_v(:) = initial_indoor_temperature
+
+          ENDIF
+       ENDDO
+!
+!-- Initialize indoor temperature at previous timestep.
+    ELSE
+       DO  nb = 1, num_build
+          IF ( buildings(nb)%on_pe )  THEN
+!
+!--          Mean indoor temperature can be initialized with initial value. This is just
+!--          used for output.
+             buildings(nb)%t_in(:) = initial_indoor_temperature
+!
+!--          Initialize theta_m_t_prev arrays. The respective data during the restart mechanism
+!--          is stored on the surface-data array.
+             DO  fa = 1, buildings(nb)%num_facades_per_building_h_l
+!
+!--             Determine indices where corresponding surface-type information is stored.
+                l = buildings(nb)%l_h(fa)
+                m = buildings(nb)%m_h(fa)
+                buildings(nb)%theta_m_t_prev_h(fa) = surf_usm_h(l)%t_prev(m)
+             ENDDO
+             DO  fa = 1, buildings(nb)%num_facades_per_building_v_l
+!
+!--             Determine indices where corresponding surface-type information is stored.
+                l = buildings(nb)%l_v(fa)
+                m = buildings(nb)%m_v(fa)
+                buildings(nb)%theta_m_t_prev_v(fa) = surf_usm_v(l)%t_prev(m)
+             ENDDO
+          ENDIF
+       ENDDO
+    ENDIF
 
     CALL location_message( 'initializing indoor model', 'finished' )
@@ -1303,5 +1337,5 @@
           ENDIF
 !
-!--       Initialize/reset indoor temperature
+!--       Initialize/reset indoor temperature - note, this is only for output
           buildings(nb)%t_in_l = 0.0_wp
 !
@@ -1548,6 +1582,9 @@
                               buildings(nb)%params_waste_heat_h * heating_on +                     &
                               buildings(nb)%params_waste_heat_c * cooling_on )                     &
-                            ) / facade_element_area                                             !< [W/m2] , observe the directional
-                                                                                                !< convention in PALM!
+                            ) / facade_element_area  !< [W/m2] , observe the directional convention in PALM!
+!
+!--          Store waste heat and previous previous indoor temperature on surface-data type.
+!--          These will be used in the urban-surface model.
+             surf_usm_h(l)%t_prev(m) = buildings(nb)%theta_m_t_prev_h(fa)
              surf_usm_h(l)%waste_heat(m) = q_waste_heat
           ENDDO !< Horizontal surfaces loop
@@ -1559,4 +1596,5 @@
              l = buildings(nb)%l_v(fa)
              m = buildings(nb)%m_v(fa)
+
 !
 !--          During spinup set window fraction to zero and add these to wall fraction.
@@ -1805,6 +1843,9 @@
              q_waste_heat = ( phi_hc_nd * ( buildings(nb)%params_waste_heat_h * heating_on +       &
                                             buildings(nb)%params_waste_heat_c * cooling_on )       &
-                                                    ) / facade_element_area  !< [W/m2] , observe the directional convention in
-                                                                             !< PALM!
+                            ) / facade_element_area  !< [W/m2] , observe the directional convention in PALM!
+!
+!--          Store waste heat and previous previous indoor temperature on surface-data type.
+!--          These will be used in the urban-surface model.
+             surf_usm_v(l)%t_prev(m)     = buildings(nb)%theta_m_t_prev_v(fa)
              surf_usm_v(l)%waste_heat(m) = q_waste_heat
           ENDDO !< Vertical surfaces loop
Index: /palm/trunk/SOURCE/surface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/surface_mod.f90	(revision 4849)
+++ /palm/trunk/SOURCE/surface_mod.f90	(revision 4850)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! +t_prev
+!
+! 4829 2021-01-06 10:11:39Z suehring
 ! Bugfix in creating error-message string
 !
@@ -418,4 +421,5 @@
 
 !--    Indoor model variables
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_prev      !< indoor temperature for facade element
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  waste_heat  !< waste heat
 !
Index: /palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 4849)
+++ /palm/trunk/SOURCE/urban_surface_mod.f90	(revision 4850)
@@ -27,4 +27,8 @@
 ! -----------------
 ! $Id$
+! - Add restart data for previous indoor temperature
+! - Bugfix in mpi-io restart mechanism for waste-heat flux
+!
+! 4843 2021-01-15 15:22:11Z raasch
 ! local namelist parameter added to switch off the module although the respective module namelist
 ! appears in the namelist file
@@ -325,10 +329,9 @@
 !> Further work:
 !> -------------
-!> @todo Revise sorting of building_pars
 !> @todo Revise initialization when building_pars / building_surface_pars are provided -
 !>       intialization is not consistent to building_pars
 !> @todo Revise flux conversion in energy-balance solver
 !> @todo Check divisions in wtend (etc.) calculations for possible division by zero, e.g. in case
-!> fraq(0,m) + fraq(1,m) = 0?!
+!>       fraq(0,m) + fraq(1,m) = 0?!
 !> @todo Use unit 90 for OPEN/CLOSE of input files (FK)
 !--------------------------------------------------------------------------------------------------!
@@ -1012,9 +1015,13 @@
     IF ( indoor_model )  THEN
        DO  l = 0, 1
+          ALLOCATE ( surf_usm_h(l)%t_prev(1:surf_usm_h(l)%ns)     )
           ALLOCATE ( surf_usm_h(l)%waste_heat(1:surf_usm_h(l)%ns) )
+          surf_usm_h(l)%t_prev     = 0.0_wp
           surf_usm_h(l)%waste_heat = 0.0_wp
        ENDDO
        DO  l = 0, 3
+          ALLOCATE ( surf_usm_v(l)%t_prev(1:surf_usm_v(l)%ns)     )
           ALLOCATE ( surf_usm_v(l)%waste_heat(1:surf_usm_v(l)%ns) )
+          surf_usm_v(l)%t_prev     = 0.0_wp
           surf_usm_v(l)%waste_heat = 0.0_wp
        ENDDO
@@ -5910,4 +5917,5 @@
     TYPE( surf_type_1d_usm ), DIMENSION(0:1), SAVE ::  tmp_surf_green_h   !<
     TYPE( surf_type_1d_usm ), DIMENSION(0:1), SAVE ::  tmp_surf_mliq_h    !<
+    TYPE( surf_type_1d_usm ), DIMENSION(0:3), SAVE ::  tmp_surf_t_prev_h  !<
     TYPE( surf_type_1d_usm ), DIMENSION(0:1), SAVE ::  tmp_surf_wall_h    !<
     TYPE( surf_type_1d_usm ), DIMENSION(0:1), SAVE ::  tmp_surf_waste_h   !<
@@ -5919,4 +5927,5 @@
 
     TYPE( surf_type_1d_usm ), DIMENSION(0:3), SAVE ::  tmp_surf_green_v   !<
+    TYPE( surf_type_1d_usm ), DIMENSION(0:3), SAVE ::  tmp_surf_t_prev_v  !<
     TYPE( surf_type_1d_usm ), DIMENSION(0:3), SAVE ::  tmp_surf_wall_v    !<
     TYPE( surf_type_1d_usm ), DIMENSION(0:3), SAVE ::  tmp_surf_waste_v   !<
@@ -5929,5 +5938,4 @@
 
     found = .TRUE.
-
 
     SELECT CASE ( restart_string(1:length) )
@@ -5946,4 +5954,5 @@
                 IF ( ALLOCATED( tmp_surf_mliq_h(l)%val) )     DEALLOCATE( tmp_surf_mliq_h(l)%val )
                 IF ( ALLOCATED( tmp_surf_waste_h(l)%val) )    DEALLOCATE( tmp_surf_waste_h(l)%val )
+                IF ( ALLOCATED( tmp_surf_t_prev_h(l)%val) )   DEALLOCATE( tmp_surf_t_prev_h(l)%val )
              ENDDO
 
@@ -5961,4 +5970,5 @@
                 ALLOCATE( tmp_surf_mliq_h(l)%val(1:ns_h_on_file_usm(l)) )
                 ALLOCATE( tmp_surf_waste_h(l)%val(1:ns_h_on_file_usm(l)) )
+                ALLOCATE( tmp_surf_t_prev_h(l)%val(1:ns_h_on_file_usm(l)) )
              ENDDO
 
@@ -5977,4 +5987,5 @@
                 IF ( ALLOCATED( tmp_green_v(l)%val ) )        DEALLOCATE( tmp_green_v(l)%val )
                 IF ( ALLOCATED( tmp_surf_waste_v(l)%val ) )   DEALLOCATE( tmp_surf_waste_v(l)%val )
+                IF ( ALLOCATED( tmp_surf_t_prev_v(l)%val ) )  DEALLOCATE( tmp_surf_t_prev_v(l)%val )
              ENDDO
 
@@ -5991,4 +6002,5 @@
                 ALLOCATE( tmp_green_v(l)%val(nzb_wall:nzt_wall+1, 1:ns_v_on_file_usm(l) ) )
                 ALLOCATE( tmp_surf_waste_v(l)%val(1:ns_v_on_file_usm(l)) )
+                ALLOCATE( tmp_surf_t_prev_v(l)%val(1:ns_v_on_file_usm(l)) )
              ENDDO
 
@@ -6019,9 +6031,9 @@
        CASE ( 't_surf_wall_h(0)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_wall_h_1(0)%val ) )                                       &
+             IF ( .NOT.  ALLOCATED( t_surf_wall_h_1(0)%val ) )                                     &
                 ALLOCATE( t_surf_wall_h_1(0)%val(1:surf_usm_h(0)%ns) )
              READ ( 13 )  tmp_surf_wall_h(0)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_wall_h_1(0)%val, tmp_surf_wall_h(0)%val,               &
+          CALL surface_restore_elements( t_surf_wall_h_1(0)%val, tmp_surf_wall_h(0)%val,           &
                                          surf_usm_h(0)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6030,9 +6042,9 @@
        CASE ( 't_surf_wall_h(1)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_wall_h_1(1)%val ) )                                       &
+             IF ( .NOT.  ALLOCATED( t_surf_wall_h_1(1)%val ) )                                     &
                 ALLOCATE( t_surf_wall_h_1(1)%val(1:surf_usm_h(1)%ns) )
              READ ( 13 )  tmp_surf_wall_h(1)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_wall_h_1(1)%val, tmp_surf_wall_h(1)%val,               &
+          CALL surface_restore_elements( t_surf_wall_h_1(1)%val, tmp_surf_wall_h(1)%val,           &
                                          surf_usm_h(1)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6041,9 +6053,9 @@
        CASE ( 't_surf_wall_v(0)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_wall_v_1(0)%val ) )                                       &
+             IF ( .NOT.  ALLOCATED( t_surf_wall_v_1(0)%val ) )                                     &
                 ALLOCATE( t_surf_wall_v_1(0)%val(1:surf_usm_v(0)%ns) )
              READ ( 13 )  tmp_surf_wall_v(0)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_wall_v_1(0)%val, tmp_surf_wall_v(0)%val,               &
+          CALL surface_restore_elements( t_surf_wall_v_1(0)%val, tmp_surf_wall_v(0)%val,           &
                                          surf_usm_v(0)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6052,9 +6064,9 @@
        CASE ( 't_surf_wall_v(1)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_wall_v_1(1)%val ) )                                       &
+             IF ( .NOT.  ALLOCATED( t_surf_wall_v_1(1)%val ) )                                     &
                 ALLOCATE( t_surf_wall_v_1(1)%val(1:surf_usm_v(1)%ns) )
              READ ( 13 )  tmp_surf_wall_v(1)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_wall_v_1(1)%val, tmp_surf_wall_v(1)%val,               &
+          CALL surface_restore_elements( t_surf_wall_v_1(1)%val, tmp_surf_wall_v(1)%val,           &
                                          surf_usm_v(1)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6063,9 +6075,9 @@
        CASE ( 't_surf_wall_v(2)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_wall_v_1(2)%val ) )                                       &
+             IF ( .NOT.  ALLOCATED( t_surf_wall_v_1(2)%val ) )                                     &
                 ALLOCATE( t_surf_wall_v_1(2)%val(1:surf_usm_v(2)%ns) )
              READ ( 13 )  tmp_surf_wall_v(2)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_wall_v_1(2)%val, tmp_surf_wall_v(2)%val,               &
+          CALL surface_restore_elements( t_surf_wall_v_1(2)%val, tmp_surf_wall_v(2)%val,           &
                                          surf_usm_v(2)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6074,9 +6086,9 @@
        CASE ( 't_surf_wall_v(3)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_wall_v_1(3)%val ) )                                       &
+             IF ( .NOT.  ALLOCATED( t_surf_wall_v_1(3)%val ) )                                     &
                 ALLOCATE( t_surf_wall_v_1(3)%val(1:surf_usm_v(3)%ns) )
              READ ( 13 )  tmp_surf_wall_v(3)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_wall_v_1(3)%val, tmp_surf_wall_v(3)%val,               &
+          CALL surface_restore_elements( t_surf_wall_v_1(3)%val, tmp_surf_wall_v(3)%val,           &
                                          surf_usm_v(3)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6085,9 +6097,9 @@
        CASE ( 't_surf_window_h(0)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_window_h_1(0)%val ) )                                     &
+             IF ( .NOT.  ALLOCATED( t_surf_window_h_1(0)%val ) )                                   &
                 ALLOCATE( t_surf_window_h_1(0)%val(1:surf_usm_h(0)%ns) )
              READ ( 13 )  tmp_surf_window_h(0)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_window_h_1(0)%val, tmp_surf_window_h(0)%val,           &
+          CALL surface_restore_elements( t_surf_window_h_1(0)%val, tmp_surf_window_h(0)%val,       &
                                          surf_usm_h(0)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6096,9 +6108,9 @@
        CASE ( 't_surf_window_h(1)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_window_h_1(1)%val ) )                                     &
+             IF ( .NOT.  ALLOCATED( t_surf_window_h_1(1)%val ) )                                   &
                 ALLOCATE( t_surf_window_h_1(1)%val(1:surf_usm_h(1)%ns) )
              READ ( 13 )  tmp_surf_window_h(1)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_window_h_1(1)%val, tmp_surf_window_h(1)%val,           &
+          CALL surface_restore_elements( t_surf_window_h_1(1)%val, tmp_surf_window_h(1)%val,       &
                                          surf_usm_h(1)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6107,9 +6119,9 @@
        CASE ( 't_surf_window_v(0)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_window_v_1(0)%val ) )                                     &
+             IF ( .NOT.  ALLOCATED( t_surf_window_v_1(0)%val ) )                                   &
                 ALLOCATE( t_surf_window_v_1(0)%val(1:surf_usm_v(0)%ns) )
              READ ( 13 )  tmp_surf_window_v(0)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_window_v_1(0)%val, tmp_surf_window_v(0)%val,           &
+          CALL surface_restore_elements( t_surf_window_v_1(0)%val, tmp_surf_window_v(0)%val,       &
                                          surf_usm_v(0)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6151,10 +6163,10 @@
        CASE ( 't_surf_green_h(0)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_green_h_1(0)%val ) )                                      &
+             IF ( .NOT.  ALLOCATED( t_surf_green_h_1(0)%val ) )                                    &
                 ALLOCATE( t_surf_green_h_1(0)%val(1:surf_usm_h(0)%ns) )
              READ ( 13 )  tmp_surf_green_h(0)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_green_h_1(0)%val, tmp_surf_green_h(0)%val,             &
-                                         surf_usm_h(0)%start_index, start_index_on_file,         &
+          CALL surface_restore_elements( t_surf_green_h_1(0)%val, tmp_surf_green_h(0)%val,         &
+                                         surf_usm_h(0)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
                                          nys_on_file, nyn_on_file, nxl_on_file, nxr_on_file )
@@ -6162,10 +6174,10 @@
        CASE ( 't_surf_green_h(1)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_green_h_1(1)%val ) )                                      &
+             IF ( .NOT.  ALLOCATED( t_surf_green_h_1(1)%val ) )                                    &
                 ALLOCATE( t_surf_green_h_1(1)%val(1:surf_usm_h(1)%ns) )
              READ ( 13 )  tmp_surf_green_h(1)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_green_h_1(1)%val, tmp_surf_green_h(1)%val,             &
-                                         surf_usm_h(1)%start_index, start_index_on_file,         &
+          CALL surface_restore_elements( t_surf_green_h_1(1)%val, tmp_surf_green_h(1)%val,         &
+                                         surf_usm_h(1)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
                                          nys_on_file, nyn_on_file, nxl_on_file, nxr_on_file )
@@ -6173,9 +6185,9 @@
        CASE ( 't_surf_green_v(0)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_green_v_1(0)%val ) )                                      &
+             IF ( .NOT.  ALLOCATED( t_surf_green_v_1(0)%val ) )                                    &
                 ALLOCATE( t_surf_green_v_1(0)%val(1:surf_usm_v(0)%ns) )
              READ ( 13 )  tmp_surf_green_v(0)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_green_v_1(0)%val, tmp_surf_green_v(0)%val,             &
+          CALL surface_restore_elements( t_surf_green_v_1(0)%val, tmp_surf_green_v(0)%val,         &
                                          surf_usm_v(0)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6184,9 +6196,9 @@
        CASE ( 't_surf_green_v(1)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_green_v_1(1)%val ) )                                      &
+             IF ( .NOT.  ALLOCATED( t_surf_green_v_1(1)%val ) )                                    &
                 ALLOCATE( t_surf_green_v_1(1)%val(1:surf_usm_v(1)%ns) )
              READ ( 13 )  tmp_surf_green_v(1)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_green_v_1(1)%val, tmp_surf_green_v(1)%val,             &
+          CALL surface_restore_elements( t_surf_green_v_1(1)%val, tmp_surf_green_v(1)%val,         &
                                          surf_usm_v(1)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6195,9 +6207,9 @@
        CASE ( 't_surf_green_v(2)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_green_v_1(2)%val ) )                                      &
+             IF ( .NOT.  ALLOCATED( t_surf_green_v_1(2)%val ) )                                    &
                 ALLOCATE( t_surf_green_v_1(2)%val(1:surf_usm_v(2)%ns) )
              READ ( 13 )  tmp_surf_green_v(2)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_green_v_1(2)%val, tmp_surf_green_v(2)%val,             &
+          CALL surface_restore_elements( t_surf_green_v_1(2)%val, tmp_surf_green_v(2)%val,         &
                                          surf_usm_v(2)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6206,9 +6218,9 @@
        CASE ( 't_surf_green_v(3)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_surf_green_v_1(3)%val ) )                                      &
+             IF ( .NOT.  ALLOCATED( t_surf_green_v_1(3)%val ) )                                    &
                 ALLOCATE( t_surf_green_v_1(3)%val(1:surf_usm_v(3)%ns) )
              READ ( 13 )  tmp_surf_green_v(3)%val
           ENDIF
-          CALL surface_restore_elements( t_surf_green_v_1(3)%val, tmp_surf_green_v(3)%val,             &
+          CALL surface_restore_elements( t_surf_green_v_1(3)%val, tmp_surf_green_v(3)%val,         &
                                          surf_usm_v(3)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6243,5 +6255,5 @@
              READ ( 13 )  tmp_surf_waste_h(0)%val
           ENDIF
-          CALL surface_restore_elements( surf_usm_h(0)%waste_heat, tmp_surf_waste_h(0)%val,          &
+          CALL surface_restore_elements( surf_usm_h(0)%waste_heat, tmp_surf_waste_h(0)%val,        &
                                          surf_usm_h(0)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6254,5 +6266,5 @@
              READ ( 13 )  tmp_surf_waste_h(1)%val
           ENDIF
-          CALL surface_restore_elements( surf_usm_h(1)%waste_heat, tmp_surf_waste_h(1)%val,          &
+          CALL surface_restore_elements( surf_usm_h(1)%waste_heat, tmp_surf_waste_h(1)%val,        &
                                          surf_usm_h(1)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6266,5 +6278,5 @@
              READ ( 13 )  tmp_surf_waste_v(0)%val
           ENDIF
-          CALL surface_restore_elements( surf_usm_v(0)%waste_heat, tmp_surf_waste_v(0)%val,          &
+          CALL surface_restore_elements( surf_usm_v(0)%waste_heat, tmp_surf_waste_v(0)%val,        &
                                          surf_usm_v(0)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6277,5 +6289,5 @@
              READ ( 13 )  tmp_surf_waste_v(1)%val
           ENDIF
-          CALL surface_restore_elements( surf_usm_v(1)%waste_heat, tmp_surf_waste_v(1)%val,          &
+          CALL surface_restore_elements( surf_usm_v(1)%waste_heat, tmp_surf_waste_v(1)%val,        &
                                          surf_usm_v(1)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6288,5 +6300,5 @@
              READ ( 13 )  tmp_surf_waste_v(2)%val
           ENDIF
-          CALL surface_restore_elements( surf_usm_v(2)%waste_heat, tmp_surf_waste_v(2)%val,          &
+          CALL surface_restore_elements( surf_usm_v(2)%waste_heat, tmp_surf_waste_v(2)%val,        &
                                          surf_usm_v(2)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6299,82 +6311,149 @@
              READ ( 13 )  tmp_surf_waste_v(3)%val
           ENDIF
-          CALL surface_restore_elements( surf_usm_v(3)%waste_heat, tmp_surf_waste_v(3)%val,          &
+          CALL surface_restore_elements( surf_usm_v(3)%waste_heat, tmp_surf_waste_v(3)%val,        &
                                          surf_usm_v(3)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
                                          nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
 
-       CASE ( 't_wall_h(0)' )
+       CASE ( 't_prev_h(0)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_wall_h_1(0)%val ) )                                            &
-                ALLOCATE( t_wall_h_1(0)%val(nzb_wall:nzt_wall+1, 1:surf_usm_h(0)%ns) )
-             READ ( 13 )  tmp_wall_h(0)%val
-          ENDIF
-          CALL surface_restore_elements( t_wall_h_1(0)%val, tmp_wall_h(0)%val,                         &
+             IF ( .NOT.  ALLOCATED( surf_usm_h(0)%t_prev ) )                                       &
+                ALLOCATE( surf_usm_h(0)%t_prev(1:surf_usm_h(0)%ns) )
+             READ ( 13 )  tmp_surf_t_prev_h(0)%val
+          ENDIF
+          CALL surface_restore_elements( surf_usm_h(0)%t_prev, tmp_surf_t_prev_h(0)%val,           &
                                          surf_usm_h(0)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
                                          nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
 
-       CASE ( 't_wall_h(1)' )
+       CASE ( 't_prev_h(1)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_wall_h_1(1)%val ) )                                            &
-                ALLOCATE( t_wall_h_1(1)%val(nzb_wall:nzt_wall+1, 1:surf_usm_h(1)%ns) )
-             READ ( 13 )  tmp_wall_h(1)%val
-          ENDIF
-          CALL surface_restore_elements( t_wall_h_1(1)%val, tmp_wall_h(1)%val,                         &
+             IF ( .NOT.  ALLOCATED( surf_usm_h(1)%t_prev ) )                                       &
+                ALLOCATE( surf_usm_h(1)%t_prev(1:surf_usm_h(1)%ns) )
+             READ ( 13 )  tmp_surf_t_prev_h(1)%val
+          ENDIF
+          CALL surface_restore_elements( surf_usm_h(1)%t_prev, tmp_surf_t_prev_h(1)%val,           &
                                          surf_usm_h(1)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
                                          nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
 
-       CASE ( 't_wall_v(0)' )
+
+       CASE ( 't_prev_v(0)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_wall_v_1(0)%val ) )                                            &
-                ALLOCATE( t_wall_v_1(0)%val(nzb_wall:nzt_wall+1, 1:surf_usm_v(0)%ns) )
-             READ ( 13 )  tmp_wall_v(0)%val
-          ENDIF
-          CALL surface_restore_elements( t_wall_v_1(0)%val, tmp_wall_v(0)%val,                         &
+             IF ( .NOT.  ALLOCATED( surf_usm_v(0)%t_prev ) )                                       &
+                ALLOCATE( surf_usm_v(0)%t_prev(1:surf_usm_v(0)%ns) )
+             READ ( 13 )  tmp_surf_t_prev_v(0)%val
+          ENDIF
+          CALL surface_restore_elements( surf_usm_v(0)%t_prev, tmp_surf_t_prev_v(0)%val,           &
                                          surf_usm_v(0)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
                                          nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
 
-       CASE ( 't_wall_v(1)' )
+       CASE ( 't_prev_v(1)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_wall_v_1(1)%val ) )                                            &
-                ALLOCATE( t_wall_v_1(1)%val(nzb_wall:nzt_wall+1, 1:surf_usm_v(1)%ns) )
-             READ ( 13 )  tmp_wall_v(1)%val
-          ENDIF
-          CALL surface_restore_elements( t_wall_v_1(1)%val, tmp_wall_v(1)%val,                         &
+             IF ( .NOT.  ALLOCATED( surf_usm_v(1)%t_prev ) )                                       &
+                ALLOCATE( surf_usm_v(1)%t_prev(1:surf_usm_v(1)%ns) )
+             READ ( 13 )  tmp_surf_t_prev_v(1)%val
+          ENDIF
+          CALL surface_restore_elements( surf_usm_v(1)%t_prev, tmp_surf_t_prev_v(1)%val,           &
                                          surf_usm_v(1)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
                                          nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
 
-       CASE ( 't_wall_v(2)' )
+       CASE ( 't_prev_v(2)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_wall_v_1(2)%val ) )                                            &
-                ALLOCATE( t_wall_v_1(2)%val(nzb_wall:nzt_wall+1, 1:surf_usm_v(2)%ns) )
-             READ ( 13 )  tmp_wall_v(2)%val
-          ENDIF
-          CALL surface_restore_elements( t_wall_v_1(2)%val, tmp_wall_v(2)%val,                         &
+             IF ( .NOT.  ALLOCATED( surf_usm_v(2)%t_prev ) )                                       &
+                ALLOCATE( surf_usm_v(2)%t_prev(1:surf_usm_v(2)%ns) )
+             READ ( 13 )  tmp_surf_t_prev_v(2)%val
+          ENDIF
+          CALL surface_restore_elements( surf_usm_v(2)%t_prev, tmp_surf_t_prev_v(2)%val,           &
                                          surf_usm_v(2)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
                                          nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
 
-       CASE ( 't_wall_v(3)' )
+       CASE ( 't_prev_v(3)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_wall_v_1(3)%val ) )                                            &
-                ALLOCATE( t_wall_v_1(3)%val(nzb_wall:nzt_wall+1, 1:surf_usm_v(3)%ns) )
-             READ ( 13 )  tmp_wall_v(3)%val
-          ENDIF
-          CALL surface_restore_elements( t_wall_v_1(3)%val, tmp_wall_v(3)%val,                         &
+             IF ( .NOT.  ALLOCATED( surf_usm_v(3)%t_prev ) )                                       &
+                ALLOCATE( surf_usm_v(3)%t_prev(1:surf_usm_v(3)%ns) )
+             READ ( 13 )  tmp_surf_t_prev_v(3)%val
+          ENDIF
+          CALL surface_restore_elements( surf_usm_v(3)%t_prev, tmp_surf_t_prev_v(3)%val,           &
                                          surf_usm_v(3)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
                                          nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
 
+       CASE ( 't_wall_h(0)' )
+          IF ( k == 1 )  THEN
+             IF ( .NOT.  ALLOCATED( t_wall_h_1(0)%val ) )                                          &
+                ALLOCATE( t_wall_h_1(0)%val(nzb_wall:nzt_wall+1, 1:surf_usm_h(0)%ns) )
+             READ ( 13 )  tmp_wall_h(0)%val
+          ENDIF
+          CALL surface_restore_elements( t_wall_h_1(0)%val, tmp_wall_h(0)%val,                     &
+                                         surf_usm_h(0)%start_index, start_index_on_file,           &
+                                         end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
+                                         nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
+
+       CASE ( 't_wall_h(1)' )
+          IF ( k == 1 )  THEN
+             IF ( .NOT.  ALLOCATED( t_wall_h_1(1)%val ) )                                          &
+                ALLOCATE( t_wall_h_1(1)%val(nzb_wall:nzt_wall+1, 1:surf_usm_h(1)%ns) )
+             READ ( 13 )  tmp_wall_h(1)%val
+          ENDIF
+          CALL surface_restore_elements( t_wall_h_1(1)%val, tmp_wall_h(1)%val,                     &
+                                         surf_usm_h(1)%start_index, start_index_on_file,           &
+                                         end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
+                                         nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
+
+       CASE ( 't_wall_v(0)' )
+          IF ( k == 1 )  THEN
+             IF ( .NOT.  ALLOCATED( t_wall_v_1(0)%val ) )                                          &
+                ALLOCATE( t_wall_v_1(0)%val(nzb_wall:nzt_wall+1, 1:surf_usm_v(0)%ns) )
+             READ ( 13 )  tmp_wall_v(0)%val
+          ENDIF
+          CALL surface_restore_elements( t_wall_v_1(0)%val, tmp_wall_v(0)%val,                     &
+                                         surf_usm_v(0)%start_index, start_index_on_file,           &
+                                         end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
+                                         nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
+
+       CASE ( 't_wall_v(1)' )
+          IF ( k == 1 )  THEN
+             IF ( .NOT.  ALLOCATED( t_wall_v_1(1)%val ) )                                          &
+                ALLOCATE( t_wall_v_1(1)%val(nzb_wall:nzt_wall+1, 1:surf_usm_v(1)%ns) )
+             READ ( 13 )  tmp_wall_v(1)%val
+          ENDIF
+          CALL surface_restore_elements( t_wall_v_1(1)%val, tmp_wall_v(1)%val,                     &
+                                         surf_usm_v(1)%start_index, start_index_on_file,           &
+                                         end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
+                                         nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
+
+       CASE ( 't_wall_v(2)' )
+          IF ( k == 1 )  THEN
+             IF ( .NOT.  ALLOCATED( t_wall_v_1(2)%val ) )                                          &
+                ALLOCATE( t_wall_v_1(2)%val(nzb_wall:nzt_wall+1, 1:surf_usm_v(2)%ns) )
+             READ ( 13 )  tmp_wall_v(2)%val
+          ENDIF
+          CALL surface_restore_elements( t_wall_v_1(2)%val, tmp_wall_v(2)%val,                     &
+                                         surf_usm_v(2)%start_index, start_index_on_file,           &
+                                         end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
+                                         nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
+
+       CASE ( 't_wall_v(3)' )
+          IF ( k == 1 )  THEN
+             IF ( .NOT.  ALLOCATED( t_wall_v_1(3)%val ) )                                          &
+                ALLOCATE( t_wall_v_1(3)%val(nzb_wall:nzt_wall+1, 1:surf_usm_v(3)%ns) )
+             READ ( 13 )  tmp_wall_v(3)%val
+          ENDIF
+          CALL surface_restore_elements( t_wall_v_1(3)%val, tmp_wall_v(3)%val,                     &
+                                         surf_usm_v(3)%start_index, start_index_on_file,           &
+                                         end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
+                                         nys_on_file, nyn_on_file, nxl_on_file,nxr_on_file )
+
        CASE ( 't_window_h(0)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_window_h_1(0)%val ) )                                               &
+             IF ( .NOT.  ALLOCATED( t_window_h_1(0)%val ) )                                        &
                 ALLOCATE( t_window_h_1(0)%val(nzb_wall:nzt_wall+1, 1:surf_usm_h(0)%ns) )
              READ ( 13 )  tmp_window_h(0)%val
           ENDIF
-          CALL surface_restore_elements( t_window_h_1(0)%val, tmp_window_h(0)%val,                     &
+          CALL surface_restore_elements( t_window_h_1(0)%val, tmp_window_h(0)%val,                 &
                                          surf_usm_h(0)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6383,9 +6462,9 @@
        CASE ( 't_window_h(1)' )
           IF ( k == 1 )  THEN
-             IF ( .NOT.  ALLOCATED( t_window_h_1(1)%val ) )                                               &
+             IF ( .NOT.  ALLOCATED( t_window_h_1(1)%val ) )                                        &
                 ALLOCATE( t_window_h_1(1)%val(nzb_wall:nzt_wall+1, 1:surf_usm_h(1)%ns) )
              READ ( 13 )  tmp_window_h(1)%val
           ENDIF
-          CALL surface_restore_elements( t_window_h_1(1)%val, tmp_window_h(1)%val,                     &
+          CALL surface_restore_elements( t_window_h_1(1)%val, tmp_window_h(1)%val,                 &
                                          surf_usm_h(1)%start_index, start_index_on_file,           &
                                          end_index_on_file, nxlc, nysc, nxlf, nxrf, nysf, nynf,    &
@@ -6561,12 +6640,15 @@
        CALL rrd_mpi_io_surface( 't_surf_green_h(' // dum // ')', t_surf_green_h_1(l)%val )
 
-       IF ( .NOT.  ALLOCATED( m_liq_usm_h_1(l)%val ) )                                            &
+       IF ( .NOT.  ALLOCATED( m_liq_usm_h_1(l)%val ) )                                             &
           ALLOCATE( m_liq_usm_h_1(l)%val(1:surf_usm_h(l)%ns) )
        CALL rrd_mpi_io_surface( 'm_liq_usm_h(' // dum // ')', m_liq_usm_h_1(l)%val )
 
        IF ( indoor_model )  THEN
-          IF ( .NOT.  ALLOCATED( surf_usm_h(l)%waste_heat ) )                                     &
+          IF ( .NOT.  ALLOCATED( surf_usm_h(l)%waste_heat ) )                                      &
              ALLOCATE( surf_usm_h(l)%waste_heat(1:surf_usm_h(l)%ns) )
           CALL rrd_mpi_io_surface( 'waste_heat_h(' // dum // ')', surf_usm_h(l)%waste_heat )
+          IF ( .NOT.  ALLOCATED( surf_usm_h(l)%t_prev ) )                                          &
+             ALLOCATE( surf_usm_h(l)%t_prev(1:surf_usm_h(l)%ns) )
+          CALL rrd_mpi_io_surface( 't_prev_h(' // dum // ')', surf_usm_h(l)%t_prev )
        ENDIF
 
@@ -6596,4 +6678,13 @@
           ALLOCATE( t_surf_green_v_1(l)%val(1:surf_usm_v(l)%ns) )
        CALL rrd_mpi_io_surface( 't_surf_green_v(' // dum // ')', t_surf_green_v_1(l)%val)
+
+       IF ( indoor_model )  THEN
+          IF ( .NOT.  ALLOCATED( surf_usm_v(l)%waste_heat ) )                                      &
+             ALLOCATE( surf_usm_v(l)%waste_heat(1:surf_usm_v(l)%ns) )
+          CALL rrd_mpi_io_surface( 'waste_heat_v(' // dum // ')', surf_usm_v(l)%waste_heat )
+          IF ( .NOT.  ALLOCATED( surf_usm_v(l)%t_prev ) )                                          &
+             ALLOCATE( surf_usm_v(l)%t_prev(1:surf_usm_v(l)%ns) )
+          CALL rrd_mpi_io_surface( 't_prev_v(' // dum // ')', surf_usm_v(l)%t_prev )
+       ENDIF
 
     ENDDO
@@ -7372,4 +7463,6 @@
              CALL wrd_write_string( 'waste_heat_h(' // dum // ')' )
              WRITE ( 14 )  surf_usm_h(l)%waste_heat
+             CALL wrd_write_string( 't_prev_h(' // dum // ')' )
+             WRITE ( 14 )  surf_usm_h(l)%t_prev
           ENDIF
        ENDDO
@@ -7397,4 +7490,6 @@
              CALL wrd_write_string( 'waste_heat_v(' // dum // ')' )
              WRITE ( 14 )  surf_usm_v(l)%waste_heat
+             CALL wrd_write_string( 't_prev_v(' // dum // ')' )
+             WRITE ( 14 )  surf_usm_v(l)%t_prev
           ENDIF
 
@@ -7466,5 +7561,6 @@
           CALL wrd_mpi_io_surface( 'm_liq_usm_h(' // dum // ')', m_liq_usm_h(l)%val )
           IF ( indoor_model )  THEN
-             CALL wrd_mpi_io_surface( 'waste_heat_h(' // dum // ')', surf_usm_h(l)%waste_heat ) ! NEED TO BE CHECKED!!!!!
+             CALL wrd_mpi_io_surface( 'waste_heat_h(' // dum // ')', surf_usm_h(l)%waste_heat )
+             CALL wrd_mpi_io_surface( 't_prev_h(' // dum // ')',     surf_usm_h(l)%t_prev     )
           ENDIF
 
@@ -7488,4 +7584,8 @@
           CALL wrd_mpi_io_surface( 't_surf_green_v(' // dum // ')', t_surf_green_v(l)%val )
 
+          IF ( indoor_model )  THEN
+             CALL wrd_mpi_io_surface( 'waste_heat_v(' // dum // ')', surf_usm_v(l)%waste_heat )
+             CALL wrd_mpi_io_surface( 't_prev_v(' // dum // ')',     surf_usm_v(l)%t_prev     )
+          ENDIF
        ENDDO
 
