!
!= å¤‰æ•°ã®å±žæ€§å–å¾—
!
! Authors::   Eizi TOYODA, Yasuhiro MORIKAWA
! Version::   $Id: gtvarattrsearch.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 GTVarAttrRewind(var)
  !
  !== å¤‰æ•°ã‹ã‚‰ã®å±žæ€§ãƒªã‚¹ãƒˆå–å¾— (åˆæœŸåŒ–ç”¨)
  !
  ! *var* ã‹ã‚‰å±žæ€§åã®ãƒªã‚¹ãƒˆã‚’å–å¾—ã™ã‚‹ãŸã‚ã«åˆ©ç”¨ã™ã‚‹ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã§ã™ã€‚
  ! ã“ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã¨ Attr_Next ã«ã‚ˆã£ã¦å±žæ€§ãƒªã‚¹ãƒˆä¸€è¦§ã‚’å–å¾—ã§ãã¾ã™ã€‚
  !
  ! ã‚ã‚‹å¤‰æ•° *var* ã«ã¤ã„ã¦å…¨ã¦ã®å±žæ€§ã‚’åˆ—æŒ™ã™ã‚‹ãŸã‚ã«ã¯ã€ã¾ãš
  ! Attr_Rewind ã‚’å‘¼ã‚“ã å¾Œã€Attr_Next ã‚’å‘¼ã³ã¾ã™ã€‚æœ€åˆã®å‘¼ã³å‡ºã—ã§
  ! æœ€åˆã®å±žæ€§ãŒã€æ¬¡ã®å‘¼ã³å‡ºã—ã§æ¬¡ã®å±žæ€§ã®åå‰ãŒå¾—ã‚‰ã‚Œã¾ã™ã€‚æœ€å¾Œã®
  ! å±žæ€§ã®ã‚ã¨ã§ã¯ end == .true. ã¨ãªã‚Šã¾ã™ã€‚
  !
  ! ä»¥ä¸‹ã®ã‚µãƒ³ãƒ—ãƒ«ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã‚’å‚ç…§ãã ã•ã„ã€‚
  !
  !
  !      ! å±žæ€§ä¸€è¦§ã®å–å¾—
  !      use gtool5
  !      type(GT_VARIABLE):: var
  !      character(len = STRING):: attrname
  !      logical:: end
  !
  !      call Attr_Rewind(var)
  !      do
  !          call Attr_Next(var, attrname, end)
  !          if (end) exit
  !          write(*,*) trim(attrname)
  !      enddo
  !
  use gtdata_types, only: GT_VARIABLE
  use gtdata_internal_map, only: var_class, vtb_class_netcdf, vtb_class_memory
  use gtdata_netcdf_generic, only: attr_rewind
  use gtdata_netcdf_types, only: GD_NC_VARIABLE
  use gtdata_memory_generic, only: attr_rewind
  use gtdata_memory_types, only: GD_MEM_VARIABLE
  implicit none
  type(GT_VARIABLE), intent(inout), target:: var
  integer:: class, cid
continue
  call var_class(var, class, cid)
  select case(class)
  case(vtb_class_netcdf)
    call attr_rewind(GD_NC_VARIABLE(cid))
  case(vtb_class_memory)
    call attr_rewind(GD_MEM_VARIABLE(cid))
  end select
end subroutine GTVarAttrRewind

subroutine GTVarAttrNext(var, name, end)
  !
  !== å¤‰æ•°ã‹ã‚‰ã®å±žæ€§ãƒªã‚¹ãƒˆå–å¾—
  !
  ! Attr_Rewind ã‚’å‚ç…§ã—ã¦ãã ã•ã„ã€‚
  !
  use gtdata_types, only: GT_VARIABLE
  use gtdata_internal_map, only: var_class, vtb_class_netcdf, vtb_class_memory
  use gtdata_netcdf_generic, only: attr_next
  use gtdata_netcdf_types, only: GD_NC_VARIABLE
  use gtdata_memory_generic, only: attr_next
  use gtdata_memory_types, only: GD_MEM_VARIABLE
  implicit none
  type(GT_VARIABLE), intent(inout), target:: var
  character(len = *), intent(out):: name
  logical, intent(out), optional:: end
  integer:: class, cid
continue
  call var_class(var, class, cid)
  select case(class)
  case(vtb_class_netcdf)
    call attr_next(GD_NC_VARIABLE(cid), name, end)
  case(vtb_class_memory)
    call attr_next(GD_MEM_VARIABLE(cid), name, end)
  end select
end subroutine GTVarAttrNext