subroutine GTVarClose(var, err)
implicit none
type(GT_VARIABLE), intent(in), target:: var
logical, intent(out), optional:: err
integer:: vid, class, cid
logical:: action, myerr
continue
call beginsub('gtvarclose', fmt='var=%d', i=(/var%mapid/))
call map_lookup(var, vid=vid)
call maptabdelete(var, myerr)
if (myerr) goto 999
! vid が 0 になるのは dup_dimmap で作られたハンドル
if (vid == 0) goto 999
call vartablelookup(vid, class, cid)
call vartabledelete(vid, action, myerr)
if (myerr) goto 999
if (.not. action) then
call DbgMessage('refcount decrement only, no close internal var')
goto 999
else if (class == vtb_class_netcdf) then
call ANVarClose(an_variable(cid), myerr)
if (myerr) goto 999
else if (class == vtb_class_memory) then
call Close(mem_variable(cid))
myerr = .false.
else
call StoreError(GT_EBADVAR, "GTVarClose", err)
call endsub('GTVarClose', 'badvar')
myerr = .true.
endif
999 continue
call endsub('gtvarclose')
if (present(err)) err = myerr
end subroutine