Index: palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3743)
+++ palm/trunk/SOURCE/urban_surface_mod.f90	(revision 3744)
@@ -23,5 +23,8 @@
 ! Current revisions:
 ! ------------------
-! 
+! - Remove internal flag indoor_model (is a global control parameter)
+! - add waste heat from buildings to the kinmatic heat flux
+! - consider waste heat in restart data
+! - remove unused USE statements
 ! 
 ! Former revisions:
@@ -401,10 +404,8 @@
 !> @todo Output of _av variables in case of restarts
 !> @todo Revise flux conversion in energy-balance solver
-!> @todo Bugfixing in nopointer branch 
 !> @todo Check optimizations for RMA operations
 !> @todo Alternatives for MPI_WIN_ALLOCATE? (causes problems with openmpi)
 !> @todo Check for load imbalances in CPU measures, e.g. for exchange_horiz_prog
 !>       factor 3 between min and max time
-!> @todo Move setting of flag indoor_model to indoor_model_mod once available
 !> @todo Check divisions in wtend (etc.) calculations for possible division
 !>       by zero, e.g. in case fraq(0,m) + fraq(1,m) = 0?!
@@ -424,5 +425,5 @@
 
     USE control_parameters,                                                    &
-        ONLY:  coupling_start_time, topography, dt_3d, humidity,               &
+        ONLY:  coupling_start_time, topography, dt_3d, humidity, indoor_model, &
                intermediate_timestep_count, initializing_actions,              &
                intermediate_timestep_count_max, simulated_time, end_time,      &
@@ -431,6 +432,5 @@
                pt_surface, large_scale_forcing, lsf_surf, spinup,              &
                spinup_pt_mean, spinup_time, time_do3d, dt_do3d,                &
-               average_count_3d, varnamelength, urban_surface,                 &
-               plant_canopy, dz
+               average_count_3d, varnamelength, urban_surface, dz
 
     USE bulk_cloud_model_mod,                                                  &
@@ -455,8 +455,5 @@
               
     USE pegrid
-    
-    USE plant_canopy_model_mod,                                                &
-        ONLY:  pc_heating_rate, pc_transpiration_rate, pc_latent_rate
-    
+        
     USE radiation_model_mod,                                                   &
         ONLY:  albedo_type, radiation_interaction, calc_zenith, zenith,        &
@@ -535,5 +532,4 @@
                                                    !< (e.g.transportation) are used
     LOGICAL ::  force_radiation_call_l = .FALSE.   !< flag parameter for unscheduled radiation model calls
-    LOGICAL ::  indoor_model = .FALSE.             !< whether to use the indoor model
     LOGICAL ::  read_wall_temp_3d = .FALSE.
     LOGICAL ::  usm_wall_mod = .FALSE.             !< reduces conductivity of the first 2 wall layers by factor 0.1
@@ -1257,5 +1253,16 @@
            ALLOCATE ( surf_usm_v(l)%target_temp_summer(1:surf_usm_v(l)%ns) )
            ALLOCATE ( surf_usm_v(l)%target_temp_winter(1:surf_usm_v(l)%ns) )
-        ENDDO   
+        ENDDO
+!
+!--     In case the indoor model is applied, allocate memory for waste heat 
+!--     and indoor temperature.
+        IF ( indoor_model )  THEN
+           ALLOCATE ( surf_usm_h%waste_heat(1:surf_usm_h%ns) )
+           surf_usm_h%waste_heat = 0.0_wp
+           DO  l = 0, 3
+              ALLOCATE ( surf_usm_v(l)%waste_heat(1:surf_usm_v(l)%ns) )
+              surf_usm_v(l)%waste_heat = 0.0_wp
+           ENDDO
+        ENDIF
 !
 !--     Allocate flag indicating ground floor level surface elements
@@ -6054,5 +6061,4 @@
                            usm_material_model,                                 &
                            wall_category,                                      &
-                           indoor_model,                                       &
                            wall_inner_temperature,                             &
                            roof_inner_temperature,                             &
@@ -6073,5 +6079,4 @@
                            usm_material_model,                                 &
                            wall_category,                                      &
-                           indoor_model,                                       &
                            wall_inner_temperature,                             &
                            roof_inner_temperature,                             &
@@ -6264,10 +6269,22 @@
 
        LOGICAL, INTENT(OUT)  ::  found 
+!!!    suehring: Why the SAVE attribute?       
+       REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE   ::  tmp_surf_wall_h
+       REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE   ::  tmp_surf_window_h
+       REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE   ::  tmp_surf_green_h
+       REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE   ::  tmp_surf_waste_h
        
-       REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE   ::  tmp_surf_wall_h, tmp_surf_window_h, tmp_surf_green_h
-       REAL(wp), DIMENSION(:,:), ALLOCATABLE, SAVE ::  tmp_wall_h, tmp_window_h, tmp_green_h
+       REAL(wp), DIMENSION(:,:), ALLOCATABLE, SAVE ::  tmp_wall_h
+       REAL(wp), DIMENSION(:,:), ALLOCATABLE, SAVE ::  tmp_window_h
+       REAL(wp), DIMENSION(:,:), ALLOCATABLE, SAVE ::  tmp_green_h
        
-       TYPE( t_surf_vertical ), DIMENSION(0:3), SAVE ::  tmp_surf_wall_v, tmp_surf_window_v, tmp_surf_green_v
-       TYPE( t_wall_vertical ), DIMENSION(0:3), SAVE ::  tmp_wall_v, tmp_window_v, tmp_green_v
+       TYPE( t_surf_vertical ), DIMENSION(0:3), SAVE ::  tmp_surf_wall_v
+       TYPE( t_surf_vertical ), DIMENSION(0:3), SAVE ::  tmp_surf_window_v
+       TYPE( t_surf_vertical ), DIMENSION(0:3), SAVE ::  tmp_surf_green_v
+       TYPE( t_surf_vertical ), DIMENSION(0:3), SAVE ::  tmp_surf_waste_v
+       
+       TYPE( t_wall_vertical ), DIMENSION(0:3), SAVE ::  tmp_wall_v
+       TYPE( t_wall_vertical ), DIMENSION(0:3), SAVE ::  tmp_window_v
+       TYPE( t_wall_vertical ), DIMENSION(0:3), SAVE ::  tmp_green_v
 
 
@@ -6289,4 +6306,6 @@
                       DEALLOCATE( tmp_surf_green_h ) 
                    IF ( ALLOCATED( tmp_green_h) ) DEALLOCATE( tmp_green_h )
+                   IF ( ALLOCATED( tmp_surf_waste_h) )                         &
+                      DEALLOCATE( tmp_surf_waste_h )
   
 !
@@ -6305,4 +6324,5 @@
                    ALLOCATE( tmp_green_h(nzb_wall:nzt_wall+1,                  &
                                          1:ns_h_on_file_usm) )
+                   ALLOCATE( tmp_surf_waste_h(1:ns_h_on_file_usm) )
 
                 ENDIF
@@ -6325,4 +6345,6 @@
                       IF ( ALLOCATED( tmp_green_v(l)%t ) )                     &
                          DEALLOCATE( tmp_green_v(l)%t )
+                      IF ( ALLOCATED( tmp_surf_waste_v(l)%t ) )                &
+                         DEALLOCATE( tmp_surf_waste_v(l)%t )
                    ENDDO 
 
@@ -6343,4 +6365,5 @@
                       ALLOCATE( tmp_green_v(l)%t(nzb_wall:nzt_wall+1,          &
                                                  1:ns_v_on_file_usm(l) ) )
+                      ALLOCATE( tmp_surf_waste_v(l)%t(1:ns_v_on_file_usm(l)) )
                    ENDDO
 
@@ -6614,4 +6637,89 @@
                                         t_surf_window_v_1(3)%t,                &  
                                         tmp_surf_window_v(3)%t,                &
+                                        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 ( 'waste_heat_h' )
+                IF ( k == 1 )  THEN
+                   IF ( .NOT.  ALLOCATED( surf_usm_h%waste_heat ) )            &
+                      ALLOCATE( surf_usm_h%waste_heat(1:surf_usm_h%ns) )
+                   READ ( 13 )  tmp_surf_waste_h
+                ENDIF              
+                CALL surface_restore_elements(                                 &
+                                        surf_usm_h%waste_heat,                 &
+                                        tmp_surf_waste_h,                      &
+                                        surf_usm_h%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 ( 'waste_heat_v(0)' )
+                IF ( k == 1 )  THEN
+                   IF ( .NOT.  ALLOCATED( surf_usm_v(0)%waste_heat ) )         &
+                      ALLOCATE( surf_usm_v(0)%waste_heat(1:surf_usm_v(0)%ns) )
+                   READ ( 13 )  tmp_surf_waste_v(0)%t
+                ENDIF
+                CALL surface_restore_elements(                                 &
+                                        surf_usm_v(0)%waste_heat,              &
+                                        tmp_surf_waste_v(0)%t,                 &
+                                        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 ( 'waste_heat_v(1)' )
+                IF ( k == 1 )  THEN
+                   IF ( .NOT.  ALLOCATED( surf_usm_v(1)%waste_heat ) )         &
+                      ALLOCATE( surf_usm_v(1)%waste_heat(1:surf_usm_v(1)%ns) )
+                   READ ( 13 )  tmp_surf_waste_v(1)%t
+                ENDIF
+                CALL surface_restore_elements(                                 &
+                                        surf_usm_v(1)%waste_heat,              &
+                                        tmp_surf_waste_v(1)%t,                 &
+                                        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 ( 'waste_heat_v(2)' )
+                IF ( k == 1 )  THEN
+                   IF ( .NOT.  ALLOCATED( surf_usm_v(2)%waste_heat ) )         &
+                      ALLOCATE( surf_usm_v(2)%waste_heat(1:surf_usm_v(2)%ns) )
+                   READ ( 13 )  tmp_surf_waste_v(2)%t
+                ENDIF
+                CALL surface_restore_elements(                                 &
+                                        surf_usm_v(2)%waste_heat,              &
+                                        tmp_surf_waste_v(2)%t,                 &
+                                        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 ( 'waste_heat_v(3)' )
+                IF ( k == 1 )  THEN
+                   IF ( .NOT.  ALLOCATED( surf_usm_v(3)%waste_heat ) )         &
+                      ALLOCATE( surf_usm_v(3)%waste_heat(1:surf_usm_v(3)%ns) )
+                   READ ( 13 )  tmp_surf_waste_v(3)%t
+                ENDIF
+                CALL surface_restore_elements(                                 &
+                                        surf_usm_v(3)%waste_heat,              &
+                                        tmp_surf_waste_v(3)%t,                 &
                                         surf_usm_v(3)%start_index,             & 
                                         start_index_on_file,                   &
@@ -7627,5 +7735,5 @@
         j_off = surf_usm_h%joff
         i_off = surf_usm_h%ioff
-
+        
 !        
 !--     First, treat horizontal surface elements
@@ -7957,4 +8065,10 @@
 !--        diffusion_s, surface_layer_fluxes,...
            surf_usm_h%shf(m) = surf_usm_h%wshf_eb(m) / c_p
+!
+!--        If the indoor model is applied, further add waste heat from buildings to the 
+!--        kinematic flux.
+           IF ( indoor_model )  THEN
+              surf_usm_h%shf(m) = surf_usm_h%shf(m) + surf_usm_h%waste_heat(m) / rho_cp
+           ENDIF
       
 
@@ -8382,4 +8496,11 @@
 !--           diffusion_s, surface_layer_fluxes,...
               surf_usm_v(l)%shf(m) = surf_usm_v(l)%wshf_eb(m) / c_p
+!
+!--           If the indoor model is applied, further add waste heat from buildings to the 
+!--           kinematic flux.
+              IF ( indoor_model )  THEN
+                 surf_usm_v(l)%shf(m) = surf_usm_v(l)%shf(m) +                       &
+                                        surf_usm_v(l)%waste_heat(m) / rho_cp
+              ENDIF              
 
               IF ( surf_usm_v(l)%frac(ind_pav_green,m) > 0.0_wp ) THEN
@@ -8685,5 +8806,17 @@
         CALL wrd_write_string( 't_surf_green_h' )
         WRITE ( 14 )  t_surf_green_h
- 
+!
+!--     Write restart data which is especially needed for the urban-surface 
+!--     model. In order to do not fill up the restart routines in 
+!--     surface_mod. 
+!--     Output of waste heat from indoor model. Restart data is required in 
+!--     this special case, because the indoor model where waste heat is 
+!--     computed is call each hour (current default), so that waste heat would
+!--     have zero value until next call of indoor model. 
+        IF ( indoor_model )  THEN
+           CALL wrd_write_string( 'waste_heat_h' )
+           WRITE ( 14 )  surf_usm_h%waste_heat
+        ENDIF   
+           
         DO  l = 0, 3
  
@@ -8703,5 +8836,10 @@
  
            CALL wrd_write_string( 't_surf_green_v(' // dum // ')' )
-           WRITE ( 14 ) t_surf_green_v(l)%t    
+           WRITE ( 14 ) t_surf_green_v(l)%t  
+           
+           IF ( indoor_model )  THEN
+              CALL wrd_write_string( 'waste_heat_v(' // dum // ')' )
+              WRITE ( 14 )  surf_usm_v(l)%waste_heat
+           ENDIF
            
         ENDDO
@@ -8742,5 +8880,4 @@
         
         ENDDO
- 
         
      END SUBROUTINE usm_wrd_local
