source: palm/trunk/UTIL/inifor/src/get_netcdf_variable.inc @ 3182

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

New Inifor features: grid stretching, improved command-interface, support start dates in different formats in both YYYYMMDD and YYYYMMDDHH, Ability to manually control input file prefixes (--radiation-prefix, --soil-preifx, --flow-prefix, --soilmoisture-prefix) for compatiblity with DWD forcast naming scheme; GNU-style short and long option; Prepared output of large-scale forcing profiles (no computation yet); Added preprocessor flag netcdf4 to switch output format between netCDF 3 and 4; Updated netCDF variable names and attributes to comply with PIDS v1.9; Inifor bugfixes: Improved compatibility with older Intel Intel compilers by avoiding implicit array allocation; Added origin_lon/_lat values and correct reference time in dynamic driver global attributes; corresponding PALM changes: adjustments to revised Inifor; variables names in dynamic driver adjusted; enable geostrophic forcing also in offline nested mode; variable names in LES-LES and COSMO offline nesting changed; lateral boundary flags for nesting, in- and outflow conditions renamed

File size: 4.1 KB
RevLine 
[3182]1!> @file src/get_netcdf_variable.inc
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 2017-2018 Leibniz Universitaet Hannover
18! Copyright 2017-2018 Deutscher Wetterdienst Offenbach
19!------------------------------------------------------------------------------!
20!
21! Current revisions:
22! -----------------
23! Initial revision
24!
25!
26! Former revisions:
27! -----------------
28! $Id$
29!
30!
31!
32! Authors:
33! --------
34! @author Eckhard Kadasch
35!
36! Description:
37! ------------
38!> This file provides the implementation of the io.f90 subroutines
39!> get_netcdf_variable_int() and get_netcdf_variable_real(). Both routines
40!> differ only in the type of the netCDF variable to be read and otherwise share
41!> their functionality. In order to avoid duplicating code, both routines source
42!> the implementation below using Fortran's INCLUDE statement.
43!>
44!------------------------------------------------------------------------------!
45 INTEGER ::  i, ncid, start(3)
46
47 ! Read in_var NetCDF attributes
48 IF ( nf90_open( TRIM(in_file), NF90_NOWRITE, ncid ) .EQ. NF90_NOERR .AND. &
49      nf90_inq_varid( ncid, in_var % name, in_var % varid ) .EQ. NF90_NOERR )  THEN
50
51    CALL check(nf90_get_att(ncid, in_var % varid, "long_name", in_var % long_name))
52    CALL check(nf90_get_att(ncid, in_var % varid, "units", in_var % units))
53
54    ! Read in_var NetCDF dimensions
55    CALL check(nf90_inquire_variable( ncid, in_var % varid,              &
56                                      ndims  = in_var % ndim,            &
57                                      dimids = in_var % dimids ))
58                                 
59    DO i = 1, in_var % ndim
60       CALL check(nf90_inquire_dimension( ncid, in_var % dimids(i),      &
61                                          name = in_var % dimname(i),    &
62                                          len  = in_var % dimlen(i) ))
63    END DO
64
65    start = (/ 1, 1, 1 /)
66    IF ( TRIM(in_var % name) .EQ. 'T_SO' )  THEN
67       ! Skip depth = 0.0 for T_SO and reduce number of depths from 9 to 8
68       in_var % dimlen(3) = in_var % dimlen(3) - 1
69
70       ! Start reading from second level, e.g. depth = 0.005 instead of 0.0
71       start(3) = 2
72    END IF
73
74    SELECT CASE(in_var % ndim)
75
76    CASE (2)
77
78       ALLOCATE( buffer( in_var % dimlen(1),                             &
79                         in_var % dimlen(2),                             &
80                         1 ) )
81
82    CASE (3, 4)
83
84       ALLOCATE( buffer( in_var % dimlen(1),                             &
85                         in_var % dimlen(2),                             &
86                         in_var % dimlen(3) ) )
87
88    CASE DEFAULT
89
90       message = "Failed reading NetCDF variable " //                    &
91          TRIM(in_var % name) // " with " // TRIM(str(in_var%ndim)) //   &
92          " dimensions because only two- and and three-dimensional" //   &
93          " variables are supported."
94       CALL abort('get_netcdf_variable', message)
95
96    END SELECT
97 CALL run_control('time', 'alloc')
98         
99    ! TODO: Check for matching dimensions of buffer and var
100    CALL check(nf90_get_var( ncid, in_var % varid, buffer,               &
101                             start = start,                              &
102                             count = in_var % dimlen(1:3) ) )
103
104 CALL run_control('time', 'read')
105 ELSE
106
107    message = "Failed to read '" // TRIM(in_var % name) // &
108       "' from file '" // TRIM(in_file) // "'."
109    CALL report('get_netcdf_variable', message)
110
111 END IF
112
113 CALL check(nf90_close(ncid))
114
115 CALL run_control('time', 'read')
Note: See TracBrowser for help on using the repository browser.