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

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

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