subroutine ANVarAttrNext(var, name, end)
use an_types, only: AN_VARIABLE, an_variable_entry
use an_vartable, only: vtable_set_attrid, vtable_lookup
use netcdf_f77
use dc_url, only: GT_PLUS
implicit none
type(AN_VARIABLE), intent(in):: var
character(len = *), intent(out):: name
type(an_variable_entry):: ent
logical, intent(out), optional:: end
character(len = NF_MAX_NAME):: attrname
integer:: stat
integer:: new_attrid
stat = vtable_lookup(var, ent)
if (stat /= NF_NOERR) goto 999
new_attrid = ent%attrid
! 最初は変数属性の検索
if (ent%attrid >= 0) then
new_attrid = ent%attrid + 1
stat = NF_INQ_ATTNAME(ent%fileid, ent%varid, new_attrid, attrname)
if (stat == NF_NOERR) then
name = attrname
stat = vtable_set_attrid(var, new_attrid)
end = .FALSE.
return
endif
new_attrid = -1
endif
! 次は大域属性の検索
stat = NF_INQ_ATTNAME(ent%fileid, NF_GLOBAL, -new_attrid, attrname)
if (stat == NF_NOERR) then
new_attrid = new_attrid - 1
name = GT_PLUS // attrname
stat = vtable_set_attrid(var, new_attrid)
end = .FALSE.
return
endif
999 continue
! ここでは attrid の再設定はしない。次呼んでもエラーになるのが適当。
end = .TRUE.
name = ""
return
end subroutine