gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
gtool_history_internal.f90
Go to the documentation of this file.
1!--
2! *** Caution!! ***
3!
4! This file is generated from "gtool_history_internal.rb2f90" by Ruby 3.3.8.
5! Please do not edit this file directly.
6!
7! [JAPANESE]
8!
9! ※※※ 注意!!! ※※※
10!
11! このファイルは "gtool_history_internal.rb2f90" から Ruby 3.3.8
12! によって自動生成されたファイルです.
13! このファイルを直接編集しませんようお願い致します.
14!
15!
16!++
48 use dc_types, only: string
50 use gtdata_types, only: gt_variable
51 implicit none
52 private
53 type(gt_history), save, target, public:: default
54 ! 各サブルーチンにおいて, history 引数が
55 ! 未指定の場合に使用される
56 ! デフォルトの GT_HISTORY 変数.
57 !
58 ! A default "GT_HISTORY" variable
59 ! that is used when "history" argument
60 ! of each subroutine is not specified.
61 character(STRING), parameter, public:: &
62 & gtool4_netCDF_Conventions = &
63 & "http://www.gfd-dennou.org/library/gtool4/conventions/"
64 ! gtool4 netCDF 規約の URL
65 character(STRING), parameter, public:: &
66 & gtool4_netCDF_version = "4.3"
67 ! gtool4 netCDF 規約のバージョン
68 public:: append_attrs, copy_attrs
69 public:: set_fake_dim_value
72 interface append_attrs
73 module procedure append_attrs
74 end interface
75 interface copy_attrs
76 module procedure copy_attrs
77 end interface
79 module procedure set_fake_dim_value
80 end interface
82 module procedure lookup_variable_ord
83 end interface
85 module procedure lookup_variable
86 end interface
88 module procedure lookup_dimension
89 end interface
91 module procedure lookup_var_or_dim
92 end interface
93contains
94 subroutine append_attrs(varname, attrs, history)
95 !
96 ! GT_HISTORY_ATTR 変数を history の varname 変数に
97 ! 付加するためのサブルーチン. 公開用ではなく,
98 ! HistoryCreate や HistoryAddVariable に GT_HISTORY_AXIS
99 ! や GT_HISTORY_VARINFO が与えられた時に内部的に利用される.
100 !
102 use gtdata_generic, only: put_attr
104 use dc_string , only: strhead, lchar, tochar
106 implicit none
107 character(*), intent(in):: varname
108 type(gt_history_attr), intent(in):: attrs(:)
109 type(gt_history), intent(inout), target, optional:: history
110 type(gt_history), pointer:: hst =>null()
111 integer :: i
112 character(*), parameter:: subname = "append_attrs"
113 continue
114 call beginsub(subname, 'varname=<%c>, size(attrs(:))=<%d>', &
115 & c1=trim(varname), i=(/size(attrs(:))/))
116 if (present(history)) then
117 hst => history
118 else
119 hst => default
120 endif
121 ! attrs(:) のサイズ分だけループ
122 do i = 1, size( attrs(:) )
123 ! attrs(i)%attrtype の種別で与える変数を変える
124 if ( strhead( 'char', trim(lchar(attrs(i)%attrtype))) ) then
125 call historyaddattr( &
126 & varname, attrs(i)%attrname, &
127 & trim(attrs(i)%Charvalue), hst )
128 elseif ( strhead( 'int', trim(lchar(attrs(i)%attrtype))) ) then
129 if ( attrs(i)%array ) then
130 call dbgmessage('Intarray(:) is selected.')
131 call historyaddattr( &
132 & varname, attrs(i)%attrname , &
133 & attrs(i)%Intarray, hst )
134 else
135 call dbgmessage('Intvalue is selected')
136 call historyaddattr( &
137 & varname, attrs(i)%attrname , &
138 & attrs(i)%Intvalue, hst )
139 endif
140 elseif ( strhead( 'real', trim(lchar(attrs(i)%attrtype))) ) then
141 if ( attrs(i)%array ) then
142 call dbgmessage('Realarray(:) is selected.')
143 call historyaddattr( &
144 & varname, attrs(i)%attrname, attrs(i)%Realarray, hst)
145 else
146 call dbgmessage('Realvalue is selected')
147 call historyaddattr( &
148 & varname, attrs(i)%attrname, attrs(i)%Realvalue, hst)
149 endif
150 elseif ( strhead( 'double', trim(lchar(attrs(i)%attrtype))) ) then
151 if ( attrs(i)%array ) then
152 call dbgmessage('Doublearray(:) is selected.')
153 call historyaddattr( &
154 & varname, attrs(i)%attrname, attrs(i)%Doublearray, hst)
155 else
156 call dbgmessage('Doublevalue is selected')
157 call historyaddattr( &
158 & varname, attrs(i)%attrname, attrs(i)%Doublevalue, hst)
159 endif
160 elseif ( strhead( 'logical', trim(lchar(attrs(i)%attrtype))) ) then
161 call historyaddattr( &
162 & varname, attrs(i)%attrname, attrs(i)%Logicalvalue, hst)
163 else
164 call dbgmessage('attrtype=<%c>=<%c>is Invalid.' , &
165 & c1=trim(attrs(i)%attrtype) , &
166 & c2=trim(lchar(attrs(i)%attrtype)) )
167 endif
168 enddo
169 call endsub(subname)
170 end subroutine append_attrs
171 subroutine copy_attrs(from, to, err)
172 !
173 ! GT_HISTORY_ATTR 変数をコピーするためのサブルーチン
174 ! このモジュール内部で利用されることを想定している.
175 ! from と to の配列サイズは同じであることが想定されている.
176 ! err を与えると, コピーの際何らかの不具合が生じると
177 ! 終了せずに err が真になって返る.
178 !
179 use dc_string,only: lchar, strhead
181 use dc_error, only: storeerror, &
183 use dc_types, only: string
185 implicit none
186 type(gt_history_attr), intent(in) :: from(:)
187 type(gt_history_attr), intent(out) :: to(:)
188 logical, intent(out), optional :: err
189 integer :: i, stat
190 character(STRING) :: cause_c
191 character(STRING), parameter:: subname = "copy_attrs"
192 continue
193 call beginsub(subname)
194 stat = dc_noerr
195 cause_c = ''
196 call dbgmessage('size(from)=<%d>, size(to)=<%d>, So copy <%d> times.', &
197 & i=(/ size(from), size(to), min(size(from),size(to)) /) )
198 if ( size(to) < size(from) ) then
200 cause_c = 'from is larger than to'
201 goto 999
202 end if
203 ! from と to の小さい方に合わせてループ
204 do i = 1, min( size(from), size(to) )
205 ! attrname と attrtype と array はまずコピー
206 to(i)%attrname = from(i)%attrname
207 to(i)%attrtype = from(i)%attrtype
208 to(i)%array = from(i)%array
209 ! from(i)%attrtype の種別でコピーする変数を変える.
210 if ( strhead( 'char', trim(lchar(from(i)%attrtype))) ) then
211 to(i)%Charvalue = from(i)%Charvalue
212 elseif ( strhead( &
213 & lchar('Int'), trim(lchar(from(i)%attrtype)))) then
214 if ( from(i)%array ) then
215 allocate( to(i)%Intarray( size(from(i)%Intarray) ) )
216 to(i)%Intarray = from(i)%Intarray
217 else
218 to(i)%Intvalue = from(i)%Intvalue
219 endif
220 elseif ( strhead( &
221 & lchar('Real'), trim(lchar(from(i)%attrtype)))) then
222 if ( from(i)%array ) then
223 allocate( to(i)%Realarray( size(from(i)%Realarray) ) )
224 to(i)%Realarray = from(i)%Realarray
225 else
226 to(i)%Realvalue = from(i)%Realvalue
227 endif
228 elseif ( strhead( &
229 & lchar('Double'), trim(lchar(from(i)%attrtype)))) then
230 if ( from(i)%array ) then
231 allocate( to(i)%Doublearray( size(from(i)%Doublearray) ) )
232 to(i)%Doublearray = from(i)%Doublearray
233 else
234 to(i)%Doublevalue = from(i)%Doublevalue
235 endif
236 elseif ( strhead( 'logical', trim(lchar(from(i)%attrtype))) ) then
237 to(i)%Logicalvalue = from(i)%Logicalvalue
238 else
239 stat = gt_ebadattrname
240 cause_c = from(i)%attrtype
241 goto 999
242 endif
243 enddo
244999 continue
245 call storeerror(stat, subname, err, cause_c=cause_c)
246 call endsub(subname)
247 end subroutine copy_attrs
248 subroutine set_fake_dim_value(history, dimord)
249 !
250 ! 次元 history % dimvars(dimord) に値が設定されていない場合、
251 ! 「とりあえず」値を設定する。ただし、無制限次元 (時間次元)
252 ! に関しては history % origin, history % interval, history % count
253 ! から「まっとうな」値が設定される。
254 !
255 use gtdata_generic, only: inquire, slice, put
256 use dc_error, only: dumperror
257 use dc_types, only: dp
258! use dc_calendar, only: DCCalConvertByUnit
259! use dc_date, only: EvalByUnit
260 type(gt_history), intent(inout):: history
261 integer, intent(in):: dimord
262 integer:: length, i
263 real(DP), allocatable:: value(:)
264 logical:: err
265 continue
266 if (dimord == history % unlimited_index) then
267 if (.not. associated(history % count)) return
268 length = maxval(history % count(:))
269 else
270 call inquire(history % dimvars(dimord), size=length)
271 endif
272 if (length == 0) return
273 allocate(value(length))
274 if (dimord == history % unlimited_index) then
275 value(:) = (/(real(i, dp), i = 1, length)/)
276 value(:) = &
277 & history % origin &
278 & + (value(:) - 1.0_dp) * history % interval
279!!$ value(:) = &
280!!$ & EvalByUnit( history % origin, '', history % unlimited_units_symbol ) &
281!!$ & + (value(:) - 1.0) &
282!!$ & * EvalByUnit( history % interval, '', history % unlimited_units_symbol )
283 call slice(history % dimvars(dimord), 1, start=1, count=length)
284 else
285 value(:) = (/(real(i, dp), i = 1, length)/)
286 endif
287 call put(history % dimvars(dimord), value, size(value), err)
288 if (err) call dumperror
289 deallocate(value)
290 end subroutine set_fake_dim_value
291 integer function lookup_variable_ord(history, varname) result(result)
292 !
293 ! history 内の varname 変数の変数番号を返す.
294 ! 現在, 明示的に history 変数を与えない場合の変数番号の
295 ! 検索は出来ない.
296 !
297 use dc_types, only: string
298 use gtdata_generic, only: inquire
300 implicit none
301 type(gt_history), intent(in):: history
302 character(len = *), intent(in):: varname
303 character(len = string):: name
304 character(len = *), parameter:: subname = 'lookup_variable_ord'
305 continue
306 call beginsub(subname, 'var=%c', c1 = trim(varname))
307 if (associated(history % vars)) then
308 do, result = 1, size(history % vars)
309 call inquire(history % vars(result), name=name)
310 if (name == varname) goto 999
311 call dbgmessage('no match <%c> <%c>', c1=trim(name), c2=trim(varname))
312 enddo
313 endif
314 result = 0
315999 continue
316 call endsub(subname, "result=%d", i=(/result/))
317 end function
318 type(gt_variable) function lookup_variable(history, varname, ord) result(result)
319 !
320 ! history 内での変数 varname の ID を取得
321 ! ID を取得できた場合, 返り値 result と ord にそれぞれ
322 ! その ID が返される。
323 ! ID を取得できない場合、ord が渡されていなければその場で終了
324 ! ord が渡されている場合は ord に 0 が返される。
325 !
326 use dc_types, only: string
327 use dc_error, only: storeerror, nf90_enotvar, dc_noerr
329 implicit none
330 type(gt_history), intent(in):: history
331 character(len = *), intent(in):: varname
332 character(len = STRING) :: cause_c
333 integer, intent(out), optional:: ord
334 integer:: ordwork
335 integer:: i, stat
336 character(len = *), parameter:: subname = 'lookup_variable'
337 continue
338 call beginsub(subname, '%c', c1=trim(varname))
339 stat = dc_noerr
340 cause_c = ''
341 if (present(ord)) ord = 0
342 ordwork = 0
343 i = lookup_variable_ord(history, varname)
344 if (i > 0) then
345 result = history % vars(i)
346 if (present(ord)) ord = i
347 goto 999
348 endif
349 if (present(ord)) then
350 ord = 0
351 else
352 stat = nf90_enotvar
353 cause_c = varname
354 i = 0
355 endif
356999 continue
357 call storeerror(stat, subname, cause_c=cause_c)
358 if (present(ord)) ordwork = ord
359 call endsub(subname, "ord=%d (0: not found)", i=(/ordwork/))
360 end function
361 type(gt_variable) function lookup_dimension(history, dimname, ord) result(result)
362 !
363 ! history 内の dimname という変数名を持つ次元の GT_VARIABLE
364 ! 変数を返す. dimname 末尾の空白は無視される.
365 !
366 use gtdata_generic, only: inquire
367 use dc_types, only: string
370 implicit none
371 type(gt_history), intent(in):: history
372 character(len = *), intent(in):: dimname
373 integer, intent(out), optional:: ord
374 integer:: ordwork
375 character(len = STRING):: name, cause_c
376 integer:: i, stat
377 character(len = *), parameter:: subname = 'lookup_dimension'
378 continue
379 call beginsub(subname, 'dimname=%c', c1=trim(dimname))
380 stat = dc_noerr
381 if (present(ord)) ord = 0
382 ordwork = 0
383 if (associated(history % dimvars)) then
384 do, i = 1, size(history % dimvars)
385 call inquire(history % dimvars(i), name=name)
386 if (name == trim(dimname)) then
387 result = history % dimvars(i)
388 if (present(ord)) ord = i
389 stat = dc_noerr
390 cause_c = ""
391 goto 999
392 endif
393 enddo
394 endif
395 if (present(ord)) then
396 ord = 0
397 else
398 stat = gt_ebaddimname
399 cause_c = dimname
400 endif
401999 continue
402 call storeerror(stat, subname, cause_c=cause_c)
403 if (present(ord)) ordwork = ord
404 call endsub(subname, 'ord=%d (0:not found)', i=(/ordwork/))
405 end function
406 subroutine lookup_var_or_dim(history, name, var, err)
407 !
408 ! history 内から, name という名前の次元または変数を探査し,
409 ! var に GT_VARIABLE 変数を返す. 見つかって正常に
410 ! var が返る場合は stat には DC_NOERR が返り,
411 ! history 内から name が発見されない場合には, stat に
412 ! NF90_ENOTVAR が返る.
413 !
414 use dc_error, only: storeerror, dc_noerr, nf90_enotvar
415 use dc_types, only: string
417 implicit none
418 type(gt_history), intent(in):: history
419 character(len = *), intent(in):: name
420 type(gt_variable), intent(out):: var
421 logical, intent(out):: err
422 integer:: stat, ord
423 character(STRING) :: cause_c
424 character(len = *), parameter:: subname = 'lookup_var_or_dim'
425 continue
426 call beginsub(subname, 'name=<%c>', c1=trim(name))
427 cause_c = ""
428 stat = dc_noerr
429 var = lookup_variable(history, name, ord)
430 if (ord /= 0) then
431 stat = dc_noerr
432 goto 999
433 endif
434 var = lookup_dimension(history, name, ord)
435 if (ord /= 0) then
436 stat = dc_noerr
437 goto 999
438 endif
439 stat = nf90_enotvar
440 cause_c = "Any vars and dims are not found"
441999 continue
442 call storeerror(stat, subname, err, cause_c)
443 call endsub(subname, 'ord=%d (0:not found)', i=(/ord/))
444 end subroutine lookup_var_or_dim
445end module gtool_history_internal
446!--
447! vi:set readonly sw=4 ts=8:
448!
449!Local Variables:
450!mode: f90
451!buffer-read-only: t
452!End:
453!
454!++
Procedure reference specification. Made as an external function to be replaceable in the future.
Definition dc_error.f90:592
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 dc_noerr
Error storage variables
Definition dc_error.f90:468
integer, parameter, public gt_ebaddimname
Definition dc_error.f90:511
integer, parameter, public gt_eargsizemismatch
Definition dc_error.f90:515
integer, parameter, public gt_ebadattrname
Definition dc_error.f90:521
Handling character types.
Definition dc_string.f90:83
Debug tracing module.
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
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public dp
Double Precision Real number
Definition dc_types.f90:92
integer, parameter, public string
Character length for string
Definition dc_types.f90:137
type(gt_history), target, save, public default