gdncvarattr.f90
Go to the documentation of this file.
1 ! Copyright (C) GFD Dennou Club, 2000. All rights reserved.
2 
3 ! --- 属性の列挙 ---
4 
5 ! ある変数 var に付随した属性をすべて取得するにはまず
6 ! attr_rewind(var) を呼び出してから無限ループの中で
7 ! attr_next(var, name, [end]) を呼び出す。name がひとつ
8 ! ひとつの属性名を与える。name が空文字列になったとき、
9 ! すべての属性を探索し終えたことになる。このとき end を
10 ! 与えていればそれが真になることでも判定できる。
11 
12 ! 大域属性は、その名前の先頭に "+" が付加された普通の変数属性で
13 ! あるかのように見える。
14 
15 subroutine gdncvarattrrewind(var)
18  use netcdf, only: nf90_noerr
19  use dc_trace, only: dbgmessage
20  implicit none
21  type(gd_nc_variable), intent(in):: var
22  integer:: stat
23  character(len = *), parameter:: subname = 'GDNcVarAttrRewind'
24 
25  stat = vtable_set_attrid(var, 0)
26  call dbgmessage("%c %d", c1=subname, i=(/stat/))
27 end subroutine gdncvarattrrewind
28 
29 subroutine gdncvarattrnext(var, name, vend)
32  use netcdf, only: nf90_noerr, nf90_max_name, nf90_inq_attname, nf90_global
33  use dc_url, only: gt_plus
34  implicit none
35  type(gd_nc_variable), intent(in):: var
36  character(len = *), intent(out):: name
37  type(gd_nc_variable_entry):: ent
38  logical, intent(out), optional:: vend
39  character(len = NF90_MAX_NAME):: attrname
40  integer:: stat
41  integer:: new_attrid
42 
43  stat = vtable_lookup(var, ent)
44  if (stat /= nf90_noerr) goto 999
45 
46  new_attrid = ent%attrid
47  ! 最初は変数属性の検索
48  if (ent%attrid >= 0) then
49  new_attrid = ent%attrid + 1
50  stat = nf90_inq_attname(ent%fileid, ent%varid, new_attrid, attrname)
51  if (stat == nf90_noerr) then
52  name = attrname
53  stat = vtable_set_attrid(var, new_attrid)
54  vend = .false.
55  return
56  end if
57  new_attrid = -1
58  endif
59 
60  ! 次は大域属性の検索
61  stat = nf90_inq_attname(ent%fileid, nf90_global, -new_attrid, attrname)
62  if (stat == nf90_noerr) then
63  new_attrid = new_attrid - 1
64  name = gt_plus // attrname
65  stat = vtable_set_attrid(var, new_attrid)
66  vend = .false.
67  return
68  endif
69 
70 999 continue
71  ! ここでは attrid の再設定はしない。次呼んでもエラーになるのが適当。
72  vend = .true.
73  name = ""
74  return
75 end subroutine gdncvarattrnext
integer function, public vtable_lookup(var, entry)
subroutine gdncvarattrrewind(var)
Definition: gdncvarattr.f90:16
character, parameter, public gt_plus
Definition: dc_url.f90:92
subroutine, public dbgmessage(fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:509
subroutine gdncvarattrnext(var, name, vend)
Definition: gdncvarattr.f90:30
integer function, public vtable_set_attrid(var, attrid)