gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
gdncvaropen.f90 File Reference

Open a netCDF variable. More...

Go to the source code of this file.

Functions/Subroutines

recursive subroutine gdncvaropen (var, url, writable, err)

Detailed Description

Open a netCDF variable.

Author
Yasuhiro MORIKAWA, Eizi TOYODA

These subroutines and functions are provided through gtdata_netcdf_generic.

Definition in file gdncvaropen.f90.

Function/Subroutine Documentation

◆ gdncvaropen()

recursive subroutine gdncvaropen ( type(gd_nc_variable), intent(out) var,
character(len = *), intent(in) url,
logical, intent(in), optional writable,
logical, intent(out), optional err )

Open a variable from URL

Opens a netCDF variable specified by URL. If the variable name is empty in the URL, the first non-dimension variable is opened.

Parameters
[out]varOpened variable handle
[in]urlVariable URL
[in]writableOpen for writing (optional)
[out]errError flag (optional)

Definition at line 40 of file gdncvaropen.f90.

41 use dc_types, only: string
45 use dc_url, only: urlsplit
46 use dc_error, only: storeerror
47 use dc_trace, only: beginsub, endsub
48 use netcdf, only: nf90_noerr, nf90_max_name, nf90_enotvar, nf90_ebaddim, &
49 & nf90_inq_varid, nf90_inq_dimid, nf90_inquire_variable, nf90_inquire
50 implicit none
51 type(GD_NC_VARIABLE), intent(out):: var
52 character(len = *), intent(in):: url
53 logical, intent(in), optional:: writable
54 logical, intent(out), optional:: err
55 character(len = STRING):: filename, varname
56 character(len = NF90_MAX_NAME):: dimname
57 integer:: stat, nvars, i
58 type(GD_NC_VARIABLE_SEARCH):: e
59 character(len = *), parameter:: subname = 'GDNcVarOpen'
60continue
61 call beginsub(subname)
62 call urlsplit(url, file=filename, var=varname)
63 if (filename == "") filename = "gtool.nc"
64 call gdncfileopen(e%fileid, trim(filename), stat=stat, writable=writable, err=err )
65 if (stat /= 0) goto 999
66 !
67 ! 名前から変数を探し出す
68 !
69 if (varname /= '') then
70 e%varid = 0
71 stat = nf90_inq_varid(e%fileid, trim(varname), e%varid)
72 if (stat == nf90_enotvar) then
73 e%varid = 0
74 stat = nf90_noerr
75 endif
76 else
77 ! 名前が空ならできれば次元変数でない最初の変数をとりだす
78 stat = nf90_inquire(e%fileid, nvariables = nvars)
79 if (stat /= 0) goto 999
80 e%varid = 1
81 do, i = 1, nvars
82 stat = nf90_inquire_variable(e%fileid, i, name = dimname)
83 if (stat /= nf90_noerr) goto 999
84 stat = nf90_inq_dimid(e%fileid, dimname, e%dimid)
85 if (stat == nf90_noerr) cycle
86 if (stat /= nf90_ebaddim) goto 999
87 e%varid = i
88 stat = nf90_noerr
89 exit
90 enddo
91 endif
92 if (stat /= nf90_noerr) goto 999
93 !
94 ! 次元id を調べる
95 !
96 stat = nf90_inq_dimid(e%fileid, trim(varname), e%dimid)
97 if (stat /= nf90_noerr) then
98 if (e%varid <= 0) goto 999
99 e%dimid = 0
100 endif
101 !
102 stat = vtable_add(var, e)
103 if (stat /= nf90_noerr) goto 999
104 call endsub(subname, 'an=%d file=%d var=%d', i=(/var%id, e%fileid, e%varid/))
105 call storeerror(stat, subname, err)
106 return
107 !
108 ! エラー処理 (正常完了時も呼ぶ)
109 !
110999 continue
111 var = gd_nc_variable(-1)
112 call endsub(subname, 'an=%d err', i=(/var%id/))
113 call storeerror(stat, subname, err, cause_c=url)
Error handling module.
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
Debug tracing module.
Definition dc_trace.f90:150
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
Definition dc_trace.f90:476
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:599
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public string
Character length for string
Definition dc_types.f90:137
Variable URL string parser.
Definition dc_url.f90:61
integer function, public vtable_add(var, entry)

References dc_trace::beginsub(), dc_trace::endsub(), dc_error::storeerror(), dc_types::string, and gtdata_netcdf_internal::vtable_add().

Here is the call graph for this function: