gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
Data Types | Functions/Subroutines | Variables
gtdata_internal_vartable Module Reference

Data Types

interface  dimrange
 

Functions/Subroutines

subroutine, public vartable_dump (vid)
 
subroutine, public vartableadd (vid, class, cid)
 
subroutine, public vartabledelete (vid, action, err)
 
subroutine, public vartablelookup (vid, class, cid)
 
subroutine, public vartablemore (vid, err)
 
integer function, public ndims (vid)
 
subroutine, public query_growable (vid, result)
 

Variables

integer, parameter, public vid_invalid = -1
 
integer, parameter, public vtb_class_unused = 0
 
integer, parameter, public vtb_class_netcdf = 1
 
integer, parameter, public classes_max = 2
 
type(gd_nc_variable_search), save, public gdnc_search
 

Detailed Description

gtool variable table management

This module is not directly referenced from the gtool module, therefore naming conventions are quite flexible. Users must not call this.

A gtool variable is actually just a handle and multi-dimensional iterator, where the handle is a small integer value. To access the actual entity, first lookup the map table using the handle value, then lookup the variable table using the vid obtained there to get the class and class-specific variable number. This is at most pointer + offset reference cost. While gtool variables create as many iterators as needed from entity variables, this variable table creates only one entry per entity variable, so it has a reference count. This eliminates the need for entity variables to manage reference counts.

Function/Subroutine Documentation

◆ ndims()

integer function, public gtdata_internal_vartable::ndims ( integer, intent(in)  vid)

Get number of dimensions of variable

Parameters
[in]vidVariable ID
Returns
Number of dimensions

Definition at line 356 of file gtdata_internal_vartable.f90.

358 use gtdata_netcdf_generic, only: gdncinquire => inquire
359 use dc_error, only: storeerror, nf90_einval
360 integer, intent(in):: vid
361 integer:: class, cid
362 call vartablelookup(vid, class, cid)
363 select case(class)
364 case(vtb_class_netcdf)
365 call gdncinquire(gd_nc_variable(cid), ndims=result)
366 case default
367 call storeerror(nf90_einval, 'gtdata::ndims')
368 end select
Error handling module.
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891

References ndims(), dc_error::storeerror(), vartablelookup(), and vtb_class_netcdf.

Here is the call graph for this function:

◆ query_growable()

subroutine, public gtdata_internal_vartable::query_growable ( integer, intent(in)  vid,
logical, intent(out)  result 
)

Query whether variable has unlimited dimension

Parameters
[in]vidVariable ID
[out]result.true. if variable has unlimited dimension

Definition at line 384 of file gtdata_internal_vartable.f90.

387 use dc_error, only: storeerror, nf90_einval
388 integer, intent(in):: vid
389 logical, intent(out):: result
390 integer:: class, cid
391 call vartablelookup(vid, class, cid)
392 select case(class)
393 case(vtb_class_netcdf)
394 call inquire(gd_nc_variable(cid), growable=result)
395 case default
396 call storeerror(nf90_einval, 'gtdata::ndims')
397 end select

References dc_error::storeerror(), vartablelookup(), and vtb_class_netcdf.

Here is the call graph for this function:

◆ vartable_dump()

subroutine, public gtdata_internal_vartable::vartable_dump ( integer, intent(in)  vid)

Dump variable table entry for debugging

Parameters
[in]vidVariable ID to dump

Definition at line 106 of file gtdata_internal_vartable.f90.

107 use dc_trace, only: dbgmessage
110 integer, intent(in):: vid
111 character(10):: class
112 if (.not. allocated(table)) return
113 if (vid <= 0 .or. vid > size(table)) return
114 select case(table(vid)%class)
115 case(vtb_class_netcdf)
116 class = 'netcdf'
117 case default
118 write(class, fmt="(i10)") table(vid)%class
119 end select
120 call dbgmessage('[vartable %d: class=%c cid=%d ref=%d]', &
121 & i=(/vid, table(vid)%cid, table(vid)%refcount/), &
122 & c1=trim(class))
123 select case(table(vid)%class)
124 case(vtb_class_netcdf)
125 call dbgmessage('[%c]', c1=trim(tostring(gd_nc_variable(table(vid)%cid))))
126 end select
Debug tracing module.
Definition dc_trace.f90:150
subroutine, public dbgmessage(fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:661

References dc_trace::dbgmessage(), vtb_class_netcdf, and vtb_class_unused.

Here is the call graph for this function:

◆ vartableadd()

subroutine, public gtdata_internal_vartable::vartableadd ( integer, intent(out)  vid,
integer, intent(in)  class,
integer, intent(in)  cid 
)

Add entry to variable table

If an entry with the same class and cid already exists, increments its reference count. Otherwise, creates a new entry.

Parameters
[out]vidAssigned variable ID
[in]classVariable class (VTB_CLASS_NETCDF, etc.)
[in]cidClass-specific ID

Definition at line 168 of file gtdata_internal_vartable.f90.

169 use dc_trace, only: dbgmessage
170 integer, intent(out):: vid
171 integer, intent(in):: class, cid
172 type(VAR_TABLE_ENTRY), allocatable:: tmp_table(:)
173 integer:: n
174 continue
175 ! 必要ならば初期幅確保
176 if (.not. allocated(table)) then
177 allocate(table(table_ini_size))
178 call entry_cleanup(table(:))
179 endif
180 ! 該当があれば参照数増加
181 do, n = 1, size(table)
182 if (table(n)%class == class .and. table(n)%cid == cid) then
183 table(n)%refcount = table(n)%refcount + 1
184 call dbgmessage('gtdata_vartable.add(class=%d cid=%d) found (ref=%d)', &
185 & i=(/table(n)%class, table(n)%cid, table(n)%refcount/))
186 vid = n
187 return
188 endif
189 enddo
190 ! もし空きが無ければ表を拡張
191 if (all(table(:)%class /= vtb_class_unused)) then
192 n = size(table)
193 allocate(tmp_table(n))
194 tmp_table(:) = table(:)
195 deallocate(table)
196 allocate(table(n * 2))
197 table(1:n) = tmp_table(1:n)
198 deallocate(tmp_table)
199 table(n+1:n*2) = var_table_entry(vtb_class_unused, -1, 0)
200 endif
201 do, n = 1, size(table)
202 if (table(n)%class == vtb_class_unused) then
203 table(n)%class = class
204 table(n)%cid = cid
205 table(n)%refcount = 1
206 vid = n
207 return
208 endif
209 enddo
210 vid = vid_invalid

References dc_trace::dbgmessage(), vid_invalid, and vtb_class_unused.

Here is the call graph for this function:

◆ vartabledelete()

subroutine, public gtdata_internal_vartable::vartabledelete ( integer, intent(in)  vid,
logical, intent(out)  action,
logical, intent(out), optional  err 
)

Delete entry from variable table

Decrements the reference count. When it reaches zero, action is set to .true. indicating actual deletion should occur.

Parameters
[in]vidVariable ID to delete
[out]action.true. if actual deletion should be performed
[out]errError flag (optional)

Definition at line 234 of file gtdata_internal_vartable.f90.

235 integer, intent(in):: vid
236 logical, intent(out):: action
237 logical, intent(out), optional:: err
238 if (.not. allocated(table)) goto 999
239 if (vid <= 0 .or. vid > size(table)) goto 999
240 if (table(vid)%class <= vtb_class_unused) goto 999
241 if (table(vid)%class > classes_max) goto 999
242 table(vid)%refcount = max(table(vid)%refcount - 1, 0)
243 action = (table(vid)%refcount == 0)
244 if (present(err)) err = .false.
245 return
246999 continue
247 action = .false.
248 if (present(err)) err = .true.

References classes_max, and vtb_class_unused.

◆ vartablelookup()

subroutine, public gtdata_internal_vartable::vartablelookup ( integer, intent(in)  vid,
integer, intent(out), optional  class,
integer, intent(out), optional  cid 
)

Look up variable table entry

Returns the class and cid of the entry with the specified vid.

Parameters
[in]vidVariable ID to look up
[out]classVariable class (optional)
[out]cidClass-specific ID (optional)

Definition at line 270 of file gtdata_internal_vartable.f90.

271 integer, intent(in):: vid
272 integer, intent(out), optional:: class, cid
273 if (.not. allocated(table)) goto 999
274 if (vid <= 0 .or. vid > size(table)) goto 999
275 if (table(vid)%class <= vtb_class_unused) goto 999
276 if (table(vid)%class > classes_max) goto 999
277 if (present(class)) class = table(vid)%class
278 if (present(cid)) cid = table(vid)%cid
279 return
280999 continue
281 if (present(class)) class = vtb_class_unused

References classes_max, and vtb_class_unused.

◆ vartablemore()

subroutine, public gtdata_internal_vartable::vartablemore ( integer, intent(in)  vid,
logical, intent(out), optional  err 
)

Increment reference count of variable table entry

Parameters
[in]vidVariable ID
[out]errError flag (optional)

Definition at line 297 of file gtdata_internal_vartable.f90.

298 integer, intent(in):: vid
299 logical, intent(out), optional:: err
300 if (.not. allocated(table)) goto 999
301 if (vid <= 0 .or. vid > size(table)) goto 999
302 if (table(vid)%class <= vtb_class_unused) goto 999
303 if (table(vid)%class > classes_max) goto 999
304 table(vid)%refcount = table(vid)%refcount + 1
305 if (present(err)) err = .false.
306 return
307999 continue
308 if (present(err)) err = .true.

References classes_max, and vtb_class_unused.

Variable Documentation

◆ classes_max

integer, parameter, public gtdata_internal_vartable::classes_max = 2

Definition at line 70 of file gtdata_internal_vartable.f90.

70 integer, parameter, public :: CLASSES_MAX = 2

◆ gdnc_search

type(gd_nc_variable_search), save, public gtdata_internal_vartable::gdnc_search

Definition at line 81 of file gtdata_internal_vartable.f90.

81 type(GD_NC_VARIABLE_SEARCH), public, save:: gdnc_search

◆ vid_invalid

integer, parameter, public gtdata_internal_vartable::vid_invalid = -1

Definition at line 66 of file gtdata_internal_vartable.f90.

66 integer, parameter, public :: vid_invalid = -1

◆ vtb_class_netcdf

integer, parameter, public gtdata_internal_vartable::vtb_class_netcdf = 1

Definition at line 69 of file gtdata_internal_vartable.f90.

69 integer, parameter, public :: VTB_CLASS_NETCDF = 1

◆ vtb_class_unused

integer, parameter, public gtdata_internal_vartable::vtb_class_unused = 0

Definition at line 68 of file gtdata_internal_vartable.f90.

68 integer, parameter, public :: VTB_CLASS_UNUSED = 0