Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 3468)
+++ palm/trunk/SOURCE/Makefile	(revision 3469)
@@ -25,4 +25,8 @@
 # -----------------
 # $Id$
+# Add indoor model (kanani, srissman, tlang),
+# minor formatting
+# 
+# 3467 2018-10-30 19:05:21Z suehring
 # Implementation of a new aerosol module salsa.
 # 
@@ -514,4 +518,9 @@
 	average_3d_data.f90 \
 	basic_constants_and_equations_mod.f90 \
+	biometeorology_mod.f90 \
+	biometeorology_ipt_mod.f90 \
+	biometeorology_pt_mod.f90 \
+	biometeorology_pet_mod.f90 \
+	biometeorology_utci_mod.f90 \
 	boundary_conds.f90 \
 	buoyancy.f90 \
@@ -553,9 +562,5 @@
 	gust_mod.f90 \
 	header.f90 \
-	biometeorology_mod.f90 \
-	biometeorology_ipt_mod.f90 \
-	biometeorology_pt_mod.f90 \
-	biometeorology_pet_mod.f90 \
-	biometeorology_utci_mod.f90 \
+	indoor_model_mod.f90 \
 	inflow_turbulence.f90 \
 	init_3d_model.f90 \
@@ -1080,4 +1085,12 @@
 	surface_mod.o \
 	virtual_flight_mod.o
+indoor_model_mod.o: \
+	cpulog_mod.o \
+	date_and_time_mod.o \
+	mod_kinds.o \
+	modules.o \
+	netcdf_data_input_mod.o \
+	surface_mod.o \
+	urban_surface_mod.o
 inflow_turbulence.o: \
 	cpulog_mod.o \
@@ -1093,4 +1106,5 @@
 	disturb_heatflux.o \
 	gust_mod.o \
+	indoor_model_mod.o \
 	land_surface_model_mod.o \
 	large_scale_forcing_nudging_mod.o \
@@ -1415,4 +1429,5 @@
 	date_and_time_mod.o \
 	gust_mod.o \
+	indoor_model_mod.o \
 	land_surface_model_mod.o \
 	model_1d_mod.o \
@@ -1708,4 +1723,5 @@
 	disturb_heatflux.o \
 	gust_mod.o \
+	indoor_model_mod.o \
 	interaction_droplets_ptq.o \
 	land_surface_model_mod.o \
Index: palm/trunk/SOURCE/indoor_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/indoor_model_mod.f90	(revision 3469)
+++ palm/trunk/SOURCE/indoor_model_mod.f90	(revision 3469)
@@ -0,0 +1,1424 @@
+!> @file indoor_model_mod.f90
+!--------------------------------------------------------------------------------!
+! This file is part of the PALM model system.
+!
+! PALM is free software: you can redistribute it and/or modify it under the
+! terms of the GNU General Public License as published by the Free Software
+! Foundation, either version 3 of the License, or (at your option) any later
+! version.
+!
+! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
+! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+!
+! You should have received a copy of the GNU General Public License along with
+! PALM. If not, see <http://www.gnu.org/licenses/>.
+!
+! Copyright 2018-2018 Leibniz Universitaet Hannover
+! Copyright 2018-2018 Hochschule Offenburg
+!--------------------------------------------------------------------------------!
+!
+! Current revisions:
+! -----------------
+! 
+! 
+! Former revisions:
+! -----------------
+! $Id$
+! Initial revision (tlang, suehring, kanani, srissman)
+! 
+! 
+!
+! Authors:
+! --------
+! @author Tobias Lang
+! @author Jens Pfafferott
+! @author Farah Kanani-Suehring
+! @author Matthias Suehring
+! @author Sascha RiÃmann
+!
+!
+! Description:
+! ------------
+!> <Description of the new module>
+!> Module for Indoor Climate Model (ICM)
+!> The module is based on the DIN EN ISO 13790 with simplified hour-based procedure.
+!> This model is a equivalent circuit diagram of a three-point RC-model (5R1C).
+!> This module differ between indoor-air temperature an average temperature of indoor surfaces which make it prossible to determine thermal comfort
+!> the heat transfer between indoor and outdoor is simplified 
+
+!> @todo Replace window_area_per_facade by %frac(1,m) for window
+!> @todo emissivity change for window blinds if solar_protection_on=1 
+!> @todo write datas in netcdf file as output data
+!> @todo reduce the building volume with netto ground surface to take respect costruction areas like walls and ceilings. Have effect on factor_a, factor_c, airchange and lambda_at
+!>
+!> @note Do we allow use of integer flags, or only logical flags? (concerns e.g. cooling_on, heating_on)
+!> @note How to write indoor temperature output to pt array?
+!>
+!> @bug  <Enter known bugs here>
+!------------------------------------------------------------------------------!
+ MODULE indoor_model_mod 
+
+    USE control_parameters,                                                    &
+        ONLY:  initializing_actions
+
+    USE kinds
+
+    USE surface_mod,                                                           &
+        ONLY:  surf_usm_h, surf_usm_v
+
+
+    IMPLICIT NONE
+
+!
+!-- Define data structure for buidlings.
+    TYPE build
+
+       INTEGER(iwp) ::  id                             !< building ID
+       INTEGER(iwp) ::  kb_min                         !< lowest vertical index of a building
+       INTEGER(iwp) ::  kb_max                         !< highest vertical index of a building
+       INTEGER(iwp) ::  num_facades_per_building_h     !< total number of horizontal facades elements
+       INTEGER(iwp) ::  num_facades_per_building_h_l   !< number of horizontal facade elements on local subdomain
+       INTEGER(iwp) ::  num_facades_per_building_v     !< total number of vertical facades elements
+       INTEGER(iwp) ::  num_facades_per_building_v_l   !< number of vertical facade elements on local subdomain
+
+       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  l_v            !< index array linking surface-element orientation index
+                                                                  !< for vertical surfaces with building 
+       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  m_h            !< index array linking surface-element index for
+                                                                  !< horizontal surfaces with building
+       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  m_v            !< index array linking surface-element index for 
+                                                                  !< vertical surfaces with building
+       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facade_h   !< number of horizontal facade elements per buidling 
+                                                                  !< and height level
+       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facade_v   !< number of vertical facades elements per buidling
+                                                                  !< and height level
+
+       LOGICAL ::  on_pe = .FALSE.   !< flag indicating whether a building with certain ID is on local subdomain
+
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_in       !< mean building indoor temperature, height dependent
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_in_l     !< mean building indoor temperature on local subdomain, height dependent
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  volume     !< total building volume, height dependent
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  vol_frac   !< fraction of local on total building volume, height dependent
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  vpf        !< building volume volume per facade element, height dependent
+
+    END TYPE build
+
+    TYPE(build), DIMENSION(:), ALLOCATABLE ::  buildings   !< building array
+
+    INTEGER(iwp) ::  num_build   !< total number of buildings in domain
+
+    REAL(wp) ::  volume_fraction
+
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_in     !< dummy array for indoor temperature for the 
+                                                     !< total building volume at each discrete height level
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_in_l   !< dummy array for indoor temperature for the 
+                                                     !< local building volume fraction at each discrete height level
+
+!
+!-- Declare all global variables within the module
+
+    INTEGER(iwp) ::  building_type = 1       !< namelist parameter with 
+                                             !< X1=construction year (cy) 1950, X2=cy 2000, X3=cy 2050
+                                             !< R=Residental building, O=Office, RW=Enlarged Windows, P=Panel type (Plattenbau) WBS 70, H=Hospital (in progress), I=Industrial halls (in progress), S=Special Building (in progress)
+                                             !< (0=R1, 1=R2, 2=R3, 3=O1, 4=O2, 5=O3,...)
+    INTEGER(iwp) ::  cooling_on              !< Indoor cooling flag (0=off, 1=on)
+    INTEGER(iwp) ::  heating_on              !< Indoor heating flag (0=off, 1=on)
+    INTEGER(iwp) ::  solar_protection_off    !< Solar protection off
+    INTEGER(iwp) ::  solar_protection_on     !< Solar protection on
+
+    REAL(wp) ::  air_change_high             !< [1/h] air changes per time_utc_hour
+    REAL(wp) ::  air_change_low              !< [1/h] air changes per time_utc_hour
+    REAL(wp) ::  eff_mass_area               !< [mÂ²] the effective mass-related area
+    REAL(wp) ::  floor_area_per_facade       !< [mÂ²] net floor area (Sum of all floors)
+    REAL(wp) ::  total_area                  !<! [mÂ²] area of all surfaces pointing to zone
+    REAL(wp) ::  window_area_per_facade      !< [m2] window area per facade element
+    REAL(wp) ::  air_change                  !< [1/h] Airflow
+    REAL(wp) ::  bldg_part_surf_i    = 4     !< [mÂ²_surf,i] part building surface, from Palm, das mÃŒsste mittlerweile "facade_element_area" sein!
+    REAL(wp) ::  facade_element_area         !< [mÂ²_facade] building surface facade
+    REAL(wp) ::  indoor_volume_per_facade    !< [mÂ³] indoor air volume per facade element
+    REAL(wp) ::  c_m                         !< [J/K] internal heat storage capacity
+    REAL(wp) ::  dt_indoor = 3600.0_wp       !< [s] namelist parameter: time interval for indoor-model application
+    REAL(wp) ::  eta_ve                      !< [-] heat recovery efficiency
+    REAL(wp) ::  f_c_win                     !< [-] shading factor
+    REAL(wp) ::  factor_a                    !< [-] Dynamic parameters specific effective surface according to Table 12; 2.5 (very light, light and medium), 3.0 (heavy), 3.5 (very heavy)
+    REAL(wp) ::  factor_c                    !< [J/(m2 K)] Dynamic parameters inner heatstorage according to Table 12; 80000 (very light), 110000 (light), 165000 (medium), 260000 (heavy), 370000 (very heavy)
+    REAL(wp) ::  g_value_win                 !< [-] SHGC factor
+    REAL(wp) ::  h_tr_1                      !<! [W/K] Heat transfer coefficient auxiliary variable 1
+    REAL(wp) ::  h_tr_2                      !<! [W/K] Heat transfer coefficient auxiliary variable 2
+    REAL(wp) ::  h_tr_3                      !<! [W/K] Heat transfer coefficient auxiliary variable 3 
+    REAL(wp) ::  h_tr_em                     !<! [W/K] Heat transfer coefficient of the emmision (got with h_tr_ms the thermal mass)
+    REAL(wp) ::  h_tr_is                     !<! [W/K] thermal coupling conductance (Thermischer Kopplungsleitwert)
+    REAL(wp) ::  h_tr_ms                     !<! [W/K] Heat transfer conductance term (got with h_tr_em the thermal mass)
+    REAL(wp) ::  h_tr_op                     !<! [W/K] heat transfer coefficient of opaque components (assumption: got all thermal mass) contains of h_tr_em and h_tr_ms
+    REAL(wp) ::  h_tr_w                      !<! [W/K] heat transfer coefficient of doors, windows, curtain walls and glazed walls (assumption: thermal mass=0)
+    REAL(wp) ::  h_ve                        !<! [W/K] heat transfer of ventilation
+    REAL(wp) ::  height_storey               !< [m] storey heigth
+    REAL(wp) ::  height_cei_con              !< [m] ceiling construction heigth    
+    REAL(wp) ::  initial_indoor_temperature  !< namelist parameter
+    REAL(wp) ::  lambda_at                   !< [-] ratio internal surface/floor area chap. 7.2.2.2.
+    REAL(wp) ::  lambda_layer3               !< [W/(m*K)] Thermal conductivity of the inner layer  
+    REAL(wp) ::  net_sw_in                   !< net short-wave radiation (in - out; was i_global --> CORRECT?)
+    REAL(wp) ::  qint_high                   !< [W/m2] internal heat gains, option Database qint_0-23
+    REAL(wp) ::  qint_low                    !< [W/m2] internal heat gains, option Database qint_0-23
+    REAL(wp) ::  phi_c_max                   !< [W] Max. Cooling capacity (negative)
+    REAL(wp) ::  phi_h_max                   !< [W] Max. Heating capacity (negative)
+    REAL(wp) ::  phi_hc_nd                   !<! [W] heating demand and/or cooling demand
+    REAL(wp) ::  phi_hc_nd_10                !<! [W] heating demand and/or cooling demand for heating or cooling 
+    REAL(wp) ::  phi_hc_nd_ac                !<! [W] actual heating demand and/or cooling demand
+    REAL(wp) ::  phi_hc_nd_un                !<! [W] unlimited heating demand and/or cooling demand which is necessary to reach the demanded required temperature (heating is positive, cooling is negative) 
+    REAL(wp) ::  phi_ia                      !< [W] internal air load = internal loads * 0.5, Eq. (C.1)
+    REAL(wp) ::  phi_m                       !<! [W] mass specific thermal load (internal and external)
+    REAL(wp) ::  phi_mtot                    !<! [W] total mass specific thermal load (internal and external)
+    REAL(wp) ::  phi_sol                     !< [W] solar loads
+    REAL(wp) ::  phi_st                      !<! [W] mass specific thermal load implied non thermal mass 
+    REAL(wp) ::  q_emission                  !< emissions, in first version = 0, option for second part of the project
+    REAL(wp) ::  q_wall_win               !< heat flux from indoor into wall/window
+    REAL(wp) ::  q_waste_heat                !< waste heat, sum of waste heat over the roof to Palm
+    REAL(wp) ::  q_waste_heat_bldg           !< [W/building] waste heat of the complete building, in Palm sum of all indoor_model-calculations
+    REAL(wp) ::  s_layer3                    !< [m] half thickness of the inner layer (layer_3)
+    REAL(wp) ::  schedule_d                  !< activation for internal loads (low or high + low)
+    REAL(wp) ::  skip_time_do_indoor = 0.0_wp  !< [s] Indoor model is not called before this time
+    REAL(wp) ::  theta_air                   !<! [Â°C] air temperature of the RC-node
+    REAL(wp) ::  theta_air_0                 !<! [oC] air temperature of the RC-node in equilibrium
+    REAL(wp) ::  theta_air_10                !<! [oC] air temperature of the RC-node from a heating capacity of 10 W/mÂ²
+    REAL(wp) ::  theta_air_ac                !< [oC] actual room temperature after heating/cooling
+    REAL(wp) ::  theta_air_set               !< [oC] Setpoint_temperature for the room
+    REAL(wp) ::  theta_int_c_set             !< [oC] Max. Setpoint temperature (summer)
+    REAL(wp) ::  theta_int_h_set             !< [oC] Max. Setpoint temperature (winter)
+    REAL(wp) ::  theta_m                     !<! [oC} inner temperature of the RC-node
+    REAL(wp) ::  theta_m_t                   !<! [oC] (Fictive) component temperature timestep
+    REAL(wp) ::  theta_m_t_prev              !< [oC] (Fictive) component temperature previous timestep (do not change)
+    REAL(wp) ::  theta_op                    !< [oC] operative temperature
+    REAL(wp) ::  theta_s                     !<! [oC] surface temperature of the RC-node
+    REAL(wp) ::  time_indoor = 0.0_wp        !< [s] time since last call of indoor model
+    REAL(wp) ::  time_utc_hour               !< Time in hours per day (UTC)
+    REAL(wp) ::  u_value_win                 !< [W/(m2*K)] transmittance
+    REAL(wp) ::  ventilation_int_loads       !< Zuteilung der GebÃ€ude fÃŒr Verlauf/AktivitÃ€t der LÃŒftung und internen Lasten
+
+!
+!-- Declare all global parameters within the module    
+    REAL(wp), PARAMETER ::  params_f_f               = 0.3_wp      !< [-] frame ratio chap. 8.3.2.1.1 for buildings with mostly cooling 2.0_wp
+    REAL(wp), PARAMETER ::  params_f_w               = 0.9_wp      !< [-] correction factor (fuer nicht senkrechten Stahlungseinfall DIN 4108-2 chap.8, (hier konstant, keine WinkelabhÃ€ngigkeit) 
+    REAL(wp), PARAMETER ::  params_f_win             = 0.5_wp      !< [-] proportion of window area, Database A_win aus Datenbank 27 window_area_per_facade_percent
+    REAL(wp), PARAMETER ::  params_solar_protection  = 300.0_wp    !< [W/m2] chap. G.5.3.1 sun protection closed, if the radiation on facade exceeds this value
+    REAL(wp), PARAMETER ::  params_waste_heat_c      = 4.0_wp      !< [-] anthropogenic heat outputs for cooling e.g. 4 for KKM with COP = 3
+    REAL(wp), PARAMETER ::  params_waste_heat_h      = 1.111_wp    !< [-] anthropogenic heat outputs for heating e.g. 1 / 0.9 = 1.111111 for combustion with eta = 0.9 or -3 for WP with COP = 4
+    REAL(wp), PARAMETER ::  h_is                     = 3.45_wp     !< [W/(m^2 K)]  h_is = 3.45 between surface and air (chap. 7.2.2.2)
+    REAL(wp), PARAMETER ::  h_ms                     = 9.1_wp      !< [W/K] h_ms = 9.10 W / (m2 K) between component and surface (chap. 12.2.2)
+  
+    SAVE
+
+
+    PRIVATE
+    
+!
+!-- Add INTERFACES that must be available to other modules
+    PUBLIC im_init, im_main_heatcool, im_parin 
+
+!
+!-- Add VARIABLES that must be available to other modules
+    PUBLIC dt_indoor, skip_time_do_indoor, time_indoor
+
+!
+!-- Calculations for indoor temperatures  
+    INTERFACE im_calc_temperatures
+       MODULE PROCEDURE im_calc_temperatures
+    END INTERFACE im_calc_temperatures
+!
+!-- Initialization actions  
+    INTERFACE im_init
+       MODULE PROCEDURE im_init
+    END INTERFACE im_init
+ 
+!
+!-- Main part of indoor model  
+    INTERFACE im_main_heatcool
+       MODULE PROCEDURE im_main_heatcool
+    END INTERFACE im_main_heatcool
+!
+!-- Reading of NAMELIST parameters
+    INTERFACE im_parin
+       MODULE PROCEDURE im_parin
+    END INTERFACE im_parin
+
+ CONTAINS
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!< Calculation of the air temperatures and mean radiation temperature
+!< This is basis for the operative temperature
+!< Based on a Crank-Nicholson scheme with a timestep of a hour
+!------------------------------------------------------------------------------!
+ SUBROUTINE im_calc_temperatures ( i, j, k, indoor_wall_window_temperature,    &
+                                   near_facade_temperature, phi_hc_nd_dummy )
+ 
+    USE arrays_3d,                                                             &
+        ONLY:  pt
+
+
+    IMPLICIT NONE
+    
+    
+    INTEGER(iwp) ::  i
+    INTEGER(iwp) ::  j
+    INTEGER(iwp) ::  k
+    
+    REAL(wp) ::  indoor_wall_window_temperature  !< weighted temperature of innermost wall/window layer
+    REAL(wp) ::  near_facade_temperature
+    REAL(wp) ::  phi_hc_nd_dummy
+
+    !< Calculation of total mass specific thermal load (internal and external)
+    phi_mtot = ( phi_m + h_tr_em * indoor_wall_window_temperature              &
+                       + h_tr_3  * ( phi_st + h_tr_w * pt(k,j,i)               &
+                                            + h_tr_1 *                         &
+                                               ( ( ( phi_ia + phi_hc_nd_dummy ) / h_ve )  &
+                                                 + near_facade_temperature )   &
+                                   ) / h_tr_2                                  &
+               )                                                                !< [oC] Eq. (C.5)
+    
+    !< Calculation of component temperature at factual timestep
+    theta_m_t = ( ( theta_m_t_prev                                               &
+                    * ( ( c_m / 3600 ) - 0.5 * ( h_tr_3 + h_tr_em ) ) + phi_mtot &
+                  )                                                              &
+                  /   ( ( c_m / 3600 ) + 0.5 * ( h_tr_3 + h_tr_em ) )            &
+                )                                                               !< [oC] Eq. (C.4)
+
+    !< Calculation of mean inner temperature for the RC-node in actual timestep
+    theta_m = ( theta_m_t + theta_m_t_prev ) * 0.5                              !< [oC] Eq. (C.9)
+    
+    !< Calculation of mean surface temperature of the RC-node in actual timestep
+    theta_s = ( (   h_tr_ms * theta_m + phi_st + h_tr_w * pt(k,j,i)                         &
+                  + h_tr_1  * ( near_facade_temperature + ( phi_ia + phi_hc_nd_dummy ) / h_ve ) &
+                )                                                                           &
+                / ( h_tr_ms + h_tr_w + h_tr_1 )                                             &
+              )                                                                 !< [oC] Eq. (C.10)
+    
+    !< Calculation of the air temperature of the RC-node
+    theta_air = ( h_tr_is * theta_s + h_ve * near_facade_temperature         &
+                                    + phi_ia + phi_hc_nd_dummy ) / ( h_tr_is + h_ve ) !< [oC] Eq. (C.11)
+
+ END SUBROUTINE im_calc_temperatures
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Initialization of the indoor model.
+!> Static information are calculated here, e.g. building parameters and
+!> geometrical information, everything that doesn't change in time.
+!
+!-- Input values
+!-- Input datas from Palm, M4
+!     i_global             -->  net_sw_in                         !global radiation [W/m2]
+!     theta_e              -->  pt(k,j,i)                         !undisturbed outside temperature, 1. PALM volume, for windows
+!     theta_sup = theta_f  -->  surf_usm_h%t_surf_10cm(m)
+!                               surf_usm_v(l)%t_surf_10cm(m)   !Air temperature, facade near (10cm) air temperature from 1. Palm volume
+!     theta_node           -->  t_wall_h(nzt_wall,m)
+!                               t_wall_v(l)%t(nzt_wall,m)         !Temperature of innermost wall layer, for opaque wall
+!------------------------------------------------------------------------------!
+ SUBROUTINE im_init
+  
+    USE arrays_3d,                                                             &
+        ONLY:  dzw
+
+    USE control_parameters,                                                    &
+        ONLY:  message_string
+
+    USE indices,                                                               &
+        ONLY:  nxl, nxr, nyn, nys, nzb, nzt, wall_flags_0
+
+    USE grid_variables,                                                        &
+        ONLY:  dx, dy
+
+    USE netcdf_data_input_mod,                                                 &
+        ONLY:  building_id_f
+
+    USE pegrid
+
+    USE surface_mod,                                                           &
+        ONLY:  surf_usm_h, surf_usm_v
+        
+    USE urban_surface_mod,                                                     &
+        ONLY:  building_pars, building_type
+
+    IMPLICIT NONE
+
+    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
+    INTEGER(iwp) ::  k    !< running index along z-direction
+    INTEGER(iwp) ::  l    !< running index for surface-element orientation
+    INTEGER(iwp) ::  m    !< running index surface elements
+    INTEGER(iwp) ::  n    !< building index
+    INTEGER(iwp) ::  nb   !< building index
+
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids           !< building IDs on entire model domain
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_final     !< building IDs on entire model domain, 
+                                                                    !< multiple occurences are sorted out 
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_final_tmp !< temporary array used for resizing
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_l         !< building IDs on local subdomain
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  build_ids_l_tmp     !< temporary array used to resize array of building IDs
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  displace_dum        !< displacements of start addresses, used for MPI_ALLGATHERV
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  k_max_l             !< highest vertical index of a building on subdomain
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  k_min_l             !< lowest vertical index of a building on subdomain
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  n_fa                !< counting array
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facades_h       !< dummy array used for summing-up total number of 
+                                                                    !< horizontal facade elements
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  num_facades_v       !< dummy array used for summing-up total number of 
+                                                                    !< vertical facade elements
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  receive_dum_h       !< dummy array used for MPI_ALLREDUCE  
+    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  receive_dum_v       !< dummy array used for MPI_ALLREDUCE  
+
+    INTEGER(iwp), DIMENSION(0:numprocs-1) ::  num_buildings         !< number of buildings with different ID on entire model domain
+    INTEGER(iwp), DIMENSION(0:numprocs-1) ::  num_buildings_l       !< number of buildings with different ID on local subdomain
+
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  local_weight   !< dummy representing fraction of local on total building volume, 
+                                                           !< height dependent
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  volume         !< total building volume at each discrete height level
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  volume_l       !< total building volume at each discrete height level,
+                                                           !< on local subdomain
+
+!
+!-- Initializing of indoor model is only possible if buildings can be 
+!-- distinguished by their IDs.
+    IF ( .NOT. building_id_f%from_file )  THEN
+       message_string = 'Indoor model requires information about building_id'
+       CALL message( 'im_init', 'PA0999', 1, 2, 0, 6, 0  )
+    ENDIF
+!
+!-- Determine number of different building IDs on local subdomain.
+    num_buildings_l = 0
+    num_buildings   = 0
+    ALLOCATE( build_ids_l(1) )
+    DO  i = nxl, nxr
+       DO  j = nys, nyn
+          IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
+             IF ( num_buildings_l(myid) > 0 )  THEN
+                IF ( ANY( building_id_f%var(j,i) .EQ.  build_ids_l ) )  THEN 
+                   CYCLE
+                ELSE
+                   num_buildings_l(myid) = num_buildings_l(myid) + 1
+!
+!--                Resize array with different local building ids
+                   ALLOCATE( build_ids_l_tmp(1:SIZE(build_ids_l)) )
+                   build_ids_l_tmp = build_ids_l
+                   DEALLOCATE( build_ids_l )
+                   ALLOCATE( build_ids_l(1:num_buildings_l(myid)) )
+                   build_ids_l(1:num_buildings_l(myid)-1) =                 &
+                               build_ids_l_tmp(1:num_buildings_l(myid)-1)
+                   build_ids_l(num_buildings_l(myid)) = building_id_f%var(j,i)
+                   DEALLOCATE( build_ids_l_tmp )
+                ENDIF
+!
+!--          First occuring building id on PE 
+             ELSE 
+                num_buildings_l(myid) = num_buildings_l(myid) + 1
+                build_ids_l(1) = building_id_f%var(j,i)
+             ENDIF
+          ENDIF
+       ENDDO
+    ENDDO
+!
+!-- Determine number of building IDs for the entire domain. (Note, building IDs
+!-- can appear multiple times as buildings might be distributed over several
+!-- PEs.) 
+#if defined( __parallel ) 
+    CALL MPI_ALLREDUCE( num_buildings_l, num_buildings, numprocs,              &
+                        MPI_INTEGER, MPI_SUM, comm2d, ierr ) 
+#else
+    num_buildings = num_buildings_l
+#endif
+    ALLOCATE( build_ids(1:SUM(num_buildings)) )
+!
+!-- Gather building IDs. Therefore, first, determine displacements used 
+!-- required for MPI_GATHERV call.
+    ALLOCATE( displace_dum(0:numprocs-1) )
+    displace_dum(0) = 0
+    DO i = 1, numprocs-1
+       displace_dum(i) = displace_dum(i-1) + num_buildings(i-1)
+    ENDDO
+
+#if defined( __parallel ) 
+    CALL MPI_ALLGATHERV( build_ids_l(1:num_buildings_l(myid)),                 &
+                         num_buildings(myid),                                  &
+                         MPI_INTEGER,                                          &
+                         build_ids,                                            &
+                         num_buildings,                                        &
+                         displace_dum,                                         & 
+                         MPI_INTEGER,                                          &
+                         comm2d, ierr )   
+
+    DEALLOCATE( displace_dum )
+
+#else
+    build_ids = build_ids_l
+#endif
+!
+!-- Note: in parallel mode, building IDs can occur mutliple times, as 
+!-- each PE has send its own ids. Therefore, sort out building IDs which 
+!-- appear multiple times. 
+    num_build = 0
+    DO  n = 1, SIZE(build_ids)
+
+       IF ( ALLOCATED(build_ids_final) )  THEN
+          IF ( ANY( build_ids(n) .EQ. build_ids_final ) )  THEN    !FK: Warum ANY?, Warum .EQ.? --> s.o
+             CYCLE
+          ELSE
+             num_build = num_build + 1
+!
+!--          Resize
+             ALLOCATE( build_ids_final_tmp(1:num_build) )
+             build_ids_final_tmp(1:num_build-1) = build_ids_final(1:num_build-1)
+             DEALLOCATE( build_ids_final )
+             ALLOCATE( build_ids_final(1:num_build) )
+             build_ids_final(1:num_build-1) = build_ids_final_tmp(1:num_build-1)
+             build_ids_final(num_build) = build_ids(n)
+             DEALLOCATE( build_ids_final_tmp )
+          ENDIF             
+       ELSE
+          num_build = num_build + 1
+          ALLOCATE( build_ids_final(1:num_build) )
+          build_ids_final(num_build) = build_ids(n)
+       ENDIF
+    ENDDO
+
+!
+!-- Allocate building-data structure array. Note, this is a global array
+!-- and all building IDs on domain are known by each PE. Further attributes, 
+!-- e.g. height-dependent arrays, however, are only allocated on PEs where 
+!-- the respective building is present (in order to reduce memory demands).
+    ALLOCATE( buildings(1:num_build) )
+!
+!-- Store building IDs and check if building with certain ID is present on
+!-- subdomain. 
+    DO  nb = 1, num_build
+       buildings(nb)%id = build_ids_final(nb)
+
+       IF ( ANY( building_id_f%var == buildings(nb)%id ) )                      &
+          buildings(nb)%on_pe = .TRUE.
+    ENDDO 
+!
+!-- Determine the maximum vertical dimension occupied by each building. 
+    ALLOCATE( k_min_l(1:num_build) )
+    ALLOCATE( k_max_l(1:num_build) )
+    k_min_l = nzt + 1
+    k_max_l = 0    
+
+    DO  i = nxl, nxr
+       DO  j = nys, nyn
+          IF ( building_id_f%var(j,i) /= building_id_f%fill )  THEN
+             nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ),   &
+                         DIM = 1 )
+             DO  k = nzb+1, nzt+1
+!
+!--             Check if grid point belongs to a building. 
+                IF ( BTEST( wall_flags_0(k,j,i), 6 ) )  THEN
+                   k_min_l(nb) = MIN( k_min_l(nb), k )
+                   k_max_l(nb) = MAX( k_max_l(nb), k )
+                ENDIF
+
+             ENDDO
+          ENDIF
+       ENDDO
+    ENDDO
+
+    DO nb = 1, num_build
+#if defined( __parallel ) 
+       CALL MPI_ALLREDUCE( k_min_l(nb), buildings(nb)%kb_min, 1, MPI_INTEGER,  &
+                           MPI_MIN, comm2d, ierr )
+       CALL MPI_ALLREDUCE( k_max_l(nb), buildings(nb)%kb_max, 1, MPI_INTEGER,  &
+                           MPI_MAX, comm2d, ierr )
+#else
+       buildings(nb)%kb_min = k_min_l(nb)
+       buildings(nb)%kb_max = k_max_l(nb)
+#endif
+
+    ENDDO 
+
+    DEALLOCATE( k_min_l )
+    DEALLOCATE( k_max_l )
+!
+!-- Calculate building volume
+    DO  nb = 1, num_build
+!
+!--    Allocate temporary array for summing-up building volume
+       ALLOCATE( volume(buildings(nb)%kb_min:buildings(nb)%kb_max)   )
+       ALLOCATE( volume_l(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+       volume   = 0.0_wp
+       volume_l = 0.0_wp
+!
+!--    Calculate building volume per height level on each PE where 
+!--    these building is present. 
+       IF ( buildings(nb)%on_pe )  THEN
+          ALLOCATE( buildings(nb)%volume(buildings(nb)%kb_min:buildings(nb)%kb_max)   )
+          ALLOCATE( buildings(nb)%vol_frac(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+          buildings(nb)%volume   = 0.0_wp
+          buildings(nb)%vol_frac = 0.0_wp
+          
+          IF ( ANY( building_id_f%var == buildings(nb)%id ) )  THEN
+             DO  i = nxl, nxr
+                DO  j = nys, nyn
+                   DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
+                      IF ( building_id_f%var(j,i) /= building_id_f%fill )      &
+                         volume_l(k) = dx * dy * dzw(k)
+                   ENDDO
+                ENDDO
+             ENDDO
+          ENDIF
+       ENDIF
+!
+!--    Sum-up building volume from all subdomains
+#if defined( __parallel ) 
+       CALL MPI_ALLREDUCE( volume_l, volume, SIZE(volume), MPI_REAL, MPI_SUM,  &
+                           comm2d, ierr )
+#else
+       volume = volume_l
+#endif
+!
+!--    Save total building volume as well as local fraction on volume on 
+!--    building data structure.
+       IF ( ALLOCATED( buildings(nb)%volume ) )  buildings(nb)%volume = volume
+!
+!--    Determine fraction of local on total building volume
+       IF ( buildings(nb)%on_pe )  buildings(nb)%vol_frac = volume_l / volume
+
+       DEALLOCATE( volume   )
+       DEALLOCATE( volume_l )
+
+    ENDDO
+
+!
+!-- Allocate arrays for indoor temperature.  
+    DO  nb = 1, num_build
+       IF ( buildings(nb)%on_pe )  THEN
+          ALLOCATE( buildings(nb)%t_in(buildings(nb)%kb_min:buildings(nb)%kb_max)   )
+          ALLOCATE( buildings(nb)%t_in_l(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+          buildings(nb)%t_in   = 0.0_wp
+          buildings(nb)%t_in_l = 0.0_wp
+       ENDIF
+    ENDDO
+!
+!-- Allocate arrays for number of facades per height level. Distinguish between
+!-- horizontal and vertical facades. 
+    DO  nb = 1, num_build
+       IF ( buildings(nb)%on_pe )  THEN
+          ALLOCATE( buildings(nb)%num_facade_h(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+          ALLOCATE( buildings(nb)%num_facade_v(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+
+          buildings(nb)%num_facade_h = 0
+          buildings(nb)%num_facade_v = 0
+       ENDIF
+    ENDDO
+!
+!-- Determine number of facade elements per building on local subdomain.
+!-- Distinguish between horizontal and vertical facade elements.
+!
+!-- Horizontal facades
+    buildings(:)%num_facades_per_building_h_l = 0
+    DO  m = 1, surf_usm_h%ns
+!
+!--    For the current facade element determine corresponding building index.
+!--    First, obtain j,j,k indices of the building. Please note the
+!--    offset between facade/surface element and building location (for 
+!--    horizontal surface elements the horizontal offsets are zero).
+       i = surf_usm_h%i(m) + surf_usm_h%ioff
+       j = surf_usm_h%j(m) + surf_usm_h%joff
+       k = surf_usm_h%k(m) + surf_usm_h%koff
+!
+!--    Determine building index and check whether building is on PE
+       nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM = 1 )
+       IF ( buildings(nb)%on_pe )  THEN
+!
+!--       Count number of facade elements at each height level.
+          buildings(nb)%num_facade_h(k) = buildings(nb)%num_facade_h(k) + 1 
+!
+!--       Moreover, sum up number of local facade elements per building.
+          buildings(nb)%num_facades_per_building_h_l =                         &
+                                buildings(nb)%num_facades_per_building_h_l + 1
+       ENDIF
+    ENDDO
+!
+!-- Vertical facades
+    buildings(:)%num_facades_per_building_v_l = 0
+    DO  l = 0, 3
+       DO  m = 1, surf_usm_v(l)%ns
+!
+!--       For the current facade element determine corresponding building index.
+!--       First, obtain j,j,k indices of the building. Please note the
+!--       offset between facade/surface element and building location (for 
+!--       vertical surface elements the vertical offsets are zero).
+          i = surf_usm_v(l)%i(m) + surf_usm_v(l)%ioff
+          j = surf_usm_v(l)%j(m) + surf_usm_v(l)%joff
+          k = surf_usm_v(l)%k(m) + surf_usm_v(l)%koff
+
+          nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ),        &
+                       DIM = 1 )
+          IF ( buildings(nb)%on_pe )  THEN
+             buildings(nb)%num_facade_v(k) = buildings(nb)%num_facade_v(k) + 1 
+             buildings(nb)%num_facades_per_building_v_l =                      &
+                                buildings(nb)%num_facades_per_building_v_l + 1
+          ENDIF
+       ENDDO
+    ENDDO
+
+!
+!-- Determine total number of facade elements per building and assign number to 
+!-- building data type.
+    DO  nb = 1, num_build
+!
+!--    Allocate dummy array used for summing-up facade elements. 
+!--    Please note, dummy arguments are necessary as building-date type
+!--    arrays are not necessarily allocated on all PEs.
+       ALLOCATE( num_facades_h(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+       ALLOCATE( num_facades_v(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+       ALLOCATE( receive_dum_h(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+       ALLOCATE( receive_dum_v(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+       num_facades_h = 0
+       num_facades_v = 0
+       receive_dum_h = 0
+       receive_dum_v = 0
+
+       IF ( buildings(nb)%on_pe )  THEN
+          num_facades_h = buildings(nb)%num_facade_h
+          num_facades_v = buildings(nb)%num_facade_v
+       ENDIF
+
+#if defined( __parallel ) 
+       CALL MPI_ALLREDUCE( num_facades_h,                                      &
+                           receive_dum_h,                                      &
+                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,    &
+                           MPI_INTEGER,                                        &
+                           MPI_SUM,                                            &
+                           comm2d,                                             &
+                           ierr )
+
+       CALL MPI_ALLREDUCE( num_facades_v,                                      &
+                           receive_dum_v,                                      &
+                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,    &
+                           MPI_INTEGER,                                        &
+                           MPI_SUM,                                            &
+                           comm2d,                                             &
+                           ierr )
+       IF ( ALLOCATED( buildings(nb)%num_facade_h ) )                          &  !FK: Was wenn not allocated? --> s.o.
+           buildings(nb)%num_facade_h = receive_dum_h
+       IF ( ALLOCATED( buildings(nb)%num_facade_v ) )                          &
+           buildings(nb)%num_facade_v = receive_dum_v
+#else
+       buildings(nb)%num_facade_h = num_facades_h
+       buildings(nb)%num_facade_v = num_facades_v
+#endif
+!
+!--    Deallocate dummy arrays
+       DEALLOCATE( num_facades_h )
+       DEALLOCATE( num_facades_v )
+       DEALLOCATE( receive_dum_h )
+       DEALLOCATE( receive_dum_v )
+!
+!--    Allocate index arrays which link facade elements with surface-data type.
+!--    Please note, no height levels are considered here (information is stored
+!--    in surface-data type itself).
+       IF ( buildings(nb)%on_pe )  THEN
+!
+!--       Determine number of facade elements per building.
+          buildings(nb)%num_facades_per_building_h = SUM( buildings(nb)%num_facade_h )
+          buildings(nb)%num_facades_per_building_v = SUM( buildings(nb)%num_facade_v )
+!
+!--       Allocate arrays which link the building with the horizontal and vertical
+!--       urban-type surfaces. Please note, linking arrays are allocated over all
+!--       facade elements, which is required in case a building is located at the
+!--       subdomain boundaries, where the building and the corresponding surface
+!--       elements are located on different subdomains. 
+          ALLOCATE( buildings(nb)%m_h(1:buildings(nb)%num_facades_per_building_h_l) )
+
+          ALLOCATE( buildings(nb)%l_v(1:buildings(nb)%num_facades_per_building_v_l) )
+          ALLOCATE( buildings(nb)%m_v(1:buildings(nb)%num_facades_per_building_v_l) )
+       ENDIF
+!
+!--    Determine volume per facade element (vpf)
+       IF ( buildings(nb)%on_pe )  THEN
+          ALLOCATE( buildings(nb)%vpf(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+          
+          DO  k = buildings(nb)%kb_min, buildings(nb)%kb_max
+             buildings(nb)%vpf(k) = buildings(nb)%volume(k) /                  &
+                                    ( buildings(nb)%num_facade_h(k) +          &
+                                      buildings(nb)%num_facade_v(k) )
+          ENDDO
+       ENDIF
+    ENDDO
+!
+!-- Link facade elements with surface data type. 
+!-- Allocate array for counting.
+    ALLOCATE( n_fa(1:num_build) )
+    n_fa = 1
+
+    DO  m = 1, surf_usm_h%ns
+       i = surf_usm_h%i(m) + surf_usm_h%ioff
+       j = surf_usm_h%j(m) + surf_usm_h%joff
+
+       nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM = 1 )
+
+       buildings(nb)%m_h(n_fa(nb)) = m
+       n_fa(nb) = n_fa(nb) + 1      
+    ENDDO
+
+    n_fa = 1
+    DO  l = 0, 3
+       DO  m = 1, surf_usm_v(l)%ns
+          i = surf_usm_v(l)%i(m) + surf_usm_v(l)%ioff
+          j = surf_usm_v(l)%j(m) + surf_usm_v(l)%joff
+
+          nb = MINLOC( ABS( buildings(:)%id - building_id_f%var(j,i) ), DIM = 1 )
+
+          buildings(nb)%l_v(n_fa(nb)) = l
+          buildings(nb)%m_v(n_fa(nb)) = m
+          n_fa(nb) = n_fa(nb) + 1      
+       ENDDO
+    ENDDO
+    DEALLOCATE( n_fa )
+
+!
+!-- Building parameters by type of building. Assigned in urban_surface_mod.f90
+
+    lambda_layer3            = building_pars(63, building_type)
+    s_layer3                 = building_pars(57, building_type)
+    f_c_win                  = building_pars(119, building_type)
+    g_value_win              = building_pars(120, building_type)    
+    u_value_win              = building_pars(121, building_type)    
+    air_change_low           = building_pars(122, building_type)    
+    air_change_high          = building_pars(123, building_type)    
+    eta_ve                   = building_pars(124, building_type)    
+    factor_a                 = building_pars(125, building_type)    
+    factor_c                 = building_pars(126, building_type)
+    lambda_at                = building_pars(127, building_type)    
+    theta_int_h_set          = building_pars(118, building_type)    
+    theta_int_c_set          = building_pars(117, building_type)
+    phi_h_max                = building_pars(128, building_type)    
+    phi_c_max                = building_pars(129, building_type)          
+    qint_high                = building_pars(130, building_type)
+    qint_low                 = building_pars(131, building_type)
+    height_storey            = building_pars(132, building_type)
+    height_cei_con           = building_pars(133, building_type)
+
+!
+!-- Setting of initial room temperature [K]
+!-- (after first loop, use theta_m_t as theta_m_t_prev)
+    theta_m_t_prev = initial_indoor_temperature
+
+
+ END SUBROUTINE im_init
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Main part of the indoor model.
+!> Calculation of .... (kanani: Please describe)
+!------------------------------------------------------------------------------!
+ SUBROUTINE im_main_heatcool
+
+    USE arrays_3d,                                                             &
+        ONLY:  ddzw, dzw
+
+    USE basic_constants_and_equations_mod,                                     &
+        ONLY:  c_p
+
+    USE control_parameters,                                                    &
+        ONLY:  rho_surface
+
+    USE date_and_time_mod,                                                     &
+        ONLY:  time_utc
+
+    USE grid_variables,                                                        &
+        ONLY:  dx, dy
+
+    USE pegrid
+    
+    USE surface_mod,                                                           &
+        ONLY:  ind_veg_wall, ind_wat_win, surf_usm_h, surf_usm_v
+
+    USE urban_surface_mod,                                                     &
+        ONLY:  nzt_wall, t_surf_10cm_h, t_surf_10cm_v, t_wall_h, t_wall_v,     &
+               t_window_h, t_window_v, building_type
+
+
+    IMPLICIT NONE
+
+    INTEGER(iwp) ::  i    !< index of facade-adjacent atmosphere grid point in x-direction
+    INTEGER(iwp) ::  j    !< index of facade-adjacent atmosphere grid point in y-direction
+    INTEGER(iwp) ::  k    !< index of facade-adjacent atmosphere grid point in z-direction
+    INTEGER(iwp) ::  kk   !< vertical index of indoor grid point adjacent to facade
+    INTEGER(iwp) ::  l    !< running index for surface-element orientation
+    INTEGER(iwp) ::  m    !< running index surface elements
+    INTEGER(iwp) ::  nb   !< running index for buildings
+    INTEGER(iwp) ::  fa   !< running index for facade elements of each building
+
+    REAL(wp) ::  indoor_wall_window_temperature   !< weighted temperature of innermost wall/window layer
+    REAL(wp) ::  near_facade_temperature          !< outside air temperature 10cm away from facade
+    REAL(wp) ::  time_utc_hour                    !< time of day (hour UTC)
+
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_in_l_send   !< dummy send buffer used for summing-up indoor temperature per kk-level
+    REAL(wp), DIMENSION(:), ALLOCATABLE ::  t_in_recv     !< dummy recv buffer used for summing-up indoor temperature per kk-level
+
+!
+!-- Daily schedule, here for 08:00-18:00 = 1, other hours = 0.
+!-- time_utc_hour is calculated here based on time_utc [s] from 
+!-- date_and_time_mod.
+!-- (kanani: Does this schedule not depend on if it's an office or resident 
+!-- building?)
+    time_utc_hour = time_utc / 3600.0_wp
+
+!
+!-- Allocation of the load profiles to the building types
+!-- Residental Building, panel WBS 70
+    if      (building_type ==  1 .OR. &
+             building_type ==  2 .OR. &
+             building_type ==  3 .OR. &
+             building_type == 10 .OR. &
+             building_type == 11 .OR. &
+             building_type == 12) then
+                                        ventilation_int_loads = 1
+!-- Office, building with large windows
+    else if (building_type ==  4 .OR. &
+             building_type ==  5 .OR. &
+             building_type ==  6 .OR. &
+             building_type ==  7 .OR. &
+             building_type ==  8 .OR. &
+             building_type ==  9) then
+                                        ventilation_int_loads = 2
+!-- Industry, hospitals
+    else if (building_type == 13 .OR. &
+             building_type == 14 .OR. &
+             building_type == 15 .OR. &
+             building_type == 16 .OR. &
+             building_type == 17 .OR. &
+             building_type == 18) then
+                                        ventilation_int_loads = 3
+
+    end if
+
+!-- Residental Building, panel WBS 70
+    
+    if (ventilation_int_loads == 1) THEN
+       if ( time_utc_hour >= 6.0_wp .AND. time_utc_hour <= 8.0_wp )  THEN
+          schedule_d = 1
+       else if ( time_utc_hour >= 18.0_wp .AND. time_utc_hour <= 23.0_wp )  THEN
+          schedule_d = 1
+       else
+          schedule_d = 0
+       end if
+    end if
+
+!-- Office, building with large windows
+
+    if (ventilation_int_loads == 2) THEN
+       if ( time_utc_hour >= 8.0_wp  .AND.  time_utc_hour <= 18.0_wp )  THEN
+          schedule_d = 1
+       else
+          schedule_d = 0
+       end if
+    end if
+       
+!-- Industry, hospitals
+    if (ventilation_int_loads == 3) THEN
+       if ( time_utc_hour >= 6.0_wp  .AND.  time_utc_hour <= 22.0_wp )  THEN
+          schedule_d = 1
+       else
+          schedule_d = 0
+       end if
+    end if
+
+
+!
+!-- Following calculations must be done for each facade element.
+    DO  nb = 1, num_build
+!
+!--    First, check whether building is present on local subdomain. 
+       IF ( buildings(nb)%on_pe )  THEN
+!
+!--       Initialize/reset indoor temperature
+          buildings(nb)%t_in   = 0.0_wp
+          buildings(nb)%t_in_l = 0.0_wp 
+!
+!--       Horizontal surfaces
+          DO  fa = 1, buildings(nb)%num_facades_per_building_h_l
+!
+!--          Determine index where corresponding surface-type information 
+!--          is stored. 
+             m = buildings(nb)%m_h(fa)
+!
+!--          Determine building height level index. 
+             kk = surf_usm_h%k(m) + surf_usm_h%koff
+!            
+!--          Building geometries --> not time-dependent
+             facade_element_area      = dx * dy                             !< [m2] surface area per facade element    
+             floor_area_per_facade    = buildings(nb)%vpf(kk) * ddzw(kk)    !< [m2] net floor area per facade element       
+             indoor_volume_per_facade = buildings(nb)%vpf(kk)               !< [m3] indoor air volume per facade element           
+             window_area_per_facade   = surf_usm_h%frac(ind_wat_win,m)  * facade_element_area  !< [m2] window area per facade element
+             eff_mass_area            = factor_a * floor_area_per_facade    !< [m2] standard values according to Table 12 section 12.3.1.2  (calculate over Eq. (65) according to section 12.3.1.2)
+             c_m                      = factor_c * floor_area_per_facade    !< [J/K] standard values according to table 12 section 12.3.1.2 (calculate over Eq. (66) according to section 12.3.1.2)
+             total_area               = lambda_at * floor_area_per_facade   !< [m2] area of all surfaces pointing to zone  Eq. (9) according to section 7.2.2.2
+
+!--          Calculation of heat transfer coefficient for transmission --> not time-dependent
+             h_tr_w   = window_area_per_facade * u_value_win   !< [W/K] only for windows
+             h_tr_is  = total_area * h_is                      !< [W/K] with h_is = 3.45 W / (m2 K) between surface and air, Eq. (9)
+             h_tr_ms  = eff_mass_area * h_ms                    !< [W/K] with h_ms = 9.10 W / (m2 K) between component and surface, Eq. (64)
+             h_tr_op  = 1 / ( 1 / ( ( facade_element_area - window_area_per_facade ) &
+                                    * lambda_layer3 / s_layer3 * 0.5 ) + 1 / h_tr_ms )
+             h_tr_em  = 1 / ( 1 / h_tr_op - 1 / h_tr_ms )      !< [W/K] Eq. (63), Section 12.2.2
+!
+!--          internal air loads dependent on the occupacy of the room
+!--          basical internal heat gains (qint_low) with additional internal heat gains by occupancy (qint_high) (0,5*phi_int)
+             phi_ia = 0.5 * ( ( qint_high * schedule_d + qint_low )            &
+                              * floor_area_per_facade )         !< [W] Eq. (C.1)
+!
+!--          Airflow dependent on the occupacy of the room
+!--          basical airflow (air_change_low) with additional airflow gains by occupancy (air_change_high)
+             air_change = ( air_change_high * schedule_d + air_change_low )  !< [1/h]? 
+!
+!--          Heat transfer of ventilation 
+!--          not less than 0.01 W/K to provide division by 0 in further calculations
+!--          with heat capacity of air 0.33 Wh/m2K
+             h_ve   = MAX( 0.01 , ( air_change * indoor_volume_per_facade *      &
+                                    0.33 * (1 - eta_ve ) ) )    !< [W/K] from ISO 13789 Eq.(10) 
+
+!--          Heat transfer coefficient auxiliary variables
+             h_tr_1 = 1 / ( ( 1 / h_ve )   + ( 1 / h_tr_is ) )  !< [W/K] Eq. (C.6)
+             h_tr_2 = h_tr_1 + h_tr_w                           !< [W/K] Eq. (C.7)
+             h_tr_3 = 1 / ( ( 1 / h_tr_2 ) + ( 1 / h_tr_ms ) )  !< [W/K] Eq. (C.8)
+!
+!--          Net short-wave radiation through window area (was i_global)
+             net_sw_in = surf_usm_h%rad_sw_in(m) - surf_usm_h%rad_sw_out(m)
+!
+!--          Quantities needed for im_calc_temperatures
+             i = surf_usm_h%i(m)
+             j = surf_usm_h%j(m)
+             k = surf_usm_h%k(m)
+             near_facade_temperature = t_surf_10cm_h(m)
+             indoor_wall_window_temperature =                                  &
+                  surf_usm_h%frac(ind_veg_wall,m) * t_wall_h(nzt_wall,m)       &
+                + surf_usm_h%frac(ind_wat_win,m)  * t_window_h(nzt_wall,m)
+!
+!--          Solar thermal gains. If net_sw_in larger than sun-protection 
+!--          threshold parameter (params_solar_protection), sun protection will 
+!--          be activated
+             IF ( net_sw_in <= params_solar_protection )  THEN 
+                solar_protection_off = 1
+                solar_protection_on  = 0 
+             ELSE 
+                solar_protection_off = 0
+                solar_protection_on  = 1 
+             ENDIF
+!
+!--          Calculation of total heat gains from net_sw_in through windows [W] in respect on automatic sun protection 
+!--          DIN 4108 - 2 chap.8
+             phi_sol = (   window_area_per_facade * net_sw_in * solar_protection_off               &
+                         + window_area_per_facade * net_sw_in * f_c_win * solar_protection_on )    &
+                       * g_value_win * ( 1 - params_f_f ) * params_f_w              !< [W]
+!
+!--          Calculation of the mass specific thermal load for internal and external heatsources of the inner node
+             phi_m   = (eff_mass_area / total_area) * ( phi_ia + phi_sol )          !< [W] Eq. (C.2) with phi_ia=0,5*phi_int
+!
+!--          Calculation mass specific thermal load implied non thermal mass 
+             phi_st  =   ( 1 - ( eff_mass_area / total_area ) - ( h_tr_w / ( 9.1 * total_area ) ) ) &
+                       * ( phi_ia + phi_sol )                                       !< [W] Eq. (C.3) with phi_ia=0,5*phi_int
+!
+!--          Calculations for deriving indoor temperature and heat flux into the wall
+!--          Step 1: Indoor temperature without heating and cooling
+!--          section C.4.1 Picture C.2 zone 3)
+             phi_hc_nd = 0
+             
+             CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
+                                         near_facade_temperature, phi_hc_nd )
+!
+!--          If air temperature between border temperatures of heating and cooling, assign output variable, then ready   
+             IF ( theta_int_h_set <= theta_air  .AND.  theta_air <= theta_int_c_set )  THEN
+                phi_hc_nd_ac = 0
+                phi_hc_nd    = phi_hc_nd_ac
+                theta_air_ac = theta_air
+!
+!--          Step 2: Else, apply 10 W/mÂ² heating/cooling power and calculate indoor temperature
+!--          again.
+             ELSE
+!
+!--             Temperature not correct, calculation method according to section C4.2
+                theta_air_0 = theta_air !< Note temperature without heating/cooling
+
+!--             Heating or cooling?
+                IF ( theta_air > theta_int_c_set )  THEN
+                   theta_air_set = theta_int_c_set
+                ELSE 
+                   theta_air_set = theta_int_h_set 
+                ENDIF
+
+!--             Calculate the temperature with phi_hc_nd_10 
+                phi_hc_nd_10 = 10.0_wp * floor_area_per_facade
+                phi_hc_nd    = phi_hc_nd_10
+       
+                CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
+                                            near_facade_temperature, phi_hc_nd )
+
+                theta_air_10 = theta_air !< Note the temperature with 10 W/m2 of heating
+!
+   
+                phi_hc_nd_un = phi_hc_nd_10 * (theta_air_set - theta_air_0)                        &
+                                            / (theta_air_10  - theta_air_0)            !< Eq. (C.13)
+                                            
+                                            
+                                        
+!--             Step 3: With temperature ratio to determine the heating or cooling capacity    
+!--             If necessary, limit the power to maximum power
+!--             section C.4.1 Picture C.2 zone 2) and 4)
+                IF ( phi_c_max < phi_hc_nd_un  .AND.  phi_hc_nd_un < phi_h_max )  THEN
+                   phi_hc_nd_ac = phi_hc_nd_un
+                   phi_hc_nd = phi_hc_nd_un    
+                ELSE
+!--             Step 4: Inner temperature with maximum heating (phi_hc_nd_un positive) or cooling (phi_hc_nd_un negative)
+!--             section C.4.1 Picture C.2 zone 1) and 5)
+                   IF ( phi_hc_nd_un > 0 )  THEN
+                      phi_hc_nd_ac = phi_h_max                                         !< Limit heating
+                   ELSE 
+                      phi_hc_nd_ac = phi_c_max                                         !< Limit cooling
+                   ENDIF
+                ENDIF
+       
+                phi_hc_nd = phi_hc_nd_ac   
+!
+!--             Calculate the temperature with phi_hc_nd_ac (new)
+                CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
+                                            near_facade_temperature, phi_hc_nd )
+
+                theta_air_ac = theta_air
+       
+             ENDIF
+!
+!--          Update theta_m_t_prev
+             theta_m_t_prev = theta_m_t
+!
+!--          Calculate the operating temperature with weighted mean temperature of air and mean solar temperature
+!--          Will be used for thermal comfort calculations 
+             theta_op     = 0.3 * theta_air_ac + 0.7 * theta_s          !< [Â°C] operative Temperature Eq. (C.12)
+!
+!--          Heat flux into the wall. Value needed in urban_surface_mod to 
+!--          calculate heat transfer through wall layers towards the facade
+!--          (use c_p * rho_surface to convert [W/m2] into [K m/s])
+             q_wall_win = h_tr_ms * ( theta_s - theta_m )                    &
+                                    / (   facade_element_area                  &
+                                        - window_area_per_facade )
+!
+!--          Transfer q_wall_win back to USM (innermost wall/window layer)
+             surf_usm_h%iwghf_eb(m)        = q_wall_win
+             surf_usm_h%iwghf_eb_window(m) = q_wall_win
+!
+!--          Sum up operational indoor temperature per kk-level. Further below,
+!--          this temperature is reduced by MPI to one temperature per kk-level
+!--          and building (processor overlapping)
+             buildings(nb)%t_in_l(kk) = buildings(nb)%t_in_l(kk) + theta_op
+!
+!--          Calculation of waste heat
+!--          Anthropogenic heat output
+              IF ( phi_hc_nd_ac > 0 )  THEN 
+                   heating_on = 1
+                   cooling_on = 0
+              ELSE 
+                   heating_on = 0
+                   cooling_on = 1
+              ENDIF
+
+             q_waste_heat = (phi_hc_nd * (params_waste_heat_h * heating_on + params_waste_heat_c * cooling_on))  !< [W/m2]  anthropogenic heat output
+!              surf_usm_h%shf(m)=q_waste_heat
+             
+          ENDDO !< Horizontal surfaces loop
+!
+!--       Vertical surfaces
+          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)
+!
+!--          Determine building height level index. 
+             kk = surf_usm_v(l)%k(m) + surf_usm_v(l)%koff
+!
+!--          Building geometries  --> not time-dependent
+             IF ( l == 0  .OR. l == 1 ) facade_element_area = dx * dzw(kk)  !< [m2] surface area per facade element
+             IF ( l == 2  .OR. l == 3 ) facade_element_area = dy * dzw(kk)  !< [m2] surface area per facade element
+             floor_area_per_facade    = buildings(nb)%vpf(kk) * ddzw(kk)    !< [m2] net floor area per facade element       
+             indoor_volume_per_facade = buildings(nb)%vpf(kk)               !< [m3] indoor air volume per facade element           
+             window_area_per_facade   = surf_usm_v(l)%frac(ind_wat_win,m)  * facade_element_area  !< [m2] window area per facade element
+             eff_mass_area            = factor_a * floor_area_per_facade    !< [m2] standard values according to Table 12 section 12.3.1.2  (calculate over Eq. (65) according to section 12.3.1.2)
+             c_m                      = factor_c * floor_area_per_facade    !< [J/K] standard values according to table 12 section 12.3.1.2 (calculate over Eq. (66) according to section 12.3.1.2)
+             total_area               = lambda_at * floor_area_per_facade   !< [m2] area of all surfaces pointing to zone Eq. (9) according to section 7.2.2.2
+!
+!--          Calculation of heat transfer coefficient for transmission --> not time-dependent
+             h_tr_w   = window_area_per_facade * u_value_win   !< [W/K] only for windows
+             h_tr_is  = total_area * h_is                      !< [W/K] with h_is = 3.45 W / (m2 K) between surface and air, Eq. (9)
+             h_tr_ms  = eff_mass_area * h_ms                   !< [W/K] with h_ms = 9.10 W / (m2 K) between component and surface, Eq. (64)
+             h_tr_op  = 1 / ( 1 / ( ( facade_element_area - window_area_per_facade ) &
+                                    * lambda_layer3 / s_layer3 * 0.5 ) + 1 / h_tr_ms )
+             h_tr_em  = 1 / ( 1 / h_tr_op - 1 / h_tr_ms )      !< [W/K] Eq. (63), Section 12.2.2
+!
+!--          internal air loads dependent on the occupacy of the room
+!--          basical internal heat gains (qint_low) with additional internal heat gains by occupancy (qint_high) (0,5*phi_int)
+             phi_ia = 0.5 * ( ( qint_high * schedule_d + qint_low )            &
+                              * floor_area_per_facade )                      !< [W] Eq. (C.1)
+!
+!--          Airflow dependent on the occupacy of the room
+!--          basical airflow (air_change_low) with additional airflow gains by occupancy (air_change_high)
+             air_change = ( air_change_high * schedule_d + air_change_low )  
+!
+!--          Heat transfer of ventilation 
+!--          not less than 0.01 W/K to provide division by 0 in further calculations
+!--          with heat capacity of air 0.33 Wh/m2K
+             h_ve   = MAX( 0.01 , ( air_change * indoor_volume_per_facade *      &
+                                    0.33 * (1 - eta_ve ) ) )                    !< [W/K] from ISO 13789 Eq.(10) 
+                                    
+!--          Heat transfer coefficient auxiliary variables
+             h_tr_1 = 1 / ( ( 1 / h_ve )   + ( 1 / h_tr_is ) )                  !< [W/K] Eq. (C.6)
+             h_tr_2 = h_tr_1 + h_tr_w                                           !< [W/K] Eq. (C.7)
+             h_tr_3 = 1 / ( ( 1 / h_tr_2 ) + ( 1 / h_tr_ms ) )                  !< [W/K] Eq. (C.8)
+!
+!--          Net short-wave radiation through window area (was i_global)
+             net_sw_in = surf_usm_v(l)%rad_sw_in(m) - surf_usm_v(l)%rad_sw_out(m)
+!
+!--          Quantities needed for im_calc_temperatures
+             i = surf_usm_v(l)%i(m)
+             j = surf_usm_v(l)%j(m)
+             k = surf_usm_v(l)%k(m)
+             near_facade_temperature = t_surf_10cm_v(l)%t(m)
+             indoor_wall_window_temperature =                                    &
+                  surf_usm_v(l)%frac(ind_veg_wall,m) * t_wall_v(l)%t(nzt_wall,m) &
+                + surf_usm_v(l)%frac(ind_wat_win,m)  * t_window_v(l)%t(nzt_wall,m)
+!
+!--          Solar thermal gains. If net_sw_in larger than sun-protection 
+!--          threshold parameter (params_solar_protection), sun protection will 
+!--          be activated
+             IF ( net_sw_in <= params_solar_protection )  THEN 
+                solar_protection_off = 1
+                solar_protection_on  = 0 
+             ELSE 
+                solar_protection_off = 0
+                solar_protection_on  = 1 
+             ENDIF
+!
+!--          Calculation of total heat gains from net_sw_in through windows [W] in respect on automatic sun protection
+!--          DIN 4108 - 2 chap.8
+             phi_sol = (   window_area_per_facade * net_sw_in * solar_protection_off               &
+                         + window_area_per_facade * net_sw_in * f_c_win * solar_protection_on )    &
+                       * g_value_win * ( 1 - params_f_f ) * params_f_w
+!
+!--          Calculation of the mass specific thermal load for internal and external heatsources
+             phi_m   = (eff_mass_area / total_area) * ( phi_ia + phi_sol )          !< [W] Eq. (C.2) with phi_ia=0,5*phi_int
+!
+!--          Calculation mass specific thermal load implied non thermal mass 
+             phi_st  =   ( 1 - ( eff_mass_area / total_area ) - ( h_tr_w / ( 9.1 * total_area ) ) ) &
+                       * ( phi_ia + phi_sol )                                       !< [W] Eq. (C.3) with phi_ia=0,5*phi_int
+!
+!--          Calculations for deriving indoor temperature and heat flux into the wall
+!--          Step 1: Indoor temperature without heating and cooling
+!--          section C.4.1 Picture C.2 zone 3)
+             phi_hc_nd = 0
+             
+             CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
+                                         near_facade_temperature, phi_hc_nd )
+!
+!--          If air temperature between border temperatures of heating and cooling, assign output variable, then ready  
+             IF ( theta_int_h_set <= theta_air  .AND.  theta_air <= theta_int_c_set )  THEN
+                phi_hc_nd_ac = 0
+                phi_hc_nd    = phi_hc_nd_ac
+                theta_air_ac = theta_air
+!
+!--          Step 2: Else, apply 10 W/mÂ² heating/cooling power and calculate indoor temperature
+!--          again.
+             ELSE
+!
+!--             Temperature not correct, calculation method according to section C4.2
+                theta_air_0 = theta_air !< Note temperature without heating/cooling
+
+!--             Heating or cooling?
+                IF ( theta_air > theta_int_c_set )  THEN
+                   theta_air_set = theta_int_c_set
+                ELSE 
+                   theta_air_set = theta_int_h_set 
+                ENDIF
+
+!--             Calculate the temperature with phi_hc_nd_10
+                phi_hc_nd_10 = 10.0_wp * floor_area_per_facade
+                phi_hc_nd    = phi_hc_nd_10
+       
+                CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
+                                            near_facade_temperature, phi_hc_nd )
+
+                theta_air_10 = theta_air !< Note the temperature with 10 W/m2 of heating
+
+                
+                phi_hc_nd_un = phi_hc_nd_10 * (theta_air_set - theta_air_0)                        &
+                                            / (theta_air_10  - theta_air_0)            !< Eq. (C.13)
+!      
+!--             Step 3: With temperature ratio to determine the heating or cooling capacity    
+!--             If necessary, limit the power to maximum power
+!--             section C.4.1 Picture C.2 zone 2) and 4)
+                IF ( phi_c_max < phi_hc_nd_un  .AND.  phi_hc_nd_un < phi_h_max )  THEN
+                   phi_hc_nd_ac = phi_hc_nd_un
+                   phi_hc_nd = phi_hc_nd_un
+                ELSE
+!--             Step 4: Inner temperature with maximum heating (phi_hc_nd_un positive) or cooling (phi_hc_nd_un negative)
+!--             section C.4.1 Picture C.2 zone 1) and 5)
+                   IF ( phi_hc_nd_un > 0 )  THEN
+                      phi_hc_nd_ac = phi_h_max                                         !< Limit heating
+                   ELSE 
+                      phi_hc_nd_ac = phi_c_max                                         !< Limit cooling
+                   ENDIF
+                ENDIF
+       
+                phi_hc_nd = phi_hc_nd_ac   
+!
+!--             Calculate the temperature with phi_hc_nd_ac (new)
+                CALL im_calc_temperatures ( i, j, k, indoor_wall_window_temperature, &
+                                            near_facade_temperature, phi_hc_nd )
+
+                theta_air_ac = theta_air
+       
+             ENDIF
+!
+!--          Update theta_m_t_prev
+             theta_m_t_prev = theta_m_t
+!
+!--          Calculate the operating temperature with weighted mean of temperature of air and mean
+!--          Will be used for thermal comfort calculations 
+             theta_op     = 0.3 * theta_air_ac + 0.7 * theta_s
+!
+!--          Heat flux into the wall. Value needed in urban_surface_mod to 
+!--          calculate heat transfer through wall layers towards the facade
+             q_wall_win = h_tr_ms * ( theta_s - theta_m )                    &
+                                    / (   facade_element_area                  &
+                                        - window_area_per_facade )
+!
+!--          Transfer q_wall_win back to USM (innermost wall/window layer)
+             surf_usm_v(l)%iwghf_eb(m)        = q_wall_win
+             surf_usm_v(l)%iwghf_eb_window(m) = q_wall_win
+!
+!--          Sum up operational indoor temperature per kk-level. Further below,
+!--          this temperature is reduced by MPI to one temperature per kk-level
+!--          and building (processor overlapping)
+             buildings(nb)%t_in_l(kk) = buildings(nb)%t_in_l(kk) + theta_op
+
+!
+!--          Calculation of waste heat
+!--          Anthropogenic heat output
+              IF ( phi_hc_nd_ac > 0 )  THEN 
+                   heating_on = 1
+                   cooling_on = 0
+              ELSE 
+                   heating_on = 0
+                   cooling_on = 1
+              ENDIF
+
+             q_waste_heat = (phi_hc_nd * (params_waste_heat_h * heating_on + params_waste_heat_c * cooling_on))   !< [W/m2] , anthropogenic heat output
+!              surf_usm_v(l)%waste_heat(m)=q_waste_heat
+             
+          ENDDO !< Vertical surfaces loop
+
+       ENDIF !< buildings(nb)%on_pe
+    ENDDO !< buildings loop
+
+!
+!-- Determine total number of facade elements per building and assign number to 
+!-- building data type.
+    DO  nb = 1, num_build
+!
+!--    Allocate dummy array used for summing-up facade elements. 
+!--    Please note, dummy arguments are necessary as building-date type
+!--    arrays are not necessarily allocated on all PEs.
+       ALLOCATE( t_in_l_send(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+       ALLOCATE( t_in_recv(buildings(nb)%kb_min:buildings(nb)%kb_max) )
+       t_in_l_send = 0.0_wp
+       t_in_recv   = 0.0_wp
+
+       IF ( buildings(nb)%on_pe )  THEN
+          t_in_l_send = buildings(nb)%t_in_l
+       ENDIF
+
+#if defined( __parallel ) 
+       CALL MPI_ALLREDUCE( t_in_l_send,                                        &
+                           t_in_recv,                                          &
+                           buildings(nb)%kb_max - buildings(nb)%kb_min + 1,    &
+                           MPI_REAL,                                           &
+                           MPI_SUM,                                            &
+                           comm2d,                                             &
+                           ierr )
+
+       IF ( ALLOCATED( buildings(nb)%t_in ) )                                  &
+           buildings(nb)%t_in = t_in_recv
+#else
+       buildings(nb)%t_in = buildings(nb)%t_in_l
+#endif
+
+       buildings(nb)%t_in =   buildings(nb)%t_in /                             &
+                            ( buildings(nb)%num_facade_h +                     &
+                              buildings(nb)%num_facade_v )
+!
+!--    Deallocate dummy arrays
+       DEALLOCATE( t_in_l_send )
+       DEALLOCATE( t_in_recv )
+
+    ENDDO
+
+
+ END SUBROUTINE im_main_heatcool
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Parin for &indoor_parameters for indoor model
+!------------------------------------------------------------------------------!
+ SUBROUTINE im_parin
+    
+    USE control_parameters,                                                    &
+        ONLY:  indoor_model
+    
+    IMPLICIT NONE
+
+    CHARACTER (LEN=80) ::  line  !< string containing current line of file PARIN
+
+    
+    
+    NAMELIST /indoor_parameters/  building_type, dt_indoor,                           &
+                                  initial_indoor_temperature
+
+!    line = ' '
+
+!
+!-- Try to find indoor model package
+    REWIND ( 11 )
+    line = ' '
+    DO   WHILE ( INDEX( line, '&indoor_parameters' ) == 0 )
+       READ ( 11, '(A)', END=10 )  line
+!    PRINT*, 'line: ', line
+    ENDDO
+    BACKSPACE ( 11 )
+
+!
+!-- Read user-defined namelist
+    READ ( 11, indoor_parameters )
+!
+!-- Set flag that indicates that the indoor model is switched on
+    indoor_model = .TRUE.
+
+!
+!--    Activate spinup (maybe later
+!        IF ( spinup_time > 0.0_wp )  THEN
+!           coupling_start_time = spinup_time
+!           end_time = end_time + spinup_time
+!           IF ( spinup_pt_mean == 9999999.9_wp )  THEN
+!              spinup_pt_mean = pt_surface
+!           ENDIF
+!           spinup = .TRUE.
+!        ENDIF
+
+ 10 CONTINUE
+    
+ END SUBROUTINE im_parin
+
+
+END MODULE indoor_model_mod
Index: palm/trunk/SOURCE/init_3d_model.f90
===================================================================
--- palm/trunk/SOURCE/init_3d_model.f90	(revision 3468)
+++ palm/trunk/SOURCE/init_3d_model.f90	(revision 3469)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Add indoor model (kanani, srissman, tlang)
+! 
+! 3467 2018-10-30 19:05:21Z suehring
 ! Implementation of a new aerosol module salsa.
 ! 
@@ -567,5 +570,8 @@
 
     USE indices
-    
+
+    USE indoor_model_mod,                                                      &
+        ONLY:  im_init
+
     USE kinds
 
@@ -2447,4 +2453,12 @@
 
 !
+!-- If required, initialize indoor model
+    IF ( indoor_model )  THEN
+       CALL location_message( 'initializing indoor model', .FALSE. )
+       CALL im_init
+       CALL location_message( 'finished', .TRUE. )
+    ENDIF
+
+!
 !-- Initialize the ws-scheme.    
     IF ( ws_scheme_sca .OR. ws_scheme_mom )  CALL ws_init
Index: palm/trunk/SOURCE/modules.f90
===================================================================
--- palm/trunk/SOURCE/modules.f90	(revision 3468)
+++ palm/trunk/SOURCE/modules.f90	(revision 3469)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Add indoor model (kanani, srissman, tlang)
+! 
+! 3467 2018-10-30 19:05:21Z suehring
 ! Add biometeorology
 ! 
@@ -1345,4 +1348,5 @@
     LOGICAL ::  humidity = .FALSE.                               !< namelist parameter
     LOGICAL ::  humidity_remote = .FALSE.                        !< switch for receiving near-surface humidity flux (atmosphere-ocean coupling)
+    LOGICAL ::  indoor_model = .FALSE.                           !< switch for indoor-climate and energy-demand model
     LOGICAL ::  large_scale_forcing = .FALSE.                    !< namelist parameter
     LOGICAL ::  large_scale_subsidence = .FALSE.                 !< namelist parameter
Index: palm/trunk/SOURCE/parin.f90
===================================================================
--- palm/trunk/SOURCE/parin.f90	(revision 3468)
+++ palm/trunk/SOURCE/parin.f90	(revision 3469)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Add indoor model (kanani, srissman, tlang),
+! minor formatting
+! 
+! 3467 2018-10-30 19:05:21Z suehring
 ! Implementation of a new aerosol module salsa.
 ! 
@@ -484,4 +488,7 @@
     USE indices,                                                               &
         ONLY:  nx, ny, nz
+
+    USE indoor_model_mod,                                                      &
+        ONLY:  im_parin
 
     USE kinds
@@ -917,8 +924,6 @@
           CALL chem_parin
           CALL uvem_parin
-!
-!--       Check if SALSA processes should be carried out and read &salsa_par
-!--       if required
-          CALL salsa_parin          
+          CALL im_parin
+          CALL salsa_parin
 !
 !--       Read user-defined variables
Index: palm/trunk/SOURCE/time_integration.f90
===================================================================
--- palm/trunk/SOURCE/time_integration.f90	(revision 3468)
+++ palm/trunk/SOURCE/time_integration.f90	(revision 3469)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Add indoor model (kanani, srissman, tlang)
+! 
+! 3467 2018-10-30 19:05:21Z suehring
 ! Implementation of a new aerosol module salsa.
 ! 
@@ -433,5 +436,5 @@
                dt_dopr_listing, dt_dots, dt_dvrp, dt_run_control, end_time,    &
                first_call_lpm, first_call_mas, galilei_transformation,         &
-               humidity, intermediate_timestep_count,                          &
+               humidity, indoor_model, intermediate_timestep_count,            &
                intermediate_timestep_count_max,                                &
                land_surface, large_scale_forcing,                              &
@@ -471,4 +474,7 @@
     USE indices,                                                               &
         ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, nzb, nzt
+
+    USE indoor_model_mod,                                                      &
+        ONLY:  dt_indoor, im_main_heatcool, skip_time_do_indoor, time_indoor
 
     USE interaction_droplets_ptq_mod,                                          &
@@ -1248,4 +1254,24 @@
        ENDIF
 !
+!--    If required, calculate indoor temperature, waste heat, heat flux
+!--    through wall, etc.
+!--    dt_indoor steers the frequency of the indoor model calculations
+       IF (       indoor_model                                                    &
+            .AND. intermediate_timestep_count == intermediate_timestep_count_max  &
+            .AND. time_since_reference_point > skip_time_do_indoor )  THEN
+
+          time_indoor = time_indoor + dt_3d
+
+          IF ( time_indoor >= dt_indoor )  THEN
+
+             time_indoor = time_indoor - dt_indoor
+
+             CALL cpu_log( log_point(76), 'indoor_model', 'start' )
+             CALL im_main_heatcool
+             CALL cpu_log( log_point(76), 'indoor_model', 'stop' )
+
+          ENDIF
+       ENDIF
+!
 !--    Increase simulation time and output times
        nr_timesteps_this_run      = nr_timesteps_this_run + 1
Index: palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3468)
+++ palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3469)
@@ -28,4 +28,7 @@
 ! -----------------
 ! $Id$
+! Add missing PUBLIC variables for new indoor model
+! 
+! 3449 2018-10-29 19:36:56Z suehring
 ! Bugfix: Fix average arrays allocations in usm_average_3d_data (J.Resler)
 ! Bugfix: Fix reading wall temperatures (J.Resler)
@@ -1251,5 +1254,7 @@
 !-- Public parameters, constants and initial values
     PUBLIC usm_anthropogenic_heat, usm_material_model, usm_wall_mod,           &
-           usm_green_heat_model, usm_temperature_near_surface, building_pars
+           usm_green_heat_model, usm_temperature_near_surface, building_pars,  &
+           nzt_wall, t_surf_10cm_h, t_surf_10cm_v, t_wall_h, t_wall_v,         &
+           t_window_h, t_window_v, building_type
 
 
