gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
historyinquire.f90
Go to the documentation of this file.
1!> @file historyinquire.f90
2!>
3!> @author Yasuhiro MORIKAWA
4!> @copyright Copyright (C) GFD Dennou Club, 2004-2026. All rights reserved. <br/>
5!> License is BSD-2-Clause. See [COPYRIGHT](@ref COPYRIGHT) in detail
6!>
7!> @en
8!> @brief Inquire for a GT_HISTORY variable
9!> @enden
10!>
11!> @ja
12!> @brief GT_HISTORY 型変数への問い合わせ
13!> @endja
14
15!>
16!> @en
17!> @brief Inquire a GT_HISTORY variable
18!>
19!> Retrieves values set by HistoryCreate, HistoryAddVariable, etc.
20!> For file, title, source, institution, origin, interval,
21!> conventions, gt_version, dims, dimsizes, longnames, units,
22!> xtypes, see HistoryCreate.
23!>
24!> For title, source, institution, origin, interval, conventions,
25!> gt_version, "unknown" is returned if values are not available.
26!>
27!> dims, dimsizes, longnames, units, xtypes return values via
28!> pointer; pass null pointers.
29!>
30!> axes and varinfo return axis and variable information respectively.
31!>
32!> HistoryInquire is a generic name for two subroutines.
33!>
34!> @param[in] history History handle
35!> @param[out] err Error flag (optional)
36!> @param[out] file Output file name (optional)
37!> @param[out] title Title (optional)
38!> @param[out] source Source (optional)
39!> @param[out] institution Institution (optional)
40!> @param[out] origin Origin time (optional)
41!> @param[out] interval Output interval (optional)
42!> @param[out] newest Newest time (optional)
43!> @param[out] oldest Oldest time (optional)
44!> @param[out] conventions Conventions (optional)
45!> @param[out] gt_version gt_version (optional)
46!> @param[out] dims Dimension names (pointer, optional)
47!> @param[out] dimsizes Dimension sizes (pointer, optional)
48!> @param[out] longnames Long names (pointer, optional)
49!> @param[out] units Units (pointer, optional)
50!> @param[out] xtypes Types (pointer, optional)
51!> @param[out] axes Axis information (pointer, optional)
52!> @param[out] varinfo Variable information (pointer, optional)
53!> @enden
54!>
55!> @ja
56!> @brief GT_HISTORY 型変数への問い合わせ
57!>
58!> HistoryCreate や HistoryAddVariable などで設定した値の
59!> 参照を行います。
60!>
61!> file, title, source, institution, origin, interval,
62!> conventions, gt_version, dims, dimsizes, longnames, units,
63!> xtypes に関しては HistoryCreate を参照してください。
64!>
65!> title, source, institution, origin, interval, conventions, gt_version
66!> に関しては、値が得られなかった場合は "unknown" が返ります。
67!>
68!> dims, dimsizes, longnames, units, xtypes に関してはポインタに
69!> 値を返すため、必ずポインタを空状態にしてから与えてください。
70!>
71!> axes と varinfo にはそれぞれ座標軸情報と変数情報を返します。
72!>
73!> HistoryInquire は 2 つのサブルーチンの総称名です。
74!> @param[in] history ヒストリーハンドル
75!> @param[out] err エラーフラグ (省略可能)
76!> @param[out] file 出力ファイル名 (省略可能)
77!> @param[out] title タイトル (省略可能)
78!> @param[out] source ソース (省略可能)
79!> @param[out] institution 組織 (省略可能)
80!> @param[out] origin 開始時間 (省略可能)
81!> @param[out] interval 出力時間間隔 (省略可能)
82!> @param[out] newest 最新の時刻 (省略可能)
83!> @param[out] oldest 最初の時刻 (省略可能)
84!> @param[out] conventions 規約 (省略可能)
85!> @param[out] gt_version gtバージョン (省略可能)
86!> @param[out] dims 次元名 (ポインタ, 省略可能)
87!> @param[out] dimsizes 次元サイズ (ポインタ, 省略可能)
88!> @param[out] longnames 長い名前 (ポインタ, 省略可能)
89!> @param[out] units 単位 (ポインタ, 省略可能)
90!> @param[out] xtypes 型 (ポインタ, 省略可能)
91!> @param[out] axes 座標軸情報 (ポインタ, 省略可能)
92!> @param[out] varinfo 変数情報 (ポインタ, 省略可能)
93!> @endja
94!>
95 subroutine historyinquire1(history, err, file, title, source, &
96 & dims, dimsizes, longnames, units, xtypes, &
97 & institution, origin, interval, newest, oldest, &
98 & conventions, gt_version, &
99 & axes, varinfo )
100 !
103 use gtdata_types, only: gt_variable
104 use dc_url, only: urlsplit
105 use dc_error, only: storeerror, dc_noerr, gt_ebadhistory, nf90_enotvar
106 use dc_trace, only: beginsub, endsub
107 use dc_types, only: string, token
108 implicit none
109 type(gt_history), intent(in):: history
110 logical, intent(out), optional :: err
111 character(*), intent(out), optional:: file, title, source, institution
112 real,intent(out), optional:: origin, interval
113 real,intent(out), optional:: newest ! 最新の時刻
114 real,intent(out), optional:: oldest ! 最初の時刻
115 character(*), intent(out), optional:: conventions, gt_version
116 character(*), pointer, optional:: dims(:) ! (out)
117 integer,pointer, optional:: dimsizes(:) ! (out)
118 character(*), pointer, optional:: longnames(:) ! (out)
119 character(*), pointer, optional:: units(:) ! (out)
120 character(*), pointer, optional:: xtypes(:) ! (out)
121 type(gt_history_axis), pointer, optional :: axes(:) ! (out)
122 type(gt_history_varinfo), pointer, optional :: varinfo(:) ! (out)
123
124 ! Internal Work
125 character(STRING) :: url, cause_c
126 character(TOKEN) :: unknown_mes = 'unknown'
127 integer :: i, j, numdims, numvars, alldims, stat
128 logical :: growable
129 type(gt_variable) :: dimvar
130 character(*), parameter:: subname = "HistoryInquire1"
131 continue
132 call beginsub(subname)
133 stat = dc_noerr
134 cause_c = ''
135 if (.not. associated(history % dimvars) .or. &
136 & size(history % dimvars) < 1) then
137 stat = gt_ebadhistory
138 goto 999
139 end if
140
141 if (present(file)) then
142 call inquire(history % dimvars(1), url=url)
143 call urlsplit(fullname=url, file=file)
144 end if
145 if (present(title)) then
146 call get_attr(history % dimvars(1), '+title', title, trim(unknown_mes))
147 end if
148 if (present(source)) then
149 call get_attr(history % dimvars(1), '+source', source, trim(unknown_mes))
150 end if
151 if (present(institution)) then
152 call get_attr(history % dimvars(1), '+institution', institution, trim(unknown_mes))
153 end if
154
155 if (present(origin)) then
156 origin = real(history % origin, kind=kind(origin))
157! origin = EvalByUnit( history % origin, '', history % unlimited_units_symbol )
158 end if
159 if (present(interval)) then
160 interval = real(history % interval, kind=kind(interval))
161! interval = EvalByUnit( history % interval, '', history % unlimited_units_symbol )
162 end if
163 if (present(newest)) then
164 newest = real(history % newest, kind=kind(newest))
165! newest = EvalByUnit( history % newest, '', history % unlimited_units_symbol )
166 end if
167 if (present(oldest)) then
168 oldest = real(history % oldest, kind=kind(oldest))
169! oldest = EvalByUnit( history % oldest, '', history % unlimited_units_symbol )
170 end if
171 if (present(conventions)) then
172 call get_attr(history % dimvars(1), '+Conventions', conventions, trim(unknown_mes))
173 end if
174 if (present(gt_version)) then
175 call get_attr(history % dimvars(1), '+gt_version', gt_version, trim(unknown_mes))
176 end if
177 if (present(dims)) then
178 numdims = size(history % dimvars)
179 allocate(dims(numdims))
180 do i = 1, numdims
181 call inquire(history % dimvars(i), name=dims(i))
182 end do
183 end if
184 if (present(dimsizes)) then
185 numdims = size(history % dimvars)
186 allocate(dimsizes(numdims))
187 do i = 1, numdims
188 call inquire(history % dimvars(i), size=dimsizes(i), growable=growable)
189 if (growable) dimsizes(i) = 0
190 end do
191 end if
192 if (present(longnames)) then
193 numdims = size(history % dimvars)
194 allocate(longnames(numdims))
195 do i = 1, numdims
196 call get_attr(history % dimvars(i), 'long_name', &
197 & longnames(i), 'unknown')
198 end do
199 end if
200 if (present(units)) then
201 numdims = size(history % dimvars)
202 allocate(units(numdims))
203 do i = 1, numdims
204 call get_attr(history % dimvars(i), 'units', &
205 & units(i), 'unknown')
206 end do
207 end if
208 if (present(xtypes)) then
209 numdims = size(history % dimvars)
210 allocate(xtypes(numdims))
211 do i = 1, numdims
212 call inquire(history % dimvars(i), xtype=xtypes(i))
213 end do
214 end if
215 if (present(axes)) then
216 numvars = size(history % dimvars)
217 allocate(axes(numvars))
218 do i = 1, numvars
219 call inquire(history % dimvars(i), &
220 & allcount=axes(i) % length, &
221 & xtype=axes(i) % xtype, name=axes(i) % name)
222 call get_attr(history % dimvars(i), 'long_name', &
223 & axes(i) % longname, 'unknown')
224 call get_attr(history % dimvars(i), 'units', &
225 & axes(i) % units, 'unknown')
226
227 ! 属性 GT_HISTORY_ATTR はまだ取得できない
228 !
229 ! するためには, 属性名に対して様々な型が存在しうると
230 ! 考えられるため, get_attr (gtdata_generic および gtdata_netcdf_generic)
231 ! に err 属性を装備させ, 取得できない際にエラーを
232 ! 返してもらわなければならないだろう.
233
234 end do
235 end if
236
237 if (present(varinfo)) then
238 if (.not. associated(history % vars) ) then
239 stat = nf90_enotvar
240 goto 999
241 end if
242 if ( size(history % vars) < 1) then
243 stat = nf90_enotvar
244 goto 999
245 end if
246 numvars = size(history % vars)
247 allocate(varinfo(numvars))
248 do i = 1, numvars
249 call inquire(history % vars(i), alldims=alldims, &
250 & xtype=varinfo(i) % xtype, name=varinfo(i) % name)
251 call get_attr(history % vars(i), 'long_name', &
252 & varinfo(i) % longname, 'unknown')
253 call get_attr(history % vars(i), 'units', &
254 & varinfo(i) % units, 'unknown')
255
256 ! 属性 GT_HISTORY_ATTR はまだ取得できない
257 !
258 ! するためには, 属性名に対して様々な型が存在しうると
259 ! 考えられるため, get_attr (gtdata_generic および gtdata_netcdf_generic)
260 ! に err 属性を装備させ, 取得できない際にエラーを
261 ! 返してもらわなければならないだろう.
262
263 allocate(varinfo(i) % dims(alldims))
264 do j = 1, alldims
265 call open(var=dimvar, source_var=history % vars(i), &
266 & dimord=j, count_compact=.true.)
267 call inquire(dimvar, name=varinfo(i) % dims(j))
268 call close(dimvar)
269 end do
270
271 varinfo(i) % initialized = .true.
272
273 end do
274 end if
275999 continue
276 call storeerror(stat, subname, err, cause_c=cause_c)
277 call endsub(subname)
278 end subroutine historyinquire1
279
280 !-------------------------------------------------------------------
281
282!> @en
283 !> @brief Inquire a GT_HISTORY variable (character interface)
284 !>
285 !> Use this subroutine for inquiries when history was not
286 !> specified in HistoryCreate. Pass the string "default" to history.
287 !> @enden
288 !> @ja
289 !> @brief GT_HISTORY 型変数への問い合わせ (文字列インターフェース)
290 !>
291 !> HistoryCreate で history を指定しなかった場合はこちらの
292 !> サブルーチンで問い合わせを行います。
293 !> history には必ず "default" という文字列を与えてください。
294 !> @endja
295 subroutine historyinquire2(history, err, file, title, source, &
296 & dims, dimsizes, longnames, units, xtypes, &
297 & institution, origin, interval, newest, oldest, &
298 & conventions, gt_version, &
299 & axes, varinfo )
303 use dc_error, only: storeerror, dc_noerr, nf90_einval
304 use dc_trace, only: beginsub, endsub
305 use dc_types, only: string
306 implicit none
307 character(*), intent(in):: history
308 logical, intent(out), optional :: err
309 character(*), intent(out), optional:: file, title, source, institution
310 real,intent(out), optional:: origin, interval, newest, oldest
311 character(*), intent(out), optional:: conventions, gt_version
312 character(*), pointer, optional:: dims(:) ! (out)
313 integer,pointer, optional:: dimsizes(:) ! (out)
314 character(*), pointer, optional:: longnames(:) ! (out)
315 character(*), pointer, optional:: units(:) ! (out)
316 character(*), pointer, optional:: xtypes(:) ! (out)
317 type(gt_history_axis), pointer, optional :: axes(:) ! (out)
318 type(gt_history_varinfo), pointer, optional :: varinfo(:) ! (out)
319 integer:: stat
320 character(STRING):: cause_c
321 character(*), parameter:: subname = "HistoryInquire2"
322 continue
323 call beginsub(subname, "history=%c", c1=trim(history))
324 stat = dc_noerr
325 cause_c = ''
326 if (trim(history) /= 'default') then
327 stat = nf90_einval
328 cause_c = 'history="' // trim(history) // '"'
329 goto 999
330 end if
331 call historyinquire(default, err, file, title, source, &
332 & dims, dimsizes, longnames, units, xtypes, &
333 & institution, origin, interval, newest, oldest, &
334 & conventions, gt_version, &
335 & axes, varinfo )
336999 continue
337 call storeerror(stat, subname, cause_c=cause_c)
338 call endsub(subname)
339 end subroutine historyinquire2
340
341 !-------------------------------------------------------------------
342
343!> @en
344 !> @brief Inquire a GT_HISTORY variable (generic interface)
345 !>
346 !> Usage is same as HistoryInquire.
347 !> @enden
348 !> @ja
349 !> @brief GT_HISTORY 型変数への問い合わせ (総称インターフェース)
350 !>
351 !> 使用方法は HistoryInquire と同様です。
352 !> @endja
353 subroutine historyinquire3(history, err, file, title, source, &
354 & dims, dimsizes, longnames, units, xtypes, &
355 & institution, origin, interval, newest, oldest, &
356 & conventions, gt_version, &
357 & axes, varinfo )
360 use dc_trace, only: beginsub, endsub
361 implicit none
362 type(gt_history), intent(in):: history
363 logical, intent(out), optional :: err
364 character(*), intent(out), optional:: file, title, source, institution
365 real,intent(out), optional:: origin, interval
366 real,intent(out), optional:: newest ! 最新の時刻
367 real,intent(out), optional:: oldest ! 最初の時刻
368 character(*), intent(out), optional:: conventions, gt_version
369 character(*), pointer, optional:: dims(:) ! (out)
370 integer,pointer, optional:: dimsizes(:) ! (out)
371 character(*), pointer, optional:: longnames(:) ! (out)
372 character(*), pointer, optional:: units(:) ! (out)
373 character(*), pointer, optional:: xtypes(:) ! (out)
374 type(gt_history_axis), pointer, optional :: axes(:) ! (out)
375 type(gt_history_varinfo), pointer, optional :: varinfo(:) ! (out)
376
377 character(*), parameter:: subname = "HistoryInquire3"
378 continue
379 call beginsub(subname)
380 call historyinquire(history, err, file, title, source, &
381 & dims, dimsizes, longnames, units, xtypes, &
382 & institution, origin, interval, newest, oldest, &
383 & conventions, gt_version, &
384 & axes, varinfo )
385 call endsub(subname)
386 end subroutine historyinquire3
387
388 !-------------------------------------------------------------------
389
390!> @en
391 !> @brief Inquire a GT_HISTORY variable (generic interface)
392 !>
393 !> Usage is same as HistoryInquire.
394 !> @enden
395 !> @ja
396 !> @brief GT_HISTORY 型変数への問い合わせ (総称インターフェース)
397 !>
398 !> 使用方法は HistoryInquire と同様です。
399 !> @endja
400 subroutine historyinquire4(history, err, file, title, source, &
401 & dims, dimsizes, longnames, units, xtypes, &
402 & institution, origin, interval, newest, oldest, &
403 & conventions, gt_version, &
404 & axes, varinfo )
407 use dc_trace, only: beginsub, endsub
408 implicit none
409 character(*), intent(in):: history
410 logical, intent(out), optional :: err
411 character(*), intent(out), optional:: file, title, source, institution
412 real,intent(out), optional:: origin, interval, newest, oldest
413 character(*), intent(out), optional:: conventions, gt_version
414 character(*), pointer, optional:: dims(:) ! (out)
415 integer,pointer, optional:: dimsizes(:) ! (out)
416 character(*), pointer, optional:: longnames(:) ! (out)
417 character(*), pointer, optional:: units(:) ! (out)
418 character(*), pointer, optional:: xtypes(:) ! (out)
419 type(gt_history_axis), pointer, optional :: axes(:) ! (out)
420 type(gt_history_varinfo), pointer, optional :: varinfo(:) ! (out)
421 character(*), parameter:: subname = "HistoryInquire4"
422 continue
423 call beginsub(subname)
424 call historyinquire(history, err, file, title, source, &
425 & dims, dimsizes, longnames, units, xtypes, &
426 & institution, origin, interval, newest, oldest, &
427 & conventions, gt_version, &
428 & axes, varinfo )
429 call endsub(subname)
430 end subroutine historyinquire4
subroutine historyinquire3(history, err, file, title, source, dims, dimsizes, longnames, units, xtypes, institution, origin, interval, newest, oldest, conventions, gt_version, axes, varinfo)
subroutine historyinquire2(history, err, file, title, source, dims, dimsizes, longnames, units, xtypes, institution, origin, interval, newest, oldest, conventions, gt_version, axes, varinfo)
subroutine historyinquire4(history, err, file, title, source, dims, dimsizes, longnames, units, xtypes, institution, origin, interval, newest, oldest, conventions, gt_version, axes, varinfo)
subroutine historyinquire1(history, err, file, title, source, dims, dimsizes, longnames, units, xtypes, institution, origin, interval, newest, oldest, conventions, gt_version, axes, varinfo)
Error handling module.
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
integer, parameter, public gt_ebadhistory
Definition dc_error.f90:522
integer, parameter, public dc_noerr
Error storage variables
Definition dc_error.f90:468
Debug tracing module.
Definition dc_trace.f90:150
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
Definition dc_trace.f90:476
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:599
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public token
Character length for word, token
Definition dc_types.f90:128
integer, parameter, public string
Character length for string
Definition dc_types.f90:137
Variable URL string parser.
Definition dc_url.f90:61
type(gt_history), target, save, public default