!
!= 螻樊ｧ縺ｮ莉伜刈
!
! Authors::   Eizi TOYODA, Yasuhiro MORIKAWA
! Version::   $Id: gtvarputattrchar.f90,v 1.6 2009-05-25 09:55:57 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#Put_Attr
! 縺ｨ縺励※謠蝉ｾ帙＆繧後∪縺吶�

subroutine GTVarPutAttrLogical(var, name, value, err)
  !
  !== 螻樊ｧ縺ｮ莉伜刈
  !
  ! 螟画焚 *var* 縺ｫ, 螻樊ｧ蜷� *name* 縺ｨ縺昴�蛟､ *value* 繧剃ｻ伜刈縺励∪縺吶�
  !
  ! *Put_Attr* 縺ｯ隍�焚縺ｮ繧ｵ繝悶Ν繝ｼ繝√Φ縺ｮ邱冗ｧｰ蜷阪↑縺ｮ縺ｧ縲�
  ! *value* 縺ｫ縺ｯ讒倥�↑蝙九�螟画焚繧剃ｸ弱∴繧九％縺ｨ縺悟庄閭ｽ縺ｧ縺吶�
  ! 莉･荳九�繧ｵ繝悶Ν繝ｼ繝√Φ繧貞盾辣ｧ縺励※縺上□縺輔＞縲�
  !
  ! 蠑墓焚縺ｫ *xtype* 繧呈戟縺､繧ゅ�縺ｯ縲√◎縺ｮ蠑墓焚縺ｫ蝙九ｒ謖�ｮ壹☆繧九％縺ｨ縺ｧ縲�
  ! 蠑墓焚 *value* 縺ｫ縺ｯ譁�ｭ怜梛繧剃ｸ弱∴縺ｦ繧ゅ�
  ! 謨ｴ謨ｰ蝙九∝ｮ滓焚蝙� (蜊倡ｲｾ蠎ｦ縲∝咲ｲｾ蠎ｦ) 縺ｮ蛟､繧剃ｻ伜刈縺吶ｋ縺薙→縺悟庄閭ｽ縺ｧ縺吶�
  ! 荳玖ｨ倥�繧ｵ繝悶Ν繝ｼ繝√Φ繧貞盾辣ｧ縺上□縺輔＞縲�
  !
  ! 繧ｨ繝ｩ繝ｼ縺檎匱逕溘＠縺溷�ｴ蜷医∝ｼ墓焚 *err* 縺御ｸ弱∴繧峨ｌ繧句�ｴ蜷医� *err* 縺�
  ! <tt>.true.</tt> 縺ｨ縺ｪ縺｣縺ｦ霑斐ｊ縺ｾ縺吶�
  ! 蠑墓焚 *err* 繧剃ｸ弱∴縺ｪ縺代ｌ縺ｰ繝励Ο繧ｰ繝ｩ繝�縺ｯ蛛懈ｭ｢縺励∪縺吶�
  !
  use gtdata_types, only: GT_VARIABLE
  use gtdata_internal_map, only: var_class, vtb_class_netcdf, vtb_class_memory
  use gtdata_netcdf_generic, only: put_attr
  use gtdata_netcdf_types, only: GD_NC_VARIABLE
  use gtdata_memory_generic, only: put_attr
  use gtdata_memory_types, only: GD_MEM_VARIABLE
  use dc_string, only: toChar
  implicit none
  type(GT_VARIABLE),  intent(inout)        :: var
  character(len = *), intent(in)           :: name
  logical,            intent(in)           :: value
  logical,            intent(out), optional:: err
  integer:: class, cid
continue
  call var_class(var, class, cid)
  if (class == vtb_class_netcdf) then
    if (value) then
      call put_attr(GD_NC_VARIABLE(cid), name, "true", err=err)
    else
      call put_attr(GD_NC_VARIABLE(cid), name, "false", err=err)
    endif
  else if (class == vtb_class_memory) then
    if (value) then
      call put_attr(GD_MEM_VARIABLE(cid), name, "true")
    else
      call put_attr(GD_MEM_VARIABLE(cid), name, "false")
    endif
    if (present(err)) err = .false.
  endif
end subroutine GTVarPutAttrLogical

!subroutine GTVarPutAttrString(var, name, value, err)
!  !--
!  ! VSTRING 蝙九ｒ蠑輔″蜿悶ｊ荳願ｨ� put_attr 繧貞他縺ｳ蜃ｺ縺吶ゆｸ倶ｽ榊ｱ､縺ｮ縺薙→縺ｯ髢｢遏･縺励↑縺�
!  !++
!  use gtdata_types, only: GT_VARIABLE
!  use dc_string, only: VSTRING, vchar, operator(==), len
!  use gtdata_generic, only: put_attr
!  implicit none
!  type(GT_VARIABLE), intent(inout):: var
!  character(len = *), intent(in):: name
!  type(VSTRING), intent(in):: value
!  logical, intent(out), optional:: err
!continue
!  call put_attr(var, name, vchar(value, len(value)), err=err)
!end subroutine GTVarPutAttrString

subroutine GTVarPutAttrInt(var, name, value, err)
  !
  ! 縺ｾ縺壹�荳願ｨ倥� Put_Attr
  ! (縺ｾ縺溘� GTVarPutAttrChar 縺翫ｈ縺ｳ GTVarPutAttrReal)
  ! 繧貞盾辣ｧ縺励※縺上□縺輔＞縲�
  !
  ! *value* 縺ｯ驟榊�繧貞女縺大叙繧九�縺ｧ縲√せ繧ｫ繝ｩ繝ｼ繧呈嶌縺榊�縺吶↓縺ｯ
  ! Fortran 縺ｮ驟榊�讒区�蟄� <tt>(/ ... /)</tt> 繧剃ｽｿ縺｣縺ｦ縺上□縺輔＞縲�
  ! 縺溘→縺医�縲√せ繧ｫ繝ｩ繝ｼ a 縺九ｉ髟ｷ縺� 1 縺ｮ驟榊� <tt>(/a/)</tt>
  ! 繧剃ｽ懊ｋ縺薙→縺後〒縺阪∪縺吶�
  !
  use gtdata_types, only: GT_VARIABLE
  use gtdata_internal_map, only: var_class, vtb_class_netcdf, vtb_class_memory
  use gtdata_netcdf_generic, only: put_attr
  use gtdata_netcdf_types, only: GD_NC_VARIABLE
  use gtdata_memory_generic, only: put_attr
  use gtdata_memory_types, only: GD_MEM_VARIABLE
  use dc_string, only: toChar
  type(GT_VARIABLE), intent(inout):: var
  character(len = *), intent(in):: name
  integer, intent(in):: value(:)
  logical, intent(out), optional:: err
  integer:: class, cid
continue
  call var_class(var, class, cid)
  if (class == vtb_class_netcdf) then
    call put_attr(GD_NC_VARIABLE(cid), name, value, err)
  else if (class == vtb_class_memory) then
    call put_attr(GD_MEM_VARIABLE(cid), name, trim(toChar(value)))
    if (present(err)) err = .false.
  endif
end subroutine GTVarPutAttrInt

subroutine GTVarPutAttrReal(var, name, value, err)
  !
  ! 縺ｾ縺壹�荳願ｨ倥� Put_Attr
  ! (縺ｾ縺溘� GTVarPutAttrChar 縺翫ｈ縺ｳ GTVarPutAttrReal)
  ! 繧貞盾辣ｧ縺励※縺上□縺輔＞縲�
  !
  use gtdata_types, only: GT_VARIABLE
  use gtdata_internal_map, only: var_class, vtb_class_netcdf, vtb_class_memory
  use gtdata_netcdf_generic, only: put_attr
  use gtdata_netcdf_types, only: GD_NC_VARIABLE
  use gtdata_memory_generic, only: put_attr
  use gtdata_memory_types, only: GD_MEM_VARIABLE
  use dc_string, only: toChar
  implicit none
  type(GT_VARIABLE), intent(inout):: var
  character(len = *), intent(in):: name
  real, intent(in):: value(:)
  logical, intent(out), optional:: err
  integer:: class, cid
continue
  call var_class(var, class, cid)
  if (class == vtb_class_netcdf) then
    call put_attr(GD_NC_VARIABLE(cid), name, value, err)
  else if (class == vtb_class_memory) then
    call put_attr(GD_MEM_VARIABLE(cid), name, trim(toChar(value)))
    if (present(err)) err = .false.
  endif
end subroutine GTVarPutAttrReal

subroutine GTVarPutAttrDouble(var, name, value, err)
  !
  ! 縺ｾ縺壹�荳願ｨ倥� Put_Attr
  ! (縺ｾ縺溘� GTVarPutAttrChar 縺翫ｈ縺ｳ GTVarPutAttrReal)
  ! 繧貞盾辣ｧ縺励※縺上□縺輔＞縲�
  !
  use gtdata_types, only: GT_VARIABLE
  use gtdata_internal_map, only: var_class, vtb_class_netcdf, vtb_class_memory
  use gtdata_netcdf_generic, only: put_attr
  use gtdata_netcdf_types, only: GD_NC_VARIABLE
  use gtdata_memory_generic, only: put_attr
  use gtdata_memory_types, only: GD_MEM_VARIABLE
  use dc_string, only: toChar
  use dc_types, only: DP
  implicit none
  type(GT_VARIABLE), intent(inout):: var
  character(len = *), intent(in):: name
  real(DP), intent(in):: value(:)
  logical, intent(out), optional:: err
  integer:: class, cid
continue
  call var_class(var, class, cid)
  if (class == vtb_class_netcdf) then
    call put_attr(GD_NC_VARIABLE(cid), name, value, err)
  else if (class == vtb_class_memory) then
    call put_attr(GD_MEM_VARIABLE(cid), name, trim(toChar(value)))
    if (present(err)) err = .false.
  endif
end subroutine GTVarPutAttrDouble

subroutine GTVarPutAttrChar(var, name, value, xtype, err)
  !
  ! 縺ｾ縺壹�荳願ｨ倥� Put_Attr
  ! (縺ｾ縺溘� GTVarPutAttrChar)
  ! 繧貞盾辣ｧ縺励※縺上□縺輔＞縲�
  !
  ! *xtype* 縺ｫ蝙九ｒ謖�ｮ壹☆繧九％縺ｨ縺ｧ縲∝ｼ墓焚 *value* 縺ｫ縺ｯ譁�ｭ怜梛繧剃ｸ弱∴縺ｦ繧ゅ�
  ! 謨ｴ謨ｰ蝙九∝ｮ滓焚蝙� (蜊倡ｲｾ蠎ｦ縲∝咲ｲｾ蠎ｦ) 縺ｮ蛟､繧剃ｻ伜刈縺吶ｋ縺薙→縺悟庄閭ｽ縺ｧ縺吶�
  !
  ! *xtype* 縺ｫ縺ｯ荳弱∴繧区枚蟄怜�縺ｨ縺励※縲∽ｻ･荳九�繧ゅ�縺梧怏蜉ｹ縺ｧ縺吶�
  ! 縺薙ｌ繧我ｻ･螟悶�蝣ｴ蜷医�譁�ｭ怜梛縺ｮ蛟､縺御ｸ弱∴繧峨ｌ縺ｾ縺吶�
  !
  ! 謨ｴ謨ｰ蝙�          :: "INTEGER", "integer", "int"
  ! 螳滓焚蝙� (蜊倡ｲｾ蠎ｦ) :: "REAL", "real", "float"
  ! 螳滓焚蝙� (蛟咲ｲｾ蠎ｦ) :: "DOUBLEPRECISION", "DOUBLE", "double"
  !--
  ! gtdata/gtdata_netcdf/gdncputattrchar.f90#GDNcVarPutAttrChar 蜿ら�
  !++
  !
  use gtdata_types, only: GT_VARIABLE
  use gtdata_internal_map, only: var_class, vtb_class_netcdf, vtb_class_memory
  use gtdata_netcdf_generic, only: put_attr
  use gtdata_netcdf_types, only: GD_NC_VARIABLE
  use gtdata_memory_generic, only: put_attr
  use gtdata_memory_types, only: GD_MEM_VARIABLE
  use dc_trace, only: beginsub, endsub
  implicit none
  type(GT_VARIABLE), intent(inout):: var
  character(len = *), intent(in):: name
  character(len = *), intent(in):: value
  character(len = *), intent(in), optional:: xtype
  logical, intent(out), optional:: err
  integer:: class, cid
  character(*), parameter:: subnam = "gtvarputattrchar"
continue
  call beginsub(subnam, "%d:%c = %c", i=(/var%mapid/), c1=trim(name), c2=trim(value))
  call var_class(var, class, cid)
  if (class == vtb_class_netcdf) then
    call put_attr(GD_NC_VARIABLE(cid), name, value, xtype, err)
  else if (class == vtb_class_memory) then
    call put_attr(GD_MEM_VARIABLE(cid), name, value)
    if (present(err)) err = .false.
  endif
  call endsub(subnam)
end subroutine GTVarPutAttrChar