!
!= 譁�ｭ怜梛螻樊ｧ縺ｮ蜈･蜉�
!
! Authors::   Eizi TOYODA, Yasuhiro MORIKAWA
! Version::   $Id: gtvargetattrsc.f90,v 1.5 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 縺九ｉ謠蝉ｾ帙＆繧後∪縺吶�
!

subroutine GTVarGetAttrCC(var, name, value, default)
  !--
  ! character 蝙九〒蜿励￠蜿悶ｋ蝣ｴ蜷医�騾壼ｸｸ縺ｮ譁�ｭ怜梛莉｣蜈･縺ｨ蜷梧ｧ倥�
  ! 蜿励￠蛛ｴ螟画焚縺ｮ髟ｷ縺輔↓蜷医ｏ縺帙※蛻�ｊ謐ｨ縺ｦ繝ｻ遨ｺ逋ｽ蝓九ａ繧定｡後≧縲�
  ! 螻樊ｧ縺悟ｭ伜惠縺励↑縺��ｴ蜷� default 蛟､繧剃ｽｿ縺��
  !++

  use gtdata_types, only: GT_VARIABLE
  use gtdata_internal_map, only: var_class, vtb_class_netcdf, vtb_class_memory
  use gtdata_netcdf_generic, only: get_attr
  use gtdata_netcdf_types, only: GD_NC_VARIABLE
  use gtdata_memory_generic, only: get_attr
  use gtdata_memory_types, only: GD_MEM_VARIABLE
  use dc_trace, only: beginsub, endsub
  use dc_types, only: string
  implicit none
  type(GT_VARIABLE), intent(in):: var
  character(len = *), intent(in):: name
  character(len = *), intent(out):: value
  character(len = *), intent(in), optional:: default
  logical:: err
  integer:: class, cid, stat
  character(len = string):: p_default
  character(len = *), parameter:: subnam = "gtvargetattrcc"
continue
  call beginsub(subnam)
  call var_class(var, class, cid)
  p_default = ""
  if (present(default)) p_default = default
  if (class == vtb_class_netcdf) then
    call get_attr(GD_NC_VARIABLE(cid), name, value, p_default, stat)
  else if (class == vtb_class_memory) then
    call get_attr(GD_MEM_VARIABLE(cid), name, value, err)
    if (err) value = p_default
  endif
  call endsub(subnam, "%d:%d:%c = %c", i=(/class, cid/), &
    & c1=trim(name), c2=trim(value))
end subroutine GTVarGetAttrCC