!
!= å±žæ€§ã®ä»˜åŠ
!
! 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