!
!= æ¬¡å…ƒã®å‰Šé™¤
!
! Authors::   Eizi TOYODA, Yasuhiro MORIKAWA
! Version::   $Id: gtvardeldim.f90,v 1.3 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 ã‹ã‚‰ gtdata_generic#Del_dim
! ã¨ã—ã¦æä¾›ã•ã‚Œã¾ã™ã€‚

subroutine GTVarDelDim(var, dimord, err)
  !
  !== æ¬¡å…ƒã®å‰Šé™¤
  !
  ! å¤‰æ•° *var* ã®æ¬¡å…ƒ *dimord* ã‚’å‰Šé™¤ã—ã¾ã™ã€‚
  ! æ¬¡å…ƒå¯¾å¿œè¡¨ã®é †ä½ã‚’ä¸‹ã’æœ‰åŠ¹æ¬¡å…ƒæ•°ã‚’ãƒ‡ã‚¯ãƒªãƒ¡ãƒ³ãƒˆã™ã‚‹ã ã‘ãªã®ã§ã€
  ! å½“è©²æ¬¡å…ƒãŒã™ã§ã«ç¸®é€€ã—ã¦ã„ã‚Œã°ã€ã“ã®æ“ä½œã®ã‚ã¨ã§ã‚‚å…¥å‡ºåŠ›ãŒå¯èƒ½ã§ã™ã€‚
  !
  ! ã‚¨ãƒ©ãƒ¼ãŒç”Ÿã˜ãŸå ´åˆã€ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’å‡ºåŠ›
  ! ã—ã¦ãƒ—ãƒã‚°ãƒ©ãƒ ã¯å¼·åˆ¶çµ‚äº†ã—ã¾ã™ã€‚*err* ã‚’ä¸Žãˆã¦ã‚ã‚‹å ´åˆã«ã¯
  ! ã®å¼•æ•°ã« .true. ãŒè¿”ã‚Šã€ãƒ—ãƒã‚°ãƒ©ãƒ ã¯çµ‚äº†ã—ã¾ã›ã‚“ã€‚
  !
  !--
  ! å®Ÿéš›ã«ã¯ã€æ¬¡å…ƒå¯¾å¿œè¡¨ã®é †ä½ã‚’ä¸‹ã’æœ‰åŠ¹æ¬¡å…ƒæ•°ã‚’ãƒ‡ã‚¯ãƒªãƒ¡ãƒ³ãƒˆ
  ! ã™ã‚‹ã ã‘ãªã®ã§ã€å…¥å‡ºåŠ›ã«æ”¯éšœã¯ãªã„ã€‚
  !
  ! NetCDF å®Ÿè£…ã«ãŠã„ã¦ã¯ã€å¤‰æ•°ã¯å‰Šé™¤ã•ã‚Œãšã€
  ! åˆ¥ã®åç§°ã«æ”¹åã•ã‚Œã‚‹ã ã‘ã§ã™ã€‚
  ! ã“ã‚Œã¯ netCDF API ã«å¤‰æ•°ã®å‰Šé™¤ãŒæ¬ ã‘ã¦ã„ã‚‹ãŸã‚ã§ã™ã€‚
  !++
  use gtdata_types, only: gt_variable
  use gtdata_internal_map, only: map_lookup, gt_dimmap, map_set_ndims, map_set
  use dc_trace, only: beginsub, endsub, DbgMessage
  implicit none
  type(gt_variable), intent(in):: var
  integer, intent(in):: dimord
  logical, intent(out):: err
  type(gt_dimmap), allocatable:: map(:)
  type(gt_dimmap):: tmpmap
  integer:: ndimsp, stat
  character(*), parameter:: subname = 'GTVarDelDim'
continue
  err = .true.
  call beginsub(subname)
  if (dimord < 1) then
    call endsub(subname, "negative dimord=%d invalid", i=(/dimord/))
    return
  endif
  call map_lookup(var, ndims=ndimsp)
  if (ndimsp <= 0) then
    call endsub(subname, "variable invalid")
    return
  else if (dimord > ndimsp) then
    call endsub(subname, "dimord=%d not exist", i=(/dimord/))
    return
  endif

  allocate(map(ndimsp))
  call map_lookup(var, map=map)
  tmpmap = map(dimord)
  map(dimord: ndimsp-1) = map(dimord+1: ndimsp)
  map(ndimsp) = tmpmap
  call map_set(var, map, stat)
  deallocate(map)

  call map_set_ndims(var, ndims = ndimsp - 1, stat=stat)
  err = stat /= 0
  call endsub(subname)
end subroutine GTVarDelDim