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

Last change on this file since 3026 was 3019, checked in by maronga, 6 years ago

disabled suspicious MPI_BARRIER, speed-up of NetCDF input

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