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

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

Additional checks for surface_fractions and building_id; Remove redundant subroutine argument in surface_mod

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