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

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

Read information from statitic driver for resolved vegetation independently from land- or urban-surface model

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