gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
gtvaradddim.f90
Go to the documentation of this file.
1!> @file gtvaradddim.f90
2!>
3!> @author Eizi TOYODA, Yasuhiro MORIKAWA
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 Add dimension
9!>
10!> This subroutine is provided as gtdata_generic#Add_dim
11!> through gtdata_generic.
12!> @enden
13!>
14!> @ja
15!> @brief 次元の追加
16!>
17!> このサブルーチンは gtdata_generic から gtdata_generic#Add_dim
18!> として提供されます。
19!> @endja
20!>
21
22!>
23!> @en
24!> @brief Add dimension to variable
25!>
26!> Adds dimension dimvar at position dimord in variable var.
27!> Dimensions at dimord and after shift one position back.
28!> If dimord is greater than the number of valid dimensions of var,
29!> it is treated as if (valid_dimensions + 1) was given.
30!>
31!> If an error occurs, outputs a message and terminates the program.
32!> If err is provided, returns .true. and program does not terminate.
33!> @param[in] var Variable handle
34!> @param[in] dimord Dimension order number for insertion
35!> @param[in] dimvar Dimension variable to add
36!> @param[out] err Error flag
37!> @enden
38!>
39!> @ja
40!> @brief 変数に次元を追加
41!>
42!> 変数 var の dimord 番目の位置に次元 dimvar を追加します。
43!> dimord 番目以降の次元は 1 つ後ろにずれます。
44!> もし dimord が var の有効次元数よりも大きい場合、
45!> (有効次元数 + 1) が与えられたものと見なされます。
46!>
47!> エラーが生じた場合、メッセージを出力してプログラムは強制終了します。
48!> err を与えてある場合にはの引数に .true. が返り、プログラムは終了しません。
49!> @param[in] var 変数ハンドル
50!> @param[in] dimord 挿入位置の次元順序番号
51!> @param[in] dimvar 追加する次元変数
52!> @param[out] err エラーフラグ
53!> @endja
54!>
55subroutine gtvaradddim(var, dimord, dimvar, err)
56 use gtdata_types, only: gt_variable
57 use gtdata_generic, only: inquire
60 implicit none
61 type(gt_variable), intent(in):: var
62 type(gt_variable), intent(in):: dimvar
63 integer, intent(in):: dimord
64 logical, intent(out):: err
65 type(gt_dimmap), pointer:: map(:)
66 type(gt_dimmap):: tmpmap
67 integer:: id, nd, ndimsp, stat, vid
68 character(*), parameter:: subname = 'GTVarAddDim'
69continue
70 err = .true.
71 call beginsub(subname)
72
73 if (dimord < 1) then
74 call endsub(subname, "negative dimord=%d invalid", i=(/dimord/))
75 return
76 endif
77
78 ! dimvar をチェックしマップ設定を tmpmap に保存
79 call map_lookup(dimvar, vid=vid, ndims=nd)
80 if (vid < 0) then
81 call endsub(subname, "dimvar invalid")
82 return
83 endif
84 if (nd <= 0) then
85 call endsub(subname, "dimvar nondimensional")
86 return
87 else if (nd > 1) then
88 call endsub(subname, "dimvar multidimensional")
89 return
90 endif
91 allocate(map(nd))
92 call map_lookup(dimvar, map=map)
93 tmpmap = map(1)
94 deallocate(map)
95
96 ! dimord 番目 (ただし ndimsp + 1 を越えない) に挿入する隙間をあける
97 call map_lookup(var, ndims=ndimsp)
98 if (dimord > ndimsp + 1) then
99 id = ndimsp + 1
100 else
101 id = dimord
102 endif
103 allocate(map(nd + 1))
104 call map_resize(var, nd + 1)
105 call map_lookup(var, map=map)
106 map(id+1: nd+1) = map(id: nd)
107
108 ! 新しい次元への参照を挿入
109 map(id)%dimno = -1
110 call inquire(dimvar, url=map(id)%url)
111 map(id)%allcount = tmpmap%allcount
112 map(id)%offset = tmpmap%offset
113 map(id)%step = tmpmap%step
114 map(id)%start = tmpmap%start
115 map(id)%count = tmpmap%count
116 map(id)%stride = tmpmap%stride
117
118 ! 登録
119 call map_set(var, map=map, stat=stat)
120 if (stat /= 0) goto 999
121 call map_set_ndims(var, ndims=ndimsp + 1, stat=stat)
122
123999 continue
124 err = (stat /= 0)
125 call endsub(subname)
126end subroutine gtvaradddim
subroutine gtvaradddim(var, dimord, dimvar, err)
デバッグ時の追跡用モジュール
Definition dc_trace.f90:150
subroutine, public dbgmessage(fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:680
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
subroutine, public map_lookup(var, vid, map, ndims)
subroutine map_set_ndims(var, ndims, stat)
subroutine map_set(var, map, stat)
subroutine map_resize(var, ndims)