gtvaropenbydimord.f90
Go to the documentation of this file.
1 !== Open GT_VARIABLE of dimension by dimord
2 !
3 ! Authors:: Yasuhiro MORIKAWA, Eizi TOYODA
4 ! Version:: $Id: gtvaropenbydimord.f90,v 1.5 2009-07-04 04:58:06 morikawa Exp $
5 ! Tag Name:: $Name: $
6 ! Copyright:: Copyright (C) GFD Dennou Club, 2000-2005. All rights reserved.
7 ! License:: See COPYRIGHT[link:../../COPYRIGHT]
8 !
9 ! 以下のサブルーチン, 関数は gtdata_generic から提供されます。
10 !
11 
12 subroutine gtvaropenbydimord(var, source_var, dimord, count_compact, err)
13  !
14  !== gtool4 データのオープン
15  !
16  ! 既に開かれた変数 *source_var* の *dimord* 番目の次元にあたる変数を
17  ! 開き var に格納します。順序 *dimord* は現在の入出力範囲が
18  ! 幅1になっている (コンパクト化している) を飛ばした
19  ! 順序であすが、*count_compact* に <tt>.true.</tt>を指定すると
20  ! すべての次元のなかの順序になります。
21  !
22  ! Open された変数は必ず Close されなければなりません。
23  !
24  ! *dimord* == 0 の場合は変数自体を再度開きます。これは参照カウンタを
25  ! 増加させる手段です。
26  !
27  ! *Open* は 2 つのサブルーチンの総称名であり、
28  ! 変数 URL を直接指定することで開くことも可能です。
29  ! 下記のサブルーチンを参照ください。
30  !
31  !=== 補足
32  !
33  ! 変数 URL にファイル名部を指定しない場合、gtool.nc であるとみなされます。
34  !
35  ! 変数 URL にファイル名だけを指定した場合、開かれる変数は以下の規則
36  ! で選択されます。
37  !
38  ! * 次元変数は選択されない
39  ! * なるべく先に定義された変数が選択される
40  !
41  use gtdata_types, only: gt_variable
42  use gtdata_internal_map, only: var_class, vtb_class_netcdf, vtb_class_memory, &
47  use gtdata_generic, only: gt_open => open
48  use dc_present, only: present_and_true
49  use dc_trace, only: beginsub, endsub, dbgmessage
50  use dc_string, only: cprintf
53  use dc_types, only: string
54  implicit none
55  type(gt_variable), intent(out):: var
56  type(gt_variable), intent(in):: source_var
57  integer, intent(in):: dimord
58  logical, intent(in), optional:: count_compact
59  logical, intent(out), optional:: err
60  integer:: sclass, scid, ld, sndims, stat, udimord, idimord, cause_i
61  type(gd_nc_variable):: gdnc
62  type(gt_dimmap), allocatable:: map_src(:)
63  type(gt_dimmap):: map_result(1)
64  logical:: cnt_compact
65  character(STRING) :: endsub_msg
66  character(len = *), parameter:: subname = "GTVarOpen-By-Dimord"
67  character(len = *), parameter:: version = &
68  & '$Name: $' // &
69  & '$Id: gtvaropenbydimord.f90,v 1.5 2009-07-04 04:58:06 morikawa Exp $'
70 continue
71  call beginsub(subname, 'var.mapid=%d dimord=%d ', &
72  & i=(/source_var%mapid, dimord/), version=version)
73  stat = dc_noerr
74  cause_i = dimord
75  endsub_msg = ''
76 
77  ! 変数それ自体を開き直す処理
78  if (dimord == 0) then
79  call map_dup(var, source_var)
80  if (present(err)) err = .false.
81  endsub_msg = 'dup'
82  goto 999
83  endif
84 
85  ! 表を引き、dimord 番 (count_compact に注意) の次元の内部変数
86  ! 次元番号を調べる。
87  call map_lookup(source_var, ndims=sndims)
88  if (sndims <= 0 .or. dimord > sndims) then
89  stat = gt_enomoredims
90  goto 999
91  endif
92  allocate(map_src(sndims))
93  call map_lookup(source_var, map=map_src)
94  cnt_compact = .false.
95  if (present_and_true(count_compact)) then
96  cnt_compact = .true.
97  else
98  cnt_compact = .false.
99  end if
100  call dbgmessage('count_compact=%y', l=(/cnt_compact/))
101 
102  if (cnt_compact) then
103  udimord = dimord
104  else
105  udimord = dimord_skip_compact(dimord, map=map_src)
106  endif
107  if (udimord <= 0 .or. udimord > size(map_src)) then
108  stat = gt_enomoredims
109  goto 999
110  endif
111 
112  idimord = map_src(udimord)%dimno
113  if (idimord < 1) then
114  call gt_open(var, map_src(udimord)%url, err=err)
115  ! storeerror はしなくてよい
116  deallocate(map_src)
117  goto 999
118  endif
119 
120  ! 実態種別に合わせ「次元変数オープン」処理
121  call var_class(source_var, sclass, scid)
122  if (sclass == vtb_class_netcdf) then
123  call open(gdnc, gd_nc_variable(scid), idimord, err)
124  call inquire(gdnc, dimlen=ld)
125  call map_create(var, vtb_class_netcdf, gdnc%id, 1, (/ld/), stat)
126  if (stat /= dc_noerr) then
127  cause_i = 1
128  goto 999
129  end if
130  call map_lookup(var, map=map_result)
131  map_result(1)%offset = map_src(udimord)%offset
132  map_result(1)%step = map_src(udimord)%step
133  map_result(1)%allcount = map_src(udimord)%allcount
134  map_result(1)%start = map_src(udimord)%start
135  map_result(1)%count = map_src(udimord)%count
136  map_result(1)%stride = map_src(udimord)%stride
137  call map_set(var, map=map_result, stat=stat)
138  else if (sclass == vtb_class_memory) then
139  var = source_var
140  stat = dc_noerr
141  else
142  stat = gt_efake
143  endif
144 
145  deallocate(map_src)
146  endsub_msg = CPrintf('result_var=%d', i=(/var%mapid/))
147 999 continue
148  call storeerror(stat, subname, cause_i=cause_i, err=err)
149  call endsub(subname, '%c', c1=trim(endsub_msg))
150 end subroutine gtvaropenbydimord
subroutine map_dup(var, source_var)
logical function, public present_and_true(arg)
Definition: dc_present.f90:80
integer, parameter, public gt_efake
Definition: dc_error.f90:523
integer function dimord_skip_compact(dimord, map)
subroutine, public map_create(var, class, cid, ndims, allcount, stat)
subroutine map_set(var, map, stat)
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition: dc_error.f90:830
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
文字型変数の操作.
Definition: dc_string.f90:24
種別型パラメタを提供します。
Definition: dc_types.f90:49
subroutine gtvaropenbydimord(var, source_var, dimord, count_compact, err)
subroutine, public map_lookup(var, vid, map, ndims)
integer, parameter, public gt_enomoredims
Definition: dc_error.f90:528
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446
subroutine, public var_class(var, class, cid)
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118