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