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

Last change on this file since 3474 was 3474, checked in by kanani, 6 years ago

Add netcdf input for uv exposure model (netcdf_data_input_mod, Makefile, .palm.iofiles), plus bugfixes (uv_exposure_model_mod)

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