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

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

add longitude and latitude to output files; update run_control files for tests

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