! Copyright (C) TOYODA Eizi, 2000.  All rights reserved.

subroutine GTVarAddMember(var, member_url, link_name)
    use gtdata_types, only: GT_VARIABLE
    use dc_string
    use gtdata_generic, only: get_attr, put_attr
    use dc_url, only: UrlSplit
    use dc_error
    type(GT_VARIABLE), intent(inout):: var
    type(VSTRING), intent(in):: member_url
    character(len = *), intent(in), optional:: link_name
    type(VSTRING):: members, myshortname
continue
    ! 短縮名称の決定
    ! 既存のメンバ名に重複しないものを選ぶ
    call get_attr(var, 'gt_structure_member', members)
    if (present(link_name)) then
        if (vindex(members, (link_name // ' ')) == 0) then
            myshortname = link_name
            goto 1000
        endif
    endif
    call UrlSplit(member_url, var=myshortname)
    ! fake 判定
    if (vindex(members, (myshortname // ' ')) /= 0) then
        call StoreError(GT_EFAKE, "GTVarAddMember(making unique name)")
    endif
    1000 continue
    members = members // myshortname // ' '
    call put_attr(var, 'gt_structure_member', members)
    call put_attr(var, 'gt_structure_link_' // vchar(myshortname, len(myshortname)), member_url)
end subroutine
