gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
hstnmlinfoadd.f90 File Reference

変数の出力情報の追加 More...

Go to the source code of this file.

Functions/Subroutines

recursive subroutine hstnmlinfoadd (gthstnml, name, file, interval_value, interval_unit, precision, time_average, average, fileprefix, origin_value, origin_unit, terminus_value, terminus_unit, slice_start, slice_end, slice_stride, space_average, newfile_intvalue, newfile_intunit, err)

Detailed Description

変数の出力情報の追加

Author
Yasuhiro MORIKAWA

Definition in file hstnmlinfoadd.f90.

Function/Subroutine Documentation

◆ hstnmlinfoadd()

recursive subroutine hstnmlinfoadd ( type(gthst_nmlinfo), intent(inout) gthstnml,
character(*), intent(in), optional name,
character(*), intent(in), optional file,
real(dp), intent(in), optional interval_value,
character(*), intent(in), optional interval_unit,
character(*), intent(in), optional precision,
logical, intent(in), optional time_average,
logical, intent(in), optional average,
character(*), intent(in), optional fileprefix,
real(dp), intent(in), optional origin_value,
character(*), intent(in), optional origin_unit,
real(dp), intent(in), optional terminus_value,
character(*), intent(in), optional terminus_unit,
integer, dimension(:), intent(in), optional slice_start,
integer, dimension(:), intent(in), optional slice_end,
integer, dimension(:), intent(in), optional slice_stride,
logical, dimension(:), intent(in), optional space_average,
integer, intent(in), optional newfile_intvalue,
character(*), intent(in), optional newfile_intunit,
logical, intent(out), optional err )

変数の出力情報を追加する

変数の出力情報を加えます.

デフォルト値を設定するには, name を与えないか, または name に空白を与えてください. デフォルト値を与える場合, file に与えられる情報は無視されます. fileprefix はデフォルト値に与える場合のみ有効です.

name に変数名が指定され, その際に file が与えられない, または空白が与えられる場合, file には "<em>name に与えられた文字</em>.nc" が指定されます.

なお, 与えられた gthstnml が HstNmlInfoCreate によって初期設定 されていない場合, プログラムはエラーを発生させます.

Parameters
[in,out]gthstnmlgtool_history_nmlinfo_types::GTHST_NMLINFO 型変数
[in]name変数名 (optional). Variable identifier.
[in]fileファイル名 (optional). History data filename.
[in]interval_value出力間隔の数値 (optional). Numerical value for interval.
[in]interval_unit出力間隔の単位 (optional). Unit for interval.
[in]precision精度 (optional). Precision.
[in]time_average時間平均化フラグ (optional). Flag for time average.
[in]averagetime_average の旧版 (optional). Old version of time_average.
[in]fileprefixファイル名の接頭詞 (optional). Prefixes of filenames.
[in]origin_value出力開始時刻 (optional). Start time of output.
[in]origin_unit出力開始時刻の単位 (optional). Unit of start time.
[in]terminus_value出力終了時刻 (optional). End time of output.
[in]terminus_unit出力終了時刻の単位 (optional). Unit of end time.
[in]slice_start空間方向の開始点 (optional). Start points of spaces.
[in]slice_end空間方向の終了点 (optional). End points of spaces.
[in]slice_stride空間方向の刻み幅 (optional). Strides of spaces.
[in]space_average平均化のフラグ (optional). Flag of average.
[in]newfile_intvalueファイル分割時間間隔 (optional). Interval of file separation.
[in]newfile_intunitファイル分割時間間隔の単位 (optional). Unit of file separation interval.
[out]err例外処理用フラグ. Exception handling flag.

Definition at line 71 of file hstnmlinfoadd.f90.

90 use dc_types, only: dp, string, token
91 use dc_date_types, only: dc_difftime
92 use dc_date, only: dcdifftimecreate, operator(>), operator(<)
93 use dc_message, only: messagenotify
96 use netcdf, only: nf90_max_dims
97 implicit none
98 type(GTHST_NMLINFO), intent(inout):: gthstnml
99 character(*), intent(in), optional:: name
100 ! 変数名.
101 !
102 ! 先頭の空白は無視されます.
103 !
104 ! "Data1,Data2" のようにカンマで区切って複数
105 ! の変数を指定することも可能です.
106 !--
107 ! ただし,
108 ! その際には, *file* 引数で与えられる情報は
109 ! 無視されます. その他の情報はそれぞれの
110 ! 変数の情報として設定されます.
111 !++
112 !
113 ! Variable identifier.
114 !
115 ! Blanks at the head of the name are ignored.
116 !
117 ! Multiple variables can be specified
118 ! as "Data1,Data2" too. Delimiter is comma.
119 !--
120 ! In this case, *file* is ignored, and
121 ! other information is set to each variable.
122 !++
123 !
124 character(*), intent(in), optional:: file
125 ! ヒストリデータのファイル名.
126 ! History data filenames
127 real(DP), intent(in), optional:: interval_value
128 ! ヒストリデータの出力間隔の数値.
129 ! 負の値を与えると, 出力を抑止します.
130 !
131 ! Numerical value for interval of history data output.
132 ! Negative values suppresses output.
133 character(*), intent(in), optional:: interval_unit
134 ! ヒストリデータの出力間隔の単位.
135 ! Unit for interval of history data output
136 character(*), intent(in), optional:: precision
137 ! ヒストリデータの精度.
138 ! Precision of history data
139 logical, intent(in), optional:: time_average
140 ! 出力データの時間平均化フラグ.
141 ! Flag for time average of output data.
142 logical, intent(in), optional:: average
143 ! time_average の旧版.
144 ! Old version of "time_average"
145 character(*), intent(in), optional:: fileprefix
146 ! ヒストリデータのファイル名の接頭詞.
147 ! Prefixes of history data filenames
148 real(DP), intent(in), optional:: origin_value
149 ! 出力開始時刻.
150 ! Start time of output.
151 character(*), intent(in), optional:: origin_unit
152 ! 出力開始時刻の単位.
153 ! Unit of start time of output.
154 real(DP), intent(in), optional:: terminus_value
155 ! 出力終了時刻.
156 ! End time of output.
157 character(*), intent(in), optional:: terminus_unit
158 ! 出力終了時刻の単位.
159 ! Unit of end time of output.
160 integer, intent(in), optional:: slice_start(:)
161 ! 空間方向の開始点.
162 ! Start points of spaces.
163 integer, intent(in), optional:: slice_end(:)
164 ! 空間方向の終了点.
165 ! End points of spaces.
166 integer, intent(in), optional:: slice_stride(:)
167 ! 空間方向の刻み幅.
168 ! Strides of spaces.
169 logical, intent(in), optional:: space_average(:)
170 ! 平均化のフラグ.
171 ! Flag of average.
172 integer, intent(in), optional:: newfile_intvalue
173 ! ファイル分割時間間隔.
174 ! Interval of time of separation of a file.
175 character(*), intent(in), optional:: newfile_intunit
176 ! ファイル分割時間間隔の単位.
177 ! Unit of interval of time of separation of a file.
178 logical, intent(out), optional:: err
179 ! 例外処理用フラグ.
180 ! デフォルトでは, この手続き内でエラーが
181 ! 生じた場合, プログラムは強制終了します.
182 ! 引数 *err* が与えられる場合,
183 ! プログラムは強制終了せず, 代わりに
184 ! *err* に .true. が代入されます.
185 !
186 ! Exception handling flag.
187 ! By default, when error occur in
188 ! this procedure, the program aborts.
189 ! If this *err* argument is given,
190 ! .true. is substituted to *err* and
191 ! the program does not abort.
192
193 !-----------------------------------
194 ! 作業変数
195 ! Work variables
196 type(GTHST_NMLINFO_ENTRY), pointer:: hptr =>null()
197 type(GTHST_NMLINFO_ENTRY), pointer:: hptr_last =>null()
198 type(DC_DIFFTIME):: interval_time, newfileint_time
199 character(TOKEN), pointer:: varnames_array(:) =>null()
200 integer:: i, vnmax, ary_size
201 integer:: stat
202 character(STRING):: cause_c
203 character(*), parameter:: subname = 'HstNmlInfoAdd'
204 continue
205 call beginsub( subname, &
206 & fmt = '@name=%a @file=%a @interval_value=%r @interval_unit=%a @precision=%a @time_average=%y @fileprefix=%a', &
207 & d = (/ present_select(.true., -1.0_dp, interval_value) /), &
208 & l = (/ present_and_true(time_average) /), &
209 & ca = stoa( present_select(.true., '<no>', name), &
210 & present_select(.true., '<no>', file), &
211 & present_select(.true., '<no>', interval_unit), &
212 & present_select(.true., '<no>', precision), &
213 & present_select(.true., '<no>', fileprefix) ) &
214 & )
215
216 stat = dc_noerr
217 cause_c = ''
218
219 !-----------------------------------------------------------------
220 ! 初期設定のチェック
221 ! Check initialization
222 !-----------------------------------------------------------------
223 if ( .not. gthstnml % initialized ) then
224 stat = dc_enotinit
225 cause_c = 'GTHST_NMLINFO'
226 goto 999
227 end if
228
229 if ( .not. gthstnml % define_mode ) then
230 stat = hst_enotindefine
231 cause_c = 'Add'
232 goto 999
233 end if
234
235 !-----------------------------------------------------------------
236 ! 複数の変数を設定する場合
237 ! Configure multiple variables
238 !-----------------------------------------------------------------
239 if ( present_and_not_empty(name) ) then
240 if ( index(name, name_delimiter) > 0 ) then
241 call dbgmessage( 'multiple entries (%c) will be created', c1 = trim(name) )
242!!$ if ( present(file) ) call DbgMessage( 'argument @file=%c is ignored', c1 = trim(file) )
243
244 call split( str = name, sep = name_delimiter, & ! (in)
245 & carray = varnames_array ) ! (out)
246 vnmax = size( varnames_array )
247
248 do i = 1, vnmax
249 call hstnmlinfoadd( &
250 & gthstnml = gthstnml, & ! (inout)
251 & name = varnames_array(i), & ! (in)
252 & file = file, & ! (in)
253 & interval_value = interval_value, & ! (in)
254 & interval_unit = interval_unit, & ! (in)
255 & precision = precision, & ! (in)
256 & time_average = time_average, & ! (in)
257 & average = average, & ! (in)
258 & origin_value = origin_value, & ! (in)
259 & origin_unit = origin_unit, & ! (in)
260 & terminus_value = terminus_value, & ! (in)
261 & terminus_unit = terminus_unit, & ! (in)
262 & slice_start = slice_start, & ! (in)
263 & slice_end = slice_end, & ! (in)
264 & slice_stride = slice_stride, & ! (in)
265 & space_average = space_average, & ! (in)
266 & newfile_intvalue = newfile_intvalue, & ! (in)
267 & newfile_intunit = newfile_intunit, & ! (in)
268 & err = err ) ! (out)
269 if ( present_and_true( err ) ) then
270 deallocate( varnames_array )
271 stat = usr_errno
272 goto 999
273 end if
274 end do
275 deallocate( varnames_array )
276 goto 999
277 end if
278 end if
279
280 !-----------------------------------------------------------------
281 ! *gthstnml* へ情報を追加.
282 ! Add information to *gthstnml*
283 !-----------------------------------------------------------------
284 if ( .not. present_and_not_empty(name) ) then
285 if ( present(interval_value) ) gthstnml % gthstnml_list % interval_value = &
286 & real(interval_value, kind=kind(gthstnml % gthstnml_list % interval_value))
287 if ( present(interval_unit) ) gthstnml % gthstnml_list % interval_unit = interval_unit
288 if ( present(precision) ) gthstnml % gthstnml_list % precision = precision
289 if ( present(average) ) gthstnml % gthstnml_list % time_average = average
290 if ( present(time_average) ) gthstnml % gthstnml_list % time_average = time_average
291 if ( present(fileprefix) ) gthstnml % gthstnml_list % fileprefix = fileprefix
292
293 if ( present(origin_value ) ) gthstnml % gthstnml_list % origin_value = &
294 & real(origin_value, kind=kind(gthstnml % gthstnml_list % origin_value))
295 if ( present(origin_unit ) ) gthstnml % gthstnml_list % origin_unit = origin_unit
296 if ( present(terminus_value ) ) gthstnml % gthstnml_list % terminus_value = &
297 & real(terminus_value, kind=kind(gthstnml % gthstnml_list % terminus_value))
298 if ( present(terminus_unit ) ) gthstnml % gthstnml_list % terminus_unit = terminus_unit
299 if ( present(slice_start ) ) then
300 ary_size = size(slice_start)
301 gthstnml % gthstnml_list % slice_start(1:ary_size) = slice_start
302 end if
303 if ( present(slice_end ) ) then
304 ary_size = size(slice_end)
305 gthstnml % gthstnml_list % slice_end(1:ary_size) = slice_end
306 end if
307 if ( present(slice_stride ) ) then
308 ary_size = size(slice_stride)
309 gthstnml % gthstnml_list % slice_stride(1:ary_size) = slice_stride
310 end if
311 if ( present(space_average ) ) then
312 ary_size = size(space_average)
313 gthstnml % gthstnml_list % space_average(1:ary_size) = space_average
314 end if
315 if ( present(newfile_intvalue) ) gthstnml % gthstnml_list % newfile_intvalue = newfile_intvalue
316 if ( present(newfile_intunit ) ) gthstnml % gthstnml_list % newfile_intunit = newfile_intunit
317
318
319 hptr => gthstnml % gthstnml_list
320
321 else
322 hptr => gthstnml % gthstnml_list
323 call listsearch( gthstnml_list = hptr, & ! (inout)
324 & name = name ) ! (in)
325 if ( .not. associated(hptr) ) then
326 call dbgmessage( 'new entry (%c) is created', c1 = trim( adjustl( name ) ) )
327
328 hptr_last => gthstnml % gthstnml_list
329 call listlast( gthstnml_list = hptr_last ) ! (inout)
330 allocate( hptr )
331
332 nullify( hptr % next )
333
334 hptr % interval_value => gthstnml % gthstnml_list % interval_value
335 hptr % interval_unit => gthstnml % gthstnml_list % interval_unit
336 hptr % precision => gthstnml % gthstnml_list % precision
337 hptr % time_average => gthstnml % gthstnml_list % time_average
338 hptr % fileprefix => gthstnml % gthstnml_list % fileprefix
339
340 hptr % origin_value => gthstnml % gthstnml_list % origin_value
341 hptr % origin_unit => gthstnml % gthstnml_list % origin_unit
342 hptr % terminus_value => gthstnml % gthstnml_list % terminus_value
343 hptr % terminus_unit => gthstnml % gthstnml_list % terminus_unit
344 hptr % slice_start => gthstnml % gthstnml_list % slice_start
345 hptr % slice_end => gthstnml % gthstnml_list % slice_end
346 hptr % slice_stride => gthstnml % gthstnml_list % slice_stride
347 hptr % space_average => gthstnml % gthstnml_list % space_average
348 hptr % newfile_intvalue => gthstnml % gthstnml_list % newfile_intvalue
349 hptr % newfile_intunit => gthstnml % gthstnml_list % newfile_intunit
350
351 hptr_last % next => hptr
352 else
353 call dbgmessage( 'entry (%c) is overwritten', c1 = trim( adjustl( name ) ) )
354 end if
355
356 hptr % name = adjustl( name )
357 if ( present_and_not_empty(file) ) then
358 hptr % file = file
359 nullify( hptr % fileprefix )
360 allocate( hptr % fileprefix )
361 hptr % fileprefix = ''
362 else
363 hptr % file = trim( adjustl(name) ) // '.nc'
364 end if
365
366 if ( present(interval_value) ) then
367 nullify( hptr % interval_value )
368 allocate( hptr % interval_value )
369 hptr % interval_value = real(interval_value, kind=kind(hptr % interval_value))
370 end if
371 if ( present(interval_unit) ) then
372 nullify( hptr % interval_unit )
373 allocate( hptr % interval_unit )
374 hptr % interval_unit = interval_unit
375 end if
376 if ( present(precision) ) then
377 nullify( hptr % precision )
378 allocate( hptr % precision )
379 hptr % precision = precision
380 end if
381 if ( present(average) ) then
382 nullify( hptr % time_average )
383 allocate( hptr % time_average )
384 hptr % time_average = average
385 end if
386 if ( present(time_average) ) then
387 nullify( hptr % time_average )
388 allocate( hptr % time_average )
389 hptr % time_average = time_average
390 end if
391
392 if ( present(origin_value) ) then
393 nullify( hptr % origin_value )
394 allocate( hptr % origin_value )
395 hptr % origin_value = real(origin_value, kind=kind(hptr % origin_value))
396 end if
397 if ( present(origin_unit) ) then
398 nullify( hptr % origin_unit )
399 allocate( hptr % origin_unit )
400 hptr % origin_unit = origin_unit
401 end if
402 if ( present(terminus_value) ) then
403 nullify( hptr % terminus_value )
404 allocate( hptr % terminus_value )
405 hptr % terminus_value = real(terminus_value, kind=kind(hptr % terminus_value))
406 end if
407 if ( present(terminus_unit) ) then
408 nullify( hptr % terminus_unit )
409 allocate( hptr % terminus_unit )
410 hptr % terminus_unit = terminus_unit
411 end if
412 if ( present(slice_start) ) then
413 ary_size = size( slice_start )
414 nullify( hptr % slice_start )
415 allocate( hptr % slice_start(1:nf90_max_dims) )
416 hptr % slice_start = 1
417 hptr % slice_start(1:ary_size) = slice_start
418 end if
419 if ( present(slice_end) ) then
420 ary_size = size( slice_end )
421 nullify( hptr % slice_end )
422 allocate( hptr % slice_end(1:nf90_max_dims) )
423 hptr % slice_end = -1
424 hptr % slice_end(1:ary_size) = slice_end
425 end if
426 if ( present(slice_stride) ) then
427 ary_size = size( slice_stride )
428 nullify( hptr % slice_stride )
429 allocate( hptr % slice_stride(1:nf90_max_dims) )
430 hptr % slice_stride = 1
431 hptr % slice_stride(1:ary_size) = slice_stride
432 end if
433 if ( present(space_average) ) then
434 ary_size = size( space_average )
435 nullify( hptr % space_average )
436 allocate( hptr % space_average(1:nf90_max_dims) )
437 hptr % space_average = .false.
438 hptr % space_average(1:ary_size) = space_average
439 end if
440 if ( present(newfile_intvalue) ) then
441 nullify( hptr % newfile_intvalue )
442 allocate( hptr % newfile_intvalue )
443 hptr % newfile_intvalue = newfile_intvalue
444 end if
445 if ( present(newfile_intunit) ) then
446 nullify( hptr % newfile_intunit )
447 allocate( hptr % newfile_intunit )
448 hptr % newfile_intunit = newfile_intunit
449 end if
450
451 end if
452
453 !---------------------------------------------------------------
454 ! 時間の単位のチェック
455 ! Check unit of time
456 !---------------------------------------------------------------
457 call dcdifftimecreate( &
458 & diff = interval_time, & ! (out)
459 & value = hptr % interval_value, & ! (in)
460 & unit = hptr % interval_unit, & ! (in)
461 & err = err ) ! (out)
462 if ( present_and_true( err ) ) then
463 call hstnmlinfodelete( &
464 & gthstnml = gthstnml, & ! (inout)
465 & name = name ) ! (in)
466 stat = usr_errno
467 goto 999
468 end if
469
470 !---------------------------------------------------------------
471 ! ファイル分割時間間隔のチェック
472 ! Check interval of time of separation of a file
473 !---------------------------------------------------------------
474 call dcdifftimecreate( &
475 & diff = newfileint_time, & ! (out)
476 & value = real( hptr % newfile_intvalue ), & ! (in)
477 & unit = hptr % newfile_intunit, & ! (in)
478 & err = err ) ! (out)
479 if ( present_and_true( err ) ) then
480 call hstnmlinfodelete( &
481 & gthstnml = gthstnml, & ! (inout)
482 & name = name ) ! (in)
483 stat = usr_errno
484 goto 999
485 end if
486
487 if ( hptr % newfile_intvalue > 0 ) then
488 if ( .not. ( newfileint_time > interval_time ) ) then
489 call messagenotify( 'W', subname, &
490 & 'newfile_int=%d [%c] must be greater than interval=%r [%c]', &
491 & i = (/ hptr % newfile_intvalue /), &
492 & r = (/ hptr % interval_value /), &
493 & c1 = trim( hptr % newfile_intunit ), &
494 & c2 = trim( hptr % interval_unit ) )
495
496 call hstnmlinfodelete( &
497 & gthstnml = gthstnml, & ! (inout)
498 & name = name ) ! (in)
499 stat = hst_ebadnewfileint
500 cause_c = cprintf( '%d [%c]', &
501 & i = (/ hptr % newfile_intvalue /), c1 = trim( hptr % newfile_intunit ) )
502 goto 999
503 end if
504 end if
505
506 nullify( hptr )
507
508 !-----------------------------------------------------------------
509 ! 終了処理, 例外処理
510 ! Termination and Exception handling
511 !-----------------------------------------------------------------
512999 continue
513 call storeerror( stat, subname, err, cause_c )
514 call endsub( subname )
日付・時刻に関する構造データ型と定数
日付および時刻に関する手続きを提供するモジュール
Definition dc_date.f90:57
エラー処理用モジュール
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
integer, parameter, public usr_errno
-1000 以下: ユーザー定義
Definition dc_error.f90:579
integer, parameter, public dc_enotinit
-400 以下: dc ユーティリティのエラー
Definition dc_error.f90:534
integer, parameter, public dc_noerr
エラー等を保持
Definition dc_error.f90:468
integer, parameter, public hst_enotindefine
-500 以下: データ入出力層のエラー
Definition dc_error.f90:557
integer, parameter, public hst_ebadnewfileint
Definition dc_error.f90:569
メッセージの出力
省略可能な制御パラメータの判定
logical function, public present_and_not_empty(arg)
logical function, public present_and_true(arg)
文字型変数の操作
Definition dc_string.f90:83
character(string) function, public joinchar(carray, expr)
デバッグ時の追跡用モジュール
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
種別型パラメタを提供します。
Definition dc_types.f90:55
integer, parameter, public token
単語やキーワードを保持する文字型変数の種別型パラメタ
Definition dc_types.f90:128
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition dc_types.f90:137
integer, parameter, public dp
倍精度実数型変数
Definition dc_types.f90:92
character(1), parameter, public name_delimiter

References dc_trace::beginsub(), dc_trace::dbgmessage(), dc_error::dc_enotinit, dc_error::dc_noerr, dc_types::dp, dc_trace::endsub(), dc_error::hst_ebadnewfileint, dc_error::hst_enotindefine, dc_string::joinchar(), gtool_history_nmlinfo_internal::name_delimiter, dc_present::present_and_not_empty(), dc_present::present_and_true(), dc_error::storeerror(), dc_types::string, dc_types::token, and dc_error::usr_errno.

Here is the call graph for this function: