23 use dc_trace, only: beginsub, endsub, dbgmessage
24 use netcdf, only: nf90_noerr, nf90_max_name, &
25 & nf90_inquire_variable, nf90_inquire_dimension, nf90_inquire
26 implicit none
27 type(GD_NC_VARIABLE), intent(in):: var
28 integer, intent(out), optional:: ndims
29
30 integer, intent(out), optional:: dimlen
31
32 logical, intent(out), optional:: growable
33
34 character(*), intent(out), optional:: name
35
36 character(*), intent(out), optional:: url
37
38 character(*), intent(out), optional:: xtype
39
40
41
42 type(GD_NC_VARIABLE_ENTRY):: ent
43 integer:: stat, length, i, i_xtype, idim_growable
44 character(len = *), parameter:: subname = 'GDNcVarInquire'
45 character(len = NF90_MAX_NAME):: buffer
46 character(len = NF90_MAX_NAME):: fbuffer
47continue
48 call beginsub(subname, 'var.id=%d', i=(/var%id/))
49
50
51 if (present(ndims)) ndims = -1
52 if (present(dimlen)) dimlen = -1
53
54
56 if (stat /= nf90_noerr) then
57 call endsub(subname, 'var not found')
58 return
59 endif
60
61
62
63 if (present(ndims)) then
64 if (associated(ent%dimids)) then
65 ndims = size(ent%dimids)
66 else
67 ndims = 0
68 endif
69 endif
70
71 if (present(dimlen)) then
72 dimlen = 1
73 if (ent%dimid > 0) then
74
75 stat = nf90_inquire_dimension(ent%fileid, ent%dimid, len = dimlen)
76 if (stat /= nf90_noerr) then
77 dimlen = -1
78 call endsub(subname, 'dimlen err')
79 return
80 endif
81 else
82
83 if (associated(ent%dimids)) then
84 do, i = 1, size(ent%dimids)
85 stat = nf90_inquire_dimension(ent%fileid, ent%dimids(i), len = length)
86 if (stat /= nf90_noerr) then
87 dimlen = -1
88 exit
89 endif
90 dimlen = dimlen * length
91 enddo
92 endif
93 endif
94 endif
95
96 if (present(xtype)) then
97 stat = nf90_inquire_variable(ent%fileid, ent%varid, xtype=i_xtype)
98 if (stat /= nf90_noerr) i_xtype = 0
100 endif
101
102 if (present(name)) then
104 name = buffer
105 endif
106
107 if (present(url)) then
109 call dbgmessage('ent%%fileid=%d', i=(/ent%fileid/))
111 url = trim(fbuffer) // '?' // buffer
112 endif
113
114 if (present(growable)) then
115 growable = .false.
117 if (stat /= nf90_noerr) return
118 stat = nf90_inquire(ent%fileid, unlimiteddimid = idim_growable)
119 if (stat /= nf90_noerr) return
120
121 if (ent%varid > 0) then
122 if (.not. associated(ent%dimids)) return
123 do, i = 1, size(ent%dimids)
124 if (ent%dimids(i) == idim_growable) growable = .true.
125 enddo
126 else
127 growable = (ent%dimid == idim_growable)
128 endif
129 endif
130
131
132 call endsub(subname, 'ok')
133 return
134
135contains
136
138 use netcdf, only: &
139 & nf90_inquire_dimension, nf90_inquire_variable, nf90_noerr
140 type(GD_NC_VARIABLE_ENTRY), intent(in):: ent
141 character(len = *), intent(out):: varname
142 if (ent%dimid > 0) then
143 stat = nf90_inquire_dimension(ent%fileid, ent%dimid, name = varname)
144 else
145 stat = nf90_inquire_variable(ent%fileid, ent%varid, name = varname)
146 endif
147 if (stat /= nf90_noerr) varname = ""
149
subroutine local_getname(ent, varname)
integer function, public vtable_lookup(var, entry)