historycreate.f90
Go to the documentation of this file.
1 !--
2 ! *** Caution!! ***
3 !
4 ! This file is generated from "historycreate.rb2f90" by Ruby 2.3.3.
5 ! Please do not edit this file directly.
6 !
7 ! [JAPANESE]
8 !
9 ! ※※※ 注意!!! ※※※
10 !
11 ! このファイルは "historycreate.rb2f90" から Ruby 2.3.3
12 ! によって自動生成されたファイルです.
13 ! このファイルを直接編集しませんようお願い致します.
14 !
15 !
16 !++
17 !
18 != gtool4 データ出力用初期設定
19 != Initialzation of gtool4 data putput
20 !
21 ! Authors:: Yasuhiro MORIKAWA, Eizi TOYODA
22 ! Version:: $Id: historycreate.rb2f90,v 1.4 2009-11-03 05:22:46 morikawa Exp $
23 ! Tag Name:: $Name: $
24 ! Copyright:: Copyright (C) GFD Dennou Club, 2000-2009. All rights reserved.
25 ! License:: See COPYRIGHT[link:../../../COPYRIGHT]
26 !
27  subroutine historycreate1( &
28  & file, title, source, institution, &
29  & dims, dimsizes, longnames, units, origin, interval, &
30  & xtypes, history, origind, intervald, conventions, gt_version, overwrite, quiet, &
31  & flag_mpi_gather, flag_mpi_split, err )
32  !
33  !== gtool4 データ出力用初期設定
34  !
35  ! このサブルーチンは、gtool4 データ出力の初期設定を行います。
36  ! HistoryAddVariable、 HistoryCopyVariable、 HistoryPut、
37  ! HistoryAddAttr、 HistoryClose、 HistorySetTime
38  ! を用いるためには、HistoryCreate による初期設定が必要です。
39  !
40  ! なお、プログラム内で HistoryCreate を呼び出した場合、
41  ! プログラムを終了する前に必ず、 HistoryClose を呼び出して
42  ! 終了処理を行なって下さい。
43  !
44  ! *HistoryCreate* というサブルーチン名は 2 つの別々の
45  ! サブルーチンの総称名です。上記のサブルーチンも参照ください。
46  !
47  !
48  ! Two specific subroutines shares common part:
49  !
50  ! Both two ones initializes a dataset *file*.
51  ! The result of type GT_HISTORY will be returned by *history*
52  ! or managed internally if omitted.
53  ! Mandatory global attributes are defined by arguments
54  ! *title*, *source*, and *institution*;
55  ! they are all declared as ((character(len = *))).
56  ! Spatial axis definitions have two different forms:
57  ! a primitive one uses several arrays of various types:
58  ! *dims*, *dimsizes*, *longnames*, *units*, and *xtypes*.
59  ! Another sophisticated one has only array of type GT_HISTORY_AXIS,
60  ! *axes*.
61  ! Temporal definition is done without *origin*, *interval*.
62  !
67  use dc_trace, only: beginsub, endsub, dbgmessage
69  use dc_string, only: joinchar, tochar, stoa, cprintf, lchar
70  use dc_url, only: urlmerge
72  use dc_types, only: string, token, dp
73  use dc_message, only: messagenotify
74  use dc_calendar, only: dc_cal, dc_cal_date, &
75  & dccalcreate, dccaldatecurrent, dccaldateinquire
77  use dc_date, only: dcdatetimecreate, tochar, dcdifftimecreate, &
78  & evalbyunit, parsetimeunits
79  use sysdep, only: sysdepenvget
80  implicit none
81  character(*), intent(in):: file
82  ! 出力するファイルの名前.
83  ! Name of output file
84  character(*), intent(in):: title
85  ! データ全体の表題.
86  ! Title of entire data
87  character(*), intent(in):: source
88  ! データを作成する際の手段.
89  ! Source of data file
90  character(*), intent(in):: institution
91  ! ファイルを最終的に変更した組織/個人.
92  ! Institution or person that changes files for the last time
93  character(*), intent(in):: dims(:)
94  ! 次元の名前.
95  !
96  ! 配列の大きさに制限はありません.
97  ! 個々の次元の文字数は dc_types#TOKEN まで.
98  ! 配列内の文字数は
99  ! 全て同じでなければなりません.
100  ! 足りない文字分は空白で
101  ! 補ってください.
102  !
103  ! Names of dimensions.
104  !
105  ! Length of array is unlimited.
106  ! Limits of numbers of characters of each
107  ! dimensions are "dc_types#TOKEN".
108  ! Numbers of characters in this array
109  ! must be same.
110  ! Make up a deficit with blanks.
111  !
112  integer, intent(in):: dimsizes (:)
113  ! dims で指定したそれぞれの次元大きさ.
114  !
115  ! 配列の大きさは dims の大きさと等しい
116  ! 必要があります. '0' (数字のゼロ) を指定
117  ! するとその次元は 無制限次元 (unlimited
118  ! dimension) となります. (gtool_history
119  ! では時間の次元に対して無制限次元を
120  ! 用いることを想定しています). ただし,
121  ! 1 つの NetCDF ファイル (バージョン 3)
122  ! は最大で 1 つの無制限次元しか持てないので,
123  ! 2 ヶ所以上に '0' を指定しないでください.
124  ! その場合, 正しく gtool4 データが出力されません.
125  !
126  ! Lengths of dimensions specified with "dims".
127  !
128  ! Length of this array must be same as
129  ! length of "dim". If '0' (zero) is
130  ! specified, the dimension is treated as
131  ! unlimited dimension.
132  ! (In "gtool_history", unlimited dimension is
133  ! expected to be used as time).
134  ! Note that one NetCDF file (version 3)
135  ! can not have two or more unlimited
136  ! dimensions, so that do not specify '0'
137  ! to two or more places. In that case,
138  ! gtoo4 data is not output currently
139  !
140  character(*), intent(in):: longnames (:)
141  ! dims で指定したそれぞれの次元の名前.
142  !
143  ! 配列の大きさは dims の大きさ
144  ! と等しい必要があります. 文字数
145  ! は dc_types#STRING まで.
146  ! 配列内の文字数は
147  ! 全て同じでなければなりません.
148  ! 足りない文字分は空白で補います.
149  !
150  ! Names of dimensions specified with "dims".
151  !
152  ! Length of this array must be same as
153  ! length of "dim".
154  ! Limits of numbers of characters are
155  ! "dc_types#STRING".
156  ! Numbers of characters in this array
157  ! must be same.
158  ! Make up a deficit with blanks.
159  !
160  character(*), intent(in):: units(:)
161  ! dims で指定したそれぞれの次元の単位.
162  !
163  ! 配列の大きさは dims の大きさ
164  ! と等しい必要があります. 文字数
165  ! は dc_types#STRING まで.
166  ! 配列内の文字数は
167  ! 全て同じでなければなりません.
168  ! 足りない文字分は空白で補います.
169  !
170  ! Units of dimensions specified with "dims".
171  !
172  ! Length of this array must be same as
173  ! length of "dim".
174  ! Limits of numbers of characters are
175  ! "dc_types#STRING".
176  ! Numbers of characters in this array
177  ! must be same.
178  ! Make up a deficit with blanks.
179  !
180  real, intent(in), optional:: origin
181  ! 時間の原点.
182  !
183  ! これは HistoryPut により変数を最初に
184  ! 出力するときの時間となります.
185  !
186  ! 省略した場合, 時間の原点には
187  ! 自動的に 0.0 が設定されます.
188  !
189  ! Origin of time.
190  !
191  ! This time is used as time
192  ! when first output is done by "HistoryPut".
193  !
194  ! If this argument is omitted,
195  ! 0.0 is specified automatically.
196  !
197  real, intent(in), optional:: interval
198  ! 出力時間間隔.
199  !
200  ! 同じ変数に対して HistoryPut が複数回
201  ! 呼ばれた時に, 自動的に時間変数がこの値
202  ! だけ増やされて出力されます. なお,
203  ! 各々の出力ファイルにつき HistorySetTime
204  ! を一度でも用いた場合, この値は無効に
205  ! なるので注意してください.
206  !
207  ! 省略した場合, 自動的に 1.0 が設定されます.
208  !
209  ! Interval of output time.
210  !
211  ! When "HistoryPut" is called two or
212  ! more times for the same variable, time
213  ! is increased as this value and
214  ! output automatically.
215  ! Note that this value becomes
216  ! invalid when "HistorySetTime" is
217  ! used for each output file even once.
218  !
219  ! If this argument is omitted,
220  ! 1.0 is specified automatically.
221  !
222  character(*), intent(in), optional:: xtypes(:)
223  ! dims で指定したそれぞれの
224  ! 次元のデータ型.
225  !
226  ! デフォルトは float (単精度実数型)
227  ! です. 有効なのは,
228  ! double (倍精度実数型),
229  ! int (整数型) です. 指定しない
230  ! 場合や, 無効な型を指定した場合には,
231  ! float となります. なお, 配列の大きさ
232  ! は *dims* の大きさと等しい必要が
233  ! あります. 配列内の文字数は全て
234  ! 同じでなければなりません.
235  ! 足りない文字分は空白で補います.
236  !
237  ! Data types of dimensions specified
238  ! with "dims".
239  !
240  ! Default value is "float" (single precision).
241  ! Other valid values are
242  ! "double" (double precision),
243  ! "int" (integer).
244  ! If no value or invalid value is specified,
245  ! "float" is applied.
246  ! Length of this array must be same as
247  ! length of "dim".
248  ! Numbers of characters in this array
249  ! must be same.
250  ! Make up a deficit with blanks.
251  !
252  type(gt_history), intent(out), optional, target:: history
253  ! 出力ファイルの設定に関する情報を
254  ! 格納した構造体.
255  !
256  ! 1 つのプログラムで複数のファイル
257  ! に gtool データを出力する
258  ! 場合に利用します.
259  ! (単独のファイルに書き出す場合は
260  ! 指定する必要はありません)
261  !
262  ! Derived type that
263  ! stores information about output files.
264  !
265  ! If multiple gtool4 data files are
266  ! output from one program, use this
267  ! argument.
268  ! (If onlye one file is output,
269  ! this argument is not needed).
270  !
271  real(DP), intent(in), optional:: origind
272  ! 時間の原点. (倍精度実数)
273  !
274  ! *time* と同様です.
275  !
276  ! Origin of time. (Double precision)
277  !
278  ! This is same as *time*.
279  !
280  real(DP), intent(in), optional:: intervald
281  ! 出力時間間隔. (倍精度実数)
282  !
283  ! *interval* と同様です.
284  !
285  ! Interval of output time. (Double precision)
286  !
287  ! This is same as *interval*.
288  !
289  character(*), intent(in), optional:: conventions
290  ! 出力するファイルの netCDF
291  ! 規約
292  !
293  ! 省略した場合,
294  ! もしくは空文字を与えた場合,
295  ! 出力する netCDF 規約の
296  ! Conventions 属性に値
297  ! gtool_history_internal#gtool4_netCDF_Conventions
298  ! が自動的に与えられます.
299  !
300  ! NetCDF conventions of output file.
301  !
302  ! If this argument is omitted or,
303  ! blanks are given,
304  ! gtool_history_internal#gtool4_netCDF_Conventions is given to
305  ! attribute "Conventions" of an output file
306  ! automatically.
307  !
308  character(*), intent(in), optional:: gt_version
309  ! gtool4 netCDF 規約のバージョン
310  !
311  ! 省略した場合, gt_version 属性に
312  ! 規約の最新版のバージョンナンバー
313  ! gtool4_netCDF_version
314  ! が与えられます.
315  ! (ただし, 引数 conventions に
316  ! gtool_history_internal#gtool4_netCDF_Conventions
317  ! 以外が与えられる場合は
318  ! gt_version 属性を作成しません).
319  !
320  ! Version of gtool4 netCDF Conventions.
321  !
322  ! If this argument is omitted,
323  ! latest version number of gtool4 netCDF
324  ! Conventions is given to attribute
325  ! "gt_version" of an output file
326  ! (However, gtool_history_internal#gtool4_netCDF_Conventions is
327  ! not given to an argument "conventions",
328  ! attribute "gt_version" is not created).
329  !
330  logical, intent(in), optional:: overwrite
331  ! 上書き可否
332  !
333  ! この引数に .false. を渡すと,
334  ! 既存のファイルを上書きしません.
335  ! デフォルトは上書きします.
336  !
337  ! Whether or not to overwrite.
338  !
339  ! If .false. is specified to this
340  ! argument, an existing file is not
341  ! overwritten.
342  ! By default, existing file is overwritten.
343  !
344  logical, intent(in), optional:: quiet
345  ! .true. を与えた場合,
346  ! メッセージ出力が抑制されます.
347  ! デフォルトは .false. です.
348  !
349  ! If ".true." is given,
350  ! messages are suppressed.
351  ! Default value is ".false.".
352  !
353  logical, intent(in), optional:: flag_mpi_gather
354  ! MPI 使用時に, 各ノードで HistoryPut
355  ! に与えたデータを一つのファイルに統合して出力
356  ! する場合には .true. を与えてください.
357  ! デフォルトは .false. です.
358  !
359  ! .true. を与えた場合, HistoryPutAxisMPI
360  ! に全体の軸データを与えてください.
361  !
362  ! When MPI is used, if ".true." is given,
363  ! data given to "HistoryPut" on each node
364  ! is integrated and output to one file.
365  ! Default value is ".false.".
366  !
367  ! If .true. is given, give data of axes in
368  ! whole area to "HistoryPutAxisMPI"
369  !
370  logical, intent(in), optional:: flag_mpi_split
371  ! MPI 使用時にこの引数に .true. を与えると,
372  ! 各ノードごとに
373  ! *file* 引数に "_rankXXXXXX"
374  ! (X は [0-9] の数値で, ノード番号を指す)
375  ! を付加したファイルを出力します.
376  ! 例えば, *file* に "output.nc" を与えた場合.
377  ! ノード 0 では "output_rank000000.nc",
378  ! ノード 12 では "output_rank000012.nc"
379  ! を出力します.
380  ! デフォルトは .false. です.
381  !
382  ! When MPI is used, if ".true." is given,
383  ! files that have names with suffixes
384  ! "_rankXXXXXX"
385  ! (X is [0-9] that indicates node number)
386  ! are output on each node.
387  ! For example, "output.nc" is given to *file*,
388  ! "output_rank000000.nc", "output_rank000012.nc"
389  ! are output on node 0 and node 12.
390  ! Default value is ".false.".
391  !
392  logical, intent(out), optional:: err
393  ! 例外処理用フラグ.
394  ! デフォルトでは, この手続き内でエラーが
395  ! 生じた場合, プログラムは強制終了します.
396  ! 引数 *err* が与えられる場合,
397  ! プログラムは強制終了せず, 代わりに
398  ! *err* に .true. が代入されます.
399  !
400  ! Exception handling flag.
401  ! By default, when error occur in
402  ! this procedure, the program aborts.
403  ! If this *err* argument is given,
404  ! .true. is substituted to *err* and
405  ! the program does not abort.
406  integer:: numdims, i, stat, blank_index
407  type(gt_history), pointer:: hst =>null()
408  character(TOKEN):: my_xtype, origin_str!, interval_str
409  character(STRING):: file_work, url, x_inst, x_conv, x_gtver, nc_history
410  character(STRING):: cause_c
411  logical:: gtver_add, overwrite_required
412  character(TOKEN):: username
413  type(dc_cal):: cal_standard
414  type(dc_cal_date):: now_date
415  character(TOKEN):: now_date_str
416  character(*), parameter:: subname = "HistoryCreate1"
417  character(*), parameter:: version = &
418  & '$Name: $' // &
419  & '$Id: historycreate.rb2f90,v 1.4 2009-11-03 05:22:46 morikawa Exp $'
420  continue
421  call beginsub(subname, 'file=%c ndims=%d', &
422  & c1=trim(file), i=(/size(dims)/), &
423  & version=version)
424  stat = dc_noerr
425  cause_c = ""
426  call dbgmessage( &
427  & 'dims(:)=%a, dimsizes(:)=%a, longnames(:)=%a, units(:)=%a', &
428  & ca=stoa(joinchar(dims), tochar(dimsizes), &
429  & joinchar(longnames), joinchar(units)))
430  if (present(history)) then
431  hst => history
432  else
433  hst => default
434  endif
435  ! 初期設定のチェック
436  ! Check initialization
437  !
438  if ( hst % initialized ) then
439  stat = dc_ealreadyinit
440  cause_c = 'GT_HISTORY'
441  goto 999
442  end if
443  ! dims, dimsizes, longnames, units の整合性チェック
444  ! Check consistency about "dims", "dimsizes", "longnames", "units"
445  !
446  numdims = size(dims)
447  if ( size(dimsizes) /= numdims ) then
448  cause_c = 'dimsizes, dims'
449  elseif ( size(longnames) /= numdims ) then
450  cause_c = 'longnames, dims'
451  elseif ( size(units) /= numdims ) then
452  cause_c = 'units, dims'
453  endif
454  if ( trim(cause_c) /= "" ) then
455  stat = gt_eargsizemismatch
456  goto 999
457  end if
458  ! 次元変数表作成.
459  ! Create table of dimensional variables
460  !
461  allocate(hst % dimvars(numdims))
462  allocate(hst % dim_value_written(numdims))
463  hst % dim_value_written(:) = .false.
464  hst % unlimited_index = 0
465  ! ユーザ名の取得
466  ! Get user name
467  !
468  call sysdepenvget('USER', username)
469  if (trim(username) == '') username = 'unknown'
470  ! 現在時刻の取得
471  ! Get current time
472  !
473  call dccaldatecurrent( now_date )
474  call dccalcreate( 'gregorian', cal_standard )
475  call dccaldateinquire( now_date_str, date = now_date, cal = cal_standard )
476 ! call DCDateTimeCreate(now_time)
477  nc_history = trim(now_date_str) // ' ' // &
478  & trim(username) // &
479  & '> gtool_history: HistoryCreate' // &
480  & achar(10)
481  ! MPI に関連する情報の初期設定
482  ! Initialize information about MPI
483  !
484  hst % mpi_gather = .false.
485  hst % mpi_split = .false.
486  ! MPI 使用時のファイル名の扱い
487  ! Treat file names when MPI is used
488  !
489  file_work = file
490  ! 変数 URL (出力ファイル) の作成
491  ! Create variable URL (output file)
492  !
493  do, i = 1, numdims
494  my_xtype = ""
495  if ( present(xtypes) ) then
496  if ( size(xtypes) >= i ) then
497  my_xtype = xtypes(i)
498  end if
499  end if
500  url = urlmerge(file=file, var=dims(i))
501  overwrite_required = .true.
502  if (present_and_false(overwrite)) overwrite_required = .false.
503  call create( &
504  & hst % dimvars(i), trim(url), &
505  & dimsizes(i), xtype=trim(my_xtype), &
506  & overwrite=overwrite_required)
507  ! conventions が存在しない場合はデフォルトの値を
508  ! 属性 Conventions に付加。
509  if ( present_and_not_empty(conventions) ) then
510  x_conv = conventions
511  else
513  endif
514  ! 1) gt_version がある場合、それを gt_version 属性に渡す。
515  ! 2) gt_version が無い場合、conventions も無いか、または
516  ! gtool4 netCDF 規約が入っていれば最新版を gt_version
517  ! に与える。そうでない場合は gt_version 属性を与えない。
518  if (present_and_not_empty(gt_version)) then
519  x_gtver = gt_version
520  gtver_add = .true.
521  else
522  if ( present_and_not_empty(conventions) .and. &
523  & .not. x_conv == gtool4_netcdf_conventions ) then
524  gtver_add = .false.
525  else
526  x_gtver = gtool4_netcdf_version
527  gtver_add = .true.
528  endif
529  endif
530  if (trim(institution) /= "") then
531  x_inst = institution
532  else
533  x_inst = "a gtool_history (by GFD Dennou Club) user"
534  endif
535  call put_attr(hst % dimvars(i), '+Conventions', trim(x_conv))
536  if (gtver_add) then
537  call put_attr(hst % dimvars(i), '+gt_version', trim(x_gtver))
538  endif
539  ! title, source, institution, history, long_name, units 属性の付加
540  call put_attr(hst % dimvars(i), '+title', title)
541  call put_attr(hst % dimvars(i), '+source', source)
542  call put_attr(hst % dimvars(i), '+institution', trim(x_inst))
543  call put_attr(hst % dimvars(i), '+history', trim(nc_history))
544  call put_attr(hst % dimvars(i), 'long_name', trim(longnames(i)))
545  call put_attr(hst % dimvars(i), 'units', trim(units(i)))
546  if (dimsizes(i) == 0) then
547  hst % unlimited_index = i
548  hst % unlimited_units = units(i)
549  end if
550  enddo
551  ! 従属変数表の初期化
552  ! Initialize table of dependent variables
553  !
554  nullify(hst % vars, hst % growable_indices, hst % count)
555  ! 時刻の単位
556  !
557  if ( hst % unlimited_index == 0 ) then
558  hst % unlimited_units_symbol = unit_symbol_sec
559  else
560  blank_index = index( trim( adjustl(hst % unlimited_units) ), ' ' )
561  if ( blank_index > 1 ) then
562  hst % unlimited_units = hst % unlimited_units(1:blank_index-1)
563  end if
564  hst % unlimited_units_symbol = parsetimeunits( hst % unlimited_units )
565  if ( hst % unlimited_units_symbol == unit_symbol_err ) then
566  call messagenotify('W', subname, &
567  & 'units of time (%c) can not be recognized as units of time. ' // &
568  & 'This units is treated as (%c)', &
569  & c1 = trim(hst % unlimited_units), c2 = 'sec')
570  hst % unlimited_units_symbol = unit_symbol_sec
571  end if
572  end if
573  ! 時間カウンタ
574  !
575  if ( present(interval) ) then
576  hst % interval = interval
577  elseif ( present(intervald) ) then
578  hst % interval = intervald
579  else
580  hst % interval = 1.0
581  end if
582  if ( present (origin) ) then
583  hst % origin = origin
584  hst % origin_setting = .true.
585  elseif( present(origind) ) then
586  hst % origin = origind
587  hst % origin_setting = .true.
588  else
589  hst % origin = 0.0
590  hst % origin_setting = .false.
591  end if
592  origin_str = trim( tochar( hst % origin ) ) // &
593  & ' [' // trim( hst % unlimited_units ) // ']'
594  hst % newest = hst % origin
595  hst % oldest = hst % origin
596  ! 時間平均値出力に関するデフォルト設定
597  ! Default settings for time-averaged value output
598  !
599  hst % time_bnds = hst % origin
600  hst % time_bnds_output_count = 0
601  ! メッセージ出力
602  ! Output messages
603  !
604  if ( .not. present_and_true(quiet) ) then
605  call messagenotify('M', subname, &
606  & '"%c" is created (origin=%c)', &
607  & c1 = trim( file_work ), &
608  & c2 = trim( origin_str ), rank_mpi = -1 )
609  end if
610  ! 終了処理, 例外処理
611  ! Termination and Exception handling
612  !
613  hst % initialized = .true.
614 999 continue
615  call storeerror(stat, subname, err, cause_c=cause_c)
616  call endsub(subname, 'stat=%d', i = (/stat/) )
617  end subroutine historycreate1
618  !-------------------------------------------------------------------
619  subroutine historycreate2( &
620  & file, title, source, institution, &
621  & dims, dimsizes, longnames, units, origin, interval, &
622  & xtypes, history, conventions, gt_version, overwrite, quiet, &
623  & flag_mpi_gather, flag_mpi_split, err )
624  !
625  !== gtool4 データ出力用初期設定
626  !
627  ! このサブルーチンは、gtool4 データ出力の初期設定を行います。
628  ! HistoryAddVariable、 HistoryCopyVariable、 HistoryPut、
629  ! HistoryAddAttr、 HistoryClose、 HistorySetTime
630  ! を用いるためには、HistoryCreate による初期設定が必要です。
631  !
632  ! なお、プログラム内で HistoryCreate を呼び出した場合、
633  ! プログラムを終了する前に必ず、 HistoryClose を呼び出して
634  ! 終了処理を行なって下さい。
635  !
636  ! *HistoryCreate* というサブルーチン名は 2 つの別々の
637  ! サブルーチンの総称名です。上記のサブルーチンも参照ください。
638  !
639  !
640  ! Two specific subroutines shares common part:
641  !
642  ! Both two ones initializes a dataset *file*.
643  ! The result of type GT_HISTORY will be returned by *history*
644  ! or managed internally if omitted.
645  ! Mandatory global attributes are defined by arguments
646  ! *title*, *source*, and *institution*;
647  ! they are all declared as ((character(len = *))).
648  ! Spatial axis definitions have two different forms:
649  ! a primitive one uses several arrays of various types:
650  ! *dims*, *dimsizes*, *longnames*, *units*, and *xtypes*.
651  ! Another sophisticated one has only array of type GT_HISTORY_AXIS,
652  ! *axes*.
653  ! Temporal definition is done without *origin*, *interval*.
654  !
656  use dc_trace, only: beginsub, endsub, dbgmessage
658  use dc_string, only: joinchar, tochar, stoa
659  use dc_url, only: urlmerge
661  use dc_types, only: string, token, dp
662  use dc_message, only: messagenotify
663  use sysdep, only: sysdepenvget
665  use dc_date, only: dcdatetimecreate, tochar, dcdifftimecreate, &
666  & evalbyunit, parsetimeunits
670  implicit none
671  character(*), intent(in):: file
672  ! 出力するファイルの名前.
673  ! Name of output file
674  character(*), intent(in):: title
675  ! データ全体の表題.
676  ! Title of entire data
677  character(*), intent(in):: source
678  ! データを作成する際の手段.
679  ! Source of data file
680  character(*), intent(in):: institution
681  ! ファイルを最終的に変更した組織/個人.
682  ! Institution or person that changes files for the last time
683  character(*), intent(in):: dims(:)
684  ! 次元の名前.
685  !
686  ! 配列の大きさに制限はありません.
687  ! 個々の次元の文字数は dc_types#TOKEN まで.
688  ! 配列内の文字数は
689  ! 全て同じでなければなりません.
690  ! 足りない文字分は空白で
691  ! 補ってください.
692  !
693  ! Names of dimensions.
694  !
695  ! Length of array is unlimited.
696  ! Limits of numbers of characters of each
697  ! dimensions are "dc_types#TOKEN".
698  ! Numbers of characters in this array
699  ! must be same.
700  ! Make up a deficit with blanks.
701  !
702  integer, intent(in):: dimsizes (:)
703  ! dims で指定したそれぞれの次元大きさ.
704  !
705  ! 配列の大きさは dims の大きさと等しい
706  ! 必要があります. '0' (数字のゼロ) を指定
707  ! するとその次元は 無制限次元 (unlimited
708  ! dimension) となります. (gtool_history
709  ! では時間の次元に対して無制限次元を
710  ! 用いることを想定しています). ただし,
711  ! 1 つの NetCDF ファイル (バージョン 3)
712  ! は最大で 1 つの無制限次元しか持てないので,
713  ! 2 ヶ所以上に '0' を指定しないでください.
714  ! その場合, 正しく gtool4 データが出力されません.
715  !
716  ! Lengths of dimensions specified with "dims".
717  !
718  ! Length of this array must be same as
719  ! length of "dim". If '0' (zero) is
720  ! specified, the dimension is treated as
721  ! unlimited dimension.
722  ! (In "gtool_history", unlimited dimension is
723  ! expected to be used as time).
724  ! Note that one NetCDF file (version 3)
725  ! can not have two or more unlimited
726  ! dimensions, so that do not specify '0'
727  ! to two or more places. In that case,
728  ! gtoo4 data is not output currently
729  !
730  character(*), intent(in):: longnames (:)
731  ! dims で指定したそれぞれの次元の名前.
732  !
733  ! 配列の大きさは dims の大きさ
734  ! と等しい必要があります. 文字数
735  ! は dc_types#STRING まで.
736  ! 配列内の文字数は
737  ! 全て同じでなければなりません.
738  ! 足りない文字分は空白で補います.
739  !
740  ! Names of dimensions specified with "dims".
741  !
742  ! Length of this array must be same as
743  ! length of "dim".
744  ! Limits of numbers of characters are
745  ! "dc_types#STRING".
746  ! Numbers of characters in this array
747  ! must be same.
748  ! Make up a deficit with blanks.
749  !
750  character(*), intent(in):: units(:)
751  ! dims で指定したそれぞれの次元の単位.
752  !
753  ! 配列の大きさは dims の大きさ
754  ! と等しい必要があります. 文字数
755  ! は dc_types#STRING まで.
756  ! 配列内の文字数は
757  ! 全て同じでなければなりません.
758  ! 足りない文字分は空白で補います.
759  !
760  ! Units of dimensions specified with "dims".
761  !
762  ! Length of this array must be same as
763  ! length of "dim".
764  ! Limits of numbers of characters are
765  ! "dc_types#STRING".
766  ! Numbers of characters in this array
767  ! must be same.
768  ! Make up a deficit with blanks.
769  !
770  type(dc_difftime), intent(in):: origin
771  ! 時間の原点.
772  !
773  ! これは HistoryPut により変数を最初に
774  ! 出力するときの時間となります.
775  !
776  ! 省略した場合, 時間の原点には
777  ! 自動的に 0.0 が設定されます.
778  !
779  ! Origin of time.
780  !
781  ! This time is used as time
782  ! when first output is done by "HistoryPut".
783  !
784  ! If this argument is omitted,
785  ! 0.0 is specified automatically.
786  !
787  type(dc_difftime), intent(in), optional:: interval
788  ! 出力時間間隔.
789  !
790  ! 同じ変数に対して HistoryPut が複数回
791  ! 呼ばれた時に, 自動的に時間変数がこの値
792  ! だけ増やされて出力されます. なお,
793  ! 各々の出力ファイルにつき HistorySetTime
794  ! を一度でも用いた場合, この値は無効に
795  ! なるので注意してください.
796  !
797  ! 省略した場合, 自動的に 1.0 が設定されます.
798  !
799  ! Interval of output time.
800  !
801  ! When "HistoryPut" is called two or
802  ! more times for the same variable, time
803  ! is increased as this value and
804  ! output automatically.
805  ! Note that this value becomes
806  ! invalid when "HistorySetTime" is
807  ! used for each output file even once.
808  !
809  ! If this argument is omitted,
810  ! 1.0 is specified automatically.
811  !
812  character(*), intent(in), optional:: xtypes(:)
813  ! dims で指定したそれぞれの
814  ! 次元のデータ型.
815  !
816  ! デフォルトは float (単精度実数型)
817  ! です. 有効なのは,
818  ! double (倍精度実数型),
819  ! int (整数型) です. 指定しない
820  ! 場合や, 無効な型を指定した場合には,
821  ! float となります. なお, 配列の大きさ
822  ! は *dims* の大きさと等しい必要が
823  ! あります. 配列内の文字数は全て
824  ! 同じでなければなりません.
825  ! 足りない文字分は空白で補います.
826  !
827  ! Data types of dimensions specified
828  ! with "dims".
829  !
830  ! Default value is "float" (single precision).
831  ! Other valid values are
832  ! "double" (double precision),
833  ! "int" (integer).
834  ! If no value or invalid value is specified,
835  ! "float" is applied.
836  ! Length of this array must be same as
837  ! length of "dim".
838  ! Numbers of characters in this array
839  ! must be same.
840  ! Make up a deficit with blanks.
841  !
842  type(gt_history), intent(out), optional, target:: history
843  ! 出力ファイルの設定に関する情報を
844  ! 格納した構造体.
845  !
846  ! 1 つのプログラムで複数のファイル
847  ! に gtool データを出力する
848  ! 場合に利用します.
849  ! (単独のファイルに書き出す場合は
850  ! 指定する必要はありません)
851  !
852  ! Derived type that
853  ! stores information about output files.
854  !
855  ! If multiple gtool4 data files are
856  ! output from one program, use this
857  ! argument.
858  ! (If onlye one file is output,
859  ! this argument is not needed).
860  !
861  character(*), intent(in), optional:: conventions
862  ! 出力するファイルの netCDF
863  ! 規約
864  !
865  ! 省略した場合,
866  ! もしくは空文字を与えた場合,
867  ! 出力する netCDF 規約の
868  ! Conventions 属性に値
869  ! gtool4_netCDF_Conventions
870  ! が自動的に与えられます.
871  !
872  ! NetCDF conventions of output file.
873  !
874  ! If this argument is omitted or,
875  ! blanks are given,
876  ! gtool4_netCDF_Conventions is given to
877  ! attribute "Conventions" of an output file
878  ! automatically.
879  !
880  character(*), intent(in), optional:: gt_version
881  ! gtool4 netCDF 規約のバージョン
882  !
883  ! 省略した場合, gt_version 属性に
884  ! 規約の最新版のバージョンナンバー
885  ! gtool4_netCDF_version
886  ! が与えられます.
887  ! (ただし, 引数 conventions に
888  ! gtool4_netCDF_Conventions
889  ! 以外が与えられる場合は
890  ! gt_version 属性を作成しません).
891  !
892  ! Version of gtool4 netCDF Conventions.
893  !
894  ! If this argument is omitted,
895  ! latest version number of gtool4 netCDF
896  ! Conventions is given to attribute
897  ! "gt_version" of an output file
898  ! (However, gtool4_netCDF_Conventions is
899  ! not given to an argument "conventions",
900  ! attribute "gt_version" is not created).
901  !
902  logical, intent(in), optional:: overwrite
903  ! 上書き可否
904  !
905  ! この引数に .false. を渡すと,
906  ! 既存のファイルを上書きしません.
907  ! デフォルトは上書きします.
908  !
909  ! Whether or not to overwrite.
910  !
911  ! If .false. is specified to this
912  ! argument, an existing file is not
913  ! overwritten.
914  ! By default, existing file is overwritten.
915  !
916  logical, intent(in), optional:: quiet
917  ! .true. を与えた場合,
918  ! メッセージ出力が抑制されます.
919  ! デフォルトは .false. です.
920  !
921  ! If ".true." is given,
922  ! messages are suppressed.
923  ! Default value is ".false.".
924  !
925  logical, intent(in), optional:: flag_mpi_gather
926  ! MPI 使用時に, 各ノードで HistoryPut
927  ! に与えたデータを一つのファイルに統合して出力
928  ! する場合には .true. を与えてください.
929  ! デフォルトは .false. です.
930  !
931  ! .true. を与えた場合, HistoryPutAxisMPI
932  ! に全体の軸データを与えてください.
933  !
934  ! When MPI is used, if ".true." is given,
935  ! data given to "HistoryPut" on each node
936  ! is integrated and output to one file.
937  ! Default value is ".false.".
938  !
939  ! If .true. is given, give data of axes in
940  ! whole area to "HistoryPutAxisMPI"
941  !
942  logical, intent(in), optional:: flag_mpi_split
943  ! MPI 使用時にこの引数に .true. を与えると,
944  ! 各ノードごとに
945  ! *file* 引数に "_rankXXXXXX"
946  ! (X は [0-9] の数値で, ノード番号を指す)
947  ! を付加したファイルを出力します.
948  ! 例えば, *file* に "output.nc" を与えた場合.
949  ! ノード 0 では "output_rank000000.nc",
950  ! ノード 12 では "output_rank000012.nc"
951  ! を出力します.
952  ! デフォルトは .false. です.
953  !
954  ! When MPI is used, if ".true." is given,
955  ! files that have names with suffixes
956  ! "_rankXXXXXX"
957  ! (X is [0-9] that indicates node number)
958  ! are output on each node.
959  ! For example, "output.nc" is given to *file*,
960  ! "output_rank000000.nc", "output_rank000012.nc"
961  ! are output on node 0 and node 12.
962  ! Default value is ".false.".
963  !
964  logical, intent(out), optional:: err
965  ! 例外処理用フラグ.
966  ! デフォルトでは, この手続き内でエラーが
967  ! 生じた場合, プログラムは強制終了します.
968  ! 引数 *err* が与えられる場合,
969  ! プログラムは強制終了せず, 代わりに
970  ! *err* に .true. が代入されます.
971  !
972  ! Exception handling flag.
973  ! By default, when error occur in
974  ! this procedure, the program aborts.
975  ! If this *err* argument is given,
976  ! .true. is substituted to *err* and
977  ! the program does not abort.
978  type(gt_history), pointer:: hst =>null()
979  real(DP):: origind, intervald
980  integer:: i, numdims, blank_index
981  character(TOKEN):: unlimited_units
982  integer:: unit_symbol
983  integer:: stat
984  character(STRING):: cause_c
985  character(*), parameter:: subname = "HistoryCreate2"
986  character(*), parameter:: version = &
987  & '$Name: $' // &
988  & '$Id: historycreate.rb2f90,v 1.4 2009-11-03 05:22:46 morikawa Exp $'
989  continue
990  call beginsub(subname, 'file=%c ndims=%d', &
991  & c1=trim(file), i=(/size(dims)/), &
992  & version=version)
993  stat = dc_noerr
994  cause_c = ""
995  numdims = size(dims)
996  unlimited_units = 'sec'
997  do, i = 1, numdims
998  if (dimsizes(i) == 0) unlimited_units = units(i)
999  end do
1000  blank_index = index( trim( adjustl(unlimited_units) ), ' ' )
1001  if ( blank_index > 1 ) then
1002  unlimited_units = unlimited_units(1:blank_index-1)
1003  end if
1004  unit_symbol = parsetimeunits( unlimited_units )
1005  if ( unit_symbol == unit_symbol_err ) unit_symbol = unit_symbol_sec
1006  if (present(interval)) then
1007  intervald = evalbyunit( interval, '', unit_symbol )
1008  else
1009  intervald = 1.0_dp
1010  end if
1011  origind = evalbyunit( origin, '', unit_symbol )
1012  call historycreate( &
1013  & file = file, title = title, &
1014  & source = source, institution = institution, &
1015  & dims = dims, dimsizes = dimsizes, &
1016  & longnames = longnames, units = units, &
1017  & xtypes = xtypes, history = history, &
1018  & origind = origind, intervald = intervald, &
1019  & conventions = conventions, gt_version = gt_version, &
1020  & overwrite = overwrite, quiet = quiet, &
1021  & flag_mpi_gather = flag_mpi_gather, flag_mpi_split = flag_mpi_split, &
1022  & err = err )
1023  if (present(history)) then
1024  hst => history
1025  else
1026  hst => default
1027  endif
1028 999 continue
1029  call storeerror(stat, subname, cause_c=cause_c)
1030  call endsub(subname, 'stat=%d', i = (/stat/) )
1031  end subroutine historycreate2
1032  !-------------------------------------------------------------------
1033  subroutine historycreate3(file, title, source, institution, &
1034  & axes, origin, interval, history, origind, intervald, conventions, gt_version, &
1035  & overwrite, quiet, flag_mpi_gather, flag_mpi_split, err )
1036  !
1037  !== gtool4 データ出力用初期設定
1038  !
1039  ! *HistoryCreate* というサブルーチン名は 2 つの別々の
1040  ! サブルーチンの総称名です。まずは HistoryCreate を参照ください。
1041  !
1042  ! もう 1 つのサブルーチンと異なる点は、座標軸の情報を
1043  ! *dims*, *dimsizes*, *longnames*, *units*, and *xtypes* といった
1044  ! 個別の引数で与えるのではなく、構造体 GT_HISTORY_AXIS 型の
1045  ! 引数 *axes* で与える点にあります。
1046  !
1047  ! GT_HISTORY_AXIS 型変数の生成 (constructer) は
1048  ! HistoryAxisCreate にて行います。
1049  !
1050  !
1051  ! Two specific subroutines shares common part:
1052  !
1053  ! Both two ones initializes a dataset *file*.
1054  ! The result of type GT_HISTORY will be returned by *history*
1055  ! or managed internally if omitted.
1056  ! Mandatory global attributes are defined by arguments
1057  ! *title*, *source*, and *institution*;
1058  ! they are all declared as ((character(len = *))).
1059  ! Spatial axis definitions have two different forms:
1060  ! a primitive one uses several arrays of various types:
1061  ! *dims*, *dimsizes*, *longnames*, *units*, and *xtypes*.
1062  ! Another sophisticated one has only array of type GT_HISTORY_AXIS,
1063  ! *axes*.
1064  ! Temporal definition is done without *origin*, *interval*.
1065  !
1066  use dc_types, only: string, token, dp
1067  use dc_present, only: present_and_true
1068  use dc_trace, only: beginsub, endsub, dbgmessage
1072  implicit none
1073  character(*), intent(in):: file
1074  ! HistoryCreate 参照
1075  ! (以下 axes を除く引数も同様)
1076  !
1077  character(*), intent(in):: title, source, institution
1078  type(gt_history_axis), intent(in):: axes(:)
1079  ! 次元情報を格納した構造型変数
1080  !
1081  ! GT_HISTORY_AXIS 型変数の生成
1082  ! (constructer) は
1083  ! HistoryAxisCreate にて行いま
1084  ! す。配列の大きさに制限は
1085  ! ありません。
1086  !
1087  real, intent(in), optional:: origin, interval
1088  type(gt_history), intent(out), optional, target:: history
1089  real(DP), intent(in), optional:: origind, intervald
1090  character(*), intent(in), optional:: conventions, gt_version
1091  logical, intent(in), optional:: overwrite
1092  logical, intent(in), optional:: quiet
1093  ! .true. を与えた場合,
1094  ! メッセージ出力が抑制されます.
1095  ! デフォルトは .false. です.
1096  !
1097  ! If ".true." is given,
1098  ! messages are suppressed.
1099  ! Default value is ".false.".
1100  !
1101  logical, intent(in), optional:: flag_mpi_gather
1102  ! MPI 使用時に, 各ノードで HistoryPut
1103  ! に与えたデータを一つのファイルに統合して出力
1104  ! する場合には .true. を与えてください.
1105  ! デフォルトは .false. です.
1106  !
1107  ! .true. を与えた場合, HistoryPutAxisMPI
1108  ! に全体の軸データを与えてください.
1109  !
1110  ! When MPI is used, if ".true." is given,
1111  ! data given to "HistoryPut" on each node
1112  ! is integrated and output to one file.
1113  ! Default value is ".false.".
1114  !
1115  ! If .true. is given, give data of axes in
1116  ! whole area to "HistoryPutAxisMPI"
1117  !
1118  logical, intent(in), optional:: flag_mpi_split
1119  ! MPI 使用時にこの引数に .true. を与えると,
1120  ! 各ノードごとに
1121  ! *file* 引数に "_rankXXXXXX"
1122  ! (X は [0-9] の数値で, ノード番号を指す)
1123  ! を付加したファイルを出力します.
1124  ! 例えば, *file* に "output.nc" を与えた場合.
1125  ! ノード 0 では "output_rank000000.nc",
1126  ! ノード 12 では "output_rank000012.nc"
1127  ! を出力します.
1128  ! デフォルトは .false. です.
1129  !
1130  ! When MPI is used, if ".true." is given,
1131  ! files that have names with suffixes
1132  ! "_rankXXXXXX"
1133  ! (X is [0-9] that indicates node number)
1134  ! are output on each node.
1135  ! For example, "output.nc" is given to *file*,
1136  ! "output_rank000000.nc", "output_rank000012.nc"
1137  ! are output on node 0 and node 12.
1138  ! Default value is ".false.".
1139  !
1140  logical, intent(out), optional:: err
1141  ! 例外処理用フラグ.
1142  ! デフォルトでは, この手続き内でエラーが
1143  ! 生じた場合, プログラムは強制終了します.
1144  ! 引数 *err* が与えられる場合,
1145  ! プログラムは強制終了せず, 代わりに
1146  ! *err* に .true. が代入されます.
1147  !
1148  ! Exception handling flag.
1149  ! By default, when error occur in
1150  ! this procedure, the program aborts.
1151  ! If this *err* argument is given,
1152  ! .true. is substituted to *err* and
1153  ! the program does not abort.
1154  ! 構造体 GT_HISTORY_AXIS のデータ蓄積用
1155  character(STRING), allocatable:: axes_name(:)
1156  integer , allocatable:: axes_length(:)
1157  character(STRING), allocatable:: axes_longname(:)
1158  character(STRING), allocatable:: axes_units(:)
1159  character(STRING), allocatable:: axes_xtype(:)
1160  integer:: i, ndims
1161  character(len = *), parameter:: subname = "HistoryCreate3"
1162  continue
1163  call beginsub(subname, 'file=%c ndims=%d', &
1164  & c1=trim(file), i=(/size(axes)/) )
1165  ! 構造体 GT_HISTORY_AXIS の axes からのデータ取得
1166  ! (Fujitsu Fortran などなら axes(:)%name という表記で配列
1167  ! データをそのまま引き渡せるが、Intel Fortran 8 などだと
1168  ! その表記をまともに解釈してくれないので、美しくないけど
1169  ! いったん他の配列に情報を引き渡す)。2004/11/27 morikawa
1170  ndims = size( axes(:) )
1171  allocate( axes_name(ndims) )
1172  allocate( axes_length(ndims) )
1173  allocate( axes_longname(ndims) )
1174  allocate( axes_units(ndims) )
1175  allocate( axes_xtype(ndims) )
1176  do i = 1, ndims
1177  axes_name(i) = axes(i) % name
1178  axes_length(i) = axes(i) % length
1179  axes_longname(i) = axes(i) % longname
1180  axes_units(i) = axes(i) % units
1181  axes_xtype(i) = axes(i) % xtype
1182  call dbgmessage('axes(%d):name=<%c>, length=<%d>, ' // &
1183  & 'longname=<%c>, units=<%c>' , &
1184  & i=(/i, axes(i) % length/) , &
1185  & c1=( trim(axes(i) % name) ) , &
1186  & c2=( trim(axes(i) % longname) ) , &
1187  & c3=( trim(axes(i) % units) ) )
1188  enddo
1189  call historycreate(file, title, source, institution, &
1190  & dims = axes_name(:), dimsizes = axes_length(:), &
1191  & longnames = axes_longname(:), units = axes_units(:), &
1192  & xtypes = axes_xtype(:), &
1193  & origin = origin, interval = interval, &
1194  & history = history, &
1195  & origind = origind, intervald = intervald, &
1196  & conventions = conventions, &
1197  & gt_version = gt_version, overwrite = overwrite, quiet = quiet, &
1198  & flag_mpi_gather = flag_mpi_gather, &
1199  & flag_mpi_split = flag_mpi_split, &
1200  & err = err )
1201  deallocate( axes_name )
1202  deallocate( axes_length )
1203  deallocate( axes_longname )
1204  deallocate( axes_units )
1205  deallocate( axes_xtype )
1206  do i = 1, ndims
1207  if ( .not. associated( axes(i) % attrs ) ) cycle
1208  call append_attrs( axes(i) % name, axes(i) % attrs, history )
1209  end do
1210  call endsub(subname)
1211  end subroutine historycreate3
1212 !--
1213 ! vi:set readonly sw=4 ts=8:
1214 !
1215 !Local Variables:
1216 !mode: f90
1217 !buffer-read-only: t
1218 !End:
1219 !
1220 !++
type(gt_history), target, save, public default
integer, parameter, public unit_symbol_err
integer, parameter, public token
単語やキーワードを保持する文字型変数の種別型パラメタ
Definition: dc_types.f90:109
logical function, public present_and_true(arg)
Definition: dc_present.f90:80
character(string), parameter, public gtool4_netcdf_version
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
logical function, public present_and_false(arg)
Definition: dc_present.f90:99
subroutine historycreate1(file, title, source, institution, dims, dimsizes, longnames, units, origin, interval, xtypes, history, origind, intervald, conventions, gt_version, overwrite, quiet, flag_mpi_gather, flag_mpi_split, err)
subroutine historycreate3(file, title, source, institution, axes, origin, interval, history, origind, intervald, conventions, gt_version, overwrite, quiet, flag_mpi_gather, flag_mpi_split, err)
character(string) function, public joinchar(carray, expr)
Definition: dc_string.f90:861
integer, parameter, public dp
倍精度実数型変数
Definition: dc_types.f90:83
subroutine, public dbgmessage(fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:509
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
integer, parameter, public unit_symbol_sec
subroutine historycreate2(file, title, source, institution, dims, dimsizes, longnames, units, origin, interval, xtypes, history, conventions, gt_version, overwrite, quiet, flag_mpi_gather, flag_mpi_split, err)
character(string), parameter, public gtool4_netcdf_conventions
subroutine sysdepenvget(env, str)
Definition: sysdepenv.f90:33
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446
integer, parameter, public dc_ealreadyinit
Definition: dc_error.f90:558
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118