!
!= 螻樊ｧ縺ｮ繧ｳ繝斐�
!
! 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