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

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

changes for commit 3209 documented

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