historyautoaddvariable.f90 File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine historyautoaddvariable1 (varname, dims, longname, units, xtype, time_units, time_average, file, origin, terminus, interval, slice_start, slice_end, slice_stride, space_average, newfile_interval)
 
subroutine historyautoaddvariable2 (varname, dims, longname, units, xtype, time_units, time_average, file, origin, terminus, interval, slice_start, slice_end, slice_stride, space_average, newfile_interval)
 

Function/Subroutine Documentation

◆ historyautoaddvariable1()

subroutine historyautoaddvariable1 ( character(*), intent(in)  varname,
character(*), dimension(:), intent(in)  dims,
character(*), intent(in)  longname,
character(*), intent(in)  units,
character(*), intent(in), optional  xtype,
character(*), intent(in), optional  time_units,
logical, intent(in), optional  time_average,
character(*), intent(in), optional  file,
real(dp), intent(in), optional  origin,
real(dp), intent(in), optional  terminus,
real(dp), intent(in), optional  interval,
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_interval 
)

Definition at line 36 of file historyautoaddvariable.f90.

References gtool_historyauto_internal::all_output_save, dc_trace::beginsub(), gtool_historyauto_internal::cal_save, gtool_historyauto_internal::data_weights, dc_error::dc_enotinit, dc_error::dc_noerr, dc_types::dp, dc_trace::endsub(), gtool_historyauto_internal::flag_allvarfixed, gtool_historyauto_internal::gthst_axes, gtool_historyauto_internal::gthst_history_vars, gtool_historyauto_internal::gthst_vars, gtool_historyauto_internal::gthst_weights, gtool_historyauto_internal::gthstnml, dc_error::hst_ealreadyregvarfix, dc_error::hst_eindivisible, dc_error::hst_emaxdimsdepended, dc_error::hst_evarinuse, gtool_historyauto_internal::initialized, gtool_historyauto_internal::interval_time_vars, gtool_historyauto_internal::interval_unitsym_vars, dc_string::joinchar(), gtool_historyauto_internal::max_dims_depended_by_var, gtool_historyauto_internal::max_vars, gtool_historyauto_internal::newfile_inttime_vars, gtool_historyauto_internal::numdims, gtool_historyauto_internal::numvars, gtool_historyauto_internal::numwgts, gtool_historyauto_internal::origin_time_vars, gtool_historyauto_internal::output_valid_vars, gtool_historyauto_internal::slice_vars, gtool_historyauto_internal::space_avr_vars, dc_error::storeerror(), dc_types::string, gtool_historyauto_internal::tavr_vars, gtool_historyauto_internal::terminus_time_vars, gtool_historyauto_internal::time_unit_bycreate, dc_types::token, gtool_historyauto_internal::varname_vars, gtool_historyauto_internal::version, gtool_historyauto_internal::weight_vars, and gtool_historyauto_internal::wgtsuf.

36  !
37  ! データ出力するための変数登録を行います.
38  !
39  ! HistoryAutoAllVarFix を呼ぶ前にこのサブルーチンを使用してください.
40  !
41  ! * 時間平均について
42  !
43  ! gtool_historyauto を用いた出力では,
44  ! 以下のいづれかの条件を満たす場合に出力データを
45  ! 時間方向に平均化して出力します.
46  !
47  ! 1. HistoryAutoCreate の引数 *namelist_filename* に
48  ! 指定された NAMELIST ファイル内において
49  ! NAMELIST 変数群 "NAMELIST#gtool_historyauto_nml" 内の
50  ! 変数の一つである 論理型変数 TimeAverage に .true. が
51  ! 与えられている.
52  !
53  ! 2. HistoryAutoAddVariable の引数 *time_average* に
54  ! .true. を与えている.
55  !
56  ! 3. HistoryAutoCreate の引数 *time_average* に
57  ! .true. を与えている.
58  !
59  ! 時間平均を行わない場合には, HistoryAutoPut の引数
60  ! *time* に与えられた時刻と出力のタイミングが合致しない場合,
61  ! HistoryAutoPut の *value* もしくは *array* に与えられた値は
62  ! 全て破棄されます. 一方で上記の条件を満たす場合には,
63  ! 本来破棄されていた値を gtool_historyauto モジュール内部
64  ! にいったん保管し, それらを出力のタイミングで平均化して
65  ! 出力します. 平均化は出力時から次の出力時の間の
66  ! データを用いて行われます. 時間間隔が一定でない場合、
67  ! 重み付けをして出力されます. 重み付けは以下のように
68  ! 行われます.
69  !
70  ! sum( <data> * <weight> ) / sum ( <weight> )
71  !
72  ! <data> :: *array* または *value* に与えられたデータ
73  ! <weight> :: 前回 HistoryAutoPut が呼ばれた際の時刻と今回の時刻との差
74  ! sum :: 前回出力が行われた時刻から *interval* 経過するまでの値の和
75  !
76  !
77  ! Register variables for history data output
78  !
79  ! Use this subroutine before "HistoryAutoAllVarFix" is called.
80  !
81 
82  ! モジュール引用 ; USE statements
83  !
84 
87  & numvars, numwgts, &
101  use dc_trace, only: beginsub, endsub
102  use dc_error, only: storeerror, dc_noerr, hst_evarinuse, &
105  use dc_message, only: messagenotify
106  use dc_string, only: strinclude, joinchar, tochar
108  use dc_date, only: dcdifftimecreate, operator(/), mod, evalsec, &
109  & operator(-), evalbyunit
111  use netcdf, only: nf90_emaxvars, nf90_max_dims
112  use dc_types, only: dp, string, token
113 
114  ! 宣言文 ; Declaration statements
115  !
116  implicit none
117  character(*), intent(in):: varname
118  ! 変数名. Variable name
119  character(*), intent(in):: dims(:)
120  ! 変数が依存する次元の名前.
121  ! 時間の次元は配列の最後に指定すること.
122  !
123  ! Names of dependency dimensions of a variable.
124  ! Dimension of time must be specified
125  ! to last of an array.
126  character(*), intent(in):: longname
127  ! 変数の記述的名称.
128  !
129  ! Descriptive name of a variable
130  character(*), intent(in):: units
131  ! 変数の単位.
132  !
133  ! Units of a variable
134  character(*), intent(in), optional:: xtype
135  !
136  ! 変数のデータ型
137  !
138  ! デフォルトは float (単精度実数型) であ
139  ! る. 有効なのは, double (倍精度実数型),
140  ! int (整数型) である. 指定しない 場合や,
141  ! 無効な型を指定した場合には, float (単
142  ! 精度実数型) となる.
143  !
144  ! Data types of dimensions specified
145  ! with "dims".
146  !
147  ! Default value is "float" (single precision).
148  ! Other valid values are
149  ! "double" (double precision),
150  ! "int" (integer).
151  ! If no value or invalid value is specified,
152  ! "float" is applied.
153  !
154  character(*), intent(in), optional:: time_units
155  ! 時刻次元の単位.
156  ! Units of time dimension.
157  logical, intent(in), optional:: time_average
158  !
159  ! 出力データを時間平均する場合には
160  ! .true. を与えます. デフォルトは
161  ! .false. です.
162  !
163  ! If output data is averaged, specify
164  ! ".true.". Default is ".false.".
165  !
166  character(*), intent(in), optional:: file
167  ! 出力ファイル名.
168  ! Output file name.
169 
170  real(DP), intent(in), optional:: origin
171  ! 出力開始時刻.
172  !
173  ! 省略した場合, 自動的に 0.0 [sec] が
174  ! 設定されます.
175  !
176  ! Start time of output.
177  !
178  ! If this argument is omitted,
179  ! 0.0 [sec] is specified
180  ! automatically.
181  !
182  real(DP), intent(in), optional:: terminus
183  ! 出力終了時刻.
184  !
185  ! 省略した場合, 数値モデルの実行が終了するまで
186  ! 出力を行います.
187  !
188  ! End time of output.
189  !
190  ! If this argument is omitted,
191  ! output is continued until a numerical model
192  ! is finished.
193  !
194  real(DP), intent(in), optional:: interval
195  ! 出力時間間隔.
196  !
197  ! 省略した場合,
198  ! 自動的に 1.0 [sec] が設定されます.
199  !
200  ! Interval of output time.
201  !
202  ! If this argument is omitted,
203  ! a value of 1.0 [sec] is specified
204  ! automatically.
205  !
206  integer, intent(in), optional:: slice_start(:)
207  ! 空間方向の開始点.
208  !
209  ! 省略した場合, 座標データの開始点が設定されます.
210  !
211  ! Start points of spaces.
212  !
213  ! If this argument is omitted,
214  ! start points of dimensions are set.
215  !
216  integer, intent(in), optional:: slice_end(:)
217  ! 空間方向の終了点.
218  !
219  ! 省略した場合, 座標データの終了点が設定されます.
220  !
221  ! End points of spaces.
222  !
223  ! If this argument is omitted,
224  ! End points of dimensions are set.
225  !
226  integer, intent(in), optional:: slice_stride(:)
227  ! 空間方向の刻み幅.
228  !
229  ! 省略した場合, 1 が設定されます.
230  !
231  ! Strides of spaces
232  !
233  ! If this argument is omitted,
234  ! 1 is set.
235  !
236  logical, intent(in), optional:: space_average(:)
237  ! 平均化のフラグ.
238  !
239  ! .true. が指定される座標に対して平均化を
240  ! 行います.
241  ! 省略した場合, .false. が設定されます.
242  !
243  ! Flag of average.
244  !
245  ! Axes specified .true. are averaged.
246  ! If this argument is omitted,
247  ! .false. is set.
248  !
249  integer, intent(in), optional:: newfile_interval
250  ! ファイル分割時間間隔.
251  !
252  ! 省略した場合,
253  ! 時間方向へのファイル分割を行いません.
254  !
255  ! Interval of time of separation of a file.
256  !
257  ! If this argument is omitted,
258  ! a files is not separated in time direction.
259  !
260 
261  ! 作業変数
262  ! Work variables
263  !
264  character(TOKEN):: interval_unit_work
265  ! データの出力間隔の単位.
266  ! Unit for interval of history data output
267  character(TOKEN):: origin_unit_work
268  ! 出力開始時刻の単位.
269  ! Unit of start time of output.
270  character(TOKEN):: terminus_unit_work
271  ! 出力終了時刻の単位.
272  ! Unit of end time of output.
273  character(TOKEN):: newfile_intunit_work
274  ! ファイル分割時間間隔の単位.
275  ! Unit of interval of time of separation of a file.
276 
277  real(DP):: interval_value
278  ! データの出力間隔の数値.
279  ! Numerical value for interval of history data output
280  real(DP):: origin_value
281  ! データの出力開始時刻の数値.
282  ! Numerical value for start time of history data output
283  real(DP):: terminus_value
284  ! 出力終了時刻の数値.
285  ! Numerical value for end time of output.
286  integer:: newfile_intvalue
287  ! ファイル分割時間間隔.
288  ! Interval of time of separation of a file.
289  character(TOKEN):: time_name
290  ! 時刻次元の名称.
291  ! Name of time dimension
292  character(STRING), allocatable:: dims_work(:)
293  ! 変数が依存する次元の名前.
294  ! Names of dependency dimensions of a variable.
295  character(TOKEN):: precision
296  ! データの精度.
297  ! Precision of history data
298  logical:: time_average_work
299  ! 出力データの時間平均フラグ.
300  ! Flag for time average of output data
301  logical:: space_average_work(1:numdims-1)
302  integer:: slice_start_work(1:numdims-1)
303  ! 空間方向の開始点.
304  ! Start points of spaces.
305  integer:: slice_end_work(1:numdims-1)
306  ! 空間方向の終了点.
307  ! End points of spaces.
308  integer:: slice_stride_work(1:numdims-1)
309  ! 空間方向の刻み幅.
310  ! Strides of spaces
311 
312  logical:: define_mode, varname_not_found
313  integer:: cause_i, stat, i, j, k, cnt, cnt2, dim_size
314  character(TOKEN), pointer:: dims_noavr(:) =>null(), dims_avr(:) =>null()
315  character(STRING):: longname_avrmsg
316  character(STRING):: name, cause_c
317  character(*), parameter:: subname = "HistoryAutoAddVariable1"
318  continue
319  call beginsub(subname, 'varname=%c', c1 = trim(varname), version = version)
320  stat = dc_noerr
321  cause_c = ""
322  cause_i = 0
323 
324  ! 初期設定チェック
325  ! Check initialization
326  !
327  if ( .not. initialized ) then
328  stat = dc_enotinit
329  cause_c = 'gtool_historyauto'
330  goto 999
331  end if
332 
333  ! 既に HistoryAutoAllVarFix が呼ばれていたらエラー
334  ! Error is occurred if "HistoryAutoAllVarFix" is called already
335  !
336  if ( flag_allvarfixed ) then
337  call messagenotify( 'W', subname, &
338  & '"HistoryAutoAddVariable" (varname = %c) must be called before "HistoryAutoAllVarFix"', &
339  & c1 = trim(varname) )
340  stat = hst_ealreadyregvarfix
341  cause_c = 'HistoryAutoAllVarFix'
342  goto 999
343  end if
344 
345  ! 重複のチェック
346  ! Check duplication
347  !
348  do i = 1, numvars
349  call historyvarinfoinquire( &
350  & varinfo = gthst_vars(i), & ! (in)
351  & name = name ) ! (out)
352  if ( trim(varname) == trim(name) ) then
353  stat = hst_evarinuse
354  cause_c = varname
355  goto 999
356  end if
357  end do
358 
359  ! 変数の数の限界チェック
360  ! Check limit of number of variables
361  !
362  if ( numvars + 1 > max_vars ) then
363  stat = nf90_emaxvars
364  goto 999
365  end if
366 
367  ! 時刻の次元に関する修正
368  ! Correction for time dimension
369  !
370  call historyaxisinquire( &
371  & axis = gthst_axes(numdims), & ! (in)
372  & name = time_name ) ! (out)
373 
374  if ( size(dims) > 0 ) then
375  if ( strinclude( dims, time_name ) ) then
376  if ( trim( dims(size(dims)) ) == trim( time_name ) ) then
377  allocate( dims_work(size(dims)) )
378  dims_work = dims
379  else
380  allocate( dims_work(size(dims)) )
381  cnt = 1
382  do i = 1, size(dims)
383  if ( trim( dims(i) ) /= trim( time_name ) ) then
384  dims_work( cnt ) = dims( i )
385  cnt = cnt + 1
386  end if
387  end do
388  dims_work(size(dims)) = time_name
389 
390  call messagenotify( 'W', subname, &
391  & 'last entity of "dims=<%c>" must be time dimension (varname=<%c>). ' // &
392  & ' "dims" are resequenced forcibly => <%c>', &
393  & c1 = trim( joinchar(dims, ',') ), c2 = trim( varname ), &
394  & c3 = trim( joinchar(dims_work, ',') ) )
395 
396  end if
397  else
398  allocate( dims_work(size(dims)+1) )
399  dims_work(1:size(dims)) = dims
400  dims_work(size(dims)+1) = time_name
401  call messagenotify( 'W', subname, &
402  & 'time dimension is not found in "dims=<%c>" (varname=<%c>). ' // &
403  & ' time dimension "%c" is appended to "dims" forcibly.', &
404  & c1 = trim( joinchar(dims, ',') ), c2 = trim( varname ), &
405  & c3 = trim( time_name ) )
406  end if
407  else
408  allocate( dims_work(1) )
409  dims_work(1) = time_name
410  call messagenotify( 'W', subname, &
411  & 'time dimension is not found (varname=<%c>). ' // &
412  & ' time dimension "%c" is appended to "dims" forcibly.', &
413  & c1 = trim( varname ), &
414  & c2 = trim( time_name ) )
415  end if
416 
417  ! 依存する次元の数の限界チェック
418  ! Check limit of number of depended dimensions
419  !
420  if ( size( dims_work ) - 1 > max_dims_depended_by_var ) then
421  call messagenotify( 'W', subname, &
422  & 'number of dimensions' // &
423  & ' on which one variable depends must not be greater than %d (varname=<%c>, dims=<%c>). ', &
424  & i = (/ 7 + 1 /), &
425  & c1 = trim( varname ), c2 = trim( joinchar(dims_work, ',') ) )
426  stat = hst_emaxdimsdepended
427  cause_i = size( dims_work )
428  cause_c = varname
429  end if
430 
431  ! 全ての変数を出力する際には, ここで登録
432  ! Register here if all variables are output
433  !
434  if ( all_output_save ) then
435  call hstnmlinfoinquire( &
436  & gthstnml = gthstnml, name = varname, & ! (in)
437  & err = varname_not_found ) ! (out) optional
438  if ( varname_not_found ) then
439  define_mode = hstnmlinfodefinemode( gthstnml )
440  if ( .not. define_mode ) call hstnmlinforedefine( gthstnml ) ! (inout)
441 
442  call hstnmlinfoinquire( &
443  & gthstnml = gthstnml, & ! (in)
444  & interval_unit = interval_unit_work, & ! (out) optional
445  & origin_unit = origin_unit_work , & ! (out) optional
446  & terminus_unit = terminus_unit_work, & ! (out) optional
447  & newfile_intunit = newfile_intunit_work ) ! (out) optional
448 
449  ! 時刻の単位を設定
450  ! Configure unit of time
451  !
452  if ( present( interval ) ) then
453  interval_unit_work = time_unit_bycreate
454  if ( present(time_units) ) interval_unit_work = time_units
455  end if
456  if ( present( origin ) ) then
457  origin_unit_work = time_unit_bycreate
458  if ( present(time_units) ) origin_unit_work = time_units
459  end if
460  if ( present( terminus ) ) then
461  terminus_unit_work = time_unit_bycreate
462  if ( present(time_units) ) terminus_unit_work = time_units
463  end if
464  if ( present( newfile_interval ) ) then
465  newfile_intunit_work = time_unit_bycreate
466  if ( present(time_units) ) newfile_intunit_work = time_units
467  end if
468 
469  call hstnmlinfoadd( &
470  & gthstnml = gthstnml, & ! (inout)
471  & name = varname, & ! (in) optional
472  & file = file, & ! (in) optional
473  & precision = xtype, & ! (in) optional
474  & interval_value = interval, & ! (in) optional
475  & interval_unit = interval_unit_work, & ! (in) optional
476  & origin_value = origin, & ! (in) optional
477  & origin_unit = origin_unit_work, & ! (in) optional
478  & terminus_value = terminus, & ! (in) optional
479  & terminus_unit = terminus_unit_work, & ! (in) optional
480  & slice_start = slice_start, & ! (in) optional
481  & slice_end = slice_end, & ! (in) optional
482  & slice_stride = slice_stride, & ! (in) optional
483  & time_average = time_average, & ! (in) optional
484  & space_average = space_average, & ! (in) optional
485  & newfile_intvalue = newfile_interval, & ! (in) optional
486  & newfile_intunit = newfile_intunit_work ) ! (in) optional
487  if ( .not. define_mode ) call hstnmlinfoenddefine( gthstnml ) ! (inout)
488  end if
489  end if
490 
491  ! 平均化に伴う次元の縮退を反映した変数情報の作り直し
492  ! Remake information of variables that reflects reduction of dimensions
493  ! correspond to average
494  !
495  call hstnmlinfoinquire( &
496  & gthstnml = gthstnml, name = varname, & ! (in)
497  & precision = precision, & ! (out) optional
498  & time_average = time_average_work, & ! (out) optional
499  & space_average = space_average_work, & ! (out) optional
500  & slice_start = slice_start_work, & ! (out)
501  & slice_end = slice_end_work, & ! (out)
502  & slice_stride = slice_stride_work, & ! (out)
503  & err = varname_not_found ) ! (out) optional
504  if ( varname_not_found ) then
505  call hstnmlinfoinquire( &
506  & gthstnml = gthstnml, name = '', & ! (in)
507  & precision = precision, & ! (out) optional
508  & time_average = time_average_work, & ! (out) optional
509  & space_average = space_average_work, & ! (out) optional
510  & slice_start = slice_start_work, & ! (out)
511  & slice_end = slice_end_work, & ! (out)
512  & slice_stride = slice_stride_work ) ! (out)
513  end if
514 
515  if ( .not. associated( space_avr_vars(numvars + 1) % avr ) ) &
516  & allocate( space_avr_vars(numvars + 1) % avr( size( dims_work ) - 1 ) )
517 
518  space_avr_vars(numvars + 1) % avr = .false.
519  do i = 1, size( dims_work ) - 1
520  do j = 1, numdims - 1
521  call historyaxisinquire( &
522  & axis = gthst_axes(j), & ! (in)
523  & name = name ) ! (out)
524  if ( trim(dims_work(i)) == trim(name) ) then
525  space_avr_vars(numvars + 1) % avr( i ) = space_average_work( j )
526  exit
527  end if
528  end do
529  end do
530 
531  allocate( dims_noavr( size(dims_work) - count(space_avr_vars(numvars + 1) % avr) ) )
532  if ( count(space_avr_vars(numvars + 1) % avr) < 1 ) then
533  dims_noavr = dims_work
534  longname_avrmsg = ''
535  else
536  allocate( dims_avr( count(space_avr_vars(numvars + 1) % avr) ) )
537  cnt = 1 ; cnt2 = 1
538  do i = 1, size( dims_work ) - 1
539  if ( .not. space_avr_vars(numvars + 1) % avr(i) ) then
540  dims_noavr( cnt ) = dims_work( i )
541  cnt = cnt + 1
542  else
543  dims_avr( cnt2 ) = dims_work( i )
544  cnt2 = cnt2 + 1
545  end if
546  end do
547  dims_noavr( cnt ) = dims_work( size ( dims_work ) )
548 
549  longname_avrmsg = ' averaged in ' // trim( joinchar( dims_avr, ',' ) ) // '-direction'
550  deallocate( dims_avr )
551  end if
552 
553  ! HistoryPut の際のデータの切り出し情報作成
554  ! Create information of slices of data for "HistoryPut"
555  !
556  if ( .not. associated( slice_vars(numvars + 1) % st ) ) &
557  & allocate( slice_vars(numvars + 1) % st( nf90_max_dims ) )
558  if ( .not. associated( slice_vars(numvars + 1) % ed ) ) &
559  & allocate( slice_vars(numvars + 1) % ed( nf90_max_dims ) )
560  if ( .not. associated( slice_vars(numvars + 1) % sd ) ) &
561  & allocate( slice_vars(numvars + 1) % sd( nf90_max_dims ) )
562  slice_vars(numvars + 1) % st = 1
563  slice_vars(numvars + 1) % ed = 1
564  slice_vars(numvars + 1) % sd = 1
565 
566  if ( size(dims_work) > 1 ) then
567  slice_subscript_search: do i = 1, size( dims_work ) - 1
568  do j = 1, numdims - 1
569  call historyaxisinquire( &
570  & axis = gthst_axes(j), & ! (in)
571  & name = name, & ! (out)
572  & size = dim_size ) ! (out)
573  if ( slice_end_work(j) < 1 ) slice_end_work(j) = dim_size
574  if ( trim(dims_work(i)) == trim(name) ) then
575  slice_vars(numvars + 1) % st( i ) = slice_start_work( j )
576  slice_vars(numvars + 1) % ed( i ) = slice_end_work( j )
577  slice_vars(numvars + 1) % sd( i ) = slice_stride_work( j )
578  cycle slice_subscript_search
579  end if
580  end do
581  end do slice_subscript_search
582  end if
583 
584 
585  ! HistoryPut の際の座標重み情報作成
586  ! Create information of axes weight for "HistoryPut"
587  !
588 
589  if ( .not. associated( weight_vars(numvars + 1) % wgt1 ) ) &
590  & allocate( weight_vars(numvars + 1) % wgt1( 1 ) )
591  weight_vars(numvars + 1) % wgt1 = 1.0_dp
592 
593  if ( size(dims_work) >= 1 ) then
594  do j = 1, numdims - 1
595  call historyaxisinquire( &
596  & axis = gthst_axes(j), & ! (in)
597  & name = name, & ! (out)
598  & size = dim_size ) ! (out)
599  if ( trim(dims_work(1)) == trim(name) ) then
600  deallocate( weight_vars(numvars + 1) % wgt1 )
601  allocate( weight_vars(numvars + 1) % wgt1( dim_size ) )
602  weight_vars(numvars + 1) % wgt1 = 1.0_dp
603  do k = 1, numwgts
604  call historyvarinfoinquire( &
605  & varinfo = gthst_weights(k), & ! (in)
606  & name = name ) ! (out)
607  if ( trim(dims_work(1)) // wgtsuf == trim(name) ) then
608  weight_vars(numvars + 1) % wgt1 = data_weights( k ) % a_axis
609  exit
610  end if
611  end do
612  exit
613  end if
614  end do
615  end if
616 
617 
618 
619  if ( .not. associated( weight_vars(numvars + 1) % wgt2 ) ) &
620  & allocate( weight_vars(numvars + 1) % wgt2( 1 ) )
621  weight_vars(numvars + 1) % wgt2 = 1.0_dp
622 
623  if ( size(dims_work) >= 2 ) then
624  do j = 1, numdims - 1
625  call historyaxisinquire( &
626  & axis = gthst_axes(j), & ! (in)
627  & name = name, & ! (out)
628  & size = dim_size ) ! (out)
629  if ( trim(dims_work(2)) == trim(name) ) then
630  deallocate( weight_vars(numvars + 1) % wgt2 )
631  allocate( weight_vars(numvars + 1) % wgt2( dim_size ) )
632  weight_vars(numvars + 1) % wgt2 = 1.0_dp
633  do k = 1, numwgts
634  call historyvarinfoinquire( &
635  & varinfo = gthst_weights(k), & ! (in)
636  & name = name ) ! (out)
637  if ( trim(dims_work(2)) // wgtsuf == trim(name) ) then
638  weight_vars(numvars + 1) % wgt2 = data_weights( k ) % a_axis
639  exit
640  end if
641  end do
642  exit
643  end if
644  end do
645  end if
646 
647 
648 
649  if ( .not. associated( weight_vars(numvars + 1) % wgt3 ) ) &
650  & allocate( weight_vars(numvars + 1) % wgt3( 1 ) )
651  weight_vars(numvars + 1) % wgt3 = 1.0_dp
652 
653  if ( size(dims_work) >= 3 ) then
654  do j = 1, numdims - 1
655  call historyaxisinquire( &
656  & axis = gthst_axes(j), & ! (in)
657  & name = name, & ! (out)
658  & size = dim_size ) ! (out)
659  if ( trim(dims_work(3)) == trim(name) ) then
660  deallocate( weight_vars(numvars + 1) % wgt3 )
661  allocate( weight_vars(numvars + 1) % wgt3( dim_size ) )
662  weight_vars(numvars + 1) % wgt3 = 1.0_dp
663  do k = 1, numwgts
664  call historyvarinfoinquire( &
665  & varinfo = gthst_weights(k), & ! (in)
666  & name = name ) ! (out)
667  if ( trim(dims_work(3)) // wgtsuf == trim(name) ) then
668  weight_vars(numvars + 1) % wgt3 = data_weights( k ) % a_axis
669  exit
670  end if
671  end do
672  exit
673  end if
674  end do
675  end if
676 
677 
678 
679  if ( .not. associated( weight_vars(numvars + 1) % wgt4 ) ) &
680  & allocate( weight_vars(numvars + 1) % wgt4( 1 ) )
681  weight_vars(numvars + 1) % wgt4 = 1.0_dp
682 
683  if ( size(dims_work) >= 4 ) then
684  do j = 1, numdims - 1
685  call historyaxisinquire( &
686  & axis = gthst_axes(j), & ! (in)
687  & name = name, & ! (out)
688  & size = dim_size ) ! (out)
689  if ( trim(dims_work(4)) == trim(name) ) then
690  deallocate( weight_vars(numvars + 1) % wgt4 )
691  allocate( weight_vars(numvars + 1) % wgt4( dim_size ) )
692  weight_vars(numvars + 1) % wgt4 = 1.0_dp
693  do k = 1, numwgts
694  call historyvarinfoinquire( &
695  & varinfo = gthst_weights(k), & ! (in)
696  & name = name ) ! (out)
697  if ( trim(dims_work(4)) // wgtsuf == trim(name) ) then
698  weight_vars(numvars + 1) % wgt4 = data_weights( k ) % a_axis
699  exit
700  end if
701  end do
702  exit
703  end if
704  end do
705  end if
706 
707 
708 
709  if ( .not. associated( weight_vars(numvars + 1) % wgt5 ) ) &
710  & allocate( weight_vars(numvars + 1) % wgt5( 1 ) )
711  weight_vars(numvars + 1) % wgt5 = 1.0_dp
712 
713  if ( size(dims_work) >= 5 ) then
714  do j = 1, numdims - 1
715  call historyaxisinquire( &
716  & axis = gthst_axes(j), & ! (in)
717  & name = name, & ! (out)
718  & size = dim_size ) ! (out)
719  if ( trim(dims_work(5)) == trim(name) ) then
720  deallocate( weight_vars(numvars + 1) % wgt5 )
721  allocate( weight_vars(numvars + 1) % wgt5( dim_size ) )
722  weight_vars(numvars + 1) % wgt5 = 1.0_dp
723  do k = 1, numwgts
724  call historyvarinfoinquire( &
725  & varinfo = gthst_weights(k), & ! (in)
726  & name = name ) ! (out)
727  if ( trim(dims_work(5)) // wgtsuf == trim(name) ) then
728  weight_vars(numvars + 1) % wgt5 = data_weights( k ) % a_axis
729  exit
730  end if
731  end do
732  exit
733  end if
734  end do
735  end if
736 
737 
738 
739  if ( .not. associated( weight_vars(numvars + 1) % wgt6 ) ) &
740  & allocate( weight_vars(numvars + 1) % wgt6( 1 ) )
741  weight_vars(numvars + 1) % wgt6 = 1.0_dp
742 
743  if ( size(dims_work) >= 6 ) then
744  do j = 1, numdims - 1
745  call historyaxisinquire( &
746  & axis = gthst_axes(j), & ! (in)
747  & name = name, & ! (out)
748  & size = dim_size ) ! (out)
749  if ( trim(dims_work(6)) == trim(name) ) then
750  deallocate( weight_vars(numvars + 1) % wgt6 )
751  allocate( weight_vars(numvars + 1) % wgt6( dim_size ) )
752  weight_vars(numvars + 1) % wgt6 = 1.0_dp
753  do k = 1, numwgts
754  call historyvarinfoinquire( &
755  & varinfo = gthst_weights(k), & ! (in)
756  & name = name ) ! (out)
757  if ( trim(dims_work(6)) // wgtsuf == trim(name) ) then
758  weight_vars(numvars + 1) % wgt6 = data_weights( k ) % a_axis
759  exit
760  end if
761  end do
762  exit
763  end if
764  end do
765  end if
766 
767 
768 
769  if ( .not. associated( weight_vars(numvars + 1) % wgt7 ) ) &
770  & allocate( weight_vars(numvars + 1) % wgt7( 1 ) )
771  weight_vars(numvars + 1) % wgt7 = 1.0_dp
772 
773  if ( size(dims_work) >= 7 ) then
774  do j = 1, numdims - 1
775  call historyaxisinquire( &
776  & axis = gthst_axes(j), & ! (in)
777  & name = name, & ! (out)
778  & size = dim_size ) ! (out)
779  if ( trim(dims_work(7)) == trim(name) ) then
780  deallocate( weight_vars(numvars + 1) % wgt7 )
781  allocate( weight_vars(numvars + 1) % wgt7( dim_size ) )
782  weight_vars(numvars + 1) % wgt7 = 1.0_dp
783  do k = 1, numwgts
784  call historyvarinfoinquire( &
785  & varinfo = gthst_weights(k), & ! (in)
786  & name = name ) ! (out)
787  if ( trim(dims_work(7)) // wgtsuf == trim(name) ) then
788  weight_vars(numvars + 1) % wgt7 = data_weights( k ) % a_axis
789  exit
790  end if
791  end do
792  exit
793  end if
794  end do
795  end if
796 
797 
798 
799  ! 変数名の有効性を設定
800  ! Set validation of the variable name
801  !
802  call hstnmlinfosetvalidname( &
803  & gthstnml = gthstnml, name = varname ) ! (in)
804 
805  ! 変数情報の登録
806  ! Register information of variable
807  !
808  call historyvarinfocreate( &
809  & varinfo = gthst_vars(numvars + 1), & ! (out)
810  & name = varname, dims = dims_noavr, & ! (in)
811  & longname = trim(longname) // longname_avrmsg , & ! (in)
812  & units = units, xtype = precision, & ! (in)
813  & time_average = time_average_work ) ! (in) optional
814  varname_vars(numvars + 1) = varname
815  tavr_vars(numvars + 1) = time_average_work
816  deallocate( dims_noavr )
817  deallocate( dims_work )
818 
819  ! 出力の有効かどうかを確認する
820  ! Confirm whether the output is effective
821  !
823 
824  ! 出力のタイミングを測るための情報の取得
825  ! Get information for measurement of output timing
826  !
827  if ( output_valid_vars(numvars + 1) ) then
828 
829  ! NAMELIST から読み込まれた情報の取得
830  ! Get information loaded from NAMELIST
831  !
832  call hstnmlinfoinquire( &
833  & gthstnml = gthstnml, & ! (in)
834  & name = varname, & ! (in)
835  & interval_value = interval_value, & ! (out)
836  & interval_unit = interval_unit_work, & ! (out)
837  & origin_value = origin_value, & ! (out)
838  & origin_unit = origin_unit_work, & ! (out)
839  & terminus_value = terminus_value, & ! (out)
840  & terminus_unit = terminus_unit_work, & ! (out)
841  & newfile_intvalue = newfile_intvalue, & ! (out)
842  & newfile_intunit = newfile_intunit_work ) ! (out)
843 
844  ! 出力間隔ステップ数を算出する.
845  ! Calculate number of step of interval of output
846  !
847  interval_time_vars(numvars + 1) = &
848  & dccalconvertbyunit( interval_value, interval_unit_work, 'sec', cal_save )
849 
850  call dccalparseunit( interval_unit_work, & ! (in)
851  & interval_unitsym_vars(numvars + 1) ) ! (out)
852 
853 !!$ call DCDiffTimeCreate( &
854 !!$ & interval_time_vars(numvars + 1), & ! (out)
855 !!$ & interval_value, interval_unit_work ) ! (in)
856 
857  ! ファイルを作成するステップ数を算出する.
858  ! Calculate number of step of interval of output
859  !
860  origin_time_vars(numvars + 1) = &
861  & dccalconvertbyunit( origin_value, origin_unit_work, 'sec', cal_save )
862 
863 !!$ call DCDiffTimeCreate( &
864 !!$ & origin_time_vars(numvars + 1), & ! (out)
865 !!$ & origin_value, origin_unit_work ) ! (in)
866 
867  ! ファイルをクローズするステップ数を算出する.
868  ! Calculate number of step of closure of file
869  !
870  terminus_time_vars(numvars + 1) = &
871  & dccalconvertbyunit( terminus_value, terminus_unit_work, 'sec', cal_save )
872 
873 !!$ call DCDiffTimeCreate( &
874 !!$ & terminus_time_vars(numvars + 1), & ! (out)
875 !!$ & terminus_value, terminus_unit_work ) ! (in)
876 
877  ! ファイルを新規に作り直すステップ数の算出
878  ! Calculate number of step of remake of file
879  !
881  & dccalconvertbyunit( real( newfile_intvalue, DP ), newfile_intunit_work, 'sec', cal_save )
882 
883 !!$ call DCDiffTimeCreate( &
884 !!$ & newfile_inttime_vars(numvars + 1), & ! (out)
885 !!$ & newfile_intvalue, newfile_intunit_work ) ! (in)
886 
887  end if
888 
889  ! GT_HISTORY 変数の取得
890  ! Get "GT_HISTORY" variable
891  !
892  if ( output_valid_vars(numvars + 1) ) then
893  define_mode = hstnmlinfodefinemode( gthstnml )
894  if ( define_mode ) call hstnmlinfoenddefine( gthstnml ) ! (inout)
895  call hstnmlinfoassocgthist( &
896  & gthstnml = gthstnml, name = varname, & ! (in)
897  & history = gthst_history_vars(numvars + 1) % gthist ) ! (out)
898 
899  if ( define_mode ) call hstnmlinforedefine( gthstnml ) ! (inout)
900  end if
901 
902  ! 登録変数の数を更新
903  ! Update number of registered variables
904  !
905  numvars = numvars + 1
906 
907 999 continue
908  call storeerror(stat, subname, cause_c = cause_c, cause_i = cause_i)
909  call endsub(subname, 'stat=%d', i = (/stat/) )
type(slice_info), dimension(1:max_vars), target, save, public slice_vars
integer, parameter, public dc_enotinit
Definition: dc_error.f90:557
real(dp), dimension(1:max_vars), save, public newfile_inttime_vars
integer, parameter, public hst_eindivisible
Definition: dc_error.f90:595
real(dp), dimension(1:max_vars), save, public interval_time_vars
integer, parameter, public max_dims_depended_by_var
type(space_avr_info), dimension(1:max_vars), target, save, public space_avr_vars
character(*), parameter, public wgtsuf
integer, parameter, public token
単語やキーワードを保持する文字型変数の種別型パラメタ
Definition: dc_types.f90:109
real(dp), dimension(1:max_vars), save, public terminus_time_vars
type(gt_history_axis_data), dimension(1:nf90_max_dims), target, save, public data_weights
integer, parameter, public hst_emaxdimsdepended
Definition: dc_error.f90:594
integer, parameter, public hst_ealreadyregvarfix
Definition: dc_error.f90:591
integer, parameter, public hst_evarinuse
Definition: dc_error.f90:590
type(gt_history_varinfo), dimension(1:max_vars), save, public gthst_vars
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition: dc_error.f90:830
integer, parameter, public dc_noerr
Definition: dc_error.f90:509
type(gt_history_varinfo), dimension(1:nf90_max_dims), save, public gthst_weights
character(string) function, public joinchar(carray, expr)
Definition: dc_string.f90:861
real(dp), dimension(1:max_vars), save, public origin_time_vars
type(gt_history_axis), dimension(1:nf90_max_dims), target, save, public gthst_axes
integer, parameter, public dp
倍精度実数型変数
Definition: dc_types.f90:83
subroutine, public beginsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca, version)
Definition: dc_trace.f90:351
integer, dimension(1:max_vars), save, public interval_unitsym_vars
character(token), dimension(1:max_vars), save, public varname_vars
文字型変数の操作.
Definition: dc_string.f90:24
種別型パラメタを提供します。
Definition: dc_types.f90:49
character(token), save, public time_unit_bycreate
integer, parameter, public max_vars
type(gthst_nmlinfo), save, public gthstnml
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446
logical, dimension(1:max_vars), save, public tavr_vars
type(dc_cal), save, public cal_save
type(axes_weight), dimension(1:max_vars), target, save, public weight_vars
logical, dimension(1:max_vars), save, public output_valid_vars
type(gt_history_multi), dimension(1:max_vars), save, public gthst_history_vars
character(*), parameter, public version
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118
Here is the call graph for this function:

◆ historyautoaddvariable2()

subroutine historyautoaddvariable2 ( character(*), intent(in)  varname,
character(*), dimension(:), intent(in)  dims,
character(*), intent(in)  longname,
character(*), intent(in)  units,
character(*), intent(in), optional  xtype,
character(*), intent(in), optional  time_units,
logical, intent(in), optional  time_average,
character(*), intent(in), optional  file,
type(dc_difftime), intent(in)  origin,
type(dc_difftime), intent(in)  terminus,
type(dc_difftime), intent(in), optional  interval,
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_interval 
)

Definition at line 922 of file historyautoaddvariable.f90.

References dc_trace::beginsub(), dc_trace::dbgmessage(), dc_error::dc_noerr, dc_types::dp, dc_trace::endsub(), gtool_historyauto_internal::initialized, gtool_historyauto_internal::numdims, dc_error::storeerror(), dc_types::string, gtool_historyauto_internal::time_unit_bycreate, dc_types::token, and gtool_historyauto_internal::version.

922  !
923  ! データ出力するための変数登録を行います.
924  !
925  ! HistoryAutoAllVarFix を呼ぶ前にこのサブルーチンを使用してください.
926  !
927  ! Register variables for history data output
928  !
929  ! Use this subroutine before "HistoryAutoAllVarFix" is called.
930  !
931 
932  ! モジュール引用 ; USE statements
933  !
934 
938  use dc_trace, only: beginsub, endsub, dbgmessage
939  use dc_error, only: storeerror, dc_noerr
940  use dc_date, only: evalbyunit
942  use dc_types, only: dp, string, token
943 
944  ! 宣言文 ; Declaration statements
945  !
946  implicit none
947  character(*), intent(in):: varname
948  ! 変数名. Variable name
949  character(*), intent(in):: dims(:)
950  ! 変数が依存する次元の名前.
951  ! 時間の次元は配列の最後に指定すること.
952  !
953  ! Names of dependency dimensions of a variable.
954  ! Dimension of time must be specified
955  ! to last of an array.
956  character(*), intent(in):: longname
957  ! 変数の記述的名称.
958  !
959  ! Descriptive name of a variable
960  character(*), intent(in):: units
961  ! 変数の単位.
962  !
963  ! Units of a variable
964  type(dc_difftime), intent(in):: origin
965  ! 出力開始時刻.
966  !
967  ! Start time of output.
968  !
969  type(dc_difftime), intent(in):: terminus
970  ! 出力終了時刻.
971  !
972  ! End time of output.
973  !
974  type(dc_difftime), intent(in), optional:: interval
975  ! 出力時間間隔.
976  !
977  ! 省略した場合,
978  ! 自動的に 1.0 [sec] が設定されます.
979  !
980  ! Interval of output time.
981  !
982  ! If this argument is omitted,
983  ! a value of 1.0 [sec] is specified
984  ! automatically.
985  !
986  character(*), intent(in), optional:: xtype
987  !
988  ! 変数のデータ型
989  !
990  ! デフォルトは float (単精度実数型) であ
991  ! る. 有効なのは, double (倍精度実数型),
992  ! int (整数型) である. 指定しない 場合や,
993  ! 無効な型を指定した場合には, float (単
994  ! 精度実数型) となる.
995  !
996  ! Data types of dimensions specified
997  ! with "dims".
998  !
999  ! Default value is "float" (single precision).
1000  ! Other valid values are
1001  ! "double" (double precision),
1002  ! "int" (integer).
1003  ! If no value or invalid value is specified,
1004  ! "float" is applied.
1005  !
1006  character(*), intent(in), optional:: time_units
1007  ! 時刻次元の単位.
1008  ! Units of time dimension.
1009  logical, intent(in), optional:: time_average
1010  !
1011  ! 出力データを時間平均する場合には
1012  ! .true. を与えます. デフォルトは
1013  ! .false. です.
1014  !
1015  ! If output data is averaged, specify
1016  ! ".true.". Default is ".false.".
1017  !
1018  character(*), intent(in), optional:: file
1019  ! 出力ファイル名.
1020  ! Output file name.
1021 
1022  integer, intent(in), optional:: slice_start(:)
1023  ! 空間方向の開始点.
1024  !
1025  ! 省略した場合, 座標データの開始点が設定されます.
1026  !
1027  ! Start points of spaces.
1028  !
1029  ! If this argument is omitted,
1030  ! start points of dimensions are set.
1031  !
1032  integer, intent(in), optional:: slice_end(:)
1033  ! 空間方向の終了点.
1034  !
1035  ! 省略した場合, 座標データの終了点が設定されます.
1036  !
1037  ! End points of spaces.
1038  !
1039  ! If this argument is omitted,
1040  ! End points of dimensions are set.
1041  !
1042  integer, intent(in), optional:: slice_stride(:)
1043  ! 空間方向の刻み幅.
1044  !
1045  ! 省略した場合, 1 が設定されます.
1046  !
1047  ! Strides of spaces
1048  !
1049  ! If this argument is omitted,
1050  ! 1 is set.
1051  !
1052  logical, intent(in), optional:: space_average(:)
1053  ! 平均化のフラグ.
1054  !
1055  ! .true. が指定される座標に対して平均化を
1056  ! 行います.
1057  ! 省略した場合, .false. が設定されます.
1058  !
1059  ! Flag of average.
1060  !
1061  ! Axes specified .true. are averaged.
1062  ! If this argument is omitted,
1063  ! .false. is set.
1064  !
1065  integer, intent(in), optional:: newfile_interval
1066  ! ファイル分割時間間隔.
1067  !
1068  ! 省略した場合,
1069  ! 時間方向へのファイル分割を行いません.
1070  !
1071  ! Interval of time of separation of a file.
1072  !
1073  ! If this argument is omitted,
1074  ! a files is not separated in time direction.
1075  !
1076 
1077  ! 作業変数
1078  ! Work variables
1079  !
1080  real(DP):: interval_value
1081  ! データの出力間隔の数値.
1082  ! Numerical value for interval of history data output
1083  real(DP):: origin_value
1084  ! データの出力開始時刻の数値.
1085  ! Numerical value for start time of history data output
1086  real(DP):: terminus_value
1087  ! 出力終了時刻の数値.
1088  ! Numerical value for end time of output.
1089  integer:: stat
1090  character(STRING):: cause_c
1091  character(*), parameter:: subname = "HistoryAutoAddVariable2"
1092  continue
1093  call beginsub(subname, 'varname=%c', c1 = trim(varname), version = version)
1094  stat = dc_noerr
1095  cause_c = ""
1096 
1097  if ( present(time_units) ) then
1098  origin_value = evalbyunit( origin, time_units )
1099  else
1100  origin_value = evalbyunit( origin, time_unit_bycreate )
1101  end if
1102 
1103  if ( present(time_units) ) then
1104  terminus_value = evalbyunit( terminus, time_units )
1105  else
1106  terminus_value = evalbyunit( terminus, time_unit_bycreate )
1107  end if
1108 
1109  if ( present(interval) ) then
1110  if ( present(time_units) ) then
1111  interval_value = evalbyunit( interval, time_units )
1112  else
1113  interval_value = evalbyunit( interval, time_unit_bycreate )
1114  end if
1115  else
1116  interval_value = 1.0
1117  end if
1118 
1119  call dbgmessage('origin=%f, terminus=%f, interval=%f', &
1120  & d = (/ origin_value, terminus_value, interval_value /) )
1121 
1122  call historyautoaddvariable( &
1123  & varname, dims, longname, units, & ! (in)
1124  & xtype, time_units, time_average, & ! (in) optional
1125  & file, & ! (in) optional
1126  & origin = origin_value, & ! (in) optional
1127  & terminus = terminus_value, & ! (in) optional
1128  & interval = interval_value, & ! (in) optional
1129  & slice_start = slice_start, & ! (in) optional
1130  & slice_end = slice_end, & ! (in) optional
1131  & slice_stride = slice_stride, & ! (in) optional
1132  & space_average = space_average, & ! (in) optional
1133  & newfile_interval = newfile_interval ) ! (in) optional
1134 
1135 999 continue
1136  call storeerror(stat, subname, cause_c = cause_c)
1137  call endsub(subname, 'stat=%d', i = (/stat/) )
integer, parameter, public token
単語やキーワードを保持する文字型変数の種別型パラメタ
Definition: dc_types.f90:109
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition: dc_error.f90:830
integer, parameter, public dc_noerr
Definition: dc_error.f90:509
integer, parameter, public dp
倍精度実数型変数
Definition: dc_types.f90:83
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
種別型パラメタを提供します。
Definition: dc_types.f90:49
character(token), save, public time_unit_bycreate
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446
character(*), parameter, public version
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118
Here is the call graph for this function: