gdncvarinquire.f90 File Reference

Go to the source code of this file.

Functions/Subroutines

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

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 
)

Definition at line 19 of file gdncvarinquire.f90.

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

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  ! 変数が1次元である場合、次元長
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
47 continue
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  ! 変数実体の探索
55  stat = vtable_lookup(var, ent)
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
99  call gdncxtypename(i_xtype, xtype)
100  endif
101 
102  if (present(name)) then
103  call local_getname(ent, buffer)
104  name = buffer
105  endif
106 
107  if (present(url)) then
108  call local_getname(ent, buffer)
109  call dbgmessage('ent%%fileid=%d', i=(/ent%fileid/))
110  call gdncfileinquire(ent%fileid, name=fbuffer)
111  url = trim(fbuffer) // '?' // buffer
112  endif
113 
114  if (present(growable)) then
115  growable = .false.
116  stat = vtable_lookup(var, ent)
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 
135 contains
136 
137  subroutine local_getname(ent, varname)
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 = ""
148  end subroutine local_getname
149 
integer function, public vtable_lookup(var, entry)
subroutine gdncxtypename(ixtype, xtype)
subroutine, public dbgmessage(fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:509
subroutine, public beginsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca, version)
Definition: dc_trace.f90:351
subroutine local_getname(ent, varname)
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446
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 138 of file gdncvarinquire.f90.

Referenced by gdncvarinquire().

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 = ""
Here is the caller graph for this function: