gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
hstnmlinfoadd.f90
Go to the documentation of this file.
1!> @file hstnmlinfoadd.f90
2!>
3!> @author Yasuhiro MORIKAWA
4!> @copyright Copyright (C) GFD Dennou Club, 2007-2026. All rights reserved. <br/>
5!> License is BSD-2-Clause. See [COPYRIGHT](@ref COPYRIGHT) in detail
6!>
7!> @en
8!> @brief Add output information of a variable
9!> @enden
10!>
11!> @ja
12!> @brief 変数の出力情報の追加
13!> @endja
14
15 !> @en
16 !> @brief Add output information of a variable
17 !>
18 !> Add output information of a variable.
19 !>
20 !> In order to set default values, specify blank to @p name or
21 !> do not specify @p name.
22 !> When default values are specified, @p file is ignored.
23 !> @p fileprefix is valid only when default values are specified.
24 !>
25 !> When a variable identifier is specified to @p name and
26 !> @p file is not specified or blanks are specified to @p file,
27 !> "<em>string given to name</em>.nc" is specified to @p file.
28 !>
29 !> If @p gthstnml is not initialized by HstNmlInfoCreate yet,
30 !> error is occurred.
31 !> @enden
32 !>
33 !> @ja
34 !> @brief 変数の出力情報を追加する
35 !>
36 !> 変数の出力情報を加えます.
37 !>
38 !> デフォルト値を設定するには, @p name を与えないか, または
39 !> @p name に空白を与えてください.
40 !> デフォルト値を与える場合, @p file に与えられる情報は無視されます.
41 !> @p fileprefix はデフォルト値に与える場合のみ有効です.
42 !>
43 !> @p name に変数名が指定され, その際に @p file が与えられない,
44 !> または空白が与えられる場合, @p file には
45 !> "<em>name に与えられた文字</em>.nc" が指定されます.
46 !>
47 !> なお, 与えられた @p gthstnml が HstNmlInfoCreate によって初期設定
48 !> されていない場合, プログラムはエラーを発生させます.
49 !> @endja
50 !>
51 !> @param[inout] gthstnml gtool_history_nmlinfo_types::GTHST_NMLINFO 型変数
52 !> @param[in] name 変数名 (optional). Variable identifier.
53 !> @param[in] file ファイル名 (optional). History data filename.
54 !> @param[in] interval_value 出力間隔の数値 (optional). Numerical value for interval.
55 !> @param[in] interval_unit 出力間隔の単位 (optional). Unit for interval.
56 !> @param[in] precision 精度 (optional). Precision.
57 !> @param[in] time_average 時間平均化フラグ (optional). Flag for time average.
58 !> @param[in] average time_average の旧版 (optional). Old version of time_average.
59 !> @param[in] fileprefix ファイル名の接頭詞 (optional). Prefixes of filenames.
60 !> @param[in] origin_value 出力開始時刻 (optional). Start time of output.
61 !> @param[in] origin_unit 出力開始時刻の単位 (optional). Unit of start time.
62 !> @param[in] terminus_value 出力終了時刻 (optional). End time of output.
63 !> @param[in] terminus_unit 出力終了時刻の単位 (optional). Unit of end time.
64 !> @param[in] slice_start 空間方向の開始点 (optional). Start points of spaces.
65 !> @param[in] slice_end 空間方向の終了点 (optional). End points of spaces.
66 !> @param[in] slice_stride 空間方向の刻み幅 (optional). Strides of spaces.
67 !> @param[in] space_average 平均化のフラグ (optional). Flag of average.
68 !> @param[in] newfile_intvalue ファイル分割時間間隔 (optional). Interval of file separation.
69 !> @param[in] newfile_intunit ファイル分割時間間隔の単位 (optional). Unit of file separation interval.
70 !> @param[out] err 例外処理用フラグ. Exception handling flag.
71 recursive subroutine hstnmlinfoadd( gthstnml, &
72 & name, file, &
73 & interval_value, interval_unit, &
74 & precision, &
75 & time_average, average, &
76 & fileprefix, &
77 & origin_value, origin_unit, &
78 & terminus_value, terminus_unit, &
79 & slice_start, slice_end, slice_stride, &
80 & space_average, &
81 & newfile_intvalue, newfile_intunit, &
82 & err )
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 )
515 end subroutine hstnmlinfoadd
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)
日付・時刻に関する構造データ型と定数
日付および時刻に関する手続きを提供するモジュール
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