gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
gdncvarattr.f90
Go to the documentation of this file.
1!> @file gdncvarattr.f90
2!>
3!> @author GFD Dennou Club
4!> @copyright Copyright (C) GFD Dennou Club, 2000-2026. All rights reserved. <br/>
5!> License is BSD-2-Clause. See [COPYRIGHT](@ref COPYRIGHT) in detail
6!>
7!> @en
8!> @brief Attribute enumeration for netCDF variables
9!>
10!> To enumerate all attributes of a variable:
11!> 1. Call attr_rewind(var) to reset the iterator
12!> 2. Call attr_next(var, name, [end]) in a loop
13!> 3. name gives each attribute name; empty string when done
14!> 4. Optionally, end becomes true when all attributes are enumerated
15!>
16!> Global attributes appear with '+' prefix added to their names.
17!> @enden
18!>
19!> @ja
20!> @brief netCDF 変数の属性列挙
21!>
22!> 変数のすべての属性を列挙するには:
23!> 1. attr_rewind(var) を呼び出してイテレータをリセット
24!> 2. ループ内で attr_next(var, name, [end]) を呼び出す
25!> 3. name が各属性名を返す; 終了時は空文字列
26!> 4. オプションで end が真になることでも終了を判定可能
27!>
28!> グローバル属性は名前の先頭に '+' が付加されて現れます。
29!> @endja
30!>
31
32!>
33!> @en
34!> @brief Reset attribute iterator to beginning
35!> @enden
36!>
37!> @ja
38!> @brief 属性イテレータを先頭にリセット
39!> @endja
40!>
41!> @param[in] var @en Variable handle @enden @ja 変数ハンドル @endja
42!>
43subroutine gdncvarattrrewind(var)
46 use dc_trace, only: dbgmessage
47 implicit none
48 type(gd_nc_variable), intent(in):: var
49 integer:: stat
50 character(len = *), parameter:: subname = 'GDNcVarAttrRewind'
51
52 stat = vtable_set_attrid(var, 0)
53 call dbgmessage("%c %d", c1=subname, i=(/stat/))
54end subroutine gdncvarattrrewind
55
56!>
57!> @en
58!> @brief Get next attribute name in enumeration
59!>
60!> Returns the next attribute name. Variable attributes are returned first,
61!> then global attributes (prefixed with '+').
62!> @enden
63!>
64!> @ja
65!> @brief 列挙の次の属性名を取得
66!>
67!> 次の属性名を返します。変数属性が先に返され、
68!> その後グローバル属性 ('+' 接頭辞付き) が返されます。
69!> @endja
70!>
71!> @param[in] var @en Variable handle @enden @ja 変数ハンドル @endja
72!> @param[out] name @en Attribute name (empty string when done) @enden
73!> @ja 属性名 (終了時は空文字列) @endja
74!> @param[out] vend @en True when all attributes enumerated (optional) @enden
75!> @ja 全属性列挙完了時に真 (省略可能) @endja
76!>
77subroutine gdncvarattrnext(var, name, vend)
80 use netcdf, only: nf90_noerr, nf90_max_name, nf90_inq_attname, nf90_global
81 use dc_url, only: gt_plus
82 implicit none
83 type(gd_nc_variable), intent(in):: var
84 character(len = *), intent(out):: name
85 type(gd_nc_variable_entry):: ent
86 logical, intent(out), optional:: vend
87 character(len = NF90_MAX_NAME):: attrname
88 integer:: stat
89 integer:: new_attrid
90
91 stat = vtable_lookup(var, ent)
92 if (stat /= nf90_noerr) goto 999
93
94 new_attrid = ent%attrid
95 ! 最初は変数属性の検索
96 if (ent%attrid >= 0) then
97 new_attrid = ent%attrid + 1
98 stat = nf90_inq_attname(ent%fileid, ent%varid, new_attrid, attrname)
99 if (stat == nf90_noerr) then
100 name = attrname
101 stat = vtable_set_attrid(var, new_attrid)
102 vend = .false.
103 return
104 end if
105 new_attrid = -1
106 endif
107
108 ! 次は大域属性の検索
109 stat = nf90_inq_attname(ent%fileid, nf90_global, -new_attrid, attrname)
110 if (stat == nf90_noerr) then
111 new_attrid = new_attrid - 1
112 name = gt_plus // attrname
113 stat = vtable_set_attrid(var, new_attrid)
114 vend = .false.
115 return
116 endif
117
118999 continue
119 ! ここでは attrid の再設定はしない。次呼んでもエラーになるのが適当。
120 vend = .true.
121 name = ""
122 return
123end subroutine gdncvarattrnext
subroutine gdncvarattrnext(var, name, vend)
subroutine gdncvarattrrewind(var)
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
Variable URL string parser.
Definition dc_url.f90:61
character, parameter, public gt_plus
Definition dc_url.f90:109
integer function, public vtable_set_attrid(var, attrid)
integer function, public vtable_lookup(var, entry)