gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
Functions/Subroutines
historycopyvariable.f90 File Reference

Copy definition of a variable . More...

Go to the source code of this file.

Functions/Subroutines

subroutine historycopyvariable1 (file, varname, history, overwrite)
 

Detailed Description

Copy definition of a variable

.

Author
Yasuhiro MORIKAWA

Definition in file historycopyvariable.f90.

Function/Subroutine Documentation

◆ historycopyvariable1()

subroutine historycopyvariable1 ( character(len = *), intent(in)  file,
character(len = *), intent(in)  varname,
type(gt_history), intent(inout), optional, target  history,
logical, intent(in), optional  overwrite 
)

Copy a variable definition from another file

Defines a variable within gtool4 data by specifying a file name and variable name from another gtool4 data file, automatically copying the variable's structure and attributes. HistoryCreate must be called beforehand. Use HistoryAddVariable to set structure and attributes manually.

Parameters
[in]filenetCDF file containing source variable
[in]varnamename of source variable
[in,out]historyhistory structure (optional)
[in]overwriteoverwrite flag (optional)

Definition at line 48 of file historycopyvariable.f90.

52 use gtdata_types, only: gt_variable
55 use dc_types, only: string, dp
56 use dc_trace, only: beginsub, endsub
57 implicit none
58 character(len = *), intent(in):: file
59 ! コピーしようとする変数が格納された
60 ! netCDF ファイル名
61 !
62 character(len = *), intent(in):: varname
63 ! コピー元となる変数の名前
64 !
65 ! 定義される変数名もこれと
66 ! 同じになります。
67 ! 最大文字数は dc_types::TOKEN 。
68 !
69 ! 依存する次元が存在しない
70 ! 場合は自動的にその次元に関する
71 ! 変数情報も元のファイルから
72 ! コピーします。
73 ! この場合に「同じ次元」と見
74 ! なされるのは、(1) 無制限次
75 ! 元 (自動的に「時間」と認識
76 ! される)、
77 ! (2) サイズと単位が同じ次元、
78 ! です。
79 !
80 type(GT_HISTORY), intent(inout), optional, target:: history
81 ! 出力ファイルの設定に関する情報を
82 ! 格納した構造体
83 !
84 ! ここに指定するものは、
85 ! HistoryCreate によって初期設定
86 ! されていなければなりません。
87 !
88 logical, intent(in), optional:: overwrite
89 ! 上書きの可否の設定
90 !
91 ! この引数に .false. を渡すと、
92 ! 既存のファイルを上書きしません。
93 ! デフォルトは上書きします。
94 !
95
96 type(GT_HISTORY), pointer:: hst =>null()
97 type(GT_VARIABLE), pointer:: vwork(:) =>null(), dimvars(:) =>null()
98 type(GT_VARIABLE):: copyfrom
99 character(STRING):: fullname, url, copyurl
100 integer, pointer:: count_work(:) =>null()
101 integer, pointer:: var_avr_count_work(:) =>null()
102 integer:: var_avr_length
103 logical, pointer:: var_avr_firstput_work(:) =>null()
104 real(DP), pointer:: var_avr_coefsum_work(:) =>null()
105 real(DP), pointer:: var_avr_baseint_work(:) =>null()
106 real(DP), pointer:: var_avr_prevtime_work(:) =>null()
107!!$ type(DC_DIFFTIME), pointer:: var_avr_baseint_work(:) =>null()
108!!$ type(DC_DIFFTIME), pointer:: var_avr_prevtime_work(:) =>null()
109 type(GT_HISTORY_AVRDATA), pointer:: var_avr_data_work(:) =>null()
110 integer:: nvars, numdims, i
111 logical:: growable, overwrite_required
112 character(*), parameter:: subname = "HistoryCopyVariable1"
113 continue
114 call beginsub(subname, 'file=%c varname=%c', &
115 & c1=trim(file), c2=trim(varname))
116 !----- 操作対象決定 -----
117 if (present(history)) then
118 hst => history
119 else
120 hst => default
121 endif
122
123 !----- 変数表拡張 -----
124 if (associated(hst % vars)) then
125 nvars = size(hst % vars(:))
126 vwork => hst % vars
127 count_work => hst % count
128 nullify(hst % vars, hst % count)
129 allocate(hst % vars(nvars + 1), hst % count(nvars + 1))
130 hst % vars(1:nvars) = vwork(1:nvars)
131 hst % count(1:nvars) = count_work(1:nvars)
132 deallocate(vwork, count_work)
133 count_work => hst % growable_indices
134 nullify(hst % growable_indices)
135 allocate(hst % growable_indices(nvars + 1))
136 hst % growable_indices(1:nvars) = count_work(1:nvars)
137 deallocate(count_work)
138
139 !
140 ! 平均値出力のための変数表コピー
141 ! Copy table of variables for average value output
142 !
143 var_avr_count_work => hst % var_avr_count
144 nullify( hst % var_avr_count )
145 allocate( hst % var_avr_count(nvars + 1) )
146 hst % var_avr_count(1:nvars) = var_avr_count_work(1:nvars)
147 deallocate( var_avr_count_work )
148
149 var_avr_data_work => hst % var_avr_data
150 nullify(hst % var_avr_data)
151 allocate(hst % var_avr_data(nvars + 1))
152 do i = 1, nvars
153 hst % var_avr_data(i) % length = var_avr_data_work(i) % length
154 allocate(hst % var_avr_data(i) % &
155 & a_dataavr(var_avr_data_work(i) % length))
156 hst % var_avr_data(i) % a_DataAvr = var_avr_data_work(i) % a_DataAvr
157 end do
158 deallocate( var_avr_data_work )
159
160 var_avr_firstput_work => hst % var_avr_firstput
161 nullify( hst % var_avr_firstput )
162 allocate( hst % var_avr_firstput(nvars + 1) )
163 hst % var_avr_firstput(1:nvars) = var_avr_firstput_work(1:nvars)
164 deallocate( var_avr_firstput_work )
165
166 var_avr_coefsum_work => hst % var_avr_coefsum
167 nullify( hst % var_avr_coefsum )
168 allocate( hst % var_avr_coefsum(nvars + 1) )
169 hst % var_avr_coefsum(1:nvars) = var_avr_coefsum_work(1:nvars)
170 deallocate( var_avr_coefsum_work )
171
172 var_avr_baseint_work => hst % var_avr_baseint
173 nullify( hst % var_avr_baseint )
174 allocate( hst % var_avr_baseint(nvars + 1) )
175 hst % var_avr_baseint(1:nvars) = var_avr_baseint_work(1:nvars)
176 deallocate( var_avr_baseint_work )
177
178 var_avr_prevtime_work => hst % var_avr_prevtime
179 nullify( hst % var_avr_prevtime )
180 allocate( hst % var_avr_prevtime(nvars + 1) )
181 hst % var_avr_prevtime(1:nvars) = var_avr_prevtime_work(1:nvars)
182 deallocate( var_avr_prevtime_work )
183 else
184 ! トリッキーだが、ここで count だけ 2 要素確保するのは、
185 ! HistorySetTime による巻き戻しに備えるため。
186 allocate(hst % vars(1), hst % count(2), hst % growable_indices(1))
187 hst % count(2) = 0
188 allocate(hst % var_avr_count(1), hst % var_avr_data(1))
189 allocate(hst % var_avr_firstput(1), hst % var_avr_coefsum(1))
190 allocate(hst % var_avr_baseint(1), hst % var_avr_prevtime(1))
191 endif
192 nvars = size(hst % vars(:))
193 hst % growable_indices(nvars) = 0
194 hst % count(nvars) = 0
195 hst % var_avr_count(nvars) = -1
196 hst % var_avr_firstput = .true.
197 hst % var_avr_coefsum(nvars) = 0.0_dp
198 hst % var_avr_baseint(nvars) = 0.0_dp
199!!$ call DCDiffTimeCreate( &
200!!$ & hst % var_avr_baseint(nvars), & ! (out)
201!!$ & sec = 0.0_DP ) ! (in)
202 hst % var_avr_prevtime(nvars) = hst % var_avr_baseint(nvars)
203
204 !----- コピー元ファイルの変数 ID 取得 -----
205 copyurl = urlmerge(file, varname)
206 call open(copyfrom, copyurl)
207
208 !----- 変数コピー -----
209 call inquire(hst % dimvars(1), url=url)
210 fullname = urlresolve((gt_atmark // trim(varname)), trim(url))
211 overwrite_required = .true.
212 if (present_and_false(overwrite)) overwrite_required = .false.
213 call create(hst % vars(nvars), trim(fullname), copyfrom, &
214 & copyvalue=.false., overwrite=overwrite_required)
215
216 !----- 無制限次元の添字を探査 -----
217 call inquire(hst % vars(nvars), alldims=numdims)
218 allocate(dimvars(numdims))
219 ! 各次元毎に情報を取得し, growable == .TRUE. のもの (つまりは時間)
220 ! の添字番号を取得する
221 do, i = 1, numdims
222 call open(var=dimvars(i), source_var=hst % vars(nvars), &
223 & dimord=i, count_compact=.true.)
224 ! 各次元変数の growable を調べる
225 call inquire(var=dimvars(i), growable=growable)
226 if (growable) then
227 hst % growable_indices(nvars) = i
228 endif
229 enddo
230
231 !----- 拡張可能次元があったらそれをサイズ 1 に拡張しておく -----
232 if (hst % growable_indices(nvars) /= 0) then
233 call slice(hst % vars(nvars), hst % growable_indices(nvars), &
234 & start=1, count=1, stride=1)
235 endif
236
237 deallocate(dimvars)
238
239 call inquire( hst % vars(nvars), size = var_avr_length )
240 allocate( hst % var_avr_data(nvars) % a_DataAvr(var_avr_length) )
241 hst % var_avr_data(nvars) % length = var_avr_length
242 hst % var_avr_data(nvars) % a_DataAvr = 0.0_dp
243
244 call close(copyfrom)
245 call endsub(subname)
Judge optional control parameters.
logical function, public present_and_false(arg)
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: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
Variable URL string parser.
Definition dc_url.f90:61
character, parameter, public gt_atmark
Definition dc_url.f90:96
type(gt_history), target, save, public default

References dc_trace::beginsub(), gtool_history_internal::default, dc_types::dp, dc_trace::endsub(), dc_url::gt_atmark, dc_present::present_and_false(), and dc_types::string.

Here is the call graph for this function: