Loading...
Searching...
No Matches
gtvaropenbydimord.f90 File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine gtvaropenbydimord (var, source_var, dimord, count_compact, err)

Function/Subroutine Documentation

◆ gtvaropenbydimord()

subroutine gtvaropenbydimord ( type(gt_variable), intent(out) var,
type(gt_variable), intent(in) source_var,
integer, intent(in) dimord,
logical, intent(in), optional count_compact,
logical, intent(out), optional err )

Definition at line 12 of file gtvaropenbydimord.f90.

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, &
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 $'
70continue
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
139 stat = gt_efake
140 endif
141
142 deallocate(map_src)
143 endsub_msg = cprintf('result_var=%d', i=(/var%mapid/))
144999 continue
145 call storeerror(stat, subname, cause_i=cause_i, err=err)
146 call endsub(subname, '%c', c1=trim(endsub_msg))
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:830
integer, parameter, public gt_efake
Definition dc_error.f90:523
integer, parameter, public dc_noerr
Definition dc_error.f90:509
integer, parameter, public gt_enomoredims
Definition dc_error.f90:528
Provides kind type parameter values.
Definition dc_types.f90:49
integer, parameter, public string
Character length for string
Definition dc_types.f90:118
subroutine, public map_lookup(var, vid, map, ndims)
subroutine map_set(var, map, stat)
integer function dimord_skip_compact(dimord, map)
subroutine, public var_class(var, class, cid)
subroutine, public map_create(var, class, cid, ndims, allcount, stat)
subroutine map_dup(var, source_var)

References dc_error::dc_noerr, gtdata_internal_map::dimord_skip_compact(), dc_error::gt_efake, dc_error::gt_enomoredims, gtdata_internal_map::map_create(), gtdata_internal_map::map_dup(), gtdata_internal_map::map_lookup(), gtdata_internal_map::map_set(), dc_error::storeerror(), dc_types::string, and gtdata_internal_map::var_class().

Here is the call graph for this function: