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

Last change on this file since 3553 was 3553, checked in by suehring, 6 years ago

last commit documented

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