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

Last change on this file since 4100 was 4100, checked in by forkel, 4 years ago

Made check for input_pids_dynamic and inifor more general

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