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

Last change on this file since 3976 was 3976, checked in by hellstea, 5 years ago

Child initialization extended to the redundant ghost points behind the nest boundaries

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