gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
gdncvarinquire.f90 File Reference

変数または属性に関する問い合わせ More...

Go to the source code of this file.

Functions/Subroutines

subroutine gdncvarinquire (var, ndims, dimlen, growable, name, url, xtype)
subroutine local_getname (ent, varname)

Detailed Description

変数または属性に関する問い合わせ

Author
Eizi TOYODA, Yasuhiro MORIKAWA

これらのサブルーチン、関数は gtdata_netcdf_generic から gtdata_netcdf_generic#Inquire として提供されます。

Definition in file gdncvarinquire.f90.

Function/Subroutine Documentation

◆ gdncvarinquire()

subroutine gdncvarinquire ( type(gd_nc_variable), intent(in) var,
integer, intent(out), optional ndims,
integer, intent(out), optional dimlen,
logical, intent(out), optional growable,
character(*), intent(out), optional name,
character(*), intent(out), optional url,
character(*), intent(out), optional xtype )

変数情報を問い合わせ

変数に関する様々な情報を取得します。各出力引数は省略可能で、 与えられた場合のみ計算されます。

Parameters
[in]var変数ハンドル
[out]ndims次元数 (省略可能)
[out]dimlen全次元長 (省略可能)
[out]growable無制限次元を持つか (省略可能)
[out]name変数名 (省略可能)
[out]urlファイル名を含む完全 URL (省略可能)
[out]xtype型名 (省略可能)

Definition at line 51 of file gdncvarinquire.f90.

57 use netcdf, only: nf90_noerr, nf90_max_name, &
58 & nf90_inquire_variable, nf90_inquire_dimension, nf90_inquire
59 implicit none
60 type(GD_NC_VARIABLE), intent(in):: var
61 integer, intent(out), optional:: ndims
62 integer, intent(out), optional:: dimlen
63 logical, intent(out), optional:: growable
64 character(*), intent(out), optional:: name
65 character(*), intent(out), optional:: url
66 character(*), intent(out), optional:: xtype
67
68 ! 内部変数
69 type(GD_NC_VARIABLE_ENTRY):: ent
70 integer:: stat, length, i, i_xtype, idim_growable
71 character(len = *), parameter:: subname = 'GDNcVarInquire'
72 character(len = NF90_MAX_NAME):: buffer
73 character(len = NF90_MAX_NAME):: fbuffer
74continue
75 call beginsub(subname, 'var.id=%d', i=(/var%id/))
76
77 ! フェイルセーフ用にエラー値をまず入れる
78 if (present(ndims)) ndims = -1
79 if (present(dimlen)) dimlen = -1
80
81 ! 変数実体の探索
82 stat = vtable_lookup(var, ent)
83 if (stat /= nf90_noerr) then
84 call endsub(subname, 'var not found')
85 return
86 endif
87
88 ! 各引数が与えられている場合について値を取得する動作を
89
90 if (present(ndims)) then
91 if (associated(ent%dimids)) then
92 ndims = size(ent%dimids)
93 else
94 ndims = 0
95 endif
96 endif
97
98 if (present(dimlen)) then
99 dimlen = 1
100 if (ent%dimid > 0) then
101 ! 実体に次元としての問い合わせが可能な場合
102 stat = nf90_inquire_dimension(ent%fileid, ent%dimid, len = dimlen)
103 if (stat /= nf90_noerr) then
104 dimlen = -1
105 call endsub(subname, 'dimlen err')
106 return
107 endif
108 else
109 ! 実体が変数として問い合わせるしかない場合
110 if (associated(ent%dimids)) then
111 do, i = 1, size(ent%dimids)
112 stat = nf90_inquire_dimension(ent%fileid, ent%dimids(i), len = length)
113 if (stat /= nf90_noerr) then
114 dimlen = -1
115 exit
116 endif
117 dimlen = dimlen * length
118 enddo
119 endif
120 endif
121 endif
122
123 if (present(xtype)) then
124 stat = nf90_inquire_variable(ent%fileid, ent%varid, xtype=i_xtype)
125 if (stat /= nf90_noerr) i_xtype = 0
126 call gdncxtypename(i_xtype, xtype)
127 endif
128
129 if (present(name)) then
130 call local_getname(ent, buffer)
131 name = buffer
132 endif
133
134 if (present(url)) then
135 call local_getname(ent, buffer)
136 call dbgmessage('ent%%fileid=%d', i=(/ent%fileid/))
137 call gdncfileinquire(ent%fileid, name=fbuffer)
138 url = trim(fbuffer) // '?' // buffer
139 endif
140
141 if (present(growable)) then
142 growable = .false.
143 stat = vtable_lookup(var, ent)
144 if (stat /= nf90_noerr) return
145 stat = nf90_inquire(ent%fileid, unlimiteddimid = idim_growable)
146 if (stat /= nf90_noerr) return
147
148 if (ent%varid > 0) then
149 if (.not. associated(ent%dimids)) return
150 do, i = 1, size(ent%dimids)
151 if (ent%dimids(i) == idim_growable) growable = .true.
152 enddo
153 else
154 growable = (ent%dimid == idim_growable)
155 endif
156 endif
157
158 ! 安全に終った
159 call endsub(subname, 'ok')
160 return
161
162contains
163
164 subroutine local_getname(ent, varname)
165 use netcdf, only: &
166 & nf90_inquire_dimension, nf90_inquire_variable, nf90_noerr
167 type(GD_NC_VARIABLE_ENTRY), intent(in):: ent
168 character(len = *), intent(out):: varname
169 if (ent%dimid > 0) then
170 stat = nf90_inquire_dimension(ent%fileid, ent%dimid, name = varname)
171 else
172 stat = nf90_inquire_variable(ent%fileid, ent%varid, name = varname)
173 endif
174 if (stat /= nf90_noerr) varname = ""
175 end subroutine local_getname
176
subroutine local_getname(ent, varname)
非公開なので gtdata_netcdf_generic には置かない
an 層の内部使用ルーチン
デバッグ時の追跡用モジュール
Definition dc_trace.f90:150
subroutine, public dbgmessage(fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:661
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
Definition dc_trace.f90:457
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:580
integer function, public vtable_lookup(var, entry)

References dc_trace::beginsub(), dc_trace::dbgmessage(), dc_trace::endsub(), local_getname(), and gtdata_netcdf_internal::vtable_lookup().

Here is the call graph for this function:

◆ local_getname()

subroutine gdncvarinquire::local_getname ( type(gd_nc_variable_entry), intent(in) ent,
character(len = *), intent(out) varname )

Definition at line 164 of file gdncvarinquire.f90.

165 use netcdf, only: &
166 & nf90_inquire_dimension, nf90_inquire_variable, nf90_noerr
167 type(GD_NC_VARIABLE_ENTRY), intent(in):: ent
168 character(len = *), intent(out):: varname
169 if (ent%dimid > 0) then
170 stat = nf90_inquire_dimension(ent%fileid, ent%dimid, name = varname)
171 else
172 stat = nf90_inquire_variable(ent%fileid, ent%varid, name = varname)
173 endif
174 if (stat /= nf90_noerr) varname = ""