gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
Functions/Subroutines
gtdata_netcdf_internal Module Reference

Functions/Subroutines

integer function, public vtable_add (var, entry)
 
integer function, public vtable_delete (var)
 
integer function, public vtable_lookup (var, entry)
 
integer function, public vtable_set_attrid (var, attrid)
 

Detailed Description

gtdata_netcdf 内で使用される内部向け定数, 変数, 手続き群

このモジュールは内部変数テーブル (gdnctab) とその管理手続きを提供します。

手続き 説明
vtable_add 変数テーブルにエントリを追加
vtable_delete 変数テーブルからエントリを削除
vtable_lookup 変数テーブルでエントリを検索
vtable_set_attrid 属性イテレータ ID を設定

Function/Subroutine Documentation

◆ vtable_add()

integer function, public gtdata_netcdf_internal::vtable_add ( type(gd_nc_variable), intent(out)  var,
type(gd_nc_variable_search), intent(in)  entry 
)

変数テーブルにエントリを追加

gdnctab に新しいエントリを追加、または既登録なら既存エントリを返します。

Parameters
[out]var変数ハンドル
[in]entry追加するエントリ
Returns
成功時 NF90_NOERR、割当失敗時 NF90_ENOMEM

Definition at line 86 of file gtdata_netcdf_internal.f90.

87 type(GD_NC_VARIABLE), intent(out):: var
88 type(GD_NC_VARIABLE_SEARCH), intent(in):: entry
89 type(GD_NC_VARIABLE_ENTRY), allocatable:: tmp_table(:)
90 integer:: i, n
91
92 ! --- 必要なら初期確保 ---
93 if (.not. allocated(gdnctab)) then
94 allocate(gdnctab(gdnctab_init_size), stat=result)
95 if (result /= 0) goto 999
96 do, i = 1, gdnctab_init_size
97 gdnctab(i)%fileid = 0
98 gdnctab(i)%varid = 0
99 gdnctab(i)%dimid = 0
100 gdnctab(i)%attrid = 0
101 nullify(gdnctab(i)%dimids)
102 enddo
103 endif
104 ! --- 同じ内容が既登録ならばそれを返す (attrid は変更しない) ---
105 do, i = 1, size(gdnctab)
106 if (gdnctab(i)%fileid == entry%fileid &
107 & .and. gdnctab(i)%varid == entry%varid &
108 & .and. gdnctab(i)%dimid == entry%dimid) then
109 var = gd_nc_variable(i)
110 result = nf90_noerr
111 call dbgmessage('gtdata_netcdf_internal.add: found %d', i=(/i/))
112 return
113 endif
114 enddo
115 !
116 ! --- 空き地があればそこに割り当て ---
117 var = gd_nc_variable(-1)
118 do, i = 1, size(gdnctab)
119 if (gdnctab(i)%fileid == 0) then
120 var = gd_nc_variable(i)
121 exit
122 endif
123 enddo
124 if (var%id == -1) then
125 ! --- 空き地はなかったのだから倍幅確保 ---
126 n = size(gdnctab)
127 allocate(tmp_table(n), stat=result)
128 if (result /= 0) goto 999
129 tmp_table(:) = gdnctab(:)
130 deallocate(gdnctab, stat=result)
131 if (result /= 0) goto 999
132 allocate(gdnctab(n * 2), stat=result)
133 if (result /= 0) goto 999
134 gdnctab(1:n) = tmp_table(1:n)
135 deallocate(tmp_table, stat=result)
136 if (result /= 0) goto 999
137 !
138 gdnctab(n+2)%fileid = 0
139 gdnctab(n+2)%varid = 0
140 gdnctab(n+2)%dimid = 0
141 gdnctab(n+2)%attrid = 0
142 nullify(gdnctab(n+2)%dimids)
143 gdnctab(n+3: n*2) = gdnctab(n+2)
144 ! 確保域の先頭を使用
145 var = gd_nc_variable(n + 1)
146 endif
147 gdnctab(var%id)%fileid = entry%fileid
148 gdnctab(var%id)%varid = entry%varid
149 gdnctab(var%id)%dimid = entry%dimid
150 !
151 ! --- 次元表の確保 ---
152 call internal_build_dimids(gdnctab(var%id), result)
153 if (result /= nf90_noerr) goto 999
154 !
155 result = nf90_noerr
156 call dbgmessage('gtdata_netcdf_internal.add: added %d', i=(/var%id/))
157 return
158 !
159999 continue
160 var = gd_nc_variable(-1)
161 result = nf90_enomem
162 return
163
164 contains
165
166 subroutine internal_build_dimids(ent, stat)
167!! use netcdf, only: &
168!! & NF90_NOERR, NF90_ENOMEM, NF90_INQUIRE_VARIABLE
169 type(GD_NC_VARIABLE_ENTRY), intent(inout):: ent
170 integer, intent(out):: stat
171 integer:: ndims
172 if (ent%varid > 0) then
173 stat = nf90_inquire_variable(ent%fileid, ent%varid, ndims = ndims)
174 if (stat /= nf90_noerr) return
175 if ((ent%dimid > 0) .and. (ndims /= 1)) goto 100
176 if (ndims == 0) then
177 nullify(ent%dimids)
178 stat = nf90_noerr
179 return
180 endif
181 allocate(ent%dimids(ndims), stat=stat)
182 if (stat /= 0) then
183 stat = nf90_enomem
184 return
185 endif
186 stat = nf90_inquire_variable(ent%fileid, ent%varid, dimids = ent%dimids)
187 if (stat /= nf90_noerr) return
188 if ((ent%dimid > 0) .and. (ent%dimids(1) /= ent%dimid)) then
189 deallocate(ent%dimids)
190 goto 100
191 endif
192 else
193 allocate(ent%dimids(1), stat=stat)
194 if (stat /= 0) then
195 stat = nf90_enomem
196 return
197 endif
198 ent%dimids(1) = ent%dimid
199 endif
200 stat = nf90_noerr
201 return
202
203100 continue
204 ent%varid = 0
205 allocate(ent%dimids(1))
206 ent%dimids(1) = ent%dimid
207 end subroutine internal_build_dimids
208

References dc_trace::dbgmessage().

Here is the call graph for this function:

◆ vtable_delete()

integer function, public gtdata_netcdf_internal::vtable_delete ( type(gd_nc_variable), intent(in)  var)

変数テーブルからエントリを削除

成功時は fileid を、失敗時は NF90_ENOTVAR を返します。

Parameters
[in]var変数ハンドル
Returns
成功時 fileid、失敗時 NF90_ENOTVAR

Definition at line 228 of file gtdata_netcdf_internal.f90.

229 type(GD_NC_VARIABLE), intent(in):: var
230 if (.not. allocated(gdnctab)) goto 999
231 if (var%id <= 0 .or. var%id > size(gdnctab)) goto 999
232 if (gdnctab(var%id)%fileid == 0) goto 999
233 result = gdnctab(var%id)%fileid
234 gdnctab(var%id)%fileid = 0
235 gdnctab(var%id)%varid = 0
236 gdnctab(var%id)%dimid = 0
237 gdnctab(var%id)%attrid = 0
238 if (associated(gdnctab(var%id)%dimids)) &
239 & deallocate(gdnctab(var%id)%dimids)
240 call dbgmessage('gtdata_netcdf_internal.delete: delete %d', i=(/var%id/))
241 return
242 !
243999 continue
244 result = nf90_enotvar

References dc_trace::dbgmessage().

Here is the call graph for this function:

◆ vtable_lookup()

integer function, public gtdata_netcdf_internal::vtable_lookup ( type(gd_nc_variable), intent(in)  var,
type(gd_nc_variable_entry), intent(out)  entry 
)

変数テーブルでエントリを検索

Parameters
[in]var変数ハンドル
[out]entry見つかったエントリ
Returns
成功時 NF90_NOERR、未発見時 NF90_ENOTVAR

Definition at line 260 of file gtdata_netcdf_internal.f90.

261 type(GD_NC_VARIABLE), intent(in):: var
262 type(GD_NC_VARIABLE_ENTRY), intent(out):: entry
263 if (.not. allocated(gdnctab)) goto 999
264 if (var%id <= 0 .or. var%id > size(gdnctab)) goto 999
265 if (gdnctab(var%id)%fileid == 0) goto 999
266 entry = gdnctab(var%id)
267 result = nf90_noerr
268 return
269 !
270999 continue
271 nullify(entry%dimids)
272 entry%fileid = -1
273 entry%varid = -1
274 entry%dimid = -1
275 entry%attrid = -1
276 result = nf90_enotvar

◆ vtable_set_attrid()

integer function, public gtdata_netcdf_internal::vtable_set_attrid ( type(gd_nc_variable), intent(in)  var,
integer, intent(in)  attrid 
)

変数の属性イテレータ ID を設定

Parameters
[in]var変数ハンドル
[in]attrid属性イテレータ ID
Returns
成功時 NF90_NOERR、失敗時 NF90_ENOTVAR

Definition at line 292 of file gtdata_netcdf_internal.f90.

293 type(GD_NC_VARIABLE), intent(in):: var
294 integer, intent(in):: attrid
295 continue
296 if (.not. allocated(gdnctab)) goto 999
297 if (var%id <= 0 .or. var%id > size(gdnctab)) goto 999
298 if (gdnctab(var%id)%fileid == 0) goto 999
299 gdnctab(var%id)%attrid = attrid
300 result = nf90_noerr
301 return
302 !
303999 continue
304 result = nf90_enotvar