gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
gtvaropenbydimord.f90
Go to the documentation of this file.
1!> @file gtvaropenbydimord.f90
2!>
3!> @author Yasuhiro MORIKAWA, Eizi TOYODA
4!> @copyright Copyright (C) GFD Dennou Club, 2000-2026. All rights reserved. <br/>
5!> License is BSD-2-Clause. See [COPYRIGHT](@ref COPYRIGHT) in detail
6!>
7!> @en
8!> @brief Open GT_VARIABLE of dimension by dimord
9!>
10!> This subroutine is provided through gtdata_generic.
11!> @enden
12!>
13!> @ja
14!> @brief 次元順序番号による GT_VARIABLE のオープン
15!>
16!> このサブルーチンは gtdata_generic から提供されます。
17!> @endja
18!>
19
20!>
21!> @en
22!> @brief Open dimension variable by order number
23!>
24!> Opens the variable corresponding to the dimord-th dimension of
25!> already-opened variable source_var and stores it in var.
26!> The order dimord skips dimensions with width 1 (compacted),
27!> but if count_compact is set to .true., all dimensions are counted.
28!>
29!> Variables opened with Open must always be closed with Close.
30!>
31!> When dimord == 0, the variable itself is reopened, incrementing
32!> the reference counter.
33!>
34!> Open is a generic name for 2 subroutines; it is also possible
35!> to open by specifying the variable URL directly.
36!> @param[out] var Variable handle
37!> @param[in] source_var Source variable
38!> @param[in] dimord Dimension order number
39!> @param[in] count_compact Include compact dimensions (optional)
40!> @param[in] inherit_slice Inherit current slice state (optional)
41!> @param[out] err Error flag (optional)
42!> @enden
43!>
44!> @ja
45!> @brief 次元順序番号による次元変数のオープン
46!>
47!> 既に開かれた変数 source_var の dimord 番目の次元にあたる変数を
48!> 開き var に格納します。順序 dimord は現在の入出力範囲が
49!> 幅1になっている (コンパクト化している) を飛ばした順序ですが、
50!> count_compact に .true. を指定するとすべての次元のなかの順序になります。
51!>
52!> Open された変数は必ず Close されなければなりません。
53!>
54!> dimord == 0 の場合は変数自体を再度開きます。これは参照カウンタを
55!> 増加させる手段です。
56!>
57!> Open は 2 つのサブルーチンの総称名であり、
58!> 変数 URL を直接指定することで開くことも可能です。
59!> @param[out] var 変数ハンドル
60!> @param[in] source_var 元の変数
61!> @param[in] dimord 次元順序番号
62!> @param[in] count_compact コンパクト次元を含むか (省略可能)
63!> @param[in] inherit_slice 現在のスライス状態を引き継ぐか (省略可能)
64!> @param[out] err エラーフラグ (省略可能)
65!> @endja
66!>
67subroutine gtvaropenbydimord(var, source_var, dimord, count_compact, inherit_slice, err)
68 use gtdata_types, only: gt_variable
69 use gtdata_internal_map, only: var_class, vtb_class_netcdf, &
74 use gtdata_generic, only: gt_open => open
77 use dc_string, only: cprintf
80 use dc_types, only: string
81 implicit none
82 type(gt_variable), intent(out):: var
83 type(gt_variable), intent(in):: source_var
84 integer, intent(in):: dimord
85 logical, intent(in), optional:: count_compact
86 logical, intent(in), optional:: inherit_slice
87 logical, intent(out), optional:: err
88 integer:: sclass, scid, ld, sndims, stat, udimord, idimord, cause_i
89 type(gd_nc_variable):: gdnc
90 type(gt_dimmap), allocatable:: map_src(:)
91 type(gt_dimmap):: map_result(1)
92 logical:: cnt_compact, keep_slice
93 character(STRING) :: endsub_msg
94 character(len = *), parameter:: subname = "GTVarOpen-By-Dimord"
95 character(len = *), parameter:: version = &
96 & '$Name: $' // &
97 & '$Id: gtvaropenbydimord.f90,v 1.5 2009-07-04 04:58:06 morikawa Exp $'
98continue
99 call beginsub(subname, 'var.mapid=%d dimord=%d ', &
100 & i=(/source_var%mapid, dimord/), version=version)
101 stat = dc_noerr
102 cause_i = dimord
103 endsub_msg = ''
104
105 ! 変数それ自体を開き直す処理
106 if (dimord == 0) then
107 call map_dup(var, source_var)
108 if (present(err)) err = .false.
109 endsub_msg = 'dup'
110 goto 999
111 endif
112
113 ! 表を引き、dimord 番 (count_compact に注意) の次元の内部変数
114 ! 次元番号を調べる。
115 call map_lookup(source_var, ndims=sndims)
116 if (sndims <= 0 .or. dimord > sndims) then
117 stat = gt_enomoredims
118 goto 999
119 endif
120 allocate(map_src(sndims))
121 call map_lookup(source_var, map=map_src)
122 cnt_compact = .false.
123 if (present_and_true(count_compact)) then
124 cnt_compact = .true.
125 else
126 cnt_compact = .false.
127 end if
128 keep_slice = .true.
129 if (present_and_false(inherit_slice)) then
130 keep_slice = .false.
131 end if
132 call dbgmessage('count_compact=%y', l=(/cnt_compact/))
133
134 if (cnt_compact) then
135 udimord = dimord
136 else
137 udimord = dimord_skip_compact(dimord, map=map_src)
138 endif
139 if (udimord <= 0 .or. udimord > size(map_src)) then
140 stat = gt_enomoredims
141 goto 999
142 endif
143
144 idimord = map_src(udimord)%dimno
145 if (idimord < 1) then
146 call gt_open(var, map_src(udimord)%url, err=err)
147 ! storeerror はしなくてよい
148 deallocate(map_src)
149 goto 999
150 endif
151
152 ! 実態種別に合わせ「次元変数オープン」処理
153 call var_class(source_var, sclass, scid)
154 if (sclass == vtb_class_netcdf) then
155 call open(gdnc, gd_nc_variable(scid), idimord, err)
156 call inquire(gdnc, dimlen=ld)
157 call map_create(var, vtb_class_netcdf, gdnc%id, 1, (/ld/), stat)
158 if (stat /= dc_noerr) then
159 cause_i = 1
160 goto 999
161 end if
162 call map_lookup(var, map=map_result)
163 map_result(1)%offset = map_src(udimord)%offset
164 map_result(1)%step = map_src(udimord)%step
165 map_result(1)%allcount = map_src(udimord)%allcount
166 if (keep_slice) then
167 map_result(1)%start = map_src(udimord)%start
168 map_result(1)%count = map_src(udimord)%count
169 map_result(1)%stride = map_src(udimord)%stride
170 else
171 map_result(1)%start = 1
172 map_result(1)%count = map_src(udimord)%allcount
173 map_result(1)%stride = 1
174 end if
175 call map_set(var, map=map_result, stat=stat)
176 else
177 stat = gt_efake
178 endif
179
180 deallocate(map_src)
181 endsub_msg = cprintf('result_var=%d', i=(/var%mapid/))
182999 continue
183 call storeerror(stat, subname, cause_i=cause_i, err=err)
184 call endsub(subname, '%c', c1=trim(endsub_msg))
185end subroutine gtvaropenbydimord
subroutine gtvaropenbydimord(var, source_var, dimord, count_compact, inherit_slice, err)
エラー処理用モジュール
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
integer, parameter, public gt_efake
正のエラー番号は libc システムエラーメッセージのために あけてある。システム依存性が大きく、非常に大きな数値も 用いられるので空き領域を確保するのは困難である。
Definition dc_error.f90:503
integer, parameter, public dc_noerr
エラー等を保持
Definition dc_error.f90:468
integer, parameter, public gt_enomoredims
-101 以下: データ構造のエラー
Definition dc_error.f90:507
省略可能な制御パラメータの判定
logical function, public present_and_false(arg)
logical function, public present_and_true(arg)
文字型変数の操作
Definition dc_string.f90:83
デバッグ時の追跡用モジュール
Definition dc_trace.f90:150
subroutine, public dbgmessage(fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:661
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
Definition dc_trace.f90:457
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:580
種別型パラメタを提供します。
Definition dc_types.f90:55
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition dc_types.f90:137
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)