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 2.3.3.
5 ! Please do not edit this file directly.
6 !
7 ! [JAPANESE]
8 !
9 ! ※※※ 注意!!! ※※※
10 !
11 ! このファイルは "gtool_history_internal.rb2f90" から Ruby 2.3.3
12 ! によって自動生成されたファイルです.
13 ! このファイルを直接編集しませんようお願い致します.
14 !
15 !
16 !++
17 !
18 !
19 != デフォルトの GT_HISTORY 変数および GT_HISTORY 操作用内部手続き
20 != A default GT_HISTORY variable and internal procedures for handling of GT_HISTORY
21 !
22 ! Authors:: Yasuhiro MORIKAWA, Eizi TOYODA
23 ! Version:: $Id: gtool_history_internal.rb2f90,v 1.3 2009-10-12 04:03:45 morikawa Exp $
24 ! Tag Name:: $Name: $
25 ! Copyright:: Copyright (C) GFD Dennou Club, 2000-2005. All rights reserved.
26 ! License:: See COPYRIGHT[link:../../../COPYRIGHT]
27 !
29  !
30  ! このモジュールは, 各サブルーチンにおいて, history 引数が
31  ! 未指定の場合に使用されるデフォルトの GT_HISTORY 変数を
32  ! 保管するとともに, GT_HISTORY 変数内の情報を編集するための
33  ! gtool_history モジュール内部で使用する手続きについても提供します.
34  ! 内部向けなので, gtool5 ライブラリの外部から呼び出さないでください.
35  !
36  ! A default "GT_HISTORY" variable
37  ! that is used when "history" argument
38  ! of each subroutine is not specified is stored in this module.
39  ! In addition, procedures that handle information in GT_HISTORY variables
40  ! are provided.
41  ! This variable is prepared for internal use,
42  ! so do not refer this variable from outside of gtool5
43  !
44  use dc_types, only: string
46  use gtdata_types, only: gt_variable
47  implicit none
48  private
49  type(gt_history), save, target, public:: default
50  ! 各サブルーチンにおいて, history 引数が
51  ! 未指定の場合に使用される
52  ! デフォルトの GT_HISTORY 変数.
53  !
54  ! A default "GT_HISTORY" variable
55  ! that is used when "history" argument
56  ! of each subroutine is not specified.
57  character(STRING), parameter, public:: &
58  & gtool4_netCDF_Conventions = &
59  & "http://www.gfd-dennou.org/library/gtool4/conventions/"
60  ! gtool4 netCDF 規約の URL
61  character(STRING), parameter, public:: &
62  & gtool4_netCDF_version = "4.3"
63  ! gtool4 netCDF 規約のバージョン
64  public:: append_attrs, copy_attrs
65  public:: set_fake_dim_value
68  interface append_attrs
69  module procedure append_attrs
70  end interface
71  interface copy_attrs
72  module procedure copy_attrs
73  end interface
75  module procedure set_fake_dim_value
76  end interface
78  module procedure lookup_variable_ord
79  end interface
80  interface lookup_variable
81  module procedure lookup_variable
82  end interface
83  interface lookup_dimension
84  module procedure lookup_dimension
85  end interface
87  module procedure lookup_var_or_dim
88  end interface
89 contains
90  subroutine append_attrs(varname, attrs, history)
91  !
92  ! GT_HISTORY_ATTR 変数を history の varname 変数に
93  ! 付加するためのサブルーチン. 公開用ではなく,
94  ! HistoryCreate や HistoryAddVariable に GT_HISTORY_AXIS
95  ! や GT_HISTORY_VARINFO が与えられた時に内部的に利用される.
96  !
98  use gtdata_generic, only: put_attr
99  use dc_trace, only: beginsub, endsub, dbgmessage
100  use dc_string , only: strhead, lchar, tochar
102  implicit none
103  character(*), intent(in):: varname
104  type(gt_history_attr), intent(in):: attrs(:)
105  type(gt_history), intent(inout), target, optional:: history
106  type(gt_history), pointer:: hst =>null()
107  integer :: i
108  character(*), parameter:: subname = "append_attrs"
109  continue
110  call beginsub(subname, 'varname=<%c>, size(attrs(:))=<%d>', &
111  & c1=trim(varname), i=(/size(attrs(:))/))
112  if (present(history)) then
113  hst => history
114  else
115  hst => default
116  endif
117  ! attrs(:) のサイズ分だけループ
118  do i = 1, size( attrs(:) )
119  ! attrs(i)%attrtype の種別で与える変数を変える
120  if ( strhead( 'char', trim(lchar(attrs(i)%attrtype))) ) then
121  call historyaddattr( &
122  & varname, attrs(i)%attrname, &
123  & trim(attrs(i)%Charvalue), hst )
124  elseif ( strhead( 'int', trim(lchar(attrs(i)%attrtype))) ) then
125  if ( attrs(i)%array ) then
126  call dbgmessage('Intarray(:) is selected.')
127  call historyaddattr( &
128  & varname, attrs(i)%attrname , &
129  & attrs(i)%Intarray, hst )
130  else
131  call dbgmessage('Intvalue is selected')
132  call historyaddattr( &
133  & varname, attrs(i)%attrname , &
134  & attrs(i)%Intvalue, hst )
135  endif
136  elseif ( strhead( 'real', trim(lchar(attrs(i)%attrtype))) ) then
137  if ( attrs(i)%array ) then
138  call dbgmessage('Realarray(:) is selected.')
139  call historyaddattr( &
140  & varname, attrs(i)%attrname, attrs(i)%Realarray, hst)
141  else
142  call dbgmessage('Realvalue is selected')
143  call historyaddattr( &
144  & varname, attrs(i)%attrname, attrs(i)%Realvalue, hst)
145  endif
146  elseif ( strhead( 'double', trim(lchar(attrs(i)%attrtype))) ) then
147  if ( attrs(i)%array ) then
148  call dbgmessage('Doublearray(:) is selected.')
149  call historyaddattr( &
150  & varname, attrs(i)%attrname, attrs(i)%Doublearray, hst)
151  else
152  call dbgmessage('Doublevalue is selected')
153  call historyaddattr( &
154  & varname, attrs(i)%attrname, attrs(i)%Doublevalue, hst)
155  endif
156  elseif ( strhead( 'logical', trim(lchar(attrs(i)%attrtype))) ) then
157  call historyaddattr( &
158  & varname, attrs(i)%attrname, attrs(i)%Logicalvalue, hst)
159  else
160  call dbgmessage('attrtype=<%c>=<%c>is Invalid.' , &
161  & c1=trim(attrs(i)%attrtype) , &
162  & c2=trim(lchar(attrs(i)%attrtype)) )
163  endif
164  enddo
165  call endsub(subname)
166  end subroutine append_attrs
167  subroutine copy_attrs(from, to, err)
168  !
169  ! GT_HISTORY_ATTR 変数をコピーするためのサブルーチン
170  ! このモジュール内部で利用されることを想定している.
171  ! from と to の配列サイズは同じであることが想定されている.
172  ! err を与えると, コピーの際何らかの不具合が生じると
173  ! 終了せずに err が真になって返る.
174  !
175  use dc_string,only: lchar, strhead
176  use dc_trace, only: beginsub, endsub, dbgmessage
177  use dc_error, only: storeerror, &
179  use dc_types, only: string, token
181  implicit none
182  type(gt_history_attr), intent(in) :: from(:)
183  type(gt_history_attr), intent(out) :: to(:)
184  logical, intent(out), optional :: err
185  integer :: i, stat
186  character(STRING) :: cause_c
187  character(STRING), parameter:: subname = "copy_attrs"
188  continue
189  call beginsub(subname)
190  stat = dc_noerr
191  cause_c = ''
192  call dbgmessage('size(from)=<%d>, size(to)=<%d>, So copy <%d> times.', &
193  & i=(/ size(from), size(to), min(size(from),size(to)) /) )
194  if ( size(to) < size(from) ) then
195  stat = gt_eargsizemismatch
196  cause_c = 'from is larger than to'
197  goto 999
198  end if
199  ! from と to の小さい方に合わせてループ
200  do i = 1, min( size(from), size(to) )
201  ! attrname と attrtype と array はまずコピー
202  to(i)%attrname = from(i)%attrname
203  to(i)%attrtype = from(i)%attrtype
204  to(i)%array = from(i)%array
205  ! from(i)%attrtype の種別でコピーする変数を変える.
206  if ( strhead( 'char', trim(lchar(from(i)%attrtype))) ) then
207  to(i)%Charvalue = from(i)%Charvalue
208  elseif ( strhead( &
209  & lchar('Int'), trim(lchar(from(i)%attrtype)))) then
210  if ( from(i)%array ) then
211  allocate( to(i)%Intarray( size(from(i)%Intarray) ) )
212  to(i)%Intarray = from(i)%Intarray
213  else
214  to(i)%Intvalue = from(i)%Intvalue
215  endif
216  elseif ( strhead( &
217  & lchar('Real'), trim(lchar(from(i)%attrtype)))) then
218  if ( from(i)%array ) then
219  allocate( to(i)%Realarray( size(from(i)%Realarray) ) )
220  to(i)%Realarray = from(i)%Realarray
221  else
222  to(i)%Realvalue = from(i)%Realvalue
223  endif
224  elseif ( strhead( &
225  & lchar('Double'), trim(lchar(from(i)%attrtype)))) then
226  if ( from(i)%array ) then
227  allocate( to(i)%Doublearray( size(from(i)%Doublearray) ) )
228  to(i)%Doublearray = from(i)%Doublearray
229  else
230  to(i)%Doublevalue = from(i)%Doublevalue
231  endif
232  elseif ( strhead( 'logical', trim(lchar(from(i)%attrtype))) ) then
233  to(i)%Logicalvalue = from(i)%Logicalvalue
234  else
235  stat = gt_ebadattrname
236  cause_c = from(i)%attrtype
237  goto 999
238  endif
239  enddo
240 999 continue
241  call storeerror(stat, subname, err, cause_c=cause_c)
242  call endsub(subname)
243  end subroutine copy_attrs
244  subroutine set_fake_dim_value(history, dimord)
245  !
246  ! 次元 history % dimvars(dimord) に値が設定されていない場合、
247  ! 「とりあえず」値を設定する。ただし、無制限次元 (時間次元)
248  ! に関しては history % origin, history % interval, history % count
249  ! から「まっとうな」値が設定される。
250  !
251  use gtdata_generic, only: inquire, slice, put
252  use dc_error, only: dumperror
253 ! use dc_calendar, only: DCCalConvertByUnit
254 ! use dc_date, only: EvalByUnit
255  type(gt_history), intent(inout):: history
256  integer, intent(in):: dimord
257  integer:: length, i
258  real, allocatable:: value(:)
259  logical:: err
260  continue
261  if (dimord == history % unlimited_index) then
262  if (.not. associated(history % count)) return
263  length = maxval(history % count(:))
264  else
265  call inquire(history % dimvars(dimord), size=length)
266  endif
267  if (length == 0) return
268  allocate(value(length))
269  if (dimord == history % unlimited_index) then
270  value(:) = (/(real(i), i = 1, length)/)
271  value(:) = &
272  & history % origin &
273  & + (value(:) - 1.0) * history % interval
274 !!$ value(:) = &
275 !!$ & EvalByUnit( history % origin, '', history % unlimited_units_symbol ) &
276 !!$ & + (value(:) - 1.0) &
277 !!$ & * EvalByUnit( history % interval, '', history % unlimited_units_symbol )
278  call slice(history % dimvars(dimord), 1, start=1, count=length)
279  else
280  value(:) = (/(real(i), i = 1, length)/)
281  endif
282  call put(history % dimvars(dimord), value, size(value), err)
283  if (err) call dumperror
284  deallocate(value)
285  end subroutine set_fake_dim_value
286  integer function lookup_variable_ord(history, varname) result(result)
287  !
288  ! history 内の varname 変数の変数番号を返す.
289  ! 現在, 明示的に history 変数を与えない場合の変数番号の
290  ! 検索は出来ない.
291  !
292  use dc_types, only: string
293  use gtdata_generic, only: inquire
294  use dc_trace, only: beginsub, endsub, dbgmessage
295  implicit none
296  type(gt_history), intent(in):: history
297  character(len = *), intent(in):: varname
298  character(len = string):: name
299  character(len = *), parameter:: subname = 'lookup_variable_ord'
300  continue
301  call beginsub(subname, 'var=%c', c1 = trim(varname))
302  if (associated(history % vars)) then
303  do, result = 1, size(history % vars)
304  call inquire(history % vars(result), name=name)
305  if (name == varname) goto 999
306  call dbgmessage('no match <%c> <%c>', c1=trim(name), c2=trim(varname))
307  enddo
308  endif
309  result = 0
310 999 continue
311  call endsub(subname, "result=%d", i=(/result/))
312  end function
313  type(gt_variable) function lookup_variable(history, varname, ord) result(result)
314  !
315  ! history 内での変数 varname の ID を取得
316  ! ID を取得できた場合, 返り値 result と ord にそれぞれ
317  ! その ID が返される。
318  ! ID を取得できない場合、ord が渡されていなければその場で終了
319  ! ord が渡されている場合は ord に 0 が返される。
320  !
321  use dc_types, only: string
322  use dc_error, only: storeerror, nf90_enotvar, dc_noerr
323  use dc_trace, only: beginsub, endsub, dbgmessage
324  implicit none
325  type(gt_history), intent(in):: history
326  character(len = *), intent(in):: varname
327  character(len = STRING) :: cause_c
328  integer, intent(out), optional:: ord
329  integer:: ordwork
330  integer:: i, stat
331  character(len = *), parameter:: subname = 'lookup_variable'
332  continue
333  call beginsub(subname, '%c', c1=trim(varname))
334  stat = dc_noerr
335  cause_c = ''
336  if (present(ord)) ord = 0
337  ordwork = 0
338  i = lookup_variable_ord(history, varname)
339  if (i > 0) then
340  result = history % vars(i)
341  if (present(ord)) ord = i
342  goto 999
343  endif
344  if (present(ord)) then
345  ord = 0
346  else
347  stat = nf90_enotvar
348  cause_c = varname
349  i = 0
350  endif
351 999 continue
352  call storeerror(stat, subname, cause_c=cause_c)
353  if (present(ord)) ordwork = ord
354  call endsub(subname, "ord=%d (0: not found)", i=(/ordwork/))
355  end function
356  type(gt_variable) function lookup_dimension(history, dimname, ord) result(result)
357  !
358  ! history 内の dimname という変数名を持つ次元の GT_VARIABLE
359  ! 変数を返す. dimname 末尾の空白は無視される.
360  !
361  use gtdata_generic, only: inquire
362  use dc_types, only: string
364  use dc_trace, only: beginsub, endsub, dbgmessage
365  implicit none
366  type(gt_history), intent(in):: history
367  character(len = *), intent(in):: dimname
368  integer, intent(out), optional:: ord
369  integer:: ordwork
370  character(len = STRING):: name, cause_c
371  integer:: i, stat
372  character(len = *), parameter:: subname = 'lookup_dimension'
373  continue
374  call beginsub(subname, 'dimname=%c', c1=trim(dimname))
375  stat = dc_noerr
376  if (present(ord)) ord = 0
377  ordwork = 0
378  if (associated(history % dimvars)) then
379  do, i = 1, size(history % dimvars)
380  call inquire(history % dimvars(i), name=name)
381  if (name == trim(dimname)) then
382  result = history % dimvars(i)
383  if (present(ord)) ord = i
384  stat = dc_noerr
385  cause_c = ""
386  goto 999
387  endif
388  enddo
389  endif
390  if (present(ord)) then
391  ord = 0
392  else
393  stat = gt_ebaddimname
394  cause_c = dimname
395  endif
396 999 continue
397  call storeerror(stat, subname, cause_c=cause_c)
398  if (present(ord)) ordwork = ord
399  call endsub(subname, 'ord=%d (0:not found)', i=(/ordwork/))
400  end function
401  subroutine lookup_var_or_dim(history, name, var, err)
402  !
403  ! history 内から, name という名前の次元または変数を探査し,
404  ! var に GT_VARIABLE 変数を返す. 見つかって正常に
405  ! var が返る場合は stat には DC_NOERR が返り,
406  ! history 内から name が発見されない場合には, stat に
407  ! NF90_ENOTVAR が返る.
408  !
409  use dc_error, only: storeerror, dc_noerr, nf90_enotvar
410  use dc_types, only: string
411  use dc_trace, only: beginsub, endsub, dbgmessage
412  implicit none
413  type(gt_history), intent(in):: history
414  character(len = *), intent(in):: name
415  type(gt_variable), intent(out):: var
416  logical, intent(out):: err
417  integer:: stat, ord
418  character(STRING) :: cause_c
419  character(len = *), parameter:: subname = 'lookup_var_or_dim'
420  continue
421  call beginsub(subname, 'name=<%c>', c1=trim(name))
422  cause_c = ""
423  stat = dc_noerr
424  var = lookup_variable(history, name, ord)
425  if (ord /= 0) then
426  stat = dc_noerr
427  goto 999
428  endif
429  var = lookup_dimension(history, name, ord)
430  if (ord /= 0) then
431  stat = dc_noerr
432  goto 999
433  endif
434  stat = nf90_enotvar
435  cause_c = "Any vars and dims are not found"
436 999 continue
437  call storeerror(stat, subname, err, cause_c)
438  call endsub(subname, 'ord=%d (0:not found)', i=(/ord/))
439  end subroutine lookup_var_or_dim
440 end module gtool_history_internal
441 !--
442 ! vi:set readonly sw=4 ts=8:
443 !
444 !Local Variables:
445 !mode: f90
446 !buffer-read-only: t
447 !End:
448 !
449 !++
type(gt_history), target, save, public default
integer, parameter, public token
単語やキーワードを保持する文字型変数の種別型パラメタ
Definition: dc_types.f90:109
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
integer, parameter, public gt_eargsizemismatch
Definition: dc_error.f90:536
種別型パラメタを提供します。
Definition: dc_types.f90:49
integer, parameter, public gt_ebadattrname
Definition: dc_error.f90:542
subroutine dumperror()
Definition: dc_error.f90:942
integer, parameter, public gt_ebaddimname
Definition: dc_error.f90:532
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118