!
!= å…¥å‡ºåŠ›ç¯„å›²ã®æŒ‡å®š
!
! Authors::   Eizi TOYODA, Yasuhiro MORIKAWA
! Version::   $Id: gtvarsliceauto.f90,v 1.1 2009-03-20 09:09:51 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#Slice
! ã¨ã—ã¦æä¾›ã•ã‚Œã¾ã™ã€‚

subroutine GTVarSliceAuto(var, compatible)
  !
  !== å…¥å‡ºåŠ›ç¯„å›²ã‚’ãŠã¾ã‹ã›æŒ‡ç¤º
  !
  ! å¤‰æ•° *var* ã®å…¥å‡ºåŠ›ç¯„å›²ã‚’ã€Œé©å½“ã«ã€å°ã•ãã—ã¾ã™ã€‚
  ! *compatible* ã‚’æŒ‡å®šã™ã‚‹ã¨ã€ãã®å¤‰æ•°ã¨å…¨ãåŒã˜å…¥å‡ºåŠ›ç¯„å›²ã«
  ! ã«æŒ‡å®šã—ã¾ã™ã€‚
  !
  ! *Slice* ã¯è¤‡æ•°ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã®ç·ç§°åã§ã‚ã‚Šã€
  ! ä»–ã«ã‚‚æ–‡å—åˆ—ã‚„ç•ªå·ã§æŒ‡å®šã™ã‚‹æ–¹æ³•ãŒã‚ã‚Šã¾ã™ã€‚
  ! ä»¥ä¸‹ã®ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã‚’å‚ç…§ã—ã¦ãã ã•ã„ã€‚
  !
  ! Slice ã«é–¢é€£ã™ã‚‹æ‰‹ç¶šãã¨ã—ã¦ã€Get_Slice ã¨ Slice_Next ãŒ
  ! ã‚ã‚Šã¾ã™ã€‚Get_Slice ã¯è¨å®šã•ã‚ŒãŸå…¥å‡ºåŠ›ç¯„å›²ã‚’å–å¾—ã—ã¾ã™ã€‚
  ! Slice_Next ã¯å…¥å‡ºåŠ›ç¯„å›²ã‚’ç§»å‹•ã™ã‚‹ã“ã¨ã«ã‚ˆã£ã¦ã€å¤‰æ•°å…¨ä½“ã‚’èªã¿å–ã‚‹
  ! ãŸã‚ã«åˆ©ç”¨ã™ã‚‹ã‚µãƒ–ãƒ«ãƒ¼ãƒãƒ³ã§ã™ã€‚
  !
  use gtdata_types, only: GT_VARIABLE
  use gtdata_generic, only: Inquire, Get_Slice, GTVarSlice
  type(GT_VARIABLE), intent(inout):: var
  type(GT_VARIABLE), intent(in), optional:: compatible
  integer:: nd, i
  integer, allocatable:: start(:), count(:), stride(:)
  call Inquire(var, alldims=nd)
  if (nd <= 0) return
  allocate(start(nd), count(nd), stride(nd))
  if (present(compatible)) then
    call Get_Slice(compatible, start, count, stride)
    do, i = 1, nd
      call GTVarSlice(var, i, start(i), count(i), stride(i))
    enddo
  else
    call Get_Slice(var, start, count, stride)
    do, i = 1, nd
      if (count(i) < 1) count(i) = 1
      call GTVarSlice(var, i, start(i), count(i), stride(i))
    enddo
  endif
  deallocate(start, count, stride)
end subroutine GTVarSliceAuto