!
!= å±žæ€§ã®ã‚³ãƒ”ãƒ¼
!
! Authors::   Eizi TOYODA, Yasuhiro MORIKAWA
! Version::   $Id: gtvarcopyattr.f90,v 1.4 2009-05-25 09:55:58 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#Copy_Attr
! ã¨ã—ã¦æä¾›ã•ã‚Œã¾ã™ã€‚

subroutine GTVarCopyAttr(to, attrname, from, err)
  !
  !== å±žæ€§ã®ã‚³ãƒ”ãƒ¼
  !
  ! å¤‰æ•° *from* ã®å±žæ€§ *attrname* ã‚’ å¤‰æ•° *to* ã¸ã‚³ãƒ”ãƒ¼ã—ã¾ã™ã€‚
  !
  ! å±žæ€§ã®ã‚³ãƒ”ãƒ¼æ™‚ã«ã‚¨ãƒ©ãƒ¼ãŒç”Ÿã˜ãŸå ´åˆã€ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’å‡ºåŠ›
  ! ã—ã¦ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã—ã¾ã™ã€‚*err* ã‚’ä¸Žãˆã¦ã‚ã‚‹å ´åˆã«ã¯
  ! ã®å¼•æ•°ã« .true. ãŒè¿”ã‚Šã€ãƒ—ãƒã‚°ãƒ©ãƒ ã¯çµ‚äº†ã—ã¾ã›ã‚“ã€‚
  !
  ! *Copy_Attr* ã¯ 2 ã¤ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã®ç·ç§°åã§ã‚ã‚Šã€
  ! ä»–ã«ã‚‚ä¸€æ‹¬ã§å¤‰æ•°ã®å…¨ã¦ã®å±žæ€§ã‚’ã‚³ãƒ”ãƒ¼ã™ã‚‹æ–¹æ³•ã‚‚ã‚ã‚Šã¾ã™ã€‚
  ! ä¸‹è¨˜ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å‚ç…§ãã ã•ã„ã€‚
  !
  use gtdata_types, only: GT_VARIABLE
  use gtdata_generic, only: GET_ATTR, PUT_ATTR
  use gtdata_internal_map, only: var_class, vtb_class_netcdf, vtb_class_memory
  use gtdata_netcdf_generic, only: copy_attr
  use gtdata_netcdf_types, only: GD_NC_VARIABLE
  use dc_trace, only: beginsub, endsub
  use dc_error, only: StoreError, DC_NOERR
  use dc_types, only: STRING
  implicit none
  type(GT_VARIABLE), intent(inout):: to
  character(len = *), intent(in):: attrname
  type(GT_VARIABLE), intent(in):: from
  logical, intent(out), optional:: err
  character(STRING):: svalue
  integer:: from_class, from_cid, to_class, to_cid, stat
continue
  if (present(err)) err = .false.
  call beginsub('gtvarcopyattr', 'mapid to=%d from=%d name=%c', &
    & i=(/to%mapid, from%mapid/), c1=attrname)
  call var_class(from, from_class, from_cid)
  call var_class(to, to_class, to_cid)
  if (from_class == vtb_class_netcdf .and. to_class == vtb_class_netcdf) then
    call Copy_Attr(GD_NC_VARIABLE(to_cid), attrname, &
      & GD_NC_VARIABLE(from_cid), stat)
  else
    ! ã¨ã‚Šã‚ãˆãšæ–‡å—åˆ—ã§å…¥å‡ºåŠ›ã—ã¦ãŠã
    call Get_Attr(from, attrname, svalue, default='')
    call Put_Attr(to, attrname, svalue, '', err)
    stat = DC_NOERR
  endif
  call StoreError(stat, "GTVarCopyAttr", err)
  call endsub('gtvarcopyattr', 'stat = %d', i=(/stat/))
end subroutine GTVarCopyAttr