gtvarclose.f90
Go to the documentation of this file.
1 !
2 != 変数の終了処理
3 !
4 ! Authors:: Yasuhiro MORIKAWA, Eizi TOYODA
5 ! Version:: $Id: gtvarclose.f90,v 1.5 2009-05-25 09:55:58 morikawa Exp $
6 ! Tag Name:: $Name: $
7 ! Copyright:: Copyright (C) GFD Dennou Club, 2000-2005. All rights reserved.
8 ! License:: See COPYRIGHT[link:../../COPYRIGHT]
9 !
10 ! 以下のサブルーチン, 関数は gtdata_generic から提供されます。
11 !
12 
13 subroutine gtvarclose(var, err)
14  !
15  !== 変数の終了処理
16  !
17  ! 変数 *var* の終了処理を行います。Open または Create されたものは
18  ! プログラムの最後に必ずこのサブルーチンを用いて終了処理を行ってください。
19  !
20  ! 終了処理の際にエラーが生じた場合、メッセージを出力してプログラムは
21  ! 強制終了します。*err* を与えてある場合にはこの引数に .true.
22  ! が返り、プログラムは終了しません。
23  !
24  use gtdata_types, only: gt_variable
25  use gtdata_internal_map, only: vtb_class_netcdf, vtb_class_memory, &
28  use gtdata_netcdf_generic, only: close
31  use dc_trace, only: beginsub, endsub, dbgmessage
32  use gtdata_memory_generic, only: close
34  implicit none
35  type(gt_variable), intent(in), target:: var
36  logical, intent(out), optional:: err
37  integer:: vid, class, cid
38  logical:: action, myerr
39 continue
40  call beginsub('gtvarclose', fmt='var=%d', i=(/var%mapid/))
41  call map_lookup(var, vid=vid)
42  call maptabdelete(var, myerr)
43  if (myerr) goto 999
44  ! vid が 0 になるのは dup_dimmap で作られたハンドル
45  if (vid == 0) goto 999
46  call vartablelookup(vid, class, cid)
47  call vartabledelete(vid, action, myerr)
48  if (myerr) goto 999
49  if (.not. action) then
50  call dbgmessage('refcount decrement only, no close internal var')
51  goto 999
52  else if (class == vtb_class_netcdf) then
53  call close(gd_nc_variable(cid), myerr)
54  if (myerr) goto 999
55  else if (class == vtb_class_memory) then
56  call close(gd_mem_variable(cid))
57  myerr = .false.
58  else
59  call storeerror(gt_ebadvar, "GTVarClose", err)
60  call endsub('GTVarClose', 'badvar')
61  myerr = .true.
62  endif
63 999 continue
64  call endsub('gtvarclose')
65  if (present(err)) err = myerr
66 end subroutine gtvarclose
subroutine, public vartabledelete(vid, action, err)
subroutine gtvarclose(var, err)
Definition: gtvarclose.f90:14
subroutine, public maptabdelete(var, err)
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition: dc_error.f90:830
integer, parameter, public gt_ebadvar
Definition: dc_error.f90:539
integer, parameter, public dc_noerr
Definition: dc_error.f90:509
subroutine, public dbgmessage(fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:509
subroutine, public beginsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca, version)
Definition: dc_trace.f90:351
subroutine, public vartablelookup(vid, class, cid)
subroutine, public map_lookup(var, vid, map, ndims)
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446