source: palm/trunk/SOURCE/urban_surface_mod.f90 @ 3351

Last change on this file since 3351 was 3351, checked in by suehring, 7 years ago

Do not overwrite values of albedo in radiation_init in case albedo has been already initialized in the urban-surface model via ASCII input

  • Property svn:keywords set to Id
File size: 442.2 KB
Line 
1!> @file urban_surface_mod.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 2015-2018 Czech Technical University in Prague
18! Copyright 2015-2018 Institute of Computer Science of the
19!                     Czech Academy of Sciences, Prague
20! Copyright 1997-2018 Leibniz Universitaet Hannover
21!------------------------------------------------------------------------------!
22!
23! Current revisions:
24! ------------------
25!
26!
27! Former revisions:
28! -----------------
29! $Id: urban_surface_mod.f90 3351 2018-10-15 18:40:42Z suehring $
30! Set flag indicating that albedo at urban surfaces is already initialized
31!
32! 3347 2018-10-15 14:21:08Z suehring
33! Enable USM initialization with default building parameters in case no static
34! input file exist.
35!
36! 3343 2018-10-15 10:38:52Z suehring
37! Add output variables usm_rad_pc_inlw, usm_rad_pc_insw*
38!
39! 3274 2018-09-24 15:42:55Z knoop
40! Modularization of all bulk cloud physics code components
41!
42! 3248 2018-09-14 09:42:06Z sward
43! Minor formating changes
44!
45! 3246 2018-09-13 15:14:50Z sward
46! Added error handling for input namelist via parin_fail_message
47!
48! 3241 2018-09-12 15:02:00Z raasch
49! unused variables removed
50!
51! 3223 2018-08-30 13:48:17Z suehring
52! Bugfix for commit 3222
53!
54! 3222 2018-08-30 13:35:35Z suehring
55! Introduction of surface array for type and its name
56!
57! 3203 2018-08-23 10:48:36Z suehring
58! Revise bulk parameter for emissivity at ground-floor level
59!
60! 3196 2018-08-13 12:26:14Z maronga
61! Added maximum aerodynamic resistance of 300 for horiztonal surfaces.
62!
63! 3176 2018-07-26 17:12:48Z suehring
64! Bugfix, update virtual potential surface temparture, else heat fluxes on
65! roofs might become unphysical
66!
67! 3152 2018-07-19 13:26:52Z suehring
68! Initialize q_surface, which might be used in surface_layer_fluxes
69!
70! 3151 2018-07-19 08:45:38Z raasch
71! remaining preprocessor define strings __check removed
72!
73! 3136 2018-07-16 14:48:21Z suehring
74! Limit also roughness length for heat and moisture where necessary
75!
76! 3123 2018-07-12 16:21:53Z suehring
77! Correct working precision for INTEGER number
78!
79! 3115 2018-07-10 12:49:26Z suehring
80! Additional building type to represent bridges
81!
82! 3091 2018-06-28 16:20:35Z suehring
83! - Limit aerodynamic resistance at vertical walls.
84! - Add check for local roughness length not exceeding surface-layer height and
85!   limit roughness length where necessary.
86!
87! 3065 2018-06-12 07:03:02Z Giersch
88! Unused array dxdir was removed, dz was replaced by dzu to consider vertical
89! grid stretching
90!
91! 3049 2018-05-29 13:52:36Z Giersch
92! Error messages revised
93!
94! 3045 2018-05-28 07:55:41Z Giersch
95! Error message added
96!
97! 3029 2018-05-23 12:19:17Z raasch
98! bugfix: close unit 151 instead of 90
99!
100! 3014 2018-05-09 08:42:38Z maronga
101! Added pc_transpiration_rate
102!
103! 2977 2018-04-17 10:27:57Z kanani
104! Implement changes from branch radiation (r2948-2971) with minor modifications.
105! (moh.hefny):
106! Extended exn for all model domain height to avoid the need to get nzut.
107!
108! 2963 2018-04-12 14:47:44Z suehring
109! Introduce index for vegetation/wall, pavement/green-wall and water/window
110! surfaces, for clearer access of surface fraction, albedo, emissivity, etc. .
111!
112! 2943 2018-04-03 16:17:10Z suehring
113! Calculate exner function at all height levels and remove some un-used
114! variables.
115!
116! 2932 2018-03-26 09:39:22Z maronga
117! renamed urban_surface_par to urban_surface_parameters
118!
119! 2921 2018-03-22 15:05:23Z Giersch
120! The activation of spinup has been moved to parin
121!
122! 2920 2018-03-22 11:22:01Z kanani
123! Remove unused pcbl, npcbl from ONLY list
124! moh.hefny:
125! Fixed bugs introduced by new structures and by moving radiation interaction
126! into radiation_model_mod.f90.
127! Bugfix: usm data output 3D didn't respect directions
128!
129! 2906 2018-03-19 08:56:40Z Giersch
130! Local variable ids has to be initialized with a value of -1 in
131! usm_average_3d_data
132!
133! 2894 2018-03-15 09:17:58Z Giersch
134! Calculations of the index range of the subdomain on file which overlaps with
135! the current subdomain are already done in read_restart_data_mod,
136! usm_read/write_restart_data have been renamed to usm_r/wrd_local, variable
137! named found has been introduced for checking if restart data was found,
138! reading of restart strings has been moved completely to
139! read_restart_data_mod, usm_rrd_local is already inside the overlap loop
140! programmed in read_restart_data_mod, SAVE attribute added where necessary,
141! deallocation and allocation of some arrays have been changed to take care of
142! different restart files that can be opened (index i), the marker *** end usm
143! *** is not necessary anymore, strings and their respective lengths are
144! written out and read now in case of restart runs to get rid of prescribed
145! character lengths
146!
147! 2805 2018-02-14 17:00:09Z suehring
148! Initialization of resistances.
149!
150! 2797 2018-02-08 13:24:35Z suehring
151! Comment concerning output of ground-heat flux added.
152!
153! 2766 2018-01-22 17:17:47Z kanani
154! Removed redundant commas, added some blanks
155!
156! 2765 2018-01-22 11:34:58Z maronga
157! Major bugfix in calculation of f_shf. Adjustment of roughness lengths in
158! building_pars
159!
160! 2750 2018-01-15 16:26:51Z knoop
161! Move flag plant canopy to modules
162!
163! 2737 2018-01-11 14:58:11Z kanani
164! Removed unused variables t_surf_whole...
165!
166! 2735 2018-01-11 12:01:27Z suehring
167! resistances are saved in surface attributes
168!
169! 2723 2018-01-05 09:27:03Z maronga
170! Bugfix for spinups (end_time was increased twice in case of LSM + USM runs)
171!
172! 2720 2018-01-02 16:27:15Z kanani
173! Correction of comment
174!
175! 2718 2018-01-02 08:49:38Z maronga
176! Corrected "Former revisions" section
177!
178! 2705 2017-12-18 11:26:23Z maronga
179! Changes from last commit documented
180!
181! 2703 2017-12-15 20:12:38Z maronga
182! Workaround for calculation of r_a
183!
184! 2696 2017-12-14 17:12:51Z kanani
185! - Change in file header (GPL part)
186! - Bugfix in calculation of pt_surface and related fluxes. (BM)
187! - Do not write surface temperatures onto pt array as this might cause
188!   problems with nesting. (MS)
189! - Revised calculation of pt1 (now done in surface_layer_fluxes).
190!   Bugfix, f_shf_window and f_shf_green were not set at vertical surface
191!   elements. (MS)
192! - merged with branch ebsolver
193!   green building surfaces do not evaporate yet
194!   properties of green wall layers and window layers are taken from wall layers
195!   this input data is missing. (RvT)
196! - Merged with branch radiation (developed by Mohamed Salim)
197! - Revised initialization. (MS)
198! - Rename emiss_surf into emissivity, roughness_wall into z0, albedo_surf into
199!   albedo. (MS)
200! - Move first call of usm_radiatin from usm_init to init_3d_model
201! - fixed problem with near surface temperature
202! - added near surface temperature t_surf_10cm_h(m), t_surf_10cm_v(l)%t(m)
203! - does not work with temp profile including stability, ol
204!   t_surf_10cm = pt1 now
205! - merged with 2357 bugfix, error message for nopointer version
206! - added indoor model coupling with wall heat flux
207! - added green substrate/ dry vegetation layer for buildings
208! - merged with 2232 new surface-type structure
209! - added transmissivity of window tiles
210! - added MOSAIK tile approach for 3 different surfaces (RvT)
211!
212! 2583 2017-10-26 13:58:38Z knoop
213! Bugfix: reverted MPI_Win_allocate_cptr introduction in last commit
214!
215! 2582 2017-10-26 13:19:46Z hellstea
216! Workaround for gnufortran compiler added in usm_calc_svf. CALL MPI_Win_allocate is
217! replaced by CALL MPI_Win_allocate_cptr if defined ( __gnufortran ).
218!
219! 2544 2017-10-13 18:09:32Z maronga
220! Date and time quantities are now read from date_and_time_mod. Solar constant is
221! read from radiation_model_mod
222!
223! 2516 2017-10-04 11:03:04Z suehring
224! Remove tabs
225!
226! 2514 2017-10-04 09:52:37Z suehring
227! upper bounds of 3d output changed from nx+1,ny+1 to nx,ny
228! no output of ghost layer data
229!
230! 2350 2017-08-15 11:48:26Z kanani
231! Bugfix and error message for nopointer version.
232! Additional "! defined(__nopointer)" as workaround to enable compilation of
233! nopointer version.
234!
235! 2318 2017-07-20 17:27:44Z suehring
236! Get topography top index via Function call
237!
238! 2317 2017-07-20 17:27:19Z suehring
239! Bugfix: adjust output of shf. Added support for spinups
240!
241! 2287 2017-06-15 16:46:30Z suehring
242! Bugfix in determination topography-top index
243!
244! 2269 2017-06-09 11:57:32Z suehring
245! Enable restart runs with different number of PEs
246! Bugfixes nopointer branch
247!
248! 2258 2017-06-08 07:55:13Z suehring
249! Bugfix, add pre-preprocessor directives to enable non-parrallel mode
250!
251! 2233 2017-05-30 18:08:54Z suehring
252!
253! 2232 2017-05-30 17:47:52Z suehring
254! Adjustments according to new surface-type structure. Remove usm_wall_heat_flux;
255! insteat, heat fluxes are directly applied in diffusion_s.
256!
257! 2213 2017-04-24 15:10:35Z kanani
258! Removal of output quantities usm_lad and usm_canopy_hr
259!
260! 2209 2017-04-19 09:34:46Z kanani
261! cpp switch __mpi3 removed,
262! minor formatting,
263! small bugfix for division by zero (Krc)
264!
265! 2113 2017-01-12 13:40:46Z kanani
266! cpp switch __mpi3 added for MPI-3 standard code (Ketelsen)
267!
268! 2071 2016-11-17 11:22:14Z maronga
269! Small bugfix (Resler)
270!
271! 2031 2016-10-21 15:11:58Z knoop
272! renamed variable rho to rho_ocean
273!
274! 2024 2016-10-12 16:42:37Z kanani
275! Bugfixes in deallocation of array plantt and reading of csf/csfsurf,
276! optimization of MPI-RMA operations,
277! declaration of pcbl as integer,
278! renamed usm_radnet -> usm_rad_net, usm_canopy_khf -> usm_canopy_hr,
279! splitted arrays svf -> svf & csf, svfsurf -> svfsurf & csfsurf,
280! use of new control parameter varnamelength,
281! added output variables usm_rad_ressw, usm_rad_reslw,
282! minor formatting changes,
283! minor optimizations.
284!
285! 2011 2016-09-19 17:29:57Z kanani
286! Major reformatting according to PALM coding standard (comments, blanks,
287! alphabetical ordering, etc.),
288! removed debug_prints,
289! removed auxiliary SUBROUTINE get_usm_info, instead, USM flag urban_surface is
290! defined in MODULE control_parameters (modules.f90) to avoid circular
291! dependencies,
292! renamed canopy_heat_flux to pc_heating_rate, as meaning of quantity changed.
293!
294! 2007 2016-08-24 15:47:17Z kanani
295! Initial revision
296!
297!
298! Description:
299! ------------
300! 2016/6/9 - Initial version of the USM (Urban Surface Model)
301!            authors: Jaroslav Resler, Pavel Krc
302!                     (Czech Technical University in Prague and Institute of
303!                      Computer Science of the Czech Academy of Sciences, Prague)
304!            with contributions: Michal Belda, Nina Benesova, Ondrej Vlcek
305!            partly inspired by PALM LSM (B. Maronga)
306!            parameterizations of Ra checked with TUF3D (E. S. Krayenhoff)
307!> Module for Urban Surface Model (USM)
308!> The module includes:
309!>    1. radiation model with direct/diffuse radiation, shading, reflections
310!>       and integration with plant canopy
311!>    2. wall and wall surface model
312!>    3. surface layer energy balance
313!>    4. anthropogenic heat (only from transportation so far)
314!>    5. necessary auxiliary subroutines (reading inputs, writing outputs,
315!>       restart simulations, ...)
316!> It also make use of standard radiation and integrates it into
317!> urban surface model.
318!>
319!> Further work:
320!> -------------
321!> 1. Remove global arrays surfouts, surfoutl and only keep track of radiosity
322!>    from surfaces that are visible from local surfaces (i.e. there is a SVF
323!>    where target is local). To do that, radiosity will be exchanged after each
324!>    reflection step using MPI_Alltoall instead of current MPI_Allgather.
325!>
326!> 2. Temporarily large values of surface heat flux can be observed, up to
327!>    1.2 Km/s, which seem to be not realistic.
328!>
329!> @todo Output of _av variables in case of restarts
330!> @todo Revise flux conversion in energy-balance solver
331!> @todo Bugfixing in nopointer branch
332!> @todo Check optimizations for RMA operations
333!> @todo Alternatives for MPI_WIN_ALLOCATE? (causes problems with openmpi)
334!> @todo Check for load imbalances in CPU measures, e.g. for exchange_horiz_prog
335!>       factor 3 between min and max time
336!> @todo Move setting of flag indoor_model to indoor_model_mod once available
337!> @todo Check divisions in wtend (etc.) calculations for possible division
338!>       by zero, e.g. in case fraq(0,m) + fraq(1,m) = 0?!
339!> @todo Use unit 90 for OPEN/CLOSE of input files (FK)
340!> @todo Move plant canopy stuff into plant canopy code
341!------------------------------------------------------------------------------!
342 MODULE urban_surface_mod
343
344#if ! defined( __nopointer )
345    USE arrays_3d,                                                             &
346        ONLY:  dzu, hyp, zu, pt, pt_1, pt_2, p, u, v, w, hyp, tend, exner
347#endif
348
349    USE basic_constants_and_equations_mod,                                     &
350        ONLY:  c_p, g, kappa, pi, r_d
351
352    USE control_parameters,                                                    &
353        ONLY:  coupling_start_time, topography, dt_3d, humidity,               &
354               intermediate_timestep_count, initializing_actions,              &
355               intermediate_timestep_count_max, simulated_time, end_time,      &
356               timestep_scheme, tsc, coupling_char, io_blocks, io_group,       &
357               message_string, time_since_reference_point, surface_pressure,   &
358               pt_surface, large_scale_forcing, lsf_surf, spinup,              &
359               spinup_pt_mean, spinup_time, time_do3d, dt_do3d,                &
360               average_count_3d, varnamelength, urban_surface,                 &
361               plant_canopy, dz
362
363    USE cpulog,                                                                &
364        ONLY:  cpu_log, log_point, log_point_s
365
366    USE date_and_time_mod,                                                     &
367        ONLY:  time_utc_init
368
369    USE grid_variables,                                                        &
370        ONLY:  dx, dy, ddx, ddy, ddx2, ddy2
371
372    USE indices,                                                               &
373        ONLY:  nx, ny, nnx, nny, nnz, nxl, nxlg, nxr, nxrg, nyn, nyng, nys,    &
374               nysg, nzb, nzt, nbgp, wall_flags_0
375
376    USE, INTRINSIC :: iso_c_binding 
377
378    USE kinds
379             
380    USE pegrid
381   
382    USE plant_canopy_model_mod,                                                &
383        ONLY:  pc_heating_rate, pc_transpiration_rate
384   
385    USE radiation_model_mod,                                                   &
386        ONLY:  albedo_type, radiation_interaction, calc_zenith, zenith,        &
387               radiation, rad_sw_in, rad_lw_in, rad_sw_out, rad_lw_out,        &
388               sigma_sb, sun_direction, sun_dir_lat, sun_dir_lon,              &
389               force_radiation_call, surfinsw, surfinlw, surfinswdir,          &
390               surfinswdif, surfoutsw, surfoutlw, surfins,nsvfl, svf, svfsurf, &
391               surfinl, surfinlwdif, rad_sw_in_dir, rad_sw_in_diff,            &
392               rad_lw_in_diff, surfouts, surfoutl, surfoutsl, surfoutll, surf, &
393               surfl, nsurfl, pcbinsw, pcbinlw, pcbinswdir,                    &
394               pcbinswdif, iup_u, inorth_u, isouth_u, ieast_u, iwest_u, iup_l, &
395               inorth_l, isouth_l, ieast_l, iwest_l, id,                       &
396               iz, iy, ix,  nsurf, idsvf, ndsvf,                               &
397               idcsf, ndcsf, kdcsf, pct,                                       &
398               startland, endland, startwall, endwall, skyvf, skyvft, nzub,    &
399               nzut, nzpt, npcbl, pcbl
400
401    USE statistics,                                                            &
402        ONLY:  hom, statistic_regions
403
404    USE surface_mod,                                                           &
405        ONLY:  get_topography_top_index_ji, get_topography_top_index,          &
406               ind_pav_green, ind_veg_wall, ind_wat_win, surf_usm_h,           &
407               surf_usm_v, surface_restore_elements
408
409
410    IMPLICIT NONE
411
412
413!-- configuration parameters (they can be setup in PALM config)
414    LOGICAL ::  usm_material_model = .TRUE.        !< flag parameter indicating wheather the  model of heat in materials is used
415    LOGICAL ::  usm_anthropogenic_heat = .FALSE.   !< flag parameter indicating wheather the anthropogenic heat sources (e.g.transportation) are used
416    LOGICAL ::  force_radiation_call_l = .FALSE.   !< flag parameter for unscheduled radiation model calls
417    LOGICAL ::  indoor_model = .FALSE.             !< whether to use the indoor model
418    LOGICAL ::  read_wall_temp_3d = .FALSE.
419
420
421    INTEGER(iwp) ::  building_type = 1               !< default building type (preleminary setting)
422    INTEGER(iwp) ::  land_category = 2               !< default category for land surface
423    INTEGER(iwp) ::  wall_category = 2               !< default category for wall surface over pedestrian zone
424    INTEGER(iwp) ::  pedestrian_category = 2         !< default category for wall surface in pedestrian zone
425    INTEGER(iwp) ::  roof_category = 2               !< default category for root surface
426    REAL(wp)     ::  roughness_concrete = 0.001_wp   !< roughness length of average concrete surface
427!
428!-- Indices of input attributes for (above) ground floor level
429    INTEGER(iwp) ::  ind_alb_wall          = 38 !< index in input list for albedo_type of wall fraction
430    INTEGER(iwp) ::  ind_alb_green         = 39 !< index in input list for albedo_type of green fraction
431    INTEGER(iwp) ::  ind_alb_win           = 40 !< index in input list for albedo_type of window fraction
432    INTEGER(iwp) ::  ind_emis_wall_agfl    = 14 !< index in input list for wall emissivity, above ground floor level
433    INTEGER(iwp) ::  ind_emis_wall_gfl     = 32 !< index in input list for wall emissivity, ground floor level
434    INTEGER(iwp) ::  ind_emis_green_agfl   = 15 !< index in input list for green emissivity, above ground floor level
435    INTEGER(iwp) ::  ind_emis_green_gfl    = 33 !< index in input list for green emissivity, ground floor level
436    INTEGER(iwp) ::  ind_emis_win_agfl     = 16 !< index in input list for window emissivity, above ground floor level
437    INTEGER(iwp) ::  ind_emis_win_gfl      = 34 !< index in input list for window emissivity, ground floor level
438    INTEGER(iwp) ::  ind_green_frac_w_agfl = 2  !< index in input list for green fraction on wall, above ground floor level
439    INTEGER(iwp) ::  ind_green_frac_w_gfl  = 23 !< index in input list for green fraction on wall, ground floor level
440    INTEGER(iwp) ::  ind_green_frac_r_agfl = 3  !< index in input list for green fraction on roof, above ground floor level
441    INTEGER(iwp) ::  ind_green_frac_r_gfl  = 24 !< index in input list for green fraction on roof, ground floor level
442    INTEGER(iwp) ::  ind_hc1_agfl          =  6 !< index in input list for heat capacity at first wall layer, above ground floor level
443    INTEGER(iwp) ::  ind_hc1_gfl           = 26 !< index in input list for heat capacity at first wall layer, ground floor level
444    INTEGER(iwp) ::  ind_hc2_agfl          = 7  !< index in input list for heat capacity at second wall layer, above ground floor level
445    INTEGER(iwp) ::  ind_hc2_gfl           = 27 !< index in input list for heat capacity at second wall layer, ground floor level
446    INTEGER(iwp) ::  ind_hc3_agfl          = 8  !< index in input list for heat capacity at third wall layer, above ground floor level
447    INTEGER(iwp) ::  ind_hc3_gfl           = 28 !< index in input list for heat capacity at third wall layer, ground floor level
448    INTEGER(iwp) ::  ind_gflh              = 20 !< index in input list for ground floor level height
449    INTEGER(iwp) ::  ind_lai_r_agfl        = 4  !< index in input list for LAI on roof, above ground floor level
450    INTEGER(iwp) ::  ind_lai_r_gfl         = 4  !< index in input list for LAI on roof, ground floor level
451    INTEGER(iwp) ::  ind_lai_w_agfl        = 5  !< index in input list for LAI on wall, above ground floor level
452    INTEGER(iwp) ::  ind_lai_w_gfl         = 25 !< index in input list for LAI on wall, ground floor level
453    INTEGER(iwp) ::  ind_tc1_agfl          = 9  !< index in input list for thermal conductivity at first wall layer, above ground floor level
454    INTEGER(iwp) ::  ind_tc1_gfl           = 29 !< index in input list for thermal conductivity at first wall layer, ground floor level
455    INTEGER(iwp) ::  ind_tc2_agfl          = 10 !< index in input list for thermal conductivity at second wall layer, above ground floor level
456    INTEGER(iwp) ::  ind_tc2_gfl           = 30 !< index in input list for thermal conductivity at second wall layer, ground floor level
457    INTEGER(iwp) ::  ind_tc3_agfl          = 11 !< index in input list for thermal conductivity at third wall layer, above ground floor level
458    INTEGER(iwp) ::  ind_tc3_gfl           = 31 !< index in input list for thermal conductivity at third wall layer, ground floor level
459    INTEGER(iwp) ::  ind_thick_1           = 41 !< index for wall layer thickness - 1st layer
460    INTEGER(iwp) ::  ind_thick_2           = 42 !< index for wall layer thickness - 2nd layer
461    INTEGER(iwp) ::  ind_thick_3           = 43 !< index for wall layer thickness - 3rd layer
462    INTEGER(iwp) ::  ind_thick_4           = 44 !< index for wall layer thickness - 4th layer
463    INTEGER(iwp) ::  ind_trans_agfl        = 17 !< index in input list for window transmissivity, above ground floor level
464    INTEGER(iwp) ::  ind_trans_gfl         = 35 !< index in input list for window transmissivity, ground floor level
465    INTEGER(iwp) ::  ind_wall_frac_agfl    = 0  !< index in input list for wall fraction, above ground floor level
466    INTEGER(iwp) ::  ind_wall_frac_gfl     = 21 !< index in input list for wall fraction, ground floor level
467    INTEGER(iwp) ::  ind_win_frac_agfl     = 1  !< index in input list for window fraction, above ground floor level
468    INTEGER(iwp) ::  ind_win_frac_gfl      = 22 !< index in input list for window fraction, ground floor level
469    INTEGER(iwp) ::  ind_z0_agfl           = 18 !< index in input list for z0, above ground floor level
470    INTEGER(iwp) ::  ind_z0_gfl            = 36 !< index in input list for z0, ground floor level
471    INTEGER(iwp) ::  ind_z0qh_agfl         = 19 !< index in input list for z0h / z0q, above ground floor level
472    INTEGER(iwp) ::  ind_z0qh_gfl          = 37 !< index in input list for z0h / z0q, ground floor level
473
474
475    REAL(wp)  ::  roof_height_limit = 4._wp          !< height for distinguish between land surfaces and roofs
476    REAL(wp)  ::  ground_floor_level = 4.0_wp        !< default ground floor level
477
478
479    CHARACTER(37), DIMENSION(0:7), PARAMETER :: building_type_name = (/     &
480                                   'user-defined                         ', & !  0
481                                   'residential - 1950                   ', & !  1
482                                   'residential 1951 - 2000              ', & !  2
483                                   'residential 2001 -                   ', & !  3
484                                   'office - 1950                        ', & !  4
485                                   'office 1951 - 2000                   ', & !  5
486                                   'office 2001 -                        ', & !  6
487                                   'bridges                              '  & !  7
488                                                                     /)
489!
490!-- building parameters, 4 different types
491!-- 0 - wall fraction, 1- window fraction, 2 - green fraction on wall, 3- green fraction
492!-- at roof, 4 - lai of green fraction at roof,  5 - lai of green fraction at wall,
493!-- 6 - heat capacity of wall layer 1, 7 - heat capacity of wall layer 2,
494!-- 8 - heat capacity of wall layer 3, 9 - thermal conductivity of wall layer 1,
495!-- 10 - thermal conductivity of wall layer 2, 11 - thermal conductivity of wall layer 3, 
496!-- 12 - indoor target summer temperature ( K ), 13 - indoor target winter temperature (K),
497!-- 14 - emissivity of wall fraction, 15 - emissivity of green fraction, 16 - emissivity of window fraction,
498!-- 17 - transmissivity of window fraction, 18 - z0, 19 - z0h/z0q, 20 - ground floor height,
499!-- 21 - ground floor wall fraction, 22 - ground floor window fraction, 23 ground floor green fraction,
500!-- 24 - ground floor green fraction on roof, 25 - ground floor lai of green fraction,
501!-- 26 - ground floor heat capacity of wall layer 1, 27 - ground floor heat capacity of wall layer 1,
502!-- 28 - ground floor heat capacity of wall layer 3, 29 - ground floor thermal conductivity of wall layer 1,
503!-- 30 - ground floor thermal conductivity of wall layer 2, 31 - ground floor thermal conductivity of wall layer 3,
504!-- 32 - ground floor emissivity of wall fraction, 33 - ground floor emissivity of green fraction,
505!-- 34 - ground floor emissivity of window fraction, 35 - ground floor transmissivity of window fraction,
506!-- 36 - ground floor z0, 37 - ground floor z0h/z0q, 38 - albedo type wall fraction
507!-- 39 - albedo type green fraction, 40 - albedo type window fraction
508!-- 41 - wall layer thickness - 1st layer, 42 - wall layer thickness - 2nd layer,
509!-- 43 - wall layer thickness - 3rd layer, 44 - wall layer thickness - 4th layer,
510!-- 45 - heat capacity of the wall surface, 46 - heat conductivity
511!-- Please note, only preleminary dummy values so far!
512    REAL(wp), DIMENSION(0:46,1:7), PARAMETER :: building_pars = RESHAPE( (/    &
513        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, 1.0_wp,                        & !parameter 0-5
514        1000000.0_wp, 1000000.0_wp, 1000000.0_wp, 0.3_wp, 0.3_wp, 0.3_wp,      & !parameter 6-11
515        296.15_wp, 293.15_wp, 0.9_wp, 0.9_wp, 0.01_wp, 0.99_wp,                & !parameter 12-17
516        0.001_wp, 0.0001_wp, 4.0_wp,                                           & !parameter 18-20
517        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 3.0_wp,                                & !parameter 21-25
518        1000000.0_wp, 1000000.0_wp, 1000000.0_wp,                              & !parameter 26-28                     
519        0.3_wp, 0.3_wp, 0.3_wp,                                                & !parameter 29-31       
520        0.9_wp, 0.4_wp, 0.4_wp, 0.4_wp, 0.01_wp, 0.001_wp,                     & !parameter 32-37
521        24.0_wp, 24.0_wp, 24.0_wp,                                             & !parameter 38-40
522        0.0242_wp, 0.0969_wp, 0.346_wp, 1.0_wp,                                & !parameter 41-44
523        20000.0_wp, 10.0_wp,                                                   & !parameter 45-46 - end of type 1
524        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, 1.0_wp,                        & !parameter 0-5
525        1000000.0_wp, 1000000.0_wp, 1000000.0_wp, 0.3_wp, 0.3_wp, 0.3_wp,      & !parameter 6-11
526        296.15_wp, 293.15_wp, 0.9_wp, 0.9_wp, 0.01_wp, 0.99_wp,                & !parameter 12-17
527        0.001_wp, 0.0001_wp, 4.0_wp,                                           & !parameter 18-20
528        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 3.0_wp,                                & !parameter 21-25
529        1000000.0_wp, 1000000.0_wp, 1000000.0_wp,                              & !parameter 26-28                     
530        0.3_wp, 0.3_wp, 0.3_wp,                                                & !parameter 29-31       
531        0.9_wp, 0.4_wp, 0.4_wp, 0.4_wp, 0.01_wp, 0.001_wp,                     & !parameter 32-37
532        24.0_wp, 24.0_wp, 24.0_wp,                                             & !parameter 38-40
533        0.0242_wp, 0.0969_wp, 0.346_wp, 1.0_wp,                                & !parameter 41-44
534        20000.0_wp, 10.0_wp,                                                   & !parameter 45-46 - end of type 2
535        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, 1.0_wp,                        & !parameter 0-5
536        1000000.0_wp, 1000000.0_wp, 1000000.0_wp, 0.3_wp, 0.3_wp, 0.3_wp,      & !parameter 6-11
537        296.15_wp, 293.15_wp, 0.9_wp, 0.9_wp, 0.01_wp, 0.99_wp,                & !parameter 12-17
538        0.001_wp, 0.0001_wp, 4.0_wp,                                           & !parameter 18-20
539        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 3.0_wp,                                & !parameter 21-25
540        1000000.0_wp, 1000000.0_wp, 1000000.0_wp,                              & !parameter 26-28                     
541        0.3_wp, 0.3_wp, 0.3_wp,                                                & !parameter 29-31       
542        0.9_wp, 0.4_wp, 0.4_wp, 0.4_wp, 0.01_wp, 0.001_wp,                     & !parameter 32-37
543        24.0_wp, 24.0_wp, 24.0_wp,                                             & !parameter 38-40
544        0.0242_wp, 0.0969_wp, 0.346_wp, 1.0_wp,                                & !parameter 41-44
545        20000.0_wp, 10.0_wp,                                                   & !parameter 45-46 - end of type 3
546        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, 1.0_wp,                        & !parameter 0-5
547        1000000.0_wp, 1000000.0_wp, 1000000.0_wp, 0.3_wp, 0.3_wp, 0.3_wp,      & !parameter 6-11
548        296.15_wp, 293.15_wp, 0.9_wp, 0.9_wp, 0.01_wp, 0.99_wp,                & !parameter 12-17
549        0.01_wp, 0.001_wp, 4.0_wp,                                             & !parameter 18-20
550        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 3.0_wp,                                & !parameter 21-25
551        1000000.0_wp, 1000000.0_wp, 1000000.0_wp,                              & !parameter 26-28                     
552        0.3_wp, 0.3_wp, 0.3_wp,                                                & !parameter 29-31       
553        0.9_wp, 0.4_wp, 0.4_wp, 0.4_wp, 0.01_wp, 0.001_wp,                     & !parameter 32-37
554        24.0_wp, 24.0_wp, 24.0_wp,                                             & !parameter 38-40
555        0.0242_wp, 0.0969_wp, 0.346_wp, 1.0_wp,                                & !parameter 41-44
556        20000.0_wp, 10.0_wp,                                                   & !parameter 45-46 - end of type 4
557        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, 1.0_wp,                        & !parameter 0-5
558        1000000.0_wp, 1000000.0_wp, 1000000.0_wp, 0.3_wp, 0.3_wp, 0.3_wp,      & !parameter 6-11
559        296.15_wp, 293.15_wp, 0.9_wp, 0.9_wp, 0.01_wp, 0.99_wp,                & !parameter 12-17
560        0.001_wp, 0.0001_wp, 4.0_wp,                                           & !parameter 18-20
561        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 3.0_wp,                                & !parameter 21-25
562        1000000.0_wp, 1000000.0_wp, 1000000.0_wp,                              & !parameter 26-28                     
563        0.3_wp, 0.3_wp, 0.3_wp,                                                & !parameter 29-31       
564        0.9_wp, 0.4_wp, 0.4_wp, 0.4_wp, 0.01_wp, 0.001_wp,                     & !parameter 32-37
565        24.0_wp, 24.0_wp, 24.0_wp,                                             & !parameter 38-40
566        0.0242_wp, 0.0969_wp, 0.346_wp, 1.0_wp,                                & !parameter 41-44
567        20000.0_wp, 10.0_wp,                                                   & !parameter 45-46 - end of type 5
568        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, 1.0_wp,                        & !parameter 0-5
569        1000000.0_wp, 1000000.0_wp, 1000000.0_wp, 0.3_wp, 0.3_wp, 0.3_wp,      & !parameter 6-11
570        296.15_wp, 293.15_wp, 0.9_wp, 0.9_wp, 0.01_wp, 0.99_wp,                & !parameter 12-17
571        0.001_wp, 0.0001_wp, 4.0_wp,                                           & !parameter 18-20
572        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 3.0_wp,                                & !parameter 21-25
573        1000000.0_wp, 1000000.0_wp, 1000000.0_wp,                              & !parameter 26-28                     
574        0.3_wp, 0.3_wp, 0.3_wp,                                                & !parameter 29-31       
575        0.9_wp, 0.4_wp, 0.4_wp, 0.4_wp, 0.01_wp, 0.001_wp,                     & !parameter 32-37
576        24.0_wp, 24.0_wp, 24.0_wp,                                             & !parameter 38-40
577        0.0242_wp, 0.0969_wp, 0.346_wp, 1.0_wp,                                & !parameter 41-44
578        20000.0_wp, 10.0_wp,                                                   & !parameter 45-46 - end of type 6
579        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, 1.0_wp,                        & !parameter 0-5
580        1000000.0_wp, 1000000.0_wp, 1000000.0_wp, 0.3_wp, 0.3_wp, 0.3_wp,      & !parameter 6-11
581        296.15_wp, 293.15_wp, 0.9_wp, 0.9_wp, 0.01_wp, 0.99_wp,                & !parameter 12-17
582        0.001_wp, 0.0001_wp, 0.0_wp,                                           & !parameter 18-20
583        1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 3.0_wp,                                & !parameter 21-25
584        1000000.0_wp, 1000000.0_wp, 1000000.0_wp,                              & !parameter 26-28                     
585        0.3_wp, 0.3_wp, 0.3_wp,                                                & !parameter 29-31       
586        0.9_wp, 0.4_wp, 0.4_wp, 0.4_wp, 0.01_wp, 0.001_wp,                     & !parameter 32-37
587        24.0_wp, 24.0_wp, 24.0_wp,                                             & !parameter 38-40
588        0.0242_wp, 0.0969_wp, 0.346_wp, 1.0_wp,                                & !parameter 41-44
589        20000.0_wp, 10.0_wp                                                    & !parameter 45-46 - end of type 7 (bridges)
590                                                                          /),  &
591                                                               (/47, 7/) )
592
593!
594!-- Type for surface temperatures at vertical walls. Is not necessary for horizontal walls.
595    TYPE t_surf_vertical
596       REAL(wp), DIMENSION(:), ALLOCATABLE         :: t
597    END TYPE t_surf_vertical
598!
599!-- Type for wall temperatures at vertical walls. Is not necessary for horizontal walls.
600    TYPE t_wall_vertical
601       REAL(wp), DIMENSION(:,:), ALLOCATABLE       :: t
602    END TYPE t_wall_vertical
603
604
605!-- arrays for time averages
606!-- Attention: the variable rad_net_av is also used in the 3d field variable in radiation_model_mod.f90. It may be better to rename it
607    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfinsw_av      !< average of sw radiation falling to local surface including radiation from reflections
608    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfinlw_av      !< average of lw radiation falling to local surface including radiation from reflections
609    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfinswdir_av   !< average of direct sw radiation falling to local surface
610    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfinswdif_av   !< average of diffuse sw radiation from sky and model boundary falling to local surface
611    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfinlwdif_av   !< average of diffuse lw radiation from sky and model boundary falling to local surface
612    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfinswref_av   !< average of sw radiation falling to surface from reflections
613    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfinlwref_av   !< average of lw radiation falling to surface from reflections
614    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfoutsw_av     !< average of total sw radiation outgoing from nonvirtual surfaces surfaces after all reflection
615    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfoutlw_av     !< average of total lw radiation outgoing from nonvirtual surfaces surfaces after all reflection
616    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfins_av       !< average of array of residua of sw radiation absorbed in surface after last reflection
617    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfinl_av       !< average of array of residua of lw radiation absorbed in surface after last reflection
618    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  pcbinlw_av       !< Average of pcbinlw
619    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  pcbinsw_av       !< Average of pcbinsw
620    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  pcbinswdir_av    !< Average of pcbinswdir
621    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  pcbinswdif_av    !< Average of pcbinswdif
622    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  pcbinswref_av    !< Average of pcbinswref
623   
624
625!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
626!-- anthropogenic heat sources
627!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
628    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE        ::  aheat             !< daily average of anthropogenic heat (W/m2)
629    REAL(wp), DIMENSION(:,:), ALLOCATABLE          ::  aheatprof         !< diurnal profiles of anthropogenic heat for particular layers
630    INTEGER(iwp)                                   ::  naheatlayers = 1  !< number of layers of anthropogenic heat
631
632!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
633!-- wall surface model
634!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
635!-- wall surface model constants
636    INTEGER(iwp), PARAMETER                        :: nzb_wall = 0       !< inner side of the wall model (to be switched)
637    INTEGER(iwp), PARAMETER                        :: nzt_wall = 3       !< outer side of the wall model (to be switched)
638    INTEGER(iwp), PARAMETER                        :: nzw = 4            !< number of wall layers (fixed for now)
639
640    REAL(wp), DIMENSION(nzb_wall:nzt_wall)         :: zwn_default = (/0.0242_wp, 0.0969_wp, 0.346_wp, 1.0_wp /)
641                                                                         !< normalized soil, wall and roof layer depths (m/m)
642!    REAL(wp), DIMENSION(nzb_wall:nzt_wall)         :: zwn_default = (/0.33_wp, 0.66_wp, 1.0_wp /)
643    REAL(wp), DIMENSION(nzb_wall:nzt_wall)         :: zwn_default_window = (/0.25_wp, 0.5_wp, 0.75_wp, 1.0_wp /)
644!    REAL(wp), DIMENSION(nzb_wall:nzt_wall)         :: zwn_default_window = (/0.33_wp, 0.66_wp, 1.0_wp /)
645!    REAL(wp), DIMENSION(nzb_wall:nzt_wall)         :: zwn_default_window = (/0.0242_wp, 0.0969_wp, 0.346_wp, 1.0_wp /)
646                                                                         !< normalized window layer depths (m/m)
647!    REAL(wp), DIMENSION(nzb_wall:nzt_wall)         :: zwn_default_green = (/0.0242_wp, 0.0969_wp, 0.346_wp, 1.0_wp /)
648                                                                         !< normalized green layer depths (m/m)
649    REAL(wp), DIMENSION(nzb_wall:nzt_wall)         :: zwn_default_green = (/0.25_wp, 0.5_wp, 0.75_wp, 1.0_wp /)
650!    REAL(wp), DIMENSION(nzb_wall:nzt_wall)         :: zwn_default_green = (/0.33_wp, 0.66_wp, 1.0_wp /)
651
652
653    REAL(wp)                                       :: wall_inner_temperature = 295.0_wp    !< temperature of the inner wall surface (~22 degrees C) (K)
654    REAL(wp)                                       :: roof_inner_temperature = 295.0_wp    !< temperature of the inner roof surface (~22 degrees C) (K)
655    REAL(wp)                                       :: soil_inner_temperature = 288.0_wp    !< temperature of the deep soil (~15 degrees C) (K)
656    REAL(wp)                                       :: window_inner_temperature = 295.0_wp  !< temperature of the inner window surface (~22 degrees C) (K)
657
658!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
659!-- surface and material model variables for walls, ground, roofs
660!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
661    REAL(wp), DIMENSION(:), ALLOCATABLE            :: zwn                !< normalized wall layer depths (m)
662    REAL(wp), DIMENSION(:), ALLOCATABLE            :: zwn_window         !< normalized window layer depths (m)
663    REAL(wp), DIMENSION(:), ALLOCATABLE            :: zwn_green          !< normalized green layer depths (m)
664
665#if defined( __nopointer )
666    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_h           !< wall surface temperature (K) at horizontal walls
667    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_h_p         !< progn. wall surface temperature (K) at horizontal walls
668    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_window_h    !< window surface temperature (K) at horizontal walls
669    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_window_h_p  !< progn. window surface temperature (K) at horizontal walls
670    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_green_h     !< green surface temperature (K) at horizontal walls
671    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_green_h_p   !< progn. green surface temperature (K) at horizontal walls
672    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_10cm_h      !< near surface temperature (10cm) (K) at horizontal walls
673    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_10cm_h_p    !< progn. near surface temperature (10cm) (K) at horizontal walls
674    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  ::  t_surf_v
675    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  ::  t_surf_v_p
676    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  ::  t_surf_window_v
677    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  ::  t_surf_window_v_p
678    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  ::  t_surf_green_v
679    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  ::  t_surf_green_v_p
680    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  ::  t_surf_10cm_v
681    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  ::  t_surf_10cm_v_p
682#else
683    REAL(wp), DIMENSION(:), POINTER                :: t_surf_h
684    REAL(wp), DIMENSION(:), POINTER                :: t_surf_h_p 
685    REAL(wp), DIMENSION(:), POINTER                :: t_surf_window_h
686    REAL(wp), DIMENSION(:), POINTER                :: t_surf_window_h_p 
687    REAL(wp), DIMENSION(:), POINTER                :: t_surf_green_h
688    REAL(wp), DIMENSION(:), POINTER                :: t_surf_green_h_p 
689    REAL(wp), DIMENSION(:), POINTER                :: t_surf_10cm_h
690    REAL(wp), DIMENSION(:), POINTER                :: t_surf_10cm_h_p
691
692    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_h_1
693    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_h_2
694    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_window_h_1
695    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_window_h_2
696    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_green_h_1
697    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_green_h_2
698    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_10cm_h_1
699    REAL(wp), DIMENSION(:), ALLOCATABLE, TARGET    :: t_surf_10cm_h_2
700
701    TYPE(t_surf_vertical), DIMENSION(:), POINTER ::  t_surf_v
702    TYPE(t_surf_vertical), DIMENSION(:), POINTER ::  t_surf_v_p
703    TYPE(t_surf_vertical), DIMENSION(:), POINTER ::  t_surf_window_v
704    TYPE(t_surf_vertical), DIMENSION(:), POINTER ::  t_surf_window_v_p
705    TYPE(t_surf_vertical), DIMENSION(:), POINTER ::  t_surf_green_v
706    TYPE(t_surf_vertical), DIMENSION(:), POINTER ::  t_surf_green_v_p
707    TYPE(t_surf_vertical), DIMENSION(:), POINTER ::  t_surf_10cm_v
708    TYPE(t_surf_vertical), DIMENSION(:), POINTER ::  t_surf_10cm_v_p
709
710    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  :: t_surf_v_1
711    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  :: t_surf_v_2
712    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  :: t_surf_window_v_1
713    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  :: t_surf_window_v_2
714    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  :: t_surf_green_v_1
715    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  :: t_surf_green_v_2
716    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  :: t_surf_10cm_v_1
717    TYPE(t_surf_vertical), DIMENSION(0:3), TARGET  :: t_surf_10cm_v_2
718   
719#endif
720
721!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
722!-- Energy balance variables
723!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
724!-- parameters of the land, roof and wall surfaces
725
726#if defined( __nopointer )
727    REAL(wp), DIMENSION(:,:), ALLOCATABLE, TARGET    :: t_wall_h             !< Wall temperature (K)
728    REAL(wp), DIMENSION(:,:), ALLOCATABLE, TARGET    :: t_wall_h_p           !< Prog. wall temperature (K)
729    REAL(wp), DIMENSION(:,:), ALLOCATABLE, TARGET    :: t_window_h           !< Window temperature (K)
730    REAL(wp), DIMENSION(:,:), ALLOCATABLE, TARGET    :: t_window_h_p         !< Prog. window temperature (K)
731    REAL(wp), DIMENSION(:,:), ALLOCATABLE, TARGET    :: t_green_h            !< Green temperature (K)
732    REAL(wp), DIMENSION(:,:), ALLOCATABLE, TARGET    :: t_green_h_p          !< Prog. green temperature (K)
733
734    TYPE(t_wall_vertical), DIMENSION(0:3), TARGET  :: t_wall_v             !< Wall temperature (K)
735    TYPE(t_wall_vertical), DIMENSION(0:3), TARGET  :: t_wall_v_p           !< Prog. wall temperature (K)
736    TYPE(t_wall_vertical), DIMENSION(0:3), TARGET  :: t_window_v           !< Window temperature (K)
737    TYPE(t_wall_vertical), DIMENSION(0:3), TARGET  :: t_window_v_p         !< Prog. window temperature (K)
738    TYPE(t_wall_vertical), DIMENSION(0:3), TARGET  :: t_green_v            !< Green temperature (K)
739    TYPE(t_wall_vertical), DIMENSION(0:3), TARGET  :: t_green_v_p          !< Prog. green temperature (K)
740#else
741    REAL(wp), DIMENSION(:,:), POINTER                :: t_wall_h, t_wall_h_p
742    REAL(wp), DIMENSION(:,:), ALLOCATABLE, TARGET    :: t_wall_h_1, t_wall_h_2
743    REAL(wp), DIMENSION(:,:), POINTER                :: t_window_h, t_window_h_p
744    REAL(wp), DIMENSION(:,:), ALLOCATABLE, TARGET    :: t_window_h_1, t_window_h_2
745    REAL(wp), DIMENSION(:,:), POINTER                :: t_green_h, t_green_h_p
746    REAL(wp), DIMENSION(:,:), ALLOCATABLE, TARGET    :: t_green_h_1, t_green_h_2
747
748    TYPE(t_wall_vertical), DIMENSION(:), POINTER   :: t_wall_v, t_wall_v_p
749    TYPE(t_wall_vertical), DIMENSION(0:3), TARGET  :: t_wall_v_1, t_wall_v_2
750    TYPE(t_wall_vertical), DIMENSION(:), POINTER   :: t_window_v, t_window_v_p
751    TYPE(t_wall_vertical), DIMENSION(0:3), TARGET  :: t_window_v_1, t_window_v_2
752    TYPE(t_wall_vertical), DIMENSION(:), POINTER   :: t_green_v, t_green_v_p
753    TYPE(t_wall_vertical), DIMENSION(0:3), TARGET  :: t_green_v_1, t_green_v_2
754#endif
755
756!
757!-- Surface and material parameters classes (surface_type)
758!-- albedo, emissivity, lambda_surf, roughness, thickness, volumetric heat capacity, thermal conductivity
759    INTEGER(iwp)                                   :: n_surface_types      !< number of the wall type categories
760    INTEGER(iwp), PARAMETER                        :: n_surface_params = 9 !< number of parameters for each type of the wall
761    INTEGER(iwp), PARAMETER                        :: ialbedo  = 1         !< albedo of the surface
762    INTEGER(iwp), PARAMETER                        :: iemiss   = 2         !< emissivity of the surface
763    INTEGER(iwp), PARAMETER                        :: ilambdas = 3         !< heat conductivity lambda S between surface and material ( W m-2 K-1 )
764    INTEGER(iwp), PARAMETER                        :: irough   = 4         !< roughness length z0 for movements
765    INTEGER(iwp), PARAMETER                        :: iroughh  = 5         !< roughness length z0h for scalars (heat, humidity,...)
766    INTEGER(iwp), PARAMETER                        :: icsurf   = 6         !< Surface skin layer heat capacity (J m-2 K-1 )
767    INTEGER(iwp), PARAMETER                        :: ithick   = 7         !< thickness of the surface (wall, roof, land)  ( m )
768    INTEGER(iwp), PARAMETER                        :: irhoC    = 8         !< volumetric heat capacity rho*C of the material ( J m-3 K-1 )
769    INTEGER(iwp), PARAMETER                        :: ilambdah = 9         !< thermal conductivity lambda H of the wall (W m-1 K-1 )
770    CHARACTER(12), DIMENSION(:), ALLOCATABLE       :: surface_type_names   !< names of wall types (used only for reports)
771    INTEGER(iwp), DIMENSION(:), ALLOCATABLE        :: surface_type_codes   !< codes of wall types
772    REAL(wp), DIMENSION(:,:), ALLOCATABLE          :: surface_params       !< parameters of wall types
773
774   
775!-- interfaces of subroutines accessed from outside of this module
776    INTERFACE usm_boundary_condition
777       MODULE PROCEDURE usm_boundary_condition
778    END INTERFACE usm_boundary_condition
779
780    INTERFACE usm_check_data_output
781       MODULE PROCEDURE usm_check_data_output
782    END INTERFACE usm_check_data_output
783   
784    INTERFACE usm_check_parameters
785       MODULE PROCEDURE usm_check_parameters
786    END INTERFACE usm_check_parameters
787   
788    INTERFACE usm_data_output_3d
789       MODULE PROCEDURE usm_data_output_3d
790    END INTERFACE usm_data_output_3d
791   
792    INTERFACE usm_define_netcdf_grid
793       MODULE PROCEDURE usm_define_netcdf_grid
794    END INTERFACE usm_define_netcdf_grid
795
796    INTERFACE usm_init_urban_surface
797       MODULE PROCEDURE usm_init_urban_surface
798    END INTERFACE usm_init_urban_surface
799
800    INTERFACE usm_material_heat_model
801       MODULE PROCEDURE usm_material_heat_model
802    END INTERFACE usm_material_heat_model
803   
804    INTERFACE usm_green_heat_model
805       MODULE PROCEDURE usm_green_heat_model
806    END INTERFACE usm_green_heat_model
807   
808    INTERFACE usm_parin
809       MODULE PROCEDURE usm_parin
810    END INTERFACE usm_parin
811   
812    INTERFACE usm_temperature_near_surface
813       MODULE PROCEDURE usm_temperature_near_surface
814    END INTERFACE usm_temperature_near_surface
815
816    INTERFACE usm_rrd_local 
817       MODULE PROCEDURE usm_rrd_local
818    END INTERFACE usm_rrd_local
819
820    INTERFACE usm_surface_energy_balance
821       MODULE PROCEDURE usm_surface_energy_balance
822    END INTERFACE usm_surface_energy_balance
823   
824    INTERFACE usm_swap_timelevel
825       MODULE PROCEDURE usm_swap_timelevel
826    END INTERFACE usm_swap_timelevel
827       
828    INTERFACE usm_wrd_local
829       MODULE PROCEDURE usm_wrd_local
830    END INTERFACE usm_wrd_local
831
832    INTERFACE usm_allocate_surface
833       MODULE PROCEDURE usm_allocate_surface
834    END INTERFACE usm_allocate_surface
835
836    INTERFACE usm_average_3d_data
837       MODULE PROCEDURE usm_average_3d_data
838    END INTERFACE usm_average_3d_data
839
840   
841    SAVE
842
843    PRIVATE 
844   
845!-- Public functions
846    PUBLIC usm_boundary_condition, usm_check_parameters, usm_init_urban_surface,&
847           usm_rrd_local,                                                      & 
848           usm_surface_energy_balance, usm_material_heat_model,                &
849           usm_swap_timelevel, usm_check_data_output, usm_average_3d_data,     &
850           usm_data_output_3d, usm_define_netcdf_grid, usm_parin,              &
851           usm_wrd_local, usm_allocate_surface
852
853!-- Public parameters, constants and initial values
854    PUBLIC usm_anthropogenic_heat, usm_material_model,                          &
855           usm_green_heat_model, usm_temperature_near_surface
856
857
858
859 CONTAINS
860
861!------------------------------------------------------------------------------!
862! Description:
863! ------------
864!> This subroutine creates the necessary indices of the urban surfaces
865!> and plant canopy and it allocates the needed arrays for USM
866!------------------------------------------------------------------------------!
867    SUBROUTINE usm_allocate_surface
868   
869        IMPLICIT NONE
870       
871        INTEGER(iwp) ::  l
872
873!
874!--     Allocate radiation arrays which are part of the new data type.
875!--     For horizontal surfaces.
876        ALLOCATE( surf_usm_h%surfhf(1:surf_usm_h%ns)    )
877        ALLOCATE( surf_usm_h%rad_net_l(1:surf_usm_h%ns) )
878!
879!--     For vertical surfaces
880        DO  l = 0, 3
881           ALLOCATE( surf_usm_v(l)%surfhf(1:surf_usm_v(l)%ns)    )
882           ALLOCATE( surf_usm_v(l)%rad_net_l(1:surf_usm_v(l)%ns) )
883        ENDDO
884
885!--     Wall surface model
886!--     allocate arrays for wall surface model and define pointers
887       
888!--     allocate array of wall types and wall parameters
889        ALLOCATE ( surf_usm_h%surface_types(1:surf_usm_h%ns)      )
890        ALLOCATE ( surf_usm_h%building_type(1:surf_usm_h%ns)      )
891        ALLOCATE ( surf_usm_h%building_type_name(1:surf_usm_h%ns) )
892        surf_usm_h%building_type      = 0
893        surf_usm_h%building_type_name = 'none'
894        DO  l = 0, 3
895           ALLOCATE( surf_usm_v(l)%surface_types(1:surf_usm_v(l)%ns) )
896           ALLOCATE ( surf_usm_v(l)%building_type(1:surf_usm_v(l)%ns)      )
897           ALLOCATE ( surf_usm_v(l)%building_type_name(1:surf_usm_v(l)%ns) )
898           surf_usm_v(l)%building_type      = 0
899           surf_usm_v(l)%building_type_name = 'none'
900        ENDDO
901!
902!--     Allocate albedo_type and albedo. Each surface element
903!--     has 3 values, 0: wall fraction, 1: green fraction, 2: window fraction.
904        ALLOCATE( surf_usm_h%albedo_type(0:2,1:surf_usm_h%ns) )
905        ALLOCATE( surf_usm_h%albedo(0:2,1:surf_usm_h%ns)      )
906        surf_usm_h%albedo_type = albedo_type
907        DO  l = 0, 3
908           ALLOCATE( surf_usm_v(l)%albedo_type(0:2,1:surf_usm_v(l)%ns) )
909           ALLOCATE( surf_usm_v(l)%albedo(0:2,1:surf_usm_v(l)%ns)      )
910           surf_usm_v(l)%albedo_type = albedo_type
911        ENDDO       
912
913
914!
915!--     Allocate indoor target temperature for summer and winter
916        ALLOCATE( surf_usm_h%target_temp_summer(1:surf_usm_h%ns) )
917        ALLOCATE( surf_usm_h%target_temp_winter(1:surf_usm_h%ns) )
918        DO  l = 0, 3
919           ALLOCATE( surf_usm_v(l)%target_temp_summer(1:surf_usm_v(l)%ns) )
920           ALLOCATE( surf_usm_v(l)%target_temp_winter(1:surf_usm_v(l)%ns) )
921        ENDDO   
922!
923!--     Allocate flag indicating ground floor level surface elements
924        ALLOCATE ( surf_usm_h%ground_level(1:surf_usm_h%ns) ) 
925        DO  l = 0, 3
926           ALLOCATE( surf_usm_v(l)%ground_level(1:surf_usm_v(l)%ns) )
927        ENDDO   
928!
929!--      Allocate arrays for relative surface fraction.
930!--      0 - wall fraction, 1 - green fraction, 2 - window fraction
931         ALLOCATE( surf_usm_h%frac(0:2,1:surf_usm_h%ns) )
932         surf_usm_h%frac = 0.0_wp
933         DO  l = 0, 3
934            ALLOCATE( surf_usm_v(l)%frac(0:2,1:surf_usm_v(l)%ns) )
935            surf_usm_v(l)%frac = 0.0_wp
936         ENDDO
937       
938!--     wall and roof surface parameters. First for horizontal surfaces
939        ALLOCATE ( surf_usm_h%isroof_surf(1:surf_usm_h%ns)     )
940        ALLOCATE ( surf_usm_h%lambda_surf(1:surf_usm_h%ns)     )
941        ALLOCATE ( surf_usm_h%lambda_surf_window(1:surf_usm_h%ns) )
942        ALLOCATE ( surf_usm_h%lambda_surf_green(1:surf_usm_h%ns)  )
943        ALLOCATE ( surf_usm_h%c_surface(1:surf_usm_h%ns)       )
944        ALLOCATE ( surf_usm_h%c_surface_window(1:surf_usm_h%ns)   )
945        ALLOCATE ( surf_usm_h%c_surface_green(1:surf_usm_h%ns)    )
946        ALLOCATE ( surf_usm_h%transmissivity(1:surf_usm_h%ns)  )
947        ALLOCATE ( surf_usm_h%lai(1:surf_usm_h%ns)             )
948        ALLOCATE ( surf_usm_h%emissivity(0:2,1:surf_usm_h%ns)  )
949        ALLOCATE ( surf_usm_h%r_a(1:surf_usm_h%ns)             )
950        ALLOCATE ( surf_usm_h%r_a_green(1:surf_usm_h%ns)       )
951        ALLOCATE ( surf_usm_h%r_a_window(1:surf_usm_h%ns)      )
952
953!
954!--     For vertical surfaces.
955        DO  l = 0, 3
956           ALLOCATE ( surf_usm_v(l)%lambda_surf(1:surf_usm_v(l)%ns)     )
957           ALLOCATE ( surf_usm_v(l)%c_surface(1:surf_usm_v(l)%ns)       )
958           ALLOCATE ( surf_usm_v(l)%lambda_surf_window(1:surf_usm_v(l)%ns) )
959           ALLOCATE ( surf_usm_v(l)%c_surface_window(1:surf_usm_v(l)%ns)   )
960           ALLOCATE ( surf_usm_v(l)%lambda_surf_green(1:surf_usm_v(l)%ns)  )
961           ALLOCATE ( surf_usm_v(l)%c_surface_green(1:surf_usm_v(l)%ns)    )
962           ALLOCATE ( surf_usm_v(l)%transmissivity(1:surf_usm_v(l)%ns)  )
963           ALLOCATE ( surf_usm_v(l)%lai(1:surf_usm_v(l)%ns)             )
964           ALLOCATE ( surf_usm_v(l)%emissivity(0:2,1:surf_usm_v(l)%ns)  )
965           ALLOCATE ( surf_usm_v(l)%r_a(1:surf_usm_v(l)%ns)             )
966           ALLOCATE ( surf_usm_v(l)%r_a_green(1:surf_usm_v(l)%ns)       )
967           ALLOCATE ( surf_usm_v(l)%r_a_window(1:surf_usm_v(l)%ns)      )
968        ENDDO
969
970!       
971!--     allocate wall and roof material parameters. First for horizontal surfaces
972        ALLOCATE ( surf_usm_h%thickness_wall(1:surf_usm_h%ns)               )
973        ALLOCATE ( surf_usm_h%thickness_window(1:surf_usm_h%ns)                  )
974        ALLOCATE ( surf_usm_h%thickness_green(1:surf_usm_h%ns)                   )
975        ALLOCATE ( surf_usm_h%lambda_h(nzb_wall:nzt_wall,1:surf_usm_h%ns)   )
976        ALLOCATE ( surf_usm_h%rho_c_wall(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
977        ALLOCATE ( surf_usm_h%lambda_h_window(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
978        ALLOCATE ( surf_usm_h%rho_c_window(nzb_wall:nzt_wall,1:surf_usm_h%ns)    )
979        ALLOCATE ( surf_usm_h%lambda_h_green(nzb_wall:nzt_wall,1:surf_usm_h%ns)  )
980        ALLOCATE ( surf_usm_h%rho_c_green(nzb_wall:nzt_wall,1:surf_usm_h%ns)     )
981
982!
983!--     For vertical surfaces.
984        DO  l = 0, 3
985           ALLOCATE ( surf_usm_v(l)%thickness_wall(1:surf_usm_v(l)%ns)               )
986           ALLOCATE ( surf_usm_v(l)%thickness_window(1:surf_usm_v(l)%ns)                  )
987           ALLOCATE ( surf_usm_v(l)%thickness_green(1:surf_usm_v(l)%ns)                   )
988           ALLOCATE ( surf_usm_v(l)%lambda_h(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns)   )
989           ALLOCATE ( surf_usm_v(l)%rho_c_wall(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns) )
990           ALLOCATE ( surf_usm_v(l)%lambda_h_window(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns) )
991           ALLOCATE ( surf_usm_v(l)%rho_c_window(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns)    )
992           ALLOCATE ( surf_usm_v(l)%lambda_h_green(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns)  )
993           ALLOCATE ( surf_usm_v(l)%rho_c_green(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns)     )
994        ENDDO
995
996!--     allocate wall and roof layers sizes. For horizontal surfaces.
997        ALLOCATE ( zwn(nzb_wall:nzt_wall) )
998        ALLOCATE ( surf_usm_h%dz_wall(nzb_wall:nzt_wall+1,1:surf_usm_h%ns)     )
999        ALLOCATE ( zwn_window(nzb_wall:nzt_wall) )
1000        ALLOCATE ( surf_usm_h%dz_window(nzb_wall:nzt_wall+1,1:surf_usm_h%ns)     )
1001        ALLOCATE ( zwn_green(nzb_wall:nzt_wall) )
1002        ALLOCATE ( surf_usm_h%dz_green(nzb_wall:nzt_wall+1,1:surf_usm_h%ns)      )
1003        ALLOCATE ( surf_usm_h%ddz_wall(nzb_wall:nzt_wall+1,1:surf_usm_h%ns)    )
1004        ALLOCATE ( surf_usm_h%dz_wall_stag(nzb_wall:nzt_wall,1:surf_usm_h%ns)  )
1005        ALLOCATE ( surf_usm_h%ddz_wall_stag(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
1006        ALLOCATE ( surf_usm_h%zw(nzb_wall:nzt_wall,1:surf_usm_h%ns)            )
1007        ALLOCATE ( surf_usm_h%ddz_window(nzb_wall:nzt_wall+1,1:surf_usm_h%ns)    )
1008        ALLOCATE ( surf_usm_h%dz_window_stag(nzb_wall:nzt_wall,1:surf_usm_h%ns)  )
1009        ALLOCATE ( surf_usm_h%ddz_window_stag(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
1010        ALLOCATE ( surf_usm_h%zw_window(nzb_wall:nzt_wall,1:surf_usm_h%ns)       )
1011        ALLOCATE ( surf_usm_h%ddz_green(nzb_wall:nzt_wall+1,1:surf_usm_h%ns)     )
1012        ALLOCATE ( surf_usm_h%dz_green_stag(nzb_wall:nzt_wall,1:surf_usm_h%ns)   )
1013        ALLOCATE ( surf_usm_h%ddz_green_stag(nzb_wall:nzt_wall,1:surf_usm_h%ns)  )
1014        ALLOCATE ( surf_usm_h%zw_green(nzb_wall:nzt_wall,1:surf_usm_h%ns)        )
1015!
1016!--     For vertical surfaces.
1017        DO  l = 0, 3
1018           ALLOCATE ( surf_usm_v(l)%dz_wall(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns)     )
1019           ALLOCATE ( surf_usm_v(l)%dz_window(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns)     )
1020           ALLOCATE ( surf_usm_v(l)%dz_green(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns)      )
1021           ALLOCATE ( surf_usm_v(l)%ddz_wall(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns)    )
1022           ALLOCATE ( surf_usm_v(l)%dz_wall_stag(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns)  )
1023           ALLOCATE ( surf_usm_v(l)%ddz_wall_stag(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns) )
1024           ALLOCATE ( surf_usm_v(l)%zw(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns)            )
1025           ALLOCATE ( surf_usm_v(l)%ddz_window(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns)    )
1026           ALLOCATE ( surf_usm_v(l)%dz_window_stag(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns)  )
1027           ALLOCATE ( surf_usm_v(l)%ddz_window_stag(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns) )
1028           ALLOCATE ( surf_usm_v(l)%zw_window(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns)       )
1029           ALLOCATE ( surf_usm_v(l)%ddz_green(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns)     )
1030           ALLOCATE ( surf_usm_v(l)%dz_green_stag(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns)   )
1031           ALLOCATE ( surf_usm_v(l)%ddz_green_stag(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns)  )
1032           ALLOCATE ( surf_usm_v(l)%zw_green(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns)        )
1033        ENDDO
1034
1035!--     allocate wall and roof temperature arrays, for horizontal walls
1036#if defined( __nopointer )
1037        IF ( .NOT. ALLOCATED( t_surf_h ) )                                     &
1038           ALLOCATE ( t_surf_h(1:surf_usm_h%ns) )
1039        IF ( .NOT. ALLOCATED( t_surf_h_p ) )                                   &
1040           ALLOCATE ( t_surf_h_p(1:surf_usm_h%ns) )
1041        IF ( .NOT. ALLOCATED( t_wall_h ) )                                     &           
1042           ALLOCATE ( t_wall_h(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) ) 
1043        IF ( .NOT. ALLOCATED( t_wall_h_p ) )                                   &           
1044           ALLOCATE ( t_wall_h_p(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) ) 
1045        IF ( .NOT. ALLOCATED( t_surf_window_h ) )                              &
1046           ALLOCATE ( t_surf_window_h(1:surf_usm_h%ns) )
1047        IF ( .NOT. ALLOCATED( t_surf_window_h_p ) )                            &
1048           ALLOCATE ( t_surf_window_h_p(1:surf_usm_h%ns) )
1049        IF ( .NOT. ALLOCATED( t_window_h ) )                                   &           
1050           ALLOCATE ( t_window_h(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) ) 
1051        IF ( .NOT. ALLOCATED( t_window_h_p ) )                                 &           
1052           ALLOCATE ( t_window_h_p(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) ) 
1053        IF ( .NOT. ALLOCATED( t_surf_green_h ) )                               &
1054           ALLOCATE ( t_surf_green_h(1:surf_usm_h%ns) )
1055        IF ( .NOT. ALLOCATED( t_surf_green_h_p ) )                             &
1056           ALLOCATE ( t_surf_green_h_p(1:surf_usm_h%ns) )           
1057        IF ( .NOT. ALLOCATED( t_green_h ) )                                    &           
1058           ALLOCATE ( t_green_h(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) ) 
1059        IF ( .NOT. ALLOCATED( t_green_h_p ) )                                  &           
1060           ALLOCATE ( t_green_h_p(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) ) 
1061        IF ( .NOT. ALLOCATED( t_surf_10cm_h ) )                                &
1062           ALLOCATE ( t_surf_10cm_h(1:surf_usm_h%ns) )
1063        IF ( .NOT. ALLOCATED( t_surf_10cm_h_p ) )                              &
1064           ALLOCATE ( t_surf_10cm_h_p(1:surf_usm_h%ns) )
1065#else
1066!
1067!--     Allocate if required. Note, in case of restarts, some of these arrays
1068!--     might be already allocated.
1069        IF ( .NOT. ALLOCATED( t_surf_h_1 ) )                                   &
1070           ALLOCATE ( t_surf_h_1(1:surf_usm_h%ns) )
1071        IF ( .NOT. ALLOCATED( t_surf_h_2 ) )                                   &
1072           ALLOCATE ( t_surf_h_2(1:surf_usm_h%ns) )
1073        IF ( .NOT. ALLOCATED( t_wall_h_1 ) )                                   &           
1074           ALLOCATE ( t_wall_h_1(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) ) 
1075        IF ( .NOT. ALLOCATED( t_wall_h_2 ) )                                   &           
1076           ALLOCATE ( t_wall_h_2(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) )         
1077        IF ( .NOT. ALLOCATED( t_surf_window_h_1 ) )                            &
1078           ALLOCATE ( t_surf_window_h_1(1:surf_usm_h%ns) )
1079        IF ( .NOT. ALLOCATED( t_surf_window_h_2 ) )                            &
1080           ALLOCATE ( t_surf_window_h_2(1:surf_usm_h%ns) )
1081        IF ( .NOT. ALLOCATED( t_window_h_1 ) )                                 &           
1082           ALLOCATE ( t_window_h_1(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) ) 
1083        IF ( .NOT. ALLOCATED( t_window_h_2 ) )                                 &           
1084           ALLOCATE ( t_window_h_2(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) )         
1085        IF ( .NOT. ALLOCATED( t_surf_green_h_1 ) )                             &
1086           ALLOCATE ( t_surf_green_h_1(1:surf_usm_h%ns) )
1087        IF ( .NOT. ALLOCATED( t_surf_green_h_2 ) )                             &
1088           ALLOCATE ( t_surf_green_h_2(1:surf_usm_h%ns) )
1089        IF ( .NOT. ALLOCATED( t_green_h_1 ) )                                  &           
1090           ALLOCATE ( t_green_h_1(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) ) 
1091        IF ( .NOT. ALLOCATED( t_green_h_2 ) )                                  &           
1092           ALLOCATE ( t_green_h_2(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) )         
1093        IF ( .NOT. ALLOCATED( t_surf_10cm_h_1 ) )                              &
1094           ALLOCATE ( t_surf_10cm_h_1(1:surf_usm_h%ns) )
1095        IF ( .NOT. ALLOCATED( t_surf_10cm_h_2 ) )                              &
1096           ALLOCATE ( t_surf_10cm_h_2(1:surf_usm_h%ns) )
1097!           
1098!--     initial assignment of the pointers
1099        t_wall_h    => t_wall_h_1;    t_wall_h_p    => t_wall_h_2
1100        t_window_h    => t_window_h_1;    t_window_h_p    => t_window_h_2
1101        t_green_h    => t_green_h_1;    t_green_h_p    => t_green_h_2
1102        t_surf_h => t_surf_h_1; t_surf_h_p => t_surf_h_2           
1103        t_surf_window_h => t_surf_window_h_1; t_surf_window_h_p => t_surf_window_h_2 
1104        t_surf_green_h => t_surf_green_h_1; t_surf_green_h_p => t_surf_green_h_2           
1105        t_surf_10cm_h => t_surf_10cm_h_1; t_surf_10cm_h_p => t_surf_10cm_h_2 
1106 
1107#endif
1108
1109!--     allocate wall and roof temperature arrays, for vertical walls if required
1110#if defined( __nopointer )
1111        DO  l = 0, 3
1112           IF ( .NOT. ALLOCATED( t_surf_v(l)%t ) )                             &
1113              ALLOCATE ( t_surf_v(l)%t(1:surf_usm_v(l)%ns) )
1114           IF ( .NOT. ALLOCATED( t_surf_v_p(l)%t ) )                           &
1115              ALLOCATE ( t_surf_v_p(l)%t(1:surf_usm_v(l)%ns) )
1116           IF ( .NOT. ALLOCATED( t_wall_v(l)%t ) )                             &
1117              ALLOCATE ( t_wall_v(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) )
1118           IF ( .NOT. ALLOCATED( t_wall_v_p(l)%t ) )                           &                 
1119              ALLOCATE ( t_wall_v_p(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) )
1120           IF ( .NOT. ALLOCATED( t_surf_window_v(l)%t ) )                      &
1121              ALLOCATE ( t_surf_window_v(l)%t(1:surf_usm_v(l)%ns) )
1122           IF ( .NOT. ALLOCATED( t_surf_window_v_p(l)%t ) )                    &
1123              ALLOCATE ( t_surf_window_v_p(l)%t(1:surf_usm_v(l)%ns) )
1124           IF ( .NOT. ALLOCATED( t_window_v(l)%t ) )                           &
1125              ALLOCATE ( t_window_v(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) )
1126           IF ( .NOT. ALLOCATED( t_window_v_p(l)%t ) )                         &                 
1127              ALLOCATE ( t_window_v_p(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) )
1128           IF ( .NOT. ALLOCATED( t_green_v(l)%t ) )                            &
1129              ALLOCATE ( t_green_v(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) )
1130           IF ( .NOT. ALLOCATED( t_green_v_p(l)%t ) )                          &                 
1131              ALLOCATE ( t_green_v_p(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) )
1132           IF ( .NOT. ALLOCATED( t_surf_green_v(l)%t ) )                       &
1133              ALLOCATE ( t_surf_green_v(l)%t(1:surf_usm_v(l)%ns) )
1134           IF ( .NOT. ALLOCATED( t_surf_green_v_p(l)%t ) )                     &
1135              ALLOCATE ( t_surf_green_v_p(l)%t(1:surf_usm_v(l)%ns) )
1136           IF ( .NOT. ALLOCATED( t_surf_10cm_v(l)%t ) )                        &
1137              ALLOCATE ( t_surf_10cm_v(l)%t(1:surf_usm_v(l)%ns) )
1138           IF ( .NOT. ALLOCATED( t_surf_10cm_v_p(l)%t ) )                        &
1139              ALLOCATE ( t_surf_10cm_v_p(l)%t(1:surf_usm_v(l)%ns) )
1140        ENDDO
1141#else
1142!
1143!--     Allocate if required. Note, in case of restarts, some of these arrays
1144!--     might be already allocated.
1145        DO  l = 0, 3
1146           IF ( .NOT. ALLOCATED( t_surf_v_1(l)%t ) )                           &
1147              ALLOCATE ( t_surf_v_1(l)%t(1:surf_usm_v(l)%ns) )
1148           IF ( .NOT. ALLOCATED( t_surf_v_2(l)%t ) )                           &
1149              ALLOCATE ( t_surf_v_2(l)%t(1:surf_usm_v(l)%ns) )
1150           IF ( .NOT. ALLOCATED( t_wall_v_1(l)%t ) )                           &           
1151              ALLOCATE ( t_wall_v_1(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) ) 
1152           IF ( .NOT. ALLOCATED( t_wall_v_2(l)%t ) )                           &           
1153              ALLOCATE ( t_wall_v_2(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) ) 
1154           IF ( .NOT. ALLOCATED( t_surf_window_v_1(l)%t ) )                    &
1155              ALLOCATE ( t_surf_window_v_1(l)%t(1:surf_usm_v(l)%ns) )
1156           IF ( .NOT. ALLOCATED( t_surf_window_v_2(l)%t ) )                    &
1157              ALLOCATE ( t_surf_window_v_2(l)%t(1:surf_usm_v(l)%ns) )
1158           IF ( .NOT. ALLOCATED( t_window_v_1(l)%t ) )                         &           
1159              ALLOCATE ( t_window_v_1(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) ) 
1160           IF ( .NOT. ALLOCATED( t_window_v_2(l)%t ) )                         &           
1161              ALLOCATE ( t_window_v_2(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) ) 
1162           IF ( .NOT. ALLOCATED( t_surf_green_v_1(l)%t ) )                     &
1163              ALLOCATE ( t_surf_green_v_1(l)%t(1:surf_usm_v(l)%ns) )
1164           IF ( .NOT. ALLOCATED( t_surf_green_v_2(l)%t ) )                     &
1165              ALLOCATE ( t_surf_green_v_2(l)%t(1:surf_usm_v(l)%ns) )
1166           IF ( .NOT. ALLOCATED( t_green_v_1(l)%t ) )                          &           
1167              ALLOCATE ( t_green_v_1(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) ) 
1168           IF ( .NOT. ALLOCATED( t_green_v_2(l)%t ) )                          &           
1169              ALLOCATE ( t_green_v_2(l)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) ) 
1170           IF ( .NOT. ALLOCATED( t_surf_10cm_v_1(l)%t ) )                     &
1171              ALLOCATE ( t_surf_10cm_v_1(l)%t(1:surf_usm_v(l)%ns) )
1172           IF ( .NOT. ALLOCATED( t_surf_10cm_v_2(l)%t ) )                     &
1173              ALLOCATE ( t_surf_10cm_v_2(l)%t(1:surf_usm_v(l)%ns) )
1174        ENDDO
1175!
1176!--     initial assignment of the pointers
1177        t_wall_v    => t_wall_v_1;    t_wall_v_p    => t_wall_v_2
1178        t_surf_v => t_surf_v_1; t_surf_v_p => t_surf_v_2
1179        t_window_v    => t_window_v_1;    t_window_v_p    => t_window_v_2
1180        t_green_v    => t_green_v_1;    t_green_v_p    => t_green_v_2
1181        t_surf_window_v => t_surf_window_v_1; t_surf_window_v_p => t_surf_window_v_2
1182        t_surf_green_v => t_surf_green_v_1; t_surf_green_v_p => t_surf_green_v_2
1183        t_surf_10cm_v => t_surf_10cm_v_1; t_surf_10cm_v_p => t_surf_10cm_v_2
1184
1185#endif
1186!
1187!--     Allocate intermediate timestep arrays. For horizontal surfaces.
1188        ALLOCATE ( surf_usm_h%tt_surface_m(1:surf_usm_h%ns)                  )
1189        ALLOCATE ( surf_usm_h%tt_wall_m(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) )
1190        ALLOCATE ( surf_usm_h%tt_surface_window_m(1:surf_usm_h%ns)             )
1191        ALLOCATE ( surf_usm_h%tt_window_m(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) )
1192        ALLOCATE ( surf_usm_h%tt_green_m(nzb_wall:nzt_wall+1,1:surf_usm_h%ns)  )
1193        ALLOCATE ( surf_usm_h%tt_surface_green_m(1:surf_usm_h%ns)              )
1194
1195!
1196!--     Set inital values for prognostic quantities
1197        IF ( ALLOCATED( surf_usm_h%tt_surface_m ) )  surf_usm_h%tt_surface_m = 0.0_wp
1198        IF ( ALLOCATED( surf_usm_h%tt_wall_m    ) )  surf_usm_h%tt_wall_m    = 0.0_wp
1199        IF ( ALLOCATED( surf_usm_h%tt_surface_window_m ) )  surf_usm_h%tt_surface_window_m = 0.0_wp
1200        IF ( ALLOCATED( surf_usm_h%tt_window_m    )      )  surf_usm_h%tt_window_m         = 0.0_wp
1201        IF ( ALLOCATED( surf_usm_h%tt_green_m    )       )  surf_usm_h%tt_green_m          = 0.0_wp
1202        IF ( ALLOCATED( surf_usm_h%tt_surface_green_m )  )  surf_usm_h%tt_surface_green_m  = 0.0_wp
1203!
1204!--     Now, for vertical surfaces
1205        DO  l = 0, 3
1206           ALLOCATE ( surf_usm_v(l)%tt_surface_m(1:surf_usm_v(l)%ns)                  )
1207           ALLOCATE ( surf_usm_v(l)%tt_wall_m(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) )
1208           IF ( ALLOCATED( surf_usm_v(l)%tt_surface_m ) )  surf_usm_v(l)%tt_surface_m = 0.0_wp
1209           IF ( ALLOCATED( surf_usm_v(l)%tt_wall_m    ) )  surf_usm_v(l)%tt_wall_m    = 0.0_wp
1210           ALLOCATE ( surf_usm_v(l)%tt_surface_window_m(1:surf_usm_v(l)%ns)             )
1211           ALLOCATE ( surf_usm_v(l)%tt_window_m(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns) )
1212           IF ( ALLOCATED( surf_usm_v(l)%tt_surface_window_m ) )  surf_usm_v(l)%tt_surface_window_m = 0.0_wp
1213           IF ( ALLOCATED( surf_usm_v(l)%tt_window_m  ) )  surf_usm_v(l)%tt_window_m    = 0.0_wp
1214           ALLOCATE ( surf_usm_v(l)%tt_surface_green_m(1:surf_usm_v(l)%ns)              )
1215           IF ( ALLOCATED( surf_usm_v(l)%tt_surface_green_m ) )  surf_usm_v(l)%tt_surface_green_m = 0.0_wp
1216           ALLOCATE ( surf_usm_v(l)%tt_green_m(nzb_wall:nzt_wall+1,1:surf_usm_v(l)%ns)  )
1217           IF ( ALLOCATED( surf_usm_v(l)%tt_green_m   ) )  surf_usm_v(l)%tt_green_m    = 0.0_wp
1218        ENDDO
1219
1220!--     allocate wall heat flux output array and set initial values. For horizontal surfaces
1221!         ALLOCATE ( surf_usm_h%wshf(1:surf_usm_h%ns)    )  !can be removed
1222        ALLOCATE ( surf_usm_h%wshf_eb(1:surf_usm_h%ns) )
1223        ALLOCATE ( surf_usm_h%wghf_eb(1:surf_usm_h%ns) )
1224        ALLOCATE ( surf_usm_h%wghf_eb_window(1:surf_usm_h%ns) )
1225        ALLOCATE ( surf_usm_h%wghf_eb_green(1:surf_usm_h%ns) )
1226        ALLOCATE ( surf_usm_h%iwghf_eb(1:surf_usm_h%ns) )
1227        ALLOCATE ( surf_usm_h%iwghf_eb_window(1:surf_usm_h%ns) )
1228        IF ( ALLOCATED( surf_usm_h%wshf    ) )  surf_usm_h%wshf    = 0.0_wp
1229        IF ( ALLOCATED( surf_usm_h%wshf_eb ) )  surf_usm_h%wshf_eb = 0.0_wp
1230        IF ( ALLOCATED( surf_usm_h%wghf_eb ) )  surf_usm_h%wghf_eb = 0.0_wp
1231        IF ( ALLOCATED( surf_usm_h%wghf_eb_window ) )  surf_usm_h%wghf_eb_window = 0.0_wp
1232        IF ( ALLOCATED( surf_usm_h%wghf_eb_green ) )  surf_usm_h%wghf_eb_green = 0.0_wp
1233        IF ( ALLOCATED( surf_usm_h%iwghf_eb ) )  surf_usm_h%iwghf_eb = 0.0_wp
1234        IF ( ALLOCATED( surf_usm_h%iwghf_eb_window ) )  surf_usm_h%iwghf_eb_window = 0.0_wp
1235!
1236!--     Now, for vertical surfaces
1237        DO  l = 0, 3
1238!            ALLOCATE ( surf_usm_v(l)%wshf(1:surf_usm_v(l)%ns)    )    ! can be removed
1239           ALLOCATE ( surf_usm_v(l)%wshf_eb(1:surf_usm_v(l)%ns) )
1240           ALLOCATE ( surf_usm_v(l)%wghf_eb(1:surf_usm_v(l)%ns) )
1241           ALLOCATE ( surf_usm_v(l)%wghf_eb_window(1:surf_usm_v(l)%ns) )
1242           ALLOCATE ( surf_usm_v(l)%wghf_eb_green(1:surf_usm_v(l)%ns) )
1243           ALLOCATE ( surf_usm_v(l)%iwghf_eb(1:surf_usm_v(l)%ns) )
1244           ALLOCATE ( surf_usm_v(l)%iwghf_eb_window(1:surf_usm_v(l)%ns) )
1245           IF ( ALLOCATED( surf_usm_v(l)%wshf    ) )  surf_usm_v(l)%wshf    = 0.0_wp
1246           IF ( ALLOCATED( surf_usm_v(l)%wshf_eb ) )  surf_usm_v(l)%wshf_eb = 0.0_wp
1247           IF ( ALLOCATED( surf_usm_v(l)%wghf_eb ) )  surf_usm_v(l)%wghf_eb = 0.0_wp
1248           IF ( ALLOCATED( surf_usm_v(l)%wghf_eb_window ) )  surf_usm_v(l)%wghf_eb_window = 0.0_wp
1249           IF ( ALLOCATED( surf_usm_v(l)%wghf_eb_green ) )  surf_usm_v(l)%wghf_eb_green = 0.0_wp
1250           IF ( ALLOCATED( surf_usm_v(l)%iwghf_eb ) )  surf_usm_v(l)%iwghf_eb = 0.0_wp
1251           IF ( ALLOCATED( surf_usm_v(l)%iwghf_eb_window ) )  surf_usm_v(l)%iwghf_eb_window = 0.0_wp
1252        ENDDO
1253       
1254    END SUBROUTINE usm_allocate_surface
1255
1256
1257!------------------------------------------------------------------------------!
1258! Description:
1259! ------------
1260!> Sum up and time-average urban surface output quantities as well as allocate
1261!> the array necessary for storing the average.
1262!------------------------------------------------------------------------------!
1263    SUBROUTINE usm_average_3d_data( mode, variable )
1264
1265        IMPLICIT NONE
1266
1267        CHARACTER(LEN=*), INTENT(IN) ::  mode
1268        CHARACTER(LEN=*), INTENT(IN) :: variable
1269 
1270        INTEGER(iwp)                                       :: i, j, k, l, m, ids, idsint, iwl, istat
1271        CHARACTER(LEN=varnamelength)                       :: var
1272        INTEGER(iwp), PARAMETER                            :: nd = 5
1273        CHARACTER(LEN=6), DIMENSION(0:nd-1), PARAMETER     :: dirname = (/ '_roof ', '_south', '_north', '_west ', '_east ' /)
1274        INTEGER(iwp), DIMENSION(0:nd-1), PARAMETER         :: dirint = (/ iup_u, isouth_u, inorth_u, iwest_u, ieast_u /)
1275
1276!--     find the real name of the variable
1277        ids = -1
1278        l = -1
1279        var = TRIM(variable)
1280        DO i = 0, nd-1
1281            k = len(TRIM(var))
1282            j = len(TRIM(dirname(i)))
1283            IF ( TRIM(var(k-j+1:k)) == TRIM(dirname(i)) )  THEN
1284                ids = i
1285                idsint = dirint(ids)
1286                var = var(:k-j)
1287                EXIT
1288            ENDIF
1289        ENDDO
1290        l = idsint - 2  ! horisontal direction index - terible hack !
1291        IF ( l < 0 .OR. l > 3 ) THEN
1292           l = -1
1293        END IF
1294        IF ( ids == -1 )  THEN
1295            var = TRIM(variable)
1296        ENDIF
1297        IF ( var(1:11) == 'usm_t_wall_'  .AND.  len(TRIM(var)) >= 12 )  THEN
1298!--          wall layers
1299            READ(var(12:12), '(I1)', iostat=istat ) iwl
1300            IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
1301                var = var(1:10)
1302            ELSE
1303!--             wrong wall layer index
1304                RETURN
1305            ENDIF
1306        ENDIF
1307        IF ( var(1:13) == 'usm_t_window_'  .AND.  len(TRIM(var)) >= 14 )  THEN
1308!--          wall layers
1309            READ(var(14:14), '(I1)', iostat=istat ) iwl
1310            IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
1311                var = var(1:12)
1312            ELSE
1313!--             wrong window layer index
1314                RETURN
1315            ENDIF
1316        ENDIF
1317        IF ( var(1:12) == 'usm_t_green_'  .AND.  len(TRIM(var)) >= 13 )  THEN
1318!--          wall layers
1319            READ(var(13:13), '(I1)', iostat=istat ) iwl
1320            IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
1321                var = var(1:11)
1322            ELSE
1323!--             wrong green layer index
1324                RETURN
1325            ENDIF
1326        ENDIF
1327
1328        IF ( mode == 'allocate' )  THEN
1329           
1330           SELECT CASE ( TRIM( var ) )
1331               
1332                CASE ( 'usm_rad_net' )
1333!--                 array of complete radiation balance
1334                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%rad_net_av) )  THEN
1335                        ALLOCATE( surf_usm_h%rad_net_av(1:surf_usm_h%ns) )
1336                        surf_usm_h%rad_net_av = 0.0_wp
1337                    ELSE
1338                        IF ( .NOT.  ALLOCATED(surf_usm_v(l)%rad_net_av) )  THEN
1339                            ALLOCATE( surf_usm_v(l)%rad_net_av(1:surf_usm_v(l)%ns) )
1340                            surf_usm_v(l)%rad_net_av = 0.0_wp
1341                        ENDIF
1342                    ENDIF
1343                   
1344                CASE ( 'usm_rad_insw' )
1345!--                 array of sw radiation falling to surface after i-th reflection
1346                    IF ( .NOT.  ALLOCATED(surfinsw_av) )  THEN
1347                        ALLOCATE( surfinsw_av(nsurfl) )
1348                        surfinsw_av = 0.0_wp
1349                    ENDIF
1350
1351                CASE ( 'usm_rad_inlw' )
1352!--                 array of lw radiation falling to surface after i-th reflection
1353                    IF ( .NOT.  ALLOCATED(surfinlw_av) )  THEN
1354                        ALLOCATE( surfinlw_av(nsurfl) )
1355                        surfinlw_av = 0.0_wp
1356                    ENDIF
1357
1358                CASE ( 'usm_rad_inswdir' )
1359!--                 array of direct sw radiation falling to surface from sun
1360                    IF ( .NOT.  ALLOCATED(surfinswdir_av) )  THEN
1361                        ALLOCATE( surfinswdir_av(nsurfl) )
1362                        surfinswdir_av = 0.0_wp
1363                    ENDIF
1364
1365                CASE ( 'usm_rad_inswdif' )
1366!--                 array of difusion sw radiation falling to surface from sky and borders of the domain
1367                    IF ( .NOT.  ALLOCATED(surfinswdif_av) )  THEN
1368                        ALLOCATE( surfinswdif_av(nsurfl) )
1369                        surfinswdif_av = 0.0_wp
1370                    ENDIF
1371
1372                CASE ( 'usm_rad_inswref' )
1373!--                 array of sw radiation falling to surface from reflections
1374                    IF ( .NOT.  ALLOCATED(surfinswref_av) )  THEN
1375                        ALLOCATE( surfinswref_av(nsurfl) )
1376                        surfinswref_av = 0.0_wp
1377                    ENDIF
1378
1379                CASE ( 'usm_rad_inlwdif' )
1380!--                 array of sw radiation falling to surface after i-th reflection
1381                   IF ( .NOT.  ALLOCATED(surfinlwdif_av) )  THEN
1382                        ALLOCATE( surfinlwdif_av(nsurfl) )
1383                        surfinlwdif_av = 0.0_wp
1384                    ENDIF
1385
1386                CASE ( 'usm_rad_inlwref' )
1387!--                 array of lw radiation falling to surface from reflections
1388                    IF ( .NOT.  ALLOCATED(surfinlwref_av) )  THEN
1389                        ALLOCATE( surfinlwref_av(nsurfl) )
1390                        surfinlwref_av = 0.0_wp
1391                    ENDIF
1392
1393                CASE ( 'usm_rad_outsw' )
1394!--                 array of sw radiation emitted from surface after i-th reflection
1395                    IF ( .NOT.  ALLOCATED(surfoutsw_av) )  THEN
1396                        ALLOCATE( surfoutsw_av(nsurfl) )
1397                        surfoutsw_av = 0.0_wp
1398                    ENDIF
1399
1400                CASE ( 'usm_rad_outlw' )
1401!--                 array of lw radiation emitted from surface after i-th reflection
1402                    IF ( .NOT.  ALLOCATED(surfoutlw_av) )  THEN
1403                        ALLOCATE( surfoutlw_av(nsurfl) )
1404                        surfoutlw_av = 0.0_wp
1405                    ENDIF
1406                CASE ( 'usm_rad_ressw' )
1407!--                 array of residua of sw radiation absorbed in surface after last reflection
1408                    IF ( .NOT.  ALLOCATED(surfins_av) )  THEN
1409                        ALLOCATE( surfins_av(nsurfl) )
1410                        surfins_av = 0.0_wp
1411                    ENDIF
1412                                   
1413                CASE ( 'usm_rad_reslw' )
1414!--                 array of residua of lw radiation absorbed in surface after last reflection
1415                    IF ( .NOT.  ALLOCATED(surfinl_av) )  THEN
1416                        ALLOCATE( surfinl_av(nsurfl) )
1417                        surfinl_av = 0.0_wp
1418                    ENDIF
1419                                   
1420                CASE ( 'usm_rad_pc_inlw' )
1421!--                 array of of lw radiation absorbed in plant canopy
1422                    IF ( .NOT.  ALLOCATED(pcbinlw_av) )  THEN
1423                        ALLOCATE( pcbinlw_av(1:npcbl) )
1424                        pcbinlw_av = 0.0_wp
1425                    ENDIF
1426                                   
1427                CASE ( 'usm_rad_pc_insw' )
1428!--                 array of of sw radiation absorbed in plant canopy
1429                    IF ( .NOT.  ALLOCATED(pcbinsw_av) )  THEN
1430                        ALLOCATE( pcbinsw_av(1:npcbl) )
1431                        pcbinsw_av = 0.0_wp
1432                    ENDIF
1433                                   
1434                CASE ( 'usm_rad_pc_inswdir' )
1435!--                 array of of direct sw radiation absorbed in plant canopy
1436                    IF ( .NOT.  ALLOCATED(pcbinswdir_av) )  THEN
1437                        ALLOCATE( pcbinswdir_av(1:npcbl) )
1438                        pcbinswdir_av = 0.0_wp
1439                    ENDIF
1440                                   
1441                CASE ( 'usm_rad_pc_inswdif' )
1442!--                 array of of diffuse sw radiation absorbed in plant canopy
1443                    IF ( .NOT.  ALLOCATED(pcbinswdif_av) )  THEN
1444                        ALLOCATE( pcbinswdif_av(1:npcbl) )
1445                        pcbinswdif_av = 0.0_wp
1446                    ENDIF
1447                                   
1448                CASE ( 'usm_rad_pc_inswref' )
1449!--                 array of of reflected sw radiation absorbed in plant canopy
1450                    IF ( .NOT.  ALLOCATED(pcbinswref_av) )  THEN
1451                        ALLOCATE( pcbinswref_av(1:npcbl) )
1452                        pcbinswref_av = 0.0_wp
1453                    ENDIF
1454                                   
1455                CASE ( 'usm_rad_hf' )
1456!--                 array of heat flux from radiation for surfaces after i-th reflection
1457                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%surfhf_av) )  THEN
1458                        ALLOCATE( surf_usm_h%surfhf_av(1:surf_usm_h%ns) )
1459                        surf_usm_h%surfhf_av = 0.0_wp
1460                    ELSE
1461                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%surfhf_av) )  THEN
1462                           ALLOCATE( surf_usm_v(l)%surfhf_av(1:surf_usm_v(l)%ns) )
1463                           surf_usm_v(l)%surfhf_av = 0.0_wp
1464                       ENDIF
1465                    ENDIF
1466
1467                CASE ( 'usm_wshf' )
1468!--                 array of sensible heat flux from surfaces
1469!--                 land surfaces
1470                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%wshf_eb_av) )  THEN
1471                        ALLOCATE( surf_usm_h%wshf_eb_av(1:surf_usm_h%ns) )
1472                        surf_usm_h%wshf_eb_av = 0.0_wp
1473                    ELSE
1474                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%wshf_eb_av) )  THEN
1475                           ALLOCATE( surf_usm_v(l)%wshf_eb_av(1:surf_usm_v(l)%ns) )
1476                           surf_usm_v(l)%wshf_eb_av = 0.0_wp
1477                       ENDIF
1478                    ENDIF
1479!
1480!--             Please note, the following output quantities belongs to the
1481!--             individual tile fractions - ground heat flux at wall-, window-,
1482!--             and green fraction. Aggregated ground-heat flux is treated
1483!--             accordingly in average_3d_data, sum_up_3d_data, etc..
1484                CASE ( 'usm_wghf' )
1485!--                 array of heat flux from ground (wall, roof, land)
1486                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%wghf_eb_av) )  THEN
1487                        ALLOCATE( surf_usm_h%wghf_eb_av(1:surf_usm_h%ns) )
1488                        surf_usm_h%wghf_eb_av = 0.0_wp
1489                    ELSE
1490                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%wghf_eb_av) )  THEN
1491                           ALLOCATE( surf_usm_v(l)%wghf_eb_av(1:surf_usm_v(l)%ns) )
1492                           surf_usm_v(l)%wghf_eb_av = 0.0_wp
1493                       ENDIF
1494                    ENDIF
1495
1496                CASE ( 'usm_wghf_window' )
1497!--                 array of heat flux from window ground (wall, roof, land)
1498                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%wghf_eb_window_av) )  THEN
1499                        ALLOCATE( surf_usm_h%wghf_eb_window_av(1:surf_usm_h%ns) )
1500                        surf_usm_h%wghf_eb_window_av = 0.0_wp
1501                    ELSE
1502                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%wghf_eb_window_av) )  THEN
1503                           ALLOCATE( surf_usm_v(l)%wghf_eb_window_av(1:surf_usm_v(l)%ns) )
1504                           surf_usm_v(l)%wghf_eb_window_av = 0.0_wp
1505                       ENDIF
1506                    ENDIF
1507
1508                CASE ( 'usm_wghf_green' )
1509!--                 array of heat flux from green ground (wall, roof, land)
1510                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%wghf_eb_green_av) )  THEN
1511                        ALLOCATE( surf_usm_h%wghf_eb_green_av(1:surf_usm_h%ns) )
1512                        surf_usm_h%wghf_eb_green_av = 0.0_wp
1513                    ELSE
1514                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%wghf_eb_green_av) )  THEN
1515                           ALLOCATE( surf_usm_v(l)%wghf_eb_green_av(1:surf_usm_v(l)%ns) )
1516                           surf_usm_v(l)%wghf_eb_green_av = 0.0_wp
1517                       ENDIF
1518                    ENDIF
1519
1520                CASE ( 'usm_iwghf' )
1521!--                 array of heat flux from indoor ground (wall, roof, land)
1522                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%iwghf_eb_av) )  THEN
1523                        ALLOCATE( surf_usm_h%iwghf_eb_av(1:surf_usm_h%ns) )
1524                        surf_usm_h%iwghf_eb_av = 0.0_wp
1525                    ELSE
1526                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%iwghf_eb_av) )  THEN
1527                           ALLOCATE( surf_usm_v(l)%iwghf_eb_av(1:surf_usm_v(l)%ns) )
1528                           surf_usm_v(l)%iwghf_eb_av = 0.0_wp
1529                       ENDIF
1530                    ENDIF
1531
1532                CASE ( 'usm_iwghf_window' )
1533!--                 array of heat flux from indoor window ground (wall, roof, land)
1534                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%iwghf_eb_window_av) )  THEN
1535                        ALLOCATE( surf_usm_h%iwghf_eb_window_av(1:surf_usm_h%ns) )
1536                        surf_usm_h%iwghf_eb_window_av = 0.0_wp
1537                    ELSE
1538                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%iwghf_eb_window_av) )  THEN
1539                           ALLOCATE( surf_usm_v(l)%iwghf_eb_window_av(1:surf_usm_v(l)%ns) )
1540                           surf_usm_v(l)%iwghf_eb_window_av = 0.0_wp
1541                       ENDIF
1542                    ENDIF
1543                   
1544                CASE ( 'usm_t_surf' )
1545!--                 surface temperature for surfaces
1546                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_surf_av) )  THEN
1547                        ALLOCATE( surf_usm_h%t_surf_av(1:surf_usm_h%ns) )
1548                        surf_usm_h%t_surf_av = 0.0_wp
1549                    ELSE
1550                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_surf_av) )  THEN
1551                           ALLOCATE( surf_usm_v(l)%t_surf_av(1:surf_usm_v(l)%ns) )
1552                           surf_usm_v(l)%t_surf_av = 0.0_wp
1553                       ENDIF
1554                    ENDIF
1555
1556                CASE ( 'usm_t_surf_window' )
1557!--                 surface temperature for window surfaces
1558                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_surf_window_av) )  THEN
1559                        ALLOCATE( surf_usm_h%t_surf_window_av(1:surf_usm_h%ns) )
1560                        surf_usm_h%t_surf_window_av = 0.0_wp
1561                    ELSE
1562                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_surf_window_av) )  THEN
1563                           ALLOCATE( surf_usm_v(l)%t_surf_window_av(1:surf_usm_v(l)%ns) )
1564                           surf_usm_v(l)%t_surf_window_av = 0.0_wp
1565                       ENDIF
1566                    ENDIF
1567                   
1568                CASE ( 'usm_t_surf_green' )
1569!--                 surface temperature for green surfaces
1570                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_surf_green_av) )  THEN
1571                        ALLOCATE( surf_usm_h%t_surf_green_av(1:surf_usm_h%ns) )
1572                        surf_usm_h%t_surf_green_av = 0.0_wp
1573                    ELSE
1574                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_surf_green_av) )  THEN
1575                           ALLOCATE( surf_usm_v(l)%t_surf_green_av(1:surf_usm_v(l)%ns) )
1576                           surf_usm_v(l)%t_surf_green_av = 0.0_wp
1577                       ENDIF
1578                    ENDIF
1579               
1580                CASE ( 'usm_t_surf_10cm' )
1581!--                 near surface temperature for whole surfaces
1582                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_surf_10cm_av) )  THEN
1583                        ALLOCATE( surf_usm_h%t_surf_10cm_av(1:surf_usm_h%ns) )
1584                        surf_usm_h%t_surf_10cm_av = 0.0_wp
1585                    ELSE
1586                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_surf_10cm_av) )  THEN
1587                           ALLOCATE( surf_usm_v(l)%t_surf_10cm_av(1:surf_usm_v(l)%ns) )
1588                           surf_usm_v(l)%t_surf_10cm_av = 0.0_wp
1589                       ENDIF
1590                    ENDIF
1591
1592                CASE ( 'usm_t_wall' )
1593!--                 wall temperature for iwl layer of walls and land
1594                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_wall_av) )  THEN
1595                        ALLOCATE( surf_usm_h%t_wall_av(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
1596                        surf_usm_h%t_wall_av = 0.0_wp
1597                    ELSE
1598                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_wall_av) )  THEN
1599                           ALLOCATE( surf_usm_v(l)%t_wall_av(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns) )
1600                           surf_usm_v(l)%t_wall_av = 0.0_wp
1601                       ENDIF
1602                    ENDIF
1603
1604                CASE ( 'usm_t_window' )
1605!--                 window temperature for iwl layer of walls and land
1606                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_window_av) )  THEN
1607                        ALLOCATE( surf_usm_h%t_window_av(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
1608                        surf_usm_h%t_window_av = 0.0_wp
1609                    ELSE
1610                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_window_av) )  THEN
1611                           ALLOCATE( surf_usm_v(l)%t_window_av(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns) )
1612                           surf_usm_v(l)%t_window_av = 0.0_wp
1613                       ENDIF
1614                    ENDIF
1615
1616                CASE ( 'usm_t_green' )
1617!--                 green temperature for iwl layer of walls and land
1618                    IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_green_av) )  THEN
1619                        ALLOCATE( surf_usm_h%t_green_av(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
1620                        surf_usm_h%t_green_av = 0.0_wp
1621                    ELSE
1622                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_green_av) )  THEN
1623                           ALLOCATE( surf_usm_v(l)%t_green_av(nzb_wall:nzt_wall,1:surf_usm_v(l)%ns) )
1624                           surf_usm_v(l)%t_green_av = 0.0_wp
1625                       ENDIF
1626                    ENDIF
1627
1628               CASE DEFAULT
1629                   CONTINUE
1630
1631           END SELECT
1632
1633        ELSEIF ( mode == 'sum' )  THEN
1634           
1635           SELECT CASE ( TRIM( var ) )
1636               
1637                CASE ( 'usm_rad_net' )
1638!--                 array of complete radiation balance
1639                    IF ( l == -1 ) THEN
1640                       DO  m = 1, surf_usm_h%ns
1641                          surf_usm_h%rad_net_av(m) =                              &
1642                                             surf_usm_h%rad_net_av(m) +           &
1643                                             surf_usm_h%rad_net_l(m)
1644                       ENDDO
1645                    ELSE
1646                       DO  m = 1, surf_usm_v(l)%ns
1647                          surf_usm_v(l)%rad_net_av(m) =                        &
1648                                          surf_usm_v(l)%rad_net_av(m) +        &
1649                                          surf_usm_v(l)%rad_net_l(m)
1650                       ENDDO
1651                    ENDIF
1652
1653                CASE ( 'usm_rad_insw' )
1654!--                 array of sw radiation falling to surface after i-th reflection
1655                    DO l = 1, nsurfl
1656                        IF ( surfl(id,l) == idsint )  THEN
1657                            surfinsw_av(l) = surfinsw_av(l) + surfinsw(l)
1658                        ENDIF
1659                    ENDDO
1660                             
1661                CASE ( 'usm_rad_inlw' )
1662!--                 array of lw radiation falling to surface after i-th reflection
1663                    DO l = 1, nsurfl
1664                        IF ( surfl(id,l) == idsint )  THEN
1665                            surfinlw_av(l) = surfinlw_av(l) + surfinlw(l)
1666                        ENDIF
1667                    ENDDO
1668                   
1669                CASE ( 'usm_rad_inswdir' )
1670!--                 array of direct sw radiation falling to surface from sun
1671                    DO l = 1, nsurfl
1672                        IF ( surfl(id,l) == idsint )  THEN
1673                            surfinswdir_av(l) = surfinswdir_av(l) + surfinswdir(l)
1674                        ENDIF
1675                    ENDDO
1676                   
1677                CASE ( 'usm_rad_inswdif' )
1678!--                 array of difusion sw radiation falling to surface from sky and borders of the domain
1679                    DO l = 1, nsurfl
1680                        IF ( surfl(id,l) == idsint )  THEN
1681                            surfinswdif_av(l) = surfinswdif_av(l) + surfinswdif(l)
1682                        ENDIF
1683                    ENDDO
1684                   
1685                CASE ( 'usm_rad_inswref' )
1686!--                 array of sw radiation falling to surface from reflections
1687                    DO l = 1, nsurfl
1688                        IF ( surfl(id,l) == idsint )  THEN
1689                            surfinswref_av(l) = surfinswref_av(l) + surfinsw(l) - &
1690                                                surfinswdir(l) - surfinswdif(l)
1691                        ENDIF
1692                    ENDDO
1693
1694                   
1695                CASE ( 'usm_rad_inlwdif' )
1696!--                 array of sw radiation falling to surface after i-th reflection
1697                    DO l = 1, nsurfl
1698                        IF ( surfl(id,l) == idsint )  THEN
1699                            surfinlwdif_av(l) = surfinlwdif_av(l) + surfinlwdif(l)
1700                        ENDIF
1701                    ENDDO
1702!                     
1703                CASE ( 'usm_rad_inlwref' )
1704!--                 array of lw radiation falling to surface from reflections
1705                    DO l = 1, nsurfl
1706                        IF ( surfl(id,l) == idsint )  THEN
1707                            surfinlwref_av(l) = surfinlwref_av(l) + &
1708                                                surfinlw(l) - surfinlwdif(l)
1709                        ENDIF
1710                    ENDDO
1711                   
1712                CASE ( 'usm_rad_outsw' )
1713!--                 array of sw radiation emitted from surface after i-th reflection
1714                    DO l = 1, nsurfl
1715                        IF ( surfl(id,l) == idsint )  THEN
1716                            surfoutsw_av(l) = surfoutsw_av(l) + surfoutsw(l)
1717                        ENDIF
1718                    ENDDO
1719                   
1720                CASE ( 'usm_rad_outlw' )
1721!--                 array of lw radiation emitted from surface after i-th reflection
1722                    DO l = 1, nsurfl
1723                        IF ( surfl(id,l) == idsint )  THEN
1724                            surfoutlw_av(l) = surfoutlw_av(l) + surfoutlw(l)
1725                        ENDIF
1726                    ENDDO
1727                   
1728                CASE ( 'usm_rad_ressw' )
1729!--                 array of residua of sw radiation absorbed in surface after last reflection
1730                    DO l = 1, nsurfl
1731                        IF ( surfl(id,l) == idsint )  THEN
1732                            surfins_av(l) = surfins_av(l) + surfins(l)
1733                        ENDIF
1734                    ENDDO
1735                                   
1736                CASE ( 'usm_rad_reslw' )
1737!--                 array of residua of lw radiation absorbed in surface after last reflection
1738                    DO l = 1, nsurfl
1739                        IF ( surfl(id,l) == idsint )  THEN
1740                            surfinl_av(l) = surfinl_av(l) + surfinl(l)
1741                        ENDIF
1742                    ENDDO
1743                   
1744                CASE ( 'usm_rad_pc_inlw' )
1745                    pcbinlw_av(:) = pcbinlw_av(:) + pcbinlw(:)
1746                   
1747                CASE ( 'usm_rad_pc_insw' )
1748                    pcbinsw_av(:) = pcbinsw_av(:) + pcbinsw(:)
1749                   
1750                CASE ( 'usm_rad_pc_inswdir' )
1751                    pcbinswdir_av(:) = pcbinswdir_av(:) + pcbinswdir(:)
1752                   
1753                CASE ( 'usm_rad_pc_inswdif' )
1754                    pcbinswdif_av(:) = pcbinswdif_av(:) + pcbinswdif(:)
1755                   
1756                CASE ( 'usm_rad_pc_inswref' )
1757                    pcbinswref_av(:) = pcbinswref_av(:) + pcbinsw(:)     &
1758                                                        - pcbinswdir(:)  &
1759                                                        - pcbinswdif(:)
1760                   
1761                CASE ( 'usm_rad_hf' )
1762!--                 array of heat flux from radiation for surfaces after i-th reflection
1763                    IF ( l == -1 ) THEN
1764                       DO  m = 1, surf_usm_h%ns
1765                          surf_usm_h%surfhf_av(m) =                               &
1766                                             surf_usm_h%surfhf_av(m) +            &
1767                                             surf_usm_h%surfhf(m)
1768                       ENDDO
1769                    ELSE
1770                       DO  m = 1, surf_usm_v(l)%ns
1771                          surf_usm_v(l)%surfhf_av(m) =                         &
1772                                          surf_usm_v(l)%surfhf_av(m) +         &
1773                                          surf_usm_v(l)%surfhf(m)
1774                       ENDDO
1775                    ENDIF
1776                   
1777                CASE ( 'usm_wshf' )
1778!--                 array of sensible heat flux from surfaces (land, roof, wall)
1779                    IF ( l == -1 ) THEN
1780                       DO  m = 1, surf_usm_h%ns
1781                          surf_usm_h%wshf_eb_av(m) =                              &
1782                                             surf_usm_h%wshf_eb_av(m) +           &
1783                                             surf_usm_h%wshf_eb(m)
1784                       ENDDO
1785                    ELSE
1786                       DO  m = 1, surf_usm_v(l)%ns
1787                          surf_usm_v(l)%wshf_eb_av(m) =                        &
1788                                          surf_usm_v(l)%wshf_eb_av(m) +        &
1789                                          surf_usm_v(l)%wshf_eb(m)
1790                       ENDDO
1791                    ENDIF
1792                   
1793                CASE ( 'usm_wghf' )
1794!--                 array of heat flux from ground (wall, roof, land)
1795                    IF ( l == -1 ) THEN
1796                       DO  m = 1, surf_usm_h%ns
1797                          surf_usm_h%wghf_eb_av(m) =                              &
1798                                             surf_usm_h%wghf_eb_av(m) +           &
1799                                             surf_usm_h%wghf_eb(m)
1800                       ENDDO
1801                    ELSE
1802                       DO  m = 1, surf_usm_v(l)%ns
1803                          surf_usm_v(l)%wghf_eb_av(m) =                        &
1804                                          surf_usm_v(l)%wghf_eb_av(m) +        &
1805                                          surf_usm_v(l)%wghf_eb(m)
1806                       ENDDO
1807                    ENDIF
1808                   
1809                CASE ( 'usm_wghf_window' )
1810!--                 array of heat flux from window ground (wall, roof, land)
1811                    IF ( l == -1 ) THEN
1812                       DO  m = 1, surf_usm_h%ns
1813                          surf_usm_h%wghf_eb_window_av(m) =                              &
1814                                             surf_usm_h%wghf_eb_window_av(m) +           &
1815                                             surf_usm_h%wghf_eb_window(m)
1816                       ENDDO
1817                    ELSE
1818                       DO  m = 1, surf_usm_v(l)%ns
1819                          surf_usm_v(l)%wghf_eb_window_av(m) =                        &
1820                                          surf_usm_v(l)%wghf_eb_window_av(m) +        &
1821                                          surf_usm_v(l)%wghf_eb_window(m)
1822                       ENDDO
1823                    ENDIF
1824
1825                CASE ( 'usm_wghf_green' )
1826!--                 array of heat flux from green ground (wall, roof, land)
1827                    IF ( l == -1 ) THEN
1828                       DO  m = 1, surf_usm_h%ns
1829                          surf_usm_h%wghf_eb_green_av(m) =                              &
1830                                             surf_usm_h%wghf_eb_green_av(m) +           &
1831                                             surf_usm_h%wghf_eb_green(m)
1832                       ENDDO
1833                    ELSE
1834                       DO  m = 1, surf_usm_v(l)%ns
1835                          surf_usm_v(l)%wghf_eb_green_av(m) =                        &
1836                                          surf_usm_v(l)%wghf_eb_green_av(m) +        &
1837                                          surf_usm_v(l)%wghf_eb_green(m)
1838                       ENDDO
1839                    ENDIF
1840                   
1841                CASE ( 'usm_iwghf' )
1842!--                 array of heat flux from indoor ground (wall, roof, land)
1843                    IF ( l == -1 ) THEN
1844                       DO  m = 1, surf_usm_h%ns
1845                          surf_usm_h%iwghf_eb_av(m) =                              &
1846                                             surf_usm_h%iwghf_eb_av(m) +           &
1847                                             surf_usm_h%iwghf_eb(m)
1848                       ENDDO
1849                    ELSE
1850                       DO  m = 1, surf_usm_v(l)%ns
1851                          surf_usm_v(l)%iwghf_eb_av(m) =                        &
1852                                          surf_usm_v(l)%iwghf_eb_av(m) +        &
1853                                          surf_usm_v(l)%iwghf_eb(m)
1854                       ENDDO
1855                    ENDIF
1856                   
1857                CASE ( 'usm_iwghf_window' )
1858!--                 array of heat flux from indoor window ground (wall, roof, land)
1859                    IF ( l == -1 ) THEN
1860                       DO  m = 1, surf_usm_h%ns
1861                          surf_usm_h%iwghf_eb_window_av(m) =                              &
1862                                             surf_usm_h%iwghf_eb_window_av(m) +           &
1863                                             surf_usm_h%iwghf_eb_window(m)
1864                       ENDDO
1865                    ELSE
1866                       DO  m = 1, surf_usm_v(l)%ns
1867                          surf_usm_v(l)%iwghf_eb_window_av(m) =                        &
1868                                          surf_usm_v(l)%iwghf_eb_window_av(m) +        &
1869                                          surf_usm_v(l)%iwghf_eb_window(m)
1870                       ENDDO
1871                    ENDIF
1872                   
1873                CASE ( 'usm_t_surf' )
1874!--                 surface temperature for surfaces
1875                    IF ( l == -1 ) THEN
1876                       DO  m = 1, surf_usm_h%ns
1877                          surf_usm_h%t_surf_av(m) =                               &
1878                                             surf_usm_h%t_surf_av(m) +            &
1879                                             t_surf_h(m)
1880                       ENDDO
1881                    ELSE
1882                       DO  m = 1, surf_usm_v(l)%ns
1883                          surf_usm_v(l)%t_surf_av(m) =                         &
1884                                          surf_usm_v(l)%t_surf_av(m) +         &
1885                                          t_surf_v(l)%t(m)
1886                       ENDDO
1887                    ENDIF
1888                   
1889                CASE ( 'usm_t_surf_window' )
1890!--                 surface temperature for window surfaces
1891                    IF ( l == -1 ) THEN
1892                       DO  m = 1, surf_usm_h%ns
1893                          surf_usm_h%t_surf_window_av(m) =                               &
1894                                             surf_usm_h%t_surf_window_av(m) +            &
1895                                             t_surf_window_h(m)
1896                       ENDDO
1897                    ELSE
1898                       DO  m = 1, surf_usm_v(l)%ns
1899                          surf_usm_v(l)%t_surf_window_av(m) =                         &
1900                                          surf_usm_v(l)%t_surf_window_av(m) +         &
1901                                          t_surf_window_v(l)%t(m)
1902                       ENDDO
1903                    ENDIF
1904                   
1905                CASE ( 'usm_t_surf_green' )
1906!--                 surface temperature for green surfaces
1907                    IF ( l == -1 ) THEN
1908                       DO  m = 1, surf_usm_h%ns
1909                          surf_usm_h%t_surf_green_av(m) =                               &
1910                                             surf_usm_h%t_surf_green_av(m) +            &
1911                                             t_surf_green_h(m)
1912                       ENDDO
1913                    ELSE
1914                       DO  m = 1, surf_usm_v(l)%ns
1915                          surf_usm_v(l)%t_surf_green_av(m) =                         &
1916                                          surf_usm_v(l)%t_surf_green_av(m) +         &
1917                                          t_surf_green_v(l)%t(m)
1918                       ENDDO
1919                    ENDIF
1920               
1921                CASE ( 'usm_t_surf_10cm' )
1922!--                 near surface temperature for whole surfaces
1923                    IF ( l == -1 ) THEN
1924                       DO  m = 1, surf_usm_h%ns
1925                          surf_usm_h%t_surf_10cm_av(m) =                               &
1926                                             surf_usm_h%t_surf_10cm_av(m) +            &
1927                                             t_surf_10cm_h(m)
1928                       ENDDO
1929                    ELSE
1930                       DO  m = 1, surf_usm_v(l)%ns
1931                          surf_usm_v(l)%t_surf_10cm_av(m) =                         &
1932                                          surf_usm_v(l)%t_surf_10cm_av(m) +         &
1933                                          t_surf_10cm_v(l)%t(m)
1934                       ENDDO
1935                    ENDIF
1936
1937                   
1938                CASE ( 'usm_t_wall' )
1939!--                 wall temperature for  iwl layer of walls and land
1940                    IF ( l == -1 ) THEN
1941                       DO  m = 1, surf_usm_h%ns
1942                          surf_usm_h%t_wall_av(iwl,m) =                           &
1943                                             surf_usm_h%t_wall_av(iwl,m) +        &
1944                                             t_wall_h(iwl,m)
1945                       ENDDO
1946                    ELSE
1947                       DO  m = 1, surf_usm_v(l)%ns
1948                          surf_usm_v(l)%t_wall_av(iwl,m) =                     &
1949                                          surf_usm_v(l)%t_wall_av(iwl,m) +     &
1950                                          t_wall_v(l)%t(iwl,m)
1951                       ENDDO
1952                    ENDIF
1953                   
1954                CASE ( 'usm_t_window' )
1955!--                 window temperature for  iwl layer of walls and land
1956                    IF ( l == -1 ) THEN
1957                       DO  m = 1, surf_usm_h%ns
1958                          surf_usm_h%t_window_av(iwl,m) =                           &
1959                                             surf_usm_h%t_window_av(iwl,m) +        &
1960                                             t_window_h(iwl,m)
1961                       ENDDO
1962                    ELSE
1963                       DO  m = 1, surf_usm_v(l)%ns
1964                          surf_usm_v(l)%t_window_av(iwl,m) =                     &
1965                                          surf_usm_v(l)%t_window_av(iwl,m) +     &
1966                                          t_window_v(l)%t(iwl,m)
1967                       ENDDO
1968                    ENDIF
1969
1970                CASE ( 'usm_t_green' )
1971!--                 green temperature for  iwl layer of walls and land
1972                    IF ( l == -1 ) THEN
1973                       DO  m = 1, surf_usm_h%ns
1974                          surf_usm_h%t_green_av(iwl,m) =                           &
1975                                             surf_usm_h%t_green_av(iwl,m) +        &
1976                                             t_green_h(iwl,m)
1977                       ENDDO
1978                    ELSE
1979                       DO  m = 1, surf_usm_v(l)%ns
1980                          surf_usm_v(l)%t_green_av(iwl,m) =                     &
1981                                          surf_usm_v(l)%t_green_av(iwl,m) +     &
1982                                          t_green_v(l)%t(iwl,m)
1983                       ENDDO
1984                    ENDIF
1985
1986                CASE DEFAULT
1987                    CONTINUE
1988
1989           END SELECT
1990
1991        ELSEIF ( mode == 'average' )  THEN
1992           
1993           SELECT CASE ( TRIM( var ) )
1994               
1995                CASE ( 'usm_rad_net' )
1996!--                 array of complete radiation balance
1997                    IF ( l == -1 ) THEN
1998                       DO  m = 1, surf_usm_h%ns
1999                          surf_usm_h%rad_net_av(m) =                              &
2000                                             surf_usm_h%rad_net_av(m) /           &
2001                                             REAL( average_count_3d, kind=wp )
2002                       ENDDO
2003                    ELSE
2004                       DO  m = 1, surf_usm_v(l)%ns
2005                          surf_usm_v(l)%rad_net_av(m) =                        &
2006                                          surf_usm_v(l)%rad_net_av(m) /        &
2007                                          REAL( average_count_3d, kind=wp )
2008                       ENDDO
2009                    ENDIF
2010                   
2011                CASE ( 'usm_rad_insw' )
2012!--                 array of sw radiation falling to surface after i-th reflection
2013                    DO l = 1, nsurfl
2014                        IF ( surfl(id,l) == idsint )  THEN
2015                            surfinsw_av(l) = surfinsw_av(l) / REAL( average_count_3d, kind=wp )
2016                        ENDIF
2017                    ENDDO
2018                             
2019                CASE ( 'usm_rad_inlw' )
2020!--                 array of lw radiation falling to surface after i-th reflection
2021                    DO l = 1, nsurfl
2022                        IF ( surfl(id,l) == idsint )  THEN
2023                            surfinlw_av(l) = surfinlw_av(l) / REAL( average_count_3d, kind=wp )
2024                        ENDIF
2025                    ENDDO
2026                   
2027                CASE ( 'usm_rad_inswdir' )
2028!--                 array of direct sw radiation falling to surface from sun
2029                    DO l = 1, nsurfl
2030                        IF ( surfl(id,l) == idsint )  THEN
2031                            surfinswdir_av(l) = surfinswdir_av(l) / REAL( average_count_3d, kind=wp )
2032                        ENDIF
2033                    ENDDO
2034                   
2035                CASE ( 'usm_rad_inswdif' )
2036!--                 array of difusion sw radiation falling to surface from sky and borders of the domain
2037                    DO l = 1, nsurfl
2038                        IF ( surfl(id,l) == idsint )  THEN
2039                            surfinswdif_av(l) = surfinswdif_av(l) / REAL( average_count_3d, kind=wp )
2040                        ENDIF
2041                    ENDDO
2042                   
2043                CASE ( 'usm_rad_inswref' )
2044!--                 array of sw radiation falling to surface from reflections
2045                    DO l = 1, nsurfl
2046                        IF ( surfl(id,l) == idsint )  THEN
2047                            surfinswref_av(l) = surfinswref_av(l) / REAL( average_count_3d, kind=wp )
2048                        ENDIF
2049                    ENDDO
2050                   
2051                CASE ( 'usm_rad_inlwdif' )
2052!--                 array of sw radiation falling to surface after i-th reflection
2053                    DO l = 1, nsurfl
2054                        IF ( surfl(id,l) == idsint )  THEN
2055                            surfinlwdif_av(l) = surfinlwdif_av(l) / REAL( average_count_3d, kind=wp )
2056                        ENDIF
2057                    ENDDO
2058                   
2059                CASE ( 'usm_rad_inlwref' )
2060!--                 array of lw radiation falling to surface from reflections
2061                    DO l = 1, nsurfl
2062                        IF ( surfl(id,l) == idsint )  THEN
2063                            surfinlwref_av(l) = surfinlwref_av(l) / REAL( average_count_3d, kind=wp )
2064                        ENDIF
2065                    ENDDO
2066                   
2067                CASE ( 'usm_rad_outsw' )
2068!--                 array of sw radiation emitted from surface after i-th reflection
2069                    DO l = 1, nsurfl
2070                        IF ( surfl(id,l) == idsint )  THEN
2071                            surfoutsw_av(l) = surfoutsw_av(l) / REAL( average_count_3d, kind=wp )
2072                        ENDIF
2073                    ENDDO
2074                   
2075                CASE ( 'usm_rad_outlw' )
2076!--                 array of lw radiation emitted from surface after i-th reflection
2077                    DO l = 1, nsurfl
2078                        IF ( surfl(id,l) == idsint )  THEN
2079                            surfoutlw_av(l) = surfoutlw_av(l) / REAL( average_count_3d, kind=wp )
2080                        ENDIF
2081                    ENDDO
2082                   
2083                CASE ( 'usm_rad_ressw' )
2084!--                 array of residua of sw radiation absorbed in surface after last reflection
2085                    DO l = 1, nsurfl
2086                        IF ( surfl(id,l) == idsint )  THEN
2087                            surfins_av(l) = surfins_av(l) / REAL( average_count_3d, kind=wp )
2088                        ENDIF
2089                    ENDDO
2090                                   
2091                CASE ( 'usm_rad_reslw' )
2092!--                 array of residua of lw radiation absorbed in surface after last reflection
2093                    DO l = 1, nsurfl
2094                        IF ( surfl(id,l) == idsint )  THEN
2095                            surfinl_av(l) = surfinl_av(l) / REAL( average_count_3d, kind=wp )
2096                        ENDIF
2097                    ENDDO
2098                   
2099                CASE ( 'usm_rad_pc_inlw' )
2100                    pcbinlw_av(:) = pcbinlw_av(:) / REAL( average_count_3d, kind=wp )
2101                   
2102                CASE ( 'usm_rad_pc_insw' )
2103                    pcbinsw_av(:) = pcbinsw_av(:) / REAL( average_count_3d, kind=wp )
2104                   
2105                CASE ( 'usm_rad_pc_inswdir' )
2106                    pcbinswdir_av(:) = pcbinswdir_av(:) / REAL( average_count_3d, kind=wp )
2107                   
2108                CASE ( 'usm_rad_pc_inswdif' )
2109                    pcbinswdif_av(:) = pcbinswdif_av(:) / REAL( average_count_3d, kind=wp )
2110                   
2111                CASE ( 'usm_rad_pc_inswref' )
2112                    pcbinswref_av(:) = pcbinswref_av(:) / REAL( average_count_3d, kind=wp )
2113                   
2114                CASE ( 'usm_rad_hf' )
2115!--                 array of heat flux from radiation for surfaces after i-th reflection
2116                    IF ( l == -1 ) THEN
2117                       DO  m = 1, surf_usm_h%ns
2118                          surf_usm_h%surfhf_av(m) =                               &
2119                                             surf_usm_h%surfhf_av(m) /            &
2120                                             REAL( average_count_3d, kind=wp )
2121                       ENDDO
2122                    ELSE
2123                       DO  m = 1, surf_usm_v(l)%ns
2124                          surf_usm_v(l)%surfhf_av(m) =                         &
2125                                          surf_usm_v(l)%surfhf_av(m) /         &
2126                                          REAL( average_count_3d, kind=wp )
2127                       ENDDO
2128                    ENDIF
2129                   
2130                CASE ( 'usm_wshf' )
2131!--                 array of sensible heat flux from surfaces (land, roof, wall)
2132                    IF ( l == -1 ) THEN
2133                       DO  m = 1, surf_usm_h%ns
2134                          surf_usm_h%wshf_eb_av(m) =                              &
2135                                             surf_usm_h%wshf_eb_av(m) /           &
2136                                             REAL( average_count_3d, kind=wp )
2137                       ENDDO
2138                    ELSE
2139                       DO  m = 1, surf_usm_v(l)%ns
2140                          surf_usm_v(l)%wshf_eb_av(m) =                        &
2141                                          surf_usm_v(l)%wshf_eb_av(m) /        &
2142                                          REAL( average_count_3d, kind=wp )
2143                       ENDDO
2144                    ENDIF
2145                   
2146                CASE ( 'usm_wghf' )
2147!--                 array of heat flux from ground (wall, roof, land)
2148                    IF ( l == -1 ) THEN
2149                       DO  m = 1, surf_usm_h%ns
2150                          surf_usm_h%wghf_eb_av(m) =                              &
2151                                             surf_usm_h%wghf_eb_av(m) /           &
2152                                             REAL( average_count_3d, kind=wp )
2153                       ENDDO
2154                    ELSE
2155                       DO  m = 1, surf_usm_v(l)%ns
2156                          surf_usm_v(l)%wghf_eb_av(m) =                        &
2157                                          surf_usm_v(l)%wghf_eb_av(m) /        &
2158                                          REAL( average_count_3d, kind=wp )
2159                       ENDDO
2160                    ENDIF
2161                   
2162                CASE ( 'usm_wghf_window' )
2163!--                 array of heat flux from window ground (wall, roof, land)
2164                    IF ( l == -1 ) THEN
2165                       DO  m = 1, surf_usm_h%ns
2166                          surf_usm_h%wghf_eb_window_av(m) =                              &
2167                                             surf_usm_h%wghf_eb_window_av(m) /           &
2168                                             REAL( average_count_3d, kind=wp )
2169                       ENDDO
2170                    ELSE
2171                       DO  m = 1, surf_usm_v(l)%ns
2172                          surf_usm_v(l)%wghf_eb_window_av(m) =                        &
2173                                          surf_usm_v(l)%wghf_eb_window_av(m) /        &
2174                                          REAL( average_count_3d, kind=wp )
2175                       ENDDO
2176                    ENDIF
2177
2178                CASE ( 'usm_wghf_green' )
2179!--                 array of heat flux from green ground (wall, roof, land)
2180                    IF ( l == -1 ) THEN
2181                       DO  m = 1, surf_usm_h%ns
2182                          surf_usm_h%wghf_eb_green_av(m) =                              &
2183                                             surf_usm_h%wghf_eb_green_av(m) /           &
2184                                             REAL( average_count_3d, kind=wp )
2185                       ENDDO
2186                    ELSE
2187                       DO  m = 1, surf_usm_v(l)%ns
2188                          surf_usm_v(l)%wghf_eb_green_av(m) =                        &
2189                                          surf_usm_v(l)%wghf_eb_green_av(m) /        &
2190                                          REAL( average_count_3d, kind=wp )
2191                       ENDDO
2192                    ENDIF
2193
2194                CASE ( 'usm_iwghf' )
2195!--                 array of heat flux from indoor ground (wall, roof, land)
2196                    IF ( l == -1 ) THEN
2197                       DO  m = 1, surf_usm_h%ns
2198                          surf_usm_h%iwghf_eb_av(m) =                              &
2199                                             surf_usm_h%iwghf_eb_av(m) /           &
2200                                             REAL( average_count_3d, kind=wp )
2201                       ENDDO
2202                    ELSE
2203                       DO  m = 1, surf_usm_v(l)%ns
2204                          surf_usm_v(l)%iwghf_eb_av(m) =                        &
2205                                          surf_usm_v(l)%iwghf_eb_av(m) /        &
2206                                          REAL( average_count_3d, kind=wp )
2207                       ENDDO
2208                    ENDIF
2209                   
2210                CASE ( 'usm_iwghf_window' )
2211!--                 array of heat flux from indoor window ground (wall, roof, land)
2212                    IF ( l == -1 ) THEN
2213                       DO  m = 1, surf_usm_h%ns
2214                          surf_usm_h%iwghf_eb_window_av(m) =                              &
2215                                             surf_usm_h%iwghf_eb_window_av(m) /           &
2216                                             REAL( average_count_3d, kind=wp )
2217                       ENDDO
2218                    ELSE
2219                       DO  m = 1, surf_usm_v(l)%ns
2220                          surf_usm_v(l)%iwghf_eb_window_av(m) =                        &
2221                                          surf_usm_v(l)%iwghf_eb_window_av(m) /        &
2222                                          REAL( average_count_3d, kind=wp )
2223                       ENDDO
2224                    ENDIF
2225                   
2226                CASE ( 'usm_t_surf' )
2227!--                 surface temperature for surfaces
2228                    IF ( l == -1 ) THEN
2229                       DO  m = 1, surf_usm_h%ns
2230                          surf_usm_h%t_surf_av(m) =                               &
2231                                             surf_usm_h%t_surf_av(m) /            &
2232                                             REAL( average_count_3d, kind=wp )
2233                       ENDDO
2234                    ELSE
2235                       DO  m = 1, surf_usm_v(l)%ns
2236                          surf_usm_v(l)%t_surf_av(m) =                         &
2237                                          surf_usm_v(l)%t_surf_av(m) /         &
2238                                          REAL( average_count_3d, kind=wp )
2239                       ENDDO
2240                    ENDIF
2241                   
2242                CASE ( 'usm_t_surf_window' )
2243!--                 surface temperature for window surfaces
2244                    IF ( l == -1 ) THEN
2245                       DO  m = 1, surf_usm_h%ns
2246                          surf_usm_h%t_surf_window_av(m) =                               &
2247                                             surf_usm_h%t_surf_window_av(m) /            &
2248                                             REAL( average_count_3d, kind=wp )
2249                       ENDDO
2250                    ELSE
2251                       DO  m = 1, surf_usm_v(l)%ns
2252                          surf_usm_v(l)%t_surf_window_av(m) =                         &
2253                                          surf_usm_v(l)%t_surf_window_av(m) /         &
2254                                          REAL( average_count_3d, kind=wp )
2255                       ENDDO
2256                    ENDIF
2257                   
2258                CASE ( 'usm_t_surf_green' )
2259!--                 surface temperature for green surfaces
2260                    IF ( l == -1 ) THEN
2261                       DO  m = 1, surf_usm_h%ns
2262                          surf_usm_h%t_surf_green_av(m) =                               &
2263                                             surf_usm_h%t_surf_green_av(m) /            &
2264                                             REAL( average_count_3d, kind=wp )
2265                       ENDDO
2266                    ELSE
2267                       DO  m = 1, surf_usm_v(l)%ns
2268                          surf_usm_v(l)%t_surf_green_av(m) =                         &
2269                                          surf_usm_v(l)%t_surf_green_av(m) /         &
2270                                          REAL( average_count_3d, kind=wp )
2271                       ENDDO
2272                    ENDIF
2273                   
2274                CASE ( 'usm_t_surf_10cm' )
2275!--                 near surface temperature for whole surfaces
2276                    IF ( l == -1 ) THEN
2277                       DO  m = 1, surf_usm_h%ns
2278                          surf_usm_h%t_surf_10cm_av(m) =                               &
2279                                             surf_usm_h%t_surf_10cm_av(m) /            &
2280                                             REAL( average_count_3d, kind=wp )
2281                       ENDDO
2282                    ELSE
2283                       DO  m = 1, surf_usm_v(l)%ns
2284                          surf_usm_v(l)%t_surf_10cm_av(m) =                         &
2285                                          surf_usm_v(l)%t_surf_10cm_av(m) /         &
2286                                          REAL( average_count_3d, kind=wp )
2287                       ENDDO
2288                    ENDIF
2289                   
2290                CASE ( 'usm_t_wall' )
2291!--                 wall temperature for  iwl layer of walls and land
2292                    IF ( l == -1 ) THEN
2293                       DO  m = 1, surf_usm_h%ns
2294                          surf_usm_h%t_wall_av(iwl,m) =                           &
2295                                             surf_usm_h%t_wall_av(iwl,m) /        &
2296                                             REAL( average_count_3d, kind=wp )
2297                       ENDDO
2298                    ELSE
2299                       DO  m = 1, surf_usm_v(l)%ns
2300                          surf_usm_v(l)%t_wall_av(iwl,m) =                     &
2301                                          surf_usm_v(l)%t_wall_av(iwl,m) /     &
2302                                          REAL( average_count_3d, kind=wp )
2303                       ENDDO
2304                    ENDIF
2305
2306                CASE ( 'usm_t_window' )
2307!--                 window temperature for  iwl layer of walls and land
2308                    IF ( l == -1 ) THEN
2309                       DO  m = 1, surf_usm_h%ns
2310                          surf_usm_h%t_window_av(iwl,m) =                           &
2311                                             surf_usm_h%t_window_av(iwl,m) /        &
2312                                             REAL( average_count_3d, kind=wp )
2313                       ENDDO
2314                    ELSE
2315                       DO  m = 1, surf_usm_v(l)%ns
2316                          surf_usm_v(l)%t_window_av(iwl,m) =                     &
2317                                          surf_usm_v(l)%t_window_av(iwl,m) /     &
2318                                          REAL( average_count_3d, kind=wp )
2319                       ENDDO
2320                    ENDIF
2321
2322                CASE ( 'usm_t_green' )
2323!--                 green temperature for  iwl layer of walls and land
2324                    IF ( l == -1 ) THEN
2325                       DO  m = 1, surf_usm_h%ns
2326                          surf_usm_h%t_green_av(iwl,m) =                           &
2327                                             surf_usm_h%t_green_av(iwl,m) /        &
2328                                             REAL( average_count_3d, kind=wp )
2329                       ENDDO
2330                    ELSE
2331                       DO  m = 1, surf_usm_v(l)%ns
2332                          surf_usm_v(l)%t_green_av(iwl,m) =                     &
2333                                          surf_usm_v(l)%t_green_av(iwl,m) /     &
2334                                          REAL( average_count_3d, kind=wp )
2335                       ENDDO
2336                    ENDIF
2337
2338
2339           END SELECT
2340
2341        ENDIF
2342
2343    END SUBROUTINE usm_average_3d_data
2344
2345
2346
2347!------------------------------------------------------------------------------!
2348! Description:
2349! ------------
2350!> Set internal Neumann boundary condition at outer soil grid points
2351!> for temperature and humidity.
2352!------------------------------------------------------------------------------!
2353 SUBROUTINE usm_boundary_condition
2354 
2355    IMPLICIT NONE
2356
2357    INTEGER(iwp) :: i      !< grid index x-direction
2358    INTEGER(iwp) :: ioff   !< offset index x-direction indicating location of soil grid point
2359    INTEGER(iwp) :: j      !< grid index y-direction
2360    INTEGER(iwp) :: joff   !< offset index x-direction indicating location of soil grid point
2361    INTEGER(iwp) :: k      !< grid index z-direction
2362    INTEGER(iwp) :: koff   !< offset index x-direction indicating location of soil grid point
2363    INTEGER(iwp) :: l      !< running index surface-orientation
2364    INTEGER(iwp) :: m      !< running index surface elements
2365
2366    koff = surf_usm_h%koff
2367    DO  m = 1, surf_usm_h%ns
2368       i = surf_usm_h%i(m)
2369       j = surf_usm_h%j(m)
2370       k = surf_usm_h%k(m)
2371       pt(k+koff,j,i) = pt(k,j,i)
2372    ENDDO
2373
2374    DO  l = 0, 3
2375       ioff = surf_usm_v(l)%ioff
2376       joff = surf_usm_v(l)%joff
2377       DO  m = 1, surf_usm_v(l)%ns
2378          i = surf_usm_v(l)%i(m)
2379          j = surf_usm_v(l)%j(m)
2380          k = surf_usm_v(l)%k(m)
2381          pt(k,j+joff,i+ioff) = pt(k,j,i)
2382       ENDDO
2383    ENDDO
2384
2385 END SUBROUTINE usm_boundary_condition
2386
2387
2388!------------------------------------------------------------------------------!
2389!
2390! Description:
2391! ------------
2392!> Subroutine checks variables and assigns units.
2393!> It is called out from subroutine check_parameters.
2394!------------------------------------------------------------------------------!
2395    SUBROUTINE usm_check_data_output( variable, unit )
2396       
2397        IMPLICIT NONE
2398 
2399        CHARACTER (len=*),INTENT(IN)    ::  variable !:
2400        CHARACTER (len=*),INTENT(OUT)   ::  unit     !:
2401       
2402        CHARACTER (len=varnamelength)   :: var
2403
2404        var = TRIM(variable)
2405        IF ( var(1:12) == 'usm_rad_net_'  .OR.  var(1:13) == 'usm_rad_insw_'  .OR.        &
2406             var(1:13) == 'usm_rad_inlw_'  .OR.  var(1:16) == 'usm_rad_inswdir_'  .OR.    &
2407             var(1:16) == 'usm_rad_inswdif_'  .OR.  var(1:16) == 'usm_rad_inswref_'  .OR. &
2408             var(1:16) == 'usm_rad_inlwdif_'  .OR.  var(1:16) == 'usm_rad_inlwref_'  .OR. &
2409             var(1:14) == 'usm_rad_outsw_'  .OR.  var(1:14) == 'usm_rad_outlw_'  .OR.     &
2410             var(1:14) == 'usm_rad_ressw_'  .OR.  var(1:14) == 'usm_rad_reslw_'  .OR.     &
2411             var(1:11) == 'usm_rad_hf_'  .OR.                                             &
2412             var(1:9)  == 'usm_wshf_'  .OR.  var(1:9) == 'usm_wghf_' .OR.                 &
2413             var(1:16) == 'usm_wghf_window_' .OR. var(1:15) == 'usm_wghf_green_' .OR.     &
2414             var(1:10) == 'usm_iwghf_' .OR. var(1:17) == 'usm_iwghf_window_' .OR.         &
2415             var(1:17) == 'usm_surfwintrans_' )  THEN
2416            unit = 'W/m2'
2417        ELSE IF ( var(1:10) == 'usm_t_surf'   .OR.  var(1:10) == 'usm_t_wall' .OR.        &
2418                  var(1:12) == 'usm_t_window' .OR. var(1:17) == 'usm_t_surf_window' .OR.  &
2419                  var(1:16) == 'usm_t_surf_green'  .OR.                                   &
2420                  var(1:11) == 'usm_t_green' .OR.                                         &
2421                  var(1:15) == 'usm_t_surf_10cm' )  THEN
2422            unit = 'K'
2423        ELSE IF ( var == 'usm_rad_pc_inlw'  .OR.  var == 'usm_rad_pc_insw'  .OR.          &
2424                  var == 'usm_rad_pc_inswdir'  .OR.  var == 'usm_rad_pc_inswdif'  .OR.    &
2425                  var == 'usm_rad_pc_inswref' )  THEN
2426            unit = 'W'
2427        ELSE IF ( var(1:9) == 'usm_surfz'  .OR.  var(1:7) == 'usm_svf'  .OR.              & 
2428                  var(1:7) == 'usm_dif'  .OR.  var(1:11) == 'usm_surfcat'  .OR.           &
2429                  var(1:11) == 'usm_surfalb'  .OR.  var(1:12) == 'usm_surfemis'  .OR.     &
2430                  var(1:9) == 'usm_skyvf' .OR. var(1:9) == 'usm_skyvft' )  THEN
2431            unit = '1'
2432        ELSE
2433            unit = 'illegal'
2434        ENDIF
2435
2436    END SUBROUTINE usm_check_data_output
2437
2438
2439!------------------------------------------------------------------------------!
2440! Description:
2441! ------------
2442!> Check parameters routine for urban surface model
2443!------------------------------------------------------------------------------!
2444    SUBROUTINE usm_check_parameters
2445   
2446       USE control_parameters,                                                 &
2447           ONLY:  bc_pt_b, bc_q_b, constant_flux_layer, large_scale_forcing,   &
2448                  lsf_surf, topography
2449
2450!
2451!--    Dirichlet boundary conditions are required as the surface fluxes are
2452!--    calculated from the temperature/humidity gradients in the urban surface
2453!--    model
2454       IF ( bc_pt_b == 'neumann'   .OR.   bc_q_b == 'neumann' )  THEN
2455          message_string = 'urban surface model requires setting of '//        &
2456                           'bc_pt_b = "dirichlet" and '//                      &
2457                           'bc_q_b  = "dirichlet"'
2458          CALL message( 'usm_check_parameters', 'PA0590', 1, 2, 0, 6, 0 )
2459       ENDIF
2460
2461       IF ( .NOT.  constant_flux_layer )  THEN
2462          message_string = 'urban surface model requires '//                   &
2463                           'constant_flux_layer = .T.'
2464          CALL message( 'usm_check_parameters', 'PA0084', 1, 2, 0, 6, 0 )
2465       ENDIF
2466
2467       IF (  .NOT.  radiation )  THEN
2468          message_string = 'urban surface model requires '//                   &
2469                           'the radiation model to be switched on'
2470          CALL message( 'usm_check_parameters', 'PA0084', 1, 2, 0, 6, 0 )
2471       ENDIF
2472!       
2473!--    Surface forcing has to be disabled for LSF in case of enabled
2474!--    urban surface module
2475       IF ( large_scale_forcing )  THEN
2476          lsf_surf = .FALSE.
2477       ENDIF
2478!
2479!--    Topography
2480       IF ( topography == 'flat' )  THEN
2481          message_string = 'topography /= "flat" is required '//               &
2482                           'when using the urban surface model'
2483          CALL message( 'check_parameters', 'PA0592', 1, 2, 0, 6, 0 )
2484       ENDIF
2485!
2486!--    naheatlayers
2487       IF ( naheatlayers > nzt )  THEN
2488          message_string = 'number of anthropogenic heat layers '//            &
2489                           '"naheatlayers" can not be larger than'//           &
2490                           ' number of domain layers "nzt"'
2491          CALL message( 'check_parameters', 'PA0593', 1, 2, 0, 6, 0 )
2492       ENDIF
2493
2494    END SUBROUTINE usm_check_parameters
2495
2496
2497!------------------------------------------------------------------------------!
2498!
2499! Description:
2500! ------------
2501!> Output of the 3D-arrays in netCDF and/or AVS format
2502!> for variables of urban_surface model.
2503!> It resorts the urban surface module output quantities from surf style
2504!> indexing into temporary 3D array with indices (i,j,k).
2505!> It is called from subroutine data_output_3d.
2506!------------------------------------------------------------------------------!
2507    SUBROUTINE usm_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
2508       
2509        IMPLICIT NONE
2510
2511        INTEGER(iwp), INTENT(IN)       ::  av        !<
2512        CHARACTER (len=*), INTENT(IN)  ::  variable  !<
2513        INTEGER(iwp), INTENT(IN)       ::  nzb_do    !< lower limit of the data output (usually 0)
2514        INTEGER(iwp), INTENT(IN)       ::  nzt_do    !< vertical upper limit of the data output (usually nz_do3d)
2515        LOGICAL, INTENT(OUT)           ::  found     !<
2516        REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf   !< sp - it has to correspond to module data_output_3d
2517        REAL(wp), DIMENSION(nzb:nzt+1,nys:nyn,nxl:nxr)     ::  temp_pf    !< temp array for urban surface output procedure
2518       
2519        CHARACTER (len=varnamelength)                          :: var, surfid
2520        INTEGER(iwp), PARAMETER                                :: nd = 5
2521        CHARACTER(len=6), DIMENSION(0:nd-1), PARAMETER         :: dirname = (/ '_roof ', '_south', '_north', '_west ', '_east ' /)
2522        INTEGER(iwp), DIMENSION(0:nd-1), PARAMETER             :: dirint =  (/    iup_u, isouth_u, inorth_u,  iwest_u,  ieast_u /)
2523        INTEGER(iwp), DIMENSION(0:nd-1), PARAMETER             :: diridx =  (/       -1,        1,        0,        3,        2 /)
2524                                                                     !< index for surf_*_v: 0:3 = (North, South, East, West)
2525        INTEGER(iwp), DIMENSION(0:nd-1)                        :: dirstart
2526        INTEGER(iwp), DIMENSION(0:nd-1)                        :: dirend
2527        INTEGER(iwp)                                           :: ids,idsint,idsidx,isurf,isvf,isurfs,isurflt,ipcgb
2528        INTEGER(iwp)                                           :: is,js,ks,i,j,k,iwl,istat, l, m
2529
2530        dirstart = (/ startland, startwall, startwall, startwall, startwall /)
2531        dirend = (/ endland, endwall, endwall, endwall, endwall /)
2532
2533        found = .TRUE.
2534        temp_pf = -1._wp
2535       
2536        ids = -1
2537        var = TRIM(variable)
2538        DO i = 0, nd-1
2539            k = len(TRIM(var))
2540            j = len(TRIM(dirname(i)))
2541            IF ( TRIM(var(k-j+1:k)) == TRIM(dirname(i)) )  THEN
2542                ids = i
2543                idsint = dirint(ids)
2544                idsidx = diridx(ids)
2545                var = var(:k-j)
2546                EXIT
2547            ENDIF
2548        ENDDO
2549        IF ( ids == -1 )  THEN
2550            var = TRIM(variable)
2551        ENDIF
2552        IF ( var(1:11) == 'usm_t_wall_'  .AND.  len(TRIM(var)) >= 12 )  THEN
2553!--         wall layers
2554            READ(var(12:12), '(I1)', iostat=istat ) iwl
2555            IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
2556                var = var(1:10)
2557            ENDIF
2558        ENDIF
2559        IF ( var(1:13) == 'usm_t_window_'  .AND.  len(TRIM(var)) >= 14 )  THEN
2560!--         window layers
2561            READ(var(14:14), '(I1)', iostat=istat ) iwl
2562            IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
2563                var = var(1:12)
2564            ENDIF
2565        ENDIF
2566        IF ( var(1:12) == 'usm_t_green_'  .AND.  len(TRIM(var)) >= 13 )  THEN
2567!--         green layers
2568            READ(var(13:13), '(I1)', iostat=istat ) iwl
2569            IF ( istat == 0  .AND.  iwl >= nzb_wall  .AND.  iwl <= nzt_wall )  THEN
2570                var = var(1:11)
2571            ENDIF
2572        ENDIF
2573        IF ( (var(1:8) == 'usm_svf_'  .OR.  var(1:8) == 'usm_dif_')  .AND.  len(TRIM(var)) >= 13 )  THEN
2574!--         svf values to particular surface
2575            surfid = var(9:)
2576            i = index(surfid,'_')
2577            j = index(surfid(i+1:),'_')
2578            READ(surfid(1:i-1),*, iostat=istat ) is
2579            IF ( istat == 0 )  THEN
2580                READ(surfid(i+1:i+j-1),*, iostat=istat ) js
2581            ENDIF
2582            IF ( istat == 0 )  THEN
2583                READ(surfid(i+j+1:),*, iostat=istat ) ks
2584            ENDIF
2585            IF ( istat == 0 )  THEN
2586                var = var(1:7)
2587            ENDIF
2588        ENDIF
2589       
2590        SELECT CASE ( TRIM(var) )
2591
2592          CASE ( 'usm_surfz' )
2593!--           array of lw radiation falling to local surface after i-th reflection
2594              IF ( idsint == iup_u )  THEN
2595                 DO  m = 1, surf_usm_h%ns
2596                    i = surf_usm_h%i(m)
2597                    j = surf_usm_h%j(m)
2598                    k = surf_usm_h%k(m)
2599                    temp_pf(0,j,i) = MAX( temp_pf(0,j,i), REAL( k, kind=wp) )
2600                 ENDDO
2601              ELSE
2602                 l = idsidx
2603                 DO  m = 1, surf_usm_v(l)%ns
2604                    i = surf_usm_v(l)%i(m)
2605                    j = surf_usm_v(l)%j(m)
2606                    k = surf_usm_v(l)%k(m)
2607                    temp_pf(0,j,i) = MAX( temp_pf(0,j,i), REAL( k, kind=wp) + 1.0_wp )
2608                 ENDDO
2609              ENDIF
2610
2611          CASE ( 'usm_surfcat' )
2612!--           surface category
2613              IF ( idsint == iup_u )  THEN
2614                 DO  m = 1, surf_usm_h%ns
2615                    i = surf_usm_h%i(m)
2616                    j = surf_usm_h%j(m)
2617                    k = surf_usm_h%k(m)
2618                    temp_pf(k,j,i) = surf_usm_h%surface_types(m)
2619                 ENDDO
2620              ELSE
2621                 l = idsidx
2622                 DO  m = 1, surf_usm_v(l)%ns
2623                    i = surf_usm_v(l)%i(m)
2624                    j = surf_usm_v(l)%j(m)
2625                    k = surf_usm_v(l)%k(m)
2626                    temp_pf(k,j,i) = surf_usm_v(l)%surface_types(m)
2627                 ENDDO
2628              ENDIF
2629             
2630          CASE ( 'usm_surfalb' )
2631!--           surface albedo, weighted average
2632              IF ( idsint == iup_u )  THEN
2633                 DO  m = 1, surf_usm_h%ns
2634                    i = surf_usm_h%i(m)
2635                    j = surf_usm_h%j(m)
2636                    k = surf_usm_h%k(m)
2637                    temp_pf(k,j,i) = surf_usm_h%frac(ind_veg_wall,m)     *     &
2638                                     surf_usm_h%albedo(ind_veg_wall,m)  +      &
2639                                     surf_usm_h%frac(ind_pav_green,m)    *     &
2640                                     surf_usm_h%albedo(ind_pav_green,m) +      &
2641                                     surf_usm_h%frac(ind_wat_win,m)      *     &
2642                                     surf_usm_h%albedo(ind_wat_win,m)
2643                 ENDDO
2644              ELSE
2645                 l = idsidx
2646                 DO  m = 1, surf_usm_v(l)%ns
2647                    i = surf_usm_v(l)%i(m)
2648                    j = surf_usm_v(l)%j(m)
2649                    k = surf_usm_v(l)%k(m)
2650                    temp_pf(k,j,i) = surf_usm_v(l)%frac(ind_veg_wall,m)     *  &
2651                                     surf_usm_v(l)%albedo(ind_veg_wall,m)  +   &
2652                                     surf_usm_v(l)%frac(ind_pav_green,m)    *  &
2653                                     surf_usm_v(l)%albedo(ind_pav_green,m) +   &
2654                                     surf_usm_v(l)%frac(ind_wat_win,m)      *  &
2655                                     surf_usm_v(l)%albedo(ind_wat_win,m)
2656                 ENDDO
2657              ENDIF
2658             
2659          CASE ( 'usm_surfemis' )
2660!--           surface emissivity, weighted average
2661              IF ( idsint == iup_u )  THEN
2662                 DO  m = 1, surf_usm_h%ns
2663                    i = surf_usm_h%i(m)
2664                    j = surf_usm_h%j(m)
2665                    k = surf_usm_h%k(m)
2666                    temp_pf(k,j,i) =  surf_usm_h%frac(ind_veg_wall,m)      *   &
2667                                      surf_usm_h%emissivity(ind_veg_wall,m)  + &
2668                                      surf_usm_h%frac(ind_pav_green,m)     *   &
2669                                      surf_usm_h%emissivity(ind_pav_green,m) + &
2670                                      surf_usm_h%frac(ind_wat_win,m)       *   &
2671                                      surf_usm_h%emissivity(ind_wat_win,m)
2672                 ENDDO
2673              ELSE
2674                 l = idsidx
2675                 DO  m = 1, surf_usm_v(l)%ns
2676                    i = surf_usm_v(l)%i(m)
2677                    j = surf_usm_v(l)%j(m)
2678                    k = surf_usm_v(l)%k(m)
2679                    temp_pf(k,j,i) = surf_usm_v(l)%frac(ind_veg_wall,m)       *&
2680                                     surf_usm_v(l)%emissivity(ind_veg_wall,m) +&
2681                                     surf_usm_v(l)%frac(ind_pav_green,m)      *&
2682                                     surf_usm_v(l)%emissivity(ind_pav_green,m)+&
2683                                     surf_usm_v(l)%frac(ind_wat_win,m)        *&
2684                                     surf_usm_v(l)%emissivity(ind_wat_win,m)
2685                 ENDDO
2686              ENDIF
2687
2688          CASE ( 'usm_surfwintrans' )
2689!--           transmissivity window tiles
2690              IF ( idsint == iup_u )  THEN
2691                 DO  m = 1, surf_usm_h%ns
2692                    i = surf_usm_h%i(m)
2693                    j = surf_usm_h%j(m)
2694                    k = surf_usm_h%k(m)
2695                    temp_pf(k,j,i) = surf_usm_h%transmissivity(m)
2696                 ENDDO
2697              ELSE
2698                 l = idsidx
2699                 DO  m = 1, surf_usm_v(l)%ns
2700                    i = surf_usm_v(l)%i(m)
2701                    j = surf_usm_v(l)%j(m)
2702                    k = surf_usm_v(l)%k(m)
2703                    temp_pf(k,j,i) = surf_usm_v(l)%transmissivity(m)
2704                 ENDDO
2705              ENDIF
2706
2707          CASE ( 'usm_skyvf' )
2708!--           sky view factor
2709              DO isurf = dirstart(ids), dirend(ids)
2710                 IF ( surfl(id,isurf) == idsint )  THEN
2711                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = skyvf(isurf)
2712                 ENDIF
2713              ENDDO
2714             
2715          CASE ( 'usm_skyvft' )
2716!--           sky view factor
2717              DO isurf = dirstart(ids), dirend(ids)
2718                 IF ( surfl(id,isurf) == ids )  THEN
2719                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = skyvft(isurf)
2720                 ENDIF
2721              ENDDO
2722
2723!
2724!-- Not adjusted so far             
2725          CASE ( 'usm_svf', 'usm_dif' )
2726!--           shape view factors or iradiance factors to selected surface
2727              IF ( TRIM(var)=='usm_svf' )  THEN
2728                  k = 1
2729              ELSE
2730                  k = 2
2731              ENDIF
2732              DO isvf = 1, nsvfl
2733                  isurflt = svfsurf(1, isvf)
2734                  isurfs = svfsurf(2, isvf)
2735                             
2736                  IF ( surf(ix,isurfs) == is  .AND.  surf(iy,isurfs) == js  .AND.       &
2737                       surf(iz,isurfs) == ks  .AND.  surf(id,isurfs) == idsint )  THEN
2738  !--                 correct source surface
2739                      temp_pf(surfl(iz,isurflt),surfl(iy,isurflt),surfl(ix,isurflt)) = svf(k,isvf)
2740                  ENDIF
2741              ENDDO
2742
2743          CASE ( 'usm_rad_net' )
2744!--           array of complete radiation balance
2745              IF ( av == 0 )  THEN
2746                 IF ( idsint == iup_u )  THEN
2747                    DO  m = 1, surf_usm_h%ns
2748                       i = surf_usm_h%i(m)
2749                       j = surf_usm_h%j(m)
2750                       k = surf_usm_h%k(m)
2751                       temp_pf(k,j,i) = surf_usm_h%rad_net_l(m)
2752                    ENDDO
2753                 ELSE
2754                    l = idsidx
2755                    DO  m = 1, surf_usm_v(l)%ns
2756                       i = surf_usm_v(l)%i(m)
2757                       j = surf_usm_v(l)%j(m)
2758                       k = surf_usm_v(l)%k(m)
2759                       temp_pf(k,j,i) = surf_usm_v(l)%rad_net_l(m)
2760                    ENDDO
2761                 ENDIF
2762              ELSE
2763                 IF ( idsint == iup_u )  THEN
2764                    DO  m = 1, surf_usm_h%ns
2765                       i = surf_usm_h%i(m)
2766                       j = surf_usm_h%j(m)
2767                       k = surf_usm_h%k(m)
2768                       temp_pf(k,j,i) = surf_usm_h%rad_net_av(m)
2769                    ENDDO
2770                 ELSE
2771                    l = idsidx
2772                    DO  m = 1, surf_usm_v(l)%ns
2773                       i = surf_usm_v(l)%i(m)
2774                       j = surf_usm_v(l)%j(m)
2775                       k = surf_usm_v(l)%k(m)
2776                       temp_pf(k,j,i) = surf_usm_v(l)%rad_net_av(m)
2777                    ENDDO
2778                 ENDIF
2779              ENDIF
2780
2781          CASE ( 'usm_rad_insw' )
2782!--           array of sw radiation falling to surface after i-th reflection
2783              DO isurf = dirstart(ids), dirend(ids)
2784                 IF ( surfl(id,isurf) == idsint )  THEN
2785                   IF ( av == 0 )  THEN
2786                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinsw(isurf)
2787                   ELSE
2788                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinsw_av(isurf)
2789                   ENDIF
2790                 ENDIF
2791              ENDDO
2792
2793          CASE ( 'usm_rad_inlw' )
2794!--           array of lw radiation falling to surface after i-th reflection
2795              DO isurf = dirstart(ids), dirend(ids)
2796                 IF ( surfl(id,isurf) == idsint )  THEN
2797                   IF ( av == 0 )  THEN
2798                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinlw(isurf)
2799                   ELSE
2800                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinlw_av(isurf)
2801                   ENDIF
2802                 ENDIF
2803              ENDDO
2804
2805          CASE ( 'usm_rad_inswdir' )
2806!--           array of direct sw radiation falling to surface from sun
2807              DO isurf = dirstart(ids), dirend(ids)
2808                 IF ( surfl(id,isurf) == idsint )  THEN
2809                   IF ( av == 0 )  THEN
2810                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinswdir(isurf)
2811                   ELSE
2812                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinswdir_av(isurf)
2813                   ENDIF
2814                 ENDIF
2815              ENDDO
2816
2817          CASE ( 'usm_rad_inswdif' )
2818!--           array of difusion sw radiation falling to surface from sky and borders of the domain
2819              DO isurf = dirstart(ids), dirend(ids)
2820                 IF ( surfl(id,isurf) == idsint )  THEN
2821                   IF ( av == 0 )  THEN
2822                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinswdif(isurf)
2823                   ELSE
2824                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinswdif_av(isurf)
2825                   ENDIF
2826                 ENDIF
2827              ENDDO
2828
2829          CASE ( 'usm_rad_inswref' )
2830!--           array of sw radiation falling to surface from reflections
2831              DO isurf = dirstart(ids), dirend(ids)
2832                 IF ( surfl(id,isurf) == idsint )  THEN
2833                   IF ( av == 0 )  THEN
2834                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = &
2835                       surfinsw(isurf) - surfinswdir(isurf) - surfinswdif(isurf)
2836                   ELSE
2837                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinswref_av(isurf)
2838                   ENDIF
2839                 ENDIF
2840              ENDDO
2841
2842          CASE ( 'usm_rad_inlwdif' )
2843!--           array of difusion lw radiation falling to surface from sky and borders of the domain
2844              DO isurf = dirstart(ids), dirend(ids)
2845                 IF ( surfl(id,isurf) == idsint )  THEN
2846                   IF ( av == 0 )  THEN
2847                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinlwdif(isurf)
2848                   ELSE
2849                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinlwdif_av(isurf)
2850                   ENDIF
2851                 ENDIF
2852              ENDDO
2853
2854          CASE ( 'usm_rad_inlwref' )
2855!--           array of lw radiation falling to surface from reflections
2856              DO isurf = dirstart(ids), dirend(ids)
2857                 IF ( surfl(id,isurf) == idsint )  THEN
2858                   IF ( av == 0 )  THEN
2859                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinlw(isurf) - surfinlwdif(isurf)
2860                   ELSE
2861                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinlwref_av(isurf)
2862                   ENDIF
2863                 ENDIF
2864              ENDDO
2865
2866          CASE ( 'usm_rad_outsw' )
2867!--           array of sw radiation emitted from surface after i-th reflection
2868              DO isurf = dirstart(ids), dirend(ids)
2869                 IF ( surfl(id,isurf) == idsint )  THEN
2870                   IF ( av == 0 )  THEN
2871                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfoutsw(isurf)
2872                   ELSE
2873                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfoutsw_av(isurf)
2874                   ENDIF
2875                 ENDIF
2876              ENDDO
2877
2878          CASE ( 'usm_rad_outlw' )
2879!--           array of lw radiation emitted from surface after i-th reflection
2880              DO isurf = dirstart(ids), dirend(ids)
2881                 IF ( surfl(id,isurf) == idsint )  THEN
2882                   IF ( av == 0 )  THEN
2883                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfoutlw(isurf)
2884                   ELSE
2885                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfoutlw_av(isurf)
2886                   ENDIF
2887                 ENDIF
2888              ENDDO
2889
2890          CASE ( 'usm_rad_ressw' )
2891!--           average of array of residua of sw radiation absorbed in surface after last reflection
2892              DO isurf = dirstart(ids), dirend(ids)
2893                 IF ( surfl(id,isurf) == idsint )  THEN
2894                   IF ( av == 0 )  THEN
2895                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfins(isurf)
2896                   ELSE
2897                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfins_av(isurf)
2898                   ENDIF
2899                 ENDIF
2900              ENDDO
2901
2902          CASE ( 'usm_rad_reslw' )
2903!--           average of array of residua of lw radiation absorbed in surface after last reflection
2904              DO isurf = dirstart(ids), dirend(ids)
2905                 IF ( surfl(id,isurf) == idsint )  THEN
2906                   IF ( av == 0 )  THEN
2907                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinl(isurf)
2908                   ELSE
2909                     temp_pf(surfl(iz,isurf),surfl(iy,isurf),surfl(ix,isurf)) = surfinl_av(isurf)
2910                   ENDIF
2911                 ENDIF
2912              ENDDO
2913
2914          CASE ( 'usm_rad_pc_inlw' )
2915!--           array of lw radiation absorbed by plant canopy
2916              DO ipcgb = 1, npcbl
2917                  IF ( av == 0 )  THEN
2918                      temp_pf(pcbl(iz,ipcgb),pcbl(iy,ipcgb),pcbl(ix,ipcgb)) = pcbinlw(ipcgb)
2919                  ELSE
2920                      temp_pf(pcbl(iz,ipcgb),pcbl(iy,ipcgb),pcbl(ix,ipcgb)) = pcbinlw_av(ipcgb)
2921                  ENDIF
2922              ENDDO
2923
2924          CASE ( 'usm_rad_pc_insw' )
2925!--           array of sw radiation absorbed by plant canopy
2926              DO ipcgb = 1, npcbl
2927                  IF ( av == 0 )  THEN
2928                      temp_pf(pcbl(iz,ipcgb),pcbl(iy,ipcgb),pcbl(ix,ipcgb)) = pcbinsw(ipcgb)
2929                  ELSE
2930                      temp_pf(pcbl(iz,ipcgb),pcbl(iy,ipcgb),pcbl(ix,ipcgb)) = pcbinsw_av(ipcgb)
2931                  ENDIF
2932              ENDDO
2933
2934          CASE ( 'usm_rad_pc_inswdir' )
2935!--           array of direct sw radiation absorbed by plant canopy
2936              DO ipcgb = 1, npcbl
2937                  IF ( av == 0 )  THEN
2938                      temp_pf(pcbl(iz,ipcgb),pcbl(iy,ipcgb),pcbl(ix,ipcgb)) = pcbinswdir(ipcgb)
2939                  ELSE
2940                      temp_pf(pcbl(iz,ipcgb),pcbl(iy,ipcgb),pcbl(ix,ipcgb)) = pcbinswdir_av(ipcgb)
2941                  ENDIF
2942              ENDDO
2943
2944          CASE ( 'usm_rad_pc_inswdif' )
2945!--           array of diffuse sw radiation absorbed by plant canopy
2946              DO ipcgb = 1, npcbl
2947                  IF ( av == 0 )  THEN
2948                      temp_pf(pcbl(iz,ipcgb),pcbl(iy,ipcgb),pcbl(ix,ipcgb)) = pcbinswdif(ipcgb)
2949                  ELSE
2950                      temp_pf(pcbl(iz,ipcgb),pcbl(iy,ipcgb),pcbl(ix,ipcgb)) = pcbinswdif_av(ipcgb)
2951                  ENDIF
2952              ENDDO
2953
2954          CASE ( 'usm_rad_pc_inswref' )
2955!--           array of reflected sw radiation absorbed by plant canopy
2956              DO ipcgb = 1, npcbl
2957                  IF ( av == 0 )  THEN
2958                      temp_pf(pcbl(iz,ipcgb),pcbl(iy,ipcgb),pcbl(ix,ipcgb)) = pcbinsw(ipcgb)      &
2959                                                                              - pcbinswdir(ipcgb) &
2960                                                                              - pcbinswdif(ipcgb)
2961                  ELSE
2962                      temp_pf(pcbl(iz,ipcgb),pcbl(iy,ipcgb),pcbl(ix,ipcgb)) = pcbinswref_av(ipcgb)
2963                  ENDIF
2964              ENDDO
2965 
2966          CASE ( 'usm_rad_hf' )
2967!--           array of heat flux from radiation for surfaces after all reflections
2968              IF ( av == 0 )  THEN
2969                 IF ( idsint == iup_u )  THEN
2970                    DO  m = 1, surf_usm_h%ns
2971                       i = surf_usm_h%i(m)
2972                       j = surf_usm_h%j(m)
2973                       k = surf_usm_h%k(m)
2974                       temp_pf(k,j,i) = surf_usm_h%surfhf(m)
2975                    ENDDO
2976                 ELSE
2977                    l = idsidx
2978                    DO  m = 1, surf_usm_v(l)%ns
2979                       i = surf_usm_v(l)%i(m)
2980                       j = surf_usm_v(l)%j(m)
2981                       k = surf_usm_v(l)%k(m)
2982                       temp_pf(k,j,i) = surf_usm_v(l)%surfhf(m)
2983                    ENDDO
2984                 ENDIF
2985              ELSE
2986                 IF ( idsint == iup_u )  THEN
2987                    DO  m = 1, surf_usm_h%ns
2988                       i = surf_usm_h%i(m)
2989                       j = surf_usm_h%j(m)
2990                       k = surf_usm_h%k(m)
2991                       temp_pf(k,j,i) = surf_usm_h%surfhf_av(m)
2992                    ENDDO
2993                 ELSE
2994                    l = idsidx
2995                    DO  m = 1, surf_usm_v(l)%ns
2996                       i = surf_usm_v(l)%i(m)
2997                       j = surf_usm_v(l)%j(m)
2998                       k = surf_usm_v(l)%k(m)
2999                       temp_pf(k,j,i) = surf_usm_v(l)%surfhf_av(m)
3000                    ENDDO
3001                 ENDIF
3002              ENDIF
3003 
3004          CASE ( 'usm_wshf' )
3005!--           array of sensible heat flux from surfaces
3006              IF ( av == 0 )  THEN
3007                 IF ( idsint == iup_u )  THEN
3008                    DO  m = 1, surf_usm_h%ns
3009                       i = surf_usm_h%i(m)
3010                       j = surf_usm_h%j(m)
3011                       k = surf_usm_h%k(m)
3012                       temp_pf(k,j,i) = surf_usm_h%wshf_eb(m)
3013                    ENDDO
3014                 ELSE
3015                    l = idsidx
3016                    DO  m = 1, surf_usm_v(l)%ns
3017                       i = surf_usm_v(l)%i(m)
3018                       j = surf_usm_v(l)%j(m)
3019                       k = surf_usm_v(l)%k(m)
3020                       temp_pf(k,j,i) = surf_usm_v(l)%wshf_eb(m)
3021                    ENDDO
3022                 ENDIF
3023              ELSE
3024                 IF ( idsint == iup_u )  THEN
3025                    DO  m = 1, surf_usm_h%ns
3026                       i = surf_usm_h%i(m)
3027                       j = surf_usm_h%j(m)
3028                       k = surf_usm_h%k(m)
3029                       temp_pf(k,j,i) = surf_usm_h%wshf_eb_av(m)
3030                    ENDDO
3031                 ELSE
3032                    l = idsidx
3033                    DO  m = 1, surf_usm_v(l)%ns
3034                       i = surf_usm_v(l)%i(m)
3035                       j = surf_usm_v(l)%j(m)
3036                       k = surf_usm_v(l)%k(m)
3037                       temp_pf(k,j,i) = surf_usm_v(l)%wshf_eb_av(m)
3038                    ENDDO
3039                 ENDIF
3040              ENDIF
3041
3042
3043          CASE ( 'usm_wghf' )
3044!--           array of heat flux from ground (land, wall, roof)
3045              IF ( av == 0 )  THEN
3046                 IF ( idsint == iup_u )  THEN
3047                    DO  m = 1, surf_usm_h%ns
3048                       i = surf_usm_h%i(m)
3049                       j = surf_usm_h%j(m)
3050                       k = surf_usm_h%k(m)
3051                       temp_pf(k,j,i) = surf_usm_h%wghf_eb(m)
3052                    ENDDO
3053                 ELSE
3054                    l = idsidx
3055                    DO  m = 1, surf_usm_v(l)%ns
3056                       i = surf_usm_v(l)%i(m)
3057                       j = surf_usm_v(l)%j(m)
3058                       k = surf_usm_v(l)%k(m)
3059                       temp_pf(k,j,i) = surf_usm_v(l)%wghf_eb(m)
3060                    ENDDO
3061                 ENDIF
3062              ELSE
3063                 IF ( idsint == iup_u )  THEN
3064                    DO  m = 1, surf_usm_h%ns
3065                       i = surf_usm_h%i(m)
3066                       j = surf_usm_h%j(m)
3067                       k = surf_usm_h%k(m)
3068                       temp_pf(k,j,i) = surf_usm_h%wghf_eb_av(m)
3069                    ENDDO
3070                 ELSE
3071                    l = idsidx
3072                    DO  m = 1, surf_usm_v(l)%ns
3073                       i = surf_usm_v(l)%i(m)
3074                       j = surf_usm_v(l)%j(m)
3075                       k = surf_usm_v(l)%k(m)
3076                       temp_pf(k,j,i) = surf_usm_v(l)%wghf_eb_av(m)
3077                    ENDDO
3078                 ENDIF
3079              ENDIF
3080
3081          CASE ( 'usm_wghf_window' )
3082!--           array of heat flux from window ground (land, wall, roof)
3083
3084              IF ( av == 0 )  THEN
3085                 IF ( idsint == iup_u )  THEN
3086                    DO  m = 1, surf_usm_h%ns
3087                       i = surf_usm_h%i(m)
3088                       j = surf_usm_h%j(m)
3089                       k = surf_usm_h%k(m)
3090                       temp_pf(k,j,i) = surf_usm_h%wghf_eb_window(m)
3091                    ENDDO
3092                 ELSE
3093                    l = idsidx
3094                    DO  m = 1, surf_usm_v(l)%ns
3095                       i = surf_usm_v(l)%i(m)
3096                       j = surf_usm_v(l)%j(m)
3097                       k = surf_usm_v(l)%k(m)
3098                       temp_pf(k,j,i) = surf_usm_v(l)%wghf_eb_window(m)
3099                    ENDDO
3100                 ENDIF
3101              ELSE
3102                 IF ( idsint == iup_u )  THEN
3103                    DO  m = 1, surf_usm_h%ns
3104                       i = surf_usm_h%i(m)
3105                       j = surf_usm_h%j(m)
3106                       k = surf_usm_h%k(m)
3107                       temp_pf(k,j,i) = surf_usm_h%wghf_eb_window_av(m)
3108                    ENDDO
3109                 ELSE
3110                    l = idsidx
3111                    DO  m = 1, surf_usm_v(l)%ns
3112                       i = surf_usm_v(l)%i(m)
3113                       j = surf_usm_v(l)%j(m)
3114                       k = surf_usm_v(l)%k(m)
3115                       temp_pf(k,j,i) = surf_usm_v(l)%wghf_eb_window_av(m)
3116                    ENDDO
3117                 ENDIF
3118              ENDIF
3119
3120          CASE ( 'usm_wghf_green' )
3121!--           array of heat flux from green ground (land, wall, roof)
3122
3123              IF ( av == 0 )  THEN
3124                 IF ( idsint == iup_u )  THEN
3125                    DO  m = 1, surf_usm_h%ns
3126                       i = surf_usm_h%i(m)
3127                       j = surf_usm_h%j(m)
3128                       k = surf_usm_h%k(m)
3129                       temp_pf(k,j,i) = surf_usm_h%wghf_eb_green(m)
3130                    ENDDO
3131                 ELSE
3132                    l = idsidx
3133                    DO  m = 1, surf_usm_v(l)%ns
3134                       i = surf_usm_v(l)%i(m)
3135                       j = surf_usm_v(l)%j(m)
3136                       k = surf_usm_v(l)%k(m)
3137                       temp_pf(k,j,i) = surf_usm_v(l)%wghf_eb_green(m)
3138                    ENDDO
3139                 ENDIF
3140              ELSE
3141                 IF ( idsint == iup_u )  THEN
3142                    DO  m = 1, surf_usm_h%ns
3143                       i = surf_usm_h%i(m)
3144                       j = surf_usm_h%j(m)
3145                       k = surf_usm_h%k(m)
3146                       temp_pf(k,j,i) = surf_usm_h%wghf_eb_green_av(m)
3147                    ENDDO
3148                 ELSE
3149                    l = idsidx
3150                    DO  m = 1, surf_usm_v(l)%ns
3151                       i = surf_usm_v(l)%i(m)
3152                       j = surf_usm_v(l)%j(m)
3153                       k = surf_usm_v(l)%k(m)
3154                       temp_pf(k,j,i) = surf_usm_v(l)%wghf_eb_green_av(m)
3155                    ENDDO
3156                 ENDIF
3157              ENDIF
3158
3159          CASE ( 'usm_iwghf' )
3160!--           array of heat flux from indoor ground (land, wall, roof)
3161              IF ( av == 0 )  THEN
3162                 IF ( idsint == iup_u )  THEN
3163                    DO  m = 1, surf_usm_h%ns
3164                       i = surf_usm_h%i(m)
3165                       j = surf_usm_h%j(m)
3166                       k = surf_usm_h%k(m)
3167                       temp_pf(k,j,i) = surf_usm_h%iwghf_eb(m)
3168                    ENDDO
3169                 ELSE
3170                    l = idsidx
3171                    DO  m = 1, surf_usm_v(l)%ns
3172                       i = surf_usm_v(l)%i(m)
3173                       j = surf_usm_v(l)%j(m)
3174                       k = surf_usm_v(l)%k(m)
3175                       temp_pf(k,j,i) = surf_usm_v(l)%iwghf_eb(m)
3176                    ENDDO
3177                 ENDIF
3178              ELSE
3179                 IF ( idsint == iup_u )  THEN
3180                    DO  m = 1, surf_usm_h%ns
3181                       i = surf_usm_h%i(m)
3182                       j = surf_usm_h%j(m)
3183                       k = surf_usm_h%k(m)
3184                       temp_pf(k,j,i) = surf_usm_h%iwghf_eb_av(m)
3185                    ENDDO
3186                 ELSE
3187                    l = idsidx
3188                    DO  m = 1, surf_usm_v(l)%ns
3189                       i = surf_usm_v(l)%i(m)
3190                       j = surf_usm_v(l)%j(m)
3191                       k = surf_usm_v(l)%k(m)
3192                       temp_pf(k,j,i) = surf_usm_v(l)%iwghf_eb_av(m)
3193                    ENDDO
3194                 ENDIF
3195              ENDIF
3196
3197          CASE ( 'usm_iwghf_window' )
3198!--           array of heat flux from indoor window ground (land, wall, roof)
3199
3200              IF ( av == 0 )  THEN
3201                 IF ( idsint == iup_u )  THEN
3202                    DO  m = 1, surf_usm_h%ns
3203                       i = surf_usm_h%i(m)
3204                       j = surf_usm_h%j(m)
3205                       k = surf_usm_h%k(m)
3206                       temp_pf(k,j,i) = surf_usm_h%iwghf_eb_window(m)
3207                    ENDDO
3208                 ELSE
3209                    l = idsidx
3210                    DO  m = 1, surf_usm_v(l)%ns
3211                       i = surf_usm_v(l)%i(m)
3212                       j = surf_usm_v(l)%j(m)
3213                       k = surf_usm_v(l)%k(m)
3214                       temp_pf(k,j,i) = surf_usm_v(l)%iwghf_eb_window(m)
3215                    ENDDO
3216                 ENDIF
3217              ELSE
3218                 IF ( idsint == iup_u )  THEN
3219                    DO  m = 1, surf_usm_h%ns
3220                       i = surf_usm_h%i(m)
3221                       j = surf_usm_h%j(m)
3222                       k = surf_usm_h%k(m)
3223                       temp_pf(k,j,i) = surf_usm_h%iwghf_eb_window_av(m)
3224                    ENDDO
3225                 ELSE
3226                    l = idsidx
3227                    DO  m = 1, surf_usm_v(l)%ns
3228                       i = surf_usm_v(l)%i(m)
3229                       j = surf_usm_v(l)%j(m)
3230                       k = surf_usm_v(l)%k(m)
3231                       temp_pf(k,j,i) = surf_usm_v(l)%iwghf_eb_window_av(m)
3232                    ENDDO
3233                 ENDIF
3234              ENDIF
3235             
3236          CASE ( 'usm_t_surf' )
3237!--           surface temperature for surfaces
3238              IF ( av == 0 )  THEN
3239                 IF ( idsint == iup_u )  THEN
3240                    DO  m = 1, surf_usm_h%ns
3241                       i = surf_usm_h%i(m)
3242                       j = surf_usm_h%j(m)
3243                       k = surf_usm_h%k(m)
3244                       temp_pf(k,j,i) = t_surf_h(m)
3245                    ENDDO
3246                 ELSE
3247                    l = idsidx
3248                    DO  m = 1, surf_usm_v(l)%ns
3249                       i = surf_usm_v(l)%i(m)
3250                       j = surf_usm_v(l)%j(m)
3251                       k = surf_usm_v(l)%k(m)
3252                       temp_pf(k,j,i) = t_surf_v(l)%t(m)
3253                    ENDDO
3254                 ENDIF
3255              ELSE
3256                 IF ( idsint == iup_u )  THEN
3257                    DO  m = 1, surf_usm_h%ns
3258                       i = surf_usm_h%i(m)
3259                       j = surf_usm_h%j(m)
3260                       k = surf_usm_h%k(m)
3261                       temp_pf(k,j,i) = surf_usm_h%t_surf_av(m)
3262                    ENDDO
3263                 ELSE
3264                    l = idsidx
3265                    DO  m = 1, surf_usm_v(l)%ns
3266                       i = surf_usm_v(l)%i(m)
3267                       j = surf_usm_v(l)%j(m)
3268                       k = surf_usm_v(l)%k(m)
3269                       temp_pf(k,j,i) = surf_usm_v(l)%t_surf_av(m)
3270                    ENDDO
3271                 ENDIF
3272              ENDIF
3273             
3274          CASE ( 'usm_t_surf_window' )
3275!--           surface temperature for window surfaces
3276
3277              IF ( av == 0 )  THEN
3278                 IF ( idsint == iup_u )  THEN
3279                    DO  m = 1, surf_usm_h%ns
3280                       i = surf_usm_h%i(m)
3281                       j = surf_usm_h%j(m)
3282                       k = surf_usm_h%k(m)
3283                       temp_pf(k,j,i) = t_surf_window_h(m)
3284                    ENDDO
3285                 ELSE
3286                    l = idsidx
3287                    DO  m = 1, surf_usm_v(l)%ns
3288                       i = surf_usm_v(l)%i(m)
3289                       j = surf_usm_v(l)%j(m)
3290                       k = surf_usm_v(l)%k(m)
3291                       temp_pf(k,j,i) = t_surf_window_v(l)%t(m)
3292                    ENDDO
3293                 ENDIF
3294
3295              ELSE
3296                 IF ( idsint == iup_u )  THEN
3297                    DO  m = 1, surf_usm_h%ns
3298                       i = surf_usm_h%i(m)
3299                       j = surf_usm_h%j(m)
3300                       k = surf_usm_h%k(m)
3301                       temp_pf(k,j,i) = surf_usm_h%t_surf_window_av(m)
3302                    ENDDO
3303                 ELSE
3304                    l = idsidx
3305                    DO  m = 1, surf_usm_v(l)%ns
3306                       i = surf_usm_v(l)%i(m)
3307                       j = surf_usm_v(l)%j(m)
3308                       k = surf_usm_v(l)%k(m)
3309                       temp_pf(k,j,i) = surf_usm_v(l)%t_surf_window_av(m)
3310                    ENDDO
3311
3312                 ENDIF
3313
3314              ENDIF
3315
3316          CASE ( 'usm_t_surf_green' )
3317!--           surface temperature for green surfaces
3318
3319              IF ( av == 0 )  THEN
3320                 IF ( idsint == iup_u )  THEN
3321                    DO  m = 1, surf_usm_h%ns
3322                       i = surf_usm_h%i(m)
3323                       j = surf_usm_h%j(m)
3324                       k = surf_usm_h%k(m)
3325                       temp_pf(k,j,i) = t_surf_green_h(m)
3326                    ENDDO
3327                 ELSE
3328                    l = idsidx
3329                    DO  m = 1, surf_usm_v(l)%ns
3330                       i = surf_usm_v(l)%i(m)
3331                       j = surf_usm_v(l)%j(m)
3332                       k = surf_usm_v(l)%k(m)
3333                       temp_pf(k,j,i) = t_surf_green_v(l)%t(m)
3334                    ENDDO
3335                 ENDIF
3336
3337              ELSE
3338                 IF ( idsint == iup_u )  THEN
3339                    DO  m = 1, surf_usm_h%ns
3340                       i = surf_usm_h%i(m)
3341                       j = surf_usm_h%j(m)
3342                       k = surf_usm_h%k(m)
3343                       temp_pf(k,j,i) = surf_usm_h%t_surf_green_av(m)
3344                    ENDDO
3345                 ELSE
3346                    l = idsidx
3347                    DO  m = 1, surf_usm_v(l)%ns
3348                       i = surf_usm_v(l)%i(m)
3349                       j = surf_usm_v(l)%j(m)
3350                       k = surf_usm_v(l)%k(m)
3351                       temp_pf(k,j,i) = surf_usm_v(l)%t_surf_green_av(m)
3352                    ENDDO
3353
3354                 ENDIF
3355
3356              ENDIF
3357
3358          CASE ( 'usm_t_surf_10cm' )
3359!--           near surface temperature for whole surfaces
3360
3361              IF ( av == 0 )  THEN
3362                 IF ( idsint == iup_u )  THEN
3363                    DO  m = 1, surf_usm_h%ns
3364                       i = surf_usm_h%i(m)
3365                       j = surf_usm_h%j(m)
3366                       k = surf_usm_h%k(m)
3367                       temp_pf(k,j,i) = t_surf_10cm_h(m)
3368                    ENDDO
3369                 ELSE
3370                    l = idsidx
3371                    DO  m = 1, surf_usm_v(l)%ns
3372                       i = surf_usm_v(l)%i(m)
3373                       j = surf_usm_v(l)%j(m)
3374                       k = surf_usm_v(l)%k(m)
3375                       temp_pf(k,j,i) = t_surf_10cm_v(l)%t(m)
3376                    ENDDO
3377                 ENDIF
3378
3379              ELSE
3380                 IF ( idsint == iup_u )  THEN
3381                    DO  m = 1, surf_usm_h%ns
3382                       i = surf_usm_h%i(m)
3383                       j = surf_usm_h%j(m)
3384                       k = surf_usm_h%k(m)
3385                       temp_pf(k,j,i) = surf_usm_h%t_surf_10cm_av(m)
3386                    ENDDO
3387                 ELSE
3388                    l = idsidx
3389                    DO  m = 1, surf_usm_v(l)%ns
3390                       i = surf_usm_v(l)%i(m)
3391                       j = surf_usm_v(l)%j(m)
3392                       k = surf_usm_v(l)%k(m)
3393                       temp_pf(k,j,i) = surf_usm_v(l)%t_surf_10cm_av(m)
3394                    ENDDO
3395
3396                 ENDIF
3397
3398              ENDIF
3399
3400             
3401          CASE ( 'usm_t_wall' )
3402!--           wall temperature for  iwl layer of walls and land
3403              IF ( av == 0 )  THEN
3404                 IF ( idsint == iup_u )  THEN
3405                    DO  m = 1, surf_usm_h%ns
3406                       i = surf_usm_h%i(m)
3407                       j = surf_usm_h%j(m)
3408                       k = surf_usm_h%k(m)
3409                       temp_pf(k,j,i) = t_wall_h(iwl,m)
3410                    ENDDO
3411                 ELSE
3412                    l = idsidx
3413                    DO  m = 1, surf_usm_v(l)%ns
3414                       i = surf_usm_v(l)%i(m)
3415                       j = surf_usm_v(l)%j(m)
3416                       k = surf_usm_v(l)%k(m)
3417                       temp_pf(k,j,i) = t_wall_v(l)%t(iwl,m)
3418                    ENDDO
3419                 ENDIF
3420              ELSE
3421                 IF ( idsint == iup_u )  THEN
3422                    DO  m = 1, surf_usm_h%ns
3423                       i = surf_usm_h%i(m)
3424                       j = surf_usm_h%j(m)
3425                       k = surf_usm_h%k(m)
3426                       temp_pf(k,j,i) = surf_usm_h%t_wall_av(iwl,m)
3427                    ENDDO
3428                 ELSE
3429                    l = idsidx
3430                    DO  m = 1, surf_usm_v(l)%ns
3431                       i = surf_usm_v(l)%i(m)
3432                       j = surf_usm_v(l)%j(m)
3433                       k = surf_usm_v(l)%k(m)
3434                       temp_pf(k,j,i) = surf_usm_v(l)%t_wall_av(iwl,m)
3435                    ENDDO
3436                 ENDIF
3437              ENDIF
3438             
3439          CASE ( 'usm_t_window' )
3440!--           window temperature for iwl layer of walls and land
3441              IF ( av == 0 )  THEN
3442                 IF ( idsint == iup_u )  THEN
3443                    DO  m = 1, surf_usm_h%ns
3444                       i = surf_usm_h%i(m)
3445                       j = surf_usm_h%j(m)
3446                       k = surf_usm_h%k(m)
3447                       temp_pf(k,j,i) = t_window_h(iwl,m)
3448                    ENDDO
3449                 ELSE
3450                    l = idsidx
3451                    DO  m = 1, surf_usm_v(l)%ns
3452                       i = surf_usm_v(l)%i(m)
3453                       j = surf_usm_v(l)%j(m)
3454                       k = surf_usm_v(l)%k(m)
3455                       temp_pf(k,j,i) = t_window_v(l)%t(iwl,m)
3456                    ENDDO
3457                 ENDIF
3458              ELSE
3459                 IF ( idsint == iup_u )  THEN
3460                    DO  m = 1, surf_usm_h%ns
3461                       i = surf_usm_h%i(m)
3462                       j = surf_usm_h%j(m)
3463                       k = surf_usm_h%k(m)
3464                       temp_pf(k,j,i) = surf_usm_h%t_window_av(iwl,m)
3465                    ENDDO
3466                 ELSE
3467                    l = idsidx
3468                    DO  m = 1, surf_usm_v(l)%ns
3469                       i = surf_usm_v(l)%i(m)
3470                       j = surf_usm_v(l)%j(m)
3471                       k = surf_usm_v(l)%k(m)
3472                       temp_pf(k,j,i) = surf_usm_v(l)%t_window_av(iwl,m)
3473                    ENDDO
3474                 ENDIF
3475              ENDIF
3476
3477          CASE ( 'usm_t_green' )
3478!--           green temperature for  iwl layer of walls and land
3479              IF ( av == 0 )  THEN
3480                 IF ( idsint == iup_u )  THEN
3481                    DO  m = 1, surf_usm_h%ns
3482                       i = surf_usm_h%i(m)
3483                       j = surf_usm_h%j(m)
3484                       k = surf_usm_h%k(m)
3485                       temp_pf(k,j,i) = t_green_h(iwl,m)
3486                    ENDDO
3487                 ELSE
3488                    l = idsidx
3489                    DO  m = 1, surf_usm_v(l)%ns
3490                       i = surf_usm_v(l)%i(m)
3491                       j = surf_usm_v(l)%j(m)
3492                       k = surf_usm_v(l)%k(m)
3493                       temp_pf(k,j,i) = t_green_v(l)%t(iwl,m)
3494                    ENDDO
3495                 ENDIF
3496              ELSE
3497                 IF ( idsint == iup_u )  THEN
3498                    DO  m = 1, surf_usm_h%ns
3499                       i = surf_usm_h%i(m)
3500                       j = surf_usm_h%j(m)
3501                       k = surf_usm_h%k(m)
3502                       temp_pf(k,j,i) = surf_usm_h%t_green_av(iwl,m)
3503                    ENDDO
3504                 ELSE
3505                    l = idsidx
3506                    DO  m = 1, surf_usm_v(l)%ns
3507                       i = surf_usm_v(l)%i(m)
3508                       j = surf_usm_v(l)%j(m)
3509                       k = surf_usm_v(l)%k(m)
3510                       temp_pf(k,j,i) = surf_usm_v(l)%t_green_av(iwl,m)
3511                    ENDDO
3512                 ENDIF
3513              ENDIF
3514
3515             
3516          CASE DEFAULT
3517              found = .FALSE.
3518              RETURN
3519        END SELECT
3520
3521!
3522!--     Rearrange dimensions for NetCDF output
3523!--     FIXME: this may generate FPE overflow upon conversion from DP to SP
3524        DO  j = nys, nyn
3525            DO  i = nxl, nxr
3526                DO  k = nzb_do, nzt_do
3527                    local_pf(i,j,k) = temp_pf(k,j,i)
3528                ENDDO
3529            ENDDO
3530        ENDDO
3531       
3532    END SUBROUTINE usm_data_output_3d
3533   
3534
3535!------------------------------------------------------------------------------!
3536!
3537! Description:
3538! ------------
3539!> Soubroutine defines appropriate grid for netcdf variables.
3540!> It is called out from subroutine netcdf.
3541!------------------------------------------------------------------------------!
3542    SUBROUTINE usm_define_netcdf_grid( variable, found, grid_x, grid_y, grid_z )
3543   
3544        IMPLICIT NONE
3545
3546        CHARACTER (len=*), INTENT(IN)  ::  variable    !<
3547        LOGICAL, INTENT(OUT)           ::  found       !<
3548        CHARACTER (len=*), INTENT(OUT) ::  grid_x      !<
3549        CHARACTER (len=*), INTENT(OUT) ::  grid_y      !<
3550        CHARACTER (len=*), INTENT(OUT) ::  grid_z      !<
3551
3552        CHARACTER (len=varnamelength)  :: var
3553
3554        var = TRIM(variable)
3555        IF ( var(1:12) == 'usm_rad_net_'  .OR.  var(1:13) == 'usm_rad_insw_'  .OR.          &
3556             var(1:13) == 'usm_rad_inlw_'  .OR.  var(1:16) == 'usm_rad_inswdir_'  .OR.      &
3557             var(1:16) == 'usm_rad_inswdif_'  .OR.  var(1:16) == 'usm_rad_inswref_'  .OR.   &
3558             var(1:16) == 'usm_rad_inlwdif_'  .OR.  var(1:16) == 'usm_rad_inlwref_'  .OR.   &
3559             var(1:14) == 'usm_rad_outsw_'  .OR.  var(1:14) == 'usm_rad_outlw_'  .OR.       &
3560             var(1:14) == 'usm_rad_ressw_'  .OR.  var(1:14) == 'usm_rad_reslw_'  .OR.       &
3561             var(1:11) == 'usm_rad_hf_'  .OR.  var == 'usm_rad_pc_inlw'  .OR.               &
3562             var == 'usm_rad_pc_insw'  .OR.  var == 'usm_rad_pc_inswdir'  .OR.              &
3563             var == 'usm_rad_pc_inswdif'  .OR.  var == 'usm_rad_pc_inswref'  .OR.           &
3564             var(1:9) == 'usm_wshf_'  .OR.  var(1:9) == 'usm_wghf_'  .OR.                   &
3565             var(1:16) == 'usm_wghf_window_'  .OR. var(1:15) == 'usm_wghf_green_' .OR.      &
3566             var(1:10) == 'usm_iwghf_'  .OR. var(1:17) == 'usm_iwghf_window_' .OR.          &
3567             var(1:10) == 'usm_t_surf'  .OR.  var(1:10) == 'usm_t_wall'  .OR.               &
3568             var(1:17) == 'usm_t_surf_window'  .OR.  var(1:12) == 'usm_t_window'  .OR.      &
3569             var(1:16) == 'usm_t_surf_green'  .OR.                                          &
3570             var(1:15) == 'usm_t_surf_10cm' .OR.                                            &
3571             var(1:9) == 'usm_surfz'  .OR.  var(1:7) == 'usm_svf'  .OR.                     & 
3572             var(1:7) == 'usm_dif'  .OR.  var(1:11) == 'usm_surfcat'  .OR.                  &
3573             var(1:11) == 'usm_surfalb'  .OR.  var(1:12) == 'usm_surfemis'  .OR.            &
3574             var(1:16) == 'usm_surfwintrans'  .OR.                                          &
3575             var(1:9) == 'usm_skyvf' .OR. var(1:9) == 'usm_skyvft' ) THEN
3576
3577            found = .TRUE.
3578            grid_x = 'x'
3579            grid_y = 'y'
3580            grid_z = 'zu'
3581        ELSE
3582            found  = .FALSE.
3583            grid_x = 'none'
3584            grid_y = 'none'
3585            grid_z = 'none'
3586        ENDIF
3587
3588    END SUBROUTINE usm_define_netcdf_grid
3589   
3590
3591!------------------------------------------------------------------------------!
3592! Description:
3593! ------------
3594!> Initialization of the wall surface model
3595!------------------------------------------------------------------------------!
3596    SUBROUTINE usm_init_material_model
3597
3598        IMPLICIT NONE
3599
3600        INTEGER(iwp) ::  k, l, m            !< running indices
3601       
3602        CALL location_message( '    initialization of wall surface model', .TRUE. )
3603       
3604!--     Calculate wall grid spacings.
3605!--     Temperature is defined at the center of the wall layers,
3606!--     whereas gradients/fluxes are defined at the edges (_stag)     
3607!--     apply for all particular surface grids. First for horizontal surfaces
3608        DO  m = 1, surf_usm_h%ns
3609
3610           surf_usm_h%dz_wall(nzb_wall,m) = surf_usm_h%zw(nzb_wall,m)
3611           DO k = nzb_wall+1, nzt_wall
3612               surf_usm_h%dz_wall(k,m) = surf_usm_h%zw(k,m) -                  &
3613                                         surf_usm_h%zw(k-1,m)
3614           ENDDO
3615           surf_usm_h%dz_window(nzb_wall,m) = surf_usm_h%zw_window(nzb_wall,m)
3616           DO k = nzb_wall+1, nzt_wall
3617               surf_usm_h%dz_window(k,m) = surf_usm_h%zw_window(k,m) -         &
3618                                         surf_usm_h%zw_window(k-1,m)
3619           ENDDO
3620           surf_usm_h%dz_green(nzb_wall,m) = surf_usm_h%zw_green(nzb_wall,m)
3621           DO k = nzb_wall+1, nzt_wall
3622               surf_usm_h%dz_green(k,m) = surf_usm_h%zw_green(k,m) -           &
3623                                         surf_usm_h%zw_green(k-1,m)
3624           ENDDO
3625           
3626           surf_usm_h%dz_wall(nzt_wall+1,m) = surf_usm_h%dz_wall(nzt_wall,m)
3627
3628           DO k = nzb_wall, nzt_wall-1
3629               surf_usm_h%dz_wall_stag(k,m) = 0.5 * (                          &
3630                           surf_usm_h%dz_wall(k+1,m) + surf_usm_h%dz_wall(k,m) )
3631           ENDDO
3632           surf_usm_h%dz_wall_stag(nzt_wall,m) = surf_usm_h%dz_wall(nzt_wall,m)
3633           
3634           surf_usm_h%dz_window(nzt_wall+1,m) = surf_usm_h%dz_window(nzt_wall,m)
3635
3636           DO k = nzb_wall, nzt_wall-1
3637               surf_usm_h%dz_window_stag(k,m) = 0.5 * (                        &
3638                           surf_usm_h%dz_window(k+1,m) + surf_usm_h%dz_window(k,m) )
3639           ENDDO
3640           surf_usm_h%dz_window_stag(nzt_wall,m) = surf_usm_h%dz_window(nzt_wall,m)
3641
3642           surf_usm_h%dz_green(nzt_wall+1,m) = surf_usm_h%dz_green(nzt_wall,m)
3643
3644           DO k = nzb_wall, nzt_wall-1
3645               surf_usm_h%dz_green_stag(k,m) = 0.5 * (                         &
3646                           surf_usm_h%dz_green(k+1,m) + surf_usm_h%dz_green(k,m) )
3647           ENDDO
3648           surf_usm_h%dz_green_stag(nzt_wall,m) = surf_usm_h%dz_green(nzt_wall,m)
3649        ENDDO
3650        surf_usm_h%ddz_wall        = 1.0_wp / surf_usm_h%dz_wall
3651        surf_usm_h%ddz_wall_stag   = 1.0_wp / surf_usm_h%dz_wall_stag
3652        surf_usm_h%ddz_window      = 1.0_wp / surf_usm_h%dz_window
3653        surf_usm_h%ddz_window_stag = 1.0_wp / surf_usm_h%dz_window_stag
3654        surf_usm_h%ddz_green       = 1.0_wp / surf_usm_h%dz_green
3655        surf_usm_h%ddz_green_stag  = 1.0_wp / surf_usm_h%dz_green_stag
3656!       
3657!--     For vertical surfaces
3658        DO  l = 0, 3
3659           DO  m = 1, surf_usm_v(l)%ns
3660              surf_usm_v(l)%dz_wall(nzb_wall,m) = surf_usm_v(l)%zw(nzb_wall,m)
3661              DO k = nzb_wall+1, nzt_wall
3662                  surf_usm_v(l)%dz_wall(k,m) = surf_usm_v(l)%zw(k,m) -         &
3663                                               surf_usm_v(l)%zw(k-1,m)
3664              ENDDO
3665              surf_usm_v(l)%dz_window(nzb_wall,m) = surf_usm_v(l)%zw_window(nzb_wall,m)
3666              DO k = nzb_wall+1, nzt_wall
3667                  surf_usm_v(l)%dz_window(k,m) = surf_usm_v(l)%zw_window(k,m) - &
3668                                               surf_usm_v(l)%zw_window(k-1,m)
3669              ENDDO
3670              surf_usm_v(l)%dz_green(nzb_wall,m) = surf_usm_v(l)%zw_green(nzb_wall,m)
3671              DO k = nzb_wall+1, nzt_wall
3672                  surf_usm_v(l)%dz_green(k,m) = surf_usm_v(l)%zw_green(k,m) - &
3673                                               surf_usm_v(l)%zw_green(k-1,m)
3674              ENDDO
3675           
3676              surf_usm_v(l)%dz_wall(nzt_wall+1,m) =                            &
3677                                              surf_usm_v(l)%dz_wall(nzt_wall,m)
3678
3679              DO k = nzb_wall, nzt_wall-1
3680                  surf_usm_v(l)%dz_wall_stag(k,m) = 0.5 * (                    &
3681                                                surf_usm_v(l)%dz_wall(k+1,m) + &
3682                                                surf_usm_v(l)%dz_wall(k,m) )
3683              ENDDO
3684              surf_usm_v(l)%dz_wall_stag(nzt_wall,m) =                         &
3685                                              surf_usm_v(l)%dz_wall(nzt_wall,m)
3686              surf_usm_v(l)%dz_window(nzt_wall+1,m) =                            &
3687                                              surf_usm_v(l)%dz_window(nzt_wall,m)
3688
3689              DO k = nzb_wall, nzt_wall-1
3690                  surf_usm_v(l)%dz_window_stag(k,m) = 0.5 * (                    &
3691                                                surf_usm_v(l)%dz_window(k+1,m) + &
3692                                                surf_usm_v(l)%dz_window(k,m) )
3693              ENDDO
3694              surf_usm_v(l)%dz_window_stag(nzt_wall,m) =                         &
3695                                              surf_usm_v(l)%dz_window(nzt_wall,m)
3696              surf_usm_v(l)%dz_green(nzt_wall+1,m) =                            &
3697                                              surf_usm_v(l)%dz_green(nzt_wall,m)
3698
3699              DO k = nzb_wall, nzt_wall-1
3700                  surf_usm_v(l)%dz_green_stag(k,m) = 0.5 * (                    &
3701                                                surf_usm_v(l)%dz_green(k+1,m) + &
3702                                                surf_usm_v(l)%dz_green(k,m) )
3703              ENDDO
3704              surf_usm_v(l)%dz_green_stag(nzt_wall,m) =                         &
3705                                              surf_usm_v(l)%dz_green(nzt_wall,m)
3706           ENDDO
3707           surf_usm_v(l)%ddz_wall        = 1.0_wp / surf_usm_v(l)%dz_wall
3708           surf_usm_v(l)%ddz_wall_stag   = 1.0_wp / surf_usm_v(l)%dz_wall_stag
3709           surf_usm_v(l)%ddz_window      = 1.0_wp / surf_usm_v(l)%dz_window
3710           surf_usm_v(l)%ddz_window_stag = 1.0_wp / surf_usm_v(l)%dz_window_stag
3711           surf_usm_v(l)%ddz_green       = 1.0_wp / surf_usm_v(l)%dz_green
3712           surf_usm_v(l)%ddz_green_stag  = 1.0_wp / surf_usm_v(l)%dz_green_stag
3713        ENDDO     
3714
3715       
3716        CALL location_message( '    wall structures filed out', .TRUE. )
3717
3718        CALL location_message( '    initialization of wall surface model finished', .TRUE. )
3719
3720    END SUBROUTINE usm_init_material_model
3721
3722 
3723!------------------------------------------------------------------------------!
3724! Description:
3725! ------------
3726!> Initialization of the urban surface model
3727!------------------------------------------------------------------------------!
3728    SUBROUTINE usm_init_urban_surface
3729
3730        USE arrays_3d,                                                         &
3731            ONLY:  zw
3732
3733        USE netcdf_data_input_mod,                                             &
3734            ONLY:  building_pars_f, building_type_f, terrain_height_f
3735   
3736        IMPLICIT NONE
3737
3738        INTEGER(iwp) ::  i                   !< loop index x-dirction
3739        INTEGER(iwp) ::  ind_emis_wall       !< index in input list for wall emissivity
3740        INTEGER(iwp) ::  ind_emis_green      !< index in input list for green emissivity
3741        INTEGER(iwp) ::  ind_emis_win        !< index in input list for window emissivity
3742        INTEGER(iwp) ::  ind_green_frac_w    !< index in input list for green fraction on wall
3743        INTEGER(iwp) ::  ind_green_frac_r    !< index in input list for green fraction on roof
3744        INTEGER(iwp) ::  ind_hc1             !< index in input list for heat capacity at first wall layer
3745        INTEGER(iwp) ::  ind_hc2             !< index in input list for heat capacity at second wall layer
3746        INTEGER(iwp) ::  ind_hc3             !< index in input list for heat capacity at third wall layer
3747        INTEGER(iwp) ::  ind_lai_r           !< index in input list for LAI on roof
3748        INTEGER(iwp) ::  ind_lai_w           !< index in input list for LAI on wall
3749        INTEGER(iwp) ::  ind_tc1             !< index in input list for thermal conductivity at first wall layer
3750        INTEGER(iwp) ::  ind_tc2             !< index in input list for thermal conductivity at second wall layer
3751        INTEGER(iwp) ::  ind_tc3             !< index in input list for thermal conductivity at third wall layer
3752        INTEGER(iwp) ::  ind_trans           !< index in input list for window transmissivity
3753        INTEGER(iwp) ::  ind_wall_frac       !< index in input list for wall fraction
3754        INTEGER(iwp) ::  ind_win_frac        !< index in input list for window fraction
3755        INTEGER(iwp) ::  ind_z0              !< index in input list for z0
3756        INTEGER(iwp) ::  ind_z0qh            !< index in input list for z0h / z0q
3757        INTEGER(iwp) ::  j                   !< loop index y-dirction
3758        INTEGER(iwp) ::  k                   !< loop index z-dirction
3759        INTEGER(iwp) ::  l                   !< loop index surface orientation
3760        INTEGER(iwp) ::  m                   !< loop index surface element
3761        INTEGER(iwp) ::  st                  !< dummy 
3762
3763        REAL(wp)     ::  c, tin, twin
3764        REAL(wp)     ::  ground_floor_level_l         !< local height of ground floor level
3765        REAL(wp)     ::  z_agl                        !< height above ground
3766
3767!
3768!-- NOPOINTER version not implemented yet
3769#if defined( __nopointer )
3770    message_string = 'The urban surface module only runs with POINTER version'
3771    CALL message( 'urban_surface_mod', 'PA0452', 1, 2, 0, 6, 0 )
3772#endif
3773
3774        CALL cpu_log( log_point_s(78), 'usm_init', 'start' )
3775!--     surface forcing have to be disabled for LSF
3776!--     in case of enabled urban surface module
3777        IF ( large_scale_forcing )  THEN
3778            lsf_surf = .FALSE.
3779        ENDIF
3780
3781!
3782!--     Flag surface elements belonging to the ground floor level. Therefore,
3783!--     use terrain height array from file, if available. This flag is later used
3784!--     to control initialization of surface attributes.
3785        surf_usm_h%ground_level = .FALSE. 
3786        DO  m = 1, surf_usm_h%ns
3787           i = surf_usm_h%i(m)
3788           j = surf_usm_h%j(m)
3789           k = surf_usm_h%k(m)
3790!
3791!--        Get local ground level. If no ground level is given in input file,
3792!--        use default value.
3793           ground_floor_level_l = ground_floor_level
3794           IF ( building_pars_f%from_file )  THEN
3795              IF ( building_pars_f%pars_xy(ind_gflh,j,i) /=                    &
3796                   building_pars_f%fill )  &
3797                 ground_floor_level_l = building_pars_f%pars_xy(ind_gflh,j,i)         
3798           ENDIF
3799!
3800!--        Determine height of surface element above ground level
3801           IF (  terrain_height_f%from_file )  THEN
3802              z_agl = zw(k) - terrain_height_f%var(j,i)
3803           ELSE
3804              z_agl = zw(k)
3805           ENDIF
3806!
3807!--        Set flag for ground level
3808           IF ( z_agl <= ground_floor_level_l )                                &
3809              surf_usm_h%ground_level(m) = .TRUE.
3810        ENDDO
3811
3812        DO  l = 0, 3
3813           surf_usm_v(l)%ground_level = .FALSE.
3814           DO  m = 1, surf_usm_v(l)%ns
3815              i = surf_usm_v(l)%i(m) + surf_usm_v(l)%ioff
3816              j = surf_usm_v(l)%j(m) + surf_usm_v(l)%joff
3817              k = surf_usm_v(l)%k(m)
3818!
3819!--           Get local ground level. If no ground level is given in input file,
3820!--           use default value.
3821              ground_floor_level_l = ground_floor_level
3822              IF ( building_pars_f%from_file )  THEN
3823                 IF ( building_pars_f%pars_xy(ind_gflh,j,i) /=                 &
3824                      building_pars_f%fill ) &
3825                    ground_floor_level_l = building_pars_f%pars_xy(ind_gflh,j,i)
3826              ENDIF
3827!
3828!--           Determine height of surface element above ground level. Please
3829!--           note, height of surface element is determined with respect to
3830!--           its height of the adjoing atmospheric grid point.
3831              IF (  terrain_height_f%from_file )  THEN
3832                 z_agl = zw(k) - terrain_height_f%var(j-surf_usm_v(l)%joff,    &
3833                                                      i-surf_usm_v(l)%ioff)
3834              ELSE
3835                 z_agl = zw(k)
3836              ENDIF
3837!
3838!--           Set flag for ground level
3839              IF ( z_agl <= ground_floor_level_l )                                &
3840                 surf_usm_v(l)%ground_level(m) = .TRUE.
3841
3842           ENDDO
3843        ENDDO
3844!
3845!--     Initialization of resistances.
3846        DO  m = 1, surf_usm_h%ns
3847           surf_usm_h%r_a(m)        = 50.0_wp
3848           surf_usm_h%r_a_green(m)  = 50.0_wp
3849           surf_usm_h%r_a_window(m) = 50.0_wp
3850        ENDDO
3851        DO  l = 0, 3
3852           DO  m = 1, surf_usm_v(l)%ns
3853              surf_usm_v(l)%r_a(m)        = 50.0_wp
3854              surf_usm_v(l)%r_a_green(m)  = 50.0_wp
3855              surf_usm_v(l)%r_a_window(m) = 50.0_wp
3856           ENDDO
3857        ENDDO
3858!
3859!--     Initialize urban-type surface attribute. According to initialization in
3860!--     land-surface model, follow a 3-level approach.
3861!--     Level 1 - initialization via default attributes
3862        DO  m = 1, surf_usm_h%ns
3863!
3864!--        Now, all horizontal surfaces are roof surfaces (?)
3865           surf_usm_h%isroof_surf(m)   = .TRUE.
3866           surf_usm_h%surface_types(m) = roof_category         !< default category for root surface
3867!
3868!--        In order to distinguish between ground floor level and
3869!--        above-ground-floor level surfaces, set input indices.
3870           ind_wall_frac    = MERGE( ind_wall_frac_gfl,    ind_wall_frac_agfl,    &
3871                                     surf_usm_h%ground_level(m) )
3872           ind_win_frac     = MERGE( ind_win_frac_gfl,     ind_win_frac_agfl,     &
3873                                     surf_usm_h%ground_level(m) )
3874           ind_green_frac_w = MERGE( ind_green_frac_w_gfl, ind_green_frac_w_agfl, &
3875                                     surf_usm_h%ground_level(m) )
3876           ind_green_frac_r = MERGE( ind_green_frac_r_gfl, ind_green_frac_r_agfl, &
3877                                     surf_usm_h%ground_level(m) )
3878           ind_lai_r        = MERGE( ind_lai_r_gfl,        ind_lai_r_agfl,        &
3879                                     surf_usm_h%ground_level(m) )
3880           ind_lai_w        = MERGE( ind_lai_w_gfl,        ind_lai_w_agfl,        &
3881                                     surf_usm_h%ground_level(m) )
3882           ind_hc1          = MERGE( ind_hc1_gfl,          ind_hc1_agfl,          &
3883                                     surf_usm_h%ground_level(m) )
3884           ind_hc2          = MERGE( ind_hc2_gfl,          ind_hc2_agfl,          &
3885                                     surf_usm_h%ground_level(m) )
3886           ind_hc3          = MERGE( ind_hc3_gfl,          ind_hc3_agfl,          &
3887                                     surf_usm_h%ground_level(m) )
3888           ind_tc1          = MERGE( ind_tc1_gfl,          ind_tc1_agfl,          &
3889                                     surf_usm_h%ground_level(m) )
3890           ind_tc2          = MERGE( ind_tc2_gfl,          ind_tc2_agfl,          &
3891                                     surf_usm_h%ground_level(m) )
3892           ind_tc3          = MERGE( ind_tc3_gfl,          ind_tc3_agfl,          &
3893                                     surf_usm_h%ground_level(m) )
3894           ind_emis_wall    = MERGE( ind_emis_wall_gfl,    ind_emis_wall_agfl,    &
3895                                     surf_usm_h%ground_level(m) )
3896           ind_emis_green   = MERGE( ind_emis_green_gfl,   ind_emis_green_agfl,   &
3897                                     surf_usm_h%ground_level(m) )
3898           ind_emis_win     = MERGE( ind_emis_win_gfl,     ind_emis_win_agfl,     &
3899                                     surf_usm_h%ground_level(m) )
3900           ind_trans        = MERGE( ind_trans_gfl,        ind_trans_agfl,        &
3901                                     surf_usm_h%ground_level(m) )
3902           ind_z0           = MERGE( ind_z0_gfl,           ind_z0_agfl,           &
3903                                     surf_usm_h%ground_level(m) )
3904           ind_z0qh         = MERGE( ind_z0qh_gfl,         ind_z0qh_agfl,         &
3905                                     surf_usm_h%ground_level(m) )
3906!
3907!--        Store building type and its name on each surface element
3908           surf_usm_h%building_type(m)      = building_type
3909           surf_usm_h%building_type_name(m) = building_type_name(building_type)
3910!
3911!--        Initialize relatvie wall- (0), green- (1) and window (2) fractions
3912           surf_usm_h%frac(ind_veg_wall,m)  = building_pars(ind_wall_frac,building_type)   
3913           surf_usm_h%frac(ind_pav_green,m) = building_pars(ind_green_frac_r,building_type) 
3914           surf_usm_h%frac(ind_wat_win,m)   = building_pars(ind_win_frac,building_type) 
3915           surf_usm_h%lai(m)                = building_pars(ind_green_frac_r,building_type) 
3916
3917           surf_usm_h%rho_c_wall(nzb_wall,m)   = building_pars(ind_hc1,building_type) 
3918           surf_usm_h%rho_c_wall(nzb_wall+1,m) = building_pars(ind_hc1,building_type)
3919           surf_usm_h%rho_c_wall(nzb_wall+2,m) = building_pars(ind_hc2,building_type)
3920           surf_usm_h%rho_c_wall(nzb_wall+3,m) = building_pars(ind_hc3,building_type)   
3921           surf_usm_h%lambda_h(nzb_wall,m)   = building_pars(ind_tc1,building_type) 
3922           surf_usm_h%lambda_h(nzb_wall+1,m) = building_pars(ind_tc1,building_type) 
3923           surf_usm_h%lambda_h(nzb_wall+2,m) = building_pars(ind_tc2,building_type)
3924           surf_usm_h%lambda_h(nzb_wall+3,m) = building_pars(ind_tc3,building_type)   
3925           surf_usm_h%rho_c_green(nzb_wall,m)   = building_pars(ind_hc1,building_type) 
3926           surf_usm_h%rho_c_green(nzb_wall+1,m) = building_pars(ind_hc1,building_type)
3927           surf_usm_h%rho_c_green(nzb_wall+2,m) = building_pars(ind_hc2,building_type)
3928           surf_usm_h%rho_c_green(nzb_wall+3,m) = building_pars(ind_hc3,building_type)   
3929           surf_usm_h%lambda_h_green(nzb_wall,m)   = building_pars(ind_tc1,building_type) 
3930           surf_usm_h%lambda_h_green(nzb_wall+1,m) = building_pars(ind_tc1,building_type) 
3931           surf_usm_h%lambda_h_green(nzb_wall+2,m) = building_pars(ind_tc2,building_type)
3932           surf_usm_h%lambda_h_green(nzb_wall+3,m) = building_pars(ind_tc3,building_type)
3933           surf_usm_h%rho_c_window(nzb_wall,m)   = building_pars(ind_hc1,building_type) 
3934           surf_usm_h%rho_c_window(nzb_wall+1,m) = building_pars(ind_hc1,building_type)
3935           surf_usm_h%rho_c_window(nzb_wall+2,m) = building_pars(ind_hc2,building_type)
3936           surf_usm_h%rho_c_window(nzb_wall+3,m) = building_pars(ind_hc3,building_type)   
3937           surf_usm_h%lambda_h_window(nzb_wall,m)   = building_pars(ind_tc1,building_type) 
3938           surf_usm_h%lambda_h_window(nzb_wall+1,m) = building_pars(ind_tc1,building_type) 
3939           surf_usm_h%lambda_h_window(nzb_wall+2,m) = building_pars(ind_tc2,building_type)
3940           surf_usm_h%lambda_h_window(nzb_wall+3,m) = building_pars(ind_tc3,building_type)   
3941
3942           surf_usm_h%target_temp_summer(m)  = building_pars(12,building_type)   
3943           surf_usm_h%target_temp_winter(m)  = building_pars(13,building_type)   
3944!
3945!--        emissivity of wall-, green- and window fraction
3946           surf_usm_h%emissivity(ind_veg_wall,m)  = building_pars(ind_emis_wall,building_type)
3947           surf_usm_h%emissivity(ind_pav_green,m) = building_pars(ind_emis_green,building_type)
3948           surf_usm_h%emissivity(ind_wat_win,m)   = building_pars(ind_emis_win,building_type)
3949
3950           surf_usm_h%transmissivity(m)      = building_pars(ind_trans,building_type)
3951
3952           surf_usm_h%z0(m)                  = building_pars(ind_z0,building_type)
3953           surf_usm_h%z0h(m)                 = building_pars(ind_z0qh,building_type)
3954           surf_usm_h%z0q(m)                 = building_pars(ind_z0qh,building_type)
3955!
3956!--        albedo type for wall fraction, green fraction, window fraction
3957           surf_usm_h%albedo_type(ind_veg_wall,m)  = INT( building_pars(ind_alb_wall,building_type)  )
3958           surf_usm_h%albedo_type(ind_pav_green,m) = INT( building_pars(ind_alb_green,building_type) )
3959           surf_usm_h%albedo_type(ind_wat_win,m)   = INT( building_pars(ind_alb_win,building_type)   )
3960
3961           surf_usm_h%zw(nzb_wall,m)         = building_pars(ind_thick_1,building_type)
3962           surf_usm_h%zw(nzb_wall+1,m)       = building_pars(ind_thick_2,building_type)
3963           surf_usm_h%zw(nzb_wall+2,m)       = building_pars(ind_thick_3,building_type)
3964           surf_usm_h%zw(nzb_wall+3,m)       = building_pars(ind_thick_4,building_type)
3965           
3966           surf_usm_h%zw_green(nzb_wall,m)         = building_pars(ind_thick_1,building_type)
3967           surf_usm_h%zw_green(nzb_wall+1,m)       = building_pars(ind_thick_2,building_type)
3968           surf_usm_h%zw_green(nzb_wall+2,m)       = building_pars(ind_thick_3,building_type)
3969           surf_usm_h%zw_green(nzb_wall+3,m)       = building_pars(ind_thick_4,building_type)
3970           
3971           surf_usm_h%zw_window(nzb_wall,m)         = building_pars(ind_thick_1,building_type)
3972           surf_usm_h%zw_window(nzb_wall+1,m)       = building_pars(ind_thick_2,building_type)
3973           surf_usm_h%zw_window(nzb_wall+2,m)       = building_pars(ind_thick_3,building_type)
3974           surf_usm_h%zw_window(nzb_wall+3,m)       = building_pars(ind_thick_4,building_type)
3975
3976           surf_usm_h%c_surface(m)           = building_pars(45,building_type) 
3977           surf_usm_h%lambda_surf(m)         = building_pars(46,building_type) 
3978           surf_usm_h%c_surface_green(m)     = building_pars(45,building_type) 
3979           surf_usm_h%lambda_surf_green(m)   = building_pars(46,building_type) 
3980           surf_usm_h%c_surface_window(m)    = building_pars(45,building_type) 
3981           surf_usm_h%lambda_surf_window(m)  = building_pars(46,building_type) 
3982
3983        ENDDO
3984
3985        DO  l = 0, 3
3986           DO  m = 1, surf_usm_v(l)%ns
3987
3988              surf_usm_v(l)%surface_types(m) = wall_category         !< default category for root surface
3989!
3990!--           In order to distinguish between ground floor level and
3991!--           above-ground-floor level surfaces, set input indices.
3992              ind_wall_frac    = MERGE( ind_wall_frac_gfl,    ind_wall_frac_agfl,    &
3993                                        surf_usm_v(l)%ground_level(m) )
3994              ind_win_frac     = MERGE( ind_win_frac_gfl,     ind_win_frac_agfl,     &
3995                                        surf_usm_v(l)%ground_level(m) )
3996              ind_green_frac_w = MERGE( ind_green_frac_w_gfl, ind_green_frac_w_agfl, &
3997                                        surf_usm_v(l)%ground_level(m) )
3998              ind_green_frac_r = MERGE( ind_green_frac_r_gfl, ind_green_frac_r_agfl, &
3999                                        surf_usm_v(l)%ground_level(m) )
4000              ind_lai_r        = MERGE( ind_lai_r_gfl,        ind_lai_r_agfl,        &
4001                                        surf_usm_v(l)%ground_level(m) )
4002              ind_lai_w        = MERGE( ind_lai_w_gfl,        ind_lai_w_agfl,        &
4003                                        surf_usm_v(l)%ground_level(m) )
4004              ind_hc1          = MERGE( ind_hc1_gfl,          ind_hc1_agfl,          &
4005                                        surf_usm_v(l)%ground_level(m) )
4006              ind_hc2          = MERGE( ind_hc2_gfl,          ind_hc2_agfl,          &
4007                                        surf_usm_v(l)%ground_level(m) )
4008              ind_hc3          = MERGE( ind_hc3_gfl,          ind_hc3_agfl,          &
4009                                        surf_usm_v(l)%ground_level(m) )
4010              ind_tc1          = MERGE( ind_tc1_gfl,          ind_tc1_agfl,          &
4011                                        surf_usm_v(l)%ground_level(m) )
4012              ind_tc2          = MERGE( ind_tc2_gfl,          ind_tc2_agfl,          &
4013                                        surf_usm_v(l)%ground_level(m) )
4014              ind_tc3          = MERGE( ind_tc3_gfl,          ind_tc3_agfl,          &
4015                                        surf_usm_v(l)%ground_level(m) )
4016              ind_emis_wall    = MERGE( ind_emis_wall_gfl,    ind_emis_wall_agfl,    &
4017                                        surf_usm_v(l)%ground_level(m) )
4018              ind_emis_green   = MERGE( ind_emis_green_gfl,   ind_emis_green_agfl,   &
4019                                        surf_usm_v(l)%ground_level(m) )
4020              ind_emis_win     = MERGE( ind_emis_win_gfl,     ind_emis_win_agfl,     &
4021                                        surf_usm_v(l)%ground_level(m) )
4022              ind_trans        = MERGE( ind_trans_gfl,       ind_trans_agfl,         &
4023                                        surf_usm_v(l)%ground_level(m) )
4024              ind_z0           = MERGE( ind_z0_gfl,           ind_z0_agfl,           &
4025                                        surf_usm_v(l)%ground_level(m) )
4026              ind_z0qh         = MERGE( ind_z0qh_gfl,         ind_z0qh_agfl,         &
4027                                        surf_usm_v(l)%ground_level(m) )
4028!
4029!--           Store building type and its name on each surface element
4030              surf_usm_v(l)%building_type(m)      = building_type
4031              surf_usm_v(l)%building_type_name(m) = building_type_name(building_type)
4032!
4033!--           Initialize relatvie wall- (0), green- (1) and window (2) fractions
4034              surf_usm_v(l)%frac(ind_veg_wall,m)   = building_pars(ind_wall_frac,building_type)   
4035              surf_usm_v(l)%frac(ind_pav_green,m)  = building_pars(ind_green_frac_w,building_type) 
4036              surf_usm_v(l)%frac(ind_wat_win,m)    = building_pars(ind_win_frac,building_type) 
4037              surf_usm_v(l)%lai(m)                 = building_pars(ind_lai_w,building_type) 
4038
4039              surf_usm_v(l)%rho_c_wall(nzb_wall,m)   = building_pars(ind_hc1,building_type) 
4040              surf_usm_v(l)%rho_c_wall(nzb_wall+1,m) = building_pars(ind_hc1,building_type)
4041              surf_usm_v(l)%rho_c_wall(nzb_wall+2,m) = building_pars(ind_hc2,building_type)
4042              surf_usm_v(l)%rho_c_wall(nzb_wall+3,m) = building_pars(ind_hc3,building_type)   
4043             
4044              surf_usm_v(l)%rho_c_green(nzb_wall,m)   = building_pars(ind_hc1,building_type) 
4045              surf_usm_v(l)%rho_c_green(nzb_wall+1,m) = building_pars(ind_hc1,building_type)
4046              surf_usm_v(l)%rho_c_green(nzb_wall+2,m) = building_pars(ind_hc2,building_type)
4047              surf_usm_v(l)%rho_c_green(nzb_wall+3,m) = building_pars(ind_hc3,building_type)   
4048             
4049              surf_usm_v(l)%rho_c_window(nzb_wall,m)   = building_pars(ind_hc1,building_type) 
4050              surf_usm_v(l)%rho_c_window(nzb_wall+1,m) = building_pars(ind_hc1,building_type)
4051              surf_usm_v(l)%rho_c_window(nzb_wall+2,m) = building_pars(ind_hc2,building_type)
4052              surf_usm_v(l)%rho_c_window(nzb_wall+3,m) = building_pars(ind_hc3,building_type)   
4053
4054              surf_usm_v(l)%lambda_h(nzb_wall,m)   = building_pars(ind_tc1,building_type) 
4055              surf_usm_v(l)%lambda_h(nzb_wall+1,m) = building_pars(ind_tc1,building_type) 
4056              surf_usm_v(l)%lambda_h(nzb_wall+2,m) = building_pars(ind_tc2,building_type)
4057              surf_usm_v(l)%lambda_h(nzb_wall+3,m) = building_pars(ind_tc3,building_type)   
4058             
4059              surf_usm_v(l)%lambda_h_green(nzb_wall,m)   = building_pars(ind_tc1,building_type) 
4060              surf_usm_v(l)%lambda_h_green(nzb_wall+1,m) = building_pars(ind_tc1,building_type) 
4061              surf_usm_v(l)%lambda_h_green(nzb_wall+2,m) = building_pars(ind_tc2,building_type)
4062              surf_usm_v(l)%lambda_h_green(nzb_wall+3,m) = building_pars(ind_tc3,building_type)   
4063
4064              surf_usm_v(l)%lambda_h_window(nzb_wall,m)   = building_pars(ind_tc1,building_type) 
4065              surf_usm_v(l)%lambda_h_window(nzb_wall+1,m) = building_pars(ind_tc1,building_type) 
4066              surf_usm_v(l)%lambda_h_window(nzb_wall+2,m) = building_pars(ind_tc2,building_type)
4067              surf_usm_v(l)%lambda_h_window(nzb_wall+3,m) = building_pars(ind_tc3,building_type)   
4068
4069              surf_usm_v(l)%target_temp_summer(m)  = building_pars(12,building_type)   
4070              surf_usm_v(l)%target_temp_winter(m)  = building_pars(13,building_type)   
4071!
4072!--           emissivity of wall-, green- and window fraction
4073              surf_usm_v(l)%emissivity(ind_veg_wall,m)  = building_pars(ind_emis_wall,building_type)
4074              surf_usm_v(l)%emissivity(ind_pav_green,m) = building_pars(ind_emis_green,building_type)
4075              surf_usm_v(l)%emissivity(ind_wat_win,m)   = building_pars(ind_emis_win,building_type)
4076
4077              surf_usm_v(l)%transmissivity(m)      = building_pars(ind_trans,building_type)
4078
4079              surf_usm_v(l)%z0(m)                  = building_pars(ind_z0,building_type)
4080              surf_usm_v(l)%z0h(m)                 = building_pars(ind_z0qh,building_type)
4081              surf_usm_v(l)%z0q(m)                 = building_pars(ind_z0qh,building_type)
4082
4083              surf_usm_v(l)%albedo_type(ind_veg_wall,m)  = INT( building_pars(ind_alb_wall,building_type) )
4084              surf_usm_v(l)%albedo_type(ind_pav_green,m) = INT( building_pars(ind_alb_green,building_type) )
4085              surf_usm_v(l)%albedo_type(ind_wat_win,m)   = INT( building_pars(ind_alb_win,building_type) )
4086
4087              surf_usm_v(l)%zw(nzb_wall,m)         = building_pars(ind_thick_1,building_type)
4088              surf_usm_v(l)%zw(nzb_wall+1,m)       = building_pars(ind_thick_2,building_type)
4089              surf_usm_v(l)%zw(nzb_wall+2,m)       = building_pars(ind_thick_3,building_type)
4090              surf_usm_v(l)%zw(nzb_wall+3,m)       = building_pars(ind_thick_4,building_type)
4091             
4092              surf_usm_v(l)%zw_green(nzb_wall,m)         = building_pars(ind_thick_1,building_type)
4093              surf_usm_v(l)%zw_green(nzb_wall+1,m)       = building_pars(ind_thick_2,building_type)
4094              surf_usm_v(l)%zw_green(nzb_wall+2,m)       = building_pars(ind_thick_3,building_type)
4095              surf_usm_v(l)%zw_green(nzb_wall+3,m)       = building_pars(ind_thick_4,building_type)
4096
4097              surf_usm_v(l)%zw_window(nzb_wall,m)         = building_pars(ind_thick_1,building_type)
4098              surf_usm_v(l)%zw_window(nzb_wall+1,m)       = building_pars(ind_thick_2,building_type)
4099              surf_usm_v(l)%zw_window(nzb_wall+2,m)       = building_pars(ind_thick_3,building_type)
4100              surf_usm_v(l)%zw_window(nzb_wall+3,m)       = building_pars(ind_thick_4,building_type)
4101
4102              surf_usm_v(l)%c_surface(m)           = building_pars(45,building_type) 
4103              surf_usm_v(l)%lambda_surf(m)         = building_pars(46,building_type)
4104              surf_usm_v(l)%c_surface_green(m)     = building_pars(45,building_type) 
4105              surf_usm_v(l)%lambda_surf_green(m)   = building_pars(46,building_type)
4106              surf_usm_v(l)%c_surface_window(m)    = building_pars(45,building_type) 
4107              surf_usm_v(l)%lambda_surf_window(m)  = building_pars(46,building_type)
4108
4109           ENDDO
4110        ENDDO
4111!
4112!--     Level 2 - initialization via building type read from file
4113        IF ( building_type_f%from_file )  THEN
4114           DO  m = 1, surf_usm_h%ns
4115              i = surf_usm_h%i(m)
4116              j = surf_usm_h%j(m)
4117!
4118!--           For the moment, limit building type to 6 (to overcome errors in input file).
4119              st = building_type_f%var(j,i)
4120              IF ( st /= building_type_f%fill )  THEN
4121
4122!
4123!--              In order to distinguish between ground floor level and
4124!--              above-ground-floor level surfaces, set input indices.
4125                 ind_wall_frac    = MERGE( ind_wall_frac_gfl,    ind_wall_frac_agfl,    &
4126                                           surf_usm_h%ground_level(m) )
4127                 ind_win_frac     = MERGE( ind_win_frac_gfl,     ind_win_frac_agfl,     &
4128                                           surf_usm_h%ground_level(m) )
4129                 ind_green_frac_w = MERGE( ind_green_frac_w_gfl, ind_green_frac_w_agfl, &
4130                                           surf_usm_h%ground_level(m) )
4131                 ind_green_frac_r = MERGE( ind_green_frac_r_gfl, ind_green_frac_r_agfl, &
4132                                           surf_usm_h%ground_level(m) )
4133                 ind_lai_r        = MERGE( ind_lai_r_gfl,        ind_lai_r_agfl,        &
4134                                           surf_usm_h%ground_level(m) )
4135                 ind_lai_w        = MERGE( ind_lai_w_gfl,        ind_lai_w_agfl,        &
4136                                           surf_usm_h%ground_level(m) )
4137                 ind_hc1          = MERGE( ind_hc1_gfl,          ind_hc1_agfl,          &
4138                                           surf_usm_h%ground_level(m) )
4139                 ind_hc2          = MERGE( ind_hc2_gfl,          ind_hc2_agfl,          &
4140                                           surf_usm_h%ground_level(m) )
4141                 ind_hc3          = MERGE( ind_hc3_gfl,          ind_hc3_agfl,          &
4142                                           surf_usm_h%ground_level(m) )
4143                 ind_tc1          = MERGE( ind_tc1_gfl,          ind_tc1_agfl,          &
4144                                           surf_usm_h%ground_level(m) )
4145                 ind_tc2          = MERGE( ind_tc2_gfl,          ind_tc2_agfl,          &
4146                                           surf_usm_h%ground_level(m) )
4147                 ind_tc3          = MERGE( ind_tc3_gfl,          ind_tc3_agfl,          &
4148                                           surf_usm_h%ground_level(m) )
4149                 ind_emis_wall    = MERGE( ind_emis_wall_gfl,    ind_emis_wall_agfl,    &
4150                                           surf_usm_h%ground_level(m) )
4151                 ind_emis_green   = MERGE( ind_emis_green_gfl,   ind_emis_green_agfl,   &
4152                                           surf_usm_h%ground_level(m) )
4153                 ind_emis_win     = MERGE( ind_emis_win_gfl,     ind_emis_win_agfl,     &
4154                                           surf_usm_h%ground_level(m) )
4155                 ind_trans        = MERGE( ind_trans_gfl,        ind_trans_agfl,        &
4156                                           surf_usm_h%ground_level(m) )
4157                 ind_z0           = MERGE( ind_z0_gfl,           ind_z0_agfl,           &
4158                                           surf_usm_h%ground_level(m) )
4159                 ind_z0qh         = MERGE( ind_z0qh_gfl,         ind_z0qh_agfl,         &
4160                                           surf_usm_h%ground_level(m) )
4161!
4162!--              Store building type and its name on each surface element
4163                 surf_usm_h%building_type(m)      = st
4164                 surf_usm_h%building_type_name(m) = building_type_name(st)
4165!
4166!--              Initialize relatvie wall- (0), green- (1) and window (2) fractions
4167                 surf_usm_h%frac(ind_veg_wall,m)  = building_pars(ind_wall_frac,st)   
4168                 surf_usm_h%frac(ind_pav_green,m) = building_pars(ind_green_frac_r,st) 
4169                 surf_usm_h%frac(ind_wat_win,m)   = building_pars(ind_win_frac,st) 
4170                 surf_usm_h%lai(m)                = building_pars(ind_green_frac_r,st) 
4171
4172                 surf_usm_h%rho_c_wall(nzb_wall,m)   = building_pars(ind_hc1,st) 
4173                 surf_usm_h%rho_c_wall(nzb_wall+1,m) = building_pars(ind_hc1,st)
4174                 surf_usm_h%rho_c_wall(nzb_wall+2,m) = building_pars(ind_hc2,st)
4175                 surf_usm_h%rho_c_wall(nzb_wall+3,m) = building_pars(ind_hc3,st)   
4176                 surf_usm_h%lambda_h(nzb_wall,m)   = building_pars(ind_tc1,st) 
4177                 surf_usm_h%lambda_h(nzb_wall+1,m) = building_pars(ind_tc1,st) 
4178                 surf_usm_h%lambda_h(nzb_wall+2,m) = building_pars(ind_tc2,st)
4179                 surf_usm_h%lambda_h(nzb_wall+3,m) = building_pars(ind_tc3,st)   
4180                 
4181                 surf_usm_h%rho_c_green(nzb_wall,m)   = building_pars(ind_hc1,st) 
4182                 surf_usm_h%rho_c_green(nzb_wall+1,m) = building_pars(ind_hc1,st)
4183                 surf_usm_h%rho_c_green(nzb_wall+2,m) = building_pars(ind_hc2,st)
4184                 surf_usm_h%rho_c_green(nzb_wall+3,m) = building_pars(ind_hc3,st)   
4185                 surf_usm_h%lambda_h_green(nzb_wall,m)   = building_pars(ind_tc1,st) 
4186                 surf_usm_h%lambda_h_green(nzb_wall+1,m) = building_pars(ind_tc1,st) 
4187                 surf_usm_h%lambda_h_green(nzb_wall+2,m) = building_pars(ind_tc2,st)
4188                 surf_usm_h%lambda_h_green(nzb_wall+3,m) = building_pars(ind_tc3,st)   
4189               
4190                 surf_usm_h%rho_c_window(nzb_wall,m)   = building_pars(ind_hc1,st) 
4191                 surf_usm_h%rho_c_window(nzb_wall+1,m) = building_pars(ind_hc1,st)
4192                 surf_usm_h%rho_c_window(nzb_wall+2,m) = building_pars(ind_hc2,st)
4193                 surf_usm_h%rho_c_window(nzb_wall+3,m) = building_pars(ind_hc3,st)   
4194                 surf_usm_h%lambda_h_window(nzb_wall,m)   = building_pars(ind_tc1,st) 
4195                 surf_usm_h%lambda_h_window(nzb_wall+1,m) = building_pars(ind_tc1,st) 
4196                 surf_usm_h%lambda_h_window(nzb_wall+2,m) = building_pars(ind_tc2,st)
4197                 surf_usm_h%lambda_h_window(nzb_wall+3,m) = building_pars(ind_tc3,st)   
4198
4199                 surf_usm_h%target_temp_summer(m)  = building_pars(12,st)   
4200                 surf_usm_h%target_temp_winter(m)  = building_pars(13,st)   
4201!
4202!--              emissivity of wall-, green- and window fraction
4203                 surf_usm_h%emissivity(ind_veg_wall,m)  = building_pars(ind_emis_wall,st)
4204                 surf_usm_h%emissivity(ind_pav_green,m) = building_pars(ind_emis_green,st)
4205                 surf_usm_h%emissivity(ind_wat_win,m)   = building_pars(ind_emis_win,st)
4206
4207                 surf_usm_h%transmissivity(m)      = building_pars(ind_trans,st)
4208
4209                 surf_usm_h%z0(m)                  = building_pars(ind_z0,st)
4210                 surf_usm_h%z0h(m)                 = building_pars(ind_z0qh,st)
4211                 surf_usm_h%z0q(m)                 = building_pars(ind_z0qh,st)
4212!
4213!--              albedo type for wall fraction, green fraction, window fraction
4214                 surf_usm_h%albedo_type(ind_veg_wall,m)  = INT( building_pars(ind_alb_wall,st) )
4215                 surf_usm_h%albedo_type(ind_pav_green,m) = INT( building_pars(ind_alb_green,st) )
4216                 surf_usm_h%albedo_type(ind_wat_win,m)   = INT( building_pars(ind_alb_win,st) )
4217
4218                 surf_usm_h%zw(nzb_wall,m)         = building_pars(ind_thick_1,st)
4219                 surf_usm_h%zw(nzb_wall+1,m)       = building_pars(ind_thick_2,st)
4220                 surf_usm_h%zw(nzb_wall+2,m)       = building_pars(ind_thick_3,st)
4221                 surf_usm_h%zw(nzb_wall+3,m)       = building_pars(ind_thick_4,st)
4222                 
4223                 surf_usm_h%zw_green(nzb_wall,m)         = building_pars(ind_thick_1,st)
4224                 surf_usm_h%zw_green(nzb_wall+1,m)       = building_pars(ind_thick_2,st)
4225                 surf_usm_h%zw_green(nzb_wall+2,m)       = building_pars(ind_thick_3,st)
4226                 surf_usm_h%zw_green(nzb_wall+3,m)       = building_pars(ind_thick_4,st)
4227
4228                 surf_usm_h%zw_window(nzb_wall,m)         = building_pars(ind_thick_1,st)
4229                 surf_usm_h%zw_window(nzb_wall+1,m)       = building_pars(ind_thick_2,st)
4230                 surf_usm_h%zw_window(nzb_wall+2,m)       = building_pars(ind_thick_3,st)
4231                 surf_usm_h%zw_window(nzb_wall+3,m)       = building_pars(ind_thick_4,st)
4232
4233                 surf_usm_h%c_surface(m)           = building_pars(45,st) 
4234                 surf_usm_h%lambda_surf(m)         = building_pars(46,st)
4235                 surf_usm_h%c_surface_green(m)     = building_pars(45,st) 
4236                 surf_usm_h%lambda_surf_green(m)   = building_pars(46,st)
4237                 surf_usm_h%c_surface_window(m)    = building_pars(45,st) 
4238                 surf_usm_h%lambda_surf_window(m)  = building_pars(46,st)
4239
4240              ENDIF
4241           ENDDO
4242
4243           DO  l = 0, 3
4244              DO  m = 1, surf_usm_v(l)%ns
4245                 i = surf_usm_v(l)%i(m) + surf_usm_v(l)%ioff
4246                 j = surf_usm_v(l)%j(m) + surf_usm_v(l)%joff
4247!
4248!--              For the moment, limit building type to 6 (to overcome errors in input file).
4249
4250                 st = building_type_f%var(j,i)
4251                 IF ( st /= building_type_f%fill )  THEN
4252
4253!
4254!--                 In order to distinguish between ground floor level and
4255!--                 above-ground-floor level surfaces, set input indices.
4256                    ind_wall_frac    = MERGE( ind_wall_frac_gfl,    ind_wall_frac_agfl,    &
4257                                              surf_usm_v(l)%ground_level(m) )
4258                    ind_win_frac     = MERGE( ind_win_frac_gfl,     ind_win_frac_agfl,     &
4259                                              surf_usm_v(l)%ground_level(m) )
4260                    ind_green_frac_w = MERGE( ind_green_frac_w_gfl, ind_green_frac_w_agfl, &
4261                                              surf_usm_v(l)%ground_level(m) )
4262                    ind_green_frac_r = MERGE( ind_green_frac_r_gfl, ind_green_frac_r_agfl, &
4263                                              surf_usm_v(l)%ground_level(m) )
4264                    ind_lai_r        = MERGE( ind_lai_r_gfl,        ind_lai_r_agfl,        &
4265                                              surf_usm_v(l)%ground_level(m) )
4266                    ind_lai_w        = MERGE( ind_lai_w_gfl,        ind_lai_w_agfl,        &
4267                                              surf_usm_v(l)%ground_level(m) )
4268                    ind_hc1          = MERGE( ind_hc1_gfl,          ind_hc1_agfl,          &
4269                                              surf_usm_v(l)%ground_level(m) )
4270                    ind_hc2          = MERGE( ind_hc2_gfl,          ind_hc2_agfl,          &
4271                                              surf_usm_v(l)%ground_level(m) )
4272                    ind_hc3          = MERGE( ind_hc3_gfl,          ind_hc3_agfl,          &
4273                                              surf_usm_v(l)%ground_level(m) )
4274                    ind_tc1          = MERGE( ind_tc1_gfl,          ind_tc1_agfl,          &
4275                                              surf_usm_v(l)%ground_level(m) )
4276                    ind_tc2          = MERGE( ind_tc2_gfl,          ind_tc2_agfl,          &
4277                                              surf_usm_v(l)%ground_level(m) )
4278                    ind_tc3          = MERGE( ind_tc3_gfl,          ind_tc3_agfl,          &
4279                                              surf_usm_v(l)%ground_level(m) )
4280                    ind_emis_wall    = MERGE( ind_emis_wall_gfl,    ind_emis_wall_agfl,    &
4281                                              surf_usm_v(l)%ground_level(m) )
4282                    ind_emis_green   = MERGE( ind_emis_green_gfl,   ind_emis_green_agfl,   &
4283                                              surf_usm_v(l)%ground_level(m) )
4284                    ind_emis_win     = MERGE( ind_emis_win_gfl,     ind_emis_win_agfl,     &
4285                                              surf_usm_v(l)%ground_level(m) )
4286                    ind_trans        = MERGE( ind_trans_gfl,       ind_trans_agfl,         &
4287                                        surf_usm_v(l)%ground_level(m) )
4288                    ind_z0           = MERGE( ind_z0_gfl,           ind_z0_agfl,           &
4289                                              surf_usm_v(l)%ground_level(m) )
4290                    ind_z0qh         = MERGE( ind_z0qh_gfl,         ind_z0qh_agfl,         &
4291                                              surf_usm_v(l)%ground_level(m) )
4292!
4293!--                 Store building type and its name on each surface element
4294                    surf_usm_v(l)%building_type(m)      = st
4295                    surf_usm_v(l)%building_type_name(m) = building_type_name(st)
4296!
4297!--                 Initialize relatvie wall- (0), green- (1) and window (2) fractions
4298                    surf_usm_v(l)%frac(ind_veg_wall,m)  = building_pars(ind_wall_frac,st)   
4299                    surf_usm_v(l)%frac(ind_pav_green,m) = building_pars(ind_green_frac_w,st) 
4300                    surf_usm_v(l)%frac(ind_wat_win,m)   = building_pars(ind_win_frac,st)   
4301                    surf_usm_v(l)%lai(m)                = building_pars(ind_lai_w,st) 
4302
4303                    surf_usm_v(l)%rho_c_wall(nzb_wall,m)   = building_pars(ind_hc1,st) 
4304                    surf_usm_v(l)%rho_c_wall(nzb_wall+1,m) = building_pars(ind_hc1,st)
4305                    surf_usm_v(l)%rho_c_wall(nzb_wall+2,m) = building_pars(ind_hc2,st)
4306                    surf_usm_v(l)%rho_c_wall(nzb_wall+3,m) = building_pars(ind_hc3,st)
4307                   
4308                    surf_usm_v(l)%rho_c_green(nzb_wall,m)   = building_pars(ind_hc1,st) 
4309                    surf_usm_v(l)%rho_c_green(nzb_wall+1,m) = building_pars(ind_hc1,st)
4310                    surf_usm_v(l)%rho_c_green(nzb_wall+2,m) = building_pars(ind_hc2,st)
4311                    surf_usm_v(l)%rho_c_green(nzb_wall+3,m) = building_pars(ind_hc3,st)
4312                   
4313                    surf_usm_v(l)%rho_c_window(nzb_wall,m)   = building_pars(ind_hc1,st) 
4314                    surf_usm_v(l)%rho_c_window(nzb_wall+1,m) = building_pars(ind_hc1,st)
4315                    surf_usm_v(l)%rho_c_window(nzb_wall+2,m) = building_pars(ind_hc2,st)
4316                    surf_usm_v(l)%rho_c_window(nzb_wall+3,m) = building_pars(ind_hc3,st)
4317
4318                    surf_usm_v(l)%lambda_h(nzb_wall,m)   = building_pars(ind_tc1,st) 
4319                    surf_usm_v(l)%lambda_h(nzb_wall+1,m) = building_pars(ind_tc1,st) 
4320                    surf_usm_v(l)%lambda_h(nzb_wall+2,m) = building_pars(ind_tc2,st)
4321                    surf_usm_v(l)%lambda_h(nzb_wall+3,m) = building_pars(ind_tc3,st) 
4322                   
4323                    surf_usm_v(l)%lambda_h_green(nzb_wall,m)   = building_pars(ind_tc1,st) 
4324                    surf_usm_v(l)%lambda_h_green(nzb_wall+1,m) = building_pars(ind_tc1,st) 
4325                    surf_usm_v(l)%lambda_h_green(nzb_wall+2,m) = building_pars(ind_tc2,st)
4326                    surf_usm_v(l)%lambda_h_green(nzb_wall+3,m) = building_pars(ind_tc3,st) 
4327                   
4328                    surf_usm_v(l)%lambda_h_window(nzb_wall,m)   = building_pars(ind_tc1,st) 
4329                    surf_usm_v(l)%lambda_h_window(nzb_wall+1,m) = building_pars(ind_tc1,st) 
4330                    surf_usm_v(l)%lambda_h_window(nzb_wall+2,m) = building_pars(ind_tc2,st)
4331                    surf_usm_v(l)%lambda_h_window(nzb_wall+3,m) = building_pars(ind_tc3,st) 
4332
4333                    surf_usm_v(l)%target_temp_summer(m)  = building_pars(12,st)   
4334                    surf_usm_v(l)%target_temp_winter(m)  = building_pars(13,st)   
4335!
4336!--                 emissivity of wall-, green- and window fraction
4337                    surf_usm_v(l)%emissivity(ind_veg_wall,m)  = building_pars(ind_emis_wall,st)
4338                    surf_usm_v(l)%emissivity(ind_pav_green,m) = building_pars(ind_emis_green,st)
4339                    surf_usm_v(l)%emissivity(ind_wat_win,m)   = building_pars(ind_emis_win,st)
4340
4341                    surf_usm_v(l)%transmissivity(m)      = building_pars(ind_trans,st)
4342
4343                    surf_usm_v(l)%z0(m)                  = building_pars(ind_z0,st)
4344                    surf_usm_v(l)%z0h(m)                 = building_pars(ind_z0qh,st)
4345                    surf_usm_v(l)%z0q(m)                 = building_pars(ind_z0qh,st)
4346
4347                    surf_usm_v(l)%albedo_type(ind_veg_wall,m)  = INT( building_pars(ind_alb_wall,st) )
4348                    surf_usm_v(l)%albedo_type(ind_pav_green,m) = INT( building_pars(ind_alb_green,st) )
4349                    surf_usm_v(l)%albedo_type(ind_wat_win,m)   = INT( building_pars(ind_alb_win,st) )
4350
4351                    surf_usm_v(l)%zw(nzb_wall,m)         = building_pars(ind_thick_1,st)
4352                    surf_usm_v(l)%zw(nzb_wall+1,m)       = building_pars(ind_thick_2,st)
4353                    surf_usm_v(l)%zw(nzb_wall+2,m)       = building_pars(ind_thick_3,st)
4354                    surf_usm_v(l)%zw(nzb_wall+3,m)       = building_pars(ind_thick_4,st)
4355                   
4356                    surf_usm_v(l)%zw_green(nzb_wall,m)         = building_pars(ind_thick_1,st)
4357                    surf_usm_v(l)%zw_green(nzb_wall+1,m)       = building_pars(ind_thick_2,st)
4358                    surf_usm_v(l)%zw_green(nzb_wall+2,m)       = building_pars(ind_thick_3,st)
4359                    surf_usm_v(l)%zw_green(nzb_wall+3,m)       = building_pars(ind_thick_4,st)
4360                   
4361                    surf_usm_v(l)%zw_window(nzb_wall,m)         = building_pars(ind_thick_1,st)
4362                    surf_usm_v(l)%zw_window(nzb_wall+1,m)       = building_pars(ind_thick_2,st)
4363                    surf_usm_v(l)%zw_window(nzb_wall+2,m)       = building_pars(ind_thick_3,st)
4364                    surf_usm_v(l)%zw_window(nzb_wall+3,m)       = building_pars(ind_thick_4,st)
4365
4366                    surf_usm_v(l)%c_surface(m)           = building_pars(45,st) 
4367                    surf_usm_v(l)%lambda_surf(m)         = building_pars(46,st) 
4368                    surf_usm_v(l)%c_surface_green(m)     = building_pars(45,st) 
4369                    surf_usm_v(l)%lambda_surf_green(m)   = building_pars(46,st) 
4370                    surf_usm_v(l)%c_surface_window(m)    = building_pars(45,st) 
4371                    surf_usm_v(l)%lambda_surf_window(m)  = building_pars(46,st) 
4372
4373
4374                 ENDIF
4375              ENDDO
4376           ENDDO
4377        ENDIF 
4378       
4379!
4380!--     Level 3 - initialization via building_pars read from file
4381        IF ( building_pars_f%from_file )  THEN
4382           DO  m = 1, surf_usm_h%ns
4383              i = surf_usm_h%i(m)
4384              j = surf_usm_h%j(m)
4385
4386!
4387!--           In order to distinguish between ground floor level and
4388!--           above-ground-floor level surfaces, set input indices.
4389              ind_wall_frac    = MERGE( ind_wall_frac_gfl,    ind_wall_frac_agfl,    &
4390                                        surf_usm_h%ground_level(m) )
4391              ind_win_frac     = MERGE( ind_win_frac_gfl,     ind_win_frac_agfl,     &
4392                                        surf_usm_h%ground_level(m) )
4393              ind_green_frac_w = MERGE( ind_green_frac_w_gfl, ind_green_frac_w_agfl, &
4394                                        surf_usm_h%ground_level(m) )
4395              ind_green_frac_r = MERGE( ind_green_frac_r_gfl, ind_green_frac_r_agfl, &
4396                                        surf_usm_h%ground_level(m) )
4397              ind_lai_r        = MERGE( ind_lai_r_gfl,        ind_lai_r_agfl,        &
4398                                        surf_usm_h%ground_level(m) )
4399              ind_lai_w        = MERGE( ind_lai_w_gfl,        ind_lai_w_agfl,        &
4400                                        surf_usm_h%ground_level(m) )
4401              ind_hc1          = MERGE( ind_hc1_gfl,          ind_hc1_agfl,          &
4402                                        surf_usm_h%ground_level(m) )
4403              ind_hc2          = MERGE( ind_hc2_gfl,          ind_hc2_agfl,          &
4404                                        surf_usm_h%ground_level(m) )
4405              ind_hc3          = MERGE( ind_hc3_gfl,          ind_hc3_agfl,          &
4406                                        surf_usm_h%ground_level(m) )
4407              ind_tc1          = MERGE( ind_tc1_gfl,          ind_tc1_agfl,          &
4408                                        surf_usm_h%ground_level(m) )
4409              ind_tc2          = MERGE( ind_tc2_gfl,          ind_tc2_agfl,          &
4410                                        surf_usm_h%ground_level(m) )
4411              ind_tc3          = MERGE( ind_tc3_gfl,          ind_tc3_agfl,          &
4412                                        surf_usm_h%ground_level(m) )
4413              ind_emis_wall    = MERGE( ind_emis_wall_gfl,    ind_emis_wall_agfl,    &
4414                                        surf_usm_h%ground_level(m) )
4415              ind_emis_green   = MERGE( ind_emis_green_gfl,   ind_emis_green_agfl,   &
4416                                        surf_usm_h%ground_level(m) )
4417              ind_emis_win     = MERGE( ind_emis_win_gfl,     ind_emis_win_agfl,     &
4418                                        surf_usm_h%ground_level(m) )
4419              ind_trans        = MERGE( ind_trans_gfl,        ind_trans_agfl,        &
4420                                        surf_usm_h%ground_level(m) )
4421              ind_z0           = MERGE( ind_z0_gfl,           ind_z0_agfl,           &
4422                                        surf_usm_h%ground_level(m) )
4423              ind_z0qh         = MERGE( ind_z0qh_gfl,         ind_z0qh_agfl,         &
4424                                        surf_usm_h%ground_level(m) )
4425
4426!
4427!--           Initialize relatvie wall- (0), green- (1) and window (2) fractions
4428              IF ( building_pars_f%pars_xy(ind_wall_frac,j,i) /= building_pars_f%fill )    &
4429                 surf_usm_h%frac(ind_veg_wall,m)  = building_pars_f%pars_xy(ind_wall_frac,j,i)   
4430              IF ( building_pars_f%pars_xy(ind_green_frac_r,j,i) /= building_pars_f%fill ) & 
4431                 surf_usm_h%frac(ind_pav_green,m) = building_pars_f%pars_xy(ind_green_frac_r,j,i) 
4432              IF ( building_pars_f%pars_xy(ind_win_frac,j,i) /= building_pars_f%fill )     & 
4433                 surf_usm_h%frac(ind_wat_win,m)   = building_pars_f%pars_xy(ind_win_frac,j,i)
4434
4435 
4436              IF ( building_pars_f%pars_xy(ind_lai_r,j,i) /= building_pars_f%fill )        &
4437                 surf_usm_h%lai(m)             = building_pars_f%pars_xy(ind_lai_r,j,i)
4438
4439              IF ( building_pars_f%pars_xy(ind_hc1,j,i) /= building_pars_f%fill )  THEN
4440                 surf_usm_h%rho_c_wall(nzb_wall,m)   = building_pars_f%pars_xy(ind_hc1,j,i) 
4441                 surf_usm_h%rho_c_wall(nzb_wall+1,m) = building_pars_f%pars_xy(ind_hc1,j,i)
4442              ENDIF
4443              IF ( building_pars_f%pars_xy(ind_hc2,j,i) /= building_pars_f%fill )    &
4444                 surf_usm_h%rho_c_wall(nzb_wall+2,m) = building_pars_f%pars_xy(ind_hc2,j,i)
4445              IF ( building_pars_f%pars_xy(ind_hc3,j,i) /= building_pars_f%fill )    & 
4446                 surf_usm_h%rho_c_wall(nzb_wall+3,m) = building_pars_f%pars_xy(ind_hc3,j,i)
4447              IF ( building_pars_f%pars_xy(ind_hc1,j,i) /= building_pars_f%fill )  THEN
4448                 surf_usm_h%rho_c_green(nzb_wall,m)   = building_pars_f%pars_xy(ind_hc1,j,i) 
4449                 surf_usm_h%rho_c_green(nzb_wall+1,m) = building_pars_f%pars_xy(ind_hc1,j,i)
4450              ENDIF
4451              IF ( building_pars_f%pars_xy(ind_hc2,j,i) /= building_pars_f%fill )    &
4452                 surf_usm_h%rho_c_green(nzb_wall+2,m) = building_pars_f%pars_xy(ind_hc2,j,i)
4453              IF ( building_pars_f%pars_xy(ind_hc3,j,i) /= building_pars_f%fill )    & 
4454                 surf_usm_h%rho_c_green(nzb_wall+3,m) = building_pars_f%pars_xy(ind_hc3,j,i)
4455              IF ( building_pars_f%pars_xy(ind_hc1,j,i) /= building_pars_f%fill )  THEN
4456                 surf_usm_h%rho_c_window(nzb_wall,m)   = building_pars_f%pars_xy(ind_hc1,j,i) 
4457                 surf_usm_h%rho_c_window(nzb_wall+1,m) = building_pars_f%pars_xy(ind_hc1,j,i)
4458              ENDIF
4459              IF ( building_pars_f%pars_xy(ind_hc2,j,i) /= building_pars_f%fill )    &
4460                 surf_usm_h%rho_c_window(nzb_wall+2,m) = building_pars_f%pars_xy(ind_hc2,j,i)
4461              IF ( building_pars_f%pars_xy(ind_hc3,j,i) /= building_pars_f%fill )    & 
4462                 surf_usm_h%rho_c_window(nzb_wall+3,m) = building_pars_f%pars_xy(ind_hc3,j,i)
4463
4464              IF ( building_pars_f%pars_xy(ind_tc1,j,i) /= building_pars_f%fill )  THEN
4465                 surf_usm_h%lambda_h(nzb_wall,m)   = building_pars_f%pars_xy(ind_tc1,j,i)         
4466                 surf_usm_h%lambda_h(nzb_wall+1,m) = building_pars_f%pars_xy(ind_tc1,j,i)       
4467              ENDIF
4468              IF ( building_pars_f%pars_xy(ind_tc2,j,i) /= building_pars_f%fill )    &
4469                 surf_usm_h%lambda_h(nzb_wall+2,m) = building_pars_f%pars_xy(ind_tc2,j,i)
4470              IF ( building_pars_f%pars_xy(ind_tc3,j,i) /= building_pars_f%fill )    & 
4471                 surf_usm_h%lambda_h(nzb_wall+3,m) = building_pars_f%pars_xy(ind_tc3,j,i)   
4472              IF ( building_pars_f%pars_xy(ind_tc1,j,i) /= building_pars_f%fill )  THEN
4473                 surf_usm_h%lambda_h_green(nzb_wall,m)   = building_pars_f%pars_xy(ind_tc1,j,i)         
4474                 surf_usm_h%lambda_h_green(nzb_wall+1,m) = building_pars_f%pars_xy(ind_tc1,j,i)       
4475              ENDIF
4476              IF ( building_pars_f%pars_xy(ind_tc2,j,i) /= building_pars_f%fill )    &
4477                 surf_usm_h%lambda_h_green(nzb_wall+2,m) = building_pars_f%pars_xy(ind_tc2,j,i)
4478              IF ( building_pars_f%pars_xy(ind_tc3,j,i) /= building_pars_f%fill )    & 
4479                 surf_usm_h%lambda_h_green(nzb_wall+3,m) = building_pars_f%pars_xy(ind_tc3,j,i)   
4480              IF ( building_pars_f%pars_xy(ind_tc1,j,i) /= building_pars_f%fill )  THEN
4481                 surf_usm_h%lambda_h_window(nzb_wall,m)   = building_pars_f%pars_xy(ind_tc1,j,i)         
4482                 surf_usm_h%lambda_h_window(nzb_wall+1,m) = building_pars_f%pars_xy(ind_tc1,j,i)       
4483              ENDIF
4484              IF ( building_pars_f%pars_xy(ind_tc2,j,i) /= building_pars_f%fill )    &
4485                 surf_usm_h%lambda_h_window(nzb_wall+2,m) = building_pars_f%pars_xy(ind_tc2,j,i)
4486              IF ( building_pars_f%pars_xy(ind_tc3,j,i) /= building_pars_f%fill )    & 
4487                 surf_usm_h%lambda_h_window(nzb_wall+3,m) = building_pars_f%pars_xy(ind_tc3,j,i)   
4488
4489              IF ( building_pars_f%pars_xy(12,j,i) /= building_pars_f%fill )         & 
4490                 surf_usm_h%target_temp_summer(m)  = building_pars_f%pars_xy(12,j,i)   
4491              IF ( building_pars_f%pars_xy(13,j,i) /= building_pars_f%fill )         & 
4492                 surf_usm_h%target_temp_winter(m)  = building_pars_f%pars_xy(13,j,i)   
4493
4494              IF ( building_pars_f%pars_xy(ind_emis_wall,j,i) /= building_pars_f%fill ) & 
4495                 surf_usm_h%emissivity(ind_veg_wall,m)  = building_pars_f%pars_xy(ind_emis_wall,j,i)
4496              IF ( building_pars_f%pars_xy(ind_emis_green,j,i) /= building_pars_f%fill )& 
4497                 surf_usm_h%emissivity(ind_pav_green,m) = building_pars_f%pars_xy(ind_emis_green,j,i)
4498              IF ( building_pars_f%pars_xy(ind_emis_win,j,i) /= building_pars_f%fill )  & 
4499                 surf_usm_h%emissivity(ind_wat_win,m)   = building_pars_f%pars_xy(ind_emis_win,j,i)
4500
4501              IF ( building_pars_f%pars_xy(ind_trans,j,i) /= building_pars_f%fill )    & 
4502                 surf_usm_h%transmissivity(m)      = building_pars_f%pars_xy(ind_trans,j,i)
4503
4504              IF ( building_pars_f%pars_xy(ind_z0,j,i) /= building_pars_f%fill )    & 
4505                 surf_usm_h%z0(m)                  = building_pars_f%pars_xy(ind_z0,j,i)
4506              IF ( building_pars_f%pars_xy(ind_z0qh,j,i) /= building_pars_f%fill )  & 
4507                 surf_usm_h%z0h(m)                 = building_pars_f%pars_xy(ind_z0qh,j,i)
4508              IF ( building_pars_f%pars_xy(ind_z0qh,j,i) /= building_pars_f%fill )  & 
4509                 surf_usm_h%z0q(m)                 = building_pars_f%pars_xy(ind_z0qh,j,i)
4510
4511              IF ( building_pars_f%pars_xy(ind_alb_wall,j,i) /= building_pars_f%fill )    & 
4512                 surf_usm_h%albedo_type(ind_veg_wall,m)  = building_pars_f%pars_xy(ind_alb_wall,j,i)
4513              IF ( building_pars_f%pars_xy(ind_alb_green,j,i) /= building_pars_f%fill )    & 
4514                 surf_usm_h%albedo_type(ind_pav_green,m) = building_pars_f%pars_xy(ind_alb_green,j,i)
4515              IF ( building_pars_f%pars_xy(ind_alb_win,j,i) /= building_pars_f%fill )    & 
4516                 surf_usm_h%albedo_type(ind_wat_win,m)   = building_pars_f%pars_xy(ind_alb_win,j,i)
4517
4518              IF ( building_pars_f%pars_xy(ind_thick_1,j,i) /= building_pars_f%fill )    & 
4519                 surf_usm_h%zw(nzb_wall,m) = building_pars_f%pars_xy(ind_thick_1,j,i)
4520              IF ( building_pars_f%pars_xy(ind_thick_2,j,i) /= building_pars_f%fill )    & 
4521                 surf_usm_h%zw(nzb_wall+1,m) = building_pars_f%pars_xy(ind_thick_2,j,i)
4522              IF ( building_pars_f%pars_xy(ind_thick_3,j,i) /= building_pars_f%fill )    & 
4523                 surf_usm_h%zw(nzb_wall+2,m) = building_pars_f%pars_xy(ind_thick_3,j,i)
4524              IF ( building_pars_f%pars_xy(ind_thick_4,j,i) /= building_pars_f%fill )    & 
4525                 surf_usm_h%zw(nzb_wall+3,m) = building_pars_f%pars_xy(ind_thick_4,j,i)
4526              IF ( building_pars_f%pars_xy(ind_thick_1,j,i) /= building_pars_f%fill )    & 
4527                 surf_usm_h%zw_green(nzb_wall,m) = building_pars_f%pars_xy(ind_thick_1,j,i)
4528              IF ( building_pars_f%pars_xy(ind_thick_2,j,i) /= building_pars_f%fill )    & 
4529                 surf_usm_h%zw_green(nzb_wall+1,m) = building_pars_f%pars_xy(ind_thick_2,j,i)
4530              IF ( building_pars_f%pars_xy(ind_thick_3,j,i) /= building_pars_f%fill )    & 
4531                 surf_usm_h%zw_green(nzb_wall+2,m) = building_pars_f%pars_xy(ind_thick_3,j,i)
4532              IF ( building_pars_f%pars_xy(ind_thick_4,j,i) /= building_pars_f%fill )    & 
4533                 surf_usm_h%zw_green(nzb_wall+3,m) = building_pars_f%pars_xy(ind_thick_4,j,i)
4534              IF ( building_pars_f%pars_xy(ind_thick_1,j,i) /= building_pars_f%fill )    & 
4535                 surf_usm_h%zw_window(nzb_wall,m) = building_pars_f%pars_xy(ind_thick_1,j,i)
4536              IF ( building_pars_f%pars_xy(ind_thick_2,j,i) /= building_pars_f%fill )    & 
4537                 surf_usm_h%zw_window(nzb_wall+1,m) = building_pars_f%pars_xy(ind_thick_2,j,i)
4538              IF ( building_pars_f%pars_xy(ind_thick_3,j,i) /= building_pars_f%fill )    & 
4539                 surf_usm_h%zw_window(nzb_wall+2,m) = building_pars_f%pars_xy(ind_thick_3,j,i)
4540              IF ( building_pars_f%pars_xy(ind_thick_4,j,i) /= building_pars_f%fill )    & 
4541                 surf_usm_h%zw_window(nzb_wall+3,m) = building_pars_f%pars_xy(ind_thick_4,j,i)
4542
4543              IF ( building_pars_f%pars_xy(45,j,i) /= building_pars_f%fill )    & 
4544                 surf_usm_h%c_surface(m)           = building_pars_f%pars_xy(45,j,i)
4545              IF ( building_pars_f%pars_xy(46,j,i) /= building_pars_f%fill )    & 
4546                 surf_usm_h%lambda_surf(m)         = building_pars_f%pars_xy(46,j,i)
4547              IF ( building_pars_f%pars_xy(45,j,i) /= building_pars_f%fill )    & 
4548                 surf_usm_h%c_surface_green(m)           = building_pars_f%pars_xy(45,j,i)
4549              IF ( building_pars_f%pars_xy(46,j,i) /= building_pars_f%fill )    & 
4550                 surf_usm_h%lambda_surf_green(m)         = building_pars_f%pars_xy(46,j,i)
4551              IF ( building_pars_f%pars_xy(45,j,i) /= building_pars_f%fill )    & 
4552                 surf_usm_h%c_surface_window(m)           = building_pars_f%pars_xy(45,j,i)
4553              IF ( building_pars_f%pars_xy(46,j,i) /= building_pars_f%fill )    & 
4554                 surf_usm_h%lambda_surf_window(m)         = building_pars_f%pars_xy(46,j,i)
4555           ENDDO
4556
4557
4558
4559           DO  l = 0, 3
4560              DO  m = 1, surf_usm_v(l)%ns
4561                 i = surf_usm_v(l)%i(m) + surf_usm_v(l)%ioff
4562                 j = surf_usm_v(l)%j(m) + surf_usm_v(l)%joff
4563               
4564!
4565!--              In order to distinguish between ground floor level and
4566!--              above-ground-floor level surfaces, set input indices.
4567                 ind_wall_frac    = MERGE( ind_wall_frac_gfl,    ind_wall_frac_agfl,     &
4568                                           surf_usm_v(l)%ground_level(m) )
4569                 ind_win_frac     = MERGE( ind_win_frac_gfl,     ind_win_frac_agfl,     &
4570                                           surf_usm_v(l)%ground_level(m) )
4571                 ind_green_frac_w = MERGE( ind_green_frac_w_gfl, ind_green_frac_w_agfl, &
4572                                           surf_usm_v(l)%ground_level(m) )
4573                 ind_green_frac_r = MERGE( ind_green_frac_r_gfl, ind_green_frac_r_agfl, &
4574                                           surf_usm_v(l)%ground_level(m) )
4575                 ind_lai_r        = MERGE( ind_lai_r_gfl,        ind_lai_r_agfl,        &
4576                                           surf_usm_v(l)%ground_level(m) )
4577                 ind_lai_w        = MERGE( ind_lai_w_gfl,        ind_lai_w_agfl,        &
4578                                           surf_usm_v(l)%ground_level(m) )
4579                 ind_hc1          = MERGE( ind_hc1_gfl,          ind_hc1_agfl,          &
4580                                           surf_usm_v(l)%ground_level(m) )
4581                 ind_hc2          = MERGE( ind_hc2_gfl,          ind_hc2_agfl,          &
4582                                           surf_usm_v(l)%ground_level(m) )
4583                 ind_hc3          = MERGE( ind_hc3_gfl,          ind_hc3_agfl,          &
4584                                           surf_usm_v(l)%ground_level(m) )
4585                 ind_tc1          = MERGE( ind_tc1_gfl,          ind_tc1_agfl,          &
4586                                           surf_usm_v(l)%ground_level(m) )
4587                 ind_tc2          = MERGE( ind_tc2_gfl,          ind_tc2_agfl,          &
4588                                           surf_usm_v(l)%ground_level(m) )
4589                 ind_tc3          = MERGE( ind_tc3_gfl,          ind_tc3_agfl,          &
4590                                           surf_usm_v(l)%ground_level(m) )
4591                 ind_emis_wall    = MERGE( ind_emis_wall_gfl,    ind_emis_wall_agfl,    &
4592                                           surf_usm_v(l)%ground_level(m) )
4593                 ind_emis_green   = MERGE( ind_emis_green_gfl,   ind_emis_green_agfl,   &
4594                                           surf_usm_v(l)%ground_level(m) )
4595                 ind_emis_win     = MERGE( ind_emis_win_gfl,     ind_emis_win_agfl,     &
4596                                           surf_usm_v(l)%ground_level(m) )
4597                 ind_trans        = MERGE( ind_trans_gfl,       ind_trans_agfl,         &
4598                                           surf_usm_v(l)%ground_level(m) )
4599                 ind_z0           = MERGE( ind_z0_gfl,           ind_z0_agfl,           &
4600                                           surf_usm_v(l)%ground_level(m) )
4601                 ind_z0qh         = MERGE( ind_z0qh_gfl,         ind_z0qh_agfl,         &
4602                                              surf_usm_v(l)%ground_level(m) )
4603
4604!
4605!--              Initialize relatvie wall- (0), green- (1) and window (2) fractions
4606                 IF ( building_pars_f%pars_xy(ind_wall_frac,j,i) /=                     &
4607                      building_pars_f%fill )                                            &
4608                    surf_usm_v(l)%frac(ind_veg_wall,m)  =                               &
4609                                      building_pars_f%pars_xy(ind_wall_frac,j,i)   
4610                 IF ( building_pars_f%pars_xy(ind_green_frac_w,j,i) /=                  &
4611                      building_pars_f%fill )                                            & 
4612                    surf_usm_v(l)%frac(ind_pav_green,m) =                               &
4613                                      building_pars_f%pars_xy(ind_green_frac_w,j,i) 
4614                 IF ( building_pars_f%pars_xy(ind_win_frac,j,i) /=                      &
4615                      building_pars_f%fill )                                            & 
4616                    surf_usm_v(l)%frac(ind_wat_win,m)   =                               &
4617                                      building_pars_f%pars_xy(ind_win_frac,j,i)
4618 
4619                 IF ( building_pars_f%pars_xy(ind_lai_w,j,i) /= building_pars_f%fill )  & 
4620                    surf_usm_v(l)%lai(m) = building_pars_f%pars_xy(ind_lai_w,j,i)
4621
4622                 IF ( building_pars_f%pars_xy(ind_hc1,j,i) /= building_pars_f%fill )    &
4623                 THEN
4624                    surf_usm_v(l)%rho_c_wall(nzb_wall,m)   =                            &
4625                                                    building_pars_f%pars_xy(ind_hc1,j,i) 
4626                    surf_usm_v(l)%rho_c_wall(nzb_wall+1,m) =                            &
4627                                                    building_pars_f%pars_xy(ind_hc1,j,i)
4628                 ENDIF
4629                 IF ( building_pars_f%pars_xy(ind_hc2,j,i) /= building_pars_f%fill )    &
4630                    surf_usm_v(l)%rho_c_wall(nzb_wall+2,m) =                            &                           
4631                                                    building_pars_f%pars_xy(ind_hc2,j,i)
4632                 IF ( building_pars_f%pars_xy(ind_hc3,j,i) /= building_pars_f%fill )    & 
4633                    surf_usm_v(l)%rho_c_wall(nzb_wall+3,m) =                            &
4634                                                    building_pars_f%pars_xy(ind_hc3,j,i)
4635                 IF ( building_pars_f%pars_xy(ind_hc1,j,i) /= building_pars_f%fill )  THEN
4636                    surf_usm_v(l)%rho_c_green(nzb_wall,m)   =                           &
4637                                                    building_pars_f%pars_xy(ind_hc1,j,i) 
4638                    surf_usm_v(l)%rho_c_green(nzb_wall+1,m) =                           &
4639                                                    building_pars_f%pars_xy(ind_hc1,j,i)
4640                 ENDIF
4641                 IF ( building_pars_f%pars_xy(ind_hc2,j,i) /= building_pars_f%fill )    &
4642                    surf_usm_v(l)%rho_c_green(nzb_wall+2,m) = building_pars_f%pars_xy(ind_hc2,j,i)
4643                 IF ( building_pars_f%pars_xy(ind_hc3,j,i) /= building_pars_f%fill )    & 
4644                    surf_usm_v(l)%rho_c_green(nzb_wall+3,m) = building_pars_f%pars_xy(ind_hc3,j,i)   
4645                 IF ( building_pars_f%pars_xy(ind_hc1,j,i) /= building_pars_f%fill )  THEN
4646                    surf_usm_v(l)%rho_c_window(nzb_wall,m)   = building_pars_f%pars_xy(ind_hc1,j,i) 
4647                    surf_usm_v(l)%rho_c_window(nzb_wall+1,m) = building_pars_f%pars_xy(ind_hc1,j,i)
4648                 ENDIF
4649                 IF ( building_pars_f%pars_xy(ind_hc2,j,i) /= building_pars_f%fill )    &
4650                    surf_usm_v(l)%rho_c_window(nzb_wall+2,m) = building_pars_f%pars_xy(ind_hc2,j,i)
4651                 IF ( building_pars_f%pars_xy(ind_hc3,j,i) /= building_pars_f%fill )    &
4652                    surf_usm_v(l)%rho_c_window(nzb_wall+3,m) = building_pars_f%pars_xy(ind_hc3,j,i)
4653
4654                 IF ( building_pars_f%pars_xy(ind_tc1,j,i) /= building_pars_f%fill )  THEN
4655                    surf_usm_v(l)%lambda_h(nzb_wall,m)   = building_pars_f%pars_xy(ind_tc1,j,i)         
4656                    surf_usm_v(l)%lambda_h(nzb_wall+1,m) = building_pars_f%pars_xy(ind_tc1,j,i)       
4657                 ENDIF
4658                 IF ( building_pars_f%pars_xy(ind_tc2,j,i) /= building_pars_f%fill )    &
4659                    surf_usm_v(l)%lambda_h(nzb_wall+2,m) = building_pars_f%pars_xy(ind_tc2,j,i)
4660                 IF ( building_pars_f%pars_xy(ind_tc3,j,i) /= building_pars_f%fill )    & 
4661                    surf_usm_v(l)%lambda_h(nzb_wall+3,m) = building_pars_f%pars_xy(ind_tc3,j,i)   
4662                 IF ( building_pars_f%pars_xy(ind_tc1,j,i) /= building_pars_f%fill )  THEN
4663                    surf_usm_v(l)%lambda_h_green(nzb_wall,m)   = building_pars_f%pars_xy(ind_tc1,j,i)         
4664                    surf_usm_v(l)%lambda_h_green(nzb_wall+1,m) = building_pars_f%pars_xy(ind_tc1,j,i)       
4665                 ENDIF
4666                 IF ( building_pars_f%pars_xy(ind_tc2,j,i) /= building_pars_f%fill )    &
4667                    surf_usm_v(l)%lambda_h_green(nzb_wall+2,m) = building_pars_f%pars_xy(ind_tc2,j,i)
4668                 IF ( building_pars_f%pars_xy(ind_tc3,j,i) /= building_pars_f%fill )    & 
4669                    surf_usm_v(l)%lambda_h_green(nzb_wall+3,m) = building_pars_f%pars_xy(ind_tc3,j,i)   
4670                 IF ( building_pars_f%pars_xy(ind_tc1,j,i) /= building_pars_f%fill )  THEN
4671                    surf_usm_v(l)%lambda_h_window(nzb_wall,m)   = building_pars_f%pars_xy(ind_tc1,j,i)         
4672                    surf_usm_v(l)%lambda_h_window(nzb_wall+1,m) = building_pars_f%pars_xy(ind_tc1,j,i)       
4673                 ENDIF
4674                 IF ( building_pars_f%pars_xy(ind_tc2,j,i) /= building_pars_f%fill )    &
4675                    surf_usm_v(l)%lambda_h_window(nzb_wall+2,m) = building_pars_f%pars_xy(ind_tc2,j,i)
4676                 IF ( building_pars_f%pars_xy(ind_tc3,j,i) /= building_pars_f%fill )    & 
4677                    surf_usm_v(l)%lambda_h_window(nzb_wall+3,m) = building_pars_f%pars_xy(ind_tc3,j,i)
4678
4679                 IF ( building_pars_f%pars_xy(12,j,i) /= building_pars_f%fill )         & 
4680                    surf_usm_v(l)%target_temp_summer(m)  = building_pars_f%pars_xy(12,j,i)   
4681                 IF ( building_pars_f%pars_xy(13,j,i) /= building_pars_f%fill )         & 
4682                    surf_usm_v(l)%target_temp_winter(m)  = building_pars_f%pars_xy(13,j,i)   
4683
4684                 IF ( building_pars_f%pars_xy(ind_emis_wall,j,i) /= building_pars_f%fill ) & 
4685                    surf_usm_v(l)%emissivity(ind_veg_wall,m)  = building_pars_f%pars_xy(ind_emis_wall,j,i)
4686                 IF ( building_pars_f%pars_xy(ind_emis_green,j,i) /= building_pars_f%fill )& 
4687                    surf_usm_v(l)%emissivity(ind_pav_green,m) = building_pars_f%pars_xy(ind_emis_green,j,i)
4688                 IF ( building_pars_f%pars_xy(ind_emis_win,j,i) /= building_pars_f%fill )  & 
4689                    surf_usm_v(l)%emissivity(ind_wat_win,m)   = building_pars_f%pars_xy(ind_emis_win,j,i)
4690
4691                 IF ( building_pars_f%pars_xy(ind_trans,j,i) /= building_pars_f%fill )    & 
4692                    surf_usm_v(l)%transmissivity(m)      = building_pars_f%pars_xy(ind_trans,j,i)
4693
4694                 IF ( building_pars_f%pars_xy(ind_z0,j,i) /= building_pars_f%fill )    & 
4695                    surf_usm_v(l)%z0(m)                  = building_pars_f%pars_xy(ind_z0,j,i)
4696                 IF ( building_pars_f%pars_xy(ind_z0qh,j,i) /= building_pars_f%fill )  & 
4697                    surf_usm_v(l)%z0h(m)                 = building_pars_f%pars_xy(ind_z0qh,j,i)
4698                 IF ( building_pars_f%pars_xy(ind_z0qh,j,i) /= building_pars_f%fill )  & 
4699                    surf_usm_v(l)%z0q(m)                 = building_pars_f%pars_xy(ind_z0qh,j,i)
4700
4701                 IF ( building_pars_f%pars_xy(ind_alb_wall,j,i) /= building_pars_f%fill )    & 
4702                    surf_usm_v(l)%albedo_type(ind_veg_wall,m)  = building_pars_f%pars_xy(ind_alb_wall,j,i)
4703                 IF ( building_pars_f%pars_xy(ind_alb_green,j,i) /= building_pars_f%fill )    & 
4704                    surf_usm_v(l)%albedo_type(ind_pav_green,m) = building_pars_f%pars_xy(ind_alb_green,j,i)
4705                 IF ( building_pars_f%pars_xy(ind_alb_win,j,i) /= building_pars_f%fill )    & 
4706                    surf_usm_v(l)%albedo_type(ind_wat_win,m)   = building_pars_f%pars_xy(ind_alb_win,j,i)
4707
4708                 IF ( building_pars_f%pars_xy(ind_thick_1,j,i) /= building_pars_f%fill )    & 
4709                    surf_usm_v(l)%zw(nzb_wall,m) = building_pars_f%pars_xy(ind_thick_1,j,i)
4710                 IF ( building_pars_f%pars_xy(ind_thick_2,j,i) /= building_pars_f%fill )    & 
4711                    surf_usm_v(l)%zw(nzb_wall+1,m) = building_pars_f%pars_xy(ind_thick_2,j,i)
4712                 IF ( building_pars_f%pars_xy(ind_thick_3,j,i) /= building_pars_f%fill )    & 
4713                    surf_usm_v(l)%zw(nzb_wall+2,m) = building_pars_f%pars_xy(ind_thick_3,j,i)
4714                 IF ( building_pars_f%pars_xy(ind_thick_4,j,i) /= building_pars_f%fill )    & 
4715                    surf_usm_v(l)%zw(nzb_wall+3,m) = building_pars_f%pars_xy(ind_thick_4,j,i)
4716                 IF ( building_pars_f%pars_xy(ind_thick_1,j,i) /= building_pars_f%fill )    & 
4717                    surf_usm_v(l)%zw_green(nzb_wall,m) = building_pars_f%pars_xy(ind_thick_1,j,i)
4718                 IF ( building_pars_f%pars_xy(ind_thick_2,j,i) /= building_pars_f%fill )    & 
4719                    surf_usm_v(l)%zw_green(nzb_wall+1,m) = building_pars_f%pars_xy(ind_thick_2,j,i)
4720                 IF ( building_pars_f%pars_xy(ind_thick_3,j,i) /= building_pars_f%fill )    & 
4721                    surf_usm_v(l)%zw_green(nzb_wall+2,m) = building_pars_f%pars_xy(ind_thick_3,j,i)
4722                 IF ( building_pars_f%pars_xy(ind_thick_4,j,i) /= building_pars_f%fill )    & 
4723                    surf_usm_v(l)%zw_green(nzb_wall+3,m) = building_pars_f%pars_xy(ind_thick_4,j,i)
4724                 IF ( building_pars_f%pars_xy(ind_thick_1,j,i) /= building_pars_f%fill )    & 
4725                    surf_usm_v(l)%zw_window(nzb_wall,m) = building_pars_f%pars_xy(ind_thick_1,j,i)
4726                 IF ( building_pars_f%pars_xy(ind_thick_2,j,i) /= building_pars_f%fill )    & 
4727                    surf_usm_v(l)%zw_window(nzb_wall+1,m) = building_pars_f%pars_xy(ind_thick_2,j,i)
4728                 IF ( building_pars_f%pars_xy(ind_thick_3,j,i) /= building_pars_f%fill )    & 
4729                    surf_usm_v(l)%zw_window(nzb_wall+2,m) = building_pars_f%pars_xy(ind_thick_3,j,i)
4730                 IF ( building_pars_f%pars_xy(ind_thick_4,j,i) /= building_pars_f%fill )    & 
4731                    surf_usm_v(l)%zw_window(nzb_wall+3,m) = building_pars_f%pars_xy(ind_thick_4,j,i)
4732
4733                 IF ( building_pars_f%pars_xy(45,j,i) /= building_pars_f%fill )    & 
4734                    surf_usm_v(l)%c_surface(m)           = building_pars_f%pars_xy(45,j,i)
4735                 IF ( building_pars_f%pars_xy(46,j,i) /= building_pars_f%fill )    & 
4736                    surf_usm_v(l)%lambda_surf(m)         = building_pars_f%pars_xy(46,j,i)
4737                 IF ( building_pars_f%pars_xy(45,j,i) /= building_pars_f%fill )    & 
4738                    surf_usm_v(l)%c_surface_green(m)     = building_pars_f%pars_xy(45,j,i)
4739                 IF ( building_pars_f%pars_xy(46,j,i) /= building_pars_f%fill )    & 
4740                    surf_usm_v(l)%lambda_surf_green(m)   = building_pars_f%pars_xy(46,j,i)
4741                 IF ( building_pars_f%pars_xy(45,j,i) /= building_pars_f%fill )    & 
4742                    surf_usm_v(l)%c_surface_window(m)    = building_pars_f%pars_xy(45,j,i)
4743                 IF ( building_pars_f%pars_xy(46,j,i) /= building_pars_f%fill )    & 
4744                    surf_usm_v(l)%lambda_surf_window(m)  = building_pars_f%pars_xy(46,j,i)
4745
4746              ENDDO
4747           ENDDO
4748        ENDIF 
4749!       
4750!--     Read the surface_types array.
4751!--     Please note, here also initialization of surface attributes is done as
4752!--     long as _urbsurf and _surfpar files are available. Values from above
4753!--     will be overwritten. This might be removed later, but is still in the
4754!--     code to enable compatibility with older model version.
4755        CALL usm_read_urban_surface_types()
4756       
4757!--     init material heat model
4758        CALL usm_init_material_model()
4759       
4760!--     init anthropogenic sources of heat
4761        IF ( usm_anthropogenic_heat )  THEN
4762!--         init anthropogenic sources of heat (from transportation for now)
4763            CALL usm_read_anthropogenic_heat()
4764        ENDIF
4765
4766        IF ( plant_canopy )  THEN
4767           
4768            IF ( .NOT.  ALLOCATED( pc_heating_rate) )  THEN
4769!--             then pc_heating_rate is allocated in init_plant_canopy
4770!--             in case of cthf /= 0 => we need to allocate it for our use here
4771                ALLOCATE( pc_heating_rate(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
4772
4773                pc_heating_rate = 0.0_wp
4774
4775            ENDIF
4776
4777            IF ( .NOT.  ALLOCATED( pc_transpiration_rate) )  THEN
4778!--             then pc_heating_rate is allocated in init_plant_canopy
4779!--             in case of cthf /= 0 => we need to allocate it for our use here
4780                ALLOCATE( pc_transpiration_rate(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
4781
4782                pc_transpiration_rate = 0.0_wp
4783
4784
4785            ENDIF
4786        ENDIF
4787!
4788!--    Check for consistent initialization.
4789!--    Check if roughness length for momentum, or heat, exceed surface-layer
4790!--    height and decrease local roughness length where necessary.
4791       DO  m = 1, surf_usm_h%ns
4792          IF ( surf_usm_h%z0(m) >= surf_usm_h%z_mo(m) )  THEN
4793         
4794             surf_usm_h%z0(m) = 0.9_wp * surf_usm_h%z_mo(m)
4795             
4796             WRITE( message_string, * ) 'z0 exceeds surface-layer height ' //  &
4797                            'at horizontal urban surface and is ' //           &
4798                            'decreased appropriately at grid point (i,j) = ',  &
4799                            surf_usm_h%i(m), surf_usm_h%j(m)
4800             CALL message( 'urban_surface_model_mod', 'PA0503',                &
4801                            0, 0, 0, 6, 0 )
4802          ENDIF
4803          IF ( surf_usm_h%z0h(m) >= surf_usm_h%z_mo(m) )  THEN
4804         
4805             surf_usm_h%z0h(m) = 0.9_wp * surf_usm_h%z_mo(m)
4806             surf_usm_h%z0q(m) = 0.9_wp * surf_usm_h%z_mo(m)
4807             
4808             WRITE( message_string, * ) 'z0h exceeds surface-layer height ' // &
4809                            'at horizontal urban surface and is ' //           &
4810                            'decreased appropriately at grid point (i,j) = ',  &
4811                            surf_usm_h%i(m), surf_usm_h%j(m)
4812             CALL message( 'urban_surface_model_mod', 'PA0507',                &
4813                            0, 0, 0, 6, 0 )
4814          ENDIF         
4815       ENDDO
4816       
4817       DO  l = 0, 3
4818          DO  m = 1, surf_usm_v(l)%ns
4819             IF ( surf_usm_v(l)%z0(m) >= surf_usm_v(l)%z_mo(m) )  THEN
4820         
4821                surf_usm_v(l)%z0(m) = 0.9_wp * surf_usm_v(l)%z_mo(m)
4822             
4823                WRITE( message_string, * ) 'z0 exceeds surface-layer height '//&
4824                            'at vertical urban surface and is ' //             &
4825                            'decreased appropriately at grid point (i,j) = ',  &
4826                            surf_usm_v(l)%i(m)+surf_usm_v(l)%ioff,             &
4827                            surf_usm_v(l)%j(m)+surf_usm_v(l)%joff
4828                CALL message( 'urban_surface_model_mod', 'PA0503',             &
4829                            0, 0, 0, 6, 0 )
4830             ENDIF
4831             IF ( surf_usm_v(l)%z0h(m) >= surf_usm_v(l)%z_mo(m) )  THEN
4832         
4833                surf_usm_v(l)%z0h(m) = 0.9_wp * surf_usm_v(l)%z_mo(m)
4834                surf_usm_v(l)%z0q(m) = 0.9_wp * surf_usm_v(l)%z_mo(m)
4835             
4836                WRITE( message_string, * ) 'z0h exceeds surface-layer height '//&
4837                            'at vertical urban surface and is ' //             &
4838                            'decreased appropriately at grid point (i,j) = ',  &
4839                            surf_usm_v(l)%i(m)+surf_usm_v(l)%ioff,             &
4840                            surf_usm_v(l)%j(m)+surf_usm_v(l)%joff
4841                CALL message( 'urban_surface_model_mod', 'PA0507',             &
4842                            0, 0, 0, 6, 0 )
4843             ENDIF
4844          ENDDO
4845       ENDDO   
4846
4847!--     Intitialization of the surface and wall/ground/roof temperature
4848
4849!--     Initialization for restart runs
4850        IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.        &
4851             TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
4852
4853!
4854!--         At horizontal surfaces. Please note, t_surf_h is defined on a
4855!--         different data type, but with the same dimension.
4856#if ! defined( __nopointer )
4857            DO  m = 1, surf_usm_h%ns
4858               i = surf_usm_h%i(m)           
4859               j = surf_usm_h%j(m)
4860               k = surf_usm_h%k(m)
4861
4862               t_surf_h(m) = pt(k,j,i) * exner(k)
4863               t_surf_window_h(m) = pt(k,j,i) * exner(k)
4864               t_surf_green_h(m) = pt(k,j,i) * exner(k)
4865               surf_usm_h%pt_surface(m) = pt(k,j,i) * exner(k)
4866            ENDDO
4867!
4868!--         At vertical surfaces.
4869            DO  l = 0, 3
4870               DO  m = 1, surf_usm_v(l)%ns
4871                  i = surf_usm_v(l)%i(m)           
4872                  j = surf_usm_v(l)%j(m)
4873                  k = surf_usm_v(l)%k(m)
4874
4875                  t_surf_v(l)%t(m) = pt(k,j,i) * exner(k)
4876                  t_surf_window_v(l)%t(m) = pt(k,j,i) * exner(k)
4877                  t_surf_green_v(l)%t(m) = pt(k,j,i) * exner(k)
4878                  surf_usm_v(l)%pt_surface(m) = pt(k,j,i) * exner(k)
4879               ENDDO
4880            ENDDO
4881#endif
4882!
4883!--         For the sake of correct initialization, set also q_surface.
4884!--         Note, at urban surfaces q_surface is initialized with 0.
4885            IF ( humidity )  THEN
4886               DO  m = 1, surf_usm_h%ns
4887                  surf_usm_h%q_surface(m) = 0.0_wp
4888               ENDDO
4889               DO  l = 0, 3
4890                  DO  m = 1, surf_usm_v(l)%ns
4891                     surf_usm_v(l)%q_surface(m) = 0.0_wp
4892                  ENDDO
4893               ENDDO
4894            ENDIF
4895     
4896!--         initial values for t_wall
4897!--         outer value is set to surface temperature
4898!--         inner value is set to wall_inner_temperature
4899!--         and profile is logaritmic (linear in nz).
4900!--         Horizontal surfaces
4901            DO  m = 1, surf_usm_h%ns
4902!
4903!--            Roof
4904               IF ( surf_usm_h%isroof_surf(m) )  THEN
4905                   tin = roof_inner_temperature
4906                   twin = window_inner_temperature
4907!
4908!--            Normal land surface
4909               ELSE
4910                   tin = soil_inner_temperature
4911                   twin = window_inner_temperature
4912               ENDIF
4913
4914               DO k = nzb_wall, nzt_wall+1
4915                   c = REAL( k - nzb_wall, wp ) /                              &
4916                       REAL( nzt_wall + 1 - nzb_wall , wp )
4917
4918                   t_wall_h(k,m) = ( 1.0_wp - c ) * t_surf_h(m) + c * tin
4919                   t_window_h(k,m) = ( 1.0_wp - c ) * t_surf_window_h(m) + c * twin
4920                   t_green_h(k,m) = t_surf_h(m)
4921               ENDDO
4922            ENDDO
4923!
4924!--         Vertical surfaces
4925            DO  l = 0, 3
4926               DO  m = 1, surf_usm_v(l)%ns
4927!
4928!--               Inner wall
4929                  tin = wall_inner_temperature
4930                  twin = window_inner_temperature
4931
4932                  DO k = nzb_wall, nzt_wall+1
4933                     c = REAL( k - nzb_wall, wp ) /                            &
4934                         REAL( nzt_wall + 1 - nzb_wall , wp )
4935                     t_wall_v(l)%t(k,m) = ( 1.0_wp - c ) * t_surf_v(l)%t(m) + c * tin
4936                     t_window_v(l)%t(k,m) = ( 1.0_wp - c ) * t_surf_window_v(l)%t(m) + c * twin
4937                     t_green_v(l)%t(k,m) = t_surf_v(l)%t(m)
4938                  ENDDO
4939               ENDDO
4940            ENDDO
4941        ELSE
4942!--         If specified, replace constant wall temperatures with fully 3D values from file
4943            IF ( read_wall_temp_3d )  CALL usm_read_wall_temperature()
4944!
4945        ENDIF
4946       
4947!--   
4948!--     Possibly DO user-defined actions (e.g. define heterogeneous wall surface)
4949        CALL user_init_urban_surface
4950
4951!--     initialize prognostic values for the first timestep
4952        t_surf_h_p = t_surf_h
4953        t_surf_v_p = t_surf_v
4954        t_surf_window_h_p = t_surf_window_h
4955        t_surf_window_v_p = t_surf_window_v
4956        t_surf_green_h_p = t_surf_green_h
4957        t_surf_green_v_p = t_surf_green_v
4958        t_surf_10cm_h_p = t_surf_10cm_h
4959        t_surf_10cm_v_p = t_surf_10cm_v
4960
4961        t_wall_h_p = t_wall_h
4962        t_wall_v_p = t_wall_v
4963        t_window_h_p = t_window_h
4964        t_window_v_p = t_window_v
4965        t_green_h_p = t_green_h
4966        t_green_v_p = t_green_v
4967
4968!--     Adjust radiative fluxes for urban surface at model start
4969        !CALL radiation_interaction
4970!--     TODO: interaction should be called once before first output,
4971!--     that is not yet possible.
4972       
4973        CALL cpu_log( log_point_s(78), 'usm_init', 'stop' )
4974
4975    END SUBROUTINE usm_init_urban_surface
4976
4977
4978!------------------------------------------------------------------------------!
4979! Description:
4980! ------------
4981!
4982!> Wall model as part of the urban surface model. The model predicts wall
4983!> temperature.
4984!------------------------------------------------------------------------------!
4985    SUBROUTINE usm_material_heat_model
4986
4987
4988        IMPLICIT NONE
4989
4990        INTEGER(iwp) ::  i,j,k,l,kw, m                      !< running indices
4991
4992        REAL(wp), DIMENSION(nzb_wall:nzt_wall) :: wtend, wintend  !< tendency
4993
4994!
4995!--     For horizontal surfaces                                   
4996        DO  m = 1, surf_usm_h%ns
4997!
4998!--        Obtain indices
4999           i = surf_usm_h%i(m)           
5000           j = surf_usm_h%j(m)
5001           k = surf_usm_h%k(m)
5002!
5003!--        prognostic equation for ground/roof temperature t_wall_h
5004           wtend(:) = 0.0_wp
5005           wtend(nzb_wall) = (1.0_wp / surf_usm_h%rho_c_wall(nzb_wall,m)) *        &
5006                                       ( surf_usm_h%lambda_h(nzb_wall,m) *         &
5007                                         ( t_wall_h(nzb_wall+1,m)                  &
5008                                         - t_wall_h(nzb_wall,m) ) *                &
5009                                         surf_usm_h%ddz_wall(nzb_wall+1,m)         &
5010                                       + surf_usm_h%frac(ind_veg_wall,m)           &
5011                                         / (surf_usm_h%frac(ind_veg_wall,m)        &
5012                                           + surf_usm_h%frac(ind_pav_green,m) )    &
5013                                         * surf_usm_h%wghf_eb(m)                   &
5014                                       - surf_usm_h%frac(ind_pav_green,m)          &
5015                                          / (surf_usm_h%frac(ind_veg_wall,m)       &
5016                                            + surf_usm_h%frac(ind_pav_green,m) )   &
5017                                         * ( surf_usm_h%lambda_h_green(nzt_wall,m) &
5018                                           * surf_usm_h%ddz_green(nzt_wall,m)      &
5019                                           + surf_usm_h%lambda_h(nzb_wall,m)       &
5020                                           * surf_usm_h%ddz_wall(nzb_wall,m) )     &
5021                                         / ( surf_usm_h%ddz_green(nzt_wall,m)      &
5022                                           + surf_usm_h%ddz_wall(nzb_wall,m) )     &
5023                                         * ( t_wall_h(nzb_wall,m)                  &
5024                                           - t_green_h(nzt_wall,m) ) ) *           &
5025                                       surf_usm_h%ddz_wall_stag(nzb_wall,m)
5026
5027!dummy value for testing
5028surf_usm_h%iwghf_eb(m) = 0.
5029
5030           IF ( indoor_model ) then
5031              DO  kw = nzb_wall+1, nzt_wall-1
5032                  wtend(kw) = (1.0_wp / surf_usm_h%rho_c_wall(kw,m))              &
5033                                 * (   surf_usm_h%lambda_h(kw,m)                  &
5034                                    * ( t_wall_h(kw+1,m) - t_wall_h(kw,m) )       &
5035                                    * surf_usm_h%ddz_wall(kw+1,m)                 &
5036                                 - surf_usm_h%lambda_h(kw-1,m)                    &
5037                                    * ( t_wall_h(kw,m) - t_wall_h(kw-1,m) )       &
5038                                    * surf_usm_h%ddz_wall(kw,m)                   &
5039                                   ) * surf_usm_h%ddz_wall_stag(kw,m)
5040              ENDDO
5041              wtend(nzt_wall) = (1.0_wp / surf_usm_h%rho_c_wall(nzt_wall,m)) *    &
5042                                         ( surf_usm_h%lambda_h(nzt_wall-1,m) *    &
5043                                           ( t_wall_h(nzt_wall,m)                 &
5044                                           - t_wall_h(nzt_wall-1,m) ) *           &
5045                                           surf_usm_h%ddz_wall(nzt_wall,m)        &
5046                                         + surf_usm_h%iwghf_eb(m) ) *             &
5047                                           surf_usm_h%ddz_wall_stag(nzt_wall,m)
5048           ELSE
5049              DO  kw = nzb_wall+1, nzt_wall
5050                  wtend(kw) = (1.0_wp / surf_usm_h%rho_c_wall(kw,m))              &
5051                                 * (   surf_usm_h%lambda_h(kw,m)                  &
5052                                    * ( t_wall_h(kw+1,m) - t_wall_h(kw,m) )       &
5053                                    * surf_usm_h%ddz_wall(kw+1,m)                 &
5054                                 - surf_usm_h%lambda_h(kw-1,m)                    &
5055                                    * ( t_wall_h(kw,m) - t_wall_h(kw-1,m) )       &
5056                                    * surf_usm_h%ddz_wall(kw,m)                   &
5057                                   ) * surf_usm_h%ddz_wall_stag(kw,m)
5058              ENDDO
5059           ENDIF
5060
5061           t_wall_h_p(nzb_wall:nzt_wall,m) = t_wall_h(nzb_wall:nzt_wall,m)     &
5062                                 + dt_3d * ( tsc(2)                            &
5063                                 * wtend(nzb_wall:nzt_wall) + tsc(3)           &
5064                                 * surf_usm_h%tt_wall_m(nzb_wall:nzt_wall,m) )   
5065
5066!--        prognostic equation for ground/roof window temperature t_window_h
5067           wintend(:) = 0.0_wp
5068           wintend(nzb_wall) = (1.0_wp / surf_usm_h%rho_c_window(nzb_wall,m)) *   &
5069                                      ( surf_usm_h%lambda_h_window(nzb_wall,m) *  &
5070                                        ( t_window_h(nzb_wall+1,m)                &
5071                                        - t_window_h(nzb_wall,m) ) *              &
5072                                        surf_usm_h%ddz_window(nzb_wall+1,m)       &
5073                                      + surf_usm_h%wghf_eb_window(m)              &
5074                                      + surf_usm_h%rad_sw_in(m)                   &
5075                                        * (1.0_wp - exp(-surf_usm_h%transmissivity(m) &
5076                                        * surf_usm_h%zw_window(nzb_wall,m) ) )    &
5077                                      ) * surf_usm_h%ddz_window_stag(nzb_wall,m)
5078
5079           IF ( indoor_model ) then
5080              DO  kw = nzb_wall+1, nzt_wall-1
5081                  wintend(kw) = (1.0_wp / surf_usm_h%rho_c_window(kw,m))          &
5082                                 * (   surf_usm_h%lambda_h_window(kw,m)           &
5083                                    * ( t_window_h(kw+1,m) - t_window_h(kw,m) )   &
5084                                    * surf_usm_h%ddz_window(kw+1,m)               &
5085                                 - surf_usm_h%lambda_h_window(kw-1,m)             &
5086                                    * ( t_window_h(kw,m) - t_window_h(kw-1,m) )   &
5087                                    * surf_usm_h%ddz_window(kw,m)                 &
5088                                 + surf_usm_h%rad_sw_in(m)                        &
5089                                    * (exp(-surf_usm_h%transmissivity(m)       &
5090                                        * surf_usm_h%zw_window(kw-1,m) )          &
5091                                        - exp(-surf_usm_h%transmissivity(m)    &
5092                                        * surf_usm_h%zw_window(kw,m) ) )          &
5093                                   ) * surf_usm_h%ddz_window_stag(kw,m)
5094
5095              ENDDO
5096              wintend(nzt_wall) = (1.0_wp / surf_usm_h%rho_c_window(nzt_wall,m)) *     &
5097                                         ( surf_usm_h%lambda_h_window(nzt_wall-1,m) *  &
5098                                           ( t_window_h(nzt_wall,m)                    &
5099                                           - t_window_h(nzt_wall-1,m) ) *              &
5100                                           surf_usm_h%ddz_window(nzt_wall,m)           &
5101                                         + surf_usm_h%iwghf_eb_window(m)               &
5102                                         + surf_usm_h%rad_sw_in(m)                     &
5103                                           * (1.0_wp - exp(-surf_usm_h%transmissivity(m) &
5104                                           * surf_usm_h%zw_window(nzt_wall,m) ) )      &
5105                                         ) * surf_usm_h%ddz_window_stag(nzt_wall,m)
5106           ELSE
5107              DO  kw = nzb_wall+1, nzt_wall
5108                  wintend(kw) = (1.0_wp / surf_usm_h%rho_c_window(kw,m))          &
5109                                 * (   surf_usm_h%lambda_h_window(kw,m)           &
5110                                    * ( t_window_h(kw+1,m) - t_window_h(kw,m) )   &
5111                                    * surf_usm_h%ddz_window(kw+1,m)               &
5112                                 - surf_usm_h%lambda_h_window(kw-1,m)             &
5113                                    * ( t_window_h(kw,m) - t_window_h(kw-1,m) )   &
5114                                    * surf_usm_h%ddz_window(kw,m)                 &
5115                                 + surf_usm_h%rad_sw_in(m)                        &
5116                                    * (exp(-surf_usm_h%transmissivity(m)       &
5117                                        * surf_usm_h%zw_window(kw-1,m) )          &
5118                                        - exp(-surf_usm_h%transmissivity(m)    &
5119                                        * surf_usm_h%zw_window(kw,m) ) )          &
5120                                   ) * surf_usm_h%ddz_window_stag(kw,m)
5121
5122              ENDDO
5123           ENDIF
5124
5125           t_window_h_p(nzb_wall:nzt_wall,m) = t_window_h(nzb_wall:nzt_wall,m)    &
5126                                 + dt_3d * ( tsc(2)                               &
5127                                 * wintend(nzb_wall:nzt_wall) + tsc(3)            &
5128                                 * surf_usm_h%tt_window_m(nzb_wall:nzt_wall,m) )   
5129
5130!
5131!--        calculate t_wall tendencies for the next Runge-Kutta step
5132           IF ( timestep_scheme(1:5) == 'runge' )  THEN
5133               IF ( intermediate_timestep_count == 1 )  THEN
5134                  DO  kw = nzb_wall, nzt_wall
5135                     surf_usm_h%tt_wall_m(kw,m) = wtend(kw)
5136                  ENDDO
5137               ELSEIF ( intermediate_timestep_count <                          &
5138                        intermediate_timestep_count_max )  THEN
5139                   DO  kw = nzb_wall, nzt_wall
5140                      surf_usm_h%tt_wall_m(kw,m) = -9.5625_wp * wtend(kw) +    &
5141                                         5.3125_wp * surf_usm_h%tt_wall_m(kw,m)
5142                   ENDDO
5143               ENDIF
5144           ENDIF
5145
5146!--        calculate t_window tendencies for the next Runge-Kutta step
5147           IF ( timestep_scheme(1:5) == 'runge' )  THEN
5148               IF ( intermediate_timestep_count == 1 )  THEN
5149                  DO  kw = nzb_wall, nzt_wall
5150                     surf_usm_h%tt_window_m(kw,m) = wintend(kw)
5151                  ENDDO
5152               ELSEIF ( intermediate_timestep_count <                          &
5153                        intermediate_timestep_count_max )  THEN
5154                   DO  kw = nzb_wall, nzt_wall
5155                      surf_usm_h%tt_window_m(kw,m) = -9.5625_wp * wintend(kw) +    &
5156                                         5.3125_wp * surf_usm_h%tt_window_m(kw,m)
5157                   ENDDO
5158               ENDIF
5159           ENDIF
5160        ENDDO
5161
5162!
5163!--     For vertical surfaces     
5164        DO  l = 0, 3                             
5165           DO  m = 1, surf_usm_v(l)%ns
5166!
5167!--           Obtain indices
5168              i = surf_usm_v(l)%i(m)           
5169              j = surf_usm_v(l)%j(m)
5170              k = surf_usm_v(l)%k(m)
5171!
5172!--           prognostic equation for wall temperature t_wall_v
5173              wtend(:) = 0.0_wp
5174
5175               wtend(nzb_wall) = (1.0_wp / surf_usm_v(l)%rho_c_wall(nzb_wall,m)) *    &
5176                                       ( surf_usm_v(l)%lambda_h(nzb_wall,m) *         &
5177                                         ( t_wall_v(l)%t(nzb_wall+1,m)                &
5178                                         - t_wall_v(l)%t(nzb_wall,m) ) *              &
5179                                         surf_usm_v(l)%ddz_wall(nzb_wall+1,m)         &
5180                                       + surf_usm_v(l)%frac(ind_veg_wall,m)           &
5181                                         / (surf_usm_v(l)%frac(ind_veg_wall,m)        &
5182                                           + surf_usm_v(l)%frac(ind_pav_green,m) )    &
5183                                         * surf_usm_v(l)%wghf_eb(m)                   &
5184                                       - surf_usm_v(l)%frac(ind_pav_green,m)          &
5185                                         / (surf_usm_v(l)%frac(ind_veg_wall,m)        &
5186                                           + surf_usm_v(l)%frac(ind_pav_green,m) )    &
5187                                         * ( surf_usm_v(l)%lambda_h_green(nzt_wall,m) &
5188                                           * surf_usm_v(l)%ddz_green(nzt_wall,m)      &
5189                                           + surf_usm_v(l)%lambda_h(nzb_wall,m)       &
5190                                           * surf_usm_v(l)%ddz_wall(nzb_wall,m) )     &
5191                                         / ( surf_usm_v(l)%ddz_green(nzt_wall,m)      &
5192                                           + surf_usm_v(l)%ddz_wall(nzb_wall,m) )     &
5193                                         * ( t_wall_v(l)%t(nzb_wall,m)                &
5194                                           - t_green_v(l)%t(nzt_wall,m) ) ) *         &
5195                                         surf_usm_v(l)%ddz_wall_stag(nzb_wall,m)
5196
5197!dummy value for testing
5198surf_usm_v(l)%iwghf_eb(m) = 0.
5199
5200              IF ( indoor_model ) then
5201                 DO  kw = nzb_wall+1, nzt_wall-1
5202                     wtend(kw) = (1.0_wp / surf_usm_v(l)%rho_c_wall(kw,m))        &
5203                              * (   surf_usm_v(l)%lambda_h(kw,m)                  &
5204                                 * ( t_wall_v(l)%t(kw+1,m) - t_wall_v(l)%t(kw,m) )&
5205                                 * surf_usm_v(l)%ddz_wall(kw+1,m)                 &
5206                              - surf_usm_v(l)%lambda_h(kw-1,m)                    &
5207                                 * ( t_wall_v(l)%t(kw,m) - t_wall_v(l)%t(kw-1,m) )&
5208                                 * surf_usm_v(l)%ddz_wall(kw,m)                   &
5209                                 ) * surf_usm_v(l)%ddz_wall_stag(kw,m)
5210                 ENDDO
5211                 wtend(nzt_wall) = (1.0_wp / surf_usm_v(l)%rho_c_wall(nzt_wall,m)) * &
5212                                         ( surf_usm_v(l)%lambda_h(nzt_wall-1,m) *    &
5213                                           ( t_wall_v(l)%t(nzt_wall,m)               &
5214                                           - t_wall_v(l)%t(nzt_wall-1,m) ) *         &
5215                                           surf_usm_v(l)%ddz_wall(nzt_wall,m)        &
5216                                         + surf_usm_v(l)%iwghf_eb(m) ) *             &
5217                                           surf_usm_v(l)%ddz_wall_stag(nzt_wall,m)
5218              ELSE
5219                 DO  kw = nzb_wall+1, nzt_wall
5220                     wtend(kw) = (1.0_wp / surf_usm_v(l)%rho_c_wall(kw,m))        &
5221                              * (   surf_usm_v(l)%lambda_h(kw,m)                  &
5222                                 * ( t_wall_v(l)%t(kw+1,m) - t_wall_v(l)%t(kw,m) )&
5223                                 * surf_usm_v(l)%ddz_wall(kw+1,m)                 &
5224                              - surf_usm_v(l)%lambda_h(kw-1,m)                    &
5225                                 * ( t_wall_v(l)%t(kw,m) - t_wall_v(l)%t(kw-1,m) )&
5226                                 * surf_usm_v(l)%ddz_wall(kw,m)                   &
5227                                 ) * surf_usm_v(l)%ddz_wall_stag(kw,m)
5228                 ENDDO
5229              ENDIF
5230
5231              t_wall_v_p(l)%t(nzb_wall:nzt_wall,m) =                           &
5232                                   t_wall_v(l)%t(nzb_wall:nzt_wall,m)          &
5233                                 + dt_3d * ( tsc(2)                            &
5234                                 * wtend(nzb_wall:nzt_wall) + tsc(3)           &
5235                                 * surf_usm_v(l)%tt_wall_m(nzb_wall:nzt_wall,m) )   
5236
5237!--           prognostic equation for window temperature t_window_v
5238              wintend(:) = 0.0_wp
5239              wintend(nzb_wall) = (1.0_wp / surf_usm_v(l)%rho_c_window(nzb_wall,m)) * &
5240                                      ( surf_usm_v(l)%lambda_h_window(nzb_wall,m) *   &
5241                                        ( t_window_v(l)%t(nzb_wall+1,m)               &
5242                                        - t_window_v(l)%t(nzb_wall,m) ) *             &
5243                                        surf_usm_v(l)%ddz_window(nzb_wall+1,m)        &
5244                                      + surf_usm_v(l)%wghf_eb_window(m)               &
5245                                      + surf_usm_v(l)%rad_sw_in(m)                    &
5246                                        * (1.0_wp - exp(-surf_usm_v(l)%transmissivity(m) &
5247                                        * surf_usm_v(l)%zw_window(nzb_wall,m) ) )     &
5248                                      ) * surf_usm_v(l)%ddz_window_stag(nzb_wall,m)
5249
5250              IF ( indoor_model ) then
5251                 DO  kw = nzb_wall+1, nzt_wall -1
5252                     wintend(kw) = (1.0_wp / surf_usm_v(l)%rho_c_window(kw,m))         &
5253                              * (   surf_usm_v(l)%lambda_h_window(kw,m)                &
5254                                 * ( t_window_v(l)%t(kw+1,m) - t_window_v(l)%t(kw,m) ) &
5255                                 * surf_usm_v(l)%ddz_window(kw+1,m)                    &
5256                              - surf_usm_v(l)%lambda_h_window(kw-1,m)                  &
5257                                 * ( t_window_v(l)%t(kw,m) - t_window_v(l)%t(kw-1,m) ) &
5258                                 * surf_usm_v(l)%ddz_window(kw,m)                      &
5259                              + surf_usm_v(l)%rad_sw_in(m)                             &
5260                                 * (exp(-surf_usm_v(l)%transmissivity(m)            &
5261                                    * surf_usm_v(l)%zw_window(kw-1,m)       )          &
5262                                        - exp(-surf_usm_v(l)%transmissivity(m)      &
5263                                        * surf_usm_v(l)%zw_window(kw,m) ) )            &
5264                                 ) * surf_usm_v(l)%ddz_window_stag(kw,m)
5265                  ENDDO
5266                  wintend(nzt_wall) = (1.0_wp / surf_usm_v(l)%rho_c_window(nzt_wall,m)) * &
5267                                          ( surf_usm_v(l)%lambda_h_window(nzt_wall-1,m) * &
5268                                            ( t_window_v(l)%t(nzt_wall,m)                 &
5269                                            - t_window_v(l)%t(nzt_wall-1,m) ) *           &
5270                                            surf_usm_v(l)%ddz_window(nzt_wall,m)          &
5271                                          + surf_usm_v(l)%iwghf_eb_window(m)              &
5272                                          + surf_usm_v(l)%rad_sw_in(m)                    &
5273                                            * (1.0_wp - exp(-surf_usm_v(l)%transmissivity(m) &
5274                                            * surf_usm_v(l)%zw_window(nzt_wall,m) ) )     &
5275                                          ) * surf_usm_v(l)%ddz_window_stag(nzt_wall,m)
5276              ELSE
5277                 DO  kw = nzb_wall+1, nzt_wall
5278                     wintend(kw) = (1.0_wp / surf_usm_v(l)%rho_c_window(kw,m))         &
5279                              * (   surf_usm_v(l)%lambda_h_window(kw,m)                &
5280                                 * ( t_window_v(l)%t(kw+1,m) - t_window_v(l)%t(kw,m) ) &
5281                                 * surf_usm_v(l)%ddz_window(kw+1,m)                    &
5282                              - surf_usm_v(l)%lambda_h_window(kw-1,m)                  &
5283                                 * ( t_window_v(l)%t(kw,m) - t_window_v(l)%t(kw-1,m) ) &
5284                                 * surf_usm_v(l)%ddz_window(kw,m)                      &
5285                              + surf_usm_v(l)%rad_sw_in(m)                             &
5286                                 * (exp(-surf_usm_v(l)%transmissivity(m)            &
5287                                    * surf_usm_v(l)%zw_window(kw-1,m)       )          &
5288                                        - exp(-surf_usm_v(l)%transmissivity(m)      &
5289                                        * surf_usm_v(l)%zw_window(kw,m) ) )            &
5290                                 ) * surf_usm_v(l)%ddz_window_stag(kw,m)
5291                 ENDDO
5292              ENDIF
5293
5294              t_window_v_p(l)%t(nzb_wall:nzt_wall,m) =                           &
5295                                   t_window_v(l)%t(nzb_wall:nzt_wall,m)          &
5296                                 + dt_3d * ( tsc(2)                              &
5297                                 * wintend(nzb_wall:nzt_wall) + tsc(3)           &
5298                                 * surf_usm_v(l)%tt_window_m(nzb_wall:nzt_wall,m) )   
5299
5300!
5301!--           calculate t_wall tendencies for the next Runge-Kutta step
5302              IF ( timestep_scheme(1:5) == 'runge' )  THEN
5303                  IF ( intermediate_timestep_count == 1 )  THEN
5304                     DO  kw = nzb_wall, nzt_wall
5305                        surf_usm_v(l)%tt_wall_m(kw,m) = wtend(kw)
5306                     ENDDO
5307                  ELSEIF ( intermediate_timestep_count <                       &
5308                           intermediate_timestep_count_max )  THEN
5309                      DO  kw = nzb_wall, nzt_wall
5310                         surf_usm_v(l)%tt_wall_m(kw,m) =                       &
5311                                     - 9.5625_wp * wtend(kw) +                 &
5312                                       5.3125_wp * surf_usm_v(l)%tt_wall_m(kw,m)
5313                      ENDDO
5314                  ENDIF
5315              ENDIF
5316!--           calculate t_window tendencies for the next Runge-Kutta step
5317              IF ( timestep_scheme(1:5) == 'runge' )  THEN
5318                  IF ( intermediate_timestep_count == 1 )  THEN
5319                     DO  kw = nzb_wall, nzt_wall
5320                        surf_usm_v(l)%tt_window_m(kw,m) = wintend(kw)
5321                     ENDDO
5322                  ELSEIF ( intermediate_timestep_count <                       &
5323                           intermediate_timestep_count_max )  THEN
5324                      DO  kw = nzb_wall, nzt_wall
5325                         surf_usm_v(l)%tt_window_m(kw,m) =                     &
5326                                     - 9.5625_wp * wintend(kw) +               &
5327                                       5.3125_wp * surf_usm_v(l)%tt_window_m(kw,m)
5328                      ENDDO
5329                  ENDIF
5330              ENDIF
5331           ENDDO
5332!!!!!!!!!!!!!HACK!!!!!!!!!!!!!!!!!!!
5333!           t_window_v_p(l)%t = t_wall_v_p(l)%t
5334!           surf_usm_v(l)%tt_window_m  = surf_usm_v(l)%tt_wall_m
5335!           t_green_v_p(l)%t = t_wall_v_p(l)%t
5336!           surf_usm_v(l)%tt_green_m  = surf_usm_v(l)%tt_wall_m
5337!!!!!!!!!!!!!HACK!!!!!!!!!!!!!!!!!!!
5338        ENDDO
5339
5340    END SUBROUTINE usm_material_heat_model
5341
5342!------------------------------------------------------------------------------!
5343! Description:
5344! ------------
5345!
5346!> Green and substrate model as part of the urban surface model. The model predicts ground
5347!> temperatures.
5348!------------------------------------------------------------------------------!
5349    SUBROUTINE usm_green_heat_model
5350
5351
5352        IMPLICIT NONE
5353
5354        INTEGER(iwp) ::  i,j,k,l,kw, m                      !< running indices
5355
5356        REAL(wp), DIMENSION(nzb_wall:nzt_wall) :: gtend  !< tendency
5357
5358!
5359!--     For horizontal surfaces                                   
5360        DO  m = 1, surf_usm_h%ns
5361!
5362!--        Obtain indices
5363           i = surf_usm_h%i(m)           
5364           j = surf_usm_h%j(m)
5365           k = surf_usm_h%k(m)
5366
5367           t_green_h(nzt_wall+1,m) = t_wall_h(nzb_wall,m)
5368!
5369!--        prognostic equation for ground/roof temperature t_green_h
5370           gtend(:) = 0.0_wp
5371           gtend(nzb_wall) = (1.0_wp / surf_usm_h%rho_c_green(nzb_wall,m)) *    &
5372                                      ( surf_usm_h%lambda_h_green(nzb_wall,m) * &
5373                                        ( t_green_h(nzb_wall+1,m)               &
5374                                        - t_green_h(nzb_wall,m) ) *             &
5375                                        surf_usm_h%ddz_green(nzb_wall+1,m)      &
5376                                      + surf_usm_h%wghf_eb_green(m) ) *         &
5377                                        surf_usm_h%ddz_green_stag(nzb_wall,m)
5378           
5379            DO  kw = nzb_wall+1, nzt_wall
5380                gtend(kw) = (1.0_wp / surf_usm_h%rho_c_green(kw,m))             &
5381                               * (   surf_usm_h%lambda_h_green(kw,m)            &
5382                                  * ( t_green_h(kw+1,m) - t_green_h(kw,m) )     &
5383                                  * surf_usm_h%ddz_green(kw+1,m)                &
5384                               - surf_usm_h%lambda_h_green(kw-1,m)              &
5385                                  * ( t_green_h(kw,m) - t_green_h(kw-1,m) )     &
5386                                  * surf_usm_h%ddz_green(kw,m)                  &
5387                                 ) * surf_usm_h%ddz_green_stag(kw,m)
5388            ENDDO
5389
5390           t_green_h_p(nzb_wall:nzt_wall,m) = t_green_h(nzb_wall:nzt_wall,m)    &
5391                                 + dt_3d * ( tsc(2)                             &
5392                                 * gtend(nzb_wall:nzt_wall) + tsc(3)            &
5393                                 * surf_usm_h%tt_green_m(nzb_wall:nzt_wall,m) )   
5394
5395         
5396!
5397!--        calculate t_green tendencies for the next Runge-Kutta step
5398           IF ( timestep_scheme(1:5) == 'runge' )  THEN
5399               IF ( intermediate_timestep_count == 1 )  THEN
5400                  DO  kw = nzb_wall, nzt_wall
5401                     surf_usm_h%tt_green_m(kw,m) = gtend(kw)
5402                  ENDDO
5403               ELSEIF ( intermediate_timestep_count <                           &
5404                        intermediate_timestep_count_max )  THEN
5405                   DO  kw = nzb_wall, nzt_wall
5406                      surf_usm_h%tt_green_m(kw,m) = -9.5625_wp * gtend(kw) +    &
5407                                         5.3125_wp * surf_usm_h%tt_green_m(kw,m)
5408                   ENDDO
5409               ENDIF
5410           ENDIF
5411        ENDDO
5412
5413!
5414!--     For vertical surfaces     
5415        DO  l = 0, 3                             
5416           DO  m = 1, surf_usm_v(l)%ns
5417!
5418!--           Obtain indices
5419              i = surf_usm_v(l)%i(m)           
5420              j = surf_usm_v(l)%j(m)
5421              k = surf_usm_v(l)%k(m)
5422
5423              t_green_v(l)%t(nzt_wall+1,m) = t_wall_v(l)%t(nzb_wall,m)
5424!
5425!--           prognostic equation for green temperature t_green_v
5426              gtend(:) = 0.0_wp
5427              gtend(nzb_wall) = (1.0_wp / surf_usm_v(l)%rho_c_green(nzb_wall,m)) * &
5428                                      ( surf_usm_v(l)%lambda_h_green(nzb_wall,m) * &
5429                                        ( t_green_v(l)%t(nzb_wall+1,m)             &
5430                                        - t_green_v(l)%t(nzb_wall,m) ) *           &
5431                                        surf_usm_v(l)%ddz_green(nzb_wall+1,m)      &
5432                                      + surf_usm_v(l)%wghf_eb(m) ) *               &
5433                                        surf_usm_v(l)%ddz_green_stag(nzb_wall,m)
5434           
5435              DO  kw = nzb_wall+1, nzt_wall
5436                 gtend(kw) = (1.0_wp / surf_usm_v(l)%rho_c_green(kw,m))          &
5437                           * (   surf_usm_v(l)%lambda_h_green(kw,m)              &
5438                             * ( t_green_v(l)%t(kw+1,m) - t_green_v(l)%t(kw,m) ) &
5439                             * surf_usm_v(l)%ddz_green(kw+1,m)                   &
5440                           - surf_usm_v(l)%lambda_h(kw-1,m)                      &
5441                             * ( t_green_v(l)%t(kw,m) - t_green_v(l)%t(kw-1,m) ) &
5442                             * surf_usm_v(l)%ddz_green(kw,m) )                   &
5443                           * surf_usm_v(l)%ddz_green_stag(kw,m)
5444              ENDDO
5445
5446              t_green_v_p(l)%t(nzb_wall:nzt_wall,m) =                              &
5447                                   t_green_v(l)%t(nzb_wall:nzt_wall,m)             &
5448                                 + dt_3d * ( tsc(2)                                &
5449                                 * gtend(nzb_wall:nzt_wall) + tsc(3)               &
5450                                 * surf_usm_v(l)%tt_green_m(nzb_wall:nzt_wall,m) )   
5451
5452!
5453!--           calculate t_green tendencies for the next Runge-Kutta step
5454              IF ( timestep_scheme(1:5) == 'runge' )  THEN
5455                  IF ( intermediate_timestep_count == 1 )  THEN
5456                     DO  kw = nzb_wall, nzt_wall
5457                        surf_usm_v(l)%tt_green_m(kw,m) = gtend(kw)
5458                     ENDDO
5459                  ELSEIF ( intermediate_timestep_count <                           &
5460                           intermediate_timestep_count_max )  THEN
5461                      DO  kw = nzb_wall, nzt_wall
5462                         surf_usm_v(l)%tt_green_m(kw,m) =                          &
5463                                     - 9.5625_wp * gtend(kw) +                     &
5464                                       5.3125_wp * surf_usm_v(l)%tt_green_m(kw,m)
5465                      ENDDO
5466                  ENDIF
5467              ENDIF
5468
5469           ENDDO
5470        ENDDO
5471
5472    END SUBROUTINE usm_green_heat_model
5473
5474!------------------------------------------------------------------------------!
5475! Description:
5476! ------------
5477!> Parin for &usm_par for urban surface model
5478!------------------------------------------------------------------------------!
5479    SUBROUTINE usm_parin
5480
5481       IMPLICIT NONE
5482
5483       CHARACTER (LEN=80) ::  line  !< string containing current line of file PARIN
5484
5485       NAMELIST /urban_surface_par/                                            &
5486                           building_type,                                      &
5487                           land_category,                                      &
5488                           naheatlayers,                                       &
5489                           pedestrian_category,                                &
5490                           roughness_concrete,                                 &
5491                           read_wall_temp_3d,                                  &
5492                           roof_category,                                      &
5493                           urban_surface,                                      &
5494                           usm_anthropogenic_heat,                             &
5495                           usm_material_model,                                 &
5496                           wall_category,                                      &
5497                           indoor_model,                                       &
5498                           wall_inner_temperature,                             &
5499                           roof_inner_temperature,                             &
5500                           soil_inner_temperature,                             &
5501                           window_inner_temperature
5502
5503       NAMELIST /urban_surface_parameters/                                     &
5504                           building_type,                                      &
5505                           land_category,                                      &
5506                           naheatlayers,                                       &
5507                           pedestrian_category,                                &
5508                           roughness_concrete,                                 &
5509                           read_wall_temp_3d,                                  &
5510                           roof_category,                                      &
5511                           urban_surface,                                      &
5512                           usm_anthropogenic_heat,                             &
5513                           usm_material_model,                                 &
5514                           wall_category,                                      &
5515                           indoor_model,                                       &
5516                           wall_inner_temperature,                             &
5517                           roof_inner_temperature,                             &
5518                           soil_inner_temperature,                             &
5519                           window_inner_temperature
5520                           
5521                           
5522 
5523!
5524!--    Try to find urban surface model package
5525       REWIND ( 11 )
5526       line = ' '
5527       DO WHILE ( INDEX( line, '&urban_surface_parameters' ) == 0 )
5528          READ ( 11, '(A)', END=12 )  line
5529       ENDDO
5530       BACKSPACE ( 11 )
5531
5532!
5533!--    Read user-defined namelist
5534       READ ( 11, urban_surface_parameters, ERR = 10 )
5535
5536!
5537!--    Set flag that indicates that the urban surface model is switched on
5538       urban_surface = .TRUE.
5539
5540       GOTO 14
5541
5542 10    BACKSPACE( 11 )
5543       READ( 11 , '(A)') line
5544       CALL parin_fail_message( 'urban_surface_parameters', line )
5545!
5546!--    Try to find old namelist
5547 12    REWIND ( 11 )
5548       line = ' '
5549       DO WHILE ( INDEX( line, '&urban_surface_par' ) == 0 )
5550          READ ( 11, '(A)', END=14 )  line
5551       ENDDO
5552       BACKSPACE ( 11 )
5553
5554!
5555!--    Read user-defined namelist
5556       READ ( 11, urban_surface_par, ERR = 13, END = 14 )
5557
5558       message_string = 'namelist urban_surface_par is deprecated and will be ' // &
5559                     'removed in near future. Please use namelist ' //   &
5560                     'urban_surface_parameters instead'
5561       CALL message( 'usm_parin', 'PA0487', 0, 1, 0, 6, 0 )
5562
5563!
5564!--    Set flag that indicates that the urban surface model is switched on
5565       urban_surface = .TRUE.
5566
5567       GOTO 14
5568
5569 13    BACKSPACE( 11 )
5570       READ( 11 , '(A)') line
5571       CALL parin_fail_message( 'urban_surface_par', line )
5572
5573
5574 14    CONTINUE
5575
5576
5577    END SUBROUTINE usm_parin
5578
5579!------------------------------------------------------------------------------!
5580! Description:
5581! ------------
5582!> Calculates temperature near surface (10 cm) for indoor model
5583!------------------------------------------------------------------------------!
5584    SUBROUTINE usm_temperature_near_surface
5585
5586       IMPLICIT NONE
5587
5588       INTEGER(iwp)                          :: i, j, k, l, m   !< running indices
5589
5590!       
5591!--    First, treat horizontal surface elements
5592       DO  m = 1, surf_usm_h%ns
5593
5594!--       Get indices of respective grid point
5595          i = surf_usm_h%i(m)
5596          j = surf_usm_h%j(m)
5597          k = surf_usm_h%k(m)
5598
5599          t_surf_10cm_h(m) = surf_usm_h%pt_surface(m) + surf_usm_h%ts(m) / kappa        &
5600                             * ( log( 0.1_wp /  surf_usm_h%z0h(m) )              &
5601                               - psi_h( 0.1_wp / surf_usm_h%ol(m) )              &
5602                               + psi_h( surf_usm_h%z0h(m) / surf_usm_h%ol(m) ) )
5603
5604       ENDDO
5605!
5606!--    Now, treat vertical surface elements
5607       DO  l = 0, 3
5608          DO  m = 1, surf_usm_v(l)%ns
5609
5610!--          Get indices of respective grid point
5611             i = surf_usm_v(l)%i(m)
5612             j = surf_usm_v(l)%j(m)
5613             k = surf_usm_v(l)%k(m)
5614
5615             t_surf_10cm_v(l)%t(m) =surf_usm_v(l)%pt_surface(m) + surf_usm_v(l)%ts(m) / kappa &
5616                                     * ( log( 0.1_wp / surf_usm_v(l)%z0h(m) )             &
5617                                       - psi_h( 0.1_wp / surf_usm_v(l)%ol(m) )            &
5618                                       + psi_h( surf_usm_v(l)%z0h(m) / surf_usm_v(l)%ol(m) ) )
5619
5620          ENDDO
5621
5622       ENDDO
5623
5624
5625    END SUBROUTINE usm_temperature_near_surface
5626
5627   
5628 
5629!------------------------------------------------------------------------------!
5630! Description:
5631! ------------
5632!
5633!> This subroutine is part of the urban surface model.
5634!> It reads daily heat produced by anthropogenic sources
5635!> and the diurnal cycle of the heat.
5636!------------------------------------------------------------------------------!
5637    SUBROUTINE usm_read_anthropogenic_heat
5638   
5639        INTEGER(iwp)                  :: i,j,k,ii
5640        REAL(wp)                      :: heat
5641
5642!--     allocation of array of sources of anthropogenic heat and their diural profile
5643        ALLOCATE( aheat(naheatlayers,nys:nyn,nxl:nxr) )
5644        ALLOCATE( aheatprof(naheatlayers,0:24) )
5645
5646!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5647!--     read daily amount of heat and its daily cycle
5648!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5649        aheat = 0.0_wp
5650        DO  ii = 0, io_blocks-1
5651            IF ( ii == io_group )  THEN
5652
5653!--             open anthropogenic heat file
5654                OPEN( 151, file='ANTHROPOGENIC_HEAT'//TRIM(coupling_char), action='read', &
5655                           status='old', form='formatted', err=11 )
5656                i = 0
5657                j = 0
5658                DO
5659                    READ( 151, *, err=12, end=13 )  i, j, k, heat
5660                    IF ( i >= nxl  .AND.  i <= nxr  .AND.  j >= nys  .AND.  j <= nyn )  THEN
5661                        IF ( k <= naheatlayers  .AND.  k > get_topography_top_index_ji( j, i, 's' ) )  THEN
5662!--                         write heat into the array
5663                            aheat(k,j,i) = heat
5664                        ENDIF
5665                    ENDIF
5666                    CYCLE
5667 12                 WRITE(message_string,'(a,2i4)') 'error in file ANTHROPOGENIC_HEAT'//TRIM(coupling_char)//' after line ',i,j
5668                    CALL message( 'usm_read_anthropogenic_heat', 'PA0515', 0, 1, 0, 6, 0 )
5669                ENDDO
5670 13             CLOSE(151)
5671                CYCLE
5672 11             message_string = 'file ANTHROPOGENIC_HEAT'//TRIM(coupling_char)//' does not exist'
5673                CALL message( 'usm_read_anthropogenic_heat', 'PA0516', 1, 2, 0, 6, 0 )
5674            ENDIF
5675           
5676#if defined( __parallel )
5677            CALL MPI_BARRIER( comm2d, ierr )
5678#endif
5679        ENDDO
5680       
5681!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5682!--     read diurnal profiles of heat sources
5683!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5684        aheatprof = 0.0_wp
5685        DO  ii = 0, io_blocks-1
5686            IF ( ii == io_group )  THEN
5687
5688!--             open anthropogenic heat profile file
5689                OPEN( 151, file='ANTHROPOGENIC_HEAT_PROFILE'//TRIM(coupling_char), action='read', &
5690                           status='old', form='formatted', err=21 )
5691                i = 0
5692                DO
5693                    READ( 151, *, err=22, end=23 )  i, k, heat
5694                    IF ( i >= 0  .AND.  i <= 24  .AND.  k <= naheatlayers )  THEN
5695!--                     write heat into the array
5696                        aheatprof(k,i) = heat
5697                    ENDIF
5698                    CYCLE
5699 22                 WRITE(message_string,'(a,i4)') 'error in file ANTHROPOGENIC_HEAT_PROFILE'// &
5700                                                     TRIM(coupling_char)//' after line ',i
5701                    CALL message( 'usm_read_anthropogenic_heat', 'PA0517', 0, 1, 0, 6, 0 )
5702                ENDDO
5703                aheatprof(:,24) = aheatprof(:,0)
5704 23             CLOSE(151)
5705                CYCLE
5706 21             message_string = 'file ANTHROPOGENIC_HEAT_PROFILE'//TRIM(coupling_char)//' does not exist'
5707                CALL message( 'usm_read_anthropogenic_heat', 'PA0518', 1, 2, 0, 6, 0 )
5708            ENDIF
5709           
5710#if defined( __parallel )
5711            CALL MPI_BARRIER( comm2d, ierr )
5712#endif
5713        ENDDO
5714       
5715    END SUBROUTINE usm_read_anthropogenic_heat
5716   
5717
5718!------------------------------------------------------------------------------!
5719! Description:
5720! ------------
5721!> Soubroutine reads t_surf and t_wall data from restart files
5722!------------------------------------------------------------------------------!
5723    SUBROUTINE usm_rrd_local( i, k, nxlf, nxlc, nxl_on_file, nxrf, nxrc,       &
5724                              nxr_on_file, nynf, nync, nyn_on_file, nysf, nysc,&
5725                              nys_on_file, found )
5726
5727
5728       USE control_parameters,                                                 &
5729           ONLY: length, restart_string
5730           
5731       IMPLICIT NONE
5732
5733       INTEGER(iwp)       ::  l                !< index variable for surface type
5734       INTEGER(iwp)       ::  i                !< running index over input files
5735       INTEGER(iwp)       ::  k                !< running index over previous input files covering current local domain
5736       INTEGER(iwp)       ::  ns_h_on_file_usm !< number of horizontal surface elements (urban type) on file
5737       INTEGER(iwp)       ::  nxlc             !< index of left boundary on current subdomain
5738       INTEGER(iwp)       ::  nxlf             !< index of left boundary on former subdomain
5739       INTEGER(iwp)       ::  nxl_on_file      !< index of left boundary on former local domain
5740       INTEGER(iwp)       ::  nxrc             !< index of right boundary on current subdomain
5741       INTEGER(iwp)       ::  nxrf             !< index of right boundary on former subdomain
5742       INTEGER(iwp)       ::  nxr_on_file      !< index of right boundary on former local domain
5743       INTEGER(iwp)       ::  nync             !< index of north boundary on current subdomain
5744       INTEGER(iwp)       ::  nynf             !< index of north boundary on former subdomain
5745       INTEGER(iwp)       ::  nyn_on_file      !< index of north boundary on former local domain
5746       INTEGER(iwp)       ::  nysc             !< index of south boundary on current subdomain
5747       INTEGER(iwp)       ::  nysf             !< index of south boundary on former subdomain
5748       INTEGER(iwp)       ::  nys_on_file      !< index of south boundary on former local domain
5749       
5750       INTEGER(iwp)       ::  ns_v_on_file_usm(0:3) !< number of vertical surface elements (urban type) on file
5751       
5752       INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE, SAVE ::  start_index_on_file 
5753       INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE, SAVE ::  end_index_on_file
5754
5755       LOGICAL, INTENT(OUT)  ::  found 
5756       
5757       REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE   ::  tmp_surf_h, tmp_surf_window_h, tmp_surf_green_h
5758       REAL(wp), DIMENSION(:,:), ALLOCATABLE, SAVE ::  tmp_wall_h, tmp_window_h, tmp_green_h
5759       
5760       TYPE( t_surf_vertical ), DIMENSION(0:3), SAVE ::  tmp_surf_v, tmp_surf_window_v, tmp_surf_green_v
5761       TYPE( t_wall_vertical ), DIMENSION(0:3), SAVE ::  tmp_wall_v, tmp_window_v, tmp_green_v
5762
5763
5764       found = .TRUE.
5765
5766
5767          SELECT CASE ( restart_string(1:length) ) 
5768
5769             CASE ( 'ns_h_on_file_usm') 
5770                IF ( k == 1 )  THEN
5771                   READ ( 13 ) ns_h_on_file_usm
5772               
5773                   IF ( ALLOCATED( tmp_surf_h ) ) DEALLOCATE( tmp_surf_h )
5774                   IF ( ALLOCATED( tmp_wall_h ) ) DEALLOCATE( tmp_wall_h ) 
5775                   IF ( ALLOCATED( tmp_surf_window_h ) )                       &
5776                      DEALLOCATE( tmp_surf_window_h ) 
5777                   IF ( ALLOCATED( tmp_window_h) ) DEALLOCATE( tmp_window_h ) 
5778                   IF ( ALLOCATED( tmp_surf_green_h) )                         &
5779                      DEALLOCATE( tmp_surf_green_h ) 
5780                   IF ( ALLOCATED( tmp_green_h) ) DEALLOCATE( tmp_green_h )
5781 
5782!
5783!--                Allocate temporary arrays for reading data on file. Note,
5784!--                the size of allocated surface elements do not necessarily
5785!--                need  to match the size of present surface elements on
5786!--                current processor, as the number of processors between
5787!--                restarts can change.
5788                   ALLOCATE( tmp_surf_h(1:ns_h_on_file_usm) )
5789                   ALLOCATE( tmp_wall_h(nzb_wall:nzt_wall+1,                   &
5790                                        1:ns_h_on_file_usm) )
5791                   ALLOCATE( tmp_surf_window_h(1:ns_h_on_file_usm) )
5792                   ALLOCATE( tmp_window_h(nzb_wall:nzt_wall+1,                 &
5793                                          1:ns_h_on_file_usm) )
5794                   ALLOCATE( tmp_surf_green_h(1:ns_h_on_file_usm) )
5795                   ALLOCATE( tmp_green_h(nzb_wall:nzt_wall+1,                  &
5796                                         1:ns_h_on_file_usm) )
5797
5798                ENDIF
5799
5800             CASE ( 'ns_v_on_file_usm')
5801                IF ( k == 1 )  THEN
5802                   READ ( 13 ) ns_v_on_file_usm 
5803
5804                   DO  l = 0, 3
5805                      IF ( ALLOCATED( tmp_surf_v(l)%t ) )                      &
5806                         DEALLOCATE( tmp_surf_v(l)%t )
5807                      IF ( ALLOCATED( tmp_wall_v(l)%t ) )                      &
5808                         DEALLOCATE( tmp_wall_v(l)%t )
5809                      IF ( ALLOCATED( tmp_surf_window_v(l)%t ) )               & 
5810                         DEALLOCATE( tmp_surf_window_v(l)%t )
5811                      IF ( ALLOCATED( tmp_window_v(l)%t ) )                    &
5812                         DEALLOCATE( tmp_window_v(l)%t )
5813                      IF ( ALLOCATED( tmp_surf_green_v(l)%t ) )                &
5814                         DEALLOCATE( tmp_surf_green_v(l)%t )
5815                      IF ( ALLOCATED( tmp_green_v(l)%t ) )                     &
5816                         DEALLOCATE( tmp_green_v(l)%t )
5817                   ENDDO 
5818
5819!
5820!--                Allocate temporary arrays for reading data on file. Note,
5821!--                the size of allocated surface elements do not necessarily
5822!--                need to match the size of present surface elements on
5823!--                current processor, as the number of processors between
5824!--                restarts can change.
5825                   DO  l = 0, 3
5826                      ALLOCATE( tmp_surf_v(l)%t(1:ns_v_on_file_usm(l)) )
5827                      ALLOCATE( tmp_wall_v(l)%t(nzb_wall:nzt_wall+1,           &
5828                                                1:ns_v_on_file_usm(l) ) )
5829                      ALLOCATE( tmp_surf_window_v(l)%t(1:ns_v_on_file_usm(l)) )
5830                      ALLOCATE( tmp_window_v(l)%t(nzb_wall:nzt_wall+1,         & 
5831                                                  1:ns_v_on_file_usm(l) ) )
5832                      ALLOCATE( tmp_surf_green_v(l)%t(1:ns_v_on_file_usm(l)) )
5833                      ALLOCATE( tmp_green_v(l)%t(nzb_wall:nzt_wall+1,          &
5834                                                 1:ns_v_on_file_usm(l) ) )
5835                   ENDDO
5836
5837                ENDIF   
5838         
5839             CASE ( 'usm_start_index_h', 'usm_start_index_v'  )   
5840                IF ( k == 1 )  THEN
5841
5842                   IF ( ALLOCATED( start_index_on_file ) )                     &
5843                      DEALLOCATE( start_index_on_file )
5844
5845                   ALLOCATE ( start_index_on_file(nys_on_file:nyn_on_file,     &
5846                                                  nxl_on_file:nxr_on_file) )
5847
5848                   READ ( 13 )  start_index_on_file
5849
5850                ENDIF
5851               
5852             CASE ( 'usm_end_index_h', 'usm_end_index_v' )   
5853                IF ( k == 1 )  THEN
5854
5855                   IF ( ALLOCATED( end_index_on_file ) )                       &
5856                      DEALLOCATE( end_index_on_file )
5857
5858                   ALLOCATE ( end_index_on_file(nys_on_file:nyn_on_file,       &
5859                                                nxl_on_file:nxr_on_file) )
5860
5861                   READ ( 13 )  end_index_on_file
5862
5863                ENDIF
5864         
5865             CASE ( 't_surf_h' )
5866#if defined( __nopointer )                   
5867                IF ( k == 1 )  THEN
5868                   IF ( .NOT.  ALLOCATED( t_surf_h ) )                         &
5869                      ALLOCATE( t_surf_h(1:surf_usm_h%ns) )
5870                   READ ( 13 )  tmp_surf_h
5871                ENDIF
5872                CALL surface_restore_elements(                                 &
5873                                        t_surf_h, tmp_surf_h,                  &
5874                                        surf_usm_h%start_index,                & 
5875                                        start_index_on_file,                   &
5876                                        end_index_on_file,                     &
5877                                        nxlc, nysc,                            &
5878                                        nxlf, nxrf, nysf, nynf,                &
5879                                        nys_on_file, nyn_on_file,              &
5880                                        nxl_on_file,nxr_on_file )
5881#else                 
5882                IF ( k == 1 )  THEN
5883                   IF ( .NOT.  ALLOCATED( t_surf_h_1 ) )                       &
5884                      ALLOCATE( t_surf_h_1(1:surf_usm_h%ns) )
5885                   READ ( 13 )  tmp_surf_h
5886                ENDIF             
5887                CALL surface_restore_elements(                                 &
5888                                        t_surf_h_1, tmp_surf_h,                &
5889                                        surf_usm_h%start_index,                & 
5890                                        start_index_on_file,                   &
5891                                        end_index_on_file,                     &
5892                                        nxlc, nysc,                            &
5893                                        nxlf, nxrf, nysf, nynf,                &
5894                                        nys_on_file, nyn_on_file,              &
5895                                        nxl_on_file,nxr_on_file )
5896#endif
5897
5898             CASE ( 't_surf_v(0)' )
5899#if defined( __nopointer )           
5900                IF ( k == 1 )  THEN
5901                   IF ( .NOT.  ALLOCATED( t_surf_v(0)%t ) )                    &
5902                      ALLOCATE( t_surf_v(0)%t(1:surf_usm_v(0)%ns) )
5903                   READ ( 13 )  tmp_surf_v(0)%t
5904                ENDIF
5905                CALL surface_restore_elements(                                 &
5906                                        t_surf_v(0)%t, tmp_surf_v(0)%t,        &
5907                                        surf_usm_v(0)%start_index,             &
5908                                        start_index_on_file,                   &
5909                                        end_index_on_file,                     &
5910                                        nxlc, nysc,                            &
5911                                        nxlf, nxrf, nysf, nynf,                &
5912                                        nys_on_file, nyn_on_file,              &
5913                                        nxl_on_file,nxr_on_file )
5914#else                     
5915                IF ( k == 1 )  THEN
5916                   IF ( .NOT.  ALLOCATED( t_surf_v_1(0)%t ) )                  &
5917                      ALLOCATE( t_surf_v_1(0)%t(1:surf_usm_v(0)%ns) )
5918                   READ ( 13 )  tmp_surf_v(0)%t
5919                ENDIF
5920                CALL surface_restore_elements(                                 &
5921                                        t_surf_v_1(0)%t, tmp_surf_v(0)%t,      &
5922                                        surf_usm_v(0)%start_index,             & 
5923                                        start_index_on_file,                   &
5924                                        end_index_on_file,                     &
5925                                        nxlc, nysc,                            &
5926                                        nxlf, nxrf, nysf, nynf,                &
5927                                        nys_on_file, nyn_on_file,              &
5928                                        nxl_on_file,nxr_on_file )
5929#endif
5930                     
5931             CASE ( 't_surf_v(1)' )
5932#if defined( __nopointer )       
5933                IF ( k == 1 )  THEN
5934                   IF ( .NOT.  ALLOCATED( t_surf_v(1)%t ) )                    &
5935                      ALLOCATE( t_surf_v(1)%t(1:surf_usm_v(1)%ns) )
5936                   READ ( 13 )  tmp_surf_v(1)%t
5937                ENDIF
5938                CALL surface_restore_elements(                                 &
5939                                        t_surf_v(1)%t, tmp_surf_v(1)%t,        &
5940                                        surf_usm_v(1)%start_index,             & 
5941                                        start_index_on_file,                   &
5942                                        end_index_on_file,                     &
5943                                        nxlc, nysc,                            &
5944                                        nxlf, nxrf, nysf, nynf,                &
5945                                        nys_on_file, nyn_on_file,              &
5946                                        nxl_on_file,nxr_on_file )                 
5947#else                     
5948                IF ( k == 1 )  THEN
5949                   IF ( .NOT.  ALLOCATED( t_surf_v_1(1)%t ) )                  &
5950                      ALLOCATE( t_surf_v_1(1)%t(1:surf_usm_v(1)%ns) )
5951                   READ ( 13 )  tmp_surf_v(1)%t
5952                ENDIF
5953                CALL surface_restore_elements(                                 &
5954                                        t_surf_v_1(1)%t, tmp_surf_v(1)%t,      &
5955                                        surf_usm_v(1)%start_index,             & 
5956                                        start_index_on_file,                   &
5957                                        end_index_on_file,                     &
5958                                        nxlc, nysc,                            &
5959                                        nxlf, nxrf, nysf, nynf,                &
5960                                        nys_on_file, nyn_on_file,              &
5961                                        nxl_on_file,nxr_on_file )
5962#endif
5963
5964             CASE ( 't_surf_v(2)' )
5965#if defined( __nopointer )         
5966                IF ( k == 1 )  THEN
5967                   IF ( .NOT.  ALLOCATED( t_surf_v(2)%t ) )                    &
5968                      ALLOCATE( t_surf_v(2)%t(1:surf_usm_v(2)%ns) )
5969                   READ ( 13 )  tmp_surf_v(2)%t
5970                ENDIF
5971                CALL surface_restore_elements(                                 &
5972                                        t_surf_v(2)%t, tmp_surf_v(2)%t,        &
5973                                        surf_usm_v(2)%start_index,             & 
5974                                        start_index_on_file,                   &
5975                                        end_index_on_file,                     &
5976                                        nxlc, nysc,                            &
5977                                        nxlf, nxrf, nysf, nynf,                &
5978                                        nys_on_file, nyn_on_file,              &
5979                                        nxl_on_file,nxr_on_file )
5980#else                     
5981                IF ( k == 1 )  THEN
5982                   IF ( .NOT.  ALLOCATED( t_surf_v_1(2)%t ) )                  &
5983                      ALLOCATE( t_surf_v_1(2)%t(1:surf_usm_v(2)%ns) )
5984                   READ ( 13 )  tmp_surf_v(2)%t
5985                ENDIF
5986                CALL surface_restore_elements(                                 &
5987                                        t_surf_v_1(2)%t, tmp_surf_v(2)%t,      &
5988                                        surf_usm_v(2)%start_index,             & 
5989                                        start_index_on_file,                   &
5990                                        end_index_on_file,                     &
5991                                        nxlc, nysc,                            &
5992                                        nxlf, nxrf, nysf, nynf,                &
5993                                        nys_on_file, nyn_on_file,              &
5994                                        nxl_on_file,nxr_on_file )
5995#endif
5996                     
5997             CASE ( 't_surf_v(3)' )
5998#if defined( __nopointer )   
5999                IF ( k == 1 )  THEN
6000                   IF ( .NOT.  ALLOCATED( t_surf_v(3)%t ) )                    &
6001                      ALLOCATE( t_surf_v(3)%t(1:surf_usm_v(3)%ns) )
6002                   READ ( 13 )  tmp_surf_v(3)%t
6003                ENDIF
6004                CALL surface_restore_elements(                                 &
6005                                        t_surf_v(3)%t, tmp_surf_v(3)%t,        &
6006                                        surf_usm_v(3)%start_index,             & 
6007                                        start_index_on_file,                   &
6008                                        end_index_on_file,                     &
6009                                        nxlc, nysc,                            &
6010                                        nxlf, nxrf, nysf, nynf,                &
6011                                        nys_on_file, nyn_on_file,              &
6012                                        nxl_on_file,nxr_on_file )
6013#else                     
6014                IF ( k == 1 )  THEN
6015                   IF ( .NOT.  ALLOCATED( t_surf_v_1(3)%t ) )                  &
6016                      ALLOCATE( t_surf_v_1(3)%t(1:surf_usm_v(3)%ns) )
6017                   READ ( 13 )  tmp_surf_v(3)%t
6018                ENDIF
6019                CALL surface_restore_elements(                                 &
6020                                        t_surf_v_1(3)%t, tmp_surf_v(3)%t,      &
6021                                        surf_usm_v(3)%start_index,             & 
6022                                        start_index_on_file,                   &
6023                                        end_index_on_file,                     &
6024                                        nxlc, nysc,                            &
6025                                        nxlf, nxrf, nysf, nynf,                &
6026                                        nys_on_file, nyn_on_file,              &
6027                                        nxl_on_file,nxr_on_file )
6028#endif
6029             CASE ( 't_surf_green_h' )
6030#if defined( __nopointer )                   
6031                IF ( k == 1 )  THEN
6032                   IF ( .NOT.  ALLOCATED( t_surf_green_h ) )                   &
6033                      ALLOCATE( t_surf_green_h(1:surf_usm_h%ns) )
6034                   READ ( 13 )  tmp_surf_green_h
6035                ENDIF
6036                CALL surface_restore_elements(                                 &
6037                                        t_surf_green_h, tmp_surf_green_h,      &
6038                                        surf_usm_h%start_index,                & 
6039                                        start_index_on_file,                   &
6040                                        end_index_on_file,                     &
6041                                        nxlc, nysc,                            &
6042                                        nxlf, nxrf, nysf, nynf,                &
6043                                        nys_on_file, nyn_on_file,              &
6044                                        nxl_on_file,nxr_on_file )
6045#else                     
6046                IF ( k == 1 )  THEN
6047                   IF ( .NOT.  ALLOCATED( t_surf_green_h_1 ) )                 &
6048                      ALLOCATE( t_surf_green_h_1(1:surf_usm_h%ns) )
6049                   READ ( 13 )  tmp_surf_green_h
6050                ENDIF
6051                CALL surface_restore_elements(                                 &
6052                                        t_surf_green_h_1, tmp_surf_green_h,    &
6053                                        surf_usm_h%start_index,                & 
6054                                        start_index_on_file,                   &
6055                                        end_index_on_file,                     &
6056                                        nxlc, nysc,                            &
6057                                        nxlf, nxrf, nysf, nynf,                &
6058                                        nys_on_file, nyn_on_file,              &
6059                                        nxl_on_file,nxr_on_file )
6060#endif
6061
6062             CASE ( 't_surf_green_v(0)' )
6063#if defined( __nopointer )           
6064                IF ( k == 1 )  THEN
6065                   IF ( .NOT.  ALLOCATED( t_surf_green_v(0)%t ) )              &
6066                      ALLOCATE( t_surf_green_v(0)%t(1:surf_usm_v(0)%ns) )
6067                   READ ( 13 )  tmp_surf_green_v(0)%t
6068                ENDIF
6069                CALL surface_restore_elements(                                 &
6070                                        t_surf_green_v(0)%t,                   &
6071                                        tmp_surf_green_v(0)%t,                 &
6072                                        surf_usm_v(0)%start_index,             & 
6073                                        start_index_on_file,                   &
6074                                        end_index_on_file,                     &
6075                                        nxlc, nysc,                            &
6076                                        nxlf, nxrf, nysf, nynf,                &
6077                                        nys_on_file, nyn_on_file,              &
6078                                        nxl_on_file,nxr_on_file )
6079#else                     
6080                IF ( k == 1 )  THEN
6081                   IF ( .NOT.  ALLOCATED( t_surf_green_v_1(0)%t ) )            &
6082                      ALLOCATE( t_surf_green_v_1(0)%t(1:surf_usm_v(0)%ns) )
6083                   READ ( 13 )  tmp_surf_green_v(0)%t
6084                ENDIF
6085                CALL surface_restore_elements(                                 &
6086                                        t_surf_green_v_1(0)%t,                 &
6087                                        tmp_surf_green_v(0)%t,                 &
6088                                        surf_usm_v(0)%start_index,             & 
6089                                        start_index_on_file,                   &
6090                                        end_index_on_file,                     &
6091                                        nxlc, nysc,                            &
6092                                        nxlf, nxrf, nysf, nynf,                &
6093                                        nys_on_file, nyn_on_file,              &
6094                                        nxl_on_file,nxr_on_file )
6095#endif
6096                   
6097             CASE ( 't_surf_green_v(1)' )
6098#if defined( __nopointer )       
6099                IF ( k == 1 )  THEN
6100                   IF ( .NOT.  ALLOCATED( t_surf_green_v(1)%t ) )              &
6101                      ALLOCATE( t_surf_green_v(1)%t(1:surf_usm_v(1)%ns) )
6102                   READ ( 13 )  tmp_surf_green_v(1)%t
6103                ENDIF
6104                CALL surface_restore_elements(                                 &
6105                                        t_surf_green_v(1)%t,                   &
6106                                        tmp_surf_green_v(1)%t,                 &
6107                                        surf_usm_v(1)%start_index,             & 
6108                                        start_index_on_file,                   &
6109                                        end_index_on_file,                     &
6110                                        nxlc, nysc,                            &
6111                                        nxlf, nxrf, nysf, nynf,                &
6112                                        nys_on_file, nyn_on_file,              &
6113                                        nxl_on_file,nxr_on_file )                 
6114#else                     
6115                IF ( k == 1 )  THEN
6116                   IF ( .NOT.  ALLOCATED( t_surf_green_v_1(1)%t ) )            &
6117                      ALLOCATE( t_surf_green_v_1(1)%t(1:surf_usm_v(1)%ns) )
6118                   READ ( 13 )  tmp_surf_green_v(1)%t
6119                ENDIF
6120                CALL surface_restore_elements(                                 &
6121                                        t_surf_green_v_1(1)%t,                 &
6122                                        tmp_surf_green_v(1)%t,                 &
6123                                        surf_usm_v(1)%start_index,             & 
6124                                        start_index_on_file,                   &
6125                                        end_index_on_file,                     &
6126                                        nxlc, nysc,                            &
6127                                        nxlf, nxrf, nysf, nynf,                &
6128                                        nys_on_file, nyn_on_file,              &
6129                                        nxl_on_file,nxr_on_file )
6130#endif
6131
6132             CASE ( 't_surf_green_v(2)' )
6133#if defined( __nopointer )         
6134                IF ( k == 1 )  THEN
6135                   IF ( .NOT.  ALLOCATED( t_surf_green_v(2)%t ) )              &
6136                      ALLOCATE( t_surf_green_v(2)%t(1:surf_usm_v(2)%ns) )
6137                   READ ( 13 )  tmp_surf_green_v(2)%t
6138                ENDIF
6139                CALL surface_restore_elements(                                 &
6140                                        t_surf_green_v(2)%t,                   & 
6141                                        tmp_surf_green_v(2)%t,                 &
6142                                        surf_usm_v(2)%start_index,             & 
6143                                        start_index_on_file,                   &
6144                                        end_index_on_file,                     &
6145                                        nxlc, nysc,                            &
6146                                        nxlf, nxrf, nysf, nynf,                &
6147                                        nys_on_file, nyn_on_file,              &
6148                                        nxl_on_file,nxr_on_file )
6149#else                     
6150                IF ( k == 1 )  THEN
6151                   IF ( .NOT.  ALLOCATED( t_surf_green_v_1(2)%t ) )            &
6152                      ALLOCATE( t_surf_green_v_1(2)%t(1:surf_usm_v(2)%ns) )
6153                   READ ( 13 )  tmp_surf_green_v(2)%t
6154                ENDIF
6155                CALL surface_restore_elements(                                 &
6156                                        t_surf_green_v_1(2)%t,                 &
6157                                        tmp_surf_green_v(2)%t,                 &
6158                                        surf_usm_v(2)%start_index,             & 
6159                                        start_index_on_file,                   &
6160                                        end_index_on_file,                     &
6161                                        nxlc, nysc,                            &
6162                                        nxlf, nxrf, nysf, nynf,                &
6163                                        nys_on_file, nyn_on_file,              &
6164                                        nxl_on_file,nxr_on_file )
6165#endif
6166                   
6167             CASE ( 't_surf_green_v(3)' )
6168#if defined( __nopointer )   
6169                IF ( k == 1 )  THEN
6170                   IF ( .NOT.  ALLOCATED( t_surf_green_v(3)%t ) )              &
6171                      ALLOCATE( t_surf_green_v(3)%t(1:surf_usm_v(3)%ns) )
6172                   READ ( 13 )  tmp_surf_green_v(3)%t
6173                ENDIF
6174                CALL surface_restore_elements(                                 &
6175                                        t_surf_green_v(3)%t,                   &
6176                                        tmp_surf_green_v(3)%t,                 &
6177                                        surf_usm_v(3)%start_index,             & 
6178                                        start_index_on_file,                   &
6179                                        end_index_on_file,                     &
6180                                        nxlc, nysc,                            &
6181                                        nxlf, nxrf, nysf, nynf,                &
6182                                        nys_on_file, nyn_on_file,              &
6183                                        nxl_on_file,nxr_on_file )
6184#else                     
6185                IF ( k == 1 )  THEN
6186                   IF ( .NOT.  ALLOCATED( t_surf_green_v_1(3)%t ) )            &
6187                      ALLOCATE( t_surf_green_v_1(3)%t(1:surf_usm_v(3)%ns) )
6188                   READ ( 13 )  tmp_surf_green_v(3)%t
6189                ENDIF
6190                CALL surface_restore_elements(                                 &
6191                                        t_surf_green_v_1(3)%t,                 & 
6192                                        tmp_surf_green_v(3)%t,                 &
6193                                        surf_usm_v(3)%start_index,             & 
6194                                        start_index_on_file,                   &
6195                                        end_index_on_file,                     &
6196                                        nxlc, nysc,                            &
6197                                        nxlf, nxrf, nysf, nynf,                &
6198                                        nys_on_file, nyn_on_file,              &
6199                                        nxl_on_file,nxr_on_file )
6200#endif
6201             CASE ( 't_surf_window_h' )
6202#if defined( __nopointer )                   
6203                IF ( k == 1 )  THEN
6204                   IF ( .NOT.  ALLOCATED( t_surf_window_h ) )                  &
6205                      ALLOCATE( t_surf_window_h(1:surf_usm_h%ns) )
6206                   READ ( 13 )  tmp_surf_window_h
6207                ENDIF
6208                CALL surface_restore_elements(                                 &
6209                                        t_surf_window_h, tmp_surf_window_h,    &
6210                                        surf_usm_h%start_index,                & 
6211                                        start_index_on_file,                   &
6212                                        end_index_on_file,                     &
6213                                        nxlc, nysc,                            &
6214                                        nxlf, nxrf, nysf, nynf,                &
6215                                        nys_on_file, nyn_on_file,              &
6216                                        nxl_on_file,nxr_on_file )
6217#else                     
6218                IF ( k == 1 )  THEN
6219                   IF ( .NOT.  ALLOCATED( t_surf_window_h_1 ) )                &
6220                      ALLOCATE( t_surf_window_h_1(1:surf_usm_h%ns) )
6221                   READ ( 13 )  tmp_surf_window_h
6222                ENDIF
6223                CALL surface_restore_elements(                                 &
6224                                        t_surf_window_h_1,                     &
6225                                        tmp_surf_window_h,                     &
6226                                        surf_usm_h%start_index,                & 
6227                                        start_index_on_file,                   &
6228                                        end_index_on_file,                     &
6229                                        nxlc, nysc,                            &
6230                                        nxlf, nxrf, nysf, nynf,                &
6231                                        nys_on_file, nyn_on_file,              &
6232                                        nxl_on_file,nxr_on_file )
6233#endif
6234
6235             CASE ( 't_surf_window_v(0)' )
6236#if defined( __nopointer )           
6237                IF ( k == 1 )  THEN
6238                   IF ( .NOT.  ALLOCATED( t_surf_window_v(0)%t ) )             &
6239                      ALLOCATE( t_surf_window_v(0)%t(1:surf_usm_v(0)%ns) )
6240                   READ ( 13 )  tmp_surf_window_v(0)%t
6241                ENDIF
6242                CALL surface_restore_elements(                                 &
6243                                        t_surf_window_v(0)%t,                  &
6244                                        tmp_surf_window_v(0)%t,                &
6245                                        surf_usm_v(0)%start_index,             & 
6246                                        start_index_on_file,                   &
6247                                        end_index_on_file,                     &
6248                                        nxlc, nysc,                            &
6249                                        nxlf, nxrf, nysf, nynf,                &
6250                                        nys_on_file, nyn_on_file,              &
6251                                        nxl_on_file,nxr_on_file )
6252#else                     
6253                IF ( k == 1 )  THEN
6254                   IF ( .NOT.  ALLOCATED( t_surf_window_v_1(0)%t ) )           &
6255                      ALLOCATE( t_surf_window_v_1(0)%t(1:surf_usm_v(0)%ns) )
6256                   READ ( 13 )  tmp_surf_window_v(0)%t
6257                ENDIF
6258                CALL surface_restore_elements(                                 &
6259                                        t_surf_window_v_1(0)%t,                &
6260                                        tmp_surf_window_v(0)%t,                &
6261                                        surf_usm_v(0)%start_index,             & 
6262                                        start_index_on_file,                   &
6263                                        end_index_on_file,                     &
6264                                        nxlc, nysc,                            &
6265                                        nxlf, nxrf, nysf, nynf,                &
6266                                        nys_on_file, nyn_on_file,              &
6267                                        nxl_on_file,nxr_on_file )
6268#endif
6269                   
6270             CASE ( 't_surf_window_v(1)' )
6271#if defined( __nopointer )       
6272                IF ( k == 1 )  THEN
6273                   IF ( .NOT.  ALLOCATED( t_surf_window_v(1)%t ) )             &
6274                      ALLOCATE( t_surf_window_v(1)%t(1:surf_usm_v(1)%ns) )
6275                   READ ( 13 )  tmp_surf_window_v(1)%t
6276                ENDIF
6277                CALL surface_restore_elements(                                 &
6278                                        t_surf_window_v(1)%t,                  & 
6279                                        tmp_surf_window_v(1)%t,                &
6280                                        surf_usm_v(1)%start_index,             & 
6281                                        start_index_on_file,                   &
6282                                        end_index_on_file,                     &
6283                                        nxlc, nysc,                            &
6284                                        nxlf, nxrf, nysf, nynf,                &
6285                                        nys_on_file, nyn_on_file,              &
6286                                        nxl_on_file,nxr_on_file )                 
6287#else                     
6288                IF ( k == 1 )  THEN
6289                   IF ( .NOT.  ALLOCATED( t_surf_window_v_1(1)%t ) )           &
6290                      ALLOCATE( t_surf_window_v_1(1)%t(1:surf_usm_v(1)%ns) )
6291                   READ ( 13 )  tmp_surf_window_v(1)%t
6292                ENDIF
6293                CALL surface_restore_elements(                                 &
6294                                        t_surf_window_v_1(1)%t,                &
6295                                        tmp_surf_window_v(1)%t,                &
6296                                        surf_usm_v(1)%start_index,             & 
6297                                        start_index_on_file,                   &
6298                                        end_index_on_file,                     &
6299                                        nxlc, nysc,                            &
6300                                        nxlf, nxrf, nysf, nynf,                &
6301                                        nys_on_file, nyn_on_file,              &
6302                                        nxl_on_file,nxr_on_file )
6303#endif
6304
6305             CASE ( 't_surf_window_v(2)' )
6306#if defined( __nopointer )         
6307                IF ( k == 1 )  THEN
6308                   IF ( .NOT.  ALLOCATED( t_surf_window_v(2)%t ) )             &
6309                      ALLOCATE( t_surf_window_v(2)%t(1:surf_usm_v(2)%ns) )
6310                   READ ( 13 )  tmp_surf_window_v(2)%t
6311                ENDIF
6312                CALL surface_restore_elements(                                 &
6313                                        t_surf_window_v(2)%t,                  &
6314                                        tmp_surf_window_v(2)%t,                &
6315                                        surf_usm_v(2)%start_index,             &   
6316                                        start_index_on_file,                   &
6317                                        end_index_on_file,                     &
6318                                        nxlc, nysc,                            &
6319                                        nxlf, nxrf, nysf, nynf,                &
6320                                        nys_on_file, nyn_on_file,              &
6321                                        nxl_on_file,nxr_on_file )
6322#else                     
6323                IF ( k == 1 )  THEN
6324                   IF ( .NOT.  ALLOCATED( t_surf_window_v_1(2)%t ) )           &
6325                      ALLOCATE( t_surf_window_v_1(2)%t(1:surf_usm_v(2)%ns) )
6326                   READ ( 13 )  tmp_surf_window_v(2)%t
6327                ENDIF
6328                CALL surface_restore_elements(                                 &
6329                                        t_surf_window_v_1(2)%t,                & 
6330                                        tmp_surf_window_v(2)%t,                &
6331                                        surf_usm_v(2)%start_index,             & 
6332                                        start_index_on_file,                   &
6333                                        end_index_on_file,                     &
6334                                        nxlc, nysc,                            &
6335                                        nxlf, nxrf, nysf, nynf,                &
6336                                        nys_on_file, nyn_on_file,              &
6337                                        nxl_on_file,nxr_on_file )
6338#endif
6339                   
6340             CASE ( 't_surf_window_v(3)' )
6341#if defined( __nopointer )   
6342                IF ( k == 1 )  THEN
6343                   IF ( .NOT.  ALLOCATED( t_surf_window_v(3)%t ) )             &
6344                      ALLOCATE( t_surf_window_v(3)%t(1:surf_usm_v(3)%ns) )
6345                   READ ( 13 )  tmp_surf_window_v(3)%t
6346                ENDIF
6347                CALL surface_restore_elements(                                 &
6348                                        t_surf_window_v(3)%t,                  &
6349                                        tmp_surf_window_v(3)%t,                &
6350                                        surf_usm_v(3)%start_index,             & 
6351                                        start_index_on_file,                   &
6352                                        end_index_on_file,                     &
6353                                        nxlc, nysc,                            &
6354                                        nxlf, nxrf, nysf, nynf,                &
6355                                        nys_on_file, nyn_on_file,              &
6356                                        nxl_on_file,nxr_on_file )
6357#else                     
6358                IF ( k == 1 )  THEN
6359                   IF ( .NOT.  ALLOCATED( t_surf_window_v_1(3)%t ) )           &
6360                      ALLOCATE( t_surf_window_v_1(3)%t(1:surf_usm_v(3)%ns) )
6361                   READ ( 13 )  tmp_surf_window_v(3)%t
6362                ENDIF
6363                CALL surface_restore_elements(                                 &
6364                                        t_surf_window_v_1(3)%t,                & 
6365                                        tmp_surf_window_v(3)%t,                &
6366                                        surf_usm_v(3)%start_index,             & 
6367                                        start_index_on_file,                   &
6368                                        end_index_on_file,                     &
6369                                        nxlc, nysc,                            &
6370                                        nxlf, nxrf, nysf, nynf,                &
6371                                        nys_on_file, nyn_on_file,              &
6372                                        nxl_on_file,nxr_on_file )
6373#endif
6374             CASE ( 't_wall_h' )
6375#if defined( __nopointer )
6376                IF ( k == 1 )  THEN
6377                   IF ( .NOT.  ALLOCATED( t_wall_h ) )                         &
6378                      ALLOCATE( t_wall_h(nzb_wall:nzt_wall+1,1:surf_usm_h%ns) )
6379                   READ ( 13 )  tmp_wall_h
6380                ENDIF
6381                CALL surface_restore_elements(                                 &
6382                                        t_wall_h, tmp_wall_h,                  &
6383                                        surf_usm_h%start_index,                & 
6384                                        start_index_on_file,                   &
6385                                        end_index_on_file,                     &
6386                                        nxlc, nysc,                            &
6387                                        nxlf, nxrf, nysf, nynf,                &
6388                                        nys_on_file, nyn_on_file,              &
6389                                        nxl_on_file,nxr_on_file )
6390#else
6391                IF ( k == 1 )  THEN
6392                   IF ( .NOT.  ALLOCATED( t_wall_h_1 ) )                       &
6393                      ALLOCATE( t_wall_h_1(nzb_wall:nzt_wall+1,                &
6394                                           1:surf_usm_h%ns) )
6395                   READ ( 13 )  tmp_wall_h
6396                ENDIF
6397                CALL surface_restore_elements(                                 &
6398                                        t_wall_h_1, tmp_wall_h,                &
6399                                        surf_usm_h%start_index,                & 
6400                                        start_index_on_file,                   &
6401                                        end_index_on_file,                     &
6402                                        nxlc, nysc,                            &
6403                                        nxlf, nxrf, nysf, nynf,                &
6404                                        nys_on_file, nyn_on_file,              &
6405                                        nxl_on_file,nxr_on_file )
6406#endif
6407             CASE ( 't_wall_v(0)' )
6408#if defined( __nopointer )
6409                IF ( k == 1 )  THEN
6410                   IF ( .NOT.  ALLOCATED( t_wall_v(0)%t ) )                    &
6411                      ALLOCATE( t_wall_v(0)%t(nzb_wall:nzt_wall+1,             &
6412                                              1:surf_usm_v(0)%ns) )
6413                   READ ( 13 )  tmp_wall_v(0)%t
6414                ENDIF
6415                CALL surface_restore_elements(                                 &
6416                                        t_wall_v(0)%t, tmp_wall_v(0)%t,        &
6417                                        surf_usm_v(0)%start_index,             &   
6418                                        start_index_on_file,                   &
6419                                        end_index_on_file,                     &
6420                                        nxlc, nysc,                            &
6421                                        nxlf, nxrf, nysf, nynf,                &
6422                                        nys_on_file, nyn_on_file,              &
6423                                        nxl_on_file,nxr_on_file )
6424#else
6425                IF ( k == 1 )  THEN
6426                   IF ( .NOT.  ALLOCATED( t_wall_v_1(0)%t ) )                  &
6427                      ALLOCATE( t_wall_v_1(0)%t(nzb_wall:nzt_wall+1,           &
6428                                                1:surf_usm_v(0)%ns) )
6429                   READ ( 13 )  tmp_wall_v(0)%t
6430                ENDIF
6431                CALL surface_restore_elements(                                 &
6432                                        t_wall_v_1(0)%t, tmp_wall_v(0)%t,      &
6433                                        surf_usm_v(0)%start_index,             & 
6434                                        start_index_on_file,                   &
6435                                        end_index_on_file,                     &
6436                                        nxlc, nysc,                            &
6437                                        nxlf, nxrf, nysf, nynf,                &
6438                                        nys_on_file, nyn_on_file,              &
6439                                        nxl_on_file,nxr_on_file )
6440#endif
6441             CASE ( 't_wall_v(1)' )
6442#if defined( __nopointer )
6443                IF ( k == 1 )  THEN
6444                   IF ( .NOT.  ALLOCATED( t_wall_v(1)%t ) )                    &
6445                      ALLOCATE( t_wall_v(1)%t(nzb_wall:nzt_wall+1,             &
6446                                              1:surf_usm_v(1)%ns) )
6447                   READ ( 13 )  tmp_wall_v(1)%t
6448                ENDIF
6449                CALL surface_restore_elements(                                 &
6450                                        t_wall_v(1)%t, tmp_wall_v(1)%t,        &
6451                                        surf_usm_v(1)%start_index,             & 
6452                                        start_index_on_file,                   &
6453                                        end_index_on_file ,                    &
6454                                        nxlc, nysc,                            &
6455                                        nys_on_file, nyn_on_file,              &
6456                                        nxl_on_file, nxr_on_file )
6457#else
6458                IF ( k == 1 )  THEN
6459                   IF ( .NOT.  ALLOCATED( t_wall_v_1(1)%t ) )                  &
6460                      ALLOCATE( t_wall_v_1(1)%t(nzb_wall:nzt_wall+1,           &
6461                                                1:surf_usm_v(1)%ns) )
6462                   READ ( 13 )  tmp_wall_v(1)%t
6463                ENDIF
6464                CALL surface_restore_elements(                                 &
6465                                        t_wall_v_1(1)%t, tmp_wall_v(1)%t,      &
6466                                        surf_usm_v(1)%start_index,             & 
6467                                        start_index_on_file,                   &
6468                                        end_index_on_file,                     &
6469                                        nxlc, nysc,                            &
6470                                        nxlf, nxrf, nysf, nynf,                &
6471                                        nys_on_file, nyn_on_file,              &
6472                                        nxl_on_file,nxr_on_file )
6473#endif
6474             CASE ( 't_wall_v(2)' )
6475#if defined( __nopointer )
6476                IF ( k == 1 )  THEN
6477                   IF ( .NOT.  ALLOCATED( t_wall_v(2)%t ) )                    &
6478                      ALLOCATE( t_wall_v(2)%t(nzb_wall:nzt_wall+1,             &
6479                                              1:surf_usm_v(2)%ns) )
6480                   READ ( 13 )  tmp_wall_v(2)%t
6481                ENDIF
6482                CALL surface_restore_elements(                                 &
6483                                        t_wall_v(2)%t, tmp_wall_v(2)%t,        &
6484                                        surf_usm_v(2)%start_index,             & 
6485                                        start_index_on_file,                   &
6486                                        end_index_on_file,                     &
6487                                        nxlc, nysc,                            &
6488                                        nxlf, nxrf, nysf, nynf,                &
6489                                        nys_on_file, nyn_on_file,              &
6490                                        nxl_on_file,nxr_on_file )
6491#else
6492                IF ( k == 1 )  THEN
6493                   IF ( .NOT.  ALLOCATED( t_wall_v_1(2)%t ) )                  &
6494                      ALLOCATE( t_wall_v_1(2)%t(nzb_wall:nzt_wall+1,           &
6495                                                1:surf_usm_v(2)%ns) )
6496                   READ ( 13 )  tmp_wall_v(2)%t
6497                ENDIF
6498                CALL surface_restore_elements(                                 &
6499                                        t_wall_v_1(2)%t, tmp_wall_v(2)%t,      &
6500                                        surf_usm_v(2)%start_index,             & 
6501                                        start_index_on_file,                   &
6502                                        end_index_on_file ,                    &
6503                                        nxlc, nysc,                            &
6504                                        nxlf, nxrf, nysf, nynf,                &
6505                                        nys_on_file, nyn_on_file,              &
6506                                        nxl_on_file,nxr_on_file )
6507#endif
6508             CASE ( 't_wall_v(3)' )
6509#if defined( __nopointer )
6510                IF ( k == 1 )  THEN
6511                   IF ( .NOT.  ALLOCATED( t_wall_v(3)%t ) )                    &
6512                      ALLOCATE( t_wall_v(3)%t(nzb_wall:nzt_wall+1,             &
6513                                              1:surf_usm_v(3)%ns) )
6514                   READ ( 13 )  tmp_wall_v(3)%t
6515                ENDIF
6516                CALL surface_restore_elements(                                 &
6517                                        t_wall_v(3)%t, tmp_wall_v(3)%t,        &
6518                                        surf_usm_v(3)%start_index,             &   
6519                                        start_index_on_file,                   &
6520                                        end_index_on_file,                     &
6521                                        nxlc, nysc,                            &
6522                                        nxlf, nxrf, nysf, nynf,                &
6523                                        nys_on_file, nyn_on_file,              &
6524                                        nxl_on_file,nxr_on_file )
6525#else
6526                IF ( k == 1 )  THEN
6527                   IF ( .NOT.  ALLOCATED( t_wall_v_1(3)%t ) )                  &
6528                      ALLOCATE( t_wall_v_1(3)%t(nzb_wall:nzt_wall+1,           &
6529                                                1:surf_usm_v(3)%ns) )
6530                   READ ( 13 )  tmp_wall_v(3)%t
6531                ENDIF
6532                CALL surface_restore_elements(                                 &
6533                                        t_wall_v_1(3)%t, tmp_wall_v(3)%t,      &
6534                                        surf_usm_v(3)%start_index,             &   
6535                                        start_index_on_file,                   &
6536                                        end_index_on_file,                     &
6537                                        nxlc, nysc,                            &
6538                                        nxlf, nxrf, nysf, nynf,                &
6539                                        nys_on_file, nyn_on_file,              &
6540                                        nxl_on_file,nxr_on_file )
6541#endif
6542             CASE ( 't_green_h' )
6543#if defined( __nopointer )
6544                IF ( k == 1 )  THEN
6545                   IF ( .NOT.  ALLOCATED( t_green_h ) )                        &
6546                      ALLOCATE( t_green_h(nzb_wall:nzt_wall+1,                 &
6547                                          1:surf_usm_h%ns) )
6548                   READ ( 13 )  tmp_green_h
6549                ENDIF
6550                CALL surface_restore_elements(                                 &
6551                                        t_green_h, tmp_green_h,                &
6552                                        surf_usm_h%start_index,                & 
6553                                        start_index_on_file,                   &
6554                                        end_index_on_file,                     &
6555                                        nxlc, nysc,                            &
6556                                        nxlf, nxrf, nysf, nynf,                &
6557                                        nys_on_file, nyn_on_file,              &
6558                                        nxl_on_file,nxr_on_file )
6559#else
6560                IF ( k == 1 )  THEN
6561                   IF ( .NOT.  ALLOCATED( t_green_h_1 ) )                      &
6562                      ALLOCATE( t_green_h_1(nzb_wall:nzt_wall+1,               &
6563                                            1:surf_usm_h%ns) )
6564                   READ ( 13 )  tmp_green_h
6565                ENDIF
6566                CALL surface_restore_elements(                                 &
6567                                        t_green_h_1, tmp_green_h,              &
6568                                        surf_usm_h%start_index,                & 
6569                                        start_index_on_file,                   &
6570                                        end_index_on_file,                     &
6571                                        nxlc, nysc,                            &
6572                                        nxlf, nxrf, nysf, nynf,                &
6573                                        nys_on_file, nyn_on_file,              &
6574                                        nxl_on_file,nxr_on_file )
6575#endif
6576             CASE ( 't_green_v(0)' )
6577#if defined( __nopointer )
6578                IF ( k == 1 )  THEN
6579                   IF ( .NOT.  ALLOCATED( t_green_v(0)%t ) )                   &
6580                      ALLOCATE( t_green_v(0)%t(nzb_wall:nzt_wall+1,            &
6581                                               1:surf_usm_v(0)%ns) )
6582                   READ ( 13 )  tmp_green_v(0)%t
6583                ENDIF
6584                CALL surface_restore_elements(                                 &
6585                                        t_green_v(0)%t, tmp_green_v(0)%t,      &
6586                                        surf_usm_v(0)%start_index,             & 
6587                                        start_index_on_file,                   &
6588                                        end_index_on_file,                     &
6589                                        nxlc, nysc,                            &
6590                                        nxlf, nxrf, nysf, nynf,                &
6591                                        nys_on_file, nyn_on_file,              &
6592                                        nxl_on_file,nxr_on_file )
6593#else
6594                IF ( k == 1 )  THEN
6595                   IF ( .NOT.  ALLOCATED( t_green_v_1(0)%t ) )                 &
6596                      ALLOCATE( t_green_v_1(0)%t(nzb_wall:nzt_wall+1,          &
6597                                                 1:surf_usm_v(0)%ns) )
6598                   READ ( 13 )  tmp_green_v(0)%t
6599                ENDIF
6600                CALL surface_restore_elements(                                 &
6601                                        t_green_v_1(0)%t, tmp_green_v(0)%t,    &
6602                                        surf_usm_v(0)%start_index,             & 
6603                                        start_index_on_file,                   &
6604                                        end_index_on_file,                     &
6605                                        nxlc, nysc,                            &
6606                                        nxlf, nxrf, nysf, nynf,                &
6607                                        nys_on_file, nyn_on_file,              &
6608                                        nxl_on_file,nxr_on_file )
6609#endif
6610             CASE ( 't_green_v(1)' )
6611#if defined( __nopointer )
6612                IF ( k == 1 )  THEN
6613                   IF ( .NOT.  ALLOCATED( t_green_v(1)%t ) )                   &
6614                      ALLOCATE( t_green_v(1)%t(nzb_wall:nzt_wall+1,            &
6615                                               1:surf_usm_v(1)%ns) )
6616                   READ ( 13 )  tmp_green_v(1)%t
6617                ENDIF
6618                CALL surface_restore_elements(                                 &
6619                                        t_green_v(1)%t, tmp_green_v(1)%t,      &
6620                                        surf_usm_v(1)%start_index,             & 
6621                                        start_index_on_file,                   &
6622                                        end_index_on_file ,                    &
6623                                        nxlc, nysc,                            &
6624                                        nys_on_file, nyn_on_file,              &
6625                                        nxl_on_file,nxr_on_file )
6626#else
6627                IF ( k == 1 )  THEN
6628                   IF ( .NOT.  ALLOCATED( t_green_v_1(1)%t ) )                 &
6629                      ALLOCATE( t_green_v_1(1)%t(nzb_wall:nzt_wall+1,          &
6630                                                 1:surf_usm_v(1)%ns) )
6631                   READ ( 13 )  tmp_green_v(1)%t
6632                ENDIF
6633                CALL surface_restore_elements(                                 &
6634                                        t_green_v_1(1)%t, tmp_green_v(1)%t,    &
6635                                        surf_usm_v(1)%start_index,             & 
6636                                        start_index_on_file,                   &
6637                                        end_index_on_file,                     &
6638                                        nxlc, nysc,                            &
6639                                        nxlf, nxrf, nysf, nynf,                &
6640                                        nys_on_file, nyn_on_file,              &
6641                                        nxl_on_file,nxr_on_file )
6642#endif
6643             CASE ( 't_green_v(2)' )
6644#if defined( __nopointer )
6645                IF ( k == 1 )  THEN
6646                   IF ( .NOT.  ALLOCATED( t_green_v(2)%t ) )                   &
6647                      ALLOCATE( t_green_v(2)%t(nzb_wall:nzt_wall+1,            &
6648                                               1:surf_usm_v(2)%ns) )
6649                   READ ( 13 )  tmp_green_v(2)%t
6650                ENDIF
6651                CALL surface_restore_elements(                                 &
6652                                        t_green_v(2)%t, tmp_green_v(2)%t,      &
6653                                        surf_usm_v(2)%start_index,             & 
6654                                        start_index_on_file,                   &
6655                                        end_index_on_file,                     &
6656                                        nxlc, nysc,                            &
6657                                        nxlf, nxrf, nysf, nynf,                &
6658                                        nys_on_file, nyn_on_file,              &
6659                                        nxl_on_file,nxr_on_file )
6660#else
6661                IF ( k == 1 )  THEN
6662                   IF ( .NOT.  ALLOCATED( t_green_v_1(2)%t ) )                 &
6663                      ALLOCATE( t_green_v_1(2)%t(nzb_wall:nzt_wall+1,          &
6664                                                 1:surf_usm_v(2)%ns) )
6665                   READ ( 13 )  tmp_green_v(2)%t
6666                ENDIF
6667                CALL surface_restore_elements(                                 &
6668                                        t_green_v_1(2)%t, tmp_green_v(2)%t,    &
6669                                        surf_usm_v(2)%start_index,             & 
6670                                        start_index_on_file,                   &
6671                                        end_index_on_file ,                    &
6672                                        nxlc, nysc,                            &
6673                                        nxlf, nxrf, nysf, nynf,                &
6674                                        nys_on_file, nyn_on_file,              &
6675                                        nxl_on_file,nxr_on_file )
6676#endif
6677             CASE ( 't_green_v(3)' )
6678#if defined( __nopointer )
6679                IF ( k == 1 )  THEN
6680                   IF ( .NOT.  ALLOCATED( t_green_v(3)%t ) )                   &
6681                      ALLOCATE( t_green_v(3)%t(nzb_wall:nzt_wall+1,            &
6682                                               1:surf_usm_v(3)%ns) )
6683                   READ ( 13 )  tmp_green_v(3)%t
6684                ENDIF
6685                CALL surface_restore_elements(                                 &
6686                                        t_green_v(3)%t, tmp_green_v(3)%t,      &
6687                                        surf_usm_v(3)%start_index,             & 
6688                                        start_index_on_file,                   &
6689                                        end_index_on_file,                     &
6690                                        nxlc, nysc,                            &
6691                                        nxlf, nxrf, nysf, nynf,                &
6692                                        nys_on_file, nyn_on_file,              &
6693                                        nxl_on_file,nxr_on_file )
6694#else
6695                IF ( k == 1 )  THEN
6696                   IF ( .NOT.  ALLOCATED( t_green_v_1(3)%t ) )                 &
6697                      ALLOCATE( t_green_v_1(3)%t(nzb_wall:nzt_wall+1,          &
6698                                                 1:surf_usm_v(3)%ns) )
6699                   READ ( 13 )  tmp_green_v(3)%t
6700                ENDIF
6701                CALL surface_restore_elements(                                 &
6702                                        t_green_v_1(3)%t, tmp_green_v(3)%t,    &
6703                                        surf_usm_v(3)%start_index,             & 
6704                                        start_index_on_file,                   &
6705                                        end_index_on_file,                     &
6706                                        nxlc, nysc,                            &
6707                                        nxlf, nxrf, nysf, nynf,                &
6708                                        nys_on_file, nyn_on_file,              &
6709                                        nxl_on_file,nxr_on_file )
6710#endif
6711             CASE ( 't_window_h' )
6712#if defined( __nopointer )
6713                IF ( k == 1 )  THEN
6714                   IF ( .NOT.  ALLOCATED( t_window_h ) )                       &
6715                      ALLOCATE( t_window_h(nzb_wall:nzt_wall+1,                &
6716                                           1:surf_usm_h%ns) )
6717                   READ ( 13 )  tmp_window_h
6718                ENDIF
6719                CALL surface_restore_elements(                                 &
6720                                        t_window_h, tmp_window_h,              &
6721                                        surf_usm_h%start_index,                & 
6722                                        start_index_on_file,                   &
6723                                        end_index_on_file,                     &
6724                                        nxlc, nysc,                            &
6725                                        nxlf, nxrf, nysf, nynf,                &
6726                                        nys_on_file, nyn_on_file,              &
6727                                        nxl_on_file,nxr_on_file )
6728#else
6729                IF ( k == 1 )  THEN
6730                   IF ( .NOT.  ALLOCATED( t_window_h_1 ) )                     &
6731                      ALLOCATE( t_window_h_1(nzb_wall:nzt_wall+1,              &
6732                                             1:surf_usm_h%ns) )
6733                   READ ( 13 )  tmp_window_h
6734                ENDIF
6735                CALL surface_restore_elements(                                 &
6736                                        t_window_h_1, tmp_window_h,            &
6737                                        surf_usm_h%start_index,                & 
6738                                        start_index_on_file,                   &
6739                                        end_index_on_file,                     &
6740                                        nxlc, nysc,                            &
6741                                        nxlf, nxrf, nysf, nynf,                &
6742                                        nys_on_file, nyn_on_file,              &
6743                                        nxl_on_file, nxr_on_file )
6744#endif
6745             CASE ( 't_window_v(0)' )
6746#if defined( __nopointer )
6747                IF ( k == 1 )  THEN
6748                   IF ( .NOT.  ALLOCATED( t_window_v(0)%t ) )                  &
6749                      ALLOCATE( t_window_v(0)%t(nzb_wall:nzt_wall+1,           &
6750                                                1:surf_usm_v(0)%ns) )
6751                   READ ( 13 )  tmp_window_v(0)%t
6752                ENDIF
6753                CALL surface_restore_elements(                                 &
6754                                        t_window_v(0)%t, tmp_window_v(0)%t,    &
6755                                        surf_usm_v(0)%start_index,             & 
6756                                        start_index_on_file,                   &
6757                                        end_index_on_file,                     &
6758                                        nxlc, nysc,                            &
6759                                        nxlf, nxrf, nysf, nynf,                &
6760                                        nys_on_file, nyn_on_file,              &
6761                                        nxl_on_file, nxr_on_file )
6762#else
6763                IF ( k == 1 )  THEN
6764                   IF ( .NOT.  ALLOCATED( t_window_v_1(0)%t ) )                &
6765                      ALLOCATE( t_window_v_1(0)%t(nzb_wall:nzt_wall+1,         &
6766                                                  1:surf_usm_v(0)%ns) )
6767                   READ ( 13 )  tmp_window_v(0)%t
6768                ENDIF
6769                CALL surface_restore_elements(                                 &
6770                                        t_window_v_1(0)%t,                     & 
6771                                        tmp_window_v(0)%t,                     &
6772                                        surf_usm_v(0)%start_index,             &
6773                                        start_index_on_file,                   &
6774                                        end_index_on_file,                     &
6775                                        nxlc, nysc,                            &
6776                                        nxlf, nxrf, nysf, nynf,                &
6777                                        nys_on_file, nyn_on_file,              &
6778                                        nxl_on_file,nxr_on_file )
6779#endif
6780             CASE ( 't_window_v(1)' )
6781#if defined( __nopointer )
6782                IF ( k == 1 )  THEN
6783                   IF ( .NOT.  ALLOCATED( t_window_v(1)%t ) )                  &
6784                      ALLOCATE( t_window_v(1)%t(nzb_wall:nzt_wall+1,           &
6785                                                1:surf_usm_v(1)%ns) )
6786                   READ ( 13 )  tmp_window_v(1)%t
6787                ENDIF
6788                CALL surface_restore_elements(                                 &
6789                                        t_window_v(1)%t, tmp_window_v(1)%t,    &
6790                                        surf_usm_v(1)%start_index,             & 
6791                                        start_index_on_file,                   &
6792                                        end_index_on_file ,                    &
6793                                        nxlc, nysc,                            &
6794                                        nys_on_file, nyn_on_file,              &
6795                                        nxl_on_file, nxr_on_file )
6796#else
6797                IF ( k == 1 )  THEN
6798                   IF ( .NOT.  ALLOCATED( t_window_v_1(1)%t ) )                &
6799                      ALLOCATE( t_window_v_1(1)%t(nzb_wall:nzt_wall+1,         &
6800                                                  1:surf_usm_v(1)%ns) )
6801                   READ ( 13 )  tmp_window_v(1)%t
6802                ENDIF
6803                CALL surface_restore_elements(                                 &
6804                                        t_window_v_1(1)%t,                     & 
6805                                        tmp_window_v(1)%t,                     &
6806                                        surf_usm_v(1)%start_index,             & 
6807                                        start_index_on_file,                   &
6808                                        end_index_on_file,                     &
6809                                        nxlc, nysc,                            &
6810                                        nxlf, nxrf, nysf, nynf,                &
6811                                        nys_on_file, nyn_on_file,              &
6812                                        nxl_on_file,nxr_on_file )
6813#endif
6814             CASE ( 't_window_v(2)' )
6815#if defined( __nopointer )
6816                IF ( k == 1 )  THEN
6817                   IF ( .NOT.  ALLOCATED( t_window_v(2)%t ) )                  &
6818                      ALLOCATE( t_window_v(2)%t(nzb_wall:nzt_wall+1,           &
6819                                                1:surf_usm_v(2)%ns) )
6820                   READ ( 13 )  tmp_window_v(2)%t
6821                ENDIF
6822                CALL surface_restore_elements(                                 &
6823                                        t_window_v(2)%t, tmp_window_v(2)%t,    &
6824                                        surf_usm_v(2)%start_index,             & 
6825                                        start_index_on_file,                   &
6826                                        end_index_on_file,                     &
6827                                        nxlc, nysc,                            &
6828                                        nxlf, nxrf, nysf, nynf,                &
6829                                        nys_on_file, nyn_on_file,              &
6830                                        nxl_on_file,nxr_on_file )
6831#else
6832                IF ( k == 1 )  THEN
6833                   IF ( .NOT.  ALLOCATED( t_window_v_1(2)%t ) )                &
6834                      ALLOCATE( t_window_v_1(2)%t(nzb_wall:nzt_wall+1,         &
6835                                                  1:surf_usm_v(2)%ns) )
6836                   READ ( 13 )  tmp_window_v(2)%t
6837                ENDIF
6838                CALL surface_restore_elements(                                 &
6839                                        t_window_v_1(2)%t,                     & 
6840                                        tmp_window_v(2)%t,                     &
6841                                        surf_usm_v(2)%start_index,             & 
6842                                        start_index_on_file,                   &
6843                                        end_index_on_file ,                    &
6844                                        nxlc, nysc,                            &
6845                                        nxlf, nxrf, nysf, nynf,                &
6846                                        nys_on_file, nyn_on_file,              &
6847                                        nxl_on_file,nxr_on_file )
6848#endif
6849             CASE ( 't_window_v(3)' )
6850#if defined( __nopointer )
6851                IF ( k == 1 )  THEN
6852                   IF ( .NOT.  ALLOCATED( t_window_v(3)%t ) )                  &
6853                      ALLOCATE( t_window_v(3)%t(nzb_wall:nzt_wall+1,           &
6854                                                1:surf_usm_v(3)%ns) )
6855                   READ ( 13 )  tmp_window_v(3)%t
6856                ENDIF
6857                CALL surface_restore_elements(                                 &
6858                                        t_window_v(3)%t, tmp_window_v(3)%t,    &
6859                                        surf_usm_v(3)%start_index,             & 
6860                                        start_index_on_file,                   &
6861                                        end_index_on_file,                     &
6862                                        nxlc, nysc,                            &
6863                                        nxlf, nxrf, nysf, nynf,                &
6864                                        nys_on_file, nyn_on_file,              &
6865                                        nxl_on_file,nxr_on_file )
6866#else
6867                IF ( k == 1 )  THEN
6868                   IF ( .NOT.  ALLOCATED( t_window_v_1(3)%t ) )                &
6869                      ALLOCATE( t_window_v_1(3)%t(nzb_wall:nzt_wall+1,1:surf_usm_v(3)%ns) )
6870                   READ ( 13 )  tmp_window_v(3)%t
6871                ENDIF
6872                CALL surface_restore_elements(                                 &
6873                                        t_window_v_1(3)%t,                     & 
6874                                        tmp_window_v(3)%t,                     &
6875                                        surf_usm_v(3)%start_index,             & 
6876                                        start_index_on_file,                   &
6877                                        end_index_on_file,                     &
6878                                        nxlc, nysc,                            &
6879                                        nxlf, nxrf, nysf, nynf,                &
6880                                        nys_on_file, nyn_on_file,              &
6881                                        nxl_on_file,nxr_on_file )
6882#endif
6883             CASE DEFAULT
6884
6885                   found = .FALSE.
6886
6887          END SELECT
6888
6889       
6890    END SUBROUTINE usm_rrd_local
6891   
6892
6893   
6894!------------------------------------------------------------------------------!
6895! Description:
6896! ------------
6897!
6898!> This subroutine reads walls, roofs and land categories and it parameters
6899!> from input files.
6900!------------------------------------------------------------------------------!
6901    SUBROUTINE usm_read_urban_surface_types
6902   
6903        USE netcdf_data_input_mod,                                             &
6904            ONLY:  building_pars_f, building_type_f
6905
6906        IMPLICIT NONE
6907
6908        CHARACTER(12)                                         :: wtn
6909        INTEGER(iwp)                                          :: wtc
6910        REAL(wp), DIMENSION(n_surface_params)                 :: wtp
6911       
6912        LOGICAL                                               :: ascii_file = .FALSE.
6913   
6914        INTEGER(iwp), DIMENSION(0:17, nysg:nyng, nxlg:nxrg)   :: usm_par
6915        REAL(wp), DIMENSION(1:14, nysg:nyng, nxlg:nxrg)       :: usm_val
6916        INTEGER(iwp)                                          :: k, l, iw, jw, kw, it, ip, ii, ij, m
6917        INTEGER(iwp)                                          :: i, j
6918        INTEGER(iwp)                                          :: nz, roof, dirwe, dirsn
6919        INTEGER(iwp)                                          :: category
6920        INTEGER(iwp)                                          :: weheight1, wecat1, snheight1, sncat1
6921        INTEGER(iwp)                                          :: weheight2, wecat2, snheight2, sncat2
6922        INTEGER(iwp)                                          :: weheight3, wecat3, snheight3, sncat3
6923        REAL(wp)                                              :: height, albedo, thick
6924        REAL(wp)                                              :: wealbedo1, wethick1, snalbedo1, snthick1
6925        REAL(wp)                                              :: wealbedo2, wethick2, snalbedo2, snthick2
6926        REAL(wp)                                              :: wealbedo3, wethick3, snalbedo3, snthick3
6927
6928!
6929!--     If building_pars or building_type are already read from static input
6930!--     file, skip reading ASCII file.
6931        IF ( building_type_f%from_file  .OR.  building_pars_f%from_file )      &
6932           RETURN
6933!
6934!--     Check if ASCII input file exists. If not, return and initialize USM
6935!--     with default settings.
6936        INQUIRE( FILE = 'SURFACE_PARAMETERS' // coupling_char,                 &
6937                 EXIST = ascii_file )
6938                 
6939        IF ( .NOT. ascii_file )  RETURN
6940
6941!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6942!--     read categories of walls and their parameters
6943!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6944        DO  ii = 0, io_blocks-1
6945            IF ( ii == io_group )  THEN
6946
6947!--             open urban surface file
6948                OPEN( 151, file='SURFACE_PARAMETERS'//coupling_char, action='read', &
6949                           status='old', form='formatted', err=15 ) 
6950!--             first test and get n_surface_types
6951                k = 0
6952                l = 0
6953                DO
6954                    l = l+1
6955                    READ( 151, *, err=11, end=12 )  wtc, wtp, wtn
6956                    k = k+1
6957                    CYCLE
6958 11                 CONTINUE
6959                ENDDO
6960 12             n_surface_types = k
6961                ALLOCATE( surface_type_names(n_surface_types) )
6962                ALLOCATE( surface_type_codes(n_surface_types) )
6963                ALLOCATE( surface_params(n_surface_params, n_surface_types) )
6964!--             real reading
6965                rewind( 151 )
6966                k = 0
6967                DO
6968                    READ( 151, *, err=13, end=14 )  wtc, wtp, wtn
6969                    k = k+1
6970                    surface_type_codes(k) = wtc
6971                    surface_params(:,k) = wtp
6972                    surface_type_names(k) = wtn
6973                    CYCLE
697413                  WRITE(6,'(i3,a,2i5)') myid, 'readparams2 error k=', k
6975                    FLUSH(6)
6976                    CONTINUE
6977                ENDDO
6978 14             CLOSE(151)
6979                CYCLE
6980 15             message_string = 'file SURFACE_PARAMETERS'//TRIM(coupling_char)//' does not exist'
6981                CALL message( 'usm_read_urban_surface_types', 'PA0513', 1, 2, 0, 6, 0 )
6982            ENDIF
6983        ENDDO
6984   
6985!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6986!--     read types of surfaces
6987!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6988        usm_par = 0
6989        DO  ii = 0, io_blocks-1
6990            IF ( ii == io_group )  THEN
6991
6992                !
6993!--             open csv urban surface file
6994                OPEN( 151, file='URBAN_SURFACE'//TRIM(coupling_char), action='read', &
6995                      status='old', form='formatted', err=23 )
6996               
6997                l = 0
6998                DO
6999                    l = l+1
7000!--                 i, j, height, nz, roof, dirwe, dirsn, category, soilcat,
7001!--                 weheight1, wecat1, snheight1, sncat1, weheight2, wecat2, snheight2, sncat2,
7002!--                 weheight3, wecat3, snheight3, sncat3
7003                    READ( 151, *, err=21, end=25 )  i, j, height, nz, roof, dirwe, dirsn,            &
7004                                            category, albedo, thick,                                 &
7005                                            weheight1, wecat1, wealbedo1, wethick1,                  &
7006                                            weheight2, wecat2, wealbedo2, wethick2,                  &
7007                                            weheight3, wecat3, wealbedo3, wethick3,                  &
7008                                            snheight1, sncat1, snalbedo1, snthick1,                  &
7009                                            snheight2, sncat2, snalbedo2, snthick2,                  &
7010                                            snheight3, sncat3, snalbedo3, snthick3
7011
7012                    IF ( i >= nxlg  .AND.  i <= nxrg  .AND.  j >= nysg  .AND.  j <= nyng )  THEN
7013!--                     write integer variables into array
7014                        usm_par(:,j,i) = (/1, nz, roof, dirwe, dirsn, category,                      &
7015                                          weheight1, wecat1, weheight2, wecat2, weheight3, wecat3,   &
7016                                          snheight1, sncat1, snheight2, sncat2, snheight3, sncat3 /)
7017!--                     write real values into array
7018                        usm_val(:,j,i) = (/ albedo, thick,                                           &
7019                                           wealbedo1, wethick1, wealbedo2, wethick2,                 &
7020                                           wealbedo3, wethick3, snalbedo1, snthick1,                 &
7021                                           snalbedo2, snthick2, snalbedo3, snthick3 /)
7022                    ENDIF
7023                    CYCLE
7024 21                 WRITE (message_string, "(A,I5)") 'errors in file URBAN_SURFACE'//TRIM(coupling_char)//' on line ', l
7025                    CALL message( 'usm_read_urban_surface_types', 'PA0512', 0, 1, 0, 6, 0 )
7026                ENDDO
7027         
7028 23             message_string = 'file URBAN_SURFACE'//TRIM(coupling_char)//' does not exist'
7029                CALL message( 'usm_read_urban_surface_types', 'PA0514', 1, 2, 0, 6, 0 )
7030
7031 25             CLOSE( 151 )
7032
7033            ENDIF
7034#if defined( __parallel )
7035            CALL MPI_BARRIER( comm2d, ierr )
7036#endif
7037        ENDDO
7038       
7039!
7040!--     check completeness and formal correctness of the data
7041        DO i = nxlg, nxrg
7042            DO j = nysg, nyng
7043                IF ( usm_par(0,j,i) /= 0  .AND.  (        &  !< incomplete data,supply default values later
7044                     usm_par(1,j,i) < nzb  .OR.           &
7045                     usm_par(1,j,i) > nzt  .OR.           &  !< incorrect height (nz < nzb  .OR.  nz > nzt)
7046                     usm_par(2,j,i) < 0  .OR.             &
7047                     usm_par(2,j,i) > 1  .OR.             &  !< incorrect roof sign
7048                     usm_par(3,j,i) < nzb-nzt  .OR.       & 
7049                     usm_par(3,j,i) > nzt-nzb  .OR.       &  !< incorrect west-east wall direction sign
7050                     usm_par(4,j,i) < nzb-nzt  .OR.       &
7051                     usm_par(4,j,i) > nzt-nzb  .OR.       &  !< incorrect south-north wall direction sign
7052                     usm_par(6,j,i) < nzb  .OR.           & 
7053                     usm_par(6,j,i) > nzt  .OR.           &  !< incorrect pedestrian level height for west-east wall
7054                     usm_par(8,j,i) > nzt  .OR.           &
7055                     usm_par(10,j,i) > nzt  .OR.          &  !< incorrect wall or roof level height for west-east wall
7056                     usm_par(12,j,i) < nzb  .OR.          & 
7057                     usm_par(12,j,i) > nzt  .OR.          &  !< incorrect pedestrian level height for south-north wall
7058                     usm_par(14,j,i) > nzt  .OR.          &
7059                     usm_par(16,j,i) > nzt                &  !< incorrect wall or roof level height for south-north wall
7060                    ) )  THEN
7061!--                 incorrect input data
7062                    WRITE (message_string, "(A,2I5)") 'missing or incorrect data in file URBAN_SURFACE'// &
7063                                                       TRIM(coupling_char)//' for i,j=', i,j
7064                    CALL message( 'usm_read_urban_surface', 'PA0504', 1, 2, 0, 6, 0 )
7065                ENDIF
7066               
7067            ENDDO
7068        ENDDO
7069!       
7070!--     Assign the surface types to the respective data type.
7071!--     First, for horizontal upward-facing surfaces.
7072!--     Further, set flag indicating that albedo is initialized via ASCII
7073!--     format, else it would be overwritten in the radiation model.
7074        surf_usm_h%albedo_from_ascii = .TRUE.
7075        DO  m = 1, surf_usm_h%ns
7076           iw = surf_usm_h%i(m)
7077           jw = surf_usm_h%j(m)
7078           kw = surf_usm_h%k(m)
7079
7080           IF ( usm_par(5,jw,iw) == 0 )  THEN
7081#if ! defined( __nopointer )
7082              IF ( zu(kw) >= roof_height_limit )  THEN
7083                 surf_usm_h%isroof_surf(m)   = .TRUE.
7084                 surf_usm_h%surface_types(m) = roof_category         !< default category for root surface
7085              ELSE
7086                 surf_usm_h%isroof_surf(m)   = .FALSE.
7087                 surf_usm_h%surface_types(m) = land_category         !< default category for land surface
7088              ENDIF
7089#endif
7090              surf_usm_h%albedo(:,m)    = -1.0_wp
7091              surf_usm_h%thickness_wall(m) = -1.0_wp
7092              surf_usm_h%thickness_green(m) = -1.0_wp
7093              surf_usm_h%thickness_window(m) = -1.0_wp
7094           ELSE
7095              IF ( usm_par(2,jw,iw)==0 )  THEN
7096                 surf_usm_h%isroof_surf(m)    = .FALSE.
7097                 surf_usm_h%thickness_wall(m) = -1.0_wp
7098                 surf_usm_h%thickness_window(m) = -1.0_wp
7099                 surf_usm_h%thickness_green(m)  = -1.0_wp
7100              ELSE
7101                 surf_usm_h%isroof_surf(m)    = .TRUE.
7102                 surf_usm_h%thickness_wall(m) = usm_val(2,jw,iw)
7103                 surf_usm_h%thickness_window(m) = usm_val(2,jw,iw)
7104                 surf_usm_h%thickness_green(m)  = usm_val(2,jw,iw)
7105              ENDIF
7106              surf_usm_h%surface_types(m) = usm_par(5,jw,iw)
7107              surf_usm_h%albedo(:,m)   = usm_val(1,jw,iw)
7108              surf_usm_h%transmissivity(m)    = 0.0_wp
7109           ENDIF
7110!
7111!--        Find the type position
7112           it = surf_usm_h%surface_types(m)
7113           ip = -99999
7114           DO k = 1, n_surface_types
7115              IF ( surface_type_codes(k) == it )  THEN
7116                 ip = k
7117                 EXIT
7118              ENDIF
7119           ENDDO
7120           IF ( ip == -99999 )  THEN
7121!--           land/roof category not found
7122              WRITE (9,"(A,I5,A,3I5)") 'land/roof category ', it,     &
7123                                       ' not found  for i,j,k=', iw,jw,kw
7124              FLUSH(9)
7125              IF ( surf_usm_h%isroof_surf(m) ) THEN
7126                 category = roof_category
7127              ELSE
7128                 category = land_category
7129              ENDIF
7130              DO k = 1, n_surface_types
7131                 IF ( surface_type_codes(k) == roof_category ) THEN
7132                    ip = k
7133                    EXIT
7134                 ENDIF
7135              ENDDO
7136              IF ( ip == -99999 )  THEN
7137!--              default land/roof category not found
7138                 WRITE (9,"(A,I5,A,3I5)") 'Default land/roof category', category, ' not found!'
7139                 FLUSH(9)
7140                 ip = 1
7141              ENDIF
7142           ENDIF
7143!
7144!--        Albedo
7145           IF ( surf_usm_h%albedo(ind_veg_wall,m) < 0.0_wp )  THEN
7146              surf_usm_h%albedo(:,m) = surface_params(ialbedo,ip)
7147           ENDIF
7148!--        Albedo type is 0 (custom), others are replaced later
7149           surf_usm_h%albedo_type(:,m) = 0
7150!--        Transmissivity
7151           IF ( surf_usm_h%transmissivity(m) < 0.0_wp )  THEN
7152              surf_usm_h%transmissivity(m) = 0.0_wp
7153           ENDIF
7154!
7155!--        emissivity of the wall
7156           surf_usm_h%emissivity(:,m) = surface_params(iemiss,ip)
7157!           
7158!--        heat conductivity λS between air and wall ( W m−2 K−1 )
7159           surf_usm_h%lambda_surf(m) = surface_params(ilambdas,ip)
7160           surf_usm_h%lambda_surf_window(m) = surface_params(ilambdas,ip)
7161           surf_usm_h%lambda_surf_green(m)  = surface_params(ilambdas,ip)
7162!           
7163!--        roughness length for momentum, heat and humidity
7164           surf_usm_h%z0(m) = surface_params(irough,ip)
7165           surf_usm_h%z0h(m) = surface_params(iroughh,ip)
7166           surf_usm_h%z0q(m) = surface_params(iroughh,ip)
7167!
7168!--        Surface skin layer heat capacity (J m−2 K−1 )
7169           surf_usm_h%c_surface(m) = surface_params(icsurf,ip)
7170           surf_usm_h%c_surface_window(m) = surface_params(icsurf,ip)
7171           surf_usm_h%c_surface_green(m)  = surface_params(icsurf,ip)
7172!           
7173!--        wall material parameters:
7174!--        thickness of the wall (m)
7175!--        missing values are replaced by default value for category
7176           IF ( surf_usm_h%thickness_wall(m) <= 0.001_wp )  THEN
7177                surf_usm_h%thickness_wall(m) = surface_params(ithick,ip)
7178           ENDIF
7179           IF ( surf_usm_h%thickness_window(m) <= 0.001_wp )  THEN
7180                surf_usm_h%thickness_window(m) = surface_params(ithick,ip)
7181           ENDIF
7182           IF ( surf_usm_h%thickness_green(m) <= 0.001_wp )  THEN
7183                surf_usm_h%thickness_green(m) = surface_params(ithick,ip)
7184           ENDIF
7185!           
7186!--        volumetric heat capacity rho*C of the wall ( J m−3 K−1 )
7187           surf_usm_h%rho_c_wall(:,m) = surface_params(irhoC,ip)
7188           surf_usm_h%rho_c_window(:,m) = surface_params(irhoC,ip)
7189           surf_usm_h%rho_c_green(:,m)  = surface_params(irhoC,ip)
7190!           
7191!--        thermal conductivity λH of the wall (W m−1 K−1 )
7192           surf_usm_h%lambda_h(:,m) = surface_params(ilambdah,ip)
7193           surf_usm_h%lambda_h_window(:,m) = surface_params(ilambdah,ip)
7194           surf_usm_h%lambda_h_green(:,m)  = surface_params(ilambdah,ip)
7195
7196        ENDDO
7197!
7198!--     For vertical surface elements ( 0 -- northward-facing, 1 -- southward-facing,
7199!--     2 -- eastward-facing, 3 -- westward-facing )
7200        DO  l = 0, 3
7201!
7202!--        Set flag indicating that albedo is initialized via ASCII format.
7203!--        Else it would be overwritten in the radiation model.
7204           surf_usm_v(l)%albedo_from_ascii = .TRUE.
7205           DO  m = 1, surf_usm_v(l)%ns
7206              i  = surf_usm_v(l)%i(m)
7207              j  = surf_usm_v(l)%j(m)
7208              kw = surf_usm_v(l)%k(m)
7209             
7210              IF ( l == 3 )  THEN ! westward facing
7211                 iw = i
7212                 jw = j
7213                 ii = 6
7214                 ij = 3
7215              ELSEIF ( l == 2 )  THEN
7216                 iw = i-1
7217                 jw = j
7218                 ii = 6
7219                 ij = 3
7220              ELSEIF ( l == 1 )  THEN
7221                 iw = i
7222                 jw = j
7223                 ii = 12
7224                 ij = 9
7225              ELSEIF ( l == 0 )  THEN
7226                 iw = i
7227                 jw = j-1
7228                 ii = 12
7229                 ij = 9
7230              ENDIF
7231
7232              IF ( iw < 0 .OR. jw < 0 ) THEN
7233!--              wall on west or south border of the domain - assign default category
7234                 IF ( kw <= roof_height_limit ) THEN
7235                     surf_usm_v(l)%surface_types(m) = wall_category   !< default category for wall surface in wall zone
7236                 ELSE
7237                     surf_usm_v(l)%surface_types(m) = roof_category   !< default category for wall surface in roof zone
7238                 END IF
7239                 surf_usm_v(l)%albedo(:,m)    = -1.0_wp
7240                 surf_usm_v(l)%thickness_wall(m) = -1.0_wp
7241                 surf_usm_v(l)%thickness_window(m)   = -1.0_wp
7242                 surf_usm_v(l)%thickness_green(m)    = -1.0_wp
7243                 surf_usm_v(l)%transmissivity(m)  = -1.0_wp
7244              ELSE IF ( kw <= usm_par(ii,jw,iw) )  THEN
7245!--                 pedestrian zone
7246                 IF ( usm_par(ii+1,jw,iw) == 0 )  THEN
7247                     surf_usm_v(l)%surface_types(m)  = pedestrian_category   !< default category for wall surface in pedestrian zone
7248                     surf_usm_v(l)%albedo(:,m)    = -1.0_wp
7249                     surf_usm_v(l)%thickness_wall(m) = -1.0_wp
7250                     surf_usm_v(l)%thickness_window(m)   = -1.0_wp
7251                     surf_usm_v(l)%thickness_green(m)    = -1.0_wp
7252                     surf_usm_v(l)%transmissivity(m)  = -1.0_wp
7253                 ELSE
7254                     surf_usm_v(l)%surface_types(m)  = usm_par(ii+1,jw,iw)
7255                     surf_usm_v(l)%albedo(:,m)    = usm_val(ij,jw,iw)
7256                     surf_usm_v(l)%thickness_wall(m) = usm_val(ij+1,jw,iw)
7257                     surf_usm_v(l)%thickness_window(m)   = usm_val(ij+1,jw,iw)
7258                     surf_usm_v(l)%thickness_green(m)    = usm_val(ij+1,jw,iw)
7259                     surf_usm_v(l)%transmissivity(m)  = 0.0_wp
7260                 ENDIF
7261              ELSE IF ( kw <= usm_par(ii+2,jw,iw) )  THEN
7262!--              wall zone
7263                 IF ( usm_par(ii+3,jw,iw) == 0 )  THEN
7264                     surf_usm_v(l)%surface_types(m)  = wall_category         !< default category for wall surface
7265                     surf_usm_v(l)%albedo(:,m)    = -1.0_wp
7266                     surf_usm_v(l)%thickness_wall(m) = -1.0_wp
7267                     surf_usm_v(l)%thickness_window(m)   = -1.0_wp
7268                     surf_usm_v(l)%thickness_green(m)    = -1.0_wp
7269                     surf_usm_v(l)%transmissivity(m)  = -1.0_wp
7270                 ELSE
7271                     surf_usm_v(l)%surface_types(m)  = usm_par(ii+3,jw,iw)
7272                     surf_usm_v(l)%albedo(:,m)    = usm_val(ij+2,jw,iw)
7273                     surf_usm_v(l)%thickness_wall(m) = usm_val(ij+3,jw,iw)
7274                     surf_usm_v(l)%thickness_window(m)   = usm_val(ij+3,jw,iw)
7275                     surf_usm_v(l)%thickness_green(m)    = usm_val(ij+3,jw,iw)
7276                     surf_usm_v(l)%transmissivity(m)  = 0.0_wp
7277                 ENDIF
7278              ELSE IF ( kw <= usm_par(ii+4,jw,iw) )  THEN
7279!--              roof zone
7280                 IF ( usm_par(ii+5,jw,iw) == 0 )  THEN
7281                     surf_usm_v(l)%surface_types(m)  = roof_category         !< default category for roof surface
7282                     surf_usm_v(l)%albedo(:,m)    = -1.0_wp
7283                     surf_usm_v(l)%thickness_wall(m) = -1.0_wp
7284                     surf_usm_v(l)%thickness_window(m)   = -1.0_wp
7285                     surf_usm_v(l)%thickness_green(m)    = -1.0_wp
7286                     surf_usm_v(l)%transmissivity(m)  = -1.0_wp
7287                 ELSE
7288                     surf_usm_v(l)%surface_types(m)  = usm_par(ii+5,jw,iw)
7289                     surf_usm_v(l)%albedo(:,m)    = usm_val(ij+4,jw,iw)
7290                     surf_usm_v(l)%thickness_wall(m) = usm_val(ij+5,jw,iw)
7291                     surf_usm_v(l)%thickness_window(m)   = usm_val(ij+5,jw,iw)
7292                     surf_usm_v(l)%thickness_green(m)    = usm_val(ij+5,jw,iw)
7293                     surf_usm_v(l)%transmissivity(m)  = 0.0_wp
7294                 ENDIF
7295              ELSE
7296!
7297                 WRITE(9,*) 'Problem reading USM data:'
7298                 WRITE(9,*) l,i,j,kw,get_topography_top_index_ji( j, i, 's' )
7299                 WRITE(9,*) ii,iw,jw,kw,get_topography_top_index_ji( jw, iw, 's' )
7300                 WRITE(9,*) usm_par(ii,jw,iw),usm_par(ii+1,jw,iw)
7301                 WRITE(9,*) usm_par(ii+2,jw,iw),usm_par(ii+3,jw,iw)
7302                 WRITE(9,*) usm_par(ii+4,jw,iw),usm_par(ii+5,jw,iw)
7303                 WRITE(9,*) kw,roof_height_limit,wall_category,roof_category
7304                 FLUSH(9)
7305!--              supply the default category
7306                 IF ( kw <= roof_height_limit ) THEN
7307                     surf_usm_v(l)%surface_types(m) = wall_category   !< default category for wall surface in wall zone
7308                 ELSE
7309                     surf_usm_v(l)%surface_types(m) = roof_category   !< default category for wall surface in roof zone
7310                 END IF
7311                 surf_usm_v(l)%albedo(:,m)    = -1.0_wp
7312                 surf_usm_v(l)%thickness_wall(m) = -1.0_wp
7313                 surf_usm_v(l)%thickness_window(m) = -1.0_wp
7314                 surf_usm_v(l)%thickness_green(m) = -1.0_wp
7315                 surf_usm_v(l)%transmissivity(m)  = -1.0_wp
7316              ENDIF
7317!
7318!--           Find the type position
7319              it = surf_usm_v(l)%surface_types(m)
7320              ip = -99999
7321              DO k = 1, n_surface_types
7322                 IF ( surface_type_codes(k) == it )  THEN
7323                    ip = k
7324                    EXIT
7325                 ENDIF
7326              ENDDO
7327              IF ( ip == -99999 )  THEN
7328!--              wall category not found
7329                 WRITE (9, "(A,I7,A,3I5)") 'wall category ', it,  &
7330                                           ' not found  for i,j,k=', iw,jw,kw
7331                 FLUSH(9)
7332                 category = wall_category 
7333                 DO k = 1, n_surface_types
7334                    IF ( surface_type_codes(k) == category ) THEN
7335                       ip = k
7336                       EXIT
7337                    ENDIF
7338                 ENDDO
7339                 IF ( ip == -99999 )  THEN
7340!--                 default wall category not found
7341                    WRITE (9, "(A,I5,A,3I5)") 'Default wall category', category, ' not found!'
7342                    FLUSH(9)
7343                    ip = 1
7344                 ENDIF
7345              ENDIF
7346
7347!
7348!--           Albedo
7349              IF ( surf_usm_v(l)%albedo(ind_veg_wall,m) < 0.0_wp )  THEN
7350                 surf_usm_v(l)%albedo(:,m) = surface_params(ialbedo,ip)
7351              ENDIF
7352!--           Albedo type is 0 (custom), others are replaced later
7353              surf_usm_v(l)%albedo_type(:,m) = 0
7354!--           Transmissivity of the windows
7355              IF ( surf_usm_v(l)%transmissivity(m) < 0.0_wp )  THEN
7356                 surf_usm_v(l)%transmissivity(m) = 0.0_wp
7357              ENDIF
7358!
7359!--           emissivity of the wall
7360              surf_usm_v(l)%emissivity(:,m) = surface_params(iemiss,ip)
7361!           
7362!--           heat conductivity lambda S between air and wall ( W m-2 K-1 )
7363              surf_usm_v(l)%lambda_surf(m) = surface_params(ilambdas,ip)
7364              surf_usm_v(l)%lambda_surf_window(m) = surface_params(ilambdas,ip)
7365              surf_usm_v(l)%lambda_surf_green(m) = surface_params(ilambdas,ip)
7366!           
7367!--           roughness length
7368              surf_usm_v(l)%z0(m) = surface_params(irough,ip)
7369              surf_usm_v(l)%z0h(m) = surface_params(iroughh,ip)
7370              surf_usm_v(l)%z0q(m) = surface_params(iroughh,ip)
7371!           
7372!--           Surface skin layer heat capacity (J m-2 K-1 )
7373              surf_usm_v(l)%c_surface(m) = surface_params(icsurf,ip)
7374              surf_usm_v(l)%c_surface_window(m) = surface_params(icsurf,ip)
7375              surf_usm_v(l)%c_surface_green(m) = surface_params(icsurf,ip)
7376!           
7377!--           wall material parameters:
7378!--           thickness of the wall (m)
7379!--           missing values are replaced by default value for category
7380              IF ( surf_usm_v(l)%thickness_wall(m) <= 0.001_wp )  THEN
7381                   surf_usm_v(l)%thickness_wall(m) = surface_params(ithick,ip)
7382              ENDIF
7383              IF ( surf_usm_v(l)%thickness_window(m) <= 0.001_wp )  THEN
7384                   surf_usm_v(l)%thickness_window(m) = surface_params(ithick,ip)
7385              ENDIF
7386              IF ( surf_usm_v(l)%thickness_green(m) <= 0.001_wp )  THEN
7387                   surf_usm_v(l)%thickness_green(m) = surface_params(ithick,ip)
7388              ENDIF
7389!
7390!--           volumetric heat capacity rho*C of the wall ( J m-3 K-1 )
7391              surf_usm_v(l)%rho_c_wall(:,m) = surface_params(irhoC,ip)
7392              surf_usm_v(l)%rho_c_window(:,m) = surface_params(irhoC,ip)
7393              surf_usm_v(l)%rho_c_green(:,m) = surface_params(irhoC,ip)
7394!           
7395!--           thermal conductivity lambda H of the wall (W m-1 K-1 )
7396              surf_usm_v(l)%lambda_h(:,m) = surface_params(ilambdah,ip)
7397              surf_usm_v(l)%lambda_h_window(:,m) = surface_params(ilambdah,ip)
7398              surf_usm_v(l)%lambda_h_green(:,m) = surface_params(ilambdah,ip)
7399
7400           ENDDO
7401        ENDDO 
7402
7403!
7404!--     Initialize wall layer thicknesses. Please note, this will be removed
7405!--     after migration to Palm input data standard. 
7406        DO k = nzb_wall, nzt_wall
7407           zwn(k) = zwn_default(k)
7408           zwn_green(k) = zwn_default_green(k)
7409           zwn_window(k) = zwn_default_window(k)
7410        ENDDO
7411!
7412!--     apply for all particular surface grids. First for horizontal surfaces
7413        DO  m = 1, surf_usm_h%ns
7414           surf_usm_h%zw(:,m) = zwn(:) * surf_usm_h%thickness_wall(m)
7415           surf_usm_h%zw_green(:,m) = zwn_green(:) * surf_usm_h%thickness_green(m)
7416           surf_usm_h%zw_window(:,m) = zwn_window(:) * surf_usm_h%thickness_window(m)
7417        ENDDO
7418        DO  l = 0, 3
7419           DO  m = 1, surf_usm_v(l)%ns
7420              surf_usm_v(l)%zw(:,m) = zwn(:) * surf_usm_v(l)%thickness_wall(m)
7421              surf_usm_v(l)%zw_green(:,m) = zwn_green(:) * surf_usm_v(l)%thickness_green(m)
7422              surf_usm_v(l)%zw_window(:,m) = zwn_window(:) * surf_usm_v(l)%thickness_window(m)
7423           ENDDO
7424        ENDDO
7425
7426       
7427        WRITE(9,*) 'Urban surfaces read'
7428        FLUSH(9)
7429       
7430        CALL location_message( '    types and parameters of urban surfaces read', .TRUE. )
7431   
7432    END SUBROUTINE usm_read_urban_surface_types
7433
7434
7435!------------------------------------------------------------------------------!
7436! Description:
7437! ------------
7438!
7439!> This function advances through the list of local surfaces to find given
7440!> x, y, d, z coordinates
7441!------------------------------------------------------------------------------!
7442    PURE FUNCTION advance_surface(isurfl_start, isurfl_stop, x, y, z, d) &
7443            result(isurfl)
7444
7445        INTEGER(iwp), INTENT(in)                :: isurfl_start, isurfl_stop
7446        INTEGER(iwp), INTENT(in)                :: x, y, z, d
7447        INTEGER(iwp)                            :: isx, isy, isz, isd
7448        INTEGER(iwp)                            :: isurfl
7449
7450        DO isurfl = isurfl_start, isurfl_stop
7451            isx = surfl(ix, isurfl)
7452            isy = surfl(iy, isurfl)
7453            isz = surfl(iz, isurfl)
7454            isd = surfl(id, isurfl)
7455            IF ( isx==x .and. isy==y .and. isz==z .and. isd==d )  RETURN
7456        ENDDO
7457
7458!--     coordinate not found
7459        isurfl = -1
7460
7461    END FUNCTION
7462
7463
7464!------------------------------------------------------------------------------!
7465! Description:
7466! ------------
7467!
7468!> This subroutine reads temperatures of respective material layers in walls,
7469!> roofs and ground from input files. Data in the input file must be in
7470!> standard order, i.e. horizontal surfaces first ordered by x, y and then
7471!> vertical surfaces ordered by x, y, direction, z
7472!------------------------------------------------------------------------------!
7473    SUBROUTINE usm_read_wall_temperature
7474
7475        INTEGER(iwp)                                          :: i, j, k, d, ii, iline
7476        INTEGER(iwp)                                          :: isurfl
7477        REAL(wp)                                              :: rtsurf
7478        REAL(wp), DIMENSION(nzb_wall:nzt_wall+1)              :: rtwall
7479
7480
7481
7482
7483        DO  ii = 0, io_blocks-1
7484            IF ( ii == io_group )  THEN
7485
7486!--             open wall temperature file
7487                OPEN( 152, file='WALL_TEMPERATURE'//coupling_char, action='read', &
7488                           status='old', form='formatted', err=15 )
7489
7490                isurfl = 0
7491                iline = 1
7492                DO
7493                    rtwall = -9999.0_wp  !< for incomplete lines
7494                    READ( 152, *, err=13, end=14 )  i, j, k, d, rtsurf, rtwall
7495
7496                    IF ( nxl <= i .and. i <= nxr .and. &
7497                        nys <= j .and. j <= nyn)  THEN  !< local processor
7498!--                     identify surface id
7499                        isurfl = advance_surface(isurfl+1, nsurfl, i, j, k, d)
7500                        IF ( isurfl == -1 )  THEN
7501                            WRITE(message_string, '(a,4i5,a,i5,a)') 'Coordinates (xyzd) ', i, j, k, d, &
7502                                ' on line ', iline, &
7503                                ' in file WALL_TEMPERATURE are either not present or out of standard order of surfaces.'
7504                            CALL message( 'usm_read_wall_temperature', 'PA0521', 1, 2, 0, 6, 0 )
7505                        ENDIF
7506
7507!--                     assign temperatures
7508                        IF ( d == 0 ) THEN
7509                           t_surf_h(isurfl) = rtsurf
7510                           t_wall_h(:,isurfl) = rtwall(:)
7511                        ELSE
7512                           t_surf_v(d-1)%t(isurfl) = rtsurf
7513                           t_wall_v(d-1)%t(:,isurfl) = rtwall(:)
7514                        ENDIF
7515                    ENDIF
7516
7517                    iline = iline + 1
7518                    CYCLE
7519 13                 WRITE(message_string, '(a,i5,a)') 'Error reading line ', iline, &
7520                        ' in file WALL_TEMPERATURE.'
7521                    CALL message( 'usm_read_wall_temperature', 'PA0522', 1, 2, 0, 6, 0 )
7522                ENDDO
7523 14             CLOSE(152)
7524                CYCLE
7525 15             message_string = 'file WALL_TEMPERATURE'//TRIM(coupling_char)//' does not exist'
7526                CALL message( 'usm_read_wall_temperature', 'PA0523', 1, 2, 0, 6, 0 )
7527            ENDIF
7528#if defined( __parallel )
7529            CALL MPI_BARRIER( comm2d, ierr )
7530#endif
7531        ENDDO
7532
7533        CALL location_message( '    wall layer temperatures read', .TRUE. )
7534
7535    END SUBROUTINE usm_read_wall_temperature
7536
7537
7538
7539!------------------------------------------------------------------------------!
7540! Description:
7541! ------------
7542!> Solver for the energy balance at the ground/roof/wall surface.
7543!> It follows basic ideas and structure of lsm_energy_balance
7544!> with many simplifications and adjustments.
7545!> TODO better description
7546!------------------------------------------------------------------------------!
7547    SUBROUTINE usm_surface_energy_balance
7548
7549        IMPLICIT NONE
7550
7551        INTEGER(iwp)                          :: i, j, k, l, m      !< running indices
7552       
7553        REAL(wp)                              :: stend              !< surface tendency
7554        REAL(wp)                              :: stend_window       !< surface tendency
7555        REAL(wp)                              :: stend_green        !< surface tendency
7556        REAL(wp)                              :: coef_1             !< first coeficient for prognostic equation
7557        REAL(wp)                              :: coef_window_1      !< first coeficient for prognostic window equation
7558        REAL(wp)                              :: coef_green_1       !< first coeficient for prognostic green wall equation
7559        REAL(wp)                              :: coef_2             !< second  coeficient for prognostic equation
7560        REAL(wp)                              :: coef_window_2      !< second  coeficient for prognostic window equation
7561        REAL(wp)                              :: coef_green_2       !< second  coeficient for prognostic green wall equation
7562        REAL(wp)                              :: rho_cp             !< rho_wall_surface * cp
7563        REAL(wp)                              :: f_shf              !< factor for shf_eb
7564        REAL(wp)                              :: f_shf_window       !< factor for shf_eb window
7565        REAL(wp)                              :: f_shf_green        !< factor for shf_eb green wall
7566        REAL(wp)                              :: lambda_surface     !< current value of lambda_surface (heat conductivity between air and wall)
7567        REAL(wp)                              :: lambda_surface_window !< current value of lambda_surface (heat conductivity between air and window)
7568        REAL(wp)                              :: lambda_surface_green  !< current value of lambda_surface (heat conductivity between air and greeb wall)
7569       
7570        REAL(wp)                              :: dtime              !< simulated time of day (in UTC)
7571        INTEGER(iwp)                          :: dhour              !< simulated hour of day (in UTC)
7572        REAL(wp)                              :: acoef              !< actual coefficient of diurnal profile of anthropogenic heat
7573
7574
7575!       
7576!--     First, treat horizontal surface elements
7577        DO  m = 1, surf_usm_h%ns
7578!
7579!--        Get indices of respective grid point
7580           i = surf_usm_h%i(m)
7581           j = surf_usm_h%j(m)
7582           k = surf_usm_h%k(m)
7583!
7584!--        TODO - how to calculate lambda_surface for horizontal surfaces
7585!--        (lambda_surface is set according to stratification in land surface model)
7586!--        MS: ???
7587           IF ( surf_usm_h%ol(m) >= 0.0_wp )  THEN
7588              lambda_surface = surf_usm_h%lambda_surf(m)
7589              lambda_surface_window = surf_usm_h%lambda_surf_window(m)
7590              lambda_surface_green = surf_usm_h%lambda_surf_green(m)
7591           ELSE
7592              lambda_surface = surf_usm_h%lambda_surf(m)
7593              lambda_surface_window = surf_usm_h%lambda_surf_window(m)
7594              lambda_surface_green = surf_usm_h%lambda_surf_green(m)
7595           ENDIF
7596#if ! defined( __nopointer )
7597!
7598!--        calculate rho * c_p coefficient at surface layer
7599           rho_cp  = c_p * hyp(k) / ( r_d * surf_usm_h%pt1(m) * exner(k) )
7600#endif
7601!
7602!--        Calculate aerodyamic resistance.
7603!--        Calculation for horizontal surfaces follows LSM formulation
7604!--        pt, us, ts are not available for the prognostic time step,
7605!--        data from the last time step is used here.
7606
7607!--        Workaround: use single r_a as stability is only treated for the
7608!--        average temperature
7609           surf_usm_h%r_a(m) = ( surf_usm_h%pt1(m) - surf_usm_h%pt_surface(m) ) /&
7610                               ( surf_usm_h%ts(m) * surf_usm_h%us(m) + 1.0E-20_wp )   
7611           surf_usm_h%r_a_window(m) = surf_usm_h%r_a(m)
7612           surf_usm_h%r_a_green(m)  = surf_usm_h%r_a(m)
7613
7614!            r_a = ( surf_usm_h%pt1(m) - t_surf_h(m) / exner(k) ) /                              &
7615!                  ( surf_usm_h%ts(m) * surf_usm_h%us(m) + 1.0E-20_wp )
7616!            r_a_window = ( surf_usm_h%pt1(m) - t_surf_window_h(m) / exner(k) ) /                &
7617!                  ( surf_usm_h%ts(m) * surf_usm_h%us(m) + 1.0E-20_wp )
7618!            r_a_green = ( surf_usm_h%pt1(m) - t_surf_green_h(m) / exner(k) ) /                  &
7619!                  ( surf_usm_h%ts(m) * surf_usm_h%us(m) + 1.0E-20_wp )
7620               
7621!--        Make sure that the resistance does not drop to zero
7622           IF ( surf_usm_h%r_a(m)        < 1.0_wp )                            &
7623               surf_usm_h%r_a(m)        = 1.0_wp
7624           IF ( surf_usm_h%r_a_green(m)  < 1.0_wp )                            &
7625               surf_usm_h%r_a_green(m) = 1.0_wp
7626           IF ( surf_usm_h%r_a_window(m) < 1.0_wp )                            &
7627               surf_usm_h%r_a_window(m) = 1.0_wp
7628             
7629!
7630!--        Make sure that the resistacne does not exceed a maxmium value in case
7631!--        of zero velocities
7632           IF ( surf_usm_h%r_a(m)        > 300.0_wp )                          &
7633               surf_usm_h%r_a(m)        = 300.0_wp
7634           IF ( surf_usm_h%r_a_green(m)  > 300.0_wp )                          &
7635               surf_usm_h%r_a_green(m) = 300.0_wp
7636           IF ( surf_usm_h%r_a_window(m) > 300.0_wp )                          &
7637               surf_usm_h%r_a_window(m) = 300.0_wp               
7638               
7639               
7640!--        factor for shf_eb
7641           f_shf  = rho_cp / surf_usm_h%r_a(m)
7642           f_shf_window  = rho_cp / surf_usm_h%r_a_window(m)
7643           f_shf_green  = rho_cp / surf_usm_h%r_a_green(m)
7644       
7645!--        add LW up so that it can be removed in prognostic equation
7646           surf_usm_h%rad_net_l(m) = surf_usm_h%rad_sw_in(m)  -                &
7647                                     surf_usm_h%rad_sw_out(m) +                &
7648                                     surf_usm_h%rad_lw_in(m)  -                &
7649                                     surf_usm_h%rad_lw_out(m)
7650
7651!--        numerator of the prognostic equation
7652!--     Todo: Adjust to tile approach. So far, emissivity for wall (element 0)
7653!--           is used
7654           coef_1 = surf_usm_h%rad_net_l(m) +                                  & 
7655                 ( 3.0_wp + 1.0_wp ) * surf_usm_h%emissivity(ind_veg_wall,m) * &
7656                                       sigma_sb * t_surf_h(m) ** 4 +           & 
7657                                       f_shf * surf_usm_h%pt1(m) +             &
7658                                       lambda_surface * t_wall_h(nzb_wall,m)
7659           coef_window_1 = surf_usm_h%rad_net_l(m) +                           & 
7660                   ( 3.0_wp + 1.0_wp ) * surf_usm_h%emissivity(ind_wat_win,m)  &
7661                                       * sigma_sb * t_surf_window_h(m) ** 4 +  & 
7662                                       f_shf_window * surf_usm_h%pt1(m) +      &
7663                                       lambda_surface_window * t_window_h(nzb_wall,m)
7664           coef_green_1 = surf_usm_h%rad_net_l(m) +                            & 
7665                 ( 3.0_wp + 1.0_wp ) * surf_usm_h%emissivity(ind_pav_green,m) *&
7666                                       sigma_sb * t_surf_green_h(m) ** 4 +     & 
7667                                       f_shf_green * surf_usm_h%pt1(m) +       &
7668                                       lambda_surface_green * t_wall_h(nzb_wall,m)
7669
7670!--        denominator of the prognostic equation
7671           coef_2 = 4.0_wp * surf_usm_h%emissivity(ind_veg_wall,m) *           &
7672                             sigma_sb * t_surf_h(m) ** 3                       &
7673                           + lambda_surface + f_shf / exner(k)
7674           coef_window_2 = 4.0_wp * surf_usm_h%emissivity(ind_wat_win,m) *     &
7675                             sigma_sb * t_surf_window_h(m) ** 3                &
7676                           + lambda_surface_window + f_shf_window / exner(k)
7677           coef_green_2 = 4.0_wp * surf_usm_h%emissivity(ind_pav_green,m) *    &
7678                             sigma_sb * t_surf_green_h(m) ** 3                 &
7679                           + lambda_surface_green + f_shf_green / exner(k)
7680
7681!--        implicit solution when the surface layer has no heat capacity,
7682!--        otherwise use RK3 scheme.
7683           t_surf_h_p(m) = ( coef_1 * dt_3d * tsc(2) +                        &
7684                             surf_usm_h%c_surface(m) * t_surf_h(m) ) /        & 
7685                           ( surf_usm_h%c_surface(m) + coef_2 * dt_3d * tsc(2) ) 
7686           t_surf_window_h_p(m) = ( coef_window_1 * dt_3d * tsc(2) +                        &
7687                             surf_usm_h%c_surface_window(m) * t_surf_window_h(m) ) /        & 
7688                           ( surf_usm_h%c_surface_window(m) + coef_window_2 * dt_3d * tsc(2) ) 
7689           t_surf_green_h_p(m) = ( coef_green_1 * dt_3d * tsc(2) +                        &
7690                             surf_usm_h%c_surface_green(m) * t_surf_green_h(m) ) /        & 
7691                           ( surf_usm_h%c_surface_green(m) + coef_green_2 * dt_3d * tsc(2) ) 
7692
7693!--        add RK3 term
7694           t_surf_h_p(m) = t_surf_h_p(m) + dt_3d * tsc(3) *                   &
7695                           surf_usm_h%tt_surface_m(m)
7696           t_surf_window_h_p(m) = t_surf_window_h_p(m) + dt_3d * tsc(3) *     &
7697                           surf_usm_h%tt_surface_window_m(m)
7698           t_surf_green_h_p(m) = t_surf_green_h_p(m) + dt_3d * tsc(3) *       &
7699                           surf_usm_h%tt_surface_green_m(m)
7700!
7701!--        Store surface temperature on pt_surface. Further, in case humidity is used
7702!--        store also vpt_surface, which is, due to the lack of moisture on roofs simply
7703!--        assumed to be the surface temperature.
7704           surf_usm_h%pt_surface(m) = ( surf_usm_h%frac(ind_veg_wall,m) * t_surf_h_p(m)   &
7705                               + surf_usm_h%frac(ind_wat_win,m) * t_surf_window_h_p(m)   &
7706                               + surf_usm_h%frac(ind_pav_green,m) * t_surf_green_h_p(m) )  &
7707                               / exner(k)
7708                               
7709           IF ( humidity )  surf_usm_h%vpt_surface(m) =                        &
7710                                                   surf_usm_h%pt_surface(m)
7711
7712!--        calculate true tendency
7713           stend = ( t_surf_h_p(m) - t_surf_h(m) - dt_3d * tsc(3) *           &
7714                     surf_usm_h%tt_surface_m(m)) / ( dt_3d  * tsc(2) )
7715           stend_window = ( t_surf_window_h_p(m) - t_surf_window_h(m) - dt_3d * tsc(3) *        &
7716                     surf_usm_h%tt_surface_window_m(m)) / ( dt_3d  * tsc(2) )
7717           stend_green = ( t_surf_green_h_p(m) - t_surf_green_h(m) - dt_3d * tsc(3) *           &
7718                     surf_usm_h%tt_surface_green_m(m)) / ( dt_3d  * tsc(2) )
7719
7720!--        calculate t_surf tendencies for the next Runge-Kutta step
7721           IF ( timestep_scheme(1:5) == 'runge' )  THEN
7722              IF ( intermediate_timestep_count == 1 )  THEN
7723                 surf_usm_h%tt_surface_m(m) = stend
7724                 surf_usm_h%tt_surface_window_m(m) = stend_window
7725                 surf_usm_h%tt_surface_green_m(m) = stend_green
7726              ELSEIF ( intermediate_timestep_count <                          &
7727                        intermediate_timestep_count_max )  THEN
7728                 surf_usm_h%tt_surface_m(m) = -9.5625_wp * stend +            &
7729                                     5.3125_wp * surf_usm_h%tt_surface_m(m)
7730                 surf_usm_h%tt_surface_window_m(m) = -9.5625_wp * stend_window +   &
7731                                     5.3125_wp * surf_usm_h%tt_surface_window_m(m)
7732                 surf_usm_h%tt_surface_green_m(m) = -9.5625_wp * stend_green +     &
7733                                     5.3125_wp * surf_usm_h%tt_surface_green_m(m)
7734              ENDIF
7735           ENDIF
7736
7737!--        in case of fast changes in the skin temperature, it is required to
7738!--        update the radiative fluxes in order to keep the solution stable
7739           IF ( ( ABS( t_surf_h_p(m) - t_surf_h(m) ) > 1.0_wp ) .OR. &
7740                ( ABS( t_surf_green_h_p(m) - t_surf_green_h(m) ) > 1.0_wp ) .OR. &
7741                ( ABS( t_surf_window_h_p(m) - t_surf_window_h(m) ) > 1.0_wp ) ) THEN
7742              force_radiation_call_l = .TRUE.
7743           ENDIF
7744!
7745!--        calculate fluxes
7746!--        rad_net_l is never used!
7747           surf_usm_h%rad_net_l(m) = surf_usm_h%rad_net_l(m) +                           &
7748                                     surf_usm_h%frac(ind_veg_wall,m) *                   &
7749                                     sigma_sb * surf_usm_h%emissivity(ind_veg_wall,m) *  &
7750                                     ( t_surf_h_p(m)**4 - t_surf_h(m)**4 )               &
7751                                    + surf_usm_h%frac(ind_wat_win,m) *                   &
7752                                     sigma_sb * surf_usm_h%emissivity(ind_wat_win,m) *   &
7753                                     ( t_surf_window_h_p(m)**4 - t_surf_window_h(m)**4 ) &
7754                                    + surf_usm_h%frac(ind_pav_green,m) *                 &
7755                                     sigma_sb * surf_usm_h%emissivity(ind_pav_green,m) * &
7756                                     ( t_surf_green_h_p(m)**4 - t_surf_green_h(m)**4 )
7757
7758           surf_usm_h%wghf_eb(m)   = lambda_surface *                         &
7759                                      ( t_surf_h_p(m) - t_wall_h(nzb_wall,m) )
7760           surf_usm_h%wghf_eb_green(m)  = lambda_surface_green *                         &
7761                                          ( t_surf_green_h_p(m) - t_green_h(nzb_wall,m) )
7762           surf_usm_h%wghf_eb_window(m) = lambda_surface_window *                        &
7763                                           ( t_surf_window_h_p(m) - t_window_h(nzb_wall,m) )
7764
7765!
7766!--        ground/wall/roof surface heat flux
7767           surf_usm_h%wshf_eb(m)   = - f_shf  * ( surf_usm_h%pt1(m) - t_surf_h_p(m) / exner(k) ) *               &
7768                                       surf_usm_h%frac(ind_veg_wall,m)         &
7769                                     - f_shf_window  * ( surf_usm_h%pt1(m) - t_surf_window_h_p(m) / exner(k) ) * &
7770                                       surf_usm_h%frac(ind_wat_win,m)          &
7771                                     - f_shf_green  * ( surf_usm_h%pt1(m) - t_surf_green_h_p(m) / exner(k) ) *   &
7772                                       surf_usm_h%frac(ind_pav_green,m)
7773!           
7774!--        store kinematic surface heat fluxes for utilization in other processes
7775!--        diffusion_s, surface_layer_fluxes,...
7776           surf_usm_h%shf(m) = surf_usm_h%wshf_eb(m) / c_p
7777     
7778       ENDDO
7779!
7780!--    Now, treat vertical surface elements
7781       DO  l = 0, 3
7782          DO  m = 1, surf_usm_v(l)%ns
7783!
7784!--          Get indices of respective grid point
7785             i = surf_usm_v(l)%i(m)
7786             j = surf_usm_v(l)%j(m)
7787             k = surf_usm_v(l)%k(m)
7788
7789!
7790!--          TODO - how to calculate lambda_surface for horizontal (??? do you mean verical ???) surfaces
7791!--          (lambda_surface is set according to stratification in land surface model).
7792!--          Please note, for vertical surfaces no ol is defined, since
7793!--          stratification is not considered in this case.
7794             lambda_surface = surf_usm_v(l)%lambda_surf(m)
7795             lambda_surface_window = surf_usm_v(l)%lambda_surf_window(m)
7796             lambda_surface_green = surf_usm_v(l)%lambda_surf_green(m)
7797
7798#if ! defined( __nopointer )         
7799!
7800!--          calculate rho * c_p coefficient at wall layer
7801             rho_cp  = c_p * hyp(k) / ( r_d * surf_usm_v(l)%pt1(m) * exner(k) )
7802#endif
7803
7804!--          Calculation of r_a for vertical surfaces
7805!--
7806!--          heat transfer coefficient for forced convection along vertical walls
7807!--          follows formulation in TUF3d model (Krayenhoff & Voogt, 2006)
7808!--           
7809!--          H = httc (Tsfc - Tair)
7810!--          httc = rw * (11.8 + 4.2 * Ueff) - 4.0
7811!--           
7812!--                rw: wall patch roughness relative to 1.0 for concrete
7813!--                Ueff: effective wind speed
7814!--                - 4.0 is a reduction of Rowley et al (1930) formulation based on
7815!--                Cole and Sturrock (1977)
7816!--           
7817!--                Ucan: Canyon wind speed
7818!--                wstar: convective velocity
7819!--                Qs: surface heat flux
7820!--                zH: height of the convective layer
7821!--                wstar = (g/Tcan*Qs*zH)**(1./3.)
7822               
7823!--          Effective velocity components must always
7824!--          be defined at scalar grid point. The wall normal component is
7825!--          obtained by simple linear interpolation. ( An alternative would
7826!--          be an logarithmic interpolation. )
7827!--          Parameter roughness_concrete (default value = 0.001) is used
7828!--          to calculation of roughness relative to concrete
7829             surf_usm_v(l)%r_a(m) = rho_cp / ( surf_usm_v(l)%z0(m) /           &
7830                        roughness_concrete * ( 11.8_wp + 4.2_wp *              &
7831                        SQRT( MAX( ( ( u(k,j,i) + u(k,j,i+1) ) * 0.5_wp )**2 + &
7832                                   ( ( v(k,j,i) + v(k,j+1,i) ) * 0.5_wp )**2 + &
7833                                   ( ( w(k,j,i) + w(k-1,j,i) ) * 0.5_wp )**2,  &
7834                              0.01_wp ) )                                      &
7835                           )  - 4.0_wp  ) 
7836!
7837!--          Limit aerodynamic resistance
7838             IF ( surf_usm_v(l)%r_a(m) < 1.0_wp )  surf_usm_v(l)%r_a(m) = 1.0_wp   
7839             
7840                           
7841             f_shf         = rho_cp / surf_usm_v(l)%r_a(m)
7842             f_shf_window  = rho_cp / surf_usm_v(l)%r_a(m)
7843             f_shf_green   = rho_cp / surf_usm_v(l)%r_a(m)
7844
7845!--          add LW up so that it can be removed in prognostic equation
7846             surf_usm_v(l)%rad_net_l(m) = surf_usm_v(l)%rad_sw_in(m)  -        &
7847                                          surf_usm_v(l)%rad_sw_out(m) +        &
7848                                          surf_usm_v(l)%rad_lw_in(m)  -        &
7849                                          surf_usm_v(l)%rad_lw_out(m)
7850
7851!--           numerator of the prognostic equation
7852              coef_1 = surf_usm_v(l)%rad_net_l(m) +                            & ! coef +1 corresponds to -lwout included in calculation of radnet_l
7853             ( 3.0_wp + 1.0_wp ) * surf_usm_v(l)%emissivity(ind_veg_wall,m) *  &
7854                                     sigma_sb *  t_surf_v(l)%t(m) ** 4 +       & 
7855                                     f_shf * surf_usm_v(l)%pt1(m) +            &
7856                                     lambda_surface * t_wall_v(l)%t(nzb_wall,m)
7857              coef_window_1 = surf_usm_v(l)%rad_net_l(m) +                     & ! coef +1 corresponds to -lwout included in calculation of radnet_l
7858               ( 3.0_wp + 1.0_wp ) * surf_usm_v(l)%emissivity(ind_wat_win,m) * &
7859                                     sigma_sb * t_surf_window_v(l)%t(m) ** 4 + & 
7860                                     f_shf * surf_usm_v(l)%pt1(m) +            &
7861                                     lambda_surface_window * t_window_v(l)%t(nzb_wall,m)
7862
7863              coef_green_1 = surf_usm_v(l)%rad_net_l(m) +                      & ! coef +1 corresponds to -lwout included in calculation of radnet_l
7864              ( 3.0_wp + 1.0_wp ) * surf_usm_v(l)%emissivity(ind_pav_green,m) *&
7865                                     sigma_sb * t_surf_green_v(l)%t(m) ** 4 +  & 
7866                                     f_shf * surf_usm_v(l)%pt1(m) +            &
7867                                     lambda_surface_green * t_wall_v(l)%t(nzb_wall,m)
7868
7869!--           denominator of the prognostic equation
7870              coef_2 = 4.0_wp * surf_usm_v(l)%emissivity(ind_veg_wall,m) *     &
7871                                sigma_sb * t_surf_v(l)%t(m) ** 3               &
7872                              + lambda_surface + f_shf / exner(k)
7873              coef_window_2 = 4.0_wp * surf_usm_v(l)%emissivity(ind_wat_win,m) *&
7874                                sigma_sb * t_surf_window_v(l)%t(m) ** 3        &
7875                              + lambda_surface_window + f_shf / exner(k)
7876              coef_green_2 = 4.0_wp * surf_usm_v(l)%emissivity(ind_pav_green,m) *&
7877                                sigma_sb * t_surf_green_v(l)%t(m) ** 3         &
7878                              + lambda_surface_green + f_shf / exner(k)
7879
7880!--           implicit solution when the surface layer has no heat capacity,
7881!--           otherwise use RK3 scheme.
7882              t_surf_v_p(l)%t(m) = ( coef_1 * dt_3d * tsc(2) +                 &
7883                             surf_usm_v(l)%c_surface(m) * t_surf_v(l)%t(m) ) / & 
7884                           ( surf_usm_v(l)%c_surface(m) + coef_2 * dt_3d * tsc(2) ) 
7885              t_surf_window_v_p(l)%t(m) = ( coef_window_1 * dt_3d * tsc(2) +                 &
7886                             surf_usm_v(l)%c_surface_window(m) * t_surf_window_v(l)%t(m) ) / & 
7887                           ( surf_usm_v(l)%c_surface_window(m) + coef_window_2 * dt_3d * tsc(2) ) 
7888
7889              t_surf_green_v_p(l)%t(m) = ( coef_green_1 * dt_3d * tsc(2) +                 &
7890                             surf_usm_v(l)%c_surface_green(m) * t_surf_green_v(l)%t(m) ) / & 
7891                           ( surf_usm_v(l)%c_surface_green(m) + coef_green_2 * dt_3d * tsc(2) ) 
7892
7893!--           add RK3 term
7894              t_surf_v_p(l)%t(m) = t_surf_v_p(l)%t(m) + dt_3d * tsc(3) *       &
7895                                surf_usm_v(l)%tt_surface_m(m)
7896              t_surf_window_v_p(l)%t(m) = t_surf_window_v_p(l)%t(m) + dt_3d * tsc(3) *     &
7897                                surf_usm_v(l)%tt_surface_window_m(m)
7898              t_surf_green_v_p(l)%t(m) = t_surf_green_v_p(l)%t(m) + dt_3d * tsc(3) *       &
7899                                surf_usm_v(l)%tt_surface_green_m(m)
7900!
7901!--           Store surface temperature. Further, in case humidity is used
7902!--           store also vpt_surface, which is, due to the lack of moisture on roofs simply
7903!--           assumed to be the surface temperature.     
7904              surf_usm_v(l)%pt_surface(m) =  ( surf_usm_v(l)%frac(ind_veg_wall,m) * t_surf_v_p(l)%t(m)  &
7905                                      + surf_usm_v(l)%frac(ind_wat_win,m) * t_surf_window_v_p(l)%t(m)  &
7906                                      + surf_usm_v(l)%frac(ind_pav_green,m) * t_surf_green_v_p(l)%t(m) ) &
7907                                      / exner(k)
7908                                     
7909              IF ( humidity )  surf_usm_v(l)%vpt_surface(m) =                  &
7910                                                    surf_usm_v(l)%pt_surface(m)
7911
7912!--           calculate true tendency
7913              stend = ( t_surf_v_p(l)%t(m) - t_surf_v(l)%t(m) - dt_3d * tsc(3) *&
7914                        surf_usm_v(l)%tt_surface_m(m) ) / ( dt_3d  * tsc(2) )
7915              stend_window = ( t_surf_window_v_p(l)%t(m) - t_surf_window_v(l)%t(m) - dt_3d * tsc(3) *&
7916                        surf_usm_v(l)%tt_surface_window_m(m) ) / ( dt_3d  * tsc(2) )
7917              stend_green = ( t_surf_green_v_p(l)%t(m) - t_surf_green_v(l)%t(m) - dt_3d * tsc(3) *&
7918                        surf_usm_v(l)%tt_surface_green_m(m) ) / ( dt_3d  * tsc(2) )
7919
7920!--           calculate t_surf tendencies for the next Runge-Kutta step
7921              IF ( timestep_scheme(1:5) == 'runge' )  THEN
7922                 IF ( intermediate_timestep_count == 1 )  THEN
7923                    surf_usm_v(l)%tt_surface_m(m) = stend
7924                    surf_usm_v(l)%tt_surface_window_m(m) = stend_window
7925                    surf_usm_v(l)%tt_surface_green_m(m) = stend_green
7926                 ELSEIF ( intermediate_timestep_count <                        &
7927                          intermediate_timestep_count_max )  THEN
7928                    surf_usm_v(l)%tt_surface_m(m) = -9.5625_wp * stend +       &
7929                                     5.3125_wp * surf_usm_v(l)%tt_surface_m(m)
7930                    surf_usm_v(l)%tt_surface_green_m(m) = -9.5625_wp * stend_green +       &
7931                                     5.3125_wp * surf_usm_v(l)%tt_surface_green_m(m)
7932                    surf_usm_v(l)%tt_surface_window_m(m) = -9.5625_wp * stend_window +       &
7933                                     5.3125_wp * surf_usm_v(l)%tt_surface_window_m(m)
7934                 ENDIF
7935              ENDIF
7936
7937!--           in case of fast changes in the skin temperature, it is required to
7938!--           update the radiative fluxes in order to keep the solution stable
7939
7940              IF ( ( ABS( t_surf_v_p(l)%t(m) - t_surf_v(l)%t(m) ) > 1.0_wp ) .OR. &
7941                   ( ABS( t_surf_green_v_p(l)%t(m) - t_surf_green_v(l)%t(m) ) > 1.0_wp ) .OR.  &
7942                   ( ABS( t_surf_window_v_p(l)%t(m) - t_surf_window_v(l)%t(m) ) > 1.0_wp ) ) THEN
7943                 force_radiation_call_l = .TRUE.
7944              ENDIF
7945
7946!--           calculate fluxes
7947!--           prognostic rad_net_l is used just for output!           
7948              surf_usm_v(l)%rad_net_l(m) = surf_usm_v(l)%frac(ind_veg_wall,m) *                      &
7949                                           ( surf_usm_v(l)%rad_net_l(m) +                            &
7950                                           3.0_wp * sigma_sb *                                       &
7951                                           t_surf_v(l)%t(m)**4 - 4.0_wp * sigma_sb *                 &
7952                                           t_surf_v(l)%t(m)**3 * t_surf_v_p(l)%t(m) )                &
7953                                         + surf_usm_v(l)%frac(ind_wat_win,m) *                       &
7954                                           ( surf_usm_v(l)%rad_net_l(m) +                            &
7955                                           3.0_wp * sigma_sb *                                       &
7956                                           t_surf_window_v(l)%t(m)**4 - 4.0_wp * sigma_sb *          &
7957                                           t_surf_window_v(l)%t(m)**3 * t_surf_window_v_p(l)%t(m) )  &
7958                                         + surf_usm_v(l)%frac(ind_pav_green,m) *                     &
7959                                           ( surf_usm_v(l)%rad_net_l(m) +                            &
7960                                           3.0_wp * sigma_sb *                                       &
7961                                           t_surf_green_v(l)%t(m)**4 - 4.0_wp * sigma_sb *           &
7962                                           t_surf_green_v(l)%t(m)**3 * t_surf_green_v_p(l)%t(m) )
7963
7964              surf_usm_v(l)%wghf_eb_window(m) = lambda_surface_window * &
7965                                                ( t_surf_window_v_p(l)%t(m) - t_window_v(l)%t(nzb_wall,m) )
7966              surf_usm_v(l)%wghf_eb(m)   = lambda_surface *                    &
7967                                     ( t_surf_v_p(l)%t(m) - t_wall_v(l)%t(nzb_wall,m) )
7968              surf_usm_v(l)%wghf_eb_green(m)  = lambda_surface_green *  &
7969                                                ( t_surf_green_v_p(l)%t(m) - t_green_v(l)%t(nzb_wall,m) )
7970
7971!--           ground/wall/roof surface heat flux
7972              surf_usm_v(l)%wshf_eb(m)   =                                     &
7973                 - f_shf  * ( surf_usm_v(l)%pt1(m) -                           &
7974                 t_surf_v_p(l)%t(m) / exner(k) ) * surf_usm_v(l)%frac(ind_veg_wall,m)       &
7975                 - f_shf_window  * ( surf_usm_v(l)%pt1(m) -                    &
7976                 t_surf_window_v_p(l)%t(m) / exner(k) ) * surf_usm_v(l)%frac(ind_wat_win,m)&
7977                 - f_shf_green  * ( surf_usm_v(l)%pt1(m) -                     &
7978                 t_surf_green_v_p(l)%t(m) / exner(k) ) * surf_usm_v(l)%frac(ind_pav_green,m)
7979
7980!           
7981!--           store kinematic surface heat fluxes for utilization in other processes
7982!--           diffusion_s, surface_layer_fluxes,...
7983              surf_usm_v(l)%shf(m) = surf_usm_v(l)%wshf_eb(m) / c_p
7984
7985           ENDDO
7986
7987        ENDDO
7988!
7989!--     Add-up anthropogenic heat, for now only at upward-facing surfaces
7990        IF ( usm_anthropogenic_heat  .AND.  &
7991             intermediate_timestep_count == intermediate_timestep_count_max )  THEN
7992!--        application of the additional anthropogenic heat sources
7993!--        we considere the traffic for now so all heat is absorbed
7994!--        to the first layer, generalization would be worth.
7995           
7996!--        calculation of actual profile coefficient
7997!--        ??? check time_since_reference_point ???
7998           dtime = mod(simulated_time + time_utc_init, 24.0_wp*3600.0_wp)
7999           dhour = INT(dtime/3600.0_wp)
8000           DO i = nxl, nxr
8001              DO j = nys, nyn
8002                 DO k = nzub, min(nzut,naheatlayers)
8003                    IF ( k > get_topography_top_index_ji( j, i, 's' ) ) THEN
8004!--                    increase of pt in box i,j,k in time dt_3d
8005!--                    given to anthropogenic heat aheat*acoef (W*m-2)
8006!--                    linear interpolation of coeficient
8007                       acoef = (REAL(dhour+1,wp)-dtime/3600.0_wp)*aheatprof(k,dhour) + &
8008                               (dtime/3600.0_wp-REAL(dhour,wp))*aheatprof(k,dhour+1)
8009                       IF ( aheat(k,j,i) > 0.0_wp )  THEN
8010!--                       calculate rho * c_p coefficient at layer k
8011                          rho_cp  = c_p * hyp(k) / ( r_d * pt(k+1,j,i) * exner(k) )
8012                          pt(k,j,i) = pt(k,j,i) + aheat(k,j,i)*acoef*dt_3d/(exner(k)*rho_cp*dz(1))
8013                       ENDIF
8014                    ENDIF
8015                 ENDDO
8016              ENDDO
8017           ENDDO
8018
8019        ENDIF
8020       
8021!--     pt and shf are defined on nxlg:nxrg,nysg:nyng
8022!--     get the borders from neighbours
8023#if ! defined( __nopointer )
8024        CALL exchange_horiz( pt, nbgp )
8025#endif
8026
8027!--     calculation of force_radiation_call:
8028!--     Make logical OR for all processes.
8029!--     Force radiation call if at least one processor forces it.
8030        IF ( intermediate_timestep_count == intermediate_timestep_count_max-1 )&
8031        THEN
8032#if defined( __parallel )
8033          IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
8034          CALL MPI_ALLREDUCE( force_radiation_call_l, force_radiation_call,    &
8035                              1, MPI_LOGICAL, MPI_LOR, comm2d, ierr )
8036#else
8037          force_radiation_call = force_radiation_call_l
8038#endif
8039          force_radiation_call_l = .FALSE.
8040       ENDIF
8041
8042    END SUBROUTINE usm_surface_energy_balance
8043
8044
8045!------------------------------------------------------------------------------!
8046! Description:
8047! ------------
8048!> Swapping of timelevels for t_surf and t_wall
8049!> called out from subroutine swap_timelevel
8050!------------------------------------------------------------------------------!
8051    SUBROUTINE usm_swap_timelevel( mod_count )
8052
8053       IMPLICIT NONE
8054
8055       INTEGER(iwp), INTENT(IN) ::  mod_count
8056     
8057#if defined( __nopointer )
8058       t_surf_h    = t_surf_h_p
8059       t_wall_h    = t_wall_h_p
8060       t_surf_v    = t_surf_v_p
8061       t_wall_v    = t_wall_v_p
8062       t_surf_window_h    = t_surf_window_h_p
8063       t_window_h    = t_window_h_p
8064       t_surf_window_v    = t_surf_window_v_p
8065       t_window_v    = t_window_v_p
8066       t_surf_green_h    = t_surf_green_h_p
8067       t_surf_green_v    = t_surf_green_v_p
8068       t_green_h    = t_green_h_p
8069       t_green_v    = t_green_v_p
8070#else
8071       SELECT CASE ( mod_count )
8072          CASE ( 0 )
8073!
8074!--          Horizontal surfaces
8075             t_surf_h  => t_surf_h_1; t_surf_h_p  => t_surf_h_2
8076             t_wall_h     => t_wall_h_1;    t_wall_h_p     => t_wall_h_2
8077             t_surf_window_h  => t_surf_window_h_1; t_surf_window_h_p  => t_surf_window_h_2
8078             t_window_h     => t_window_h_1;    t_window_h_p     => t_window_h_2
8079             t_surf_green_h  => t_surf_green_h_1; t_surf_green_h_p  => t_surf_green_h_2
8080             t_green_h     => t_green_h_1;    t_green_h_p     => t_green_h_2
8081!
8082!--          Vertical surfaces
8083             t_surf_v  => t_surf_v_1; t_surf_v_p  => t_surf_v_2
8084             t_wall_v     => t_wall_v_1;    t_wall_v_p     => t_wall_v_2
8085             t_surf_window_v  => t_surf_window_v_1; t_surf_window_v_p  => t_surf_window_v_2
8086             t_window_v     => t_window_v_1;    t_window_v_p     => t_window_v_2
8087             t_surf_green_v  => t_surf_green_v_1; t_surf_green_v_p  => t_surf_green_v_2
8088             t_green_v     => t_green_v_1;    t_green_v_p     => t_green_v_2
8089          CASE ( 1 )
8090!
8091!--          Horizontal surfaces
8092             t_surf_h  => t_surf_h_2; t_surf_h_p  => t_surf_h_1
8093             t_wall_h     => t_wall_h_2;    t_wall_h_p     => t_wall_h_1
8094             t_surf_window_h  => t_surf_window_h_2; t_surf_window_h_p  => t_surf_window_h_1
8095             t_window_h     => t_window_h_2;    t_window_h_p     => t_window_h_1
8096             t_surf_green_h  => t_surf_green_h_2; t_surf_green_h_p  => t_surf_green_h_1
8097             t_green_h     => t_green_h_2;    t_green_h_p     => t_green_h_1
8098!
8099!--          Vertical surfaces
8100             t_surf_v  => t_surf_v_2; t_surf_v_p  => t_surf_v_1
8101             t_wall_v     => t_wall_v_2;    t_wall_v_p     => t_wall_v_1
8102             t_surf_window_v  => t_surf_window_v_2; t_surf_window_v_p  => t_surf_window_v_1
8103             t_window_v     => t_window_v_2;    t_window_v_p     => t_window_v_1
8104             t_surf_green_v  => t_surf_green_v_2; t_surf_green_v_p  => t_surf_green_v_1
8105             t_green_v     => t_green_v_2;    t_green_v_p     => t_green_v_1
8106       END SELECT
8107#endif
8108       
8109    END SUBROUTINE usm_swap_timelevel
8110
8111!------------------------------------------------------------------------------!
8112! Description:
8113! ------------
8114!> Subroutine writes t_surf and t_wall data into restart files
8115!------------------------------------------------------------------------------!
8116    SUBROUTINE usm_wrd_local
8117
8118   
8119       IMPLICIT NONE
8120       
8121       CHARACTER(LEN=1) ::  dum     !< dummy string to create output-variable name 
8122       INTEGER(iwp)     ::  l       !< index surface type orientation
8123
8124       CALL wrd_write_string( 'ns_h_on_file_usm' )
8125       WRITE ( 14 )  surf_usm_h%ns
8126
8127       CALL wrd_write_string( 'ns_v_on_file_usm' )
8128       WRITE ( 14 )  surf_usm_v(0:3)%ns
8129
8130       CALL wrd_write_string( 'usm_start_index_h' )
8131       WRITE ( 14 )  surf_usm_h%start_index
8132
8133       CALL wrd_write_string( 'usm_end_index_h' )
8134       WRITE ( 14 )  surf_usm_h%end_index
8135
8136       CALL wrd_write_string( 't_surf_h' )
8137       WRITE ( 14 )  t_surf_h
8138
8139       CALL wrd_write_string( 't_surf_window_h' )
8140       WRITE ( 14 )  t_surf_window_h
8141
8142       CALL wrd_write_string( 't_surf_green_h' )
8143       WRITE ( 14 )  t_surf_green_h
8144
8145       DO  l = 0, 3
8146
8147          CALL wrd_write_string( 'usm_start_index_v' )
8148          WRITE ( 14 )  surf_usm_v(l)%start_index
8149
8150          CALL wrd_write_string( 'usm_end_index_v' )
8151          WRITE ( 14 )  surf_usm_v(l)%end_index
8152
8153          WRITE( dum, '(I1)')  l         
8154
8155          CALL wrd_write_string( 't_surf_v(' // dum // ')' )
8156          WRITE ( 14 )  t_surf_v(l)%t
8157
8158          CALL wrd_write_string( 't_surf_window_v(' // dum // ')' )
8159          WRITE ( 14 ) t_surf_window_v(l)%t     
8160
8161          CALL wrd_write_string( 't_surf_green_v(' // dum // ')' )
8162          WRITE ( 14 ) t_surf_green_v(l)%t   
8163         
8164       ENDDO
8165
8166       CALL wrd_write_string( 'usm_start_index_h' )
8167       WRITE ( 14 )  surf_usm_h%start_index
8168
8169       CALL wrd_write_string( 'usm_end_index_h' )
8170       WRITE ( 14 )  surf_usm_h%end_index
8171
8172       CALL wrd_write_string( 't_wall_h' )
8173       WRITE ( 14 )  t_wall_h
8174
8175       CALL wrd_write_string( 't_window_h' )
8176       WRITE ( 14 )  t_window_h
8177
8178       CALL wrd_write_string( 't_green_h' )
8179       WRITE ( 14 )  t_green_h
8180
8181       DO  l = 0, 3
8182
8183          CALL wrd_write_string( 'usm_start_index_v' )
8184          WRITE ( 14 )  surf_usm_v(l)%start_index
8185
8186          CALL wrd_write_string( 'usm_end_index_v' )
8187          WRITE ( 14 )  surf_usm_v(l)%end_index
8188
8189          WRITE( dum, '(I1)')  l     
8190
8191          CALL wrd_write_string( 't_wall_v(' // dum // ')' )
8192          WRITE ( 14 )  t_wall_v(l)%t
8193
8194          CALL wrd_write_string( 't_window_v(' // dum // ')' )
8195          WRITE ( 14 )  t_window_v(l)%t
8196
8197          CALL wrd_write_string( 't_green_v(' // dum // ')' )
8198          WRITE ( 14 )  t_green_v(l)%t
8199       
8200       ENDDO
8201
8202       
8203    END SUBROUTINE usm_wrd_local
8204
8205!
8206!-- Integrated stability function for heat and moisture
8207    FUNCTION psi_h( zeta )
8208
8209           USE kinds
8210
8211       IMPLICIT NONE
8212
8213       REAL(wp)            :: psi_h !< Integrated similarity function result
8214       REAL(wp)            :: zeta  !< Stability parameter z/L
8215       REAL(wp)            :: x     !< dummy variable
8216
8217       REAL(wp), PARAMETER :: a = 1.0_wp            !< constant
8218       REAL(wp), PARAMETER :: b = 0.66666666666_wp  !< constant
8219       REAL(wp), PARAMETER :: c = 5.0_wp            !< constant
8220       REAL(wp), PARAMETER :: d = 0.35_wp           !< constant
8221       REAL(wp), PARAMETER :: c_d_d = c / d         !< constant
8222       REAL(wp), PARAMETER :: bc_d_d = b * c / d    !< constant
8223
8224
8225      IF ( zeta < 0.0_wp )  THEN
8226         x = SQRT( 1.0_wp  - 16.0_wp * zeta )
8227         psi_h = 2.0_wp * LOG( (1.0_wp + x ) / 2.0_wp )
8228      ELSE
8229         psi_h = - b * ( zeta - c_d_d ) * EXP( -d * zeta ) - (1.0_wp          &
8230                 + 0.66666666666_wp * a * zeta )**1.5_wp - bc_d_d             &
8231                 + 1.0_wp
8232!
8233!--       Old version for stable conditions (only valid for z/L < 0.5)
8234!--       psi_h = - 5.0_wp * zeta
8235       ENDIF
8236
8237   END FUNCTION psi_h
8238   
8239 END MODULE urban_surface_mod
Note: See TracBrowser for help on using the repository browser.