source: palm/trunk/SOURCE/netcdf_data_input_mod.f90 @ 3943

Last change on this file since 3943 was 3943, checked in by maronga, 6 years ago

bugfixes in urban surface model; output of greenz roof transpiration added/corrected; minor formatting improvements

  • Property svn:keywords set to Id
File size: 283.0 KB
Line 
1!> @file netcdf_data_input_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 1997-2019 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: netcdf_data_input_mod.f90 3943 2019-05-02 09:50:41Z maronga $
27! Temporarily disabled some (faulty) checks for static driver.
28!
29! 3942 2019-04-30 13:08:30Z kanani
30! Fix: increase LEN of all NetCDF attribute values (caused crash in
31! netcdf_create_global_atts due to insufficient length)
32!
33! 3941 2019-04-30 09:48:33Z suehring
34! Move check for grid dimension to an earlier point in time when first array
35! is read.
36! Improve checks for building types / IDs with respect to 2D/3D buildings.
37!
38! 3885 2019-04-11 11:29:34Z kanani
39! Changes related to global restructuring of location messages and introduction
40! of additional debug messages
41!
42! 3864 2019-04-05 09:01:56Z monakurppa
43! get_variable_4d_to_3d_real modified to enable read in data of type
44! data(t,y,x,n) one timestep at a time + some routines made public
45!
46! 3855 2019-04-03 10:00:59Z suehring
47! Typo removed
48!
49! 3854 2019-04-02 16:59:33Z suehring
50! Bugfix in one of the checks. Typo removed.
51!
52! 3744 2019-02-15 18:38:58Z suehring
53! Enable mesoscale offline nesting for chemistry variables as well as
54! initialization of chemistry via dynamic input file.
55!
56! 3705 2019-01-29 19:56:39Z suehring
57! Interface for attribute input of 8-bit and 32-bit integer
58!
59! 3704 2019-01-29 19:51:41Z suehring
60! unused variables removed
61!
62! 3560 2018-11-23 09:20:21Z raasch
63! Some formatting adjustment
64!
65! 3556 2018-11-22 14:11:57Z suehring
66! variables documented and unused variables removed
67!
68! 3552 2018-11-22 10:28:35Z suehring
69! Revise ghost point exchange and resizing of input variables
70!
71! 3542 2018-11-20 17:04:13Z suehring
72! - read optional attributes from file
73! - set default origin_time
74!
75! 3518 2018-11-12 18:10:23Z suehring
76! Additional checks
77!
78! 3516 2018-11-12 15:49:39Z gronemeier
79! bugfix: - difference in z coordinate between file and PALM must be <1e-6
80!         - output of error 553 for all PEs
81!
82! 3498 2018-11-07 10:53:03Z gronemeier
83! Bugfix: print error message by processor which encounters the error
84!
85! 3485 2018-11-03 17:09:40Z gronemeier
86! - get central meridian from origin_lon if crs does not exist
87! - set default origin_lon to 0
88!
89! 3483 2018-11-02 14:19:26Z raasch
90! bugfix: misplaced directives for netCDF fixed
91!
92! 3474 2018-10-30 21:07:39Z kanani
93! Add UV exposure model input (Schrempf)
94!
95! 3472 2018-10-30 20:43:50Z suehring
96! Salsa implemented
97!
98! 3464 2018-10-30 18:08:55Z kanani
99! Define coordinate reference system (crs) and read from input dataset
100! Revise default values for reference coordinates
101!
102! 3459 2018-10-30 15:04:11Z gronemeier
103! from chemistry branch r3443, banzhafs, Russo:
104! Uncommented lines on dimension of surface_fractions
105! Removed par_emis_time_factor variable, moved to chem_emissions_mod
106! Initialized nspec and other emission variables at time of declaration
107! Modified EXPERT mode to PRE-PROCESSED mode
108! Introduced Chemistry static netcdf file
109! Added the routine for reading-in netcdf data for chemistry
110! Added routines to get_variable interface specific for chemistry files
111!
112! 3429 2018-10-25 13:04:23Z knoop
113! add default values of origin_x/y/z
114!
115! 3404 2018-10-23 13:29:11Z suehring
116! Consider time-dependent geostrophic wind components in offline nesting
117!
118! 3376 2018-10-19 10:15:32Z suehring
119! Additional check for consistent building initialization implemented
120!
121! 3347 2018-10-15 14:21:08Z suehring
122! Subroutine renamed
123!
124! 3257 2018-09-17 17:11:46Z suehring
125! (from branch resler)
126! Formatting
127!
128! 3298 2018-10-02 12:21:11Z kanani
129! Modified EXPERT mode to PRE-PROCESSED mode (Russo)
130! Introduced Chemistry static netcdf file (Russo)
131! Added the routine for reading-in netcdf data for chemistry (Russo)
132! Added routines to get_variable interface specific for chemistry files (Russo)
133!
134! 3257 2018-09-17 17:11:46Z suehring
135! Adjust checks for building_type and building_id, which is necessary after
136! topography filtering (building_type and id can be modified by the filtering).
137!
138! 3254 2018-09-17 10:53:57Z suehring
139! Additional check for surface_fractions and and checks for building_id and
140! building_type extended.
141!
142! 3241 2018-09-12 15:02:00Z raasch
143! unused variables removed
144!
145! 3215 2018-08-29 09:58:59Z suehring
146! - Separate input of soil properties from input of atmospheric data. This
147!   enables input of soil properties also in child domains without any
148!   dependence on atmospheric input
149! - Check for missing initial 1D/3D data in dynamic input file
150! - Revise checks for matching grid spacing in model and input file
151! - Bugfix, add netcdf4_parallel directive for collective read operation
152! - Revise error message numbers
153!
154! 3209 2018-08-27 16:58:37Z suehring
155! Read zsoil dimension length only if soil variables are provided
156!
157! 3183 2018-07-27 14:25:55Z suehring
158! Adjust input of dynamic driver according to revised Inifor version.
159! Replace simulated_time by time_since_reference_point.
160! Rename variables in mesoscale-offline nesting mode.
161!
162! 3182 2018-07-27 13:36:03Z suehring
163! Slightly revise check for surface_fraction in order to check only the relevant
164! fractions
165!
166! 3103 2018-07-04 17:30:52Z suehring
167! New check for negative terrain heights
168!
169! 3089 2018-06-27 13:20:38Z suehring
170! Revise call for message routine in case of local data inconsistencies.
171!
172! 3054 2018-06-01 16:08:59Z gronemeier
173! Bugfix: force an MPI abort if errors occur while reading building heights
174! from ASCII file
175!
176! 3053 2018-06-01 12:59:07Z suehring
177! Revise checks for variable surface_fraction
178!
179! 3051 2018-05-30 17:43:55Z suehring
180! - Speed-up NetCDF input
181! - Revise input routines and remove NetCDF input via IO-blocks since this is
182!   not working in parallel mode in case blocking collective read operations
183!   are done
184! - Temporarily revoke renaming of input variables in dynamic driver (tend_ug,
185!   tend_vg, zsoil) in order to keep dynamic input file working with current
186!   model version
187! - More detailed error messages created
188!
189! 3045 2018-05-28 07:55:41Z Giersch
190! Error messages revised
191!
192! 3041 2018-05-25 10:39:54Z gronemeier
193! Add data type for global file attributes
194! Add read of global attributes of static driver
195!
196! 3037 2018-05-24 10:39:29Z gronemeier
197! renamed 'depth' to 'zsoil'
198!
199! 3036 2018-05-24 10:18:26Z gronemeier
200! Revision of input vars according to UC2 data standard
201!  - renamed 'orography_2D' to 'zt'
202!  - renamed 'buildings_2D' to 'buildings_2d'
203!  - renamed 'buildings_3D' to 'buildings_3d'
204!  - renamed 'leaf_are_density' to 'lad'
205!  - renamed 'basal_are_density' to 'bad'
206!  - renamed 'root_are_density_lad' to 'root_area_dens_r'
207!  - renamed 'root_are_density_lsm' to 'root_area_dens_s'
208!  - renamed 'ls_forcing_ug' to 'tend_ug'
209!  - renamed 'ls_forcing_vg' to 'tend_vg'
210!
211! 3019 2018-05-13 07:05:43Z maronga
212! Improved reading speed of large NetCDF files
213!
214! 2963 2018-04-12 14:47:44Z suehring
215! - Revise checks for static input variables.
216! - Introduce index for vegetation/wall, pavement/green-wall and water/window
217!   surfaces, for clearer access of surface fraction, albedo, emissivity, etc. .
218!
219! 2958 2018-04-11 15:38:13Z suehring
220! Synchronize longitude and latitude between nested model domains, values are
221! taken from the root model.
222!
223! 2955 2018-04-09 15:14:01Z suehring
224! Extend checks for consistent setting of buildings, its ID and type.
225! Add log-points to measure CPU time of NetCDF data input.
226!
227! 2953 2018-04-09 11:26:02Z suehring
228! Bugfix in checks for initialization data
229!
230! 2947 2018-04-04 18:01:41Z suehring
231! Checks for dynamic input revised
232!
233! 2946 2018-04-04 17:01:23Z suehring
234! Bugfix for revision 2945, perform checks only if dynamic input file is
235! available.
236!
237! 2945 2018-04-04 16:27:14Z suehring
238! - Mimic for topography input slightly revised, in order to enable consistency
239!   checks
240! - Add checks for dimensions in dynamic input file and move already existing
241!   checks
242!
243! 2938 2018-03-27 15:52:42Z suehring
244! Initial read of geostrophic wind components from dynamic driver.
245!
246! 2773 2018-01-30 14:12:54Z suehring
247! Revise checks for surface_fraction.
248!
249! 2925 2018-03-23 14:54:11Z suehring
250! Check for further inconsistent settings of surface_fractions.
251! Some messages slightly rephrased and error numbers renamed.
252!
253! 2898 2018-03-15 13:03:01Z suehring
254! Check if each building has a type. Further, check if dimensions in static
255! input file match the model dimensions.
256!
257! 2897 2018-03-15 11:47:16Z suehring
258! Relax restrictions for topography input, terrain and building heights can be
259! input separately and are not mandatory any more.
260!
261! 2874 2018-03-13 10:55:42Z knoop
262! Bugfix: wrong placement of netcdf cpp-macros fixed
263!
264! 2794 2018-02-07 14:09:43Z knoop
265! Check if 3D building input is consistent to numeric grid.
266!
267! 2773 2018-01-30 14:12:54Z suehring
268! - Enable initialization with 3D topography.
269! - Move check for correct initialization in nesting mode to check_parameters.
270!
271! 2772 2018-01-29 13:10:35Z suehring
272! Initialization of simulation independent on land-surface model.
273!
274! 2746 2018-01-15 12:06:04Z suehring
275! Read plant-canopy variables independently on land-surface model usage
276!
277! 2718 2018-01-02 08:49:38Z maronga
278! Corrected "Former revisions" section
279!
280! 2711 2017-12-20 17:04:49Z suehring
281! Rename subroutine close_file to avoid double-naming.
282!
283! 2700 2017-12-15 14:12:35Z suehring
284!
285! 2696 2017-12-14 17:12:51Z kanani
286! Initial revision (suehring)
287!
288!
289!
290!
291! Authors:
292! --------
293! @author Matthias Suehring
294!
295! Description:
296! ------------
297!> Modulue contains routines to input data according to Palm input data
298!> standart using dynamic and static input files.
299!> @todo - Chemistry: revise reading of netcdf file and ajdust formatting according to standard!!!
300!> @todo - Order input alphabetically
301!> @todo - Revise error messages and error numbers
302!> @todo - Input of missing quantities (chemical species, emission rates)
303!> @todo - Defninition and input of still missing variable attributes
304!> @todo - Input of initial geostrophic wind profiles with cyclic conditions.
305!------------------------------------------------------------------------------!
306 MODULE netcdf_data_input_mod
307
308    USE control_parameters,                                                    &
309        ONLY:  coupling_char, io_blocks, io_group
310
311    USE cpulog,                                                                &
312        ONLY:  cpu_log, log_point_s
313
314    USE indices,                                                               &
315        ONLY:  nbgp
316
317    USE kinds
318
319#if defined ( __netcdf )
320    USE NETCDF
321#endif
322
323    USE pegrid
324
325    USE surface_mod,                                                           &
326        ONLY:  ind_pav_green, ind_veg_wall, ind_wat_win
327!
328!-- Define type for dimensions.
329    TYPE dims_xy
330       INTEGER(iwp) :: nx                             !< dimension length in x
331       INTEGER(iwp) :: ny                             !< dimension length in y
332       INTEGER(iwp) :: nz                             !< dimension length in z
333       REAL(wp), DIMENSION(:), ALLOCATABLE :: x       !< dimension array in x
334       REAL(wp), DIMENSION(:), ALLOCATABLE :: y       !< dimension array in y
335       REAL(wp), DIMENSION(:), ALLOCATABLE :: z       !< dimension array in z
336    END TYPE dims_xy
337!
338!-- Define data type for nesting in larger-scale models like COSMO.
339!-- Data type comprises u, v, w, pt, and q at lateral and top boundaries.
340    TYPE nest_offl_type
341
342       CHARACTER(LEN=16) ::  char_l = 'ls_forcing_left_'  !< leading substring for variables at left boundary
343       CHARACTER(LEN=17) ::  char_n = 'ls_forcing_north_' !< leading substring for variables at north boundary 
344       CHARACTER(LEN=17) ::  char_r = 'ls_forcing_right_' !< leading substring for variables at right boundary 
345       CHARACTER(LEN=17) ::  char_s = 'ls_forcing_south_' !< leading substring for variables at south boundary
346       CHARACTER(LEN=15) ::  char_t = 'ls_forcing_top_'   !< leading substring for variables at top boundary
347   
348       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names         !< list of variable in dynamic input file
349       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_l  !< names of mesoscale nested chemistry variables at left boundary
350       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_n  !< names of mesoscale nested chemistry variables at north boundary
351       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_r  !< names of mesoscale nested chemistry variables at right boundary
352       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_s  !< names of mesoscale nested chemistry variables at south boundary
353       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_t  !< names of mesoscale nested chemistry variables at top boundary
354
355       INTEGER(iwp) ::  nt     !< number of time levels in dynamic input file
356       INTEGER(iwp) ::  nzu    !< number of vertical levels on scalar grid in dynamic input file
357       INTEGER(iwp) ::  nzw    !< number of vertical levels on w grid in dynamic input file
358       INTEGER(iwp) ::  tind   !< time index for reference time in mesoscale-offline nesting
359       INTEGER(iwp) ::  tind_p !< time index for following time in mesoscale-offline nesting
360
361       LOGICAL      ::  init         = .FALSE. !< flag indicating that offline nesting is already initialized
362       
363       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_l !< flags inidicating whether left boundary data for chemistry is in dynamic input file 
364       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_n !< flags inidicating whether north boundary data for chemistry is in dynamic input file
365       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_r !< flags inidicating whether right boundary data for chemistry is in dynamic input file
366       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_s !< flags inidicating whether south boundary data for chemistry is in dynamic input file
367       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_t !< flags inidicating whether top boundary data for chemistry is in dynamic input file
368
369       REAL(wp), DIMENSION(:), ALLOCATABLE ::  surface_pressure !< time dependent surface pressure
370       REAL(wp), DIMENSION(:), ALLOCATABLE ::  time             !< time levels in dynamic input file
371       REAL(wp), DIMENSION(:), ALLOCATABLE ::  zu_atmos         !< vertical levels at scalar grid in dynamic input file
372       REAL(wp), DIMENSION(:), ALLOCATABLE ::  zw_atmos         !< vertical levels at w grid in dynamic input file
373
374       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ug         !< domain-averaged geostrophic component
375       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  vg         !< domain-averaged geostrophic component
376
377       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_left   !< u-component at left boundary
378       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_left   !< v-component at left boundary
379       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_left   !< w-component at left boundary
380       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_left   !< mixing ratio at left boundary
381       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_left  !< potentital temperautre at left boundary
382
383       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_north  !< u-component at north boundary
384       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_north  !< v-component at north boundary
385       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_north  !< w-component at north boundary
386       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_north  !< mixing ratio at north boundary
387       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_north !< potentital temperautre at north boundary
388
389       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_right  !< u-component at right boundary
390       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_right  !< v-component at right boundary
391       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_right  !< w-component at right boundary
392       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_right  !< mixing ratio at right boundary
393       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_right !< potentital temperautre at right boundary
394
395       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_south  !< u-component at south boundary
396       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_south  !< v-component at south boundary
397       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_south  !< w-component at south boundary
398       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_south  !< mixing ratio at south boundary
399       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_south !< potentital temperautre at south boundary
400
401       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_top    !< u-component at top boundary
402       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_top    !< v-component at top boundary
403       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_top    !< w-component at top boundary
404       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_top    !< mixing ratio at top boundary
405       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_top   !< potentital temperautre at top boundary
406       
407       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_left   !< chemical species at left boundary
408       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_north  !< chemical species at left boundary
409       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_right  !< chemical species at left boundary
410       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_south  !< chemical species at left boundary
411       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_top    !< chemical species at left boundary
412
413    END TYPE nest_offl_type
414
415    TYPE init_type
416
417       CHARACTER(LEN=16) ::  init_char = 'init_atmosphere_'          !< leading substring for init variables
418       CHARACTER(LEN=23) ::  origin_time = '2000-01-01 00:00:00 +00' !< reference time of input data
419       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem !< list of chemistry variable names that can potentially be on file
420
421       INTEGER(iwp) ::  lod_msoil !< level of detail - soil moisture
422       INTEGER(iwp) ::  lod_pt    !< level of detail - pt
423       INTEGER(iwp) ::  lod_q     !< level of detail - q
424       INTEGER(iwp) ::  lod_tsoil !< level of detail - soil temperature
425       INTEGER(iwp) ::  lod_u     !< level of detail - u-component
426       INTEGER(iwp) ::  lod_v     !< level of detail - v-component
427       INTEGER(iwp) ::  lod_w     !< level of detail - w-component
428       INTEGER(iwp) ::  nx        !< number of scalar grid points along x in dynamic input file
429       INTEGER(iwp) ::  nxu       !< number of u grid points along x in dynamic input file
430       INTEGER(iwp) ::  ny        !< number of scalar grid points along y in dynamic input file
431       INTEGER(iwp) ::  nyv       !< number of v grid points along y in dynamic input file
432       INTEGER(iwp) ::  nzs       !< number of vertical soil levels in dynamic input file
433       INTEGER(iwp) ::  nzu       !< number of vertical levels on scalar grid in dynamic input file
434       INTEGER(iwp) ::  nzw       !< number of vertical levels on w grid in dynamic input file
435       
436       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  lod_chem !< level of detail - chemistry variables
437
438       LOGICAL ::  from_file_msoil  = .FALSE. !< flag indicating whether soil moisture is already initialized from file
439       LOGICAL ::  from_file_pt     = .FALSE. !< flag indicating whether pt is already initialized from file
440       LOGICAL ::  from_file_q      = .FALSE. !< flag indicating whether q is already initialized from file
441       LOGICAL ::  from_file_tsoil  = .FALSE. !< flag indicating whether soil temperature is already initialized from file
442       LOGICAL ::  from_file_u      = .FALSE. !< flag indicating whether u is already initialized from file
443       LOGICAL ::  from_file_ug     = .FALSE. !< flag indicating whether ug is already initialized from file
444       LOGICAL ::  from_file_v      = .FALSE. !< flag indicating whether v is already initialized from file
445       LOGICAL ::  from_file_vg     = .FALSE. !< flag indicating whether ug is already initialized from file
446       LOGICAL ::  from_file_w      = .FALSE. !< flag indicating whether w is already initialized from file
447       
448       LOGICAL, DIMENSION(:), ALLOCATABLE ::  from_file_chem !< flag indicating whether chemistry variable is read from file
449
450       REAL(wp) ::  fill_msoil              !< fill value for soil moisture
451       REAL(wp) ::  fill_pt                 !< fill value for pt
452       REAL(wp) ::  fill_q                  !< fill value for q
453       REAL(wp) ::  fill_tsoil              !< fill value for soil temperature
454       REAL(wp) ::  fill_u                  !< fill value for u
455       REAL(wp) ::  fill_v                  !< fill value for v
456       REAL(wp) ::  fill_w                  !< fill value for w
457       REAL(wp) ::  latitude = 0.0_wp       !< latitude of the lower left corner
458       REAL(wp) ::  longitude = 0.0_wp      !< longitude of the lower left corner
459       REAL(wp) ::  origin_x = 500000.0_wp  !< UTM easting of the lower left corner
460       REAL(wp) ::  origin_y = 0.0_wp       !< UTM northing of the lower left corner
461       REAL(wp) ::  origin_z = 0.0_wp       !< reference height of input data
462       REAL(wp) ::  rotation_angle = 0.0_wp !< rotation angle of input data
463
464       REAL(wp), DIMENSION(:), ALLOCATABLE ::  fill_chem    !< fill value - chemistry variables
465       REAL(wp), DIMENSION(:), ALLOCATABLE ::  msoil_1d     !< initial vertical profile of soil moisture
466       REAL(wp), DIMENSION(:), ALLOCATABLE ::  pt_init      !< initial vertical profile of pt
467       REAL(wp), DIMENSION(:), ALLOCATABLE ::  q_init       !< initial vertical profile of q
468       REAL(wp), DIMENSION(:), ALLOCATABLE ::  tsoil_1d     !< initial vertical profile of soil temperature
469       REAL(wp), DIMENSION(:), ALLOCATABLE ::  u_init       !< initial vertical profile of u
470       REAL(wp), DIMENSION(:), ALLOCATABLE ::  ug_init      !< initial vertical profile of ug
471       REAL(wp), DIMENSION(:), ALLOCATABLE ::  v_init       !< initial vertical profile of v
472       REAL(wp), DIMENSION(:), ALLOCATABLE ::  vg_init      !< initial vertical profile of ug
473       REAL(wp), DIMENSION(:), ALLOCATABLE ::  w_init       !< initial vertical profile of w
474       REAL(wp), DIMENSION(:), ALLOCATABLE ::  z_soil       !< vertical levels in soil in dynamic input file, used for interpolation
475       REAL(wp), DIMENSION(:), ALLOCATABLE ::  zu_atmos     !< vertical levels at scalar grid in dynamic input file, used for interpolation
476       REAL(wp), DIMENSION(:), ALLOCATABLE ::  zw_atmos     !< vertical levels at w grid in dynamic input file, used for interpolation
477       
478       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  chem_init  !< initial vertical profiles of chemistry variables
479
480
481       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  msoil_3d !< initial 3d soil moisture provide by Inifor and interpolated onto soil grid
482       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  tsoil_3d !< initial 3d soil temperature provide by Inifor and interpolated onto soil grid
483
484    END TYPE init_type
485
486!-- Data type for the general information of chemistry emissions, do not dependent on the particular chemical species
487    TYPE chem_emis_att_type 
488
489       !-DIMENSIONS
490       INTEGER(iwp)                                 :: nspec=0                   !< number of chem species for which emission values are provided
491       INTEGER(iwp)                                 :: ncat=0                    !< number of emission categories
492       INTEGER(iwp)                                 :: nvoc=0                    !< number of VOCs components
493       INTEGER(iwp)                                 :: npm=0                     !< number of PMs components
494       INTEGER(iwp)                                 :: nnox=2                    !< number of NOx components: NO and NO2
495       INTEGER(iwp)                                 :: nsox=2                    !< number of SOx components: SO and SO4
496       INTEGER(iwp)                                 :: nhoursyear                !< number of hours of a specific year in the HOURLY mode
497                                                                                 !  of the default mode
498       INTEGER(iwp)                                 :: nmonthdayhour             !< number of month days and hours in the MDH mode
499                                                                                 !  of the default mode
500       INTEGER(iwp)                                 :: dt_emission               !< Number of emissions timesteps for one year
501                                                                                 !  in the pre-processed emissions case
502       !-- 1d emission input variables
503       CHARACTER (LEN=25),ALLOCATABLE, DIMENSION(:) :: pm_name                   !< Names of PMs components
504       CHARACTER (LEN=25),ALLOCATABLE, DIMENSION(:) :: cat_name                  !< Emission categories names
505       CHARACTER (LEN=25),ALLOCATABLE, DIMENSION(:) :: species_name              !< Names of emission chemical species
506       CHARACTER (LEN=25),ALLOCATABLE, DIMENSION(:) :: voc_name                  !< Names of VOCs components
507       CHARACTER (LEN=25)                           :: units                     !< Units
508
509       INTEGER(iwp)                                 :: i_hour                    !< indices for assigning the emission values at different timesteps
510       INTEGER(iwp),ALLOCATABLE, DIMENSION(:)       :: cat_index                 !< Index of emission categories
511       INTEGER(iwp),ALLOCATABLE, DIMENSION(:)       :: species_index             !< Index of emission chem species
512
513       REAL(wp),ALLOCATABLE, DIMENSION(:)           :: xm                        !< Molecular masses of emission chem species
514
515       !-- 2d emission input variables
516       REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: hourly_emis_time_factor   !< Time factors for HOURLY emissions (DEFAULT mode)
517       REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: mdh_emis_time_factor      !< Time factors for MDH emissions (DEFAULT mode)
518       REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: nox_comp                  !< Composition of NO and NO2
519       REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: sox_comp                  !< Composition of SO2 and SO4
520       REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: voc_comp                  !< Composition of different VOC components (number not fixed)
521
522       !-- 3d emission input variables
523       REAL(wp),ALLOCATABLE, DIMENSION(:,:,:)       :: pm_comp                   !< Composition of different PMs components (number not fixed)
524 
525    END TYPE chem_emis_att_type
526
527
528!-- Data type for the values of chemistry emissions ERUSSO
529    TYPE chem_emis_val_type 
530
531       !REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: stack_height              !< stack height
532
533       !-- 3d emission input variables
534       REAL(wp),ALLOCATABLE, DIMENSION(:,:,:)     :: default_emission_data     !< Input Values emissions DEFAULT mode
535
536       !-- 4d emission input variables
537       REAL(wp),ALLOCATABLE, DIMENSION(:,:,:,:)   :: preproc_emission_data      !< Input Values emissions PRE-PROCESSED mode
538
539    END TYPE chem_emis_val_type
540
541!
542!-- Define data structures for different input data types.
543!-- 8-bit Integer 2D
544    TYPE int_2d_8bit
545       INTEGER(KIND=1) ::  fill = -127                      !< fill value
546       INTEGER(KIND=1), DIMENSION(:,:), ALLOCATABLE ::  var !< respective variable
547
548       LOGICAL ::  from_file = .FALSE.  !< flag indicating whether an input variable is available and read from file or default values are used
549    END TYPE int_2d_8bit
550!
551!-- 8-bit Integer 3D
552    TYPE int_3d_8bit
553       INTEGER(KIND=1) ::  fill = -127                           !< fill value
554       INTEGER(KIND=1), DIMENSION(:,:,:), ALLOCATABLE ::  var_3d !< respective variable
555
556       LOGICAL ::  from_file = .FALSE.  !< flag indicating whether an input variable is available and read from file or default values are used
557    END TYPE int_3d_8bit
558!
559!-- 32-bit Integer 2D
560    TYPE int_2d_32bit
561       INTEGER(iwp) ::  fill = -9999                      !< fill value
562       INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  var  !< respective variable
563
564       LOGICAL ::  from_file = .FALSE. !< flag indicating whether an input variable is available and read from file or default values are used
565    END TYPE int_2d_32bit
566
567!
568!-- Define data type to read 2D real variables
569    TYPE real_2d
570       LOGICAL ::  from_file = .FALSE.  !< flag indicating whether an input variable is available and read from file or default values are used
571
572       REAL(wp) ::  fill = -9999.9_wp                !< fill value
573       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  var !< respective variable
574    END TYPE real_2d
575
576!
577!-- Define data type to read 3D real variables
578    TYPE real_3d
579       LOGICAL ::  from_file = .FALSE.  !< flag indicating whether an input variable is available and read from file or default values are used
580
581       INTEGER(iwp) ::  nz   !< number of grid points along vertical dimension
582
583       REAL(wp) ::  fill = -9999.9_wp                  !< fill value
584       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  var !< respective variable
585    END TYPE real_3d
586!
587!-- Define data structure where the dimension and type of the input depends
588!-- on the given level of detail.
589!-- For buildings, the input is either 2D float, or 3d byte.
590    TYPE build_in
591       INTEGER(iwp)    ::  lod = 1                               !< level of detail
592       INTEGER(KIND=1) ::  fill2 = -127                          !< fill value for lod = 2
593       INTEGER(iwp)    ::  nz                                    !< number of vertical layers in file
594       INTEGER(KIND=1), DIMENSION(:,:,:), ALLOCATABLE ::  var_3d !< 3d variable (lod = 2)
595
596       REAL(wp), DIMENSION(:), ALLOCATABLE ::  z                 !< vertical coordinate for 3D building, used for consistency check
597
598       LOGICAL ::  from_file = .FALSE.  !< flag indicating whether an input variable is available and read from file or default values are used
599
600       REAL(wp)                              ::  fill1 = -9999.9_wp !< fill values for lod = 1
601       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  var_2d             !< 2d variable (lod = 1)
602    END TYPE build_in
603
604!
605!-- For soil_type, the input is either 2D or 3D one-byte integer.
606    TYPE soil_in
607       INTEGER(iwp)                                   ::  lod = 1      !< level of detail
608       INTEGER(KIND=1)                                ::  fill = -127  !< fill value for lod = 2
609       INTEGER(KIND=1), DIMENSION(:,:), ALLOCATABLE   ::  var_2d       !< 2d variable (lod = 1)
610       INTEGER(KIND=1), DIMENSION(:,:,:), ALLOCATABLE ::  var_3d       !< 3d variable (lod = 2)
611
612       LOGICAL ::  from_file = .FALSE.  !< flag indicating whether an input variable is available and read from file or default values are used
613    END TYPE soil_in
614
615!
616!-- Define data type for fractions between surface types
617    TYPE fracs
618       INTEGER(iwp)                            ::  nf             !< total number of fractions
619       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  nfracs         !< dimension array for fraction
620
621       LOGICAL ::  from_file = .FALSE. !< flag indicating whether an input variable is available and read from file or default values are used
622
623       REAL(wp)                                ::  fill = -9999.9_wp !< fill value
624       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  frac              !< respective fraction between different surface types
625    END TYPE fracs
626!
627!-- Data type for parameter lists, Depending on the given level of detail,
628!-- the input is 3D or 4D
629    TYPE pars
630       INTEGER(iwp)                            ::  lod = 1         !< level of detail
631       INTEGER(iwp)                            ::  np              !< total number of parameters
632       INTEGER(iwp)                            ::  nz              !< vertical dimension - number of soil layers
633       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  layers          !< dimension array for soil layers
634       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  pars            !< dimension array for parameters
635
636       LOGICAL ::  from_file = .FALSE.  !< flag indicating whether an input variable is available and read from file or default values are used
637
638       REAL(wp)                                  ::  fill = -9999.9_wp !< fill value
639       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  pars_xy           !< respective parameters, level of detail = 1
640       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  pars_xyz          !< respective parameters, level of detail = 2
641    END TYPE pars
642!
643!-- Define type for global file attributes
644!-- Please refer to the PALM data standard for a detailed description of each
645!-- attribute.
646    TYPE global_atts_type
647       CHARACTER(LEN=200) ::  acronym = ' '                      !< acronym of institution
648       CHARACTER(LEN=7)   ::  acronym_char = 'acronym'           !< name of attribute
649       CHARACTER(LEN=200) ::  author  = ' '                      !< first name, last name, email adress
650       CHARACTER(LEN=6)   ::  author_char = 'author'             !< name of attribute
651       CHARACTER(LEN=200) ::  campaign = 'PALM-4U'               !< name of campaign
652       CHARACTER(LEN=8)   ::  campaign_char = 'campaign'         !< name of attribute
653       CHARACTER(LEN=200) ::  comment = ' '                      !< comment to data
654       CHARACTER(LEN=7)   ::  comment_char = 'comment'           !< name of attribute
655       CHARACTER(LEN=200) ::  contact_person = ' '               !< first name, last name, email adress
656       CHARACTER(LEN=14)  ::  contact_person_char = 'contact_person'  !< name of attribute
657       CHARACTER(LEN=200) ::  conventions = 'CF-1.7'             !< netCDF convention
658       CHARACTER(LEN=11)  ::  conventions_char = 'Conventions'   !< name of attribute
659       CHARACTER(LEN=23 ) ::  creation_time = ' '                !< creation time of data set
660       CHARACTER(LEN=13)  ::  creation_time_char = 'creation_time'  !< name of attribute
661       CHARACTER(LEN=200) ::  data_content = ' '                 !< content of data set
662       CHARACTER(LEN=12)  ::  data_content_char = 'data_content' !< name of attribute
663       CHARACTER(LEN=200) ::  dependencies = ' '                 !< dependencies of data set
664       CHARACTER(LEN=12)  ::  dependencies_char = 'dependencies' !< name of attribute
665       CHARACTER(LEN=200) ::  history = ' '                      !< information about data processing
666       CHARACTER(LEN=7)   ::  history_char = 'history'           !< name of attribute
667       CHARACTER(LEN=200) ::  institution = ' '                  !< name of responsible institution
668       CHARACTER(LEN=11)  ::  institution_char = 'institution'   !< name of attribute
669       CHARACTER(LEN=200) ::  keywords = ' '                     !< keywords of data set
670       CHARACTER(LEN=8)   ::  keywords_char = 'keywords'         !< name of attribute
671       CHARACTER(LEN=200) ::  licence = ' '                      !< licence of data set
672       CHARACTER(LEN=7)   ::  licence_char = 'licence'           !< name of attribute
673       CHARACTER(LEN=200) ::  location = ' '                     !< place which refers to data set
674       CHARACTER(LEN=8)   ::  location_char = 'location'         !< name of attribute
675       CHARACTER(LEN=10)  ::  origin_lat_char = 'origin_lat'     !< name of attribute
676       CHARACTER(LEN=10)  ::  origin_lon_char = 'origin_lon'     !< name of attribute
677       CHARACTER(LEN=23 ) ::  origin_time = '2000-01-01 00:00:00 +00'  !< reference time
678       CHARACTER(LEN=11)  ::  origin_time_char = 'origin_time'   !< name of attribute
679       CHARACTER(LEN=8)   ::  origin_x_char = 'origin_x'         !< name of attribute
680       CHARACTER(LEN=8)   ::  origin_y_char = 'origin_y'         !< name of attribute
681       CHARACTER(LEN=8)   ::  origin_z_char = 'origin_z'         !< name of attribute
682       CHARACTER(LEN=12)  ::  palm_version_char = 'palm_version' !< name of attribute
683       CHARACTER(LEN=200) ::  references = ' '                   !< literature referring to data set
684       CHARACTER(LEN=10)  ::  references_char = 'references'     !< name of attribute
685       CHARACTER(LEN=14)  ::  rotation_angle_char = 'rotation_angle'  !< name of attribute
686       CHARACTER(LEN=200) ::  site = ' '                         !< name of model domain
687       CHARACTER(LEN=4)   ::  site_char = 'site'                 !< name of attribute
688       CHARACTER(LEN=200) ::  source = ' '                       !< source of data set
689       CHARACTER(LEN=6)   ::  source_char = 'source'             !< name of attribute
690       CHARACTER(LEN=200) ::  title = ' '                        !< title of data set
691       CHARACTER(LEN=5)   ::  title_char = 'title'               !< name of attribute
692       CHARACTER(LEN=7)   ::  version_char = 'version'           !< name of attribute
693
694       INTEGER(iwp) ::  version              !< version of data set
695
696       REAL(wp) ::  origin_lat               !< latitude of lower left corner
697       REAL(wp) ::  origin_lon               !< longitude of lower left corner
698       REAL(wp) ::  origin_x                 !< easting (UTM coordinate) of lower left corner
699       REAL(wp) ::  origin_y                 !< northing (UTM coordinate) of lower left corner
700       REAL(wp) ::  origin_z                 !< reference height
701       REAL(wp) ::  palm_version             !< PALM version of data set
702       REAL(wp) ::  rotation_angle           !< rotation angle of coordinate system of data set
703    END TYPE global_atts_type
704!
705!-- Define type for coordinate reference system (crs)
706    TYPE crs_type
707       CHARACTER(LEN=200) ::  epsg_code = 'EPSG:25831'                   !< EPSG code
708       CHARACTER(LEN=200) ::  grid_mapping_name = 'transverse_mercator'  !< name of grid mapping
709       CHARACTER(LEN=200) ::  long_name = 'coordinate reference system'  !< name of variable crs
710       CHARACTER(LEN=200) ::  units = 'm'                                !< unit of crs
711
712       REAL(wp) ::  false_easting = 500000.0_wp                  !< false easting
713       REAL(wp) ::  false_northing = 0.0_wp                      !< false northing
714       REAL(wp) ::  inverse_flattening = 298.257223563_wp        !< 1/f (default for WGS84)
715       REAL(wp) ::  latitude_of_projection_origin = 0.0_wp       !< latitude of projection origin
716       REAL(wp) ::  longitude_of_central_meridian = 3.0_wp       !< longitude of central meridian of UTM zone (default: zone 31)
717       REAL(wp) ::  longitude_of_prime_meridian = 0.0_wp         !< longitude of prime meridian
718       REAL(wp) ::  scale_factor_at_central_meridian = 0.9996_wp !< scale factor of UTM coordinates
719       REAL(wp) ::  semi_major_axis = 6378137.0_wp               !< length of semi major axis (default for WGS84)
720    END TYPE crs_type
721
722!
723!-- Define variables
724    TYPE(crs_type)   ::  coord_ref_sys  !< coordinate reference system
725
726    TYPE(dims_xy)    ::  dim_static     !< data structure for x, y-dimension in static input file
727
728    TYPE(nest_offl_type) ::  nest_offl  !< data structure for data input at lateral and top boundaries (provided by Inifor) 
729
730    TYPE(init_type) ::  init_3d    !< data structure for the initialization of the 3D flow and soil fields
731    TYPE(init_type) ::  init_model !< data structure for the initialization of the model
732
733!
734!-- Define 2D variables of type NC_BYTE
735    TYPE(int_2d_8bit)  ::  albedo_type_f     !< input variable for albedo type
736    TYPE(int_2d_8bit)  ::  building_type_f   !< input variable for building type
737    TYPE(int_2d_8bit)  ::  pavement_type_f   !< input variable for pavenment type
738    TYPE(int_2d_8bit)  ::  street_crossing_f !< input variable for water type
739    TYPE(int_2d_8bit)  ::  street_type_f     !< input variable for water type
740    TYPE(int_2d_8bit)  ::  vegetation_type_f !< input variable for vegetation type
741    TYPE(int_2d_8bit)  ::  water_type_f      !< input variable for water type
742!
743!-- Define 3D variables of type NC_BYTE
744    TYPE(int_3d_8bit)  ::  building_obstruction_f    !< input variable for building obstruction
745    TYPE(int_3d_8bit)  ::  building_obstruction_full !< input variable for building obstruction
746!
747!-- Define 2D variables of type NC_INT
748    TYPE(int_2d_32bit) ::  building_id_f     !< input variable for building ID
749!
750!-- Define 2D variables of type NC_FLOAT
751    TYPE(real_2d) ::  terrain_height_f       !< input variable for terrain height
752    TYPE(real_2d) ::  uvem_irradiance_f      !< input variable for uvem irradiance lookup table
753    TYPE(real_2d) ::  uvem_integration_f     !< input variable for uvem integration
754!
755!-- Define 3D variables of type NC_FLOAT
756    TYPE(real_3d) ::  basal_area_density_f    !< input variable for basal area density - resolved vegetation
757    TYPE(real_3d) ::  leaf_area_density_f     !< input variable for leaf area density - resolved vegetation
758    TYPE(real_3d) ::  root_area_density_lad_f !< input variable for root area density - resolved vegetation
759    TYPE(real_3d) ::  root_area_density_lsm_f !< input variable for root area density - parametrized vegetation
760    TYPE(real_3d) ::  uvem_radiance_f         !< input variable for uvem radiance lookup table
761    TYPE(real_3d) ::  uvem_projarea_f         !< input variable for uvem projection area lookup table
762!
763!-- Define input variable for buildings
764    TYPE(build_in) ::  buildings_f           !< input variable for buildings
765!
766!-- Define input variables for soil_type
767    TYPE(soil_in)  ::  soil_type_f           !< input variable for soil type
768
769    TYPE(fracs) ::  surface_fraction_f       !< input variable for surface fraction
770
771    TYPE(pars)  ::  albedo_pars_f              !< input variable for albedo parameters
772    TYPE(pars)  ::  building_pars_f            !< input variable for building parameters
773    TYPE(pars)  ::  pavement_pars_f            !< input variable for pavement parameters
774    TYPE(pars)  ::  pavement_subsurface_pars_f !< input variable for pavement parameters
775    TYPE(pars)  ::  soil_pars_f                !< input variable for soil parameters
776    TYPE(pars)  ::  vegetation_pars_f          !< input variable for vegetation parameters
777    TYPE(pars)  ::  water_pars_f               !< input variable for water parameters
778
779    TYPE(chem_emis_att_type)                             ::  chem_emis_att    !< Input Information of Chemistry Emission Data from netcdf 
780    TYPE(chem_emis_val_type), ALLOCATABLE, DIMENSION(:)  ::  chem_emis        !< Input Chemistry Emission Data from netcdf 
781
782    CHARACTER(LEN=3)  ::  char_lod  = 'lod'         !< name of level-of-detail attribute in NetCDF file
783
784    CHARACTER(LEN=10) ::  char_fill = '_FillValue'        !< name of fill value attribute in NetCDF file
785
786    CHARACTER(LEN=100) ::  input_file_static  = 'PIDS_STATIC'  !< Name of file which comprises static input data
787    CHARACTER(LEN=100) ::  input_file_dynamic = 'PIDS_DYNAMIC' !< Name of file which comprises dynamic input data
788    CHARACTER(LEN=100) ::  input_file_chem    = 'PIDS_CHEM'    !< Name of file which comprises chemistry input data
789    CHARACTER(LEN=100) ::  input_file_uvem    = 'PIDS_UVEM'    !< Name of file which comprises static uv_exposure model input data
790    CHARACTER(LEN=100) ::  input_file_vm      = 'PIDS_VM'      !< Name of file which comprises virtual measurement data
791   
792    CHARACTER(LEN=25), ALLOCATABLE, DIMENSION(:)    ::  string_values  !< output of string variables read from netcdf input files
793
794    INTEGER(iwp)                                     ::  id_emis        !< NetCDF id of input file for chemistry emissions: TBD: It has to be removed
795
796    INTEGER(iwp) ::  nc_stat         !< return value of nf90 function call
797
798    LOGICAL ::  input_pids_static  = .FALSE.   !< Flag indicating whether Palm-input-data-standard file containing static information exists
799    LOGICAL ::  input_pids_dynamic = .FALSE.   !< Flag indicating whether Palm-input-data-standard file containing dynamic information exists
800    LOGICAL ::  input_pids_chem    = .FALSE.   !< Flag indicating whether Palm-input-data-standard file containing chemistry information exists
801    LOGICAL ::  input_pids_uvem    = .FALSE.   !< Flag indicating whether uv-expoure-model input file containing static information exists
802    LOGICAL ::  input_pids_vm      = .FALSE.   !< Flag indicating whether input file for virtual measurements exist
803
804    LOGICAL ::  collective_read = .FALSE.      !< Enable NetCDF collective read
805
806    TYPE(global_atts_type) ::  input_file_atts !< global attributes of input file
807
808    SAVE
809
810    PRIVATE
811
812    INTERFACE netcdf_data_input_interpolate
813       MODULE PROCEDURE netcdf_data_input_interpolate_1d
814       MODULE PROCEDURE netcdf_data_input_interpolate_1d_soil
815       MODULE PROCEDURE netcdf_data_input_interpolate_2d
816       MODULE PROCEDURE netcdf_data_input_interpolate_3d
817    END INTERFACE netcdf_data_input_interpolate
818
819    INTERFACE netcdf_data_input_check_dynamic
820       MODULE PROCEDURE netcdf_data_input_check_dynamic
821    END INTERFACE netcdf_data_input_check_dynamic
822
823    INTERFACE netcdf_data_input_check_static
824       MODULE PROCEDURE netcdf_data_input_check_static
825    END INTERFACE netcdf_data_input_check_static
826
827    INTERFACE netcdf_data_input_chemistry_data                       
828       MODULE PROCEDURE netcdf_data_input_chemistry_data
829    END INTERFACE netcdf_data_input_chemistry_data
830   
831    INTERFACE netcdf_data_input_get_dimension_length                       
832       MODULE PROCEDURE netcdf_data_input_get_dimension_length
833    END INTERFACE netcdf_data_input_get_dimension_length
834
835    INTERFACE netcdf_data_input_inquire_file
836       MODULE PROCEDURE netcdf_data_input_inquire_file
837    END INTERFACE netcdf_data_input_inquire_file
838
839    INTERFACE netcdf_data_input_init
840       MODULE PROCEDURE netcdf_data_input_init
841    END INTERFACE netcdf_data_input_init
842   
843    INTERFACE netcdf_data_input_att
844       MODULE PROCEDURE netcdf_data_input_att_int8
845       MODULE PROCEDURE netcdf_data_input_att_int32
846       MODULE PROCEDURE netcdf_data_input_att_real
847       MODULE PROCEDURE netcdf_data_input_att_string
848    END INTERFACE netcdf_data_input_att
849
850    INTERFACE netcdf_data_input_init_3d
851       MODULE PROCEDURE netcdf_data_input_init_3d
852    END INTERFACE netcdf_data_input_init_3d
853   
854    INTERFACE netcdf_data_input_init_lsm
855       MODULE PROCEDURE netcdf_data_input_init_lsm
856    END INTERFACE netcdf_data_input_init_lsm
857
858    INTERFACE netcdf_data_input_offline_nesting
859       MODULE PROCEDURE netcdf_data_input_offline_nesting
860    END INTERFACE netcdf_data_input_offline_nesting
861
862    INTERFACE netcdf_data_input_surface_data
863       MODULE PROCEDURE netcdf_data_input_surface_data
864    END INTERFACE netcdf_data_input_surface_data
865
866    INTERFACE netcdf_data_input_var
867       MODULE PROCEDURE netcdf_data_input_var_char
868       MODULE PROCEDURE netcdf_data_input_var_real_1d
869       MODULE PROCEDURE netcdf_data_input_var_real_2d
870    END INTERFACE netcdf_data_input_var
871
872    INTERFACE netcdf_data_input_uvem
873       MODULE PROCEDURE netcdf_data_input_uvem
874    END INTERFACE netcdf_data_input_uvem
875
876    INTERFACE get_variable
877       MODULE PROCEDURE get_variable_1d_char
878       MODULE PROCEDURE get_variable_1d_int
879       MODULE PROCEDURE get_variable_1d_real
880       MODULE PROCEDURE get_variable_2d_int8
881       MODULE PROCEDURE get_variable_2d_int32
882       MODULE PROCEDURE get_variable_2d_real
883       MODULE PROCEDURE get_variable_3d_int8
884       MODULE PROCEDURE get_variable_3d_real
885       MODULE PROCEDURE get_variable_3d_real_dynamic
886       MODULE PROCEDURE get_variable_4d_to_3d_real
887       MODULE PROCEDURE get_variable_4d_real
888       MODULE PROCEDURE get_variable_5d_to_4d_real
889       MODULE PROCEDURE get_variable_string       
890    END INTERFACE get_variable
891
892    INTERFACE get_variable_pr
893       MODULE PROCEDURE get_variable_pr
894    END INTERFACE get_variable_pr
895
896    INTERFACE get_attribute
897       MODULE PROCEDURE get_attribute_real
898       MODULE PROCEDURE get_attribute_int8
899       MODULE PROCEDURE get_attribute_int32
900       MODULE PROCEDURE get_attribute_string
901    END INTERFACE get_attribute
902
903!
904!-- Public variables
905    PUBLIC albedo_pars_f, albedo_type_f, basal_area_density_f, buildings_f,    &
906           building_id_f, building_pars_f, building_type_f,                    &
907           chem_emis, chem_emis_att, chem_emis_att_type, chem_emis_val_type,   &
908           coord_ref_sys,                                                      &
909           init_3d, init_model, input_file_atts, input_file_static,            &
910           input_pids_static,                                                  &
911           input_pids_dynamic, input_pids_vm, input_file_vm,                   &
912           leaf_area_density_f, nest_offl,                                     &
913           pavement_pars_f, pavement_subsurface_pars_f, pavement_type_f,       &
914           root_area_density_lad_f, root_area_density_lsm_f, soil_pars_f,      &
915           soil_type_f, street_crossing_f, street_type_f, surface_fraction_f,  &
916           terrain_height_f, vegetation_pars_f, vegetation_type_f,             &
917           water_pars_f, water_type_f
918!
919!-- Public uv exposure variables
920    PUBLIC building_obstruction_f, input_file_uvem, input_pids_uvem,           &
921           netcdf_data_input_uvem,                                             &
922           uvem_integration_f, uvem_irradiance_f,                              &
923           uvem_projarea_f, uvem_radiance_f
924
925!
926!-- Public subroutines
927    PUBLIC netcdf_data_input_check_dynamic, netcdf_data_input_check_static,    &
928           netcdf_data_input_chemistry_data,                                   &
929           netcdf_data_input_get_dimension_length,                             &
930           netcdf_data_input_inquire_file,                                     &
931           netcdf_data_input_init, netcdf_data_input_init_lsm,                 &
932           netcdf_data_input_init_3d, netcdf_data_input_att,                   &
933           netcdf_data_input_interpolate, netcdf_data_input_offline_nesting,   &
934           netcdf_data_input_surface_data, netcdf_data_input_topo,             &
935           netcdf_data_input_var, get_attribute, get_variable, open_read_file, &
936           check_existence, inquire_num_variables, inquire_variable_names
937
938
939 CONTAINS
940
941!------------------------------------------------------------------------------!
942! Description:
943! ------------
944!> Inquires whether NetCDF input files according to Palm-input-data standard
945!> exist. Moreover, basic checks are performed.
946!------------------------------------------------------------------------------!
947    SUBROUTINE netcdf_data_input_inquire_file
948
949       USE control_parameters,                                                 &
950           ONLY:  topo_no_distinct
951
952       IMPLICIT NONE
953
954#if defined ( __netcdf )
955       INQUIRE( FILE = TRIM( input_file_static )   // TRIM( coupling_char ),   &
956                EXIST = input_pids_static  )
957       INQUIRE( FILE = TRIM( input_file_dynamic ) // TRIM( coupling_char ),    &
958                EXIST = input_pids_dynamic )
959       INQUIRE( FILE = TRIM( input_file_chem )    // TRIM( coupling_char ),    &
960                EXIST = input_pids_chem )
961       INQUIRE( FILE = TRIM( input_file_uvem ) // TRIM( coupling_char ),       &
962                EXIST = input_pids_uvem  )
963       INQUIRE( FILE = TRIM( input_file_vm )      // TRIM( coupling_char ),    &
964                EXIST = input_pids_vm )
965#endif
966
967!
968!--    As long as topography can be input via ASCII format, no distinction
969!--    between building and terrain can be made. This case, classify all
970!--    surfaces as default type. Same in case land-surface and urban-surface
971!--    model are not applied.
972       IF ( .NOT. input_pids_static )  THEN
973          topo_no_distinct = .TRUE.
974       ENDIF
975
976    END SUBROUTINE netcdf_data_input_inquire_file
977
978!------------------------------------------------------------------------------!
979! Description:
980! ------------
981!> Reads global attributes and coordinate reference system required for
982!> initialization of the model.
983!------------------------------------------------------------------------------!
984    SUBROUTINE netcdf_data_input_init
985
986       IMPLICIT NONE
987
988       INTEGER(iwp) ::  id_mod     !< NetCDF id of input file
989       INTEGER(iwp) ::  var_id_crs !< NetCDF id of variable crs
990
991       IF ( .NOT. input_pids_static )  RETURN
992
993#if defined ( __netcdf )
994!
995!--    Open file in read-only mode
996       CALL open_read_file( TRIM( input_file_static ) //                       &
997                            TRIM( coupling_char ), id_mod )
998!
999!--    Read global attributes
1000       CALL get_attribute( id_mod, input_file_atts%origin_lat_char,            &
1001                           input_file_atts%origin_lat, .TRUE. )
1002
1003       CALL get_attribute( id_mod, input_file_atts%origin_lon_char,            &
1004                           input_file_atts%origin_lon, .TRUE. )
1005
1006       CALL get_attribute( id_mod, input_file_atts%origin_time_char,           &
1007                           input_file_atts%origin_time, .TRUE. )
1008
1009       CALL get_attribute( id_mod, input_file_atts%origin_x_char,              &
1010                           input_file_atts%origin_x, .TRUE. )
1011
1012       CALL get_attribute( id_mod, input_file_atts%origin_y_char,              &
1013                           input_file_atts%origin_y, .TRUE. )
1014
1015       CALL get_attribute( id_mod, input_file_atts%origin_z_char,              &
1016                           input_file_atts%origin_z, .TRUE. )
1017
1018       CALL get_attribute( id_mod, input_file_atts%rotation_angle_char,        &
1019                           input_file_atts%rotation_angle, .TRUE. )
1020
1021       CALL get_attribute( id_mod, input_file_atts%author_char,                &
1022                           input_file_atts%author, .TRUE., no_abort=.FALSE. )
1023       CALL get_attribute( id_mod, input_file_atts%contact_person_char,        &
1024                           input_file_atts%contact_person, .TRUE., no_abort=.FALSE. )
1025       CALL get_attribute( id_mod, input_file_atts%institution_char,           &
1026                           input_file_atts%institution,    .TRUE., no_abort=.FALSE. )
1027       CALL get_attribute( id_mod, input_file_atts%acronym_char,               &
1028                           input_file_atts%acronym,        .TRUE., no_abort=.FALSE. )
1029
1030       CALL get_attribute( id_mod, input_file_atts%campaign_char,              &
1031                           input_file_atts%campaign, .TRUE., no_abort=.FALSE. )
1032       CALL get_attribute( id_mod, input_file_atts%location_char,              &
1033                           input_file_atts%location, .TRUE., no_abort=.FALSE. )
1034       CALL get_attribute( id_mod, input_file_atts%site_char,                  &
1035                           input_file_atts%site,     .TRUE., no_abort=.FALSE. )
1036
1037       CALL get_attribute( id_mod, input_file_atts%source_char,                &
1038                           input_file_atts%source,     .TRUE., no_abort=.FALSE. )
1039       CALL get_attribute( id_mod, input_file_atts%references_char,            &
1040                           input_file_atts%references, .TRUE., no_abort=.FALSE. )
1041       CALL get_attribute( id_mod, input_file_atts%keywords_char,              &
1042                           input_file_atts%keywords,   .TRUE., no_abort=.FALSE. )
1043       CALL get_attribute( id_mod, input_file_atts%licence_char,               &
1044                           input_file_atts%licence,    .TRUE., no_abort=.FALSE. )
1045       CALL get_attribute( id_mod, input_file_atts%comment_char,               &
1046                           input_file_atts%comment,    .TRUE., no_abort=.FALSE. )
1047!
1048!--    Read coordinate reference system if available
1049       nc_stat = NF90_INQ_VARID( id_mod, 'crs', var_id_crs )
1050       IF ( nc_stat == NF90_NOERR )  THEN
1051          CALL get_attribute( id_mod, 'epsg_code',                             &
1052                              coord_ref_sys%epsg_code,                         &
1053                              .FALSE., 'crs' )
1054          CALL get_attribute( id_mod, 'false_easting',                         &
1055                              coord_ref_sys%false_easting,                     &
1056                              .FALSE., 'crs' )
1057          CALL get_attribute( id_mod, 'false_northing',                        &
1058                              coord_ref_sys%false_northing,                    &
1059                              .FALSE., 'crs' )
1060          CALL get_attribute( id_mod, 'grid_mapping_name',                     &
1061                              coord_ref_sys%grid_mapping_name,                 &
1062                              .FALSE., 'crs' )
1063          CALL get_attribute( id_mod, 'inverse_flattening',                    &
1064                              coord_ref_sys%inverse_flattening,                &
1065                              .FALSE., 'crs' )
1066          CALL get_attribute( id_mod, 'latitude_of_projection_origin',         &
1067                              coord_ref_sys%latitude_of_projection_origin,     &
1068                              .FALSE., 'crs' )
1069          CALL get_attribute( id_mod, 'long_name',                             &
1070                              coord_ref_sys%long_name,                         &
1071                              .FALSE., 'crs' )
1072          CALL get_attribute( id_mod, 'longitude_of_central_meridian',         &
1073                              coord_ref_sys%longitude_of_central_meridian,     &
1074                              .FALSE., 'crs' )
1075          CALL get_attribute( id_mod, 'longitude_of_prime_meridian',           &
1076                              coord_ref_sys%longitude_of_prime_meridian,       &
1077                              .FALSE., 'crs' )
1078          CALL get_attribute( id_mod, 'scale_factor_at_central_meridian',      &
1079                              coord_ref_sys%scale_factor_at_central_meridian,  &
1080                              .FALSE., 'crs' )
1081          CALL get_attribute( id_mod, 'semi_major_axis',                       &
1082                              coord_ref_sys%semi_major_axis,                   &
1083                              .FALSE., 'crs' )
1084          CALL get_attribute( id_mod, 'units',                                 &
1085                              coord_ref_sys%units,                             &
1086                              .FALSE., 'crs' )
1087       ELSE
1088!
1089!--       Calculate central meridian from origin_lon
1090          coord_ref_sys%longitude_of_central_meridian = &
1091             CEILING( input_file_atts%origin_lon / 6.0_wp ) * 6.0_wp - 3.0_wp
1092       ENDIF
1093!
1094!--    Finally, close input file
1095       CALL close_input_file( id_mod )
1096#endif
1097!
1098!--    Copy latitude, longitude, origin_z, rotation angle on init type
1099       init_model%latitude        = input_file_atts%origin_lat
1100       init_model%longitude       = input_file_atts%origin_lon
1101       init_model%origin_time     = input_file_atts%origin_time 
1102       init_model%origin_x        = input_file_atts%origin_x
1103       init_model%origin_y        = input_file_atts%origin_y
1104       init_model%origin_z        = input_file_atts%origin_z 
1105       init_model%rotation_angle  = input_file_atts%rotation_angle 
1106           
1107!
1108!--    In case of nested runs, each model domain might have different longitude
1109!--    and latitude, which would result in different Coriolis parameters and
1110!--    sun-zenith angles. To avoid this, longitude and latitude in each model
1111!--    domain will be set to the values of the root model. Please note, this
1112!--    synchronization is required already here.
1113#if defined( __parallel )
1114       CALL MPI_BCAST( init_model%latitude,  1, MPI_REAL, 0,                   &
1115                       MPI_COMM_WORLD, ierr )
1116       CALL MPI_BCAST( init_model%longitude, 1, MPI_REAL, 0,                   &
1117                       MPI_COMM_WORLD, ierr )
1118#endif
1119
1120    END SUBROUTINE netcdf_data_input_init
1121   
1122!------------------------------------------------------------------------------!
1123! Description:
1124! ------------
1125!> Read an array of characters.
1126!------------------------------------------------------------------------------!
1127    SUBROUTINE netcdf_data_input_var_char( val, search_string, id_mod )
1128
1129       IMPLICIT NONE
1130
1131       CHARACTER(LEN=*) ::  search_string     !< name of the variable
1132       CHARACTER(LEN=*), DIMENSION(:) ::  val !< variable which should be read
1133       
1134       INTEGER(iwp) ::  id_mod   !< NetCDF id of input file
1135
1136#if defined ( __netcdf )
1137!
1138!--    Read variable
1139       CALL get_variable( id_mod, search_string, val )
1140#endif           
1141
1142    END SUBROUTINE netcdf_data_input_var_char
1143   
1144!------------------------------------------------------------------------------!
1145! Description:
1146! ------------
1147!> Read an 1D array of REAL values.
1148!------------------------------------------------------------------------------!
1149    SUBROUTINE netcdf_data_input_var_real_1d( val, search_string, id_mod )
1150
1151       IMPLICIT NONE
1152
1153       CHARACTER(LEN=*) ::  search_string     !< name of the variable     
1154       
1155       INTEGER(iwp) ::  id_mod        !< NetCDF id of input file
1156       
1157       REAL(wp), DIMENSION(:) ::  val !< variable which should be read
1158
1159#if defined ( __netcdf )
1160!
1161!--    Read variable
1162       CALL get_variable( id_mod, search_string, val )
1163#endif           
1164
1165    END SUBROUTINE netcdf_data_input_var_real_1d
1166   
1167!------------------------------------------------------------------------------!
1168! Description:
1169! ------------
1170!> Read an 1D array of REAL values.
1171!------------------------------------------------------------------------------!
1172    SUBROUTINE netcdf_data_input_var_real_2d( val, search_string,              &
1173                                              id_mod, d1s, d1e, d2s, d2e )
1174
1175       IMPLICIT NONE
1176
1177       CHARACTER(LEN=*) ::  search_string     !< name of the variable     
1178       
1179       INTEGER(iwp) ::  id_mod  !< NetCDF id of input file
1180       INTEGER(iwp) ::  d1e     !< end index of first dimension to be read
1181       INTEGER(iwp) ::  d2e     !< end index of second dimension to be read
1182       INTEGER(iwp) ::  d1s     !< start index of first dimension to be read
1183       INTEGER(iwp) ::  d2s     !< start index of second dimension to be read
1184       
1185       REAL(wp), DIMENSION(:,:) ::  val !< variable which should be read
1186
1187#if defined ( __netcdf )
1188!
1189!--    Read character variable
1190       CALL get_variable( id_mod, search_string, val, d1s, d1e, d2s, d2e )
1191#endif           
1192
1193    END SUBROUTINE netcdf_data_input_var_real_2d
1194   
1195!------------------------------------------------------------------------------!
1196! Description:
1197! ------------
1198!> Read a global string attribute
1199!------------------------------------------------------------------------------!
1200    SUBROUTINE netcdf_data_input_att_string( val, search_string, id_mod,       &
1201                                             input_file, global, openclose,    &
1202                                             variable_name )
1203
1204       IMPLICIT NONE
1205
1206       CHARACTER(LEN=*) ::  search_string !< name of the attribue
1207       CHARACTER(LEN=*) ::  val           !< attribute
1208       
1209       CHARACTER(LEN=*) ::  input_file    !< name of input file
1210       CHARACTER(LEN=*) ::  openclose     !< string indicating whether NetCDF needs to be opend or closed
1211       CHARACTER(LEN=*) ::  variable_name !< string indicating whether NetCDF needs to be opend or closed 
1212       
1213       INTEGER(iwp) ::  id_mod   !< NetCDF id of input file
1214       
1215       LOGICAL ::  global                 !< flag indicating a global or a variable's attribute
1216
1217#if defined ( __netcdf )
1218!
1219!--    Open file in read-only mode if necessary
1220       IF ( openclose == 'open' )  THEN
1221          CALL open_read_file( TRIM( input_file ) // TRIM( coupling_char ), &
1222                                  id_mod )
1223       ENDIF
1224!
1225!--    Read global attribute
1226       IF ( global )  THEN
1227          CALL get_attribute( id_mod, search_string, val, global )
1228!
1229!--    Read variable attribute
1230       ELSE
1231          CALL get_attribute( id_mod, search_string, val, global, variable_name )
1232       ENDIF
1233!
1234!--    Close input file
1235       IF ( openclose == 'close' )  CALL close_input_file( id_mod )
1236#endif           
1237
1238    END SUBROUTINE netcdf_data_input_att_string
1239   
1240!------------------------------------------------------------------------------!
1241! Description:
1242! ------------
1243!> Read a global 8-bit integer attribute
1244!------------------------------------------------------------------------------!
1245    SUBROUTINE netcdf_data_input_att_int8( val, search_string, id_mod,         &
1246                                           input_file, global, openclose,      &
1247                                           variable_name )
1248
1249       IMPLICIT NONE
1250
1251       CHARACTER(LEN=*) ::  search_string !< name of the attribue
1252       
1253       CHARACTER(LEN=*) ::  input_file    !< name of input file
1254       CHARACTER(LEN=*) ::  openclose     !< string indicating whether NetCDF needs to be opend or closed
1255       CHARACTER(LEN=*) ::  variable_name !< string indicating whether NetCDF needs to be opend or closed
1256       
1257       INTEGER(iwp) ::  id_mod   !< NetCDF id of input file
1258       INTEGER(KIND=1) ::  val      !< value of the attribute
1259       
1260       LOGICAL ::  global        !< flag indicating a global or a variable's attribute
1261
1262#if defined ( __netcdf )
1263!
1264!--    Open file in read-only mode
1265       IF ( openclose == 'open' )  THEN
1266          CALL open_read_file( TRIM( input_file ) // TRIM( coupling_char ), &
1267                                  id_mod )
1268       ENDIF
1269!
1270!--    Read global attribute
1271       IF ( global )  THEN
1272          CALL get_attribute( id_mod, search_string, val, global )
1273!
1274!--    Read variable attribute
1275       ELSE
1276          CALL get_attribute( id_mod, search_string, val, global, variable_name )
1277       ENDIF
1278!
1279!--    Finally, close input file
1280       IF ( openclose == 'close' )  CALL close_input_file( id_mod )
1281#endif           
1282
1283    END SUBROUTINE netcdf_data_input_att_int8
1284   
1285!------------------------------------------------------------------------------!
1286! Description:
1287! ------------
1288!> Read a global 32-bit integer attribute
1289!------------------------------------------------------------------------------!
1290    SUBROUTINE netcdf_data_input_att_int32( val, search_string, id_mod,        &
1291                                            input_file, global, openclose,     &
1292                                            variable_name )
1293
1294       IMPLICIT NONE
1295
1296       CHARACTER(LEN=*) ::  search_string !< name of the attribue
1297       
1298       CHARACTER(LEN=*) ::  input_file    !< name of input file
1299       CHARACTER(LEN=*) ::  openclose     !< string indicating whether NetCDF needs to be opend or closed
1300       CHARACTER(LEN=*) ::  variable_name !< string indicating whether NetCDF needs to be opend or closed
1301       
1302       INTEGER(iwp) ::  id_mod   !< NetCDF id of input file
1303       INTEGER(iwp) ::  val      !< value of the attribute
1304       
1305       LOGICAL ::  global        !< flag indicating a global or a variable's attribute
1306
1307#if defined ( __netcdf )
1308!
1309!--    Open file in read-only mode
1310       IF ( openclose == 'open' )  THEN
1311          CALL open_read_file( TRIM( input_file ) // TRIM( coupling_char ), &
1312                                  id_mod )
1313       ENDIF
1314!
1315!--    Read global attribute
1316       IF ( global )  THEN
1317          CALL get_attribute( id_mod, search_string, val, global )
1318!
1319!--    Read variable attribute
1320       ELSE
1321          CALL get_attribute( id_mod, search_string, val, global, variable_name )
1322       ENDIF
1323!
1324!--    Finally, close input file
1325       IF ( openclose == 'close' )  CALL close_input_file( id_mod )
1326#endif           
1327
1328    END SUBROUTINE netcdf_data_input_att_int32
1329   
1330!------------------------------------------------------------------------------!
1331! Description:
1332! ------------
1333!> Read a global real attribute
1334!------------------------------------------------------------------------------!
1335    SUBROUTINE netcdf_data_input_att_real( val, search_string, id_mod,         &
1336                                           input_file, global, openclose,      &
1337                                           variable_name )
1338
1339       IMPLICIT NONE
1340
1341       CHARACTER(LEN=*) ::  search_string !< name of the attribue
1342       
1343       CHARACTER(LEN=*) ::  input_file    !< name of input file
1344       CHARACTER(LEN=*) ::  openclose     !< string indicating whether NetCDF needs to be opend or closed
1345       CHARACTER(LEN=*) ::  variable_name !< string indicating whether NetCDF needs to be opend or closed
1346       
1347       INTEGER(iwp) ::  id_mod            !< NetCDF id of input file
1348       
1349       LOGICAL ::  global                 !< flag indicating a global or a variable's attribute
1350       
1351       REAL(wp) ::  val                   !< value of the attribute
1352
1353#if defined ( __netcdf )
1354!
1355!--    Open file in read-only mode
1356       IF ( openclose == 'open' )  THEN
1357          CALL open_read_file( TRIM( input_file ) // TRIM( coupling_char ), &
1358                                  id_mod )
1359       ENDIF
1360!
1361!--    Read global attribute
1362       IF ( global )  THEN
1363          CALL get_attribute( id_mod, search_string, val, global )
1364!
1365!--    Read variable attribute
1366       ELSE
1367          CALL get_attribute( id_mod, search_string, val, global, variable_name )
1368       ENDIF
1369!
1370!--    Finally, close input file
1371       IF ( openclose == 'close' )  CALL close_input_file( id_mod )
1372#endif           
1373
1374    END SUBROUTINE netcdf_data_input_att_real
1375
1376!------------------------------------------------------------------------------!
1377! Description:
1378! ------------
1379!> Reads Chemistry NETCDF Input data, such as emission values, emission species, etc. .
1380!------------------------------------------------------------------------------!
1381    SUBROUTINE netcdf_data_input_chemistry_data(emt_att,emt)
1382
1383       USE chem_modules,                                       &
1384           ONLY:  mode_emis, time_fac_type, surface_csflux_name
1385
1386       USE control_parameters,                                 &
1387           ONLY:  message_string
1388
1389       USE indices,                                            &
1390           ONLY:  nx, ny, nxl, nxr, nys, nyn
1391
1392       IMPLICIT NONE
1393
1394       TYPE(chem_emis_att_type), INTENT(INOUT)                                        :: emt_att
1395       TYPE(chem_emis_val_type), ALLOCATABLE, DIMENSION(:), INTENT(INOUT)             :: emt
1396   
1397       INTEGER(iwp)                                     :: ispec                 !< index for number of emission species in input
1398
1399       INTEGER(iwp)                                     :: num_vars              !< number of variables in netcdf input file
1400       INTEGER(iwp)                                     :: len_dims              !< Length of dimension
1401
1402       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)          :: dum_var_3d            !< variable for storing temporary data of 3-dimensional
1403                                                                                 !  variables read from netcdf for chemistry emissions
1404
1405       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:)        :: dum_var_4d            !< variable for storing temporary data of 5-dimensional
1406                                                                                 !< variables read from netcdf for chemistry emissions
1407!--
1408       !> Start the processing of the data
1409
1410       !> Parameterized mode of the emissions
1411       IF (TRIM(mode_emis)=="PARAMETERIZED" .OR. TRIM(mode_emis)=="parameterized") THEN
1412
1413           ispec=1
1414           emt_att%nspec=0
1415
1416          !number of species
1417           DO  WHILE (TRIM( surface_csflux_name( ispec ) ) /= 'novalue' )
1418
1419             emt_att%nspec=emt_att%nspec+1
1420             ispec=ispec+1
1421
1422           ENDDO
1423
1424          !-- allocate emission values data type arrays
1425          ALLOCATE(emt(emt_att%nspec))
1426
1427          !-- Read EMISSION SPECIES NAMES
1428
1429          !Assign values
1430          ALLOCATE(emt_att%species_name(emt_att%nspec))
1431 
1432         DO ispec=1,emt_att%nspec
1433            emt_att%species_name(ispec) = TRIM(surface_csflux_name(ispec))
1434         ENDDO
1435
1436
1437       !> DEFAULT AND PRE-PROCESSED MODE
1438       ELSE
1439
1440#if defined ( __netcdf )       
1441          IF ( .NOT. input_pids_chem )  RETURN
1442
1443          !-- Open file in read-only mode
1444          CALL open_read_file( TRIM( input_file_chem ) //                       &
1445                               TRIM( coupling_char ), id_emis )
1446          !-- inquire number of variables
1447          CALL inquire_num_variables( id_emis, num_vars )
1448
1449          !-- Get General Dimension Lengths: only number of species and number of categories.
1450          !                                  the other dimensions depend on the mode of the emissions or on the presence of specific components
1451          !nspecies
1452          CALL netcdf_data_input_get_dimension_length( id_emis, emt_att%nspec, 'nspecies' )
1453
1454 
1455          !-- Allocate emission values data type arrays
1456          ALLOCATE(emt(1:emt_att%nspec))
1457
1458
1459          !-- Read EMISSION SPECIES NAMES
1460          !Allocate Arrays
1461          ALLOCATE(emt_att%species_name(emt_att%nspec)) 
1462
1463          !Call get Variable
1464          CALL get_variable( id_emis, 'emission_name', string_values, emt_att%nspec )
1465          emt_att%species_name=string_values
1466          ! If allocated, Deallocate var_string, an array only used for reading-in strings
1467          IF (ALLOCATED(string_values)) DEALLOCATE(string_values) 
1468
1469          !-- Read EMISSION SPECIES INDEX
1470          !Allocate Arrays
1471          ALLOCATE(emt_att%species_index(emt_att%nspec))
1472          !Call get Variable
1473          CALL get_variable( id_emis, 'emission_index', emt_att%species_index )
1474
1475
1476          !-- Now the routine has to distinguish between DEFAULT and PRE-PROCESSED chemistry emission modes
1477
1478          IF (TRIM(mode_emis)=="DEFAULT" .OR. TRIM(mode_emis)=="default") THEN
1479 
1480             !number of categories
1481             CALL netcdf_data_input_get_dimension_length( id_emis, emt_att%ncat, 'ncat' )
1482
1483             !-- Read EMISSION CATEGORIES INDEX
1484             !Allocate Arrays
1485             ALLOCATE(emt_att%cat_index(emt_att%ncat))
1486             !Call get Variable
1487             CALL get_variable( id_emis, 'emission_cat_index', emt_att%cat_index )
1488
1489 
1490             DO ispec=1,emt_att%nspec
1491                !-- EMISSION_VOC_NAME (1-DIMENSIONAL)
1492                IF (TRIM(emt_att%species_name(ispec))=="VOC" .OR. TRIM(emt_att%species_name(ispec))=="voc") THEN
1493                   !Allocate Array
1494                   CALL netcdf_data_input_get_dimension_length( id_emis, emt_att%nvoc, 'nvoc' )
1495                   ALLOCATE(emt_att%voc_name(1:emt_att%nvoc))
1496                   !Read-in Variable
1497                   CALL get_variable( id_emis,"emission_voc_name",string_values, emt_att%nvoc)
1498                   emt_att%voc_name=string_values
1499                   IF (ALLOCATED(string_values)) DEALLOCATE(string_values)
1500 
1501                !-- COMPOSITION VOC (2-DIMENSIONAL)
1502                   !Allocate Array
1503                   ALLOCATE(emt_att%voc_comp(1:emt_att%ncat,1:emt_att%nvoc))
1504                   !Read-in Variable
1505!               CALL get_variable(id_emis,"composition_voc",emt%voc_comp,1,1,emt%ncat,emt%nvoc)
1506                   CALL get_variable(id_emis,"composition_voc",emt_att%voc_comp,1,emt_att%ncat,1,emt_att%nvoc)
1507                ENDIF
1508
1509                !-- EMISSION_PM_NAME (1-DIMENSIONAL)
1510                IF (TRIM(emt_att%species_name(ispec))=="PM" .OR. TRIM(emt_att%species_name(ispec))=="pm") THEN
1511                   CALL netcdf_data_input_get_dimension_length( id_emis, emt_att%npm, 'npm' )
1512                   ALLOCATE(emt_att%pm_name(1:emt_att%npm))
1513                   !Read-in Variable
1514                   CALL get_variable( id_emis,"pm_name",string_values, emt_att%npm)
1515                   emt_att%pm_name=string_values
1516                   IF (ALLOCATED(string_values)) DEALLOCATE(string_values)     
1517
1518                !-- COMPOSITION PM (3-DIMENSIONAL)
1519                   !Allocate
1520                   len_dims=3  !> number of PMs: PM1, PM2.5 and PM10
1521                   ALLOCATE(emt_att%pm_comp(1:emt_att%ncat,1:emt_att%npm,1:len_dims))
1522                   !Read-in Variable
1523                   CALL get_variable(id_emis,"composition_pm",emt_att%pm_comp,1,emt_att%ncat,1,emt_att%npm,1,len_dims)                   
1524                ENDIF
1525
1526                !-- COMPOSITION_NOX (2-DIMENSIONAL)
1527                IF (TRIM(emt_att%species_name(ispec))=="NOx" .OR. TRIM(emt_att%species_name(ispec))=="nox") THEN
1528                   !Allocate array
1529                   ALLOCATE(emt_att%nox_comp(1:emt_att%ncat,1:emt_att%nnox))
1530                   !Read-in Variable
1531                   CALL get_variable(id_emis,"composition_nox",emt_att%nox_comp,1,emt_att%ncat,1,emt_att%nnox)
1532                ENDIF
1533
1534                !-- COMPOSITION-SOX (2-DIMENSIONAL)
1535                IF (TRIM(emt_att%species_name(ispec))=="SOx" .OR. TRIM(emt_att%species_name(ispec))=="sox") THEN
1536                   ALLOCATE(emt_att%sox_comp(1:emt_att%ncat,1:emt_att%nsox))
1537                   !Read-in Variable
1538                   CALL get_variable(id_emis,"composition_sox",emt_att%sox_comp,1,emt_att%ncat,1,emt_att%nsox)
1539                ENDIF
1540             ENDDO !>ispec
1541
1542!-- For reading the emission time factors, the distinction between HOUR and MDH data is necessary
1543     
1544             !-- EMISSION_TIME_SCALING_FACTORS
1545                !-- HOUR   
1546             IF (TRIM(time_fac_type)=="HOUR" .OR. TRIM(time_fac_type)=="hour") THEN
1547                !-- Allocate Array
1548                CALL netcdf_data_input_get_dimension_length( id_emis, emt_att%nhoursyear, 'nhoursyear' )
1549                ALLOCATE(emt_att%hourly_emis_time_factor(1:emt_att%ncat,1:emt_att%nhoursyear))
1550                !Read-in Variable
1551                CALL get_variable(id_emis,"emission_time_factors",emt_att%hourly_emis_time_factor,1,   &
1552                                  emt_att%ncat,1,emt_att%nhoursyear)
1553
1554                !-- MDH
1555             ELSE IF (TRIM(time_fac_type) == "MDH" .OR. TRIM(time_fac_type) == "mdh") THEN
1556                !-- Allocate Array
1557                CALL netcdf_data_input_get_dimension_length( id_emis, emt_att%nmonthdayhour, 'nmonthdayhour' )
1558                ALLOCATE(emt_att%mdh_emis_time_factor(1:emt_att%ncat,1:emt_att%nmonthdayhour))
1559                !-- Read-in Variable
1560                CALL get_variable(id_emis,"emission_time_factors",emt_att%mdh_emis_time_factor,1,       &
1561                                  emt_att%ncat,1,emt_att%nmonthdayhour)
1562
1563             ELSE
1564
1565             message_string = 'We are in the DEFAULT chemistry emissions mode: '            //          &
1566                              '     !no time-factor type specified!'                        //          &
1567                              'Please, specify the value of time_fac_type:'                 //          &
1568                              '         either "MDH" or "HOUR"'                 
1569             CALL message( 'netcdf_data_input_chemistry_data', 'CM0200', 2, 2, 0, 6, 0 ) 
1570 
1571
1572             ENDIF
1573
1574             !-- Finally read-in the emission values and their units (DEFAULT mode)
1575
1576             DO ispec=1,emt_att%nspec
1577
1578                IF ( .NOT. ALLOCATED( emt(ispec)%default_emission_data ) )                              &
1579                    ALLOCATE(emt(ispec)%default_emission_data(1:emt_att%ncat,1:ny+1,1:nx+1))
1580
1581                ALLOCATE(dum_var_3d(1:emt_att%ncat,nys+1:nyn+1,nxl+1:nxr+1))
1582
1583                CALL get_variable(id_emis,"emission_values",dum_var_3d,ispec,1,emt_att%ncat,nys,nyn,nxl,nxr)         
1584
1585                emt(ispec)%default_emission_data(:,nys+1:nyn+1,nxl+1:nxr+1) =                           &
1586                    dum_var_3d(1:emt_att%ncat,nys+1:nyn+1,nxl+1:nxr+1)
1587
1588                DEALLOCATE (dum_var_3d)
1589
1590             ENDDO
1591
1592             !-- UNITS
1593             CALL get_attribute(id_emis,"units",emt_att%units,.FALSE.,"emission_values")
1594
1595
1596          !-- PRE-PROCESSED MODE --
1597
1598          ELSE IF (TRIM(mode_emis)=="PRE-PROCESSED" .OR. TRIM(mode_emis)=="pre-processed") THEN
1599          !-- In the PRE-PROCESSED mode, only the VOC names, the VOC_composition, the emission values and their units remain to be read at this point
1600
1601             DO ispec=1,emt_att%nspec
1602
1603             !-- EMISSION_VOC_NAME (1-DIMENSIONAL)
1604                IF (TRIM(emt_att%species_name(ispec))=="VOC" .OR. TRIM(emt_att%species_name(ispec))=="voc") THEN
1605                   !Allocate Array
1606                   CALL netcdf_data_input_get_dimension_length( id_emis, emt_att%nvoc, 'nvoc' )
1607                   ALLOCATE(emt_att%voc_name(1:emt_att%nvoc))
1608                   !Read-in Variable
1609                   CALL get_variable( id_emis,"emission_voc_name",string_values, emt_att%nvoc)
1610                   emt_att%voc_name=string_values
1611                   IF (ALLOCATED(string_values)) DEALLOCATE(string_values)
1612 
1613             !-- COMPOSITION VOC (2-DIMENSIONAL)
1614                   !Allocate Array
1615                   ALLOCATE(emt_att%voc_comp(1:emt_att%ncat,1:emt_att%nvoc))
1616                   !Read-in Variable
1617                   CALL get_variable(id_emis,"composition_voc",emt_att%voc_comp,1,emt_att%ncat,1,emt_att%nvoc)
1618                ENDIF
1619 
1620             ENDDO !> ispec
1621
1622             !-- EMISSION_VALUES (4-DIMENSIONAL)
1623             !Calculate temporal dimension length
1624             CALL netcdf_data_input_get_dimension_length( id_emis, emt_att%dt_emission, 'time' )   
1625         
1626
1627             DO ispec=1,emt_att%nspec
1628
1629                !Allocation for the entire domain has to be done only for the first processor between all the subdomains     
1630                IF ( .NOT. ALLOCATED( emt(ispec)%preproc_emission_data ) )                              &
1631                    ALLOCATE(emt(ispec)%preproc_emission_data(emt_att%dt_emission,1,1:ny+1,1:nx+1))
1632
1633                !> allocate variable where to pass emission values read from netcdf
1634                ALLOCATE(dum_var_4d(1:emt_att%dt_emission,1,nys+1:nyn+1,nxl+1:nxr+1))
1635
1636                !Read-in Variable
1637                CALL get_variable(id_emis,"emission_values",dum_var_4d,ispec,1,emt_att%dt_emission,1,1,nys,nyn,nxl,nxr)         
1638
1639     
1640                emt(ispec)%preproc_emission_data(:,1,nys+1:nyn+1,nxl+1:nxr+1) =                         &
1641                      dum_var_4d(1:emt_att%dt_emission,1,nys+1:nyn+1,nxl+1:nxr+1)
1642
1643                DEALLOCATE ( dum_var_4d )
1644
1645             ENDDO
1646
1647             !-- UNITS
1648             CALL get_attribute(id_emis,"units",emt_att%units,.FALSE.,"emission_values")
1649       
1650          ENDIF
1651
1652       CALL close_input_file( id_emis )
1653
1654#endif
1655       ENDIF
1656
1657    END SUBROUTINE netcdf_data_input_chemistry_data
1658
1659!------------------------------------------------------------------------------!
1660! Description:
1661! ------------
1662!> Reads surface classification data, such as vegetation and soil type, etc. .
1663!------------------------------------------------------------------------------!
1664    SUBROUTINE netcdf_data_input_surface_data
1665
1666       USE control_parameters,                                                 &
1667           ONLY:  land_surface, plant_canopy, urban_surface
1668
1669       USE indices,                                                            &
1670           ONLY:  nbgp, nxl, nxr, nyn, nys
1671
1672
1673       IMPLICIT NONE
1674
1675       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names  !< variable names in static input file
1676
1677       INTEGER(iwp) ::  id_surf   !< NetCDF id of input file
1678       INTEGER(iwp) ::  k         !< running index along z-direction
1679       INTEGER(iwp) ::  k2        !< running index
1680       INTEGER(iwp) ::  num_vars  !< number of variables in input file
1681       INTEGER(iwp) ::  nz_soil   !< number of soil layers in file
1682
1683!
1684!--    If not static input file is available, skip this routine
1685       IF ( .NOT. input_pids_static )  RETURN
1686!
1687!--    Measure CPU time
1688       CALL cpu_log( log_point_s(82), 'NetCDF input', 'start' )
1689!
1690!--    Read plant canopy variables.
1691       IF ( plant_canopy )  THEN
1692#if defined ( __netcdf )
1693!
1694!--       Open file in read-only mode
1695          CALL open_read_file( TRIM( input_file_static ) //                    &
1696                               TRIM( coupling_char ) , id_surf )
1697!
1698!--       At first, inquire all variable names.
1699!--       This will be used to check whether an optional input variable
1700!--       exist or not.
1701          CALL inquire_num_variables( id_surf, num_vars )
1702
1703          ALLOCATE( var_names(1:num_vars) )
1704          CALL inquire_variable_names( id_surf, var_names )
1705
1706!
1707!--       Read leaf area density - resolved vegetation
1708          IF ( check_existence( var_names, 'lad' ) )  THEN
1709             leaf_area_density_f%from_file = .TRUE.
1710             CALL get_attribute( id_surf, char_fill,                           &
1711                                 leaf_area_density_f%fill,                     &
1712                                 .FALSE., 'lad' )
1713!
1714!--          Inquire number of vertical vegetation layer
1715             CALL netcdf_data_input_get_dimension_length( id_surf,             &
1716                                                 leaf_area_density_f%nz,       &
1717                                                 'zlad' )
1718!
1719!--          Allocate variable for leaf-area density
1720             ALLOCATE( leaf_area_density_f%var( 0:leaf_area_density_f%nz-1,    &
1721                                                nys:nyn,nxl:nxr) )
1722
1723             CALL get_variable( id_surf, 'lad', leaf_area_density_f%var,       &
1724                                nxl, nxr, nys, nyn,                            &
1725                                0, leaf_area_density_f%nz-1 )
1726
1727          ELSE
1728             leaf_area_density_f%from_file = .FALSE.
1729          ENDIF
1730
1731!
1732!--       Read basal area density - resolved vegetation
1733          IF ( check_existence( var_names, 'bad' ) )  THEN
1734             basal_area_density_f%from_file = .TRUE.
1735             CALL get_attribute( id_surf, char_fill,                           &
1736                                 basal_area_density_f%fill,                    &
1737                                 .FALSE., 'bad' )
1738!
1739!--          Inquire number of vertical vegetation layer
1740             CALL netcdf_data_input_get_dimension_length( id_surf,             &
1741                                                 basal_area_density_f%nz,      &
1742                                                 'zlad' )
1743!
1744!--          Allocate variable
1745             ALLOCATE( basal_area_density_f%var(0:basal_area_density_f%nz-1,   &
1746                                                nys:nyn,nxl:nxr) )
1747
1748             CALL get_variable( id_surf, 'bad', basal_area_density_f%var,      &
1749                                nxl, nxr, nys, nyn,                            &
1750                                0,  basal_area_density_f%nz-1 )
1751          ELSE
1752             basal_area_density_f%from_file = .FALSE.
1753          ENDIF
1754
1755!
1756!--       Read root area density - resolved vegetation
1757          IF ( check_existence( var_names, 'root_area_dens_r' ) )  THEN
1758             root_area_density_lad_f%from_file = .TRUE.
1759             CALL get_attribute( id_surf, char_fill,                           &
1760                                 root_area_density_lad_f%fill,                 &
1761                                 .FALSE., 'root_area_dens_r' )
1762!
1763!--          Inquire number of vertical soil layers
1764             CALL netcdf_data_input_get_dimension_length( id_surf,             &
1765                                                   root_area_density_lad_f%nz, &
1766                                                  'zsoil' )
1767!
1768!--          Allocate variable
1769             ALLOCATE( root_area_density_lad_f%var                             &
1770                                         (0:root_area_density_lad_f%nz-1,      &
1771                                          nys:nyn,nxl:nxr) )
1772
1773             CALL get_variable( id_surf, 'root_area_dens_r',                   &
1774                                root_area_density_lad_f%var,                   &
1775                                nxl, nxr, nys, nyn,                            &
1776                                0,  root_area_density_lad_f%nz-1 )
1777          ELSE
1778             root_area_density_lad_f%from_file = .FALSE.
1779          ENDIF
1780!
1781!--       Finally, close input file
1782          CALL close_input_file( id_surf )
1783#endif
1784       ENDIF
1785!
1786!--    Deallocate variable list. Will be re-allocated in case further
1787!--    variables are read from file.
1788       IF ( ALLOCATED( var_names ) )  DEALLOCATE( var_names )
1789!
1790!--    Skip the following if no land-surface or urban-surface module are
1791!--    applied. This case, no one of the following variables is used anyway.
1792       IF (  .NOT. land_surface  .AND.  .NOT. urban_surface )  RETURN
1793
1794#if defined ( __netcdf )
1795!
1796!--    Open file in read-only mode
1797       CALL open_read_file( TRIM( input_file_static ) //                       &
1798                            TRIM( coupling_char ) , id_surf )
1799!
1800!--    Inquire all variable names.
1801!--    This will be used to check whether an optional input variable exist
1802!--    or not.
1803       CALL inquire_num_variables( id_surf, num_vars )
1804
1805       ALLOCATE( var_names(1:num_vars) )
1806       CALL inquire_variable_names( id_surf, var_names )
1807!
1808!--    Read vegetation type and required attributes
1809       IF ( check_existence( var_names, 'vegetation_type' ) )  THEN
1810          vegetation_type_f%from_file = .TRUE.
1811          CALL get_attribute( id_surf, char_fill,                              &
1812                              vegetation_type_f%fill,                          &
1813                              .FALSE., 'vegetation_type' )
1814
1815          ALLOCATE ( vegetation_type_f%var(nys:nyn,nxl:nxr)  )
1816
1817          CALL get_variable( id_surf, 'vegetation_type',                       &
1818                             vegetation_type_f%var, nxl, nxr, nys, nyn )
1819       ELSE
1820          vegetation_type_f%from_file = .FALSE.
1821       ENDIF
1822
1823!
1824!--    Read soil type and required attributes
1825       IF ( check_existence( var_names, 'soil_type' ) )  THEN
1826             soil_type_f%from_file = .TRUE.
1827!
1828!--       Note, lod is currently not on file; skip for the moment
1829!           CALL get_attribute( id_surf, char_lod,                       &
1830!                                      soil_type_f%lod,                  &
1831!                                      .FALSE., 'soil_type' )
1832          CALL get_attribute( id_surf, char_fill,                              &
1833                              soil_type_f%fill,                                &
1834                              .FALSE., 'soil_type' )
1835
1836          IF ( soil_type_f%lod == 1 )  THEN
1837
1838             ALLOCATE ( soil_type_f%var_2d(nys:nyn,nxl:nxr)  )
1839
1840             CALL get_variable( id_surf, 'soil_type', soil_type_f%var_2d,      &
1841                                nxl, nxr, nys, nyn )
1842
1843          ELSEIF ( soil_type_f%lod == 2 )  THEN
1844!
1845!--          Obtain number of soil layers from file.
1846             CALL netcdf_data_input_get_dimension_length( id_surf, nz_soil,    &
1847                                                          'zsoil' )
1848
1849             ALLOCATE ( soil_type_f%var_3d(0:nz_soil,nys:nyn,nxl:nxr) )
1850
1851             CALL get_variable( id_surf, 'soil_type', soil_type_f%var_3d,      &
1852                                nxl, nxr, nys, nyn, 0, nz_soil )
1853 
1854          ENDIF
1855       ELSE
1856          soil_type_f%from_file = .FALSE.
1857       ENDIF
1858
1859!
1860!--    Read pavement type and required attributes
1861       IF ( check_existence( var_names, 'pavement_type' ) )  THEN
1862          pavement_type_f%from_file = .TRUE.
1863          CALL get_attribute( id_surf, char_fill,                              &
1864                              pavement_type_f%fill, .FALSE.,                   &
1865                              'pavement_type' )
1866
1867          ALLOCATE ( pavement_type_f%var(nys:nyn,nxl:nxr)  )
1868
1869          CALL get_variable( id_surf, 'pavement_type', pavement_type_f%var,    &
1870                             nxl, nxr, nys, nyn )
1871       ELSE
1872          pavement_type_f%from_file = .FALSE.
1873       ENDIF
1874
1875!
1876!--    Read water type and required attributes
1877       IF ( check_existence( var_names, 'water_type' ) )  THEN
1878          water_type_f%from_file = .TRUE.
1879          CALL get_attribute( id_surf, char_fill, water_type_f%fill,           &
1880                              .FALSE., 'water_type' )
1881
1882          ALLOCATE ( water_type_f%var(nys:nyn,nxl:nxr)  )
1883
1884          CALL get_variable( id_surf, 'water_type', water_type_f%var,          &
1885                             nxl, nxr, nys, nyn )
1886
1887       ELSE
1888          water_type_f%from_file = .FALSE.
1889       ENDIF
1890!
1891!--    Read relative surface fractions of vegetation, pavement and water.
1892       IF ( check_existence( var_names, 'surface_fraction' ) )  THEN
1893          surface_fraction_f%from_file = .TRUE.
1894          CALL get_attribute( id_surf, char_fill,                              &
1895                              surface_fraction_f%fill,                         &
1896                              .FALSE., 'surface_fraction' )
1897!
1898!--       Inquire number of surface fractions
1899          CALL netcdf_data_input_get_dimension_length( id_surf,                &
1900                                                       surface_fraction_f%nf,  &
1901                                                       'nsurface_fraction' )
1902!
1903!--       Allocate dimension array and input array for surface fractions
1904          ALLOCATE( surface_fraction_f%nfracs(0:surface_fraction_f%nf-1) )
1905          ALLOCATE( surface_fraction_f%frac(0:surface_fraction_f%nf-1,         &
1906                                            nys:nyn,nxl:nxr) )
1907!
1908!--       Get dimension of surface fractions
1909          CALL get_variable( id_surf, 'nsurface_fraction',                     &
1910                             surface_fraction_f%nfracs )
1911!
1912!--       Read surface fractions
1913          CALL get_variable( id_surf, 'surface_fraction',                      &
1914                             surface_fraction_f%frac, nxl, nxr, nys, nyn,      &
1915                             0, surface_fraction_f%nf-1 )
1916       ELSE
1917          surface_fraction_f%from_file = .FALSE.
1918       ENDIF
1919!
1920!--    Read building parameters and related information
1921       IF ( check_existence( var_names, 'building_pars' ) )  THEN
1922          building_pars_f%from_file = .TRUE.
1923          CALL get_attribute( id_surf, char_fill,                              &
1924                              building_pars_f%fill,                            &
1925                              .FALSE., 'building_pars' )
1926!
1927!--       Inquire number of building parameters
1928          CALL netcdf_data_input_get_dimension_length( id_surf,                &
1929                                                       building_pars_f%np,     &
1930                                                       'nbuilding_pars' )
1931!
1932!--       Allocate dimension array and input array for building parameters
1933          ALLOCATE( building_pars_f%pars(0:building_pars_f%np-1) )
1934          ALLOCATE( building_pars_f%pars_xy(0:building_pars_f%np-1,            &
1935                                            nys:nyn,nxl:nxr) )
1936!
1937!--       Get dimension of building parameters
1938          CALL get_variable( id_surf, 'nbuilding_pars',                        &
1939                             building_pars_f%pars )
1940!
1941!--       Read building_pars
1942          CALL get_variable( id_surf, 'building_pars',                         &
1943                             building_pars_f%pars_xy, nxl, nxr, nys, nyn,      &
1944                             0, building_pars_f%np-1 )
1945       ELSE
1946          building_pars_f%from_file = .FALSE.
1947       ENDIF
1948
1949!
1950!--    Read albedo type and required attributes
1951       IF ( check_existence( var_names, 'albedo_type' ) )  THEN
1952          albedo_type_f%from_file = .TRUE.
1953          CALL get_attribute( id_surf, char_fill, albedo_type_f%fill,          &
1954                              .FALSE.,  'albedo_type' )
1955
1956          ALLOCATE ( albedo_type_f%var(nys:nyn,nxl:nxr)  )
1957         
1958          CALL get_variable( id_surf, 'albedo_type', albedo_type_f%var,        &
1959                             nxl, nxr, nys, nyn )
1960       ELSE
1961          albedo_type_f%from_file = .FALSE.
1962       ENDIF
1963!
1964!--    Read albedo parameters and related information
1965       IF ( check_existence( var_names, 'albedo_pars' ) )  THEN
1966          albedo_pars_f%from_file = .TRUE.
1967          CALL get_attribute( id_surf, char_fill, albedo_pars_f%fill,          &
1968                              .FALSE., 'albedo_pars' )
1969!
1970!--       Inquire number of albedo parameters
1971          CALL netcdf_data_input_get_dimension_length( id_surf,                &
1972                                                       albedo_pars_f%np,       &
1973                                                       'nalbedo_pars' )
1974!
1975!--       Allocate dimension array and input array for albedo parameters
1976          ALLOCATE( albedo_pars_f%pars(0:albedo_pars_f%np-1) )
1977          ALLOCATE( albedo_pars_f%pars_xy(0:albedo_pars_f%np-1,                &
1978                                          nys:nyn,nxl:nxr) )
1979!
1980!--       Get dimension of albedo parameters
1981          CALL get_variable( id_surf, 'nalbedo_pars', albedo_pars_f%pars )
1982
1983          CALL get_variable( id_surf, 'albedo_pars', albedo_pars_f%pars_xy,    &
1984                             nxl, nxr, nys, nyn,                               &
1985                             0, albedo_pars_f%np-1 )
1986       ELSE
1987          albedo_pars_f%from_file = .FALSE.
1988       ENDIF
1989
1990!
1991!--    Read pavement parameters and related information
1992       IF ( check_existence( var_names, 'pavement_pars' ) )  THEN
1993          pavement_pars_f%from_file = .TRUE.
1994          CALL get_attribute( id_surf, char_fill,                              &
1995                              pavement_pars_f%fill,                            &
1996                              .FALSE., 'pavement_pars' )
1997!
1998!--       Inquire number of pavement parameters
1999          CALL netcdf_data_input_get_dimension_length( id_surf,                &
2000                                                       pavement_pars_f%np,     &
2001                                                       'npavement_pars' )
2002!
2003!--       Allocate dimension array and input array for pavement parameters
2004          ALLOCATE( pavement_pars_f%pars(0:pavement_pars_f%np-1) )
2005          ALLOCATE( pavement_pars_f%pars_xy(0:pavement_pars_f%np-1,            &
2006                                            nys:nyn,nxl:nxr) )
2007!
2008!--       Get dimension of pavement parameters
2009          CALL get_variable( id_surf, 'npavement_pars', pavement_pars_f%pars )
2010
2011          CALL get_variable( id_surf, 'pavement_pars', pavement_pars_f%pars_xy,&
2012                             nxl, nxr, nys, nyn,                               &
2013                             0, pavement_pars_f%np-1 )
2014       ELSE
2015          pavement_pars_f%from_file = .FALSE.
2016       ENDIF
2017
2018!
2019!--    Read pavement subsurface parameters and related information
2020       IF ( check_existence( var_names, 'pavement_subsurface_pars' ) )         &
2021       THEN
2022          pavement_subsurface_pars_f%from_file = .TRUE.
2023          CALL get_attribute( id_surf, char_fill,                              &
2024                              pavement_subsurface_pars_f%fill,                 &
2025                              .FALSE., 'pavement_subsurface_pars' )
2026!
2027!--       Inquire number of parameters
2028          CALL netcdf_data_input_get_dimension_length( id_surf,                &
2029                                                pavement_subsurface_pars_f%np, &
2030                                               'npavement_subsurface_pars' )
2031!
2032!--       Inquire number of soil layers
2033          CALL netcdf_data_input_get_dimension_length( id_surf,                &
2034                                                pavement_subsurface_pars_f%nz, &
2035                                                'zsoil' )
2036!
2037!--       Allocate dimension array and input array for pavement parameters
2038          ALLOCATE( pavement_subsurface_pars_f%pars                            &
2039                            (0:pavement_subsurface_pars_f%np-1) )
2040          ALLOCATE( pavement_subsurface_pars_f%pars_xyz                        &
2041                            (0:pavement_subsurface_pars_f%np-1,                &
2042                             0:pavement_subsurface_pars_f%nz-1,                &
2043                             nys:nyn,nxl:nxr) )
2044!
2045!--       Get dimension of pavement parameters
2046          CALL get_variable( id_surf, 'npavement_subsurface_pars',             &
2047                             pavement_subsurface_pars_f%pars )
2048
2049          CALL get_variable( id_surf, 'pavement_subsurface_pars',              &
2050                             pavement_subsurface_pars_f%pars_xyz,              &
2051                             nxl, nxr, nys, nyn,                               &
2052                             0, pavement_subsurface_pars_f%nz-1,               &
2053                             0, pavement_subsurface_pars_f%np-1 )
2054       ELSE
2055          pavement_subsurface_pars_f%from_file = .FALSE.
2056       ENDIF
2057
2058
2059!
2060!--    Read vegetation parameters and related information
2061       IF ( check_existence( var_names, 'vegetation_pars' ) )  THEN
2062          vegetation_pars_f%from_file = .TRUE.
2063          CALL get_attribute( id_surf, char_fill,                              &
2064                              vegetation_pars_f%fill,                          &
2065                              .FALSE.,  'vegetation_pars' )
2066!
2067!--       Inquire number of vegetation parameters
2068          CALL netcdf_data_input_get_dimension_length( id_surf,                &
2069                                                       vegetation_pars_f%np,   &
2070                                                       'nvegetation_pars' )
2071!
2072!--       Allocate dimension array and input array for surface fractions
2073          ALLOCATE( vegetation_pars_f%pars(0:vegetation_pars_f%np-1) )
2074          ALLOCATE( vegetation_pars_f%pars_xy(0:vegetation_pars_f%np-1,        &
2075                                              nys:nyn,nxl:nxr) )
2076!
2077!--       Get dimension of the parameters
2078          CALL get_variable( id_surf, 'nvegetation_pars',                      &
2079                             vegetation_pars_f%pars )
2080
2081          CALL get_variable( id_surf, 'vegetation_pars',                       &
2082                             vegetation_pars_f%pars_xy, nxl, nxr, nys, nyn,    &
2083                             0, vegetation_pars_f%np-1 )
2084       ELSE
2085          vegetation_pars_f%from_file = .FALSE.
2086       ENDIF
2087
2088!
2089!--    Read root parameters/distribution and related information
2090       IF ( check_existence( var_names, 'soil_pars' ) )  THEN
2091          soil_pars_f%from_file = .TRUE.
2092          CALL get_attribute( id_surf, char_fill,                              &
2093                              soil_pars_f%fill,                                &
2094                              .FALSE., 'soil_pars' )
2095
2096          CALL get_attribute( id_surf, char_lod,                               &
2097                              soil_pars_f%lod,                                 &
2098                              .FALSE., 'soil_pars' )
2099
2100!
2101!--       Inquire number of soil parameters
2102          CALL netcdf_data_input_get_dimension_length( id_surf,                &
2103                                                       soil_pars_f%np,         &
2104                                                       'nsoil_pars' )
2105!
2106!--       Read parameters array
2107          ALLOCATE( soil_pars_f%pars(0:soil_pars_f%np-1) )
2108          CALL get_variable( id_surf, 'nsoil_pars', soil_pars_f%pars )
2109
2110!
2111!--       In case of level of detail 2, also inquire number of vertical
2112!--       soil layers, allocate memory and read the respective dimension
2113          IF ( soil_pars_f%lod == 2 )  THEN
2114             CALL netcdf_data_input_get_dimension_length( id_surf,             &
2115                                                          soil_pars_f%nz,      &
2116                                                          'zsoil' )
2117
2118             ALLOCATE( soil_pars_f%layers(0:soil_pars_f%nz-1) )
2119             CALL get_variable( id_surf, 'zsoil', soil_pars_f%layers )
2120
2121          ENDIF
2122
2123!
2124!--       Read soil parameters, depending on level of detail
2125          IF ( soil_pars_f%lod == 1 )  THEN
2126             ALLOCATE( soil_pars_f%pars_xy(0:soil_pars_f%np-1,                 &
2127                                           nys:nyn,nxl:nxr) )
2128                 
2129             CALL get_variable( id_surf, 'soil_pars', soil_pars_f%pars_xy,     &
2130                                nxl, nxr, nys, nyn, 0, soil_pars_f%np-1 )
2131
2132          ELSEIF ( soil_pars_f%lod == 2 )  THEN
2133             ALLOCATE( soil_pars_f%pars_xyz(0:soil_pars_f%np-1,                &
2134                                            0:soil_pars_f%nz-1,                &
2135                                            nys:nyn,nxl:nxr) )
2136             CALL get_variable( id_surf, 'soil_pars',                          &
2137                                soil_pars_f%pars_xyz,                          &
2138                                nxl, nxr, nys, nyn, 0, soil_pars_f%nz-1,       &
2139                                0, soil_pars_f%np-1 )
2140
2141          ENDIF
2142       ELSE
2143          soil_pars_f%from_file = .FALSE.
2144       ENDIF
2145
2146!
2147!--    Read water parameters and related information
2148       IF ( check_existence( var_names, 'water_pars' ) )  THEN
2149          water_pars_f%from_file = .TRUE.
2150          CALL get_attribute( id_surf, char_fill,                              &
2151                              water_pars_f%fill,                               &
2152                              .FALSE., 'water_pars' )
2153!
2154!--       Inquire number of water parameters
2155          CALL netcdf_data_input_get_dimension_length( id_surf,                &
2156                                                       water_pars_f%np,        &
2157                                                       'nwater_pars' )
2158!
2159!--       Allocate dimension array and input array for water parameters
2160          ALLOCATE( water_pars_f%pars(0:water_pars_f%np-1) )
2161          ALLOCATE( water_pars_f%pars_xy(0:water_pars_f%np-1,                  &
2162                                         nys:nyn,nxl:nxr) )
2163!
2164!--       Get dimension of water parameters
2165          CALL get_variable( id_surf, 'nwater_pars', water_pars_f%pars )
2166
2167          CALL get_variable( id_surf, 'water_pars', water_pars_f%pars_xy,      &
2168                             nxl, nxr, nys, nyn, 0, water_pars_f%np-1 )
2169       ELSE
2170          water_pars_f%from_file = .FALSE.
2171       ENDIF
2172!
2173!--    Read root area density - parametrized vegetation
2174       IF ( check_existence( var_names, 'root_area_dens_s' ) )  THEN
2175          root_area_density_lsm_f%from_file = .TRUE.
2176          CALL get_attribute( id_surf, char_fill,                              &
2177                              root_area_density_lsm_f%fill,                    &
2178                              .FALSE., 'root_area_dens_s' )
2179!
2180!--       Obtain number of soil layers from file and allocate variable
2181          CALL netcdf_data_input_get_dimension_length( id_surf,                &
2182                                                   root_area_density_lsm_f%nz, &
2183                                                   'zsoil' )
2184          ALLOCATE( root_area_density_lsm_f%var                                &
2185                                        (0:root_area_density_lsm_f%nz-1,       &
2186                                         nys:nyn,nxl:nxr) )
2187
2188!
2189!--       Read root-area density
2190          CALL get_variable( id_surf, 'root_area_dens_s',                      &
2191                             root_area_density_lsm_f%var,                      &
2192                             nxl, nxr, nys, nyn,                               &
2193                             0, root_area_density_lsm_f%nz-1 )
2194
2195       ELSE
2196          root_area_density_lsm_f%from_file = .FALSE.
2197       ENDIF
2198!
2199!--    Read street type and street crossing
2200       IF ( check_existence( var_names, 'street_type' ) )  THEN
2201          street_type_f%from_file = .TRUE.
2202          CALL get_attribute( id_surf, char_fill,                              &
2203                              street_type_f%fill, .FALSE.,                     &
2204                              'street_type' )
2205
2206          ALLOCATE ( street_type_f%var(nys:nyn,nxl:nxr)  )
2207         
2208          CALL get_variable( id_surf, 'street_type', street_type_f%var,        &
2209                             nxl, nxr, nys, nyn )
2210       ELSE
2211          street_type_f%from_file = .FALSE.
2212       ENDIF
2213
2214       IF ( check_existence( var_names, 'street_crossing' ) )  THEN
2215          street_crossing_f%from_file = .TRUE.
2216          CALL get_attribute( id_surf, char_fill,                              &
2217                              street_crossing_f%fill, .FALSE.,                 &
2218                              'street_crossing' )
2219
2220          ALLOCATE ( street_crossing_f%var(nys:nyn,nxl:nxr)  )
2221
2222          CALL get_variable( id_surf, 'street_crossing',                       &
2223                             street_crossing_f%var, nxl, nxr, nys, nyn )
2224
2225       ELSE
2226          street_crossing_f%from_file = .FALSE.
2227       ENDIF
2228!
2229!--    Still missing: root_resolved and building_surface_pars.
2230!--    Will be implemented as soon as they are available.
2231
2232!
2233!--    Finally, close input file
2234       CALL close_input_file( id_surf )
2235#endif
2236!
2237!--    End of CPU measurement
2238       CALL cpu_log( log_point_s(82), 'NetCDF input', 'stop' )
2239!
2240!--    Exchange ghost points for surface variables. Therefore, resize
2241!--    variables.
2242       IF ( albedo_type_f%from_file )  THEN
2243          CALL resize_array_2d_int8( albedo_type_f%var, nys, nyn, nxl, nxr )
2244          CALL exchange_horiz_2d_byte( albedo_type_f%var, nys, nyn, nxl, nxr,  &
2245                                       nbgp )
2246       ENDIF
2247       IF ( pavement_type_f%from_file )  THEN
2248          CALL resize_array_2d_int8( pavement_type_f%var, nys, nyn, nxl, nxr )
2249          CALL exchange_horiz_2d_byte( pavement_type_f%var, nys, nyn, nxl, nxr,&
2250                                       nbgp )
2251       ENDIF
2252       IF ( soil_type_f%from_file  .AND.  ALLOCATED( soil_type_f%var_2d ) )  THEN
2253          CALL resize_array_2d_int8( soil_type_f%var_2d, nys, nyn, nxl, nxr )
2254          CALL exchange_horiz_2d_byte( soil_type_f%var_2d, nys, nyn, nxl, nxr, &
2255                                       nbgp )
2256       ENDIF
2257       IF ( vegetation_type_f%from_file )  THEN
2258          CALL resize_array_2d_int8( vegetation_type_f%var, nys, nyn, nxl, nxr )
2259          CALL exchange_horiz_2d_byte( vegetation_type_f%var, nys, nyn, nxl,   &
2260                                       nxr, nbgp )
2261       ENDIF
2262       IF ( water_type_f%from_file )  THEN
2263          CALL resize_array_2d_int8( water_type_f%var, nys, nyn, nxl, nxr )
2264          CALL exchange_horiz_2d_byte( water_type_f%var, nys, nyn, nxl, nxr,   &
2265                                       nbgp )
2266       ENDIF
2267!
2268!--    Exchange ghost points for 3/4-D variables. For the sake of simplicity,
2269!--    loop further dimensions to use 2D exchange routines. Unfortunately this
2270!--    is necessary, else new MPI-data types need to be introduced just for
2271!--    2 variables.
2272       IF ( soil_type_f%from_file  .AND.  ALLOCATED( soil_type_f%var_3d ) )    &
2273       THEN
2274          CALL resize_array_3d_int8( soil_type_f%var_3d, 0, nz_soil,           &
2275                                     nys, nyn, nxl, nxr )
2276          DO  k = 0, nz_soil
2277             CALL exchange_horiz_2d_int(                                       & 
2278                        soil_type_f%var_3d(k,:,:), nys, nyn, nxl, nxr, nbgp )
2279          ENDDO
2280       ENDIF
2281
2282       IF ( surface_fraction_f%from_file )  THEN
2283          CALL resize_array_3d_real( surface_fraction_f%frac,                  &
2284                                     0, surface_fraction_f%nf-1,               &
2285                                     nys, nyn, nxl, nxr )
2286          DO  k = 0, surface_fraction_f%nf-1
2287             CALL exchange_horiz_2d( surface_fraction_f%frac(k,:,:), nbgp )
2288          ENDDO
2289       ENDIF
2290
2291       IF ( building_pars_f%from_file )  THEN         
2292          CALL resize_array_3d_real( building_pars_f%pars_xy,                  &
2293                                     0, building_pars_f%np-1,                  &
2294                                     nys, nyn, nxl, nxr )
2295          DO  k = 0, building_pars_f%np-1
2296             CALL exchange_horiz_2d( building_pars_f%pars_xy(k,:,:), nbgp )
2297          ENDDO
2298       ENDIF
2299
2300       IF ( albedo_pars_f%from_file )  THEN         
2301          CALL resize_array_3d_real( albedo_pars_f%pars_xy,                    &
2302                                     0, albedo_pars_f%np-1,                    &
2303                                     nys, nyn, nxl, nxr )
2304          DO  k = 0, albedo_pars_f%np-1
2305             CALL exchange_horiz_2d( albedo_pars_f%pars_xy(k,:,:), nbgp )
2306          ENDDO
2307       ENDIF
2308
2309       IF ( pavement_pars_f%from_file )  THEN         
2310          CALL resize_array_3d_real( pavement_pars_f%pars_xy,                  &
2311                                     0, pavement_pars_f%np-1,                  &
2312                                     nys, nyn, nxl, nxr )
2313          DO  k = 0, pavement_pars_f%np-1
2314             CALL exchange_horiz_2d( pavement_pars_f%pars_xy(k,:,:), nbgp )
2315          ENDDO
2316       ENDIF
2317
2318       IF ( vegetation_pars_f%from_file )  THEN
2319          CALL resize_array_3d_real( vegetation_pars_f%pars_xy,                &
2320                                     0, vegetation_pars_f%np-1,                &
2321                                     nys, nyn, nxl, nxr )
2322          DO  k = 0, vegetation_pars_f%np-1
2323             CALL exchange_horiz_2d( vegetation_pars_f%pars_xy(k,:,:), nbgp )
2324          ENDDO
2325       ENDIF
2326
2327       IF ( water_pars_f%from_file )  THEN
2328          CALL resize_array_3d_real( water_pars_f%pars_xy,                     &
2329                                     0, water_pars_f%np-1,                     &
2330                                     nys, nyn, nxl, nxr )
2331          DO  k = 0, water_pars_f%np-1
2332             CALL exchange_horiz_2d( water_pars_f%pars_xy(k,:,:), nbgp )
2333          ENDDO
2334       ENDIF
2335
2336       IF ( root_area_density_lsm_f%from_file )  THEN
2337          CALL resize_array_3d_real( root_area_density_lsm_f%var,              &
2338                                     0, root_area_density_lsm_f%nz-1,          &
2339                                     nys, nyn, nxl, nxr )
2340          DO  k = 0, root_area_density_lsm_f%nz-1
2341             CALL exchange_horiz_2d( root_area_density_lsm_f%var(k,:,:), nbgp )
2342          ENDDO
2343       ENDIF
2344
2345       IF ( soil_pars_f%from_file )  THEN
2346          IF ( soil_pars_f%lod == 1 )  THEN
2347         
2348             CALL resize_array_3d_real( soil_pars_f%pars_xy,                   &
2349                                        0, soil_pars_f%np-1,                   &
2350                                        nys, nyn, nxl, nxr )
2351             DO  k = 0, soil_pars_f%np-1
2352                CALL exchange_horiz_2d( soil_pars_f%pars_xy(k,:,:), nbgp )
2353             ENDDO
2354             
2355          ELSEIF ( soil_pars_f%lod == 2 )  THEN
2356             CALL resize_array_4d_real( soil_pars_f%pars_xyz,                  &
2357                                        0, soil_pars_f%np-1,                   &
2358                                        0, soil_pars_f%nz-1,                   &
2359                                        nys, nyn, nxl, nxr )
2360
2361             DO  k2 = 0, soil_pars_f%nz-1
2362                DO  k = 0, soil_pars_f%np-1
2363                   CALL exchange_horiz_2d( soil_pars_f%pars_xyz(k,k2,:,:),     &
2364                                           nbgp )
2365                ENDDO
2366             ENDDO
2367          ENDIF
2368       ENDIF
2369
2370       IF ( pavement_subsurface_pars_f%from_file )  THEN         
2371          CALL resize_array_4d_real( pavement_subsurface_pars_f%pars_xyz,      &
2372                                     0, pavement_subsurface_pars_f%np-1,       &
2373                                     0, pavement_subsurface_pars_f%nz-1,       &
2374                                     nys, nyn, nxl, nxr )
2375
2376          DO  k2 = 0, pavement_subsurface_pars_f%nz-1
2377             DO  k = 0, pavement_subsurface_pars_f%np-1
2378                CALL exchange_horiz_2d(                                        &
2379                           pavement_subsurface_pars_f%pars_xyz(k,k2,:,:), nbgp )
2380             ENDDO
2381          ENDDO
2382       ENDIF
2383
2384    END SUBROUTINE netcdf_data_input_surface_data
2385
2386!------------------------------------------------------------------------------!
2387! Description:
2388! ------------
2389!> Reads uvem lookup table information.
2390!------------------------------------------------------------------------------!
2391    SUBROUTINE netcdf_data_input_uvem
2392       
2393       USE indices,                                                            &
2394           ONLY:  nxl, nxr, nyn, nys
2395
2396       IMPLICIT NONE
2397
2398       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names  !< variable names in static input file
2399
2400
2401       INTEGER(iwp) ::  id_uvem       !< NetCDF id of uvem lookup table input file
2402       INTEGER(iwp) ::  nli = 35      !< dimension length of lookup table in x
2403       INTEGER(iwp) ::  nlj =  9      !< dimension length of lookup table in y
2404       INTEGER(iwp) ::  nlk = 90      !< dimension length of lookup table in z
2405       INTEGER(iwp) ::  num_vars      !< number of variables in netcdf input file
2406!
2407!--    Input via uv exposure model lookup table input
2408       IF ( input_pids_uvem )  THEN
2409
2410#if defined ( __netcdf )
2411!
2412!--       Open file in read-only mode
2413          CALL open_read_file( TRIM( input_file_uvem ) //                    &
2414                               TRIM( coupling_char ), id_uvem )
2415!
2416!--       At first, inquire all variable names.
2417!--       This will be used to check whether an input variable exist or not.
2418          CALL inquire_num_variables( id_uvem, num_vars )
2419!
2420!--       Allocate memory to store variable names and inquire them.
2421          ALLOCATE( var_names(1:num_vars) )
2422          CALL inquire_variable_names( id_uvem, var_names )
2423!
2424!--       uvem integration
2425          IF ( check_existence( var_names, 'int_factors' ) )  THEN
2426             uvem_integration_f%from_file = .TRUE.
2427!
2428!--          Input 2D uvem integration.
2429             ALLOCATE ( uvem_integration_f%var(0:nlj,0:nli)  )
2430             
2431             CALL get_variable( id_uvem, 'int_factors', uvem_integration_f%var, 0, nli, 0, nlj )
2432          ELSE
2433             uvem_integration_f%from_file = .FALSE.
2434          ENDIF
2435!
2436!--       uvem irradiance
2437          IF ( check_existence( var_names, 'irradiance' ) )  THEN
2438             uvem_irradiance_f%from_file = .TRUE.
2439!
2440!--          Input 2D uvem irradiance.
2441             ALLOCATE ( uvem_irradiance_f%var(0:nlk, 0:2)  )
2442             
2443             CALL get_variable( id_uvem, 'irradiance', uvem_irradiance_f%var, 0, 2, 0, nlk )
2444          ELSE
2445             uvem_irradiance_f%from_file = .FALSE.
2446          ENDIF
2447!
2448!--       uvem porjection areas
2449          IF ( check_existence( var_names, 'projarea' ) )  THEN
2450             uvem_projarea_f%from_file = .TRUE.
2451!
2452!--          Input 3D uvem projection area (human geometgry)
2453             ALLOCATE ( uvem_projarea_f%var(0:2,0:nlj,0:nli)  )
2454           
2455             CALL get_variable( id_uvem, 'projarea', uvem_projarea_f%var, 0, nli, 0, nlj, 0, 2 )
2456          ELSE
2457             uvem_projarea_f%from_file = .FALSE.
2458          ENDIF
2459!
2460!--       uvem radiance
2461          IF ( check_existence( var_names, 'radiance' ) )  THEN
2462             uvem_radiance_f%from_file = .TRUE.
2463!
2464!--          Input 3D uvem radiance
2465             ALLOCATE ( uvem_radiance_f%var(0:nlk,0:nlj,0:nli)  )
2466             
2467             CALL get_variable( id_uvem, 'radiance', uvem_radiance_f%var, 0, nli, 0, nlj, 0, nlk )
2468          ELSE
2469             uvem_radiance_f%from_file = .FALSE.
2470          ENDIF
2471!
2472!--       Read building obstruction
2473          IF ( check_existence( var_names, 'obstruction' ) )  THEN
2474             building_obstruction_full%from_file = .TRUE.
2475!--          Input 3D uvem building obstruction
2476              ALLOCATE ( building_obstruction_full%var_3d(0:44,0:2,0:2) )
2477              CALL get_variable( id_uvem, 'obstruction', building_obstruction_full%var_3d,0, 2, 0, 2, 0, 44 )       
2478          ELSE
2479             building_obstruction_full%from_file = .FALSE.
2480          ENDIF
2481!
2482          IF ( check_existence( var_names, 'obstruction' ) )  THEN
2483             building_obstruction_f%from_file = .TRUE.
2484!
2485!--          Input 3D uvem building obstruction
2486             ALLOCATE ( building_obstruction_f%var_3d(0:44,nys:nyn,nxl:nxr) )
2487!
2488             CALL get_variable( id_uvem, 'obstruction', building_obstruction_f%var_3d,      &
2489                                nxl, nxr, nys, nyn, 0, 44 )       
2490          ELSE
2491             building_obstruction_f%from_file = .FALSE.
2492          ENDIF
2493!
2494!--       Close uvem lookup table input file
2495          CALL close_input_file( id_uvem )
2496#else
2497          CONTINUE
2498#endif
2499       ENDIF
2500    END SUBROUTINE netcdf_data_input_uvem
2501
2502!------------------------------------------------------------------------------!
2503! Description:
2504! ------------
2505!> Reads orography and building information.
2506!------------------------------------------------------------------------------!
2507    SUBROUTINE netcdf_data_input_topo
2508
2509       USE control_parameters,                                                 &
2510           ONLY:  message_string, topography
2511
2512       USE grid_variables,                                                     &
2513           ONLY:  dx, dy   
2514           
2515       USE indices,                                                            &
2516           ONLY:  nbgp, nx, nxl, nxr, ny, nyn, nys, nzb
2517
2518
2519       IMPLICIT NONE
2520
2521       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names  !< variable names in static input file
2522
2523
2524       INTEGER(iwp) ::  i             !< running index along x-direction
2525       INTEGER(iwp) ::  ii            !< running index for IO blocks
2526       INTEGER(iwp) ::  id_topo       !< NetCDF id of topograhy input file
2527       INTEGER(iwp) ::  j             !< running index along y-direction
2528       INTEGER(iwp) ::  num_vars      !< number of variables in netcdf input file
2529       INTEGER(iwp) ::  skip_n_rows   !< counting variable to skip rows while reading topography file
2530
2531       REAL(wp) ::  dum           !< dummy variable to skip columns while reading topography file
2532!
2533!--    CPU measurement
2534       CALL cpu_log( log_point_s(83), 'NetCDF/ASCII input topo', 'start' )
2535
2536!
2537!--    Input via palm-input data standard
2538       IF ( input_pids_static )  THEN
2539#if defined ( __netcdf )
2540!
2541!--       Open file in read-only mode
2542          CALL open_read_file( TRIM( input_file_static ) //                    &
2543                               TRIM( coupling_char ), id_topo )
2544!
2545!--       At first, inquire all variable names.
2546!--       This will be used to check whether an  input variable exist
2547!--       or not.
2548          CALL inquire_num_variables( id_topo, num_vars )
2549!
2550!--       Allocate memory to store variable names and inquire them.
2551          ALLOCATE( var_names(1:num_vars) )
2552          CALL inquire_variable_names( id_topo, var_names )
2553!
2554!--       Read x, y - dimensions. Only required for consistency checks.
2555          CALL netcdf_data_input_get_dimension_length( id_topo, dim_static%nx, 'x' )
2556          CALL netcdf_data_input_get_dimension_length( id_topo, dim_static%ny, 'y' )
2557          ALLOCATE( dim_static%x(0:dim_static%nx-1) )
2558          ALLOCATE( dim_static%y(0:dim_static%ny-1) )
2559          CALL get_variable( id_topo, 'x', dim_static%x )
2560          CALL get_variable( id_topo, 'y', dim_static%y )
2561!
2562!--       Check whether dimension size in input file matches the model dimensions
2563          IF ( dim_static%nx-1 /= nx  .OR.  dim_static%ny-1 /= ny )  THEN
2564             message_string = 'Static input file: horizontal dimension in ' // &
2565                              'x- and/or y-direction ' //                      &
2566                              'do not match the respective model dimension'
2567             CALL message( 'netcdf_data_input_mod', 'PA0548', 1, 2, 0, 6, 0 )
2568          ENDIF
2569!
2570!--       Check if grid spacing of provided input data matches the respective
2571!--       grid spacing in the model.
2572          IF ( ABS( dim_static%x(1) - dim_static%x(0) - dx ) > 10E-6_wp  .OR.  &
2573               ABS( dim_static%y(1) - dim_static%y(0) - dy ) > 10E-6_wp )  THEN
2574             message_string = 'Static input file: horizontal grid spacing ' // &
2575                              'in x- and/or y-direction ' //                   &
2576                              'do not match the respective model grid spacing.'
2577             CALL message( 'netcdf_data_input_mod', 'PA0549', 1, 2, 0, 6, 0 )
2578          ENDIF
2579!
2580!--       Terrain height. First, get variable-related _FillValue attribute
2581          IF ( check_existence( var_names, 'zt' ) )  THEN
2582             terrain_height_f%from_file = .TRUE.
2583             CALL get_attribute( id_topo, char_fill, terrain_height_f%fill,    &
2584                                 .FALSE., 'zt' )
2585!
2586!--          Input 2D terrain height.
2587             ALLOCATE ( terrain_height_f%var(nys:nyn,nxl:nxr)  )
2588             
2589             CALL get_variable( id_topo, 'zt', terrain_height_f%var,           &
2590                                nxl, nxr, nys, nyn )
2591
2592          ELSE
2593             terrain_height_f%from_file = .FALSE.
2594          ENDIF
2595
2596!
2597!--       Read building height. First, read its _FillValue attribute,
2598!--       as well as lod attribute
2599          buildings_f%from_file = .FALSE.
2600          IF ( check_existence( var_names, 'buildings_2d' ) )  THEN
2601             buildings_f%from_file = .TRUE.
2602             CALL get_attribute( id_topo, char_lod, buildings_f%lod,           &
2603                                 .FALSE., 'buildings_2d' )
2604
2605             CALL get_attribute( id_topo, char_fill, buildings_f%fill1,        &
2606                                 .FALSE., 'buildings_2d' )
2607
2608!
2609!--          Read 2D buildings
2610             IF ( buildings_f%lod == 1 )  THEN
2611                ALLOCATE ( buildings_f%var_2d(nys:nyn,nxl:nxr) )
2612
2613                CALL get_variable( id_topo, 'buildings_2d',                    &
2614                                   buildings_f%var_2d,                         &
2615                                   nxl, nxr, nys, nyn )
2616             ELSE
2617                message_string = 'NetCDF attribute lod ' //                    &
2618                                 '(level of detail) is not set ' //            &
2619                                 'properly for buildings_2d.'
2620                CALL message( 'netcdf_data_input_mod', 'PA0540',               &
2621                               1, 2, 0, 6, 0 )
2622             ENDIF
2623          ENDIF
2624!
2625!--       If available, also read 3D building information. If both are
2626!--       available, use 3D information.
2627          IF ( check_existence( var_names, 'buildings_3d' ) )  THEN
2628             buildings_f%from_file = .TRUE.
2629             CALL get_attribute( id_topo, char_lod, buildings_f%lod,           &
2630                                 .FALSE., 'buildings_3d' )     
2631
2632             CALL get_attribute( id_topo, char_fill, buildings_f%fill2,        &
2633                                 .FALSE., 'buildings_3d' )
2634
2635             CALL netcdf_data_input_get_dimension_length( id_topo,             &
2636                                                          buildings_f%nz, 'z' )
2637!
2638!--          Read 3D buildings
2639             IF ( buildings_f%lod == 2 )  THEN
2640                ALLOCATE( buildings_f%z(nzb:buildings_f%nz-1) )
2641                CALL get_variable( id_topo, 'z', buildings_f%z )
2642
2643                ALLOCATE( buildings_f%var_3d(nzb:buildings_f%nz-1,             &
2644                                             nys:nyn,nxl:nxr) )
2645                buildings_f%var_3d = 0
2646               
2647                CALL get_variable( id_topo, 'buildings_3d',                    &
2648                                   buildings_f%var_3d,                         &
2649                                   nxl, nxr, nys, nyn, 0, buildings_f%nz-1 )
2650             ELSE
2651                message_string = 'NetCDF attribute lod ' //                    &
2652                                 '(level of detail) is not set ' //            &
2653                                 'properly for buildings_3d.'
2654                CALL message( 'netcdf_data_input_mod', 'PA0541',               &
2655                               1, 2, 0, 6, 0 )
2656             ENDIF
2657          ENDIF
2658!
2659!--       Read building IDs and its FillValue attribute. Further required
2660!--       for mapping buildings on top of orography.
2661          IF ( check_existence( var_names, 'building_id' ) )  THEN
2662             building_id_f%from_file = .TRUE.
2663             CALL get_attribute( id_topo, char_fill,                           &
2664                                 building_id_f%fill, .FALSE.,                  &
2665                                 'building_id' )
2666
2667             ALLOCATE ( building_id_f%var(nys:nyn,nxl:nxr) )
2668             
2669             CALL get_variable( id_topo, 'building_id', building_id_f%var,     &
2670                                nxl, nxr, nys, nyn )
2671          ELSE
2672             building_id_f%from_file = .FALSE.
2673          ENDIF
2674!
2675!--       Read building_type and required attributes.
2676          IF ( check_existence( var_names, 'building_type' ) )  THEN
2677             building_type_f%from_file = .TRUE.
2678             CALL get_attribute( id_topo, char_fill,                           &
2679                                 building_type_f%fill, .FALSE.,                &
2680                                 'building_type' )
2681
2682             ALLOCATE ( building_type_f%var(nys:nyn,nxl:nxr) )
2683
2684             CALL get_variable( id_topo, 'building_type', building_type_f%var, &
2685                                nxl, nxr, nys, nyn )
2686
2687          ELSE
2688             building_type_f%from_file = .FALSE.
2689          ENDIF
2690!
2691!--       Close topography input file
2692          CALL close_input_file( id_topo )
2693#else
2694          CONTINUE
2695#endif
2696!
2697!--    ASCII input
2698       ELSEIF ( TRIM( topography ) == 'read_from_file' )  THEN
2699             
2700          DO  ii = 0, io_blocks-1
2701             IF ( ii == io_group )  THEN
2702
2703                OPEN( 90, FILE='TOPOGRAPHY_DATA'//TRIM( coupling_char ),       &
2704                      STATUS='OLD', FORM='FORMATTED', ERR=10 )
2705!
2706!--             Read topography PE-wise. Rows are read from nyn to nys, columns
2707!--             are read from nxl to nxr. At first, ny-nyn rows need to be skipped.
2708                skip_n_rows = 0
2709                DO WHILE ( skip_n_rows < ny - nyn )
2710                   READ( 90, * )
2711                   skip_n_rows = skip_n_rows + 1
2712                ENDDO
2713!
2714!--             Read data from nyn to nys and nxl to nxr. Therefore, skip
2715!--             column until nxl-1 is reached
2716                ALLOCATE ( buildings_f%var_2d(nys:nyn,nxl:nxr) )
2717                DO  j = nyn, nys, -1
2718                   READ( 90, *, ERR=11, END=11 )                               &
2719                                   ( dum, i = 0, nxl-1 ),                      &
2720                                   ( buildings_f%var_2d(j,i), i = nxl, nxr )
2721                ENDDO
2722
2723                GOTO 12
2724
2725 10             message_string = 'file TOPOGRAPHY_DATA'//                      &
2726                                 TRIM( coupling_char )// ' does not exist'
2727                CALL message( 'netcdf_data_input_mod', 'PA0208', 1, 2, 0, 6, 0 )
2728
2729 11             message_string = 'errors in file TOPOGRAPHY_DATA'//            &
2730                                 TRIM( coupling_char )
2731                CALL message( 'netcdf_data_input_mod', 'PA0209', 2, 2, 0, 6, 0 )
2732
2733 12             CLOSE( 90 )
2734                buildings_f%from_file = .TRUE.
2735
2736             ENDIF
2737#if defined( __parallel )
2738             CALL MPI_BARRIER( comm2d, ierr )
2739#endif
2740          ENDDO
2741
2742       ENDIF
2743!
2744!--    End of CPU measurement
2745       CALL cpu_log( log_point_s(83), 'NetCDF/ASCII input topo', 'stop' )
2746!
2747!--    Check for minimum requirement to setup building topography. If buildings
2748!--    are provided, also an ID and a type are required.
2749!--    Note, doing this check in check_parameters
2750!--    will be too late (data will be used for grid inititialization before).
2751       IF ( input_pids_static )  THEN
2752          IF ( buildings_f%from_file  .AND.                                    &
2753               .NOT. building_id_f%from_file )  THEN
2754             message_string = 'If building heights are prescribed in ' //      &
2755                              'static input file, also an ID is required.'
2756             CALL message( 'netcdf_data_input_mod', 'PA0542', 1, 2, 0, 6, 0 )
2757          ENDIF
2758       ENDIF
2759!
2760!--    In case no terrain height is provided by static input file, allocate
2761!--    array nevertheless and set terrain height to 0, which simplifies
2762!--    topography initialization.
2763       IF ( .NOT. terrain_height_f%from_file )  THEN
2764          ALLOCATE ( terrain_height_f%var(nys:nyn,nxl:nxr) )
2765          terrain_height_f%var = 0.0_wp
2766       ENDIF
2767!
2768!--    Finally, exchange 1 ghost point for building ID and type.
2769!--    In case of non-cyclic boundary conditions set Neumann conditions at the
2770!--    lateral boundaries.
2771       IF ( building_id_f%from_file )  THEN
2772          CALL resize_array_2d_int32( building_id_f%var, nys, nyn, nxl, nxr )
2773          CALL exchange_horiz_2d_int( building_id_f%var, nys, nyn, nxl, nxr,   &
2774                                      nbgp )
2775       ENDIF
2776
2777       IF ( building_type_f%from_file )  THEN
2778          CALL resize_array_2d_int8( building_type_f%var, nys, nyn, nxl, nxr )
2779          CALL exchange_horiz_2d_byte( building_type_f%var, nys, nyn, nxl, nxr,   &
2780                                       nbgp )
2781       ENDIF
2782
2783    END SUBROUTINE netcdf_data_input_topo
2784
2785!------------------------------------------------------------------------------!
2786! Description:
2787! ------------
2788!> Reads initialization data of u, v, w, pt, q, geostrophic wind components,
2789!> as well as soil moisture and soil temperature, derived from larger-scale
2790!> model (COSMO) by Inifor.
2791!------------------------------------------------------------------------------!
2792    SUBROUTINE netcdf_data_input_init_3d
2793
2794       USE arrays_3d,                                                          &
2795           ONLY:  q, pt, u, v, w, zu, zw
2796
2797       USE control_parameters,                                                 &
2798           ONLY:  air_chemistry, bc_lr_cyc, bc_ns_cyc, humidity,               &
2799                  message_string, neutral
2800
2801       USE indices,                                                            &
2802           ONLY:  nx, nxl, nxlu, nxr, ny, nyn, nys, nysv, nzb, nz, nzt
2803
2804       IMPLICIT NONE
2805
2806       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names
2807
2808       LOGICAL      ::  dynamic_3d = .TRUE. !< flag indicating that 3D data is read from dynamic file
2809       
2810       INTEGER(iwp) ::  id_dynamic !< NetCDF id of dynamic input file
2811       INTEGER(iwp) ::  n          !< running index for chemistry variables
2812       INTEGER(iwp) ::  num_vars   !< number of variables in netcdf input file
2813
2814       LOGICAL      ::  check_passed !< flag indicating if a check passed
2815
2816!
2817!--    Skip routine if no input file with dynamic input data is available.
2818       IF ( .NOT. input_pids_dynamic )  RETURN
2819!
2820!--    Please note, Inifor is designed to provide initial data for u and v for
2821!--    the prognostic grid points in case of lateral Dirichlet conditions.
2822!--    This means that Inifor provides data from nxlu:nxr (for u) and
2823!--    from nysv:nyn (for v) at the left and south domain boundary, respectively.
2824!--    However, as work-around for the moment, PALM will run with cyclic
2825!--    conditions and will be initialized with data provided by Inifor
2826!--    boundaries in case of Dirichlet.
2827!--    Hence, simply set set nxlu/nysv to 1 (will be reset to its original value
2828!--    at the end of this routine.
2829       IF ( bc_lr_cyc  .AND.  nxl == 0 )  nxlu = 1
2830       IF ( bc_ns_cyc  .AND.  nys == 0 )  nysv = 1
2831
2832!
2833!--    CPU measurement
2834       CALL cpu_log( log_point_s(85), 'NetCDF input init', 'start' )
2835
2836#if defined ( __netcdf )
2837!
2838!--    Open file in read-only mode
2839       CALL open_read_file( TRIM( input_file_dynamic ) //                      &
2840                            TRIM( coupling_char ), id_dynamic )
2841
2842!
2843!--    At first, inquire all variable names.
2844       CALL inquire_num_variables( id_dynamic, num_vars )
2845!
2846!--    Allocate memory to store variable names.
2847       ALLOCATE( var_names(1:num_vars) )
2848       CALL inquire_variable_names( id_dynamic, var_names )
2849!
2850!--    Read vertical dimension of scalar und w grid.
2851       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nzu, 'z'     )
2852       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nzw, 'zw'    )
2853!
2854!--    Read also the horizontal dimensions. These are used just used fo
2855!--    checking the compatibility with the PALM grid before reading.
2856       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nx,  'x'  )
2857       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nxu, 'xu' )
2858       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%ny,  'y'  )
2859       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nyv, 'yv' )
2860
2861!
2862!--    Check for correct horizontal and vertical dimension. Please note,
2863!--    checks are performed directly here and not called from
2864!--    check_parameters as some varialbes are still not allocated there.
2865!--    Moreover, please note, u- and v-grid has 1 grid point less on
2866!--    Inifor grid.
2867       IF ( init_3d%nx-1 /= nx  .OR.  init_3d%nxu-1 /= nx - 1  .OR.            &
2868            init_3d%ny-1 /= ny  .OR.  init_3d%nyv-1 /= ny - 1 )  THEN
2869          message_string = 'Number of inifor horizontal grid points  '//       &
2870                           'does not match the number of numeric grid '//      &
2871                           'points.'
2872          CALL message( 'netcdf_data_input_mod', 'PA0543', 1, 2, 0, 6, 0 )
2873       ENDIF
2874
2875       IF ( init_3d%nzu /= nz )  THEN
2876          message_string = 'Number of inifor vertical grid points ' //         &
2877                           'does not match the number of numeric grid '//      &
2878                           'points.'
2879          CALL message( 'netcdf_data_input_mod', 'PA0543', 1, 2, 0, 6, 0 )
2880       ENDIF
2881!
2882!--    Read vertical dimensions. Later, these are required for eventual
2883!--    inter- and extrapolations of the initialization data.
2884       IF ( check_existence( var_names, 'z' ) )  THEN
2885          ALLOCATE( init_3d%zu_atmos(1:init_3d%nzu) )
2886          CALL get_variable( id_dynamic, 'z', init_3d%zu_atmos )
2887       ENDIF
2888       IF ( check_existence( var_names, 'zw' ) )  THEN
2889          ALLOCATE( init_3d%zw_atmos(1:init_3d%nzw) )
2890          CALL get_variable( id_dynamic, 'zw', init_3d%zw_atmos )
2891       ENDIF
2892!
2893!--    Check for consistency between vertical coordinates in dynamic
2894!--    driver and numeric grid.
2895!--    Please note, depending on compiler options both may be
2896!--    equal up to a certain threshold, and differences between
2897!--    the numeric grid and vertical coordinate in the driver can built-
2898!--    up to 10E-1-10E-0 m. For this reason, the check is performed not
2899!--    for exactly matching values.
2900       IF ( ANY( ABS( zu(1:nzt)   - init_3d%zu_atmos(1:init_3d%nzu) )    &
2901                      > 10E-1 )  .OR.                                    &
2902            ANY( ABS( zw(1:nzt-1) - init_3d%zw_atmos(1:init_3d%nzw) )    &
2903                      > 10E-1 ) )  THEN
2904          message_string = 'Vertical grid in dynamic driver does not '// &
2905                           'match the numeric grid.'
2906          CALL message( 'netcdf_data_input_mod', 'PA0543', 1, 2, 0, 6, 0 )
2907       ENDIF
2908!
2909!--    Read initial geostrophic wind components at
2910!--    t = 0 (index 1 in file).
2911       IF ( check_existence( var_names, 'ls_forcing_ug' ) )  THEN
2912          ALLOCATE( init_3d%ug_init(nzb:nzt+1) )
2913          init_3d%ug_init = 0.0_wp
2914
2915          CALL get_variable_pr( id_dynamic, 'ls_forcing_ug', 1,          &
2916                                init_3d%ug_init(1:nzt) )
2917!
2918!--       Set top-boundary condition (Neumann)
2919          init_3d%ug_init(nzt+1) = init_3d%ug_init(nzt)
2920
2921          init_3d%from_file_ug = .TRUE.
2922       ELSE
2923          init_3d%from_file_ug = .FALSE.
2924       ENDIF
2925       IF ( check_existence( var_names, 'ls_forcing_vg' ) )  THEN
2926          ALLOCATE( init_3d%vg_init(nzb:nzt+1) )
2927          init_3d%vg_init = 0.0_wp
2928
2929          CALL get_variable_pr( id_dynamic, 'ls_forcing_vg', 1,          &
2930                                init_3d%vg_init(1:nzt) )
2931!
2932!--       Set top-boundary condition (Neumann)
2933          init_3d%vg_init(nzt+1) = init_3d%vg_init(nzt)
2934
2935          init_3d%from_file_vg = .TRUE.
2936       ELSE
2937          init_3d%from_file_vg = .FALSE.
2938       ENDIF
2939!
2940!--    Read inital 3D data of u, v, w, pt and q,
2941!--    derived from COSMO model. Read PE-wise yz-slices.
2942!--    Please note, the u-, v- and w-component are defined on different
2943!--    grids with one element less in the x-, y-,
2944!--    and z-direction, respectively. Hence, reading is subdivided
2945!--    into separate loops. 
2946!--    Read u-component
2947       IF ( check_existence( var_names, 'init_atmosphere_u' ) )  THEN
2948!
2949!--       Read attributes for the fill value and level-of-detail
2950          CALL get_attribute( id_dynamic, char_fill, init_3d%fill_u,           &
2951                              .FALSE., 'init_atmosphere_u' )
2952          CALL get_attribute( id_dynamic, char_lod, init_3d%lod_u,             &
2953                              .FALSE., 'init_atmosphere_u' )
2954!
2955!--       level-of-detail 1 - read initialization profile
2956          IF ( init_3d%lod_u == 1 )  THEN
2957             ALLOCATE( init_3d%u_init(nzb:nzt+1) )
2958             init_3d%u_init = 0.0_wp
2959
2960             CALL get_variable( id_dynamic, 'init_atmosphere_u',               &
2961                                init_3d%u_init(nzb+1:nzt) )
2962!
2963!--          Set top-boundary condition (Neumann)
2964             init_3d%u_init(nzt+1) = init_3d%u_init(nzt)
2965!
2966!--       level-of-detail 2 - read 3D initialization data
2967          ELSEIF ( init_3d%lod_u == 2 )  THEN
2968             CALL get_variable( id_dynamic, 'init_atmosphere_u',               &
2969                                u(nzb+1:nzt,nys:nyn,nxlu:nxr),                 &
2970                                nxlu, nys+1, nzb+1,                            &
2971                                nxr-nxlu+1, nyn-nys+1, init_3d%nzu,            &
2972                                dynamic_3d )
2973!
2974!--          Set value at leftmost model grid point nxl = 0. This is because
2975!--          Inifor provides data only from 1:nx-1 since it assumes non-cyclic
2976!--          conditions.
2977             IF ( nxl == 0 )                                                   &
2978                u(nzb+1:nzt,nys:nyn,nxl) = u(nzb+1:nzt,nys:nyn,nxlu)
2979!
2980!--          Set bottom and top-boundary
2981             u(nzb,:,:)   = u(nzb+1,:,:)
2982             u(nzt+1,:,:) = u(nzt,:,:)
2983             
2984          ENDIF
2985          init_3d%from_file_u = .TRUE.
2986       ELSE
2987          message_string = 'Missing initial data for u-component'
2988          CALL message( 'netcdf_data_input_mod', 'PA0544', 1, 2, 0, 6, 0 )
2989       ENDIF
2990!
2991!--    Read v-component
2992       IF ( check_existence( var_names, 'init_atmosphere_v' ) )  THEN
2993!
2994!--       Read attributes for the fill value and level-of-detail
2995          CALL get_attribute( id_dynamic, char_fill, init_3d%fill_v,           &
2996                              .FALSE., 'init_atmosphere_v' )
2997          CALL get_attribute( id_dynamic, char_lod, init_3d%lod_v,             &
2998                              .FALSE., 'init_atmosphere_v' )
2999!
3000!--       level-of-detail 1 - read initialization profile
3001          IF ( init_3d%lod_v == 1 )  THEN
3002             ALLOCATE( init_3d%v_init(nzb:nzt+1) )
3003             init_3d%v_init = 0.0_wp
3004
3005             CALL get_variable( id_dynamic, 'init_atmosphere_v',               &
3006                                init_3d%v_init(nzb+1:nzt) )
3007!
3008!--          Set top-boundary condition (Neumann)
3009             init_3d%v_init(nzt+1) = init_3d%v_init(nzt)
3010!
3011!--       level-of-detail 2 - read 3D initialization data
3012          ELSEIF ( init_3d%lod_v == 2 )  THEN
3013         
3014             CALL get_variable( id_dynamic, 'init_atmosphere_v',               &
3015                                v(nzb+1:nzt,nysv:nyn,nxl:nxr),                 &
3016                                nxl+1, nysv, nzb+1,                            &
3017                                nxr-nxl+1, nyn-nysv+1, init_3d%nzu,            &
3018                                dynamic_3d )
3019!
3020!--          Set value at southmost model grid point nys = 0. This is because
3021!--          Inifor provides data only from 1:ny-1 since it assumes non-cyclic
3022!--          conditions.
3023             IF ( nys == 0 )                                                   &
3024                v(nzb+1:nzt,nys,nxl:nxr) = v(nzb+1:nzt,nysv,nxl:nxr)                               
3025!
3026!--          Set bottom and top-boundary
3027             v(nzb,:,:)   = v(nzb+1,:,:)
3028             v(nzt+1,:,:) = v(nzt,:,:)
3029             
3030          ENDIF
3031          init_3d%from_file_v = .TRUE.
3032       ELSE
3033          message_string = 'Missing initial data for v-component'
3034          CALL message( 'netcdf_data_input_mod', 'PA0544', 1, 2, 0, 6, 0 )
3035       ENDIF
3036!
3037!--    Read w-component
3038       IF ( check_existence( var_names, 'init_atmosphere_w' ) )  THEN
3039!
3040!--       Read attributes for the fill value and level-of-detail
3041          CALL get_attribute( id_dynamic, char_fill, init_3d%fill_w,           &
3042                              .FALSE., 'init_atmosphere_w' )
3043          CALL get_attribute( id_dynamic, char_lod, init_3d%lod_w,             &
3044                              .FALSE., 'init_atmosphere_w' )
3045!
3046!--       level-of-detail 1 - read initialization profile
3047          IF ( init_3d%lod_w == 1 )  THEN
3048             ALLOCATE( init_3d%w_init(nzb:nzt+1) )
3049             init_3d%w_init = 0.0_wp
3050
3051             CALL get_variable( id_dynamic, 'init_atmosphere_w',               &
3052                                init_3d%w_init(nzb+1:nzt-1) )
3053!
3054!--          Set top-boundary condition (Neumann)
3055             init_3d%w_init(nzt:nzt+1) = init_3d%w_init(nzt-1)
3056!
3057!--       level-of-detail 2 - read 3D initialization data
3058          ELSEIF ( init_3d%lod_w == 2 )  THEN
3059
3060             CALL get_variable( id_dynamic, 'init_atmosphere_w',                &
3061                                w(nzb+1:nzt-1,nys:nyn,nxl:nxr),                 &
3062                                nxl+1, nys+1, nzb+1,                            &
3063                                nxr-nxl+1, nyn-nys+1, init_3d%nzw,              &
3064                                dynamic_3d )
3065!
3066!--          Set bottom and top-boundary                               
3067             w(nzb,:,:)   = 0.0_wp 
3068             w(nzt,:,:)   = w(nzt-1,:,:)
3069             w(nzt+1,:,:) = w(nzt-1,:,:)
3070
3071          ENDIF
3072          init_3d%from_file_w = .TRUE.
3073       ELSE
3074          message_string = 'Missing initial data for w-component'
3075          CALL message( 'netcdf_data_input_mod', 'PA0544', 1, 2, 0, 6, 0 )
3076       ENDIF
3077!
3078!--    Read potential temperature
3079       IF ( .NOT. neutral )  THEN
3080          IF ( check_existence( var_names, 'init_atmosphere_pt' ) )  THEN
3081!
3082!--          Read attributes for the fill value and level-of-detail
3083             CALL get_attribute( id_dynamic, char_fill, init_3d%fill_pt,       &
3084                                 .FALSE., 'init_atmosphere_pt' )
3085             CALL get_attribute( id_dynamic, char_lod, init_3d%lod_pt,         &
3086                                 .FALSE., 'init_atmosphere_pt' )
3087!
3088!--          level-of-detail 1 - read initialization profile
3089             IF ( init_3d%lod_pt == 1 )  THEN
3090                ALLOCATE( init_3d%pt_init(nzb:nzt+1) )
3091
3092                CALL get_variable( id_dynamic, 'init_atmosphere_pt',           &
3093                                   init_3d%pt_init(nzb+1:nzt) )
3094!
3095!--             Set Neumann top and surface boundary condition for initial
3096!--             profil
3097                init_3d%pt_init(nzb)   = init_3d%pt_init(nzb+1)
3098                init_3d%pt_init(nzt+1) = init_3d%pt_init(nzt)
3099!
3100!--          level-of-detail 2 - read 3D initialization data
3101             ELSEIF ( init_3d%lod_pt == 2 )  THEN
3102
3103                CALL get_variable( id_dynamic, 'init_atmosphere_pt',           &
3104                                   pt(nzb+1:nzt,nys:nyn,nxl:nxr),              &
3105                                   nxl+1, nys+1, nzb+1,                        &
3106                                   nxr-nxl+1, nyn-nys+1, init_3d%nzu,          &
3107                                   dynamic_3d )
3108                                   
3109!
3110!--             Set bottom and top-boundary
3111                pt(nzb,:,:)   = pt(nzb+1,:,:)
3112                pt(nzt+1,:,:) = pt(nzt,:,:)             
3113
3114             ENDIF
3115             init_3d%from_file_pt = .TRUE.
3116          ELSE
3117             message_string = 'Missing initial data for ' //                   &
3118                              'potential temperature'
3119             CALL message( 'netcdf_data_input_mod', 'PA0544', 1, 2, 0, 6, 0 )
3120          ENDIF
3121       ENDIF
3122!
3123!--    Read mixing ratio
3124       IF ( humidity )  THEN
3125          IF ( check_existence( var_names, 'init_atmosphere_qv' ) )  THEN
3126!
3127!--          Read attributes for the fill value and level-of-detail
3128             CALL get_attribute( id_dynamic, char_fill, init_3d%fill_q,        &
3129                                 .FALSE., 'init_atmosphere_qv' )
3130             CALL get_attribute( id_dynamic, char_lod, init_3d%lod_q,          &
3131                                 .FALSE., 'init_atmosphere_qv' )
3132!
3133!--          level-of-detail 1 - read initialization profile
3134             IF ( init_3d%lod_q == 1 )  THEN
3135                ALLOCATE( init_3d%q_init(nzb:nzt+1) )
3136
3137                CALL get_variable( id_dynamic, 'init_atmosphere_qv',           &
3138                                    init_3d%q_init(nzb+1:nzt) )
3139!
3140!--             Set bottom and top boundary condition (Neumann)
3141                init_3d%q_init(nzb)   = init_3d%q_init(nzb+1)
3142                init_3d%q_init(nzt+1) = init_3d%q_init(nzt)
3143!
3144!--          level-of-detail 2 - read 3D initialization data
3145             ELSEIF ( init_3d%lod_q == 2 )  THEN
3146             
3147                CALL get_variable( id_dynamic, 'init_atmosphere_qv',           &
3148                                   q(nzb+1:nzt,nys:nyn,nxl:nxr),               &
3149                                   nxl+1, nys+1, nzb+1,                        &
3150                                   nxr-nxl+1, nyn-nys+1, init_3d%nzu,          &
3151                                   dynamic_3d )
3152                                   
3153!
3154!--             Set bottom and top-boundary
3155                q(nzb,:,:)   = q(nzb+1,:,:)
3156                q(nzt+1,:,:) = q(nzt,:,:)
3157               
3158             ENDIF
3159             init_3d%from_file_q = .TRUE.
3160          ELSE
3161             message_string = 'Missing initial data for ' //                   &
3162                              'mixing ratio'
3163             CALL message( 'netcdf_data_input_mod', 'PA0544', 1, 2, 0, 6, 0 )
3164          ENDIF
3165       ENDIF       
3166!
3167!--    Read chemistry variables.
3168!--    Please note, for the moment, only LOD=1 is allowed
3169       IF ( air_chemistry )  THEN
3170!
3171!--       Allocate chemistry input profiles, as well as arrays for fill values
3172!--       and LOD's.
3173          ALLOCATE( init_3d%chem_init(nzb:nzt+1,                               &
3174                                      1:UBOUND(init_3d%var_names_chem, 1 )) )
3175          ALLOCATE( init_3d%fill_chem(1:UBOUND(init_3d%var_names_chem, 1)) )   
3176          ALLOCATE( init_3d%lod_chem(1:UBOUND(init_3d%var_names_chem, 1))  ) 
3177         
3178          DO  n = 1, UBOUND(init_3d%var_names_chem, 1)
3179             IF ( check_existence( var_names,                                  &
3180                                   TRIM( init_3d%var_names_chem(n) ) ) )  THEN
3181!
3182!--             Read attributes for the fill value and level-of-detail
3183                CALL get_attribute( id_dynamic, char_fill,                     &
3184                                    init_3d%fill_chem(n),                      &
3185                                    .FALSE.,                                   &
3186                                    TRIM( init_3d%var_names_chem(n) ) )
3187                CALL get_attribute( id_dynamic, char_lod,                      &
3188                                    init_3d%lod_chem(n),                       &
3189                                    .FALSE.,                                   &
3190                                    TRIM( init_3d%var_names_chem(n) ) )
3191!
3192!--             Give message that only LOD=1 is allowed.
3193                IF ( init_3d%lod_chem(n) /= 1 )  THEN               
3194                   message_string = 'For chemistry variables only LOD=1 is ' //&
3195                                    'allowed.'
3196                   CALL message( 'netcdf_data_input_mod', 'PA0586',            &
3197                                 1, 2, 0, 6, 0 )
3198                ENDIF
3199!
3200!--             level-of-detail 1 - read initialization profile
3201                CALL get_variable( id_dynamic,                                 &
3202                                   TRIM( init_3d%var_names_chem(n) ),          &
3203                                   init_3d%chem_init(nzb+1:nzt,n) )
3204!
3205!--             Set bottom and top boundary condition (Neumann)
3206                init_3d%chem_init(nzb,n)   = init_3d%chem_init(nzb+1,n)
3207                init_3d%chem_init(nzt+1,n) = init_3d%chem_init(nzt,n)
3208               
3209                init_3d%from_file_chem(n) = .TRUE.
3210             ENDIF
3211          ENDDO
3212       ENDIF
3213!
3214!--    Close input file
3215       CALL close_input_file( id_dynamic )
3216#endif
3217!
3218!--    End of CPU measurement
3219       CALL cpu_log( log_point_s(85), 'NetCDF input init', 'stop' )
3220!
3221!--    Finally, check if the input data has any fill values. Please note,
3222!--    checks depend on the LOD of the input data.
3223       IF ( init_3d%from_file_u )  THEN
3224          check_passed = .TRUE.
3225          IF ( init_3d%lod_u == 1 )  THEN
3226             IF ( ANY( init_3d%u_init(nzb+1:nzt+1) == init_3d%fill_u ) )       &
3227                check_passed = .FALSE.
3228          ELSEIF ( init_3d%lod_u == 2 )  THEN
3229             IF ( ANY( u(nzb+1:nzt+1,nys:nyn,nxlu:nxr) == init_3d%fill_u ) )   &
3230                check_passed = .FALSE.
3231          ENDIF
3232          IF ( .NOT. check_passed )  THEN
3233             message_string = 'NetCDF input for init_atmosphere_u must ' //    &
3234                              'not contain any _FillValues'
3235             CALL message( 'netcdf_data_input_mod', 'PA0545', 2, 2, 0, 6, 0 )
3236          ENDIF
3237       ENDIF
3238
3239       IF ( init_3d%from_file_v )  THEN
3240          check_passed = .TRUE.
3241          IF ( init_3d%lod_v == 1 )  THEN
3242             IF ( ANY( init_3d%v_init(nzb+1:nzt+1) == init_3d%fill_v ) )       &
3243                check_passed = .FALSE.
3244          ELSEIF ( init_3d%lod_v == 2 )  THEN
3245             IF ( ANY( v(nzb+1:nzt+1,nysv:nyn,nxl:nxr) == init_3d%fill_v ) )   &
3246                check_passed = .FALSE.
3247          ENDIF
3248          IF ( .NOT. check_passed )  THEN
3249             message_string = 'NetCDF input for init_atmosphere_v must ' //    &
3250                              'not contain any _FillValues'
3251             CALL message( 'netcdf_data_input_mod', 'PA0545', 2, 2, 0, 6, 0 )
3252          ENDIF
3253       ENDIF
3254
3255       IF ( init_3d%from_file_w )  THEN
3256          check_passed = .TRUE.
3257          IF ( init_3d%lod_w == 1 )  THEN
3258             IF ( ANY( init_3d%w_init(nzb+1:nzt) == init_3d%fill_w ) )         &
3259                check_passed = .FALSE.
3260          ELSEIF ( init_3d%lod_w == 2 )  THEN
3261             IF ( ANY( w(nzb+1:nzt,nys:nyn,nxl:nxr) == init_3d%fill_w ) )      &
3262                check_passed = .FALSE.
3263          ENDIF
3264          IF ( .NOT. check_passed )  THEN
3265             message_string = 'NetCDF input for init_atmosphere_w must ' //    &
3266                              'not contain any _FillValues'
3267             CALL message( 'netcdf_data_input_mod', 'PA0545', 2, 2, 0, 6, 0 )
3268          ENDIF
3269       ENDIF
3270
3271       IF ( init_3d%from_file_pt )  THEN
3272          check_passed = .TRUE.
3273          IF ( init_3d%lod_pt == 1 )  THEN
3274             IF ( ANY( init_3d%pt_init(nzb+1:nzt+1) == init_3d%fill_pt ) )     &
3275                check_passed = .FALSE.
3276          ELSEIF ( init_3d%lod_pt == 2 )  THEN
3277             IF ( ANY( pt(nzb+1:nzt+1,nys:nyn,nxl:nxr) == init_3d%fill_pt ) )  &
3278                check_passed = .FALSE.
3279          ENDIF
3280          IF ( .NOT. check_passed )  THEN
3281             message_string = 'NetCDF input for init_atmosphere_pt must ' //   &
3282                              'not contain any _FillValues'
3283             CALL message( 'netcdf_data_input_mod', 'PA0545', 2, 2, 0, 6, 0 )
3284          ENDIF
3285       ENDIF
3286
3287       IF ( init_3d%from_file_q )  THEN
3288          check_passed = .TRUE.
3289          IF ( init_3d%lod_q == 1 )  THEN
3290             IF ( ANY( init_3d%q_init(nzb+1:nzt+1) == init_3d%fill_q ) )       &
3291                check_passed = .FALSE.
3292          ELSEIF ( init_3d%lod_q == 2 )  THEN
3293             IF ( ANY( q(nzb+1:nzt+1,nys:nyn,nxl:nxr) == init_3d%fill_q ) )    &
3294                check_passed = .FALSE.
3295          ENDIF
3296          IF ( .NOT. check_passed )  THEN
3297             message_string = 'NetCDF input for init_atmosphere_q must ' //    &
3298                              'not contain any _FillValues'
3299             CALL message( 'netcdf_data_input_mod', 'PA0545', 2, 2, 0, 6, 0 )
3300          ENDIF
3301       ENDIF
3302!
3303!--    Workaround for cyclic conditions. Please see above for further explanation.
3304       IF ( bc_lr_cyc  .AND.  nxl == 0 )  nxlu = nxl
3305       IF ( bc_ns_cyc  .AND.  nys == 0 )  nysv = nys
3306
3307    END SUBROUTINE netcdf_data_input_init_3d
3308   
3309!------------------------------------------------------------------------------!
3310! Description:
3311! ------------
3312!> Reads initialization data of u, v, w, pt, q, geostrophic wind components,
3313!> as well as soil moisture and soil temperature, derived from larger-scale
3314!> model (COSMO) by Inifor.
3315!------------------------------------------------------------------------------!
3316    SUBROUTINE netcdf_data_input_init_lsm
3317
3318       USE control_parameters,                                                 &
3319           ONLY:  message_string
3320
3321       USE indices,                                                            &
3322           ONLY:  nx, nxl, nxr, ny, nyn, nys
3323
3324       IMPLICIT NONE
3325
3326       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names !< string containing all variables on file
3327     
3328       INTEGER(iwp) ::  id_dynamic !< NetCDF id of dynamic input file
3329       INTEGER(iwp) ::  num_vars   !< number of variables in netcdf input file
3330
3331!
3332!--    Skip routine if no input file with dynamic input data is available.
3333       IF ( .NOT. input_pids_dynamic )  RETURN
3334!
3335!--    CPU measurement
3336       CALL cpu_log( log_point_s(85), 'NetCDF input init', 'start' )
3337
3338#if defined ( __netcdf )
3339!
3340!--    Open file in read-only mode
3341       CALL open_read_file( TRIM( input_file_dynamic ) //                      &
3342                            TRIM( coupling_char ), id_dynamic )
3343
3344!
3345!--    At first, inquire all variable names.
3346       CALL inquire_num_variables( id_dynamic, num_vars )
3347!
3348!--    Allocate memory to store variable names.
3349       ALLOCATE( var_names(1:num_vars) )
3350       CALL inquire_variable_names( id_dynamic, var_names )
3351!
3352!--    Read vertical dimension for soil depth.
3353       IF ( check_existence( var_names, 'zsoil' ) )                            &
3354          CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nzs,&
3355                                                       'zsoil' )
3356!
3357!--    Read also the horizontal dimensions required for soil initialization.
3358!--    Please note, in case of non-nested runs or in case of root domain,
3359!--    these data is already available, but will be read again for the sake
3360!--    of clearness.
3361       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nx,    &
3362                                                    'x'  )
3363       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%ny,    &
3364                                                    'y'  )
3365!
3366!--    Check for correct horizontal and vertical dimension. Please note,
3367!--    in case of non-nested runs or in case of root domain, these checks
3368!--    are already performed
3369       IF ( init_3d%nx-1 /= nx  .OR.  init_3d%ny-1 /= ny )  THEN
3370          message_string = 'Number of inifor horizontal grid points  '//       &
3371                           'does not match the number of numeric grid points.'
3372          CALL message( 'netcdf_data_input_mod', 'PA0543', 1, 2, 0, 6, 0 )
3373       ENDIF
3374!
3375!--    Read vertical dimensions. Later, these are required for eventual
3376!--    inter- and extrapolations of the initialization data.
3377       IF ( check_existence( var_names, 'zsoil' ) )  THEN
3378          ALLOCATE( init_3d%z_soil(1:init_3d%nzs) )
3379          CALL get_variable( id_dynamic, 'zsoil', init_3d%z_soil )
3380       ENDIF
3381!
3382!--    Read initial data for soil moisture
3383       IF ( check_existence( var_names, 'init_soil_m' ) )  THEN
3384!
3385!--       Read attributes for the fill value and level-of-detail
3386          CALL get_attribute( id_dynamic, char_fill,                           &
3387                              init_3d%fill_msoil,                              &
3388                              .FALSE., 'init_soil_m' )
3389          CALL get_attribute( id_dynamic, char_lod,                            &
3390                              init_3d%lod_msoil,                               &
3391                              .FALSE., 'init_soil_m' )
3392!
3393!--       level-of-detail 1 - read initialization profile
3394          IF ( init_3d%lod_msoil == 1 )  THEN
3395             ALLOCATE( init_3d%msoil_1d(0:init_3d%nzs-1) )
3396
3397             CALL get_variable( id_dynamic, 'init_soil_m',                     &
3398                                init_3d%msoil_1d(0:init_3d%nzs-1) )
3399!
3400!--       level-of-detail 2 - read 3D initialization data
3401          ELSEIF ( init_3d%lod_msoil == 2 )  THEN
3402             ALLOCATE ( init_3d%msoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr) )
3403
3404            CALL get_variable( id_dynamic, 'init_soil_m',                      &   
3405                             init_3d%msoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr),&
3406                             nxl, nxr, nys, nyn, 0, init_3d%nzs-1 )
3407
3408          ENDIF
3409          init_3d%from_file_msoil = .TRUE.
3410       ENDIF
3411!
3412!--    Read soil temperature
3413       IF ( check_existence( var_names, 'init_soil_t' ) )  THEN
3414!
3415!--       Read attributes for the fill value and level-of-detail
3416          CALL get_attribute( id_dynamic, char_fill,                           &
3417                              init_3d%fill_tsoil,                              &
3418                              .FALSE., 'init_soil_t' )
3419          CALL get_attribute( id_dynamic, char_lod,                            &
3420                              init_3d%lod_tsoil,                               &
3421                              .FALSE., 'init_soil_t' )
3422!
3423!--       level-of-detail 1 - read initialization profile
3424          IF ( init_3d%lod_tsoil == 1 )  THEN
3425             ALLOCATE( init_3d%tsoil_1d(0:init_3d%nzs-1) )
3426
3427             CALL get_variable( id_dynamic, 'init_soil_t',                     &
3428                                init_3d%tsoil_1d(0:init_3d%nzs-1) )
3429
3430!
3431!--       level-of-detail 2 - read 3D initialization data
3432          ELSEIF ( init_3d%lod_tsoil == 2 )  THEN
3433             ALLOCATE ( init_3d%tsoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr) )
3434             
3435             CALL get_variable( id_dynamic, 'init_soil_t',                     &   
3436                             init_3d%tsoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr),&
3437                             nxl, nxr, nys, nyn, 0, init_3d%nzs-1 )
3438          ENDIF
3439          init_3d%from_file_tsoil = .TRUE.
3440       ENDIF
3441!
3442!--    Close input file
3443       CALL close_input_file( id_dynamic )
3444#endif
3445!
3446!--    End of CPU measurement
3447       CALL cpu_log( log_point_s(85), 'NetCDF input init', 'stop' )
3448
3449    END SUBROUTINE netcdf_data_input_init_lsm   
3450
3451!------------------------------------------------------------------------------!
3452! Description:
3453! ------------
3454!> Reads data at lateral and top boundaries derived from larger-scale model
3455!> (COSMO) by Inifor.
3456!------------------------------------------------------------------------------!
3457    SUBROUTINE netcdf_data_input_offline_nesting
3458
3459       USE control_parameters,                                                 &
3460           ONLY:  air_chemistry, bc_dirichlet_l, bc_dirichlet_n,               &
3461                  bc_dirichlet_r, bc_dirichlet_s, humidity, neutral,           &
3462                  nesting_offline, time_since_reference_point
3463
3464       USE indices,                                                            &
3465           ONLY:  nxl, nxlu, nxr, nyn, nys, nysv, nzb, nzt
3466
3467       IMPLICIT NONE
3468       
3469       INTEGER(iwp) ::  id_dynamic !< NetCDF id of dynamic input file
3470       INTEGER(iwp) ::  n          !< running index for chemistry variables
3471       INTEGER(iwp) ::  num_vars   !< number of variables in netcdf input file
3472       INTEGER(iwp) ::  t          !< running index time dimension
3473!
3474!--    Skip input if no forcing from larger-scale models is applied.
3475       IF ( .NOT. nesting_offline )  RETURN
3476
3477!
3478!--    CPU measurement
3479       CALL cpu_log( log_point_s(86), 'NetCDF input forcing', 'start' )
3480
3481#if defined ( __netcdf )
3482!
3483!--    Open file in read-only mode
3484       CALL open_read_file( TRIM( input_file_dynamic ) //                      &
3485                            TRIM( coupling_char ), id_dynamic )
3486!
3487!--    Initialize INIFOR forcing.
3488       IF ( .NOT. nest_offl%init )  THEN
3489!
3490!--       At first, inquire all variable names.
3491          CALL inquire_num_variables( id_dynamic, num_vars )
3492!
3493!--       Allocate memory to store variable names.
3494          ALLOCATE( nest_offl%var_names(1:num_vars) )
3495          CALL inquire_variable_names( id_dynamic, nest_offl%var_names )
3496!
3497!--       Read time dimension, allocate memory and finally read time array
3498          CALL netcdf_data_input_get_dimension_length( id_dynamic,             &
3499                                                       nest_offl%nt, 'time' )
3500
3501          IF ( check_existence( nest_offl%var_names, 'time' ) )  THEN
3502             ALLOCATE( nest_offl%time(0:nest_offl%nt-1) )
3503             CALL get_variable( id_dynamic, 'time', nest_offl%time )
3504          ENDIF
3505!
3506!--       Read vertical dimension of scalar und w grid
3507          CALL netcdf_data_input_get_dimension_length( id_dynamic,             &
3508                                                       nest_offl%nzu, 'z' )
3509          CALL netcdf_data_input_get_dimension_length( id_dynamic,             &
3510                                                       nest_offl%nzw, 'zw' )
3511
3512          IF ( check_existence( nest_offl%var_names, 'z' ) )  THEN
3513             ALLOCATE( nest_offl%zu_atmos(1:nest_offl%nzu) )
3514             CALL get_variable( id_dynamic, 'z', nest_offl%zu_atmos )
3515          ENDIF
3516          IF ( check_existence( nest_offl%var_names, 'zw' ) )  THEN
3517             ALLOCATE( nest_offl%zw_atmos(1:nest_offl%nzw) )
3518             CALL get_variable( id_dynamic, 'zw', nest_offl%zw_atmos )
3519          ENDIF
3520
3521!
3522!--       Read surface pressure
3523          IF ( check_existence( nest_offl%var_names,                           &
3524                                'surface_forcing_surface_pressure' ) )  THEN
3525             ALLOCATE( nest_offl%surface_pressure(0:nest_offl%nt-1) )
3526             CALL get_variable( id_dynamic,                                    &
3527                                'surface_forcing_surface_pressure',            &
3528                                nest_offl%surface_pressure )
3529          ENDIF
3530!
3531!--       Set control flag to indicate that initialization is already done
3532          nest_offl%init = .TRUE.
3533
3534       ENDIF
3535
3536!
3537!--    Obtain time index for current input starting at 0.
3538!--    @todo: At the moment INIFOR and simulated time correspond
3539!--           to each other. If required, adjust to daytime.
3540       nest_offl%tind = MINLOC( ABS( nest_offl%time -                          &
3541                                     time_since_reference_point ), DIM = 1 )   &
3542                        - 1
3543       nest_offl%tind_p = nest_offl%tind + 1       
3544!
3545!--    Read geostrophic wind components
3546       DO  t = nest_offl%tind, nest_offl%tind_p
3547          CALL get_variable_pr( id_dynamic, 'ls_forcing_ug', t+1,              &
3548                                nest_offl%ug(t-nest_offl%tind,nzb+1:nzt) )
3549          CALL get_variable_pr( id_dynamic, 'ls_forcing_vg', t+1,              &
3550                                nest_offl%vg(t-nest_offl%tind,nzb+1:nzt) )
3551       ENDDO
3552!
3553!--    Read data at lateral and top boundaries. Please note, at left and
3554!--    right domain boundary, yz-layers are read for u, v, w, pt and q.
3555!--    For the v-component, the data starts at nysv, while for the other
3556!--    quantities the data starts at nys. This is equivalent at the north
3557!--    and south domain boundary for the u-component.
3558!--    Further, lateral data is not accessed by parallel IO, indicated by the
3559!--    last passed flag in the subroutine get_variable(). This is because
3560!--    not every PE participates in this collective blocking read operation.
3561       IF ( bc_dirichlet_l )  THEN
3562          CALL get_variable( id_dynamic, 'ls_forcing_left_u',                  &
3563                           nest_offl%u_left(0:1,nzb+1:nzt,nys:nyn),            &
3564                           nys+1, nzb+1, nest_offl%tind+1,                     &
3565                           nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
3566     
3567          CALL get_variable( id_dynamic, 'ls_forcing_left_v',                  &
3568                           nest_offl%v_left(0:1,nzb+1:nzt,nysv:nyn),           &
3569                           nysv, nzb+1, nest_offl%tind+1,                      &
3570                           nyn-nysv+1, nest_offl%nzu, 2, .FALSE. )
3571
3572          CALL get_variable( id_dynamic, 'ls_forcing_left_w',                  &
3573                           nest_offl%w_left(0:1,nzb+1:nzt-1,nys:nyn),          &
3574                           nys+1, nzb+1, nest_offl%tind+1,                     &
3575                           nyn-nys+1, nest_offl%nzw, 2, .FALSE. )
3576
3577          IF ( .NOT. neutral )  THEN
3578             CALL get_variable( id_dynamic, 'ls_forcing_left_pt',              &
3579                           nest_offl%pt_left(0:1,nzb+1:nzt,nys:nyn),           &
3580                           nys+1, nzb+1, nest_offl%tind+1,                     &
3581                           nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
3582          ENDIF
3583
3584          IF ( humidity )  THEN
3585             CALL get_variable( id_dynamic, 'ls_forcing_left_qv',              &
3586                           nest_offl%q_left(0:1,nzb+1:nzt,nys:nyn),            &
3587                           nys+1, nzb+1, nest_offl%tind+1,                     &
3588                           nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
3589          ENDIF
3590         
3591          IF ( air_chemistry )  THEN
3592             DO  n = 1, UBOUND(nest_offl%var_names_chem_l, 1)
3593                IF ( check_existence( nest_offl%var_names,                     &
3594                                      nest_offl%var_names_chem_l(n) ) )        &
3595                THEN
3596                   CALL get_variable( id_dynamic,                              &
3597                              TRIM( nest_offl%var_names_chem_l(n) ),           &
3598                              nest_offl%chem_left(0:1,nzb+1:nzt,nys:nyn,n),    &
3599                              nys+1, nzb+1, nest_offl%tind+1,                  &
3600                              nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
3601                   nest_offl%chem_from_file_l(n) = .TRUE.
3602                ENDIF
3603             ENDDO
3604          ENDIF
3605
3606       ENDIF
3607
3608       IF ( bc_dirichlet_r )  THEN
3609          CALL get_variable( id_dynamic, 'ls_forcing_right_u',                 &
3610                           nest_offl%u_right(0:1,nzb+1:nzt,nys:nyn),           &
3611                           nys+1, nzb+1, nest_offl%tind+1,                     &
3612                           nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
3613                           
3614          CALL get_variable( id_dynamic, 'ls_forcing_right_v',                 &
3615                           nest_offl%v_right(0:1,nzb+1:nzt,nysv:nyn),          &
3616                           nysv, nzb+1, nest_offl%tind+1,                      &
3617                           nyn-nysv+1, nest_offl%nzu, 2, .FALSE. )
3618                           
3619          CALL get_variable( id_dynamic, 'ls_forcing_right_w',                 &
3620                           nest_offl%w_right(0:1,nzb+1:nzt-1,nys:nyn),         &
3621                           nys+1, nzb+1, nest_offl%tind+1,                     &
3622                           nyn-nys+1, nest_offl%nzw, 2, .FALSE. )
3623                           
3624          IF ( .NOT. neutral )  THEN
3625             CALL get_variable( id_dynamic, 'ls_forcing_right_pt',             &
3626                           nest_offl%pt_right(0:1,nzb+1:nzt,nys:nyn),          &
3627                           nys+1, nzb+1, nest_offl%tind+1,                     &
3628                           nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
3629          ENDIF
3630          IF ( humidity )  THEN
3631             CALL get_variable( id_dynamic, 'ls_forcing_right_qv',             &
3632                           nest_offl%q_right(0:1,nzb+1:nzt,nys:nyn),           &
3633                           nys+1, nzb+1, nest_offl%tind+1,                     &
3634                           nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
3635          ENDIF
3636         
3637          IF ( air_chemistry )  THEN
3638             DO  n = 1, UBOUND(nest_offl%var_names_chem_r, 1)
3639                IF ( check_existence( nest_offl%var_names,                     &
3640                                      nest_offl%var_names_chem_r(n) ) )        &
3641                THEN
3642                   CALL get_variable( id_dynamic,                              &
3643                              TRIM( nest_offl%var_names_chem_r(n) ),           &
3644                              nest_offl%chem_right(0:1,nzb+1:nzt,nys:nyn,n),   &
3645                              nys+1, nzb+1, nest_offl%tind+1,                  &
3646                              nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
3647                   nest_offl%chem_from_file_r(n) = .TRUE.
3648                ENDIF
3649             ENDDO
3650          ENDIF
3651       ENDIF
3652
3653       IF ( bc_dirichlet_n )  THEN
3654       
3655          CALL get_variable( id_dynamic, 'ls_forcing_north_u',                 &
3656                           nest_offl%u_north(0:1,nzb+1:nzt,nxlu:nxr),          &
3657                           nxlu, nzb+1, nest_offl%tind+1,                      &
3658                           nxr-nxlu+1, nest_offl%nzu, 2, .FALSE. )
3659                           
3660          CALL get_variable( id_dynamic, 'ls_forcing_north_v',                 &
3661                           nest_offl%v_north(0:1,nzb+1:nzt,nxl:nxr),           &
3662                           nxl+1, nzb+1, nest_offl%tind+1,                     &
3663                           nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
3664                           
3665          CALL get_variable( id_dynamic, 'ls_forcing_north_w',                 &
3666                           nest_offl%w_north(0:1,nzb+1:nzt-1,nxl:nxr),         &
3667                           nxl+1, nzb+1, nest_offl%tind+1,                     &
3668                           nxr-nxl+1, nest_offl%nzw, 2, .FALSE. )
3669                           
3670          IF ( .NOT. neutral )  THEN
3671             CALL get_variable( id_dynamic, 'ls_forcing_north_pt',             &
3672                           nest_offl%pt_north(0:1,nzb+1:nzt,nxl:nxr),          &
3673                           nxl+1, nzb+1, nest_offl%tind+1,                     &
3674                           nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
3675          ENDIF
3676          IF ( humidity )  THEN
3677             CALL get_variable( id_dynamic, 'ls_forcing_north_qv',             &
3678                           nest_offl%q_north(0:1,nzb+1:nzt,nxl:nxr),           &
3679                           nxl+1, nzb+1, nest_offl%tind+1,                     &
3680                           nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
3681          ENDIF
3682         
3683          IF ( air_chemistry )  THEN
3684             DO  n = 1, UBOUND(nest_offl%var_names_chem_n, 1)
3685                IF ( check_existence( nest_offl%var_names,                     &
3686                                      nest_offl%var_names_chem_n(n) ) )        &
3687                THEN
3688                   CALL get_variable( id_dynamic,                              &
3689                              TRIM( nest_offl%var_names_chem_n(n) ),           &
3690                              nest_offl%chem_north(0:1,nzb+1:nzt,nxl:nxr,n),   &
3691                              nxl+1, nzb+1, nest_offl%tind+1,                  &
3692                              nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
3693                   nest_offl%chem_from_file_n(n) = .TRUE.
3694                ENDIF
3695             ENDDO
3696          ENDIF
3697       ENDIF
3698
3699       IF ( bc_dirichlet_s )  THEN
3700          CALL get_variable( id_dynamic, 'ls_forcing_south_u',                 &
3701                           nest_offl%u_south(0:1,nzb+1:nzt,nxlu:nxr),          &
3702                           nxlu, nzb+1, nest_offl%tind+1,                      &
3703                           nxr-nxlu+1, nest_offl%nzu, 2, .FALSE. )
3704
3705          CALL get_variable( id_dynamic, 'ls_forcing_south_v',                 &
3706                           nest_offl%v_south(0:1,nzb+1:nzt,nxl:nxr),           &
3707                           nxl+1, nzb+1, nest_offl%tind+1,                     &
3708                           nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
3709                           
3710          CALL get_variable( id_dynamic, 'ls_forcing_south_w',                 &
3711                           nest_offl%w_south(0:1,nzb+1:nzt-1,nxl:nxr),         &
3712                           nxl+1, nzb+1, nest_offl%tind+1,                     &
3713                           nxr-nxl+1, nest_offl%nzw, 2, .FALSE. )
3714                           
3715          IF ( .NOT. neutral )  THEN
3716             CALL get_variable( id_dynamic, 'ls_forcing_south_pt',             &
3717                           nest_offl%pt_south(0:1,nzb+1:nzt,nxl:nxr),          &
3718                           nxl+1, nzb+1, nest_offl%tind+1,                     &
3719                           nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
3720          ENDIF
3721          IF ( humidity )  THEN
3722             CALL get_variable( id_dynamic, 'ls_forcing_south_qv',             &
3723                           nest_offl%q_south(0:1,nzb+1:nzt,nxl:nxr),           &
3724                           nxl+1, nzb+1, nest_offl%tind+1,                     &
3725                           nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
3726          ENDIF
3727         
3728          IF ( air_chemistry )  THEN
3729             DO  n = 1, UBOUND(nest_offl%var_names_chem_s, 1)
3730                IF ( check_existence( nest_offl%var_names,                     &
3731                                      nest_offl%var_names_chem_s(n) ) )        &
3732                THEN
3733                   CALL get_variable( id_dynamic,                              &
3734                              TRIM( nest_offl%var_names_chem_s(n) ),           &
3735                              nest_offl%chem_south(0:1,nzb+1:nzt,nxl:nxr,n),   &
3736                              nxl+1, nzb+1, nest_offl%tind+1,                  &
3737                              nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
3738                   nest_offl%chem_from_file_s(n) = .TRUE.
3739                ENDIF
3740             ENDDO
3741          ENDIF
3742       ENDIF
3743
3744!
3745!--    Top boundary
3746       CALL get_variable( id_dynamic, 'ls_forcing_top_u',                      &
3747                             nest_offl%u_top(0:1,nys:nyn,nxlu:nxr),            &
3748                             nxlu, nys+1, nest_offl%tind+1,                    &
3749                             nxr-nxlu+1, nyn-nys+1, 2, .TRUE. )
3750
3751       CALL get_variable( id_dynamic, 'ls_forcing_top_v',                      &
3752                             nest_offl%v_top(0:1,nysv:nyn,nxl:nxr),            &
3753                             nxl+1, nysv, nest_offl%tind+1,                    &
3754                             nxr-nxl+1, nyn-nysv+1, 2, .TRUE. )
3755                             
3756       CALL get_variable( id_dynamic, 'ls_forcing_top_w',                      &
3757                             nest_offl%w_top(0:1,nys:nyn,nxl:nxr),             &
3758                             nxl+1, nys+1, nest_offl%tind+1,                   &
3759                             nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
3760                             
3761       IF ( .NOT. neutral )  THEN
3762          CALL get_variable( id_dynamic, 'ls_forcing_top_pt',                  &
3763                                nest_offl%pt_top(0:1,nys:nyn,nxl:nxr),         &
3764                                nxl+1, nys+1, nest_offl%tind+1,                &
3765                                nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
3766       ENDIF
3767       IF ( humidity )  THEN
3768          CALL get_variable( id_dynamic, 'ls_forcing_top_qv',                  &
3769                                nest_offl%q_top(0:1,nys:nyn,nxl:nxr),          &
3770                                nxl+1, nys+1, nest_offl%tind+1,                &
3771                                nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
3772       ENDIF
3773       
3774       IF ( air_chemistry )  THEN
3775          DO  n = 1, UBOUND(nest_offl%var_names_chem_t, 1)
3776             IF ( check_existence( nest_offl%var_names,                     &
3777                                   nest_offl%var_names_chem_t(n) ) )  THEN     
3778                CALL get_variable( id_dynamic,                                 &
3779                              TRIM( nest_offl%var_names_chem_t(n) ),           &
3780                              nest_offl%chem_top(0:1,nys:nyn,nxl:nxr,n),       &
3781                              nxl+1, nys+1, nest_offl%tind+1,                  &
3782                              nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
3783                nest_offl%chem_from_file_t(n) = .TRUE.
3784             ENDIF
3785          ENDDO
3786       ENDIF
3787
3788!
3789!--    Close input file
3790       CALL close_input_file( id_dynamic )
3791#endif
3792!
3793!--    End of CPU measurement
3794       CALL cpu_log( log_point_s(86), 'NetCDF input forcing', 'stop' )
3795
3796    END SUBROUTINE netcdf_data_input_offline_nesting
3797
3798
3799!------------------------------------------------------------------------------!
3800! Description:
3801! ------------
3802!> Checks input file for consistency and minimum requirements.
3803!------------------------------------------------------------------------------!
3804    SUBROUTINE netcdf_data_input_check_dynamic
3805
3806       USE control_parameters,                                                 &
3807           ONLY:  initializing_actions, message_string, nesting_offline 
3808
3809       IMPLICIT NONE
3810
3811!
3812!--    In case of forcing, check whether dynamic input file is present
3813       IF ( .NOT. input_pids_dynamic  .AND.  nesting_offline  )  THEN
3814          message_string = 'nesting_offline = .TRUE. requires dynamic '  //    &
3815                            'input file ' //                                   &
3816                            TRIM( input_file_dynamic ) // TRIM( coupling_char )
3817          CALL message( 'netcdf_data_input_mod', 'PA0546', 1, 2, 0, 6, 0 )
3818       ENDIF
3819!
3820!--    Dynamic input file must also be present if initialization via inifor is
3821!--    prescribed.
3822       IF ( .NOT. input_pids_dynamic  .AND.                                    &
3823            TRIM( initializing_actions ) == 'inifor' )  THEN
3824          message_string = 'initializing_actions = inifor requires dynamic ' //&
3825                           'input file ' // TRIM( input_file_dynamic ) //      &
3826                           TRIM( coupling_char )
3827          CALL message( 'netcdf_data_input_mod', 'PA0547', 1, 2, 0, 6, 0 )
3828       ENDIF
3829
3830    END SUBROUTINE netcdf_data_input_check_dynamic
3831
3832!------------------------------------------------------------------------------!
3833! Description:
3834! ------------
3835!> Checks input file for consistency and minimum requirements.
3836!------------------------------------------------------------------------------!
3837    SUBROUTINE netcdf_data_input_check_static
3838
3839       USE arrays_3d,                                                          &
3840           ONLY:  zu
3841
3842       USE control_parameters,                                                 &
3843           ONLY:  land_surface, message_string, urban_surface
3844
3845       USE indices,                                                            &
3846           ONLY:  nxl, nxr, nyn, nys
3847
3848       IMPLICIT NONE
3849
3850       INTEGER(iwp) ::  i      !< loop index along x-direction
3851       INTEGER(iwp) ::  j      !< loop index along y-direction
3852       INTEGER(iwp) ::  n_surf !< number of different surface types at given location
3853
3854       LOGICAL      ::  check_passed !< flag indicating if a check passed
3855
3856!
3857!--    Return if no static input file is available
3858       IF ( .NOT. input_pids_static )  RETURN
3859!
3860!--    Check for correct dimension of surface_fractions, should run from 0-2.
3861       IF ( surface_fraction_f%from_file )  THEN
3862          IF ( surface_fraction_f%nf-1 > 2 )  THEN
3863             message_string = 'nsurface_fraction must not be larger than 3.' 
3864             CALL message( 'netcdf_data_input_mod', 'PA0580', 1, 2, 0, 6, 0 )
3865          ENDIF
3866       ENDIF
3867!
3868!--    Check orography for fill-values. For the moment, give an error message.
3869!--    More advanced methods, e.g. a nearest neighbor algorithm as used in GIS
3870!--    systems might be implemented later.
3871!--    Please note, if no terrain height is provided, it is set to 0.
3872       IF ( ANY( terrain_height_f%var == terrain_height_f%fill ) )  THEN
3873          message_string = 'NetCDF variable zt is not ' //                     &
3874                           'allowed to have missing data'
3875          CALL message( 'netcdf_data_input_mod', 'PA0550', 2, 2, myid, 6, 0 )
3876       ENDIF
3877!
3878!--    Check for negative terrain heights
3879       IF ( ANY( terrain_height_f%var < 0.0_wp ) )  THEN
3880          message_string = 'NetCDF variable zt is not ' //                     &
3881                           'allowed to have negative values'
3882          CALL message( 'netcdf_data_input_mod', 'PA0551', 2, 2, myid, 6, 0 )
3883       ENDIF
3884!
3885!--    If 3D buildings are read, check if building information is consistent
3886!--    to numeric grid.
3887       IF ( buildings_f%from_file )  THEN
3888          IF ( buildings_f%lod == 2 )  THEN
3889             IF ( buildings_f%nz > SIZE( zu ) )  THEN
3890                message_string = 'Reading 3D building data - too much ' //     &
3891                                 'data points along the vertical coordinate.'
3892                CALL message( 'netcdf_data_input_mod', 'PA0552', 2, 2, 0, 6, 0 )
3893             ENDIF
3894
3895             IF ( ANY( ABS( buildings_f%z(0:buildings_f%nz-1) -                &
3896                       zu(0:buildings_f%nz-1) ) > 1E-6_wp ) )  THEN
3897                message_string = 'Reading 3D building data - vertical ' //     &
3898                                 'coordinate do not match numeric grid.'
3899                CALL message( 'netcdf_data_input_mod', 'PA0553', 2, 2, myid, 6, 0 )
3900             ENDIF
3901          ENDIF
3902       ENDIF
3903
3904!
3905!--    Skip further checks concerning buildings and natural surface properties
3906!--    if no urban surface and land surface model are applied.
3907       IF (  .NOT. land_surface  .AND.  .NOT. urban_surface )  RETURN
3908!
3909!--    Check for minimum requirement of surface-classification data in case
3910!--    static input file is used.
3911       IF ( ( .NOT. vegetation_type_f%from_file  .OR.                          &
3912              .NOT. pavement_type_f%from_file    .OR.                          &
3913              .NOT. water_type_f%from_file       .OR.                          &
3914              .NOT. soil_type_f%from_file             ) .OR.                   &
3915             ( urban_surface  .AND.  .NOT. building_type_f%from_file ) )  THEN
3916          message_string = 'Minimum requirement for surface classification ' //&
3917                           'is not fulfilled. At least ' //                    &
3918                           'vegetation_type, pavement_type, ' //               &
3919                           'soil_type and water_type are '//                   &
3920                           'required. If urban-surface model is applied, ' //  &
3921                           'also building_type is required'
3922          CALL message( 'netcdf_data_input_mod', 'PA0554', 1, 2, 0, 6, 0 )
3923       ENDIF
3924!
3925!--    Check for general availability of input variables.
3926!--    If vegetation_type is 0 at any location, vegetation_pars as well as
3927!--    root_area_dens_s are required.
3928       IF ( vegetation_type_f%from_file )  THEN
3929          IF ( ANY( vegetation_type_f%var == 0 ) )  THEN
3930             IF ( .NOT. vegetation_pars_f%from_file )  THEN
3931                message_string = 'If vegetation_type = 0 at any location, ' // &
3932                                 'vegetation_pars is required'
3933                CALL message( 'netcdf_data_input_mod', 'PA0555', 2, 2, -1, 6, 0 )
3934             ENDIF
3935             IF ( .NOT. root_area_density_lsm_f%from_file )  THEN
3936                message_string = 'If vegetation_type = 0 at any location, ' // &
3937                                 'root_area_dens_s is required'
3938                CALL message( 'netcdf_data_input_mod', 'PA0556', 2, 2, myid, 6, 0 )
3939             ENDIF
3940          ENDIF
3941       ENDIF
3942!
3943!--    If soil_type is zero at any location, soil_pars is required.
3944       IF ( soil_type_f%from_file )  THEN
3945          check_passed = .TRUE.
3946          IF ( ALLOCATED( soil_type_f%var_2d ) )  THEN
3947             IF ( ANY( soil_type_f%var_2d == 0 ) )  THEN
3948                IF ( .NOT. soil_pars_f%from_file )  check_passed = .FALSE.
3949             ENDIF
3950          ELSE
3951             IF ( ANY( soil_type_f%var_3d == 0 ) )  THEN
3952                IF ( .NOT. soil_pars_f%from_file )  check_passed = .FALSE.
3953             ENDIF
3954          ENDIF
3955          IF ( .NOT. check_passed )  THEN
3956             message_string = 'If soil_type = 0 at any location, ' //          &
3957                              'soil_pars is required'
3958             CALL message( 'netcdf_data_input_mod', 'PA0557', 2, 2, myid, 6, 0 )
3959          ENDIF
3960       ENDIF
3961!
3962!--    Buildings require a type in case of urban-surface model.
3963       IF ( buildings_f%from_file  .AND.  .NOT. building_type_f%from_file  )  THEN
3964          message_string = 'If buildings are provided, also building_type ' // &
3965                           'is required'
3966          CALL message( 'netcdf_data_input_mod', 'PA0581', 2, 2, myid, 6, 0 )
3967       ENDIF
3968!
3969!--    Buildings require an ID.
3970       IF ( buildings_f%from_file  .AND.  .NOT. building_id_f%from_file  )  THEN
3971          message_string = 'If buildings are provided, also building_id ' //   &
3972                           'is required'
3973          CALL message( 'netcdf_data_input_mod', 'PA0582', 2, 2, myid, 6, 0 )
3974       ENDIF
3975!
3976!--    If building_type is zero at any location, building_pars is required.
3977       IF ( building_type_f%from_file )  THEN
3978          IF ( ANY( building_type_f%var == 0 ) )  THEN
3979             IF ( .NOT. building_pars_f%from_file )  THEN
3980                message_string = 'If building_type = 0 at any location, ' //   &
3981                                 'building_pars is required'
3982                CALL message( 'netcdf_data_input_mod', 'PA0558', 2, 2, myid, 6, 0 )
3983             ENDIF
3984          ENDIF
3985       ENDIF
3986!
3987!--    If building_type is provided, also building_id is needed (due to the
3988!--    filtering algorithm).
3989       IF ( building_type_f%from_file  .AND.  .NOT. building_id_f%from_file )  &
3990       THEN
3991          message_string = 'If building_type is provided, also building_id '// &
3992                           'is required'
3993          CALL message( 'netcdf_data_input_mod', 'PA0519', 2, 2, myid, 6, 0 )
3994       ENDIF       
3995!
3996!--    If albedo_type is zero at any location, albedo_pars is required.
3997       IF ( albedo_type_f%from_file )  THEN
3998          IF ( ANY( albedo_type_f%var == 0 ) )  THEN
3999             IF ( .NOT. albedo_pars_f%from_file )  THEN
4000                message_string = 'If albedo_type = 0 at any location, ' //     &
4001                                 'albedo_pars is required'
4002                CALL message( 'netcdf_data_input_mod', 'PA0559', 2, 2, myid, 6, 0 )
4003             ENDIF
4004          ENDIF
4005       ENDIF
4006!
4007!--    If pavement_type is zero at any location, pavement_pars is required.
4008       IF ( pavement_type_f%from_file )  THEN
4009          IF ( ANY( pavement_type_f%var == 0 ) )  THEN
4010             IF ( .NOT. pavement_pars_f%from_file )  THEN
4011                message_string = 'If pavement_type = 0 at any location, ' //   &
4012                                 'pavement_pars is required'
4013                CALL message( 'netcdf_data_input_mod', 'PA0560', 2, 2, myid, 6, 0 )
4014             ENDIF
4015          ENDIF
4016       ENDIF
4017!
4018!--    If pavement_type is zero at any location, also pavement_subsurface_pars
4019!--    is required.
4020       IF ( pavement_type_f%from_file )  THEN
4021          IF ( ANY( pavement_type_f%var == 0 ) )  THEN
4022             IF ( .NOT. pavement_subsurface_pars_f%from_file )  THEN
4023                message_string = 'If pavement_type = 0 at any location, ' //   &
4024                                 'pavement_subsurface_pars is required'
4025                CALL message( 'netcdf_data_input_mod', 'PA0561', 2, 2, myid, 6, 0 )
4026             ENDIF
4027          ENDIF
4028       ENDIF
4029!
4030!--    If water_type is zero at any location, water_pars is required.
4031       IF ( water_type_f%from_file )  THEN
4032          IF ( ANY( water_type_f%var == 0 ) )  THEN
4033             IF ( .NOT. water_pars_f%from_file )  THEN
4034                message_string = 'If water_type = 0 at any location, ' //      &
4035                                 'water_pars is required'
4036                CALL message( 'netcdf_data_input_mod', 'PA0562', 2, 2,myid, 6, 0 )
4037             ENDIF
4038          ENDIF
4039       ENDIF
4040!
4041!--    Check for local consistency of the input data.
4042       DO  i = nxl, nxr
4043          DO  j = nys, nyn
4044!
4045!--          For each (y,x)-location at least one of the parameters
4046!--          vegetation_type, pavement_type, building_type, or water_type
4047!--          must be set to a non­missing value.
4048             IF ( land_surface  .AND.  .NOT. urban_surface )  THEN
4049                IF ( vegetation_type_f%var(j,i) == vegetation_type_f%fill  .AND.&
4050                     pavement_type_f%var(j,i)   == pavement_type_f%fill    .AND.&
4051                     water_type_f%var(j,i)      == water_type_f%fill )  THEN
4052                   WRITE( message_string, * )                                  &
4053                                    'At least one of the parameters '//        &
4054                                    'vegetation_type, pavement_type, '     //  &
4055                                    'or water_type must be set '//             &
4056                                    'to a non-missing value. Grid point: ', j, i
4057                   CALL message( 'netcdf_data_input_mod', 'PA0563', 2, 2, myid, 6, 0 )
4058                ENDIF
4059             ELSEIF ( land_surface  .AND.  urban_surface )  THEN
4060                IF ( vegetation_type_f%var(j,i) == vegetation_type_f%fill  .AND.&
4061                     pavement_type_f%var(j,i)   == pavement_type_f%fill    .AND.&
4062                     building_type_f%var(j,i)   == building_type_f%fill    .AND.&
4063                     water_type_f%var(j,i)      == water_type_f%fill )  THEN
4064                   WRITE( message_string, * )                                  &
4065                                 'At least one of the parameters '//           &
4066                                 'vegetation_type, pavement_type, '  //        &
4067                                 'building_type, or water_type must be set '// &
4068                                 'to a non-missing value. Grid point: ', j, i
4069                   CALL message( 'netcdf_data_input_mod', 'PA0563', 2, 2, myid, 6, 0 )
4070                ENDIF
4071             ENDIF
4072               
4073!
4074!--          Note that a soil_type is required for each location (y,x) where
4075!--          either vegetation_type or pavement_type is a non­missing value.
4076             IF ( ( vegetation_type_f%var(j,i) /= vegetation_type_f%fill  .OR. &
4077                    pavement_type_f%var(j,i)   /= pavement_type_f%fill ) )  THEN
4078                check_passed = .TRUE.
4079                IF ( ALLOCATED( soil_type_f%var_2d ) )  THEN
4080                   IF ( soil_type_f%var_2d(j,i) == soil_type_f%fill )          &
4081                      check_passed = .FALSE.
4082                ELSE
4083                   IF ( ANY( soil_type_f%var_3d(:,j,i) == soil_type_f%fill) )  &
4084                      check_passed = .FALSE.
4085                ENDIF
4086
4087                IF ( .NOT. check_passed )  THEN
4088                   message_string = 'soil_type is required for each '//        &
4089                                 'location (y,x) where vegetation_type or ' // &
4090                                 'pavement_type is a non-missing value.'
4091                   CALL message( 'netcdf_data_input_mod', 'PA0564',            &
4092                                  2, 2, myid, 6, 0 )
4093                ENDIF
4094             ENDIF
4095!
4096!--          Check for consistency of surface fraction. If more than one type
4097!--          is set, surface fraction need to be given and the sum must not
4098!--          be larger than 1.
4099             n_surf = 0
4100             IF ( vegetation_type_f%var(j,i) /= vegetation_type_f%fill )       &
4101                n_surf = n_surf + 1
4102             IF ( water_type_f%var(j,i)      /= water_type_f%fill )            &
4103                n_surf = n_surf + 1
4104             IF ( pavement_type_f%var(j,i)   /= pavement_type_f%fill )         &
4105                n_surf = n_surf + 1
4106
4107             IF ( n_surf > 1 )  THEN
4108                IF ( .NOT. surface_fraction_f%from_file )  THEN
4109                   message_string = 'If more than one surface type is ' //     &
4110                                 'given at a location, surface_fraction ' //   &
4111                                 'must be provided.'
4112                   CALL message( 'netcdf_data_input_mod', 'PA0565',            &
4113                                  2, 2, myid, 6, 0 )
4114                ELSEIF ( ANY ( surface_fraction_f%frac(:,j,i) ==               &
4115                               surface_fraction_f%fill ) )  THEN
4116                   message_string = 'If more than one surface type is ' //     &
4117                                 'given at a location, surface_fraction ' //   &
4118                                 'must be provided.'
4119                   CALL message( 'netcdf_data_input_mod', 'PA0565',            &
4120                                  2, 2, myid, 6, 0 )
4121                ENDIF
4122             ENDIF
4123!
4124!--          Check for further mismatches. e.g. relative fractions exceed 1 or
4125!--          vegetation_type is set but surface vegetation fraction is zero,
4126!--          etc..
4127             IF ( surface_fraction_f%from_file )  THEN
4128!
4129!--             Sum of relative fractions must not exceed 1.
4130                IF ( SUM ( surface_fraction_f%frac(0:2,j,i) ) > 1.0_wp )  THEN
4131                   message_string = 'surface_fraction must not exceed 1'
4132                   CALL message( 'netcdf_data_input_mod', 'PA0566',            &
4133                                  2, 2, myid, 6, 0 )
4134                ENDIF
4135!
4136!--             Relative fraction for a type must not be zero at locations where
4137!--             this type is set.
4138                IF (                                                           &
4139                  ( vegetation_type_f%var(j,i) /= vegetation_type_f%fill  .AND.&
4140                 ( surface_fraction_f%frac(ind_veg_wall,j,i) == 0.0_wp .OR.    &
4141                   surface_fraction_f%frac(ind_veg_wall,j,i) ==                &
4142                                                     surface_fraction_f%fill ) &
4143                  )  .OR.                                                      &
4144                  ( pavement_type_f%var(j,i) /= pavement_type_f%fill     .AND. &
4145                 ( surface_fraction_f%frac(ind_pav_green,j,i) == 0.0_wp .OR.   &
4146                   surface_fraction_f%frac(ind_pav_green,j,i) ==               &
4147                                                     surface_fraction_f%fill ) &
4148                  )  .OR.                                                      &
4149                  ( water_type_f%var(j,i) /= water_type_f%fill           .AND. &
4150                 ( surface_fraction_f%frac(ind_wat_win,j,i) == 0.0_wp .OR.     &
4151                   surface_fraction_f%frac(ind_wat_win,j,i) ==                 &
4152                                                     surface_fraction_f%fill ) &
4153                  ) )  THEN
4154                   WRITE( message_string, * ) 'Mismatch in setting of '     // &
4155                             'surface_fraction. Vegetation-, pavement-, or '// &
4156                             'water surface is given at (i,j) = ( ', i, j,     &
4157                             ' ), but surface fraction is 0 for the given type.'
4158                   CALL message( 'netcdf_data_input_mod', 'PA0567',            &
4159                                  2, 2, myid, 6, 0 )
4160                ENDIF
4161!
4162!--             Relative fraction for a type must not contain non-zero values
4163!--             if this type is not set.
4164                IF (                                                           &
4165                  ( vegetation_type_f%var(j,i) == vegetation_type_f%fill  .AND.&
4166                 ( surface_fraction_f%frac(ind_veg_wall,j,i) /= 0.0_wp .AND.   &
4167                   surface_fraction_f%frac(ind_veg_wall,j,i) /=                &
4168                                                     surface_fraction_f%fill ) &
4169                  )  .OR.                                                      &
4170                  ( pavement_type_f%var(j,i) == pavement_type_f%fill     .AND. &
4171                 ( surface_fraction_f%frac(ind_pav_green,j,i) /= 0.0_wp .AND.  &
4172                   surface_fraction_f%frac(ind_pav_green,j,i) /=               &
4173                                                     surface_fraction_f%fill ) &
4174                  )  .OR.                                                      &
4175                  ( water_type_f%var(j,i) == water_type_f%fill           .AND. &
4176                 ( surface_fraction_f%frac(ind_wat_win,j,i) /= 0.0_wp .AND.    &
4177                   surface_fraction_f%frac(ind_wat_win,j,i) /=                 &
4178                                                     surface_fraction_f%fill ) &
4179                  ) )  THEN
4180                   WRITE( message_string, * ) 'Mismatch in setting of '     // &
4181                             'surface_fraction. Vegetation-, pavement-, or '// &
4182                             'water surface is not given at (i,j) = ( ', i, j, &
4183                             ' ), but surface fraction is not 0 for the ' //   &
4184                             'given type.'
4185                   CALL message( 'netcdf_data_input_mod', 'PA0568',            &
4186                                  2, 2, myid, 6, 0 )
4187                ENDIF
4188             ENDIF
4189!
4190!--          Check vegetation_pars. If vegetation_type is 0, all parameters
4191!--          need to be set, otherwise, single parameters set by
4192!--          vegetation_type can be overwritten.
4193             IF ( vegetation_type_f%from_file )  THEN
4194                IF ( vegetation_type_f%var(j,i) == 0 )  THEN
4195                   IF ( ANY( vegetation_pars_f%pars_xy(:,j,i) ==               &
4196                             vegetation_pars_f%fill ) )  THEN
4197                      message_string = 'If vegetation_type(y,x) = 0, all '  // &
4198                                       'parameters of vegetation_pars at '//   &
4199                                       'this location must be set.'
4200                      CALL message( 'netcdf_data_input_mod', 'PA0569',         &
4201                                     2, 2, myid, 6, 0 )
4202                   ENDIF
4203                ENDIF
4204             ENDIF
4205!
4206!--          Check root distribution. If vegetation_type is 0, all levels must
4207!--          be set.
4208             IF ( vegetation_type_f%from_file )  THEN
4209                IF ( vegetation_type_f%var(j,i) == 0 )  THEN
4210                   IF ( ANY( root_area_density_lsm_f%var(:,j,i) ==             &
4211                             root_area_density_lsm_f%fill ) )  THEN
4212                      message_string = 'If vegetation_type(y,x) = 0, all ' //  &
4213                                       'levels of root_area_dens_s ' //        &
4214                                       'must be set at this location.'
4215                      CALL message( 'netcdf_data_input_mod', 'PA0570',         &
4216                                     2, 2, myid, 6, 0 )
4217                   ENDIF
4218                ENDIF
4219             ENDIF
4220!
4221!--          Check soil parameters. If soil_type is 0, all parameters
4222!--          must be set.
4223             IF ( soil_type_f%from_file )  THEN
4224                check_passed = .TRUE.
4225                IF ( ALLOCATED( soil_type_f%var_2d ) )  THEN
4226                   IF ( soil_type_f%var_2d(j,i) == 0 )  THEN
4227                      IF ( ANY( soil_pars_f%pars_xy(:,j,i) ==                  &
4228                                soil_pars_f%fill ) )  check_passed = .FALSE.
4229                   ENDIF
4230                ELSE
4231                   IF ( ANY( soil_type_f%var_3d(:,j,i) == 0 ) )  THEN
4232                      IF ( ANY( soil_pars_f%pars_xy(:,j,i) ==                  &
4233                                soil_pars_f%fill ) )  check_passed = .FALSE.
4234                   ENDIF
4235                ENDIF
4236                IF ( .NOT. check_passed )  THEN
4237                   message_string = 'If soil_type(y,x) = 0, all levels of '  //&
4238                                    'soil_pars at this location must be set.'
4239                   CALL message( 'netcdf_data_input_mod', 'PA0571',            &
4240                                  2, 2, myid, 6, 0 )
4241                ENDIF
4242             ENDIF
4243
4244!
4245!--          Check building parameters. If building_type is 0, all parameters
4246!--          must be set.
4247             IF ( building_type_f%from_file )  THEN
4248                IF ( building_type_f%var(j,i) == 0 )  THEN
4249                   IF ( ANY( building_pars_f%pars_xy(:,j,i) ==                 &
4250                             building_pars_f%fill ) )  THEN
4251                      message_string = 'If building_type(y,x) = 0, all ' //    &
4252                                       'parameters of building_pars at this '//&
4253                                       'location must be set.'
4254                      CALL message( 'netcdf_data_input_mod', 'PA0572',         &
4255                                     2, 2, myid, 6, 0 )
4256                   ENDIF
4257                ENDIF
4258             ENDIF
4259!
4260!--          Check if building_type is set at each building and vice versa.
4261!              IF ( building_type_f%from_file  .AND.  buildings_f%from_file )  THEN
4262!                 IF ( buildings_f%lod == 1 )  THEN
4263!                    IF ( buildings_f%var_2d(j,i)  /= buildings_f%fill1  .AND.   &
4264!                         building_type_f%var(j,i) == building_type_f%fill  .OR. &
4265!                         buildings_f%var_2d(j,i)  == buildings_f%fill1  .AND.   &
4266!                         building_type_f%var(j,i) /= building_type_f%fill )  THEN
4267!                       WRITE( message_string, * ) 'Each location where a ' //   &
4268!                                       '2D building is set requires a type ' // &
4269!                                       '( and vice versa ) in case the ' //     &
4270!                                       'urban-surface model is applied. ' //    &
4271!                                       'i, j = ', i, j
4272!                       CALL message( 'netcdf_data_input_mod', 'PA0573',         &
4273!                                      2, 2, myid, 6, 0 )
4274!                    ENDIF
4275!                 ENDIF
4276!                 IF ( buildings_f%lod == 2 )  THEN
4277!                    IF ( ANY( buildings_f%var_3d(:,j,i) == 1 )  .AND.           &
4278!                         building_type_f%var(j,i) == building_type_f%fill  .OR. &
4279!                   .NOT. ANY( buildings_f%var_3d(:,j,i) == 1 )  .AND.           &
4280!                         building_type_f%var(j,i) /= building_type_f%fill )  THEN
4281!                       WRITE( message_string, * ) 'Each location where a ' //   &
4282!                                       '3D building is set requires a type ' // &
4283!                                       '( and vice versa ) in case the ' //     &
4284!                                       'urban-surface model is applied. ' //    &
4285!                                       'i, j = ', i, j
4286!                       CALL message( 'netcdf_data_input_mod', 'PA0573',         &
4287!                                      2, 2, myid, 6, 0 )
4288!                    ENDIF
4289!                 ENDIF
4290!              ENDIF
4291!
4292!--          Check if at each location where a building is present also an ID
4293!--          is set and vice versa.
4294!              IF ( buildings_f%from_file )  THEN
4295!                 IF ( buildings_f%lod == 1 )  THEN
4296!                    IF ( buildings_f%var_2d(j,i) /= buildings_f%fill1  .AND.    &
4297!                         building_id_f%var(j,i)  == building_id_f%fill  .OR.    &
4298!                         buildings_f%var_2d(j,i) == buildings_f%fill1  .AND.    &
4299!                         building_id_f%var(j,i)  /= building_id_f%fill )  THEN
4300!                       WRITE( message_string, * ) 'Each location where a ' //   &
4301!                                       '2D building is set requires an ID ' //  &
4302!                                       '( and vice versa ). i, j = ', i, j
4303!                       CALL message( 'netcdf_data_input_mod', 'PA0574',         &
4304!                                      2, 2, myid, 6, 0 )
4305!                    ENDIF
4306!                 ELSEIF ( buildings_f%lod == 2 )  THEN
4307!                    IF ( ANY( buildings_f%var_3d(:,j,i) == 1 )  .AND.           &
4308!                         building_id_f%var(j,i) == building_id_f%fill  .OR.     &
4309!                   .NOT. ANY( buildings_f%var_3d(:,j,i) == 1 )  .AND.           &
4310!                         building_id_f%var(j,i) /= building_id_f%fill )  THEN
4311!                       WRITE( message_string, * ) 'Each location where a ' //   &
4312!                                       '3D building is set requires an ID ' //  &
4313!                                       '( and vice versa ). i, j = ', i, j
4314!                       CALL message( 'netcdf_data_input_mod', 'PA0574',         &
4315!                                      2, 2, myid, 6, 0 )
4316!                    ENDIF
4317!                 ENDIF
4318!              ENDIF
4319!
4320<