historyautocreate.f90
Go to the documentation of this file.
1 != gtool_historyauto の初期設定
2 != Initialization of gtool_historyauto
3 !
4 ! Authors:: Yasuhiro MORIKAWA
5 ! Version:: $Id: historyautocreate.f90,v 1.7 2010-01-16 14:14:16 morikawa Exp $
6 ! Tag Name:: $Name: $
7 ! Copyright:: Copyright (C) GFD Dennou Club, 2008-2009. All rights reserved.
8 ! License:: See COPYRIGHT[link:../../../COPYRIGHT]
9 !
10  subroutine historyautocreate3( &
11  & title, source, institution, & ! (in)
12  & dims, dimsizes, longnames, units, & ! (in)
13  & origin, terminus, & ! (in)
14  & xtypes, conventions, gt_version, & ! (in) optional
15  & all_output, & ! (in) optional
16  & file_prefix, & ! (in) optional
17  & namelist_filename, & ! (in) optional
18  & interval, & ! (in) optional
19  & slice_start, slice_end, slice_stride, & ! (in) optional
20  & space_average, & ! (in) optional
21  & time_average, & ! (in) optional
22  & newfile_interval, & ! (in) optional
23  & rank, & ! (in) optional
24  & origin_date, origin_date_invalid, & ! (in) optional
25  & start_date, cal, & ! (in) optional
26  & flag_mpi_gather, flag_mpi_split & ! (in) optional
27  & )
28  !
29  ! 複数のデータ出力を行うための初期化を行います.
30  !
31  ! この HistoryAutoCreate には, モデル内で出力する
32  ! 変数が依存する座標や座標重みなどを全てを設定してください.
33  !
34  ! all_output に .true. を与えた場合や,
35  ! namelist_filename を与えない (空文字を与える) 場合には,
36  ! HistoryAutoAddVariable で登録される全ての変数が出力されます.
37  ! 一方で namelist_filename に NAMELIST ファイル名を与える場合には,
38  ! その NAMELIST ファイルから出力のオンオフや,
39  ! 出力ファイル名, 出力間隔などを変更可能です.
40  ! 変更可能な項目に関しては NAMELIST#gtool_historyauto_nml
41  ! を参照して下さい.
42  !
43  ! interval, origin, terminus, slice_start, slice_end, slice_stride,
44  ! space_average, time_average, newfile_interval
45  ! などの設定はデフォルト値として使用されます.
46  ! これらの設定値は HistoryAutoAddVariable および
47  ! NAMELIST#gtool_historyauto_nml で上書きされます.
48  ! (優先度が高いのは NAMELIST#gtool_historyauto_nml ,
49  ! HistoryAutoAddVariable の引数,
50  ! HistoryAutoCreate の引数 の順です).
51  !
52  !
53  ! Initialization for multiple history data output
54  !
55  ! Set all axes and their weights depended by variables
56  ! output from numerical models to this "HistoryAutoCreate".
57  !
58  ! All variables registered by "HistoryAutoAddVariable"
59  ! are output if .true. is given to "all_output" or
60  ! "namelist_filename" is not given (or blanks are given)
61  ! On the other hand, if a filename of NAMELIST file is
62  ! given to "namelist_filename", on/off of output,
63  ! output filename and output interval, etc. can be changed
64  ! from the NAMELIST file.
65  ! For available items, see "NAMELIST#gtool_historyauto_nml".
66  !
67  ! Settings about
68  ! "interval", "origin", "terminus", "slice_start", "slice_end", "slice_stride",
69  ! "space_average", "time_average", "newfile_interval"
70  ! etc. are used as default values.
71  ! Their set values are overwritten by
72  ! "HistoryAutoAddVariable" or
73  ! "NAMELIST#gtool_historyauto_nml".
74  ! ("NAMELIST#gtool_historyauto_nml" is high priority,
75  ! arguments of "HistoryAutoAddVariable" are medium,
76  ! arguments of "HistoryAutoCreate" are low).
77  !
79  & zero_time, numdims, &
84  use gtool_history, only: historyaxiscreate, historyaxisaddattr
88  use dc_trace, only: beginsub, endsub
91  use netcdf, only: nf90_emaxdims, nf90_max_dims
95  use dc_calendar, only: dc_cal, dc_cal_date, &
96  & dccaldateinquire, dccalinquire, dccaldefault
97  use dc_date, only: dcdifftimecreate, evalbyunit, tochar, tocharcal, eval
99  use dc_message, only: messagenotify
100  use dc_iounit, only: fileopen
101  use dc_types, only: dp, string, token
102  implicit none
103  character(*), intent(in):: title
104  ! データ全体の表題.
105  ! Title of entire data
106  character(*), intent(in):: source
107  ! データを作成する際の手段.
108  ! Source of data file
109  character(*), intent(in):: institution
110  ! ファイルを最終的に変更した組織/個人.
111  ! Institution or person that changes files for the last time
112  character(*), intent(in):: dims(:)
113  ! 次元の名前.
114  !
115  ! 配列の大きさに制限はありません.
116  ! 個々の次元の文字数は dc_types#TOKEN まで.
117  ! 配列内の文字数は
118  ! 全て同じでなければなりません.
119  ! 足りない文字分は空白で
120  ! 補ってください.
121  !
122  ! Names of dimensions.
123  !
124  ! Length of array is unlimited.
125  ! Limits of numbers of characters of each
126  ! dimensions are "dc_types#TOKEN".
127  ! Numbers of characters in this array
128  ! must be same.
129  ! Make up a deficit with blanks.
130  !
131  integer, intent(in):: dimsizes (:)
132  ! dims で指定したそれぞれの次元大きさ.
133  !
134  ! 配列の大きさは dims の大きさと等しい
135  ! 必要があります. '0' (数字のゼロ) を指定
136  ! するとその次元は 無制限次元 (unlimited
137  ! dimension) となります. (gtool_history
138  ! では時間の次元に対して無制限次元を
139  ! 用いることを想定しています). ただし,
140  ! 1 つの NetCDF ファイル (バージョン 3)
141  ! は最大で 1 つの無制限次元しか持てないので,
142  ! 2 ヶ所以上に '0' を指定しないでください.
143  ! その場合, 正しく gtool4 データが出力されません.
144  !
145  ! Lengths of dimensions specified with "dims".
146  !
147  ! Length of this array must be same as
148  ! length of "dim". If '0' (zero) is
149  ! specified, the dimension is treated as
150  ! unlimited dimension.
151  ! (In "gtool_history", unlimited dimension is
152  ! expected to be used as time).
153  ! Note that one NetCDF file (version 3)
154  ! can not have two or more unlimited
155  ! dimensions, so that do not specify '0'
156  ! to two or more places. In that case,
157  ! gtoo4 data is not output currently
158  !
159  character(*), intent(in):: longnames (:)
160  ! dims で指定したそれぞれの次元の名前.
161  !
162  ! 配列の大きさは dims の大きさ
163  ! と等しい必要があります. 文字数
164  ! は dc_types#STRING まで.
165  ! 配列内の文字数は
166  ! 全て同じでなければなりません.
167  ! 足りない文字分は空白で補います.
168  !
169  ! Names of dimensions specified with "dims".
170  !
171  ! Length of this array must be same as
172  ! length of "dim".
173  ! Limits of numbers of characters are
174  ! "dc_types#STRING".
175  ! Numbers of characters in this array
176  ! must be same.
177  ! Make up a deficit with blanks.
178  !
179  character(*), intent(in):: units(:)
180  ! dims で指定したそれぞれの次元の単位.
181  !
182  ! 配列の大きさは dims の大きさ
183  ! と等しい必要があります. 文字数
184  ! は dc_types#STRING まで.
185  ! 配列内の文字数は
186  ! 全て同じでなければなりません.
187  ! 足りない文字分は空白で補います.
188  !
189  ! Units of dimensions specified with "dims".
190  !
191  ! Length of this array must be same as
192  ! length of "dim".
193  ! Limits of numbers of characters are
194  ! "dc_types#STRING".
195  ! Numbers of characters in this array
196  ! must be same.
197  ! Make up a deficit with blanks.
198  !
199  type(dc_difftime), intent(in):: origin
200  ! 出力開始時刻.
201  !
202  ! Start time of output.
203  !
204  type(dc_difftime), intent(in):: terminus
205  ! 出力終了時刻.
206  !
207  ! End time of output.
208  !
209  character(*), intent(in), optional:: xtypes(:)
210  ! dims で指定したそれぞれの
211  ! 次元のデータ型.
212  !
213  ! デフォルトは float (単精度実数型)
214  ! です. 有効なのは,
215  ! double (倍精度実数型),
216  ! int (整数型) です. 指定しない
217  ! 場合や, 無効な型を指定した場合には,
218  ! float となります. なお, 配列の大きさ
219  ! は *dims* の大きさと等しい必要が
220  ! あります. 配列内の文字数は全て
221  ! 同じでなければなりません.
222  ! 足りない文字分は空白で補います.
223  !
224  ! Data types of dimensions specified
225  ! with "dims".
226  !
227  ! Default value is "float" (single precision).
228  ! Other valid values are
229  ! "double" (double precision),
230  ! "int" (integer).
231  ! If no value or invalid value is specified,
232  ! "float" is applied.
233  ! Length of this array must be same as
234  ! length of "dim".
235  ! Numbers of characters in this array
236  ! must be same.
237  ! Make up a deficit with blanks.
238  !
239  character(*), intent(in), optional:: conventions
240  ! 出力するファイルの netCDF
241  ! 規約
242  !
243  ! 省略した場合,
244  ! もしくは空文字を与えた場合,
245  ! 出力する netCDF 規約の
246  ! Conventions 属性に値
247  ! gtool4_netCDF_Conventions
248  ! が自動的に与えられます.
249  !
250  ! NetCDF conventions of output file.
251  !
252  ! If this argument is omitted or,
253  ! blanks are given,
254  ! gtool4_netCDF_Conventions is given to
255  ! attribute "Conventions" of an output file
256  ! automatically.
257  !
258  character(*), intent(in), optional:: gt_version
259  ! gtool4 netCDF 規約のバージョン
260  !
261  ! 省略した場合, gt_version 属性に
262  ! 規約の最新版のバージョンナンバー
263  ! gtool4_netCDF_version
264  ! が与えられます.
265  ! (ただし, 引数 conventions に
266  ! gtool4_netCDF_Conventions
267  ! 以外が与えられる場合は
268  ! gt_version 属性を作成しません).
269  !
270  ! Version of gtool4 netCDF Conventions.
271  !
272  ! If this argument is omitted,
273  ! latest version number of gtool4 netCDF
274  ! Conventions is given to attribute
275  ! "gt_version" of an output file
276  ! (However, gtool4_netCDF_Conventions is
277  ! not given to an argument "conventions",
278  ! attribute "gt_version" is not created).
279  !
280  logical, intent(in), optional:: all_output
281  ! 登録変数を全て出力するためのフラグ.
282  !
283  ! .true. を指定すると,
284  ! HistoryAutoAddVariable で登録された
285  ! 変数が全て出力されるようになります.
286  !
287  ! *namelist_filename* が指定される場合
288  ! には, デフォルトは .false. となります.
289  ! この場合には,
290  ! *namelist_filename* に指定された
291  ! NAMELIST ファイルから読み込まれる
292  ! NAMELIST#gtool_historyauto_nml
293  ! で指定された変数のみ出力されます.
294  !
295  ! *namelist_filename* が指定されない場合
296  ! には, .true. となります.
297  !
298  !
299  ! Flag for output all registered variables.
300  !
301  ! When .true. is specified,
302  ! all variables registered by
303  ! "HistoryAutoAddVariable" are output.
304  !
305  ! If *namelist_filename* is specified,
306  ! default value becomes .false. .
307  ! In this case,
308  ! only variables specified in
309  ! "NAMELIST#gtool_historyauto_nml"
310  ! loaded from a NAMELIST file
311  ! *namelist_filename*.
312  !
313  ! If *namelist_filename* is not specified,
314  ! this value becomes .true. .
315  !
316  character(*), intent(in), optional:: file_prefix
317  ! データのファイル名の接頭詞.
318  ! Prefixes of history data filenames
319  character(*), intent(in), optional:: namelist_filename
320  ! NAMELIST ファイルの名称.
321  !
322  ! 省略した場合, もしくは空白文字を与えた場合,
323  ! NAMELIST ファイルは読み込みません.
324  !
325  ! Name of NAMELIST file.
326  !
327  ! If this argument is omitted,
328  ! or blanks are specified,
329  ! no NAMELIST file is loaded.
330  !
331  type(dc_difftime), intent(in), optional:: interval
332  ! 出力時間間隔.
333  !
334  ! 省略した場合,
335  ! 自動的に 1.0 [sec] が設定されます.
336  !
337  ! Interval of output time.
338  !
339  ! If this argument is omitted,
340  ! 1.0 [sec] is specified
341  ! automatically.
342  !
343  integer, intent(in), optional:: slice_start(:)
344  ! 空間方向の開始点.
345  !
346  ! 省略した場合, 座標データの開始点が設定されます.
347  !
348  ! Start points of spaces.
349  !
350  ! If this argument is omitted,
351  ! start points of dimensions are set.
352  !
353  integer, intent(in), optional:: slice_end(:)
354  ! 空間方向の終了点.
355  !
356  ! 省略した場合, もしくは負の値が与えら得た場合,
357  ! 座標データの終了点が設定されます.
358  !
359  ! End points of spaces.
360  !
361  ! If this argument is omitted or
362  ! negative value is specified,
363  ! end points of dimensions are set.
364  !
365  integer, intent(in), optional:: slice_stride(:)
366  ! 空間方向の刻み幅.
367  !
368  ! 省略した場合, 1 が設定されます.
369  !
370  ! Strides of spaces
371  !
372  ! If this argument is omitted,
373  ! 1 is set.
374  !
375  logical, intent(in), optional:: space_average(:)
376  ! 平均化のフラグ.
377  !
378  ! .true. が指定される座標に対して平均化を
379  ! 行います.
380  ! 省略した場合, .false. が設定されます.
381  !
382  ! Flag of average.
383  !
384  ! Axes specified .true. are averaged.
385  ! If this argument is omitted,
386  ! .false. is set.
387  !
388  logical, intent(in), optional:: time_average
389  ! 出力データの時間平均フラグ.
390  ! デフォルトは .false.
391  ! Flag for time average of output data
392  ! Default value is .false.
393  integer, intent(in), optional:: newfile_interval
394  ! ファイル分割時間間隔.
395  !
396  ! 省略した場合,
397  ! 時間方向へのファイル分割を行いません.
398  !
399  ! Interval of time of separation of a file.
400  !
401  ! If this argument is omitted,
402  ! a files is not separated in time direction.
403  !
404  character(*), intent(in), optional:: rank
405  ! ランクの名称.
406  !
407  ! Name of a rank.
408  !
409  type(dc_datetime), intent(in), optional:: origin_date
410  ! 出力開始日時.
411  ! この引数は廃止予定のため, start_date を使用して下さい.
412  !
413  ! Start date of output.
414  ! Use "start_date" because this argument is obsolete.
415  !
416  logical, intent(in), optional:: origin_date_invalid
417  ! .true. を与えると, origin_date を無効にします.
418  !
419  ! If ".true." is given, "origin_date" is ignored.
420  type(dc_cal_date), intent(in), optional:: start_date
421  ! 出力開始日時.
422  !
423  ! Start date of output.
424  !
425  type(dc_cal), intent(in), optional:: cal
426  ! 暦情報.
427  ! これを指定しない場合, dc_calendar モジュールの
428  ! デフォルトの暦が使用されます.
429  !
430  ! Calendar.
431  ! If this argument is specified, default calendar in
432  ! "dc_calendar" module is used.
433  !
434  logical, intent(in), optional:: flag_mpi_gather
435  ! MPI 使用時に, 各ノードで HistoryPut
436  ! に与えたデータを一つのファイルに統合して出力
437  ! する場合には .true. を与えてください.
438  ! デフォルトは .false. です.
439  !
440  ! .true. を与えた場合, HistoryPutAxisMPI
441  ! に全体の軸データを与えてください.
442  !
443  ! When MPI is used, if ".true." is given,
444  ! data given to "HistoryPut" on each node
445  ! is integrated and output to one file.
446  ! Default value is ".false.".
447  !
448  ! If .true. is given, give data of axes in
449  ! whole area to "HistoryPutAxisMPI"
450  !
451  logical, intent(in), optional:: flag_mpi_split
452  ! MPI 使用時に, 各ノードで HistoryPut
453  ! に与えたデータをそれぞれ別名のファイルに
454  ! 出力する場合には .true. を与えてください.
455  ! デフォルトは .false. です.
456  !
457  ! When MPI is used, if ".true." is given,
458  ! data given to "HistoryPut" on each node
459  ! is split into discrete files.
460  ! Default value is ".false.".
461  !
462 
463 
464  ! NAMELIST 変数群 ; NAMELIST group of variables
465  character(STRING):: Name
466  ! 変数名.
467  ! 空白の場合には, この他の設定値は
468  ! gtool_historyauto モジュールにおいて
469  ! 出力されるデータ全ての
470  ! デフォルト値となります.
471  !
472  ! "Data1,Data2" のようにカンマで区切って複数
473  ! の変数を指定することも可能です.
474  !
475  ! Variable identifier.
476  ! If blank is given, other values are
477  ! used as default values of output data
478  ! in "gtool_historyauto".
479  !
480  ! Multiple variables can be specified
481  ! as "Data1,Data2" too. Delimiter is comma.
482  character(STRING):: File
483  ! 出力ファイル名.
484  ! これはデフォルト値としては使用されません.
485  ! *Name* に値が設定されている時のみ有効です.
486  !
487  ! Output file name.
488  ! This is not used as default value.
489  ! This value is valid only when *Name* is
490  ! specified.
491 
492  real(DP):: IntValue
493  ! データの出力間隔の数値.
494  ! 負の値を与えると, 出力を抑止します.
495  ! Numerical value for interval of history data output
496  ! Negative values suppresses output.
497  character(TOKEN):: IntUnit
498  ! データの出力間隔の単位.
499  ! Unit for interval of history data output
500  character(TOKEN):: Precision
501  ! データの精度.
502  ! デフォルトは float (単精度実数型)
503  ! です. 有効なのは,
504  ! double (倍精度実数型),
505  ! int (整数型) です. 指定しない
506  ! 場合や, 無効な型を指定した場合には,
507  ! float となります.
508  !
509  ! Precision of history data
510  ! Default value is "float" (single precision).
511  ! Other valid values are
512  ! "double" (double precision),
513  ! "int" (integer).
514  ! If no value or invalid value is specified,
515  ! "float" is applied.
516  character(STRING):: FilePrefix
517  ! データのファイル名の接頭詞.
518  ! Prefixes of history data filenames
519  logical:: TimeAverage
520  ! 出力データの時間平均フラグ.
521  !
522  ! ".true." を与えると, 時間平均値が出力されます.
523  !
524  ! Flag for time average of output data
525  !
526  ! If ".ture." is specified,
527  ! time average values are output.
528  !
529  logical:: AllOutput
530  ! 登録変数を全て出力するためのフラグ.
531  ! Flag for output all registered variables.
532  real(DP):: OriginValue
533  ! 出力開始時刻.
534  ! Start time of output.
535  character(TOKEN):: OriginUnit
536  ! 出力開始時刻の単位.
537  ! Unit of start time of output.
538  real(DP):: TerminusValue
539  ! 出力終了時刻.
540  ! End time of output.
541  character(TOKEN):: TerminusUnit
542  ! 出力終了時刻の単位.
543  ! Unit of end time of output.
544  integer:: SliceStart(1:nf90_max_dims)
545  ! 空間方向の開始点.
546  ! Start points of spaces.
547  integer:: SliceEnd(1:nf90_max_dims)
548  ! 空間方向の終了点.
549  !
550  ! 省略した場合, もしくは負の値が与えら得た場合,
551  ! 座標データの終了点が設定されます.
552  !
553  ! End points of spaces.
554  !
555  ! If this argument is omitted or
556  ! negative value is specified,
557  ! end points of dimensions are set.
558  !
559  integer:: SliceStride(1:nf90_max_dims)
560  ! 空間方向の刻み幅.
561  ! Strides of spaces.
562  logical:: SpaceAverage(1:nf90_max_dims)
563  ! 空間平均のフラグ.
564  ! Flag of spatial average.
565  integer:: NewFileIntValue
566  ! ファイル分割時間間隔の数値.
567  ! Numerical value for interval of time of separation of a file.
568  character(TOKEN):: NewFileIntUnit
569  ! ファイル分割時間間隔の単位.
570  ! Unit of interval of time of separation of a file.
571 
572  namelist /gtool_historyauto_nml/ &
573  & name, file, &
574  & intvalue, intunit, &
575  & precision, &
576  & fileprefix, &
577  & timeaverage, alloutput, &
578  & originvalue, originunit, &
579  & terminusvalue, terminusunit, &
580  & slicestart, sliceend, slicestride, spaceaverage, &
581  & newfileintvalue, newfileintunit
582  ! gtool_historyauto モジュールのデータ用
583  ! NAMELIST 変数群名.
584  !
585  ! gtool_historyauto_generic#HistoryAutoCreate
586  ! を使用する際に, オプショナル引数 *namelist_filename*
587  ! へ NAMELIST ファイル名を指定することで,
588  ! そのファイルからこの NAMELIST 変数群を
589  ! 読み込みます.
590  !
591  ! NAMELIST group name for
592  ! history data of "gtool_historyauto" module.
593  !
594  ! If a NAMELIST filename is specified to
595  ! an optional argument *namelist_filename* when
596  ! "gtool_historyauto_generic#HistoryAutoCreate"
597  ! is used, this NAMELIST group is
598  ! loaded from the file.
599 
600 
601  ! 作業変数 ; Work variables
602  integer:: blank_index
603  integer:: stat
604  character(STRING):: cause_c
605  integer:: unit_nml ! NAMELIST ファイルオープン用装置番号.
606  ! Unit number for NAMELIST file open
607  integer:: iostat_nml ! NAMELIST 読み込み時の IOSTAT.
608  ! IOSTAT of NAMELIST read
609  character(TOKEN):: pos_nml
610  ! NAMELIST 読み込み時のファイル位置.
611  ! File position of NAMELIST read
612  integer:: i, j
613  character(TOKEN):: my_xtype
614 
615  real(DP):: interval_work, origin_work, terminus_work
616  integer:: date_day
617  real(DP):: date_sec
618  integer:: msnot_rank
619  character(STRING):: date_str
620  character(TOKEN):: cal_str, cal_type
621  integer:: origin_year, origin_month, origin_day, origin_hour, origin_min
622  real(DP):: origin_sec
623  integer:: month_in_year, hour_in_day, min_in_hour
624  integer, pointer:: day_in_month(:) =>null()
625  real(DP):: sec_in_min
626  character(*), parameter:: subname = "HistoryAutoCreate3"
627  continue
628  call beginsub(subname, version = version)
629  stat = dc_noerr
630  cause_c = ""
631 
632  ! このサブルーチンが 2 度呼ばれたらエラー
633  ! Error is occurred when this subroutine is called twice
634  !
635  if ( initialized ) then
636  stat = dc_ealreadyinit
637  cause_c = 'gtool_historyauto'
638  goto 999
639  end if
640 
641  ! ゼロ秒の作成.
642  ! Create zero seconds
643  !
644  zero_time = 0.0_dp
645 !!$ call DCDiffTimeCreate( &
646 !!$ & zero_time, & ! (out)
647 !!$ & sec = 0.0_DP ) ! (in)
648 
649  ! 次元の数に関するエラー処理
650  ! Error handling for number of dimensions
651  !
652  numdims = size(dims)
653 
654  if ( size(dimsizes) /= numdims ) then
655  cause_c = 'dimsizes, dims'
656  elseif ( size(longnames) /= numdims ) then
657  cause_c = 'longnames, dims'
658  elseif ( size(units) /= numdims ) then
659  cause_c = 'units, dims'
660  endif
661  if ( trim(cause_c) /= "" ) then
662  stat = gt_eargsizemismatch
663  goto 999
664  end if
665 
666  if ( numdims > nf90_max_dims ) then
667  stat = nf90_emaxdims
668  goto 999
669  end if
670 
671  ! 時刻次元に関するエラー処理
672  ! Error handling for time dimension
673  !
674  if ( dimsizes(numdims) /= 0 ) then
675  call messagenotify( 'W', subname, &
676  & 'time dimension must be specified to the last of "dims"' )
677  stat = hst_enotimedim
678  goto 999
679  end if
680 
681  ! 出力ファイルの基本メタデータの保管
682  ! Save basic meta data for output file
683  !
684  title_save = title
685  source_save = source
686  institution_save = institution
687 
688  conventions_save = ''
689  if ( present(conventions) ) conventions_save = conventions
690 
691  gt_version_save = ''
692  if ( present(gt_version) ) gt_version_save = gt_version
693 
694  rank_save = ''
695  if ( present(rank) ) rank_save = rank
696 
697  ! MPI に関する情報の保管
698  ! Save information about MPI
699  !
700  save_mpi_split = present_and_true( flag_mpi_split )
701  save_mpi_gather = present_and_true( flag_mpi_gather )
702 
703  msnot_rank = -1
704  if ( save_mpi_gather ) msnot_rank = 0
705 
706  ! 時刻の単位のチェック
707  ! Check units of time
708  !
709  time_unit_bycreate = units(numdims)
710  time_unit_suffix = ''
711  blank_index = index( trim( adjustl(time_unit_bycreate) ), ' ' )
712  if ( blank_index > 1 ) then
713  time_unit_suffix = time_unit_bycreate(blank_index+1:)
714  time_unit_bycreate = time_unit_bycreate(1:blank_index-1)
715  end if
716 
717  ! 座標軸データの保管
718  ! Save axes data
719  !
720  do i = 1, numdims
721  my_xtype = ''
722  if ( present(xtypes) ) then
723  if ( size(xtypes) >= i ) then
724  my_xtype = xtypes(i)
725  end if
726  end if
727 
728  call historyaxiscreate( &
729  & axis = gthst_axes(i), & ! (out)
730  & name = dims(i), size = dimsizes(i), & ! (in)
731  & longname = longnames(i), units = units(i), & ! (in)
732  & xtype = my_xtype ) ! (in)
733 
734  allocate( data_axes(i) % a_axis( dimsizes(i) ) )
735  data_axes(i) % a_axis = (/ ( real( j, DP ), j = 1, dimsizes(i) ) /)
736 
737  end do
738 
739  ! 暦の登録
740  ! Register calendar
741  !
742  if ( present(cal) ) then
743  cal_save = cal
744  else
745  call dccaldefault( cal_save )
746  end if
747 
748  ! 日時の指定
749  ! Specify date
750  !
751  if ( present(start_date) ) then
752 
753  call dccaldateinquire( &
754  & date_str = date_str, & ! (out)
755  & date = start_date, & ! (in) optional
756  & cal = cal & ! (in) optional
757  ! & , zone = "+09:00" &
758  & ) ! (in) optional
759 
760  call dccaldateinquire( &
761  & origin_year, origin_month, origin_day, & ! (out) optional
762  & origin_hour, origin_min, origin_sec, & ! (out) optional
763  & date = start_date, & ! (in) optional
764  & cal = cal & ! (in) optional
765  & )
766 
767  call dccalinquire( &
768  & cal_str, & ! (out) optional
769  & month_in_year = month_in_year, & ! (out) optional
770  & day_in_month_ptr = day_in_month , & ! (out) optional
771  & hour_in_day = hour_in_day , & ! (out) optional
772  & min_in_hour = min_in_hour , & ! (out) optional
773  & sec_in_min = sec_in_min , & ! (out) optional
774  & cal = cal_save ) ! (in) optional
775 
776  ! 地球暦の場合のみ units 属性に "since ..." を付加
777  !
778  select case ( trim(cal_str) )
779  case ( 'gregorian' )
781  & ' since ' // trim(date_str)
782  case ( 'julian' )
784  & ' since ' // trim(date_str)
785  case ( 'noleap' )
787  & ' since ' // trim(date_str)
788  case ( '360day' )
790  & ' since ' // trim(date_str)
791  case ( 'cyclic' )
793  & ' since ' // trim(date_str)
794  end select
795 
796  ! 開始日時情報の付与
797  !
798  call historyaxisaddattr( &
799  & axis = gthst_axes(numdims), & ! (inout)
800  & attrname = 'origin', & ! (in)
801  & value = 'origin_year origin_month origin_day ' // &
802  & 'origin_hour origin_min origin_sec' ) ! (in)
803 
804  call historyaxisaddattr( gthst_axes(numdims), 'origin_year', origin_year )
805  call historyaxisaddattr( gthst_axes(numdims), 'origin_month', origin_month )
806  call historyaxisaddattr( gthst_axes(numdims), 'origin_day', origin_day )
807  call historyaxisaddattr( gthst_axes(numdims), 'origin_hour', origin_hour )
808  call historyaxisaddattr( gthst_axes(numdims), 'origin_min', origin_min )
809 
810  ! 暦情報の付与
811  !
812  call historyaxisaddattr( &
813  & axis = gthst_axes(numdims), & ! (inout)
814  & attrname = 'calendar', & ! (in)
815  & value = cal_str ) ! (in)
816 
817  if ( trim(cal_str) == 'user_defined' ) then
818  call historyaxisaddattr( gthst_axes(numdims), 'month_in_year', month_in_year )
819  call historyaxisaddattr( gthst_axes(numdims), 'day_in_month', day_in_month )
820  call historyaxisaddattr( gthst_axes(numdims), 'hour_in_day', hour_in_day )
821  call historyaxisaddattr( gthst_axes(numdims), 'min_in_hour', min_in_hour )
822  call historyaxisaddattr( gthst_axes(numdims), 'sec_in_min', sec_in_min )
823  end if
824 
825  deallocate( day_in_month )
826 
827  elseif ( present(origin_date) &
828  & .and. .not. present_and_true(origin_date_invalid) ) then
829  call eval( origin_date, & ! (in)
830  & day = date_day, sec = date_sec ) ! (out)
831  if ( date_day /= 0 .or. date_sec /= 0.0 ) then
833  & ' since ' // tochar(origin_date)
834 
835  call historyaxisaddattr( &
836  & axis = gthst_axes(numdims), & ! (inout)
837  & attrname = 'calendar', & ! (in)
838  & value = tocharcal(origin_date) ) ! (in)
839 
840  end if
841  end if
842 
843  ! 登録変数を全て出力するためのフラグの保管
844  ! Save flag for output all registered variables
845  !
846  if ( present(all_output) ) all_output_save = all_output
847  if ( .not. present_and_not_empty(namelist_filename) ) all_output_save = .true.
848  alloutput = all_output_save
849 
850  ! 出力時間間隔のデフォルト値設定
851  ! Configure default interval of output time
852  !
853  if ( all_output_save ) then
854  if ( present(interval) ) then
855  interval_work = evalbyunit( interval, time_unit_bycreate )
856  else
857  interval_work = 1.0
858  end if
859  else
860  interval_work = - 1.0
861  end if
862 
863  ! 出力開始・終了時刻のデフォルト値設定
864  ! Configure default origin/terminus time of output
865  !
866  origin_work = evalbyunit( origin, 'sec' )
867  terminus_work = evalbyunit( terminus, time_unit_bycreate )
868 
869  ! gtool_historyauto_nml へデフォルト値の設定
870  ! Configure default values for "gtool_historyauto_nml"
871  !
872  call hstnmlinfocreate( gthstnml ) ! (out)
873 
874  call hstnmlinfoadd( &
875  & gthstnml = gthstnml, & ! (inout)
876  & name = '', & ! (in) optional
877  & precision = 'float', & ! (in) optional
878  & fileprefix = file_prefix, & ! (in) optional
879  & interval_value = interval_work, & ! (in) optional
880  & interval_unit = time_unit_bycreate, & ! (in) optional
881  & origin_value = origin_work, & ! (in) optional
882  & origin_unit = 'sec', & ! (in) optional
883 !!$ & origin_unit = time_unit_bycreate, & ! (in) optional
884  & terminus_value = terminus_work, & ! (in) optional
885  & terminus_unit = time_unit_bycreate, & ! (in) optional
886  & time_average = time_average, & ! (in) optional
887  & slice_start = slice_start, & ! (in) optional
888  & slice_end = slice_end, & ! (in) optional
889  & slice_stride = slice_stride, & ! (in) optional
890  & space_average = space_average, & ! (in) optional
891  & newfile_intvalue = newfile_interval, & ! (in) optional
892  & newfile_intunit = time_unit_bycreate ) ! (in) optional
893 
894  ! NAMELIST ファイルの読み込み
895  ! Load NAMELIST file
896  !
897  if ( present_and_not_empty(namelist_filename) ) then
898  call fileopen( unit_nml, & ! (out)
899  & namelist_filename, mode = 'r' ) ! (in)
900 
901  iostat_nml = 0
902  pos_nml = ''
903 
904  call messagenotify( 'M', sub_sname, '----- "gtool_historyauto_nml" is loaded from "%c" -----', &
905  & c1 = trim(namelist_filename), rank_mpi = msnot_rank )
906 
907  do while ( trim(pos_nml) /= 'APPEND' .and. iostat_nml == 0 )
908 
909  name = ''
910  file = ''
911  call hstnmlinfoinquire( &
912  & gthstnml = gthstnml, & ! (in)
913  & interval_value = intvalue, & ! (out) optional
914  & interval_unit = intunit, & ! (out) optional
915  & precision = precision, & ! (out) optional
916  & time_average = timeaverage, & ! (out) optional
917  & origin_value = originvalue, & ! (out) optional
918  & origin_unit = originunit, & ! (out) optional
919  & terminus_value = terminusvalue, & ! (out) optional
920  & terminus_unit = terminusunit, & ! (out) optional
921  & slice_start = slicestart, & ! (out) optional
922  & slice_end = sliceend, & ! (out) optional
923  & slice_stride = slicestride, & ! (out) optional
924  & space_average = spaceaverage, & ! (out) optional
925  & newfile_intvalue = newfileintvalue, & ! (out) optional
926  & newfile_intunit = newfileintunit, & ! (out) optional
927  & fileprefix = fileprefix ) ! (out) optional
928 
929  read( unit = unit_nml, & ! (in)
930  & nml = gtool_historyauto_nml, & ! (out)
931  & iostat = iostat_nml ) ! (out)
932  inquire( unit = unit_nml, & ! (in)
933  & position = pos_nml ) ! (out)
934 
935  if ( iostat_nml == 0 ) then
936 
937  ! NAMELIST から与えられた値が無効な場合, デフォルト値を使用
938  ! Default values are used when values from NAMELIST are invalid
939  !
940  if ( .not. intvalue > 0.0 ) then
941  intvalue = interval_work
942  intunit = time_unit_bycreate
943  end if
944  if ( .not. originvalue > 0.0 ) then
945  originvalue = origin_work
946  originunit = 'sec'
947  end if
948  if ( .not. terminusvalue > 0.0 ) then
949  terminusvalue = terminus_work
950  terminusunit = time_unit_bycreate
951  end if
952 
953  ! 情報の登録
954  ! Register information
955  !
956  call hstnmlinfoadd( &
957  & gthstnml = gthstnml, & ! (inout)
958  & name = name, & ! (in) optional
959  & file = file, & ! (in) optional
960  & interval_value = intvalue, & ! (in) optional
961  & interval_unit = intunit, & ! (in) optional
962  & precision = precision, & ! (in) optional
963  & time_average = timeaverage, & ! (in) optional
964  & origin_value = originvalue, & ! (in) optional
965  & origin_unit = originunit, & ! (in) optional
966  & terminus_value = terminusvalue, & ! (in) optional
967  & terminus_unit = terminusunit, & ! (in) optional
968  & slice_start = slicestart, & ! (in) optional
969  & slice_end = sliceend, & ! (in) optional
970  & slice_stride = slicestride, & ! (in) optional
971  & space_average = spaceaverage, & ! (in) optional
972  & newfile_intvalue = newfileintvalue, & ! (in) optional
973  & newfile_intunit = newfileintunit, & ! (in) optional
974  & fileprefix = fileprefix ) ! (in) optional
975 
976  ! 登録変数を全て出力するためのフラグの保管
977  ! Save flag for output all registered variables
978  !
979  if ( trim(name) == '' ) then
980  all_output_save = alloutput
981  end if
982 
983  ! 印字 ; Print
984  !
985  if ( trim(file) == '' ) file = trim(fileprefix) // '<Name>.nc'
986 
987  if ( trim(name) == '' ) then
988  call messagenotify( 'M', sub_sname, 'Global Settings:', rank_mpi = msnot_rank )
989  call messagenotify( 'M', sub_sname, ' AllOutput = %b', l = (/ alloutput /), rank_mpi = msnot_rank )
990  call messagenotify( 'M', sub_sname, ' FilePrefix = %c', c1 = trim(fileprefix ), rank_mpi = msnot_rank )
991  else
992  call messagenotify( 'M', sub_sname, 'Individual Settings:', rank_mpi = msnot_rank )
993  call messagenotify( 'M', sub_sname, ' Name = %c', c1 = trim(name ), rank_mpi = msnot_rank )
994  call messagenotify( 'M', sub_sname, ' File = %c', c1 = trim(file ), rank_mpi = msnot_rank )
995  end if
996  call messagenotify( 'M', sub_sname, ' Interval = %f [%c]', &
997  & d = (/ intvalue /), c1 = trim( intunit ), rank_mpi = msnot_rank )
998  call messagenotify( 'M', sub_sname, ' Precision = %c', c1 = trim(precision ), rank_mpi = msnot_rank )
999  call messagenotify( 'M', sub_sname, ' TimeAverage = %b', l = (/ timeaverage /), rank_mpi = msnot_rank )
1000  call messagenotify( 'M', sub_sname, ' Origin = %f [%c]', &
1001  & d = (/ originvalue /), c1 = trim( originunit ), rank_mpi = msnot_rank )
1002  call messagenotify( 'M', sub_sname, ' Terminus = %f [%c]', &
1003  & d = (/ terminusvalue /), c1 = trim( terminusunit ), rank_mpi = msnot_rank )
1004  call messagenotify( 'M', sub_sname, ' SliceStart = (/ %*d /)', &
1005  & i = slicestart(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
1006  call messagenotify( 'M', sub_sname, ' SliceEnd = (/ %*d /)', &
1007  & i = sliceend(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
1008  call messagenotify( 'M', sub_sname, ' SliceStride = (/ %*d /)', &
1009  & i = slicestride(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
1010  call messagenotify( 'M', sub_sname, ' SpaceAverage = (/ %*b /)', &
1011  & l = spaceaverage(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
1012  call messagenotify( 'M', sub_sname, ' NewFileInterval = %d [%c]', &
1013  & i = (/ newfileintvalue /), c1 = trim( newfileintunit ), rank_mpi = msnot_rank )
1014  call messagenotify( 'M', sub_sname, '', rank_mpi = msnot_rank )
1015 
1016  else
1017  call messagenotify( 'M', sub_sname, '----- loading is finished (iostat=%d) -----', &
1018  & i = (/iostat_nml/), rank_mpi = msnot_rank )
1019  end if
1020  end do
1021 
1022  close( unit_nml )
1023 
1024 
1025  ! NAMELIST ファイルを読み込まない場合
1026  ! NAMELIST file is not loaded
1027  !
1028  else
1029  call messagenotify( 'M', sub_sname, '----- "gtool_historyauto_nml" is not loaded" -----', rank_mpi = msnot_rank )
1030  name = ''
1031  file = ''
1032  call hstnmlinfoinquire( &
1033  & gthstnml = gthstnml, & ! (in)
1034  & interval_value = intvalue, & ! (out) optional
1035  & interval_unit = intunit, & ! (out) optional
1036  & precision = precision, & ! (out) optional
1037  & time_average = timeaverage, & ! (out) optional
1038  & origin_value = originvalue, & ! (out) optional
1039  & origin_unit = originunit, & ! (out) optional
1040  & terminus_value = terminusvalue, & ! (out) optional
1041  & terminus_unit = terminusunit, & ! (out) optional
1042  & slice_start = slicestart, & ! (out) optional
1043  & slice_end = sliceend, & ! (out) optional
1044  & slice_stride = slicestride, & ! (out) optional
1045  & space_average = spaceaverage, & ! (out) optional
1046  & newfile_intvalue = newfileintvalue, & ! (out) optional
1047  & newfile_intunit = newfileintunit, & ! (out) optional
1048  & fileprefix = fileprefix ) ! (out) optional
1049 
1050  ! 印字 ; Print
1051  !
1052  call messagenotify( 'M', sub_sname, 'Global Settings:', rank_mpi = msnot_rank )
1053  call messagenotify( 'M', sub_sname, ' AllOutput = %b', l = (/ alloutput /), rank_mpi = msnot_rank )
1054  call messagenotify( 'M', sub_sname, ' FilePrefix = %c', c1 = trim(fileprefix ), rank_mpi = msnot_rank )
1055  call messagenotify( 'M', sub_sname, ' Interval = %f [%c]', &
1056  & d = (/ intvalue /), c1 = trim( intunit ), rank_mpi = msnot_rank )
1057  call messagenotify( 'M', sub_sname, ' Precision = %c', c1 = trim(precision ), rank_mpi = msnot_rank )
1058  call messagenotify( 'M', sub_sname, ' TimeAverage = %b', l = (/ timeaverage /), rank_mpi = msnot_rank )
1059  call messagenotify( 'M', sub_sname, ' Origin = %f [%c]', &
1060  & d = (/ originvalue /), c1 = trim( originunit ), rank_mpi = msnot_rank )
1061  call messagenotify( 'M', sub_sname, ' Terminus = %f [%c]', &
1062  & d = (/ terminusvalue /), c1 = trim( terminusunit ), rank_mpi = msnot_rank )
1063  call messagenotify( 'M', sub_sname, ' SliceStart = (/ %*d /)', &
1064  & i = slicestart(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
1065  call messagenotify( 'M', sub_sname, ' SliceEnd = (/ %*d /)', &
1066  & i = sliceend(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
1067  call messagenotify( 'M', sub_sname, ' SliceStride = (/ %*d /)', &
1068  & i = slicestride(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
1069  call messagenotify( 'M', sub_sname, ' SpaceAverage = (/ %*b /)', &
1070  & l = spaceaverage(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
1071  call messagenotify( 'M', sub_sname, ' NewFileInterval = %d [%c]', &
1072  & i = (/ newfileintvalue /), c1 = trim( newfileintunit ), rank_mpi = msnot_rank )
1073  call messagenotify( 'M', sub_sname, '' , rank_mpi = msnot_rank)
1074 
1075  end if
1076 
1077  ! 終了処理, 例外処理
1078  ! Termination and Exception handling
1079  !
1080  initialized = .true.
1081 
1082 999 continue
1083  call storeerror(stat, subname, cause_c = cause_c)
1084  call endsub(subname, 'stat=%d', i = (/stat/) )
1085  end subroutine historyautocreate3
1086 
1087  !-------------------------------------------------------------------
1088 
1089  subroutine historyautocreate2( &
1090  & title, source, institution, & ! (in)
1091  & dims, dimsizes, longnames, units, & ! (in)
1092  & xtypes, conventions, gt_version,& ! (in) optional
1093  & all_output, & ! (in) optional
1094  & file_prefix, & ! (in) optional
1095  & namelist_filename, & ! (in) optional
1096  & interval, origin, terminus, & ! (in) optional
1097  & slice_start, slice_end, slice_stride, & ! (in) optional
1098  & space_average, & ! (in) optional
1099  & time_average, & ! (in) optional
1100  & newfile_interval, & ! (in) optional
1101  & rank, & ! (in) optional
1102  & origin_date, origin_date_invalid, & ! (in) optional
1103  & start_date, cal, & ! (in) optional
1104  & flag_mpi_gather, flag_mpi_split & ! (in) optional
1105  & )
1106  !
1107  ! 複数のヒストリデータ出力を行うための初期化を行います.
1108  !
1109  ! この HistoryAutoCreate には, モデル内で出力する
1110  ! 変数が依存する座標や座標重みなどを全てを設定してください.
1111  !
1112  ! all_output に .true. を与えた場合や,
1113  ! namelist_filename を与えない (空文字を与える) 場合には,
1114  ! HistoryAutoAddVariable で登録される全ての変数が出力されます.
1115  ! 一方で namelist_filename に NAMELIST ファイル名を与える場合には,
1116  ! その NAMELIST ファイルから出力のオンオフや,
1117  ! 出力ファイル名, 出力間隔などを変更可能です.
1118  ! 変更可能な項目に関しては NAMELIST#gtool_historyauto_nml
1119  ! を参照して下さい.
1120  !
1121  ! interval, origin, terminus, slice_start, slice_end, slice_stride,
1122  ! space_average, time_average, newfile_interval
1123  ! などの設定はデフォルト値として使用されます.
1124  ! これらの設定値は HistoryAutoAddVariable および
1125  ! NAMELIST#gtool_historyauto_nml で上書きされます.
1126  ! (優先度が高いのは NAMELIST#gtool_historyauto_nml ,
1127  ! HistoryAutoAddVariable の引数,
1128  ! HistoryAutoCreate の引数 の順です).
1129  !
1130  !
1131  ! Initialization for multiple history data output
1132  !
1133  ! Set all axes and their weights depended by variables
1134  ! output from numerical models to this "HistoryAutoCreate".
1135  !
1136  ! All variables registered by "HistoryAutoAddVariable"
1137  ! are output if .true. is given to "all_output" or
1138  ! "namelist_filename" is not given (or blanks are given)
1139  ! On the other hand, if a filename of NAMELIST file is
1140  ! given to "namelist_filename", on/off of output,
1141  ! output filename and output interval, etc. can be changed
1142  ! from the NAMELIST file.
1143  ! For available items, see "NAMELIST#gtool_historyauto_nml".
1144  !
1145  ! Settings about
1146  ! "interval", "origin", "terminus", "slice_start", "slice_end", "slice_stride",
1147  ! "space_average", "time_average", "newfile_interval"
1148  ! etc. are used as default values.
1149  ! Their set values are overwritten by
1150  ! "HistoryAutoAddVariable" or
1151  ! "NAMELIST#gtool_historyauto_nml".
1152  ! ("NAMELIST#gtool_historyauto_nml" is high priority,
1153  ! arguments of "HistoryAutoAddVariable" are medium,
1154  ! arguments of "HistoryAutoCreate" are low).
1155  !
1158  use gtool_history, only: historyaxiscreate
1162  use dc_trace, only: beginsub, endsub
1165  use netcdf, only: nf90_emaxdims, nf90_max_dims
1168  & present_select
1169  use dc_calendar, only: dc_cal, dc_cal_date
1170  use dc_date, only: dcdifftimecreate, evalbyunit
1172  use dc_message, only: messagenotify
1173  use dc_iounit, only: fileopen
1174  use dc_types, only: dp, string, token
1175  implicit none
1176  character(*), intent(in):: title
1177  ! データ全体の表題.
1178  ! Title of entire data
1179  character(*), intent(in):: source
1180  ! データを作成する際の手段.
1181  ! Source of data file
1182  character(*), intent(in):: institution
1183  ! ファイルを最終的に変更した組織/個人.
1184  ! Institution or person that changes files for the last time
1185  character(*), intent(in):: dims(:)
1186  ! 次元の名前.
1187  !
1188  ! 配列の大きさに制限はありません.
1189  ! 個々の次元の文字数は dc_types#TOKEN まで.
1190  ! 配列内の文字数は
1191  ! 全て同じでなければなりません.
1192  ! 足りない文字分は空白で
1193  ! 補ってください.
1194  !
1195  ! Names of dimensions.
1196  !
1197  ! Length of array is unlimited.
1198  ! Limits of numbers of characters of each
1199  ! dimensions are "dc_types#TOKEN".
1200  ! Numbers of characters in this array
1201  ! must be same.
1202  ! Make up a deficit with blanks.
1203  !
1204  integer, intent(in):: dimsizes (:)
1205  ! dims で指定したそれぞれの次元大きさ.
1206  !
1207  ! 配列の大きさは dims の大きさと等しい
1208  ! 必要があります. '0' (数字のゼロ) を指定
1209  ! するとその次元は 無制限次元 (unlimited
1210  ! dimension) となります. (gtool_history
1211  ! では時間の次元に対して無制限次元を
1212  ! 用いることを想定しています). ただし,
1213  ! 1 つの NetCDF ファイル (バージョン 3)
1214  ! は最大で 1 つの無制限次元しか持てないので,
1215  ! 2 ヶ所以上に '0' を指定しないでください.
1216  ! その場合, 正しく gtool4 データが出力されません.
1217  !
1218  ! Lengths of dimensions specified with "dims".
1219  !
1220  ! Length of this array must be same as
1221  ! length of "dim". If '0' (zero) is
1222  ! specified, the dimension is treated as
1223  ! unlimited dimension.
1224  ! (In "gtool_history", unlimited dimension is
1225  ! expected to be used as time).
1226  ! Note that one NetCDF file (version 3)
1227  ! can not have two or more unlimited
1228  ! dimensions, so that do not specify '0'
1229  ! to two or more places. In that case,
1230  ! gtoo4 data is not output currently
1231  !
1232  character(*), intent(in):: longnames (:)
1233  ! dims で指定したそれぞれの次元の名前.
1234  !
1235  ! 配列の大きさは dims の大きさ
1236  ! と等しい必要があります. 文字数
1237  ! は dc_types#STRING まで.
1238  ! 配列内の文字数は
1239  ! 全て同じでなければなりません.
1240  ! 足りない文字分は空白で補います.
1241  !
1242  ! Names of dimensions specified with "dims".
1243  !
1244  ! Length of this array must be same as
1245  ! length of "dim".
1246  ! Limits of numbers of characters are
1247  ! "dc_types#STRING".
1248  ! Numbers of characters in this array
1249  ! must be same.
1250  ! Make up a deficit with blanks.
1251  !
1252  character(*), intent(in):: units(:)
1253  ! dims で指定したそれぞれの次元の単位.
1254  !
1255  ! 配列の大きさは dims の大きさ
1256  ! と等しい必要があります. 文字数
1257  ! は dc_types#STRING まで.
1258  ! 配列内の文字数は
1259  ! 全て同じでなければなりません.
1260  ! 足りない文字分は空白で補います.
1261  !
1262  ! Units of dimensions specified with "dims".
1263  !
1264  ! Length of this array must be same as
1265  ! length of "dim".
1266  ! Limits of numbers of characters are
1267  ! "dc_types#STRING".
1268  ! Numbers of characters in this array
1269  ! must be same.
1270  ! Make up a deficit with blanks.
1271  !
1272  character(*), intent(in), optional:: xtypes(:)
1273  ! dims で指定したそれぞれの
1274  ! 次元のデータ型.
1275  !
1276  ! デフォルトは float (単精度実数型)
1277  ! です. 有効なのは,
1278  ! double (倍精度実数型),
1279  ! int (整数型) です. 指定しない
1280  ! 場合や, 無効な型を指定した場合には,
1281  ! float となります. なお, 配列の大きさ
1282  ! は *dims* の大きさと等しい必要が
1283  ! あります. 配列内の文字数は全て
1284  ! 同じでなければなりません.
1285  ! 足りない文字分は空白で補います.
1286  !
1287  ! Data types of dimensions specified
1288  ! with "dims".
1289  !
1290  ! Default value is "float" (single precision).
1291  ! Other valid values are
1292  ! "double" (double precision),
1293  ! "int" (integer).
1294  ! If no value or invalid value is specified,
1295  ! "float" is applied.
1296  ! Length of this array must be same as
1297  ! length of "dim".
1298  ! Numbers of characters in this array
1299  ! must be same.
1300  ! Make up a deficit with blanks.
1301  !
1302  character(*), intent(in), optional:: conventions
1303  ! 出力するファイルの netCDF
1304  ! 規約
1305  !
1306  ! 省略した場合,
1307  ! もしくは空文字を与えた場合,
1308  ! 出力する netCDF 規約の
1309  ! Conventions 属性に値
1310  ! gtool4_netCDF_Conventions
1311  ! が自動的に与えられます.
1312  !
1313  ! NetCDF conventions of output file.
1314  !
1315  ! If this argument is omitted or,
1316  ! blanks are given,
1317  ! gtool4_netCDF_Conventions is given to
1318  ! attribute "Conventions" of an output file
1319  ! automatically.
1320  !
1321  character(*), intent(in), optional:: gt_version
1322  ! gtool4 netCDF 規約のバージョン
1323  !
1324  ! 省略した場合, gt_version 属性に
1325  ! 規約の最新版のバージョンナンバー
1326  ! gtool4_netCDF_version
1327  ! が与えられます.
1328  ! (ただし, 引数 conventions に
1329  ! gtool4_netCDF_Conventions
1330  ! 以外が与えられる場合は
1331  ! gt_version 属性を作成しません).
1332  !
1333  ! Version of gtool4 netCDF Conventions.
1334  !
1335  ! If this argument is omitted,
1336  ! latest version number of gtool4 netCDF
1337  ! Conventions is given to attribute
1338  ! "gt_version" of an output file
1339  ! (However, gtool4_netCDF_Conventions is
1340  ! not given to an argument "conventions",
1341  ! attribute "gt_version" is not created).
1342  !
1343  logical, intent(in), optional:: all_output
1344  ! 登録変数を全て出力するためのフラグ.
1345  !
1346  ! .true. を指定すると,
1347  ! HistoryAutoAddVariable で登録された
1348  ! 変数が全て出力されるようになります.
1349  !
1350  ! *namelist_filename* が指定される場合
1351  ! には, デフォルトは .false. となります.
1352  ! この場合には,
1353  ! *namelist_filename* に指定された
1354  ! NAMELIST ファイルから読み込まれる
1355  ! NAMELIST#gtool_historyauto_nml
1356  ! で指定された変数のみ出力されます.
1357  !
1358  ! *namelist_filename* が指定されない場合
1359  ! には, .true. となります.
1360  !
1361  !
1362  ! Flag for output all registered variables.
1363  !
1364  ! When .true. is specified,
1365  ! all variables registered by
1366  ! "HistoryAutoAddVariable" are output.
1367  !
1368  ! If *namelist_filename* is specified,
1369  ! default value becomes .false. .
1370  ! In this case,
1371  ! only variables specified in
1372  ! "NAMELIST#gtool_historyauto_nml"
1373  ! loaded from a NAMELIST file
1374  ! *namelist_filename*.
1375  !
1376  ! If *namelist_filename* is not specified,
1377  ! this value becomes .true. .
1378  !
1379  character(*), intent(in), optional:: file_prefix
1380  ! ヒストリデータのファイル名の接頭詞.
1381  ! Prefixes of history data filenames
1382  character(*), intent(in), optional:: namelist_filename
1383  ! NAMELIST ファイルの名称.
1384  !
1385  ! 省略した場合, もしくは空白文字を与えた場合,
1386  ! NAMELIST ファイルは読み込みません.
1387  !
1388  ! Name of NAMELIST file.
1389  !
1390  ! If this argument is omitted,
1391  ! or blanks are specified,
1392  ! no NAMELIST file is loaded.
1393  !
1394  real, intent(in), optional:: interval
1395  ! 出力時間間隔.
1396  !
1397  ! 省略した場合,
1398  ! 自動的に 1.0 [sec] が設定されます.
1399  !
1400  ! Interval of output time.
1401  !
1402  ! If this argument is omitted,
1403  ! 1.0 [sec] is specified
1404  ! automatically.
1405  !
1406  real, intent(in), optional:: origin
1407  ! 出力開始時刻.
1408  !
1409  ! 省略した場合, 自動的に 0.0 [sec] が
1410  ! 設定されます.
1411  !
1412  ! Start time of output.
1413  !
1414  ! If this argument is omitted,
1415  ! 0.0 [sec] is specified
1416  ! automatically.
1417  !
1418  real, intent(in), optional:: terminus
1419  ! 出力終了時刻.
1420  !
1421  ! 省略した場合, 数値モデルの実行が終了するまで
1422  ! 出力を行います.
1423  !
1424  ! End time of output.
1425  !
1426  ! If this argument is omitted,
1427  ! output is continued until a numerical model
1428  ! is finished.
1429  !
1430  integer, intent(in), optional:: slice_start(:)
1431  ! 空間方向の開始点.
1432  !
1433  ! 省略した場合, 座標データの開始点が設定されます.
1434  !
1435  ! Start points of spaces.
1436  !
1437  ! If this argument is omitted,
1438  ! start points of dimensions are set.
1439  !
1440  integer, intent(in), optional:: slice_end(:)
1441  ! 空間方向の終了点.
1442  !
1443  ! 省略した場合, 座標データの終了点が設定されます.
1444  !
1445  ! End points of spaces.
1446  !
1447  ! If this argument is omitted,
1448  ! End points of dimensions are set.
1449  !
1450  integer, intent(in), optional:: slice_stride(:)
1451  ! 空間方向の刻み幅.
1452  !
1453  ! 省略した場合, 1 が設定されます.
1454  !
1455  ! Strides of spaces
1456  !
1457  ! If this argument is omitted,
1458  ! 1 is set.
1459  !
1460  logical, intent(in), optional:: space_average(:)
1461  ! 平均化のフラグ.
1462  !
1463  ! .true. が指定される座標に対して平均化を
1464  ! 行います.
1465  ! 省略した場合, .false. が設定されます.
1466  !
1467  ! Flag of average.
1468  !
1469  ! Axes specified .true. are averaged.
1470  ! If this argument is omitted,
1471  ! .false. is set.
1472  !
1473  logical, intent(in), optional:: time_average
1474  ! 出力データの時間平均フラグ.
1475  ! デフォルトは .false.
1476  ! Flag for time average of output data
1477  ! Default value is .false.
1478  integer, intent(in), optional:: newfile_interval
1479  ! ファイル分割時間間隔.
1480  !
1481  ! 省略した場合,
1482  ! 時間方向へのファイル分割を行いません.
1483  !
1484  ! Interval of time of separation of a file.
1485  !
1486  ! If this argument is omitted,
1487  ! a files is not separated in time direction.
1488  !
1489  character(*), intent(in), optional:: rank
1490  ! ランクの名称.
1491  ! 空文字を与えた場合には無視されます.
1492  !
1493  ! Name of a rank.
1494  ! If blank is given, this argument is ignored.
1495  !
1496  type(dc_datetime), intent(in), optional:: origin_date
1497  ! 出力開始日時.
1498  ! この引数は廃止予定のため, start_date を使用して下さい.
1499  !
1500  ! Start date of output.
1501  ! Use "start_date" because this argument is obsolete.
1502  !
1503  logical, intent(in), optional:: origin_date_invalid
1504  ! .true. を与えると, origin_date を無効にします.
1505  !
1506  ! If ".true." is given, "origin_date" is ignored.
1507  !
1508  type(dc_cal_date), intent(in), optional:: start_date
1509  ! 出力開始日時.
1510  !
1511  ! Start date of output.
1512  !
1513  type(dc_cal), intent(in), optional:: cal
1514  ! 暦情報.
1515  ! これを指定しない場合, dc_calendar モジュールの
1516  ! デフォルトの暦が使用されます.
1517  !
1518  ! Calendar.
1519  ! If this argument is specified, default calendar in
1520  ! "dc_calendar" module is used.
1521  !
1522  logical, intent(in), optional:: flag_mpi_gather
1523  ! MPI 使用時に, 各ノードで HistoryPut
1524  ! に与えたデータを一つのファイルに統合して出力
1525  ! する場合には .true. を与えてください.
1526  ! デフォルトは .false. です.
1527  !
1528  ! .true. を与えた場合, HistoryPutAxisMPI
1529  ! に全体の軸データを与えてください.
1530  !
1531  ! When MPI is used, if ".true." is given,
1532  ! data given to "HistoryPut" on each node
1533  ! is integrated and output to one file.
1534  ! Default value is ".false.".
1535  !
1536  ! If .true. is given, give data of axes in
1537  ! whole area to "HistoryPutAxisMPI"
1538  !
1539  logical, intent(in), optional:: flag_mpi_split
1540  ! MPI 使用時に, 各ノードで HistoryPut
1541  ! に与えたデータをそれぞれ別名のファイルに
1542  ! 出力する場合には .true. を与えてください.
1543  ! デフォルトは .false. です.
1544  !
1545  ! When MPI is used, if ".true." is given,
1546  ! data given to "HistoryPut" on each node
1547  ! is split into discrete files.
1548  ! Default value is ".false.".
1549  !
1550  integer:: blank_index
1551  type(dc_difftime):: interval_difftime, origin_difftime, terminus_difftime
1552  integer:: stat
1553  character(STRING):: cause_c
1554  character(*), parameter:: subname = "HistoryAutoCreate2"
1555  continue
1556  call beginsub(subname)
1557  stat = dc_noerr
1558  cause_c = ""
1559 
1560  ! このサブルーチンが 2 度呼ばれたらエラー
1561  ! Error is occurred when this subroutine is called twice
1562  !
1563  if ( initialized ) then
1564  stat = dc_ealreadyinit
1565  cause_c = 'gtool_historyauto'
1566  goto 999
1567  end if
1568 
1569  ! 次元の数に関するエラー処理
1570  ! Error handling for number of dimensions
1571  !
1572  numdims = size(dims)
1573 
1574  if ( size(dimsizes) /= numdims ) then
1575  cause_c = 'dimsizes, dims'
1576  elseif ( size(longnames) /= numdims ) then
1577  cause_c = 'longnames, dims'
1578  elseif ( size(units) /= numdims ) then
1579  cause_c = 'units, dims'
1580  endif
1581  if ( trim(cause_c) /= "" ) then
1582  stat = gt_eargsizemismatch
1583  goto 999
1584  end if
1585 
1586  if ( numdims > nf90_max_dims ) then
1587  stat = nf90_emaxdims
1588  goto 999
1589  end if
1590 
1591  ! 時刻次元に関するエラー処理
1592  ! Error handling for time dimension
1593  !
1594  if ( dimsizes(numdims) /= 0 ) then
1595  call messagenotify( 'W', subname, &
1596  & 'time dimension must be specified to the last of "dims"' )
1597  stat = hst_enotimedim
1598  goto 999
1599  end if
1600 
1601  ! 時刻の単位のチェック
1602  ! Check units of time
1603  !
1604  time_unit_bycreate = units(numdims)
1605  time_unit_suffix = ''
1606  blank_index = index( trim( adjustl(time_unit_bycreate) ), ' ' )
1607  if ( blank_index > 1 ) then
1608  time_unit_suffix = time_unit_bycreate(blank_index+1:)
1609  time_unit_bycreate = time_unit_bycreate(1:blank_index-1)
1610  end if
1611 
1612  ! 出力時間間隔のデフォルト値設定
1613  ! Configure default interval of output time
1614  !
1615  if ( present(interval) ) then
1616  call dcdifftimecreate( &
1617  & interval_difftime, & ! (out)
1618  & interval, time_unit_bycreate ) ! (in)
1619  else
1620  call dcdifftimecreate( &
1621  & interval_difftime, & ! (out)
1622  & 1.0, time_unit_bycreate ) ! (in)
1623  end if
1624 
1625  ! 出力開始・終了時刻のデフォルト値設定
1626  ! Configure default origin/terminus time of output
1627  !
1628  if ( present(origin) ) then
1629  call dcdifftimecreate( &
1630  & origin_difftime, & ! (out)
1631  & origin, time_unit_bycreate ) ! (in)
1632  else
1633  call dcdifftimecreate( &
1634  & origin_difftime, & ! (out)
1635  & 0.0, time_unit_bycreate ) ! (in)
1636  end if
1637 
1638  if ( present(terminus) ) then
1639  call dcdifftimecreate( &
1640  & terminus_difftime, & ! (out)
1641  & terminus, time_unit_bycreate ) ! (in)
1642  else
1643  call dcdifftimecreate( &
1644  & terminus_difftime, & ! (out)
1645  & -1.0, time_unit_bycreate ) ! (in)
1646  end if
1647 
1648  ! HistoryAutoCreate1 の呼び出し
1649  ! Call "HistoryAutoCreate1"
1650  !
1651  call historyautocreate( &
1652  & title = title, source = source, & ! (in)
1653  & institution = institution, & ! (in)
1654  & dims = dims, dimsizes = dimsizes, & ! (in)
1655  & longnames = longnames, units = units, & ! (in)
1656  & origin = origin_difftime, & ! (in)
1657  & terminus = terminus_difftime, & ! (in)
1658  & xtypes = xtypes, & ! (in) optional
1659  & conventions = conventions, & ! (in) optional
1660  & gt_version = gt_version, & ! (in) optional
1661  & all_output = all_output, & ! (in) optional
1662  & file_prefix = file_prefix, & ! (in) optional
1663  & namelist_filename = namelist_filename, & ! (in) optional
1664  & interval = interval_difftime, & ! (in) optional
1665  & slice_start = slice_start, & ! (in) optional
1666  & slice_end = slice_end, & ! (in) optional
1667  & slice_stride = slice_stride, & ! (in) optional
1668  & space_average = space_average, & ! (in) optional
1669  & time_average = time_average, & ! (in) optional
1670  & newfile_interval = newfile_interval, & ! (in) optional
1671  & rank = rank, & ! (in) optional
1672  & origin_date = origin_date, & ! (in) optional
1673  & origin_date_invalid = origin_date_invalid, & ! (in) optional
1674  & start_date = start_date, & ! (in) optional
1675  & cal = cal, & ! (in) optional
1676  & flag_mpi_gather = flag_mpi_gather, & ! (in) optional
1677  & flag_mpi_split = flag_mpi_split ) ! (in) optional
1678 
1679 999 continue
1680  call storeerror(stat, subname, cause_c = cause_c)
1681  call endsub(subname)
1682  end subroutine historyautocreate2
1683 
1684  !-------------------------------------------------------------------
1685 
1686  subroutine historyautocreate1( &
1687  & title, source, institution, & ! (in)
1688  & dims, dimsizes, longnames, units, & ! (in)
1689  & origin, terminus, & ! (in)
1690  & xtypes, conventions, gt_version, & ! (in) optional
1691  & all_output, & ! (in) optional
1692  & file_prefix, & ! (in) optional
1693  & namelist_filename, & ! (in) optional
1694  & interval, & ! (in) optional
1695  & slice_start, slice_end, slice_stride, & ! (in) optional
1696  & space_average, & ! (in) optional
1697  & time_average, & ! (in) optional
1698  & newfile_interval, & ! (in) optional
1699  & rank, & ! (in) optional
1700  & origin_date, origin_date_invalid, & ! (in) optional
1701  & start_date, cal, & ! (in) optional
1702  & flag_mpi_gather, flag_mpi_split & ! (in) optional
1703  & )
1704  !
1705  ! 複数のデータ出力を行うための初期化を行います.
1706  !
1707  ! この HistoryAutoCreate には, モデル内で出力する
1708  ! 変数が依存する座標や座標重みなどを全てを設定してください.
1709  !
1710  ! all_output に .true. を与えた場合や,
1711  ! namelist_filename を与えない (空文字を与える) 場合には,
1712  ! HistoryAutoAddVariable で登録される全ての変数が出力されます.
1713  ! 一方で namelist_filename に NAMELIST ファイル名を与える場合には,
1714  ! その NAMELIST ファイルから出力のオンオフや,
1715  ! 出力ファイル名, 出力間隔などを変更可能です.
1716  ! 変更可能な項目に関しては NAMELIST#gtool_historyauto_nml
1717  ! を参照して下さい.
1718  !
1719  ! interval, origin, terminus, slice_start, slice_end, slice_stride,
1720  ! space_average, time_average, newfile_interval
1721  ! などの設定はデフォルト値として使用されます.
1722  ! これらの設定値は HistoryAutoAddVariable および
1723  ! NAMELIST#gtool_historyauto_nml で上書きされます.
1724  ! (優先度が高いのは NAMELIST#gtool_historyauto_nml ,
1725  ! HistoryAutoAddVariable の引数,
1726  ! HistoryAutoCreate の引数 の順です).
1727  !
1728  !
1729  ! Initialization for multiple history data output
1730  !
1731  ! Set all axes and their weights depended by variables
1732  ! output from numerical models to this "HistoryAutoCreate".
1733  !
1734  ! All variables registered by "HistoryAutoAddVariable"
1735  ! are output if .true. is given to "all_output" or
1736  ! "namelist_filename" is not given (or blanks are given)
1737  ! On the other hand, if a filename of NAMELIST file is
1738  ! given to "namelist_filename", on/off of output,
1739  ! output filename and output interval, etc. can be changed
1740  ! from the NAMELIST file.
1741  ! For available items, see "NAMELIST#gtool_historyauto_nml".
1742  !
1743  ! Settings about
1744  ! "interval", "origin", "terminus", "slice_start", "slice_end", "slice_stride",
1745  ! "space_average", "time_average", "newfile_interval"
1746  ! etc. are used as default values.
1747  ! Their set values are overwritten by
1748  ! "HistoryAutoAddVariable" or
1749  ! "NAMELIST#gtool_historyauto_nml".
1750  ! ("NAMELIST#gtool_historyauto_nml" is high priority,
1751  ! arguments of "HistoryAutoAddVariable" are medium,
1752  ! arguments of "HistoryAutoCreate" are low).
1753  !
1755  & zero_time, numdims, &
1760  use gtool_history, only: historyaxiscreate, historyaxisaddattr
1764  use dc_trace, only: beginsub, endsub
1767  use netcdf, only: nf90_emaxdims, nf90_max_dims
1770  & present_select
1771  use dc_calendar, only: dc_cal, dc_cal_date, &
1772  & dccaldateinquire, dccalinquire, dccaldefault, dccalconvertbyunit
1773  use dc_date, only: dcdifftimecreate, evalbyunit, tochar, tocharcal, eval
1775  use dc_message, only: messagenotify
1776  use dc_iounit, only: fileopen
1777  use dc_types, only: dp, string, token
1778  implicit none
1779  character(*), intent(in):: title
1780  ! データ全体の表題.
1781  ! Title of entire data
1782  character(*), intent(in):: source
1783  ! データを作成する際の手段.
1784  ! Source of data file
1785  character(*), intent(in):: institution
1786  ! ファイルを最終的に変更した組織/個人.
1787  ! Institution or person that changes files for the last time
1788  character(*), intent(in):: dims(:)
1789  ! 次元の名前.
1790  !
1791  ! 配列の大きさに制限はありません.
1792  ! 個々の次元の文字数は dc_types#TOKEN まで.
1793  ! 配列内の文字数は
1794  ! 全て同じでなければなりません.
1795  ! 足りない文字分は空白で
1796  ! 補ってください.
1797  !
1798  ! Names of dimensions.
1799  !
1800  ! Length of array is unlimited.
1801  ! Limits of numbers of characters of each
1802  ! dimensions are "dc_types#TOKEN".
1803  ! Numbers of characters in this array
1804  ! must be same.
1805  ! Make up a deficit with blanks.
1806  !
1807  integer, intent(in):: dimsizes (:)
1808  ! dims で指定したそれぞれの次元大きさ.
1809  !
1810  ! 配列の大きさは dims の大きさと等しい
1811  ! 必要があります. '0' (数字のゼロ) を指定
1812  ! するとその次元は 無制限次元 (unlimited
1813  ! dimension) となります. (gtool_history
1814  ! では時間の次元に対して無制限次元を
1815  ! 用いることを想定しています). ただし,
1816  ! 1 つの NetCDF ファイル (バージョン 3)
1817  ! は最大で 1 つの無制限次元しか持てないので,
1818  ! 2 ヶ所以上に '0' を指定しないでください.
1819  ! その場合, 正しく gtool4 データが出力されません.
1820  !
1821  ! Lengths of dimensions specified with "dims".
1822  !
1823  ! Length of this array must be same as
1824  ! length of "dim". If '0' (zero) is
1825  ! specified, the dimension is treated as
1826  ! unlimited dimension.
1827  ! (In "gtool_history", unlimited dimension is
1828  ! expected to be used as time).
1829  ! Note that one NetCDF file (version 3)
1830  ! can not have two or more unlimited
1831  ! dimensions, so that do not specify '0'
1832  ! to two or more places. In that case,
1833  ! gtoo4 data is not output currently
1834  !
1835  character(*), intent(in):: longnames (:)
1836  ! dims で指定したそれぞれの次元の名前.
1837  !
1838  ! 配列の大きさは dims の大きさ
1839  ! と等しい必要があります. 文字数
1840  ! は dc_types#STRING まで.
1841  ! 配列内の文字数は
1842  ! 全て同じでなければなりません.
1843  ! 足りない文字分は空白で補います.
1844  !
1845  ! Names of dimensions specified with "dims".
1846  !
1847  ! Length of this array must be same as
1848  ! length of "dim".
1849  ! Limits of numbers of characters are
1850  ! "dc_types#STRING".
1851  ! Numbers of characters in this array
1852  ! must be same.
1853  ! Make up a deficit with blanks.
1854  !
1855  character(*), intent(in):: units(:)
1856  ! dims で指定したそれぞれの次元の単位.
1857  !
1858  ! 配列の大きさは dims の大きさ
1859  ! と等しい必要があります. 文字数
1860  ! は dc_types#STRING まで.
1861  ! 配列内の文字数は
1862  ! 全て同じでなければなりません.
1863  ! 足りない文字分は空白で補います.
1864  !
1865  ! Units of dimensions specified with "dims".
1866  !
1867  ! Length of this array must be same as
1868  ! length of "dim".
1869  ! Limits of numbers of characters are
1870  ! "dc_types#STRING".
1871  ! Numbers of characters in this array
1872  ! must be same.
1873  ! Make up a deficit with blanks.
1874  !
1875  real(DP), intent(in):: origin
1876  ! 出力開始時刻.
1877  !
1878  ! Start time of output.
1879  !
1880  real(DP), intent(in):: terminus
1881  ! 出力終了時刻.
1882  !
1883  ! End time of output.
1884  !
1885  character(*), intent(in), optional:: xtypes(:)
1886  ! dims で指定したそれぞれの
1887  ! 次元のデータ型.
1888  !
1889  ! デフォルトは float (単精度実数型)
1890  ! です. 有効なのは,
1891  ! double (倍精度実数型),
1892  ! int (整数型) です. 指定しない
1893  ! 場合や, 無効な型を指定した場合には,
1894  ! float となります. なお, 配列の大きさ
1895  ! は *dims* の大きさと等しい必要が
1896  ! あります. 配列内の文字数は全て
1897  ! 同じでなければなりません.
1898  ! 足りない文字分は空白で補います.
1899  !
1900  ! Data types of dimensions specified
1901  ! with "dims".
1902  !
1903  ! Default value is "float" (single precision).
1904  ! Other valid values are
1905  ! "double" (double precision),
1906  ! "int" (integer).
1907  ! If no value or invalid value is specified,
1908  ! "float" is applied.
1909  ! Length of this array must be same as
1910  ! length of "dim".
1911  ! Numbers of characters in this array
1912  ! must be same.
1913  ! Make up a deficit with blanks.
1914  !
1915  character(*), intent(in), optional:: conventions
1916  ! 出力するファイルの netCDF
1917  ! 規約
1918  !
1919  ! 省略した場合,
1920  ! もしくは空文字を与えた場合,
1921  ! 出力する netCDF 規約の
1922  ! Conventions 属性に値
1923  ! gtool4_netCDF_Conventions
1924  ! が自動的に与えられます.
1925  !
1926  ! NetCDF conventions of output file.
1927  !
1928  ! If this argument is omitted or,
1929  ! blanks are given,
1930  ! gtool4_netCDF_Conventions is given to
1931  ! attribute "Conventions" of an output file
1932  ! automatically.
1933  !
1934  character(*), intent(in), optional:: gt_version
1935  ! gtool4 netCDF 規約のバージョン
1936  !
1937  ! 省略した場合, gt_version 属性に
1938  ! 規約の最新版のバージョンナンバー
1939  ! gtool4_netCDF_version
1940  ! が与えられます.
1941  ! (ただし, 引数 conventions に
1942  ! gtool4_netCDF_Conventions
1943  ! 以外が与えられる場合は
1944  ! gt_version 属性を作成しません).
1945  !
1946  ! Version of gtool4 netCDF Conventions.
1947  !
1948  ! If this argument is omitted,
1949  ! latest version number of gtool4 netCDF
1950  ! Conventions is given to attribute
1951  ! "gt_version" of an output file
1952  ! (However, gtool4_netCDF_Conventions is
1953  ! not given to an argument "conventions",
1954  ! attribute "gt_version" is not created).
1955  !
1956  logical, intent(in), optional:: all_output
1957  ! 登録変数を全て出力するためのフラグ.
1958  !
1959  ! .true. を指定すると,
1960  ! HistoryAutoAddVariable で登録された
1961  ! 変数が全て出力されるようになります.
1962  !
1963  ! *namelist_filename* が指定される場合
1964  ! には, デフォルトは .false. となります.
1965  ! この場合には,
1966  ! *namelist_filename* に指定された
1967  ! NAMELIST ファイルから読み込まれる
1968  ! NAMELIST#gtool_historyauto_nml
1969  ! で指定された変数のみ出力されます.
1970  !
1971  ! *namelist_filename* が指定されない場合
1972  ! には, .true. となります.
1973  !
1974  !
1975  ! Flag for output all registered variables.
1976  !
1977  ! When .true. is specified,
1978  ! all variables registered by
1979  ! "HistoryAutoAddVariable" are output.
1980  !
1981  ! If *namelist_filename* is specified,
1982  ! default value becomes .false. .
1983  ! In this case,
1984  ! only variables specified in
1985  ! "NAMELIST#gtool_historyauto_nml"
1986  ! loaded from a NAMELIST file
1987  ! *namelist_filename*.
1988  !
1989  ! If *namelist_filename* is not specified,
1990  ! this value becomes .true. .
1991  !
1992  character(*), intent(in), optional:: file_prefix
1993  ! データのファイル名の接頭詞.
1994  ! Prefixes of history data filenames
1995  character(*), intent(in), optional:: namelist_filename
1996  ! NAMELIST ファイルの名称.
1997  !
1998  ! 省略した場合, もしくは空白文字を与えた場合,
1999  ! NAMELIST ファイルは読み込みません.
2000  !
2001  ! Name of NAMELIST file.
2002  !
2003  ! If this argument is omitted,
2004  ! or blanks are specified,
2005  ! no NAMELIST file is loaded.
2006  !
2007  real(DP), intent(in), optional:: interval
2008  ! 出力時間間隔.
2009  !
2010  ! 省略した場合,
2011  ! 自動的に 1.0 [sec] が設定されます.
2012  !
2013  ! Interval of output time.
2014  !
2015  ! If this argument is omitted,
2016  ! 1.0 [sec] is specified
2017  ! automatically.
2018  !
2019  integer, intent(in), optional:: slice_start(:)
2020  ! 空間方向の開始点.
2021  !
2022  ! 省略した場合, 座標データの開始点が設定されます.
2023  !
2024  ! Start points of spaces.
2025  !
2026  ! If this argument is omitted,
2027  ! start points of dimensions are set.
2028  !
2029  integer, intent(in), optional:: slice_end(:)
2030  ! 空間方向の終了点.
2031  !
2032  ! 省略した場合, もしくは負の値が与えら得た場合,
2033  ! 座標データの終了点が設定されます.
2034  !
2035  ! End points of spaces.
2036  !
2037  ! If this argument is omitted or
2038  ! negative value is specified,
2039  ! end points of dimensions are set.
2040  !
2041  integer, intent(in), optional:: slice_stride(:)
2042  ! 空間方向の刻み幅.
2043  !
2044  ! 省略した場合, 1 が設定されます.
2045  !
2046  ! Strides of spaces
2047  !
2048  ! If this argument is omitted,
2049  ! 1 is set.
2050  !
2051  logical, intent(in), optional:: space_average(:)
2052  ! 平均化のフラグ.
2053  !
2054  ! .true. が指定される座標に対して平均化を
2055  ! 行います.
2056  ! 省略した場合, .false. が設定されます.
2057  !
2058  ! Flag of average.
2059  !
2060  ! Axes specified .true. are averaged.
2061  ! If this argument is omitted,
2062  ! .false. is set.
2063  !
2064  logical, intent(in), optional:: time_average
2065  ! 出力データの時間平均フラグ.
2066  ! デフォルトは .false.
2067  ! Flag for time average of output data
2068  ! Default value is .false.
2069  integer, intent(in), optional:: newfile_interval
2070  ! ファイル分割時間間隔.
2071  !
2072  ! 省略した場合,
2073  ! 時間方向へのファイル分割を行いません.
2074  !
2075  ! Interval of time of separation of a file.
2076  !
2077  ! If this argument is omitted,
2078  ! a files is not separated in time direction.
2079  !
2080  character(*), intent(in), optional:: rank
2081  ! ランクの名称.
2082  !
2083  ! Name of a rank.
2084  !
2085  type(dc_datetime), intent(in), optional:: origin_date
2086  ! 出力開始日時.
2087  ! この引数は廃止予定のため, start_date を使用して下さい.
2088  !
2089  ! Start date of output.
2090  ! Use "start_date" because this argument is obsolete.
2091  !
2092  logical, intent(in), optional:: origin_date_invalid
2093  ! .true. を与えると, origin_date を無効にします.
2094  !
2095  ! If ".true." is given, "origin_date" is ignored.
2096  type(dc_cal_date), intent(in), optional:: start_date
2097  ! 出力開始日時.
2098  !
2099  ! Start date of output.
2100  !
2101  type(dc_cal), intent(in), optional:: cal
2102  ! 暦情報.
2103  ! これを指定しない場合, dc_calendar モジュールの
2104  ! デフォルトの暦が使用されます.
2105  !
2106  ! Calendar.
2107  ! If this argument is specified, default calendar in
2108  ! "dc_calendar" module is used.
2109  !
2110  logical, intent(in), optional:: flag_mpi_gather
2111  ! MPI 使用時に, 各ノードで HistoryPut
2112  ! に与えたデータを一つのファイルに統合して出力
2113  ! する場合には .true. を与えてください.
2114  ! デフォルトは .false. です.
2115  !
2116  ! .true. を与えた場合, HistoryPutAxisMPI
2117  ! に全体の軸データを与えてください.
2118  !
2119  ! When MPI is used, if ".true." is given,
2120  ! data given to "HistoryPut" on each node
2121  ! is integrated and output to one file.
2122  ! Default value is ".false.".
2123  !
2124  ! If .true. is given, give data of axes in
2125  ! whole area to "HistoryPutAxisMPI"
2126  !
2127  logical, intent(in), optional:: flag_mpi_split
2128  ! MPI 使用時に, 各ノードで HistoryPut
2129  ! に与えたデータをそれぞれ別名のファイルに
2130  ! 出力する場合には .true. を与えてください.
2131  ! デフォルトは .false. です.
2132  !
2133  ! When MPI is used, if ".true." is given,
2134  ! data given to "HistoryPut" on each node
2135  ! is split into discrete files.
2136  ! Default value is ".false.".
2137  !
2138 
2139 
2140  ! NAMELIST 変数群 ; NAMELIST group of variables
2141  character(STRING):: Name
2142  ! 変数名.
2143  ! 空白の場合には, この他の設定値は
2144  ! gtool_historyauto モジュールにおいて
2145  ! 出力されるデータ全ての
2146  ! デフォルト値となります.
2147  !
2148  ! "Data1,Data2" のようにカンマで区切って複数
2149  ! の変数を指定することも可能です.
2150  !
2151  ! Variable identifier.
2152  ! If blank is given, other values are
2153  ! used as default values of output data
2154  ! in "gtool_historyauto".
2155  !
2156  ! Multiple variables can be specified
2157  ! as "Data1,Data2" too. Delimiter is comma.
2158  character(STRING):: File
2159  ! 出力ファイル名.
2160  ! これはデフォルト値としては使用されません.
2161  ! *Name* に値が設定されている時のみ有効です.
2162  !
2163  ! Output file name.
2164  ! This is not used as default value.
2165  ! This value is valid only when *Name* is
2166  ! specified.
2167 
2168  real(DP):: IntValue
2169  ! データの出力間隔の数値.
2170  ! 負の値を与えると, 出力を抑止します.
2171  ! Numerical value for interval of history data output
2172  ! Negative values suppresses output.
2173  character(TOKEN):: IntUnit
2174  ! データの出力間隔の単位.
2175  ! Unit for interval of history data output
2176  character(TOKEN):: Precision
2177  ! データの精度.
2178  ! デフォルトは float (単精度実数型)
2179  ! です. 有効なのは,
2180  ! double (倍精度実数型),
2181  ! int (整数型) です. 指定しない
2182  ! 場合や, 無効な型を指定した場合には,
2183  ! float となります.
2184  !
2185  ! Precision of history data
2186  ! Default value is "float" (single precision).
2187  ! Other valid values are
2188  ! "double" (double precision),
2189  ! "int" (integer).
2190  ! If no value or invalid value is specified,
2191  ! "float" is applied.
2192  character(STRING):: FilePrefix
2193  ! データのファイル名の接頭詞.
2194  ! Prefixes of history data filenames
2195  logical:: TimeAverage
2196  ! 出力データの時間平均フラグ.
2197  !
2198  ! ".true." を与えると, 時間平均値が出力されます.
2199  !
2200  ! Flag for time average of output data
2201  !
2202  ! If ".ture." is specified,
2203  ! time average values are output.
2204  !
2205  logical:: AllOutput
2206  ! 登録変数を全て出力するためのフラグ.
2207  ! Flag for output all registered variables.
2208  real(DP):: OriginValue
2209  ! 出力開始時刻.
2210  ! Start time of output.
2211  character(TOKEN):: OriginUnit
2212  ! 出力開始時刻の単位.
2213  ! Unit of start time of output.
2214  real(DP):: TerminusValue
2215  ! 出力終了時刻.
2216  ! End time of output.
2217  character(TOKEN):: TerminusUnit
2218  ! 出力終了時刻の単位.
2219  ! Unit of end time of output.
2220  integer:: SliceStart(1:nf90_max_dims)
2221  ! 空間方向の開始点.
2222  ! Start points of spaces.
2223  integer:: SliceEnd(1:nf90_max_dims)
2224  ! 空間方向の終了点.
2225  !
2226  ! 省略した場合, もしくは負の値が与えら得た場合,
2227  ! 座標データの終了点が設定されます.
2228  !
2229  ! End points of spaces.
2230  !
2231  ! If this argument is omitted or
2232  ! negative value is specified,
2233  ! end points of dimensions are set.
2234  !
2235  integer:: SliceStride(1:nf90_max_dims)
2236  ! 空間方向の刻み幅.
2237  ! Strides of spaces.
2238  logical:: SpaceAverage(1:nf90_max_dims)
2239  ! 空間平均のフラグ.
2240  ! Flag of spatial average.
2241  integer:: NewFileIntValue
2242  ! ファイル分割時間間隔の数値.
2243  ! Numerical value for interval of time of separation of a file.
2244  character(TOKEN):: NewFileIntUnit
2245  ! ファイル分割時間間隔の単位.
2246  ! Unit of interval of time of separation of a file.
2247 
2248  namelist /gtool_historyauto_nml/ &
2249  & name, file, &
2250  & intvalue, intunit, &
2251  & precision, &
2252  & fileprefix, &
2253  & timeaverage, alloutput, &
2254  & originvalue, originunit, &
2255  & terminusvalue, terminusunit, &
2256  & slicestart, sliceend, slicestride, spaceaverage, &
2257  & newfileintvalue, newfileintunit
2258  ! gtool_historyauto モジュールのデータ用
2259  ! NAMELIST 変数群名.
2260  !
2261  ! gtool_historyauto_generic#HistoryAutoCreate
2262  ! を使用する際に, オプショナル引数 *namelist_filename*
2263  ! へ NAMELIST ファイル名を指定することで,
2264  ! そのファイルからこの NAMELIST 変数群を
2265  ! 読み込みます.
2266  !
2267  ! NAMELIST group name for
2268  ! history data of "gtool_historyauto" module.
2269  !
2270  ! If a NAMELIST filename is specified to
2271  ! an optional argument *namelist_filename* when
2272  ! "gtool_historyauto_generic#HistoryAutoCreate"
2273  ! is used, this NAMELIST group is
2274  ! loaded from the file.
2275 
2276 
2277  ! 作業変数 ; Work variables
2278  integer:: blank_index
2279  integer:: stat
2280  character(STRING):: cause_c
2281  integer:: unit_nml ! NAMELIST ファイルオープン用装置番号.
2282  ! Unit number for NAMELIST file open
2283  integer:: iostat_nml ! NAMELIST 読み込み時の IOSTAT.
2284  ! IOSTAT of NAMELIST read
2285  character(TOKEN):: pos_nml
2286  ! NAMELIST 読み込み時のファイル位置.
2287  ! File position of NAMELIST read
2288  integer:: i, j
2289  character(TOKEN):: my_xtype
2290 
2291  real(DP):: interval_work, origin_work, terminus_work
2292  integer:: date_day
2293  real(DP):: date_sec
2294  integer:: msnot_rank
2295  character(STRING):: date_str
2296  character(TOKEN):: cal_str, cal_type
2297  integer:: origin_year, origin_month, origin_day, origin_hour, origin_min
2298  real(DP):: origin_sec
2299  integer:: month_in_year, hour_in_day, min_in_hour
2300  integer, pointer:: day_in_month(:) =>null()
2301  real(DP):: sec_in_min
2302  character(*), parameter:: subname = "HistoryAutoCreate1"
2303  continue
2304  call beginsub(subname, version = version)
2305  stat = dc_noerr
2306  cause_c = ""
2307 
2308  ! このサブルーチンが 2 度呼ばれたらエラー
2309  ! Error is occurred when this subroutine is called twice
2310  !
2311  if ( initialized ) then
2312  stat = dc_ealreadyinit
2313  cause_c = 'gtool_historyauto'
2314  goto 999
2315  end if
2316 
2317  ! ゼロ秒の作成.
2318  ! Create zero seconds
2319  !
2320  zero_time = 0.0_dp
2321 !!$ call DCDiffTimeCreate( &
2322 !!$ & zero_time, & ! (out)
2323 !!$ & sec = 0.0_DP ) ! (in)
2324 
2325  ! 次元の数に関するエラー処理
2326  ! Error handling for number of dimensions
2327  !
2328  numdims = size(dims)
2329 
2330  if ( size(dimsizes) /= numdims ) then
2331  cause_c = 'dimsizes, dims'
2332  elseif ( size(longnames) /= numdims ) then
2333  cause_c = 'longnames, dims'
2334  elseif ( size(units) /= numdims ) then
2335  cause_c = 'units, dims'
2336  endif
2337  if ( trim(cause_c) /= "" ) then
2338  stat = gt_eargsizemismatch
2339  goto 999
2340  end if
2341 
2342  if ( numdims > nf90_max_dims ) then
2343  stat = nf90_emaxdims
2344  goto 999
2345  end if
2346 
2347  ! 時刻次元に関するエラー処理
2348  ! Error handling for time dimension
2349  !
2350  if ( dimsizes(numdims) /= 0 ) then
2351  call messagenotify( 'W', subname, &
2352  & 'time dimension must be specified to the last of "dims"' )
2353  stat = hst_enotimedim
2354  goto 999
2355  end if
2356 
2357  ! 出力ファイルの基本メタデータの保管
2358  ! Save basic meta data for output file
2359  !
2360  title_save = title
2361  source_save = source
2362  institution_save = institution
2363 
2364  conventions_save = ''
2365  if ( present(conventions) ) conventions_save = conventions
2366 
2367  gt_version_save = ''
2368  if ( present(gt_version) ) gt_version_save = gt_version
2369 
2370  rank_save = ''
2371  if ( present(rank) ) rank_save = rank
2372 
2373  ! MPI に関する情報の保管
2374  ! Save information about MPI
2375  !
2376  save_mpi_split = present_and_true( flag_mpi_split )
2377  save_mpi_gather = present_and_true( flag_mpi_gather )
2378 
2379  msnot_rank = -1
2380  if ( save_mpi_gather ) msnot_rank = 0
2381 
2382  ! 時刻の単位のチェック
2383  ! Check units of time
2384  !
2385  time_unit_bycreate = units(numdims)
2386  time_unit_suffix = ''
2387  blank_index = index( trim( adjustl(time_unit_bycreate) ), ' ' )
2388  if ( blank_index > 1 ) then
2389  time_unit_suffix = time_unit_bycreate(blank_index+1:)
2390  time_unit_bycreate = time_unit_bycreate(1:blank_index-1)
2391  end if
2392 
2393  ! 座標軸データの保管
2394  ! Save axes data
2395  !
2396  do i = 1, numdims
2397  my_xtype = ''
2398  if ( present(xtypes) ) then
2399  if ( size(xtypes) >= i ) then
2400  my_xtype = xtypes(i)
2401  end if
2402  end if
2403 
2404  call historyaxiscreate( &
2405  & axis = gthst_axes(i), & ! (out)
2406  & name = dims(i), size = dimsizes(i), & ! (in)
2407  & longname = longnames(i), units = units(i), & ! (in)
2408  & xtype = my_xtype ) ! (in)
2409 
2410  allocate( data_axes(i) % a_axis( dimsizes(i) ) )
2411  data_axes(i) % a_axis = (/ ( real( j, DP ), j = 1, dimsizes(i) ) /)
2412 
2413  end do
2414 
2415  ! 暦の登録
2416  ! Register calendar
2417  !
2418  if ( present(cal) ) then
2419  cal_save = cal
2420  else
2421  call dccaldefault( cal_save )
2422  end if
2423 
2424  ! 日時の指定
2425  ! Specify date
2426  !
2427  if ( present(start_date) ) then
2428 
2429  call dccaldateinquire( &
2430  & date_str = date_str, & ! (out)
2431  & date = start_date, & ! (in) optional
2432  & cal = cal & ! (in) optional
2433  ! & , zone = "+09:00" &
2434  & )
2435 
2436  call dccaldateinquire( &
2437  & origin_year, origin_month, origin_day, & ! (out) optional
2438  & origin_hour, origin_min, origin_sec, & ! (out) optional
2439  & date = start_date, & ! (in) optional
2440  & cal = cal & ! (in) optional
2441  & )
2442 
2443  call dccalinquire( &
2444  & cal_str, & ! (out) optional
2445  & month_in_year = month_in_year, & ! (out) optional
2446  & day_in_month_ptr = day_in_month , & ! (out) optional
2447  & hour_in_day = hour_in_day , & ! (out) optional
2448  & min_in_hour = min_in_hour , & ! (out) optional
2449  & sec_in_min = sec_in_min , & ! (out) optional
2450  & cal = cal_save ) ! (in) optional
2451 
2452  ! 地球暦の場合のみ units 属性に "since ..." を付加
2453  !
2454  select case ( trim(cal_str) )
2455  case ( 'gregorian' )
2456  time_unit_suffix = trim(time_unit_suffix) // &
2457  & ' since ' // trim(date_str)
2458  case ( 'julian' )
2459  time_unit_suffix = trim(time_unit_suffix) // &
2460  & ' since ' // trim(date_str)
2461  case ( 'noleap' )
2462  time_unit_suffix = trim(time_unit_suffix) // &
2463  & ' since ' // trim(date_str)
2464  case ( '360day' )
2465  time_unit_suffix = trim(time_unit_suffix) // &
2466  & ' since ' // trim(date_str)
2467  case ( 'cyclic' )
2468  time_unit_suffix = trim(time_unit_suffix) // &
2469  & ' since ' // trim(date_str)
2470  end select
2471 
2472  ! 開始日時情報の付与
2473  !
2474  call historyaxisaddattr( &
2475  & axis = gthst_axes(numdims), & ! (inout)
2476  & attrname = 'origin', & ! (in)
2477  & value = 'origin_year origin_month origin_day ' // &
2478  & 'origin_hour origin_min origin_sec' ) ! (in)
2479 
2480  call historyaxisaddattr( gthst_axes(numdims), 'origin_year', origin_year )
2481  call historyaxisaddattr( gthst_axes(numdims), 'origin_month', origin_month )
2482  call historyaxisaddattr( gthst_axes(numdims), 'origin_day', origin_day )
2483  call historyaxisaddattr( gthst_axes(numdims), 'origin_hour', origin_hour )
2484  call historyaxisaddattr( gthst_axes(numdims), 'origin_min', origin_min )
2485 
2486  ! 暦情報の付与
2487  !
2488  call historyaxisaddattr( &
2489  & axis = gthst_axes(numdims), & ! (inout)
2490  & attrname = 'calendar', & ! (in)
2491  & value = cal_str ) ! (in)
2492 
2493  if ( trim(cal_str) == 'user_defined' ) then
2494  call historyaxisaddattr( gthst_axes(numdims), 'month_in_year', month_in_year )
2495  call historyaxisaddattr( gthst_axes(numdims), 'day_in_month', day_in_month )
2496  call historyaxisaddattr( gthst_axes(numdims), 'hour_in_day', hour_in_day )
2497  call historyaxisaddattr( gthst_axes(numdims), 'min_in_hour', min_in_hour )
2498  call historyaxisaddattr( gthst_axes(numdims), 'sec_in_min', sec_in_min )
2499  end if
2500 
2501  deallocate( day_in_month )
2502 
2503  elseif ( present(origin_date) &
2504  & .and. .not. present_and_true(origin_date_invalid) ) then
2505  call eval( origin_date, & ! (in)
2506  & day = date_day, sec = date_sec ) ! (out)
2507  if ( date_day /= 0 .or. date_sec /= 0.0 ) then
2508  time_unit_suffix = trim(time_unit_suffix) // &
2509  & ' since ' // tochar(origin_date)
2510 
2511  call historyaxisaddattr( &
2512  & axis = gthst_axes(numdims), & ! (inout)
2513  & attrname = 'calendar', & ! (in)
2514  & value = tocharcal(origin_date) ) ! (in)
2515 
2516  end if
2517  end if
2518 
2519  ! 登録変数を全て出力するためのフラグの保管
2520  ! Save flag for output all registered variables
2521  !
2522  if ( present(all_output) ) all_output_save = all_output
2523  if ( .not. present_and_not_empty(namelist_filename) ) all_output_save = .true.
2524  alloutput = all_output_save
2525 
2526  ! 出力時間間隔のデフォルト値設定
2527  ! Configure default interval of output time
2528  !
2529  if ( all_output_save ) then
2530  if ( present(interval) ) then
2531  interval_work = interval
2532 ! interval_work = EvalbyUnit( interval, time_unit_bycreate )
2533  else
2534  interval_work = 1.0
2535  end if
2536  else
2537  interval_work = - 1.0
2538  end if
2539 
2540  ! 出力開始・終了時刻のデフォルト値設定
2541  ! Configure default origin/terminus time of output
2542  !
2543  origin_work = &
2544  & dccalconvertbyunit( origin, time_unit_bycreate, 'sec', cal_save )
2545  terminus_work = terminus
2546 
2547 ! origin_work = EvalbyUnit( origin, 'sec' )
2548 ! terminus_work = EvalbyUnit( terminus, time_unit_bycreate )
2549 
2550  ! gtool_historyauto_nml へデフォルト値の設定
2551  ! Configure default values for "gtool_historyauto_nml"
2552  !
2553  call hstnmlinfocreate( gthstnml ) ! (out)
2554 
2555  call hstnmlinfoadd( &
2556  & gthstnml = gthstnml, & ! (inout)
2557  & name = '', & ! (in) optional
2558  & precision = 'float', & ! (in) optional
2559  & fileprefix = file_prefix, & ! (in) optional
2560  & interval_value = interval_work, & ! (in) optional
2561  & interval_unit = time_unit_bycreate, & ! (in) optional
2562  & origin_value = origin_work, & ! (in) optional
2563  & origin_unit = 'sec', & ! (in) optional
2564 !!$ & origin_unit = time_unit_bycreate, & ! (in) optional
2565  & terminus_value = terminus_work, & ! (in) optional
2566  & terminus_unit = time_unit_bycreate, & ! (in) optional
2567  & time_average = time_average, & ! (in) optional
2568  & slice_start = slice_start, & ! (in) optional
2569  & slice_end = slice_end, & ! (in) optional
2570  & slice_stride = slice_stride, & ! (in) optional
2571  & space_average = space_average, & ! (in) optional
2572  & newfile_intvalue = newfile_interval, & ! (in) optional
2573  & newfile_intunit = time_unit_bycreate ) ! (in) optional
2574 
2575  ! NAMELIST ファイルの読み込み
2576  ! Load NAMELIST file
2577  !
2578  if ( present_and_not_empty(namelist_filename) ) then
2579  call fileopen( unit_nml, & ! (out)
2580  & namelist_filename, mode = 'r' ) ! (in)
2581 
2582  iostat_nml = 0
2583  pos_nml = ''
2584 
2585  call messagenotify( 'M', sub_sname, '----- "gtool_historyauto_nml" is loaded from "%c" -----', &
2586  & c1 = trim(namelist_filename), rank_mpi = msnot_rank )
2587 
2588  do while ( trim(pos_nml) /= 'APPEND' .and. iostat_nml == 0 )
2589 
2590  name = ''
2591  file = ''
2592  call hstnmlinfoinquire( &
2593  & gthstnml = gthstnml, & ! (in)
2594  & interval_value = intvalue, & ! (out) optional
2595  & interval_unit = intunit, & ! (out) optional
2596  & precision = precision, & ! (out) optional
2597  & time_average = timeaverage, & ! (out) optional
2598  & origin_value = originvalue, & ! (out) optional
2599  & origin_unit = originunit, & ! (out) optional
2600  & terminus_value = terminusvalue, & ! (out) optional
2601  & terminus_unit = terminusunit, & ! (out) optional
2602  & slice_start = slicestart, & ! (out) optional
2603  & slice_end = sliceend, & ! (out) optional
2604  & slice_stride = slicestride, & ! (out) optional
2605  & space_average = spaceaverage, & ! (out) optional
2606  & newfile_intvalue = newfileintvalue, & ! (out) optional
2607  & newfile_intunit = newfileintunit, & ! (out) optional
2608  & fileprefix = fileprefix ) ! (out) optional
2609 
2610  read( unit = unit_nml, & ! (in)
2611  & nml = gtool_historyauto_nml, & ! (out)
2612  & iostat = iostat_nml ) ! (out)
2613  inquire( unit = unit_nml, & ! (in)
2614  & position = pos_nml ) ! (out)
2615 
2616  if ( iostat_nml == 0 ) then
2617 
2618  ! NAMELIST から与えられた値が無効な場合, デフォルト値を使用
2619  ! Default values are used when values from NAMELIST are invalid
2620  !
2621  if ( .not. intvalue > 0.0 ) then
2622  intvalue = interval_work
2623  intunit = time_unit_bycreate
2624  end if
2625  if ( .not. originvalue > 0.0 ) then
2626  originvalue = origin_work
2627  originunit = 'sec'
2628  end if
2629  if ( .not. terminusvalue > 0.0 ) then
2630  terminusvalue = terminus_work
2631  terminusunit = time_unit_bycreate
2632  end if
2633 
2634  ! 情報の登録
2635  ! Register information
2636  !
2637  call hstnmlinfoadd( &
2638  & gthstnml = gthstnml, & ! (inout)
2639  & name = name, & ! (in) optional
2640  & file = file, & ! (in) optional
2641  & interval_value = intvalue, & ! (in) optional
2642  & interval_unit = intunit, & ! (in) optional
2643  & precision = precision, & ! (in) optional
2644  & time_average = timeaverage, & ! (in) optional
2645  & origin_value = originvalue, & ! (in) optional
2646  & origin_unit = originunit, & ! (in) optional
2647  & terminus_value = terminusvalue, & ! (in) optional
2648  & terminus_unit = terminusunit, & ! (in) optional
2649  & slice_start = slicestart, & ! (in) optional
2650  & slice_end = sliceend, & ! (in) optional
2651  & slice_stride = slicestride, & ! (in) optional
2652  & space_average = spaceaverage, & ! (in) optional
2653  & newfile_intvalue = newfileintvalue, & ! (in) optional
2654  & newfile_intunit = newfileintunit, & ! (in) optional
2655  & fileprefix = fileprefix ) ! (in) optional
2656 
2657  ! 登録変数を全て出力するためのフラグの保管
2658  ! Save flag for output all registered variables
2659  !
2660  if ( trim(name) == '' ) then
2661  all_output_save = alloutput
2662  end if
2663 
2664  ! 印字 ; Print
2665  !
2666  if ( trim(file) == '' ) file = trim(fileprefix) // '<Name>.nc'
2667 
2668  if ( trim(name) == '' ) then
2669  call messagenotify( 'M', sub_sname, 'Global Settings:', rank_mpi = msnot_rank )
2670  call messagenotify( 'M', sub_sname, ' AllOutput = %b', l = (/ alloutput /), rank_mpi = msnot_rank )
2671  call messagenotify( 'M', sub_sname, ' FilePrefix = %c', c1 = trim(fileprefix ), rank_mpi = msnot_rank )
2672  else
2673  call messagenotify( 'M', sub_sname, 'Individual Settings:', rank_mpi = msnot_rank )
2674  call messagenotify( 'M', sub_sname, ' Name = %c', c1 = trim(name ), rank_mpi = msnot_rank )
2675  call messagenotify( 'M', sub_sname, ' File = %c', c1 = trim(file ), rank_mpi = msnot_rank )
2676  end if
2677  call messagenotify( 'M', sub_sname, ' Interval = %f [%c]', &
2678  & d = (/ intvalue /), c1 = trim( intunit ), rank_mpi = msnot_rank )
2679  call messagenotify( 'M', sub_sname, ' Precision = %c', c1 = trim(precision ), rank_mpi = msnot_rank )
2680  call messagenotify( 'M', sub_sname, ' TimeAverage = %b', l = (/ timeaverage /), rank_mpi = msnot_rank )
2681  call messagenotify( 'M', sub_sname, ' Origin = %f [%c]', &
2682  & d = (/ originvalue /), c1 = trim( originunit ), rank_mpi = msnot_rank )
2683  call messagenotify( 'M', sub_sname, ' Terminus = %f [%c]', &
2684  & d = (/ terminusvalue /), c1 = trim( terminusunit ), rank_mpi = msnot_rank )
2685  call messagenotify( 'M', sub_sname, ' SliceStart = (/ %*d /)', &
2686  & i = slicestart(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
2687  call messagenotify( 'M', sub_sname, ' SliceEnd = (/ %*d /)', &
2688  & i = sliceend(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
2689  call messagenotify( 'M', sub_sname, ' SliceStride = (/ %*d /)', &
2690  & i = slicestride(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
2691  call messagenotify( 'M', sub_sname, ' SpaceAverage = (/ %*b /)', &
2692  & l = spaceaverage(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
2693  call messagenotify( 'M', sub_sname, ' NewFileInterval = %d [%c]', &
2694  & i = (/ newfileintvalue /), c1 = trim( newfileintunit ), rank_mpi = msnot_rank )
2695  call messagenotify( 'M', sub_sname, '', rank_mpi = msnot_rank )
2696 
2697  else
2698  call messagenotify( 'M', sub_sname, '----- loading is finished (iostat=%d) -----', &
2699  & i = (/iostat_nml/), rank_mpi = msnot_rank )
2700  end if
2701  end do
2702 
2703  close( unit_nml )
2704 
2705 
2706  ! NAMELIST ファイルを読み込まない場合
2707  ! NAMELIST file is not loaded
2708  !
2709  else
2710  call messagenotify( 'M', sub_sname, '----- "gtool_historyauto_nml" is not loaded" -----', rank_mpi = msnot_rank )
2711  name = ''
2712  file = ''
2713  call hstnmlinfoinquire( &
2714  & gthstnml = gthstnml, & ! (in)
2715  & interval_value = intvalue, & ! (out) optional
2716  & interval_unit = intunit, & ! (out) optional
2717  & precision = precision, & ! (out) optional
2718  & time_average = timeaverage, & ! (out) optional
2719  & origin_value = originvalue, & ! (out) optional
2720  & origin_unit = originunit, & ! (out) optional
2721  & terminus_value = terminusvalue, & ! (out) optional
2722  & terminus_unit = terminusunit, & ! (out) optional
2723  & slice_start = slicestart, & ! (out) optional
2724  & slice_end = sliceend, & ! (out) optional
2725  & slice_stride = slicestride, & ! (out) optional
2726  & space_average = spaceaverage, & ! (out) optional
2727  & newfile_intvalue = newfileintvalue, & ! (out) optional
2728  & newfile_intunit = newfileintunit, & ! (out) optional
2729  & fileprefix = fileprefix ) ! (out) optional
2730 
2731  ! 印字 ; Print
2732  !
2733  call messagenotify( 'M', sub_sname, 'Global Settings:', rank_mpi = msnot_rank )
2734  call messagenotify( 'M', sub_sname, ' AllOutput = %b', l = (/ alloutput /), rank_mpi = msnot_rank )
2735  call messagenotify( 'M', sub_sname, ' FilePrefix = %c', c1 = trim(fileprefix ), rank_mpi = msnot_rank )
2736  call messagenotify( 'M', sub_sname, ' Interval = %f [%c]', &
2737  & d = (/ intvalue /), c1 = trim( intunit ), rank_mpi = msnot_rank )
2738  call messagenotify( 'M', sub_sname, ' Precision = %c', c1 = trim(precision ), rank_mpi = msnot_rank )
2739  call messagenotify( 'M', sub_sname, ' TimeAverage = %b', l = (/ timeaverage /), rank_mpi = msnot_rank )
2740  call messagenotify( 'M', sub_sname, ' Origin = %f [%c]', &
2741  & d = (/ originvalue /), c1 = trim( originunit ), rank_mpi = msnot_rank )
2742  call messagenotify( 'M', sub_sname, ' Terminus = %f [%c]', &
2743  & d = (/ terminusvalue /), c1 = trim( terminusunit ), rank_mpi = msnot_rank )
2744  call messagenotify( 'M', sub_sname, ' SliceStart = (/ %*d /)', &
2745  & i = slicestart(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
2746  call messagenotify( 'M', sub_sname, ' SliceEnd = (/ %*d /)', &
2747  & i = sliceend(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
2748  call messagenotify( 'M', sub_sname, ' SliceStride = (/ %*d /)', &
2749  & i = slicestride(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
2750  call messagenotify( 'M', sub_sname, ' SpaceAverage = (/ %*b /)', &
2751  & l = spaceaverage(1:numdims-1), n = (/ numdims-1 /), rank_mpi = msnot_rank )
2752  call messagenotify( 'M', sub_sname, ' NewFileInterval = %d [%c]', &
2753  & i = (/ newfileintvalue /), c1 = trim( newfileintunit ), rank_mpi = msnot_rank )
2754  call messagenotify( 'M', sub_sname, '' , rank_mpi = msnot_rank)
2755 
2756  end if
2757 
2758  ! 終了処理, 例外処理
2759  ! Termination and Exception handling
2760  !
2761  initialized = .true.
2762 
2763 999 continue
2764  call storeerror(stat, subname, cause_c = cause_c)
2765  call endsub(subname, 'stat=%d', i = (/stat/) )
2766  end subroutine historyautocreate1
character(string), save, public time_unit_suffix
character(string), save, public institution_save
subroutine historyautocreate1(title, source, institution, dims, dimsizes, longnames, units, origin, terminus, xtypes, conventions, gt_version, all_output, file_prefix, namelist_filename, interval, slice_start, slice_end, slice_stride, space_average, time_average, newfile_interval, rank, origin_date, origin_date_invalid, start_date, cal, flag_mpi_gather, flag_mpi_split)
character(string), save, public conventions_save
integer, parameter, public token
単語やキーワードを保持する文字型変数の種別型パラメタ
Definition: dc_types.f90:109
logical function, public present_and_true(arg)
Definition: dc_present.f90:80
character(string), save, public title_save
character(string), save, public source_save
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
character(token), save, public gt_version_save
integer, parameter, public hst_enotimedim
Definition: dc_error.f90:588
character(string) function, public joinchar(carray, expr)
Definition: dc_string.f90:861
type(gt_history_axis_data), dimension(1:nf90_max_dims), target, save, public data_axes
type(gt_history_axis), dimension(1:nf90_max_dims), target, save, public gthst_axes
integer, parameter, public dp
倍精度実数型変数
Definition: dc_types.f90:83
logical function, public present_and_not_empty(arg)
Definition: dc_present.f90:276
subroutine, public beginsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca, version)
Definition: dc_trace.f90:351
文字型変数の操作.
Definition: dc_string.f90:24
integer, parameter, public gt_eargsizemismatch
Definition: dc_error.f90:536
種別型パラメタを提供します。
Definition: dc_types.f90:49
character(token), save, public time_unit_bycreate
subroutine historyautocreate3(title, source, institution, dims, dimsizes, longnames, units, origin, terminus, xtypes, conventions, gt_version, all_output, file_prefix, namelist_filename, interval, slice_start, slice_end, slice_stride, space_average, time_average, newfile_interval, rank, origin_date, origin_date_invalid, start_date, cal, flag_mpi_gather, flag_mpi_split)
type(gthst_nmlinfo), save, public gthstnml
character(token), save, public rank_save
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446
type(dc_cal), save, public cal_save
character(*), parameter, public sub_sname
integer, parameter, public dc_ealreadyinit
Definition: dc_error.f90:558
subroutine historyautocreate2(title, source, institution, dims, dimsizes, longnames, units, xtypes, conventions, gt_version, all_output, file_prefix, namelist_filename, interval, origin, terminus, slice_start, slice_end, slice_stride, space_average, time_average, newfile_interval, rank, origin_date, origin_date_invalid, start_date, cal, flag_mpi_gather, flag_mpi_split)
integer, parameter, public dc_enegative
Definition: dc_error.f90:568
character(*), parameter, public version
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118