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

Last change on this file since 2772 was 2772, checked in by suehring, 7 years ago

Enable initialization via inifor without running land-surface model; small bugfix in chemistry model string treatment

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