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

Last change on this file since 3529 was 3529, checked in by gronemeier, 6 years ago

change date format in output files; add global attributes; change fill_value; move definition of UTM and lon/lat into subroutine; change attributes of time variable; read optional attributes from input netcdf file; update test cases

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