!
!= æ§‹é€ åž‹å¤‰æ•°ã® gt_structure_member å±žæ€§ã®è¿½åŠ
!
! Authors::   Eizi TOYODA, Yasuhiro MORIKAWA
! Version::   $Id: gtvaraddmember.f90,v 1.1 2009-03-20 09:09:52 morikawa Exp $
! Tag Name::  $Name:  $
! Copyright:: Copyright (C) GFD Dennou Club, 2000-2005. All rights reserved.
! License::   See COPYRIGHT[link:../../COPYRIGHT]
!
! ä»¥ä¸‹ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã€é–¢æ•°ã¯ gtdata_generic ã‹ã‚‰ gtdata_generic#Add_Member
! ã¨ã—ã¦æä¾›ã•ã‚Œã¾ã™ã€‚
!

subroutine GTVarAddMember(var, member_url, link_name)
  !
  !== æ§‹é€ åž‹å¤‰æ•°ã® gt_structure_member å±žæ€§ã®è¿½åŠ
  !
  ! å¤‰æ•° *var* ã® gt_structure_member å±žæ€§
  ! ({gtool4 netCDF è¦ç´„}[link:../xref.htm#label-6] ã® ã€Œ4. æ§‹é€ ä½“å¤‰æ•°ã€å‚ç…§)
  ! ã« *member_url* ã®å¤‰æ•°åéƒ¨åˆ†ã‚’è¿½åŠ ã—ã¾ã™ã€‚
  !
  use gtdata_types, only: GT_VARIABLE
  use dc_types, only: STRING
  use dc_url, only: UrlSplit
  use gtdata_generic, only: put_attr, get_attr
  use dc_error
  implicit none
  type(GT_VARIABLE), intent(inout):: var
  character(len = *), intent(in):: member_url
  character(len = *), intent(in), optional:: link_name
  character(len = string):: members, myshortname, conv
continue
  ! çŸç¸®åç§°ã®æ±ºå®š
  ! æ—¢å˜ã®ãƒ¡ãƒ³ãƒåã«é‡è¤‡ã—ãªã„ã‚‚ã®ã‚’é¸ã¶
  call get_attr(var, 'gt_structure_member', members)
  if (present(link_name)) then
    if (index(members, ' ' //link_name) == 0) then
      myshortname = link_name
      goto 1000
    endif
  endif
  conv = member_url
  call UrlSplit(conv, var=myshortname)
  ! fake åˆ¤å®š
  if (index(members, trim(myshortname)) /= 0) then
    call StoreError(GT_EFAKE, "GTVarAddMember(making unique name)")
  endif
1000 continue
  members = trim(members) // ' ' // trim(myshortname)
  call put_attr(var, 'gt_structure_member', trim(members))
  myshortname = 'gt_structure_link_' // trim(myshortname)
  call put_attr(var, myshortname, trim(member_url))

end subroutine GTVarAddMember