gtvaradddim.f90 File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine gtvaradddim (var, dimord, dimvar, err)
 

Function/Subroutine Documentation

◆ gtvaradddim()

subroutine gtvaradddim ( type(gt_variable), intent(in)  var,
integer, intent(in)  dimord,
type(gt_variable), intent(in)  dimvar,
logical, intent(out)  err 
)

Definition at line 14 of file gtvaradddim.f90.

References dc_trace::beginsub(), dc_trace::dbgmessage(), dc_trace::endsub(), gtdata_internal_map::map_lookup(), gtdata_internal_map::map_resize(), gtdata_internal_map::map_set(), and gtdata_internal_map::map_set_ndims().

14  !
15  !== 次元の追加
16  !
17  ! 変数 *var* の *dimord* 番目の位置に次元 *dimvar*
18  ! を追加します。*dimord* 番目以降の次元は 1 つ後ろにずれます。
19  ! もし *dimord* が *var* の有効次元数よりも大きい場合、
20  ! (有効次元数 + 1) が与えられたものと見なされます。
21  !
22  ! エラーが生じた場合、メッセージを出力
23  ! してプログラムは強制終了します。*err* を与えてある場合には
24  ! の引数に .true. が返り、プログラムは終了しません。
25  !
26  use gtdata_types, only: gt_variable
27  use gtdata_generic, only: inquire
29  use dc_trace, only: beginsub, endsub, dbgmessage
30  implicit none
31  type(gt_variable), intent(in):: var
32  type(gt_variable), intent(in):: dimvar
33  integer, intent(in):: dimord
34  logical, intent(out):: err
35  type(gt_dimmap), pointer:: map(:)
36  type(gt_dimmap):: tmpmap
37  integer:: id, nd, ndimsp, stat, vid
38  character(*), parameter:: subname = 'GTVarAddDim'
39 continue
40  err = .true.
41  call beginsub(subname)
42 
43  if (dimord < 1) then
44  call endsub(subname, "negative dimord=%d invalid", i=(/dimord/))
45  return
46  endif
47 
48  ! dimvar をチェックしマップ設定を tmpmap に保存
49  call map_lookup(dimvar, vid=vid, ndims=nd)
50  if (vid < 0) then
51  call endsub(subname, "dimvar invalid")
52  return
53  endif
54  if (nd <= 0) then
55  call endsub(subname, "dimvar nondimensional")
56  return
57  else if (nd > 1) then
58  call endsub(subname, "dimvar multidimensional")
59  return
60  endif
61  allocate(map(nd))
62  call map_lookup(dimvar, map=map)
63  tmpmap = map(1)
64  deallocate(map)
65 
66  ! dimord 番目 (ただし ndimsp + 1 を越えない) に挿入する隙間をあける
67  call map_lookup(var, ndims=ndimsp)
68  if (dimord > ndimsp + 1) then
69  id = ndimsp + 1
70  else
71  id = dimord
72  endif
73  allocate(map(nd + 1))
74  call map_resize(var, nd + 1)
75  call map_lookup(var, map=map)
76  map(id+1: nd+1) = map(id: nd)
77 
78  ! 新しい次元への参照を挿入
79  map(id)%dimno = -1
80  call inquire(dimvar, url=map(id)%url)
81  map(id)%allcount = tmpmap%allcount
82  map(id)%offset = tmpmap%offset
83  map(id)%step = tmpmap%step
84  map(id)%start = tmpmap%start
85  map(id)%count = tmpmap%count
86  map(id)%stride = tmpmap%stride
87 
88  ! 登録
89  call map_set(var, map=map, stat=stat)
90  if (stat /= 0) goto 999
91  call map_set_ndims(var, ndims=ndimsp + 1, stat=stat)
92 
93 999 continue
94  err = (stat /= 0)
95  call endsub(subname)
subroutine map_set(var, map, stat)
subroutine map_set_ndims(var, ndims, stat)
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
subroutine, public map_lookup(var, vid, map, ndims)
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446
subroutine map_resize(var, ndims)
Here is the call graph for this function: