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 )
75 & dccalcreate, dccaldatecurrent, dccaldateinquire
77 use dc_date,
only: dcdatetimecreate,
tochar, dcdifftimecreate, &
78 & evalbyunit, parsetimeunits
82 character(*),
intent(in):: file
85 character(*),
intent(in):: title
88 character(*),
intent(in):: source
91 character(*),
intent(in):: institution
94 character(*),
intent(in):: dims(:)
113 integer,
intent(in):: dimsizes (:)
141 character(*),
intent(in):: longnames (:)
161 character(*),
intent(in):: units(:)
181 real,
intent(in),
optional:: origin
198 real,
intent(in),
optional:: interval
223 character(*),
intent(in),
optional:: xtypes(:)
253 type(
gt_history),
intent(out),
optional,
target:: history
272 real(DP),
intent(in),
optional:: origind
281 real(DP),
intent(in),
optional:: intervald
290 character(*),
intent(in),
optional:: conventions
309 character(*),
intent(in),
optional:: gt_version
331 logical,
intent(in),
optional:: overwrite
345 logical,
intent(in),
optional:: quiet
354 logical,
intent(in),
optional:: flag_mpi_gather
371 logical,
intent(in),
optional:: flag_mpi_split
393 logical,
intent(out),
optional:: err
407 integer:: numdims, i, stat, blank_index
409 character(TOKEN):: my_xtype, origin_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 = &
423 &
'$Id: historycreate.rb2f90,v 1.4 2009-11-03 05:22:46 morikawa Exp $'
425 call beginsub(subname,
'file=%c ndims=%d', &
426 & c1=trim(file), i=(/
size(dims)/), &
431 &
'dims(:)=%a, dimsizes(:)=%a, longnames(:)=%a, units(:)=%a', &
434 if (
present(history))
then
442 if ( hst % initialized )
then
444 cause_c =
'GT_HISTORY'
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'
458 if ( trim(cause_c) /=
"" )
then
465 allocate(hst % dimvars(numdims))
466 allocate(hst % dim_value_written(numdims))
467 hst % dim_value_written(:) = .false.
468 hst % unlimited_index = 0
473 if (trim(username) ==
'') username =
'unknown'
477 call dccaldatecurrent( now_date )
478 call dccalcreate(
'gregorian', cal_standard )
479 call dccaldateinquire( now_date_str, date = now_date, cal = cal_standard )
481 nc_history = trim(now_date_str) //
' ' // &
482 & trim(username) // &
483 &
'> gtool_history: HistoryCreate' // &
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
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)
506 if ( hst % mpi_split )
then
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 )
516 file_mpi = trim( file_mpi ) // trim( myrank_str_mpi )
525 if (
present(xtypes) )
then
526 if (
size(xtypes) >= i )
then
527 my_xtype =
cprintft(
'%c', c1=xtypes(i))
530 if ( hst % mpi_split )
then
531 url =
urlmerge(file=file_mpi, var=dims(i))
533 url =
urlmerge(file=file, var=dims(i))
535 overwrite_required = .true.
537 if ( .not. hst % mpi_gather )
then
539 & hst % dimvars(i), trim(url), &
540 & dimsizes(i), xtype=trim(my_xtype), &
541 & overwrite=overwrite_required)
565 if (trim(institution) /=
"")
then
568 x_inst =
"a gtool_history (by GFD Dennou Club) user"
570 call put_attr(hst % dimvars(i),
'+Conventions', trim(x_conv))
572 call put_attr(hst % dimvars(i),
'+gt_version', trim(x_gtver))
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)))
583 if (
present(xtypes) )
then
584 if (
size(xtypes) >= i )
then
585 my_xtype =
cprintft(
'%c', c1=xtypes(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.
595 & hst % mpi_fileinfo % overwrite = .false.
597 hst % mpi_fileinfo % conventions = conventions
602 hst % mpi_fileinfo % gt_version =
cprintft(
'%c', c1=gt_version)
603 hst % mpi_fileinfo % gtver_add = .true.
607 hst % mpi_fileinfo % gtver_add = .false.
610 hst % mpi_fileinfo % gtver_add = .true.
613 if (trim(institution) /=
"")
then
614 hst % mpi_fileinfo % institution = institution
616 hst % mpi_fileinfo % institution =
"a gtool_history (by GFD Dennou Club) user"
618 hst % mpi_fileinfo % quiet = .false.
620 hst % mpi_fileinfo % nc_history = nc_history
622 if (dimsizes(i) == 0)
then
623 hst % unlimited_index = i
624 hst % unlimited_units = units(i)
630 nullify(hst % vars, hst % growable_indices, hst % count)
633 if ( hst % unlimited_index == 0 )
then
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)
640 hst % unlimited_units_symbol = parsetimeunits( hst % unlimited_units )
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')
651 if (
present(interval) )
then
652 hst % interval = interval
653 elseif (
present(intervald) )
then
654 hst % interval = intervald
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.
666 hst % origin_setting = .false.
668 origin_str = trim(
tochar( hst % origin ) ) // &
669 &
' [' // trim( hst % unlimited_units ) //
']'
670 hst % newest = hst % origin
671 hst % oldest = hst % origin
675 hst % time_bnds = hst % origin
676 hst % time_bnds_output_count = 0
680 if ( .not. hst % mpi_gather )
then
683 &
'"%c" is created (origin=%c)', &
684 & c1 = trim( file_work ), &
685 & c2 = trim( origin_str ), rank_mpi = -1 )
691 hst % initialized = .true.
693 call storeerror(stat, subname, err, cause_c=cause_c)
694 call endsub(subname,
'stat=%d', i = (/stat/) )
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 )
734 use dc_date,
only: dcdatetimecreate, tochar, dcdifftimecreate, &
735 & evalbyunit, parsetimeunits
740 character(*),
intent(in):: file
743 character(*),
intent(in):: title
746 character(*),
intent(in):: source
749 character(*),
intent(in):: institution
752 character(*),
intent(in):: dims(:)
771 integer,
intent(in):: dimsizes (:)
799 character(*),
intent(in):: longnames (:)
819 character(*),
intent(in):: units(:)
881 character(*),
intent(in),
optional:: xtypes(:)
911 type(
gt_history),
intent(out),
optional,
target:: history
930 character(*),
intent(in),
optional:: conventions
949 character(*),
intent(in),
optional:: gt_version
971 logical,
intent(in),
optional:: overwrite
985 logical,
intent(in),
optional:: quiet
994 logical,
intent(in),
optional:: flag_mpi_gather
1011 logical,
intent(in),
optional:: flag_mpi_split
1033 logical,
intent(out),
optional:: err
1048 real(DP):: origind, intervald
1049 integer:: i, numdims, blank_index
1050 character(TOKEN):: unlimited_units
1051 integer:: unit_symbol
1053 character(STRING):: cause_c
1054 character(*),
parameter:: subname =
"HistoryCreate2"
1055 character(*),
parameter:: version = &
1057 &
'$Id: historycreate.rb2f90,v 1.4 2009-11-03 05:22:46 morikawa Exp $'
1059 call beginsub(subname,
'file=%c ndims=%d', &
1060 & c1=trim(file), i=(/
size(dims)/), &
1064 numdims =
size(dims)
1065 unlimited_units =
'sec'
1067 if (dimsizes(i) == 0) unlimited_units = units(i)
1069 blank_index = index( trim( adjustl(unlimited_units) ),
' ' )
1070 if ( blank_index > 1 )
then
1071 unlimited_units = unlimited_units(1:blank_index-1)
1073 unit_symbol = parsetimeunits( unlimited_units )
1075 if (
present(interval))
then
1076 intervald = evalbyunit( interval,
'', unit_symbol )
1080 origind = evalbyunit( origin,
'', unit_symbol )
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, &
1092 if (
present(history))
then
1097 call storeerror(stat, subname, cause_c=cause_c)
1098 call endsub(subname,
'stat=%d', i = (/stat/) )
1102 & axes, origin, interval, history, origind, intervald, conventions, gt_version, &
1103 & overwrite, quiet, flag_mpi_gather, flag_mpi_split, err )
1138 character(*),
intent(in):: file
1142 character(*),
intent(in):: title, source, institution
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
1166 logical,
intent(in),
optional:: flag_mpi_gather
1183 logical,
intent(in),
optional:: flag_mpi_split
1205 logical,
intent(out),
optional:: err
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(:)
1228 character(len = *),
parameter:: subname =
"HistoryCreate3"
1230 call beginsub(subname,
'file=%c ndims=%d', &
1231 & c1=trim(file), i=(/
size(axes)/) )
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) )
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) ) )
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, &
1268 deallocate( axes_name )
1269 deallocate( axes_length )
1270 deallocate( axes_longname )
1271 deallocate( axes_units )
1272 deallocate( axes_xtype )
1275 if ( .not.
associated( axes(i) % attrs ) ) cycle
1276 call append_attrs( axes(i) % name, axes(i) % attrs, history )
1279 if (
present(history))
then
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 ) )
1289 & to = hst % mpi_dimdata_all(i) % attrs )
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 データ出力用初期設定