gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
gtool_historyauto_internal::hstfilecreate Interface Reference

Public Member Functions

subroutine hstfilecreate (gthist, varname, time)

Detailed Description

Definition at line 340 of file gtool_historyauto_internal.f90.

Constructor & Destructor Documentation

◆ hstfilecreate()

subroutine gtool_historyauto_internal::hstfilecreate::hstfilecreate ( type(gt_history), intent(inout) gthist,
character(*), intent(in) varname,
real(dp), intent(in) time )

ファイル作成用内部サブルーチン.

Parameters
[in,out]gthistgtool_history モジュール用構造体.
[in]varname変数の名前.
[in]time現在時刻.

Definition at line 645 of file gtool_historyauto_internal.f90.

650 use dc_trace, only: beginsub, endsub
653 use dc_calendar, only: dccalconvertbyunit
654 use dc_date_types, only: dc_difftime
655 use dc_date, only: dcdifftimecreate, evalbyunit
657 use dc_message, only: messagenotify
660 use gtool_history, only: gt_history, &
661 & historycreate, historyaddvariable, historyaddattr, &
662 & historyinitialized, historyput, historyputaxismpi, &
663 & historyaxiscreate, historyaxisinquire, historyaxiscopy, &
664 & historyvarinfoinquire, historyvarinfocreate, &
665 & historyvarinfocopy, historyvarinfoinitialized, &
666 & historyvarinfoclear
667
668 implicit none
669 type(GT_HISTORY), intent(inout):: gthist
670 ! gtool_history モジュール用構造体.
671 ! Derived type for "gtool_history" module
672 character(*), intent(in):: varname
673 ! 変数の名前.
674 ! Variable name
675 real(DP), intent(in):: time
676 ! 現在時刻. Current time
677
678 character(TOKEN):: interval_unit
679 ! データの出力間隔の単位.
680 ! Unit for interval of history data output
681 real(DP):: origin_value
682 ! データの出力開始時刻の数値.
683 ! Numerical value for start time of history data output
684 character(TOKEN):: origin_unit
685 ! データの出力開始時刻の単位.
686 ! Unit for start time of history data output
687
688 real(DP):: origin_sec
689 integer:: newfile_intvalue
690 real(DP):: newfile_intvalued
691 ! ファイル分割時間間隔.
692 ! Interval of time of separation of a file.
693 character(TOKEN):: newfile_intunit
694 ! ファイル分割時間間隔の単位.
695 ! Unit of interval of time of separation of a file.
696
697 character(STRING):: file, file_base, file_suffix, file_newfile_time, file_rank
698 ! 出力ファイル名.
699 ! Output file name.
700 integer:: stat, i, j, k, vnum, numdims_slice, dim_size, cnt
701 character(STRING):: name, units, longname, cause_c, wgt_name
702 character(TOKEN):: xtype
703 type(GT_HISTORY_AXIS):: gthst_axes_time
704 type(GT_HISTORY_AXIS), pointer:: gthst_axes_slices(:) =>null()
705 type(GT_HISTORY_AXIS_DATA), pointer:: data_axes_slices(:) =>null()
706 type(GT_HISTORY_AXIS_DATA), pointer:: data_weights_slices(:) =>null()
707 real(DP):: wgt_sum, wgt_sum_s
708 logical:: slice_valid
709 integer:: slice_start(1:numdims-1)
710 ! 空間方向の開始点.
711 ! Start points of spaces.
712 integer:: slice_end(1:numdims-1)
713 ! 空間方向の終了点.
714 ! End points of spaces.
715 integer:: slice_stride(1:numdims-1)
716 ! 空間方向の刻み幅.
717 ! Strides of spaces
718
719 character(*), parameter:: subname = "HstFileCreate"
720 continue
721 call beginsub(subname, 'varname=%c', c1 = trim(varname) )
722 stat = dc_noerr
723 cause_c = ""
724
725 ! varname から変数情報の探査
726 ! Search information of a variable from "varname"
727 !
728 vnum = 0
729 do i = 1, numvars
730 call historyvarinfoinquire( &
731 & varinfo = gthst_vars(i), & ! (in)
732 & name = name ) ! (out)
733 if ( trim(varname) == trim(name) ) vnum = i
734 end do
735
736 if ( vnum == 0 ) then
737 stat = hst_ebadvarname
738 cause_c = varname
739 goto 999
740 end if
741
742 ! 出力が有効かどうかを確認する
743 ! Confirm whether the output is effective
744 !
745 if ( .not. hstnmlinfooutputvalid( gthstnml, varname ) ) then
746 goto 999
747 end if
748
749 ! 出力間隔の単位に応じて時間座標情報の作り直し
750 ! Remake time axis information correspond to units of output interval
751 !
752 call hstnmlinfoinquire( &
753 & gthstnml = gthstnml, & ! (in)
754 & name = varname, & ! (in)
755 & file = file, & ! (out)
756 & interval_unit = interval_unit ) ! (out)
757
758 call historyaxiscopy( &
759 & gthst_axes_time, & ! (out)
760 & gthst_axes(numdims), & ! (in)
761 & units = trim(interval_unit) // ' ' // &
762 & trim(time_unit_suffix) ) ! (in)
763
764 ! 空間方向のスライスに対応して, 座標および座標重み情報の作り直し
765 ! Remake axes and weights information correspond to spatial slices
766 !
767 call hstnmlinfoinquire( &
768 & gthstnml = gthstnml, & ! (in)
769 & name = varname, & ! (in)
770 & slice_start = slice_start, & ! (out)
771 & slice_end = slice_end, & ! (out)
772 & slice_stride = slice_stride ) ! (out)
773
774 ! ファイルが未作成の場合は, まずファイル作成
775 ! At first, the file is created if the file is not created yet
776 !
777 if ( .not. historyinitialized( gthist ) ) then
778
779 if ( all( slice_start == (/ ( 1, i = 1, numdims -1 ) /) ) &
780 & .and. all( slice_end < (/ ( 1, i = 1, numdims -1 ) /) ) &
781 & .and. all( slice_stride == (/ ( 1, i = 1, numdims -1 ) /) ) ) then
782
783 allocate( gthst_axes_slices(1:numdims) )
784 gthst_axes_slices(1:numdims-1) = gthst_axes(1:numdims-1)
785 gthst_axes_slices(numdims:numdims) = gthst_axes_time
786
787 data_axes_slices => data_axes
788 data_weights_slices => data_weights
789 slice_valid = .false.
790
791 else
792 allocate( gthst_axes_slices(1:numdims) )
793 allocate( data_axes_slices(1:numdims) )
794 allocate( data_weights_slices(1:numdims) )
795
796 do i = 1, numdims-1
797
798 ! スライス値の有効性をチェック
799 ! Check validity of slices
800 !
801 if ( slice_start(i) < 1 ) then
802 stat = hst_ebadslice
803 cause_c = cprintf('slice_start=%d', &
804 & i = (/ slice_start(i) /) )
805 goto 999
806 end if
807
808 if ( slice_stride(i) < 1 ) then
809 stat = hst_ebadslice
810 cause_c = cprintf('slice_stride=%d', &
811 & i = (/ slice_stride(i) /) )
812 goto 999
813 end if
814
815 ! 再生成の必要性をチェック
816 ! Check necessity of remaking
817 !
818 if ( ( slice_start(i) == 1 ) &
819 & .and. ( slice_end(i) < 1 ) &
820 & .and. ( slice_stride(i) == 1 ) ) then
821
822 call historyaxiscopy( &
823 & axis_dest = gthst_axes_slices(i) , & ! (out)
824 & axis_src = gthst_axes(i) ) ! (in)
825
826 data_axes_slices(i) = data_axes(i)
827
828 cycle
829 end if
830
831 ! 座標情報の再生成
832 ! Remake information of axis
833 !
834 call historyaxisinquire( &
835 & axis = gthst_axes(i), & ! (in)
836 & name = name, & ! (out)
837 & size = dim_size, & ! (out)
838 & longname = longname, & ! (out)
839 & units = units, & ! (out)
840 & xtype = xtype ) ! (out)
841
842 ! 終点のスライス値の補正 ; Correct end points of slices
843 if ( slice_end(i) < 1 ) slice_end(i) = dim_size
844 if ( slice_end(i) > dim_size ) then
845 call messagenotify( 'W', subname, &
846 & 'slice options to (%c) are undesirable ' // &
847 & '(@slice_end=%d). @slice_end is corrected forcibly to (%d) ', &
848 & c1 = trim(name), &
849 & i = (/ slice_end(i), dim_size /) )
850
851 slice_end(i) = dim_size
852 end if
853
854 ! スライス値の有効性をチェック ; Check validity of slices
855 if ( slice_start(i) > slice_end(i) ) then
856 stat = hst_ebadslice
857 cause_c = cprintf('slice_start=%d, slice_end=%d', &
858 & i = (/ slice_start(i), slice_end(i) /) )
859 goto 999
860 end if
861
862 numdims_slice = int( ( slice_end(i) - slice_start(i) + 1 ) / slice_stride(i) )
863
864 ! スライス値の有効性をチェック ; Check validity of slices
865 if ( numdims_slice < 1 ) then
866 call messagenotify( 'W', subname, &
867 & 'slice options to (%c) are invalid. ' // &
868 & '(@slice_start=%d @slice_end=%d @slice_stride=%d)', &
869 & c1 = trim(name), &
870 & i = (/ slice_start(i), slice_end(i), slice_stride(i) /) )
871 stat = hst_ebadslice
872 cause_c = cprintf('slice_start=%d, slice_end=%d, slice_stride=%d', &
873 & i = (/ slice_start(i), slice_end(i), slice_stride(i) /) )
874 goto 999
875 end if
876
877 call historyaxiscreate( &
878 & axis = gthst_axes_slices(i), & ! (out)
879 & name = name, & ! (in)
880 & size = numdims_slice, & ! (in)
881 & longname = longname, & ! (in)
882 & units = units, & ! (in)
883 & xtype = xtype ) ! (in)
884
885
886 ! 座標データの再生成
887 ! Regenerate data of axis
888 !
889 allocate( data_axes_slices(i) % a_axis( numdims_slice ) )
890 cnt = 1
891 do j = slice_start(i), slice_end(i), slice_stride(i)
892 data_axes_slices(i) % a_axis( cnt ) = data_axes(i) % a_axis( j )
893 cnt = cnt + 1
894 end do
895
896 ! 座標重みデータの再生成
897 ! Remake information of axis data
898 !
899 do j = 1, numwgts
900 call historyvarinfoinquire( &
901 & varinfo = gthst_weights(j), & ! (in)
902 & name = wgt_name ) ! (out) optional
903
904 if ( trim(name) // wgtsuf == trim(wgt_name) ) then
905
906 ! 座標重みの計算は結構いい加減...
907 ! Calculation about axis weight is irresponsible...
908 !
909 wgt_sum = sum( data_weights(j) % a_axis )
910
911 allocate( data_weights_slices(j) % a_axis( numdims_slice ) )
912 cnt = 1
913 do k = slice_start(i), slice_end(i), slice_stride(i)
914 data_weights_slices(j) % a_axis( cnt ) = data_weights(j) % a_axis( k )
915 cnt = cnt + 1
916 end do
917
918 wgt_sum_s = sum( data_weights_slices(j) % a_axis )
919 data_weights_slices(j) % a_axis = data_weights_slices(j) % a_axis * ( wgt_sum / wgt_sum_s )
920
921 end if
922
923 end do
924
925 end do
926
927 ! 空間切り出しされていない座標に関する座標重みデータを作成
928 ! Make data of axis weight not sliced
929 !
930 do i = 1, numwgts
931 if ( .not. associated( data_weights_slices(i) % a_axis ) ) then
932 allocate( data_weights_slices(i) % a_axis( size(data_weights(i) % a_axis ) ) )
933 data_weights_slices(i) % a_axis = data_weights(i) % a_axis
934 end if
935 end do
936
937 ! 時刻次元のコピー
938 ! Copy time dimension
939 !
940 gthst_axes_slices(numdims) = gthst_axes_time
941
942 slice_valid = .true.
943 end if
944
945 ! HistoryCreate のための設定値の取得
946 ! Get the settings for "HistoryCreate"
947 !
948 call hstnmlinfoinquire( &
949 & gthstnml = gthstnml, & ! (in)
950 & name = varname, & ! (in)
951 & file = file, & ! (out)
952 & origin_value = origin_value, & ! (out)
953 & origin_unit = origin_unit, & ! (out)
954 & interval_unit = interval_unit, & ! (out)
955 & newfile_intvalue = newfile_intvalue, & ! (out)
956 & newfile_intunit = newfile_intunit ) ! (out)
957
958 ! データ出力時刻の設定
959 ! Configure data output time
960 !
961 origin_sec = &
962 & dccalconvertbyunit( &
963 & real( origin_value, dp ), origin_unit, 'sec', cal_save )
964
965!!$ ! dc_date モジュール使用時
966!!$ !
967!!$ call DCDiffTimeCreate( &
968!!$ & origin_sec, & ! (out)
969!!$ & origin_value, origin_unit ) ! (in)
970
971 if ( newfile_intvalue < 1 ) then
972
973 origin_value = dccalconvertbyunit( &
974 & origin_sec, 'sec', interval_unit, cal_save )
975
976! origin_value = EvalbyUnit( origin_sec, interval_unit )
977 else
978
979 origin_value = &
980 & dccalconvertbyunit( time, 'sec', interval_unit, cal_save )
981
982! origin_value = EvalbyUnit( time, interval_unit )
983 end if
984
985 ! ファイル名の設定
986 ! Configure file name
987 !
988 if ( len_trim( file ) - index(file, '.nc', .true.) == 2 ) then
989 file_base = file(1:len_trim( file ) - 3)
990 file_suffix = '.nc'
991 else
992 file_base = file
993 file_suffix = ''
994 end if
995 if ( trim(rank_save) == '' ) then
996 file_rank = ''
997 else
998 file_rank = '_rank' // trim( adjustl(rank_save) )
999 end if
1000 if ( newfile_intvalue > 0 ) then
1001 newfile_intvalued = &
1002 & dccalconvertbyunit( time, 'sec', newfile_intunit, cal_save )
1003
1004 file_newfile_time = &
1005 & cprintf( '_time%08d', i = (/ int( newfile_intvalued ) /) )
1006! & i = (/ int( EvalbyUnit( time, newfile_intunit ) ) /) )
1007 else
1008 file_newfile_time = ''
1009 end if
1010
1011 file = trim(file_base) // trim(file_rank) // trim(file_newfile_time) // trim(file_suffix)
1012
1013 ! HistoryCreate によるファイル作成
1014 ! Files are created by "HistoryCreate"
1015 !
1016 call historycreate( &
1017 & history = gthist, & ! (inout)
1018 & file = file, title = title_save, & ! (in)
1019 & source = source_save, institution = institution_save, & ! (in)
1020 & axes = gthst_axes_slices(1:numdims), & ! (in)
1021 & origind = origin_value, & ! (in)
1022 & conventions = conventions_save, & ! (in)
1023 & gt_version = gt_version_save, & ! (in)
1024 & flag_mpi_split = save_mpi_split, & ! (in)
1025 & flag_mpi_gather = save_mpi_gather ) ! (in)
1026
1027 ! 座標データを出力
1028 ! Output axes data
1029 !
1030 do i = 1, numdims - 1
1031 call historyaxisinquire( &
1032 & axis = gthst_axes_slices(i), & ! (in)
1033 & name = name ) ! (out)
1034 call historyput( &
1035 & history = gthist, & ! (inout) optional
1036 & varname = name, & ! (in)
1037 & array = data_axes_slices(i) % a_axis ) ! (in)
1038 end do
1039
1040 ! MPI 用に領域全体の座標データを出力
1041 ! Output axes data in whole area for MPI
1042 !
1043 if ( save_mpi_gather ) then
1044 do i = 1, numdims - 1
1045 call historyaxisinquire( &
1046 & axis = gthst_axes_slices(i), & ! (in)
1047 & name = name ) ! (out)
1048
1049 if ( .not. associated( data_axes_whole(i) % a_axis ) ) then
1050 call messagenotify('W', subname, &
1051 & 'data of axis (%c) in whole area is lack. ' // &
1052 & 'Specify the data by "HistoryAutoPutAxisMPI" explicitly.', &
1053 & c1 = trim(name) )
1054 stat = hst_empinoaxisdata
1055 cause_c = name
1056 end if
1057
1058 call historyputaxismpi( &
1059 & history = gthist, & ! (inout) optional
1060 & varname = name, & ! (in)
1061 & array = data_axes_whole(i) % a_axis ) ! (in)
1062 end do
1063 end if
1064
1065 ! 割付解除
1066 ! Deallocation
1067 !
1068 if ( slice_valid ) then
1069 deallocate( gthst_axes_slices )
1070 deallocate( data_axes_slices )
1071 else
1072 deallocate( gthst_axes_slices )
1073 nullify( data_axes_slices )
1074 end if
1075
1076 ! 座標重みデータを追加
1077 ! Add axes weights data
1078 !
1079 do i = 1, numwgts
1080 call historyaddvariable( &
1081 & history = gthist, & ! (inout)
1082 & varinfo = gthst_weights(i) ) ! (in)
1083 call historyvarinfoinquire( &
1084 & varinfo = gthst_weights(i), & ! (in)
1085 & name = name ) ! (out)
1086 call historyput( &
1087 & history = gthist, & ! (inout) optional
1088 & varname = name, & ! (in)
1089 & array = data_weights_slices(i) % a_axis ) ! (in)
1090 end do
1091
1092 if ( slice_valid ) then
1093 deallocate( data_weights_slices )
1094 else
1095 nullify( data_weights_slices )
1096 end if
1097
1098 ! ファイル作成おしまい; Creation of file is finished
1099 end if
1100
1101
1102 ! 変数情報を追加
1103 ! Add information of variables
1104 !
1105 call historyaddvariable( &
1106 & varinfo = gthst_vars(vnum), & ! (in)
1107 & history = gthist ) ! (inout) optional
1108
1109999 continue
1110 call storeerror(stat, subname, cause_c = cause_c)
1111 call endsub(subname)
暦と日時モジュール
日付・時刻に関する構造データ型と定数
日付および時刻に関する手続きを提供するモジュール
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 hst_ebadslice
Definition dc_error.f90:568
integer, parameter, public hst_ebadvarname
Definition dc_error.f90:563
integer, parameter, public dc_noerr
エラー等を保持
Definition dc_error.f90:468
integer, parameter, public hst_empinoaxisdata
Definition dc_error.f90:574
メッセージの出力
文字型変数の操作
Definition dc_string.f90:83
character(string) function, public joinchar(carray, expr)
デバッグ時の追跡用モジュール
Definition dc_trace.f90:150
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

References dc_trace::beginsub(), gtool_historyauto_internal::cal_save, gtool_historyauto_internal::conventions_save, gtool_historyauto_internal::data_axes, gtool_historyauto_internal::data_axes_whole, gtool_historyauto_internal::data_weights, dc_error::dc_noerr, dc_trace::endsub(), gtool_historyauto_internal::gt_version_save, gtool_historyauto_internal::gthst_axes, gtool_historyauto_internal::gthst_vars, gtool_historyauto_internal::gthst_weights, gtool_historyauto_internal::gthstnml, dc_error::hst_ebadslice, dc_error::hst_ebadvarname, dc_error::hst_empinoaxisdata, gtool_historyauto_internal::institution_save, dc_string::joinchar(), gtool_historyauto_internal::numvars, gtool_historyauto_internal::numwgts, gtool_historyauto_internal::rank_save, gtool_historyauto_internal::save_mpi_gather, gtool_historyauto_internal::save_mpi_split, gtool_historyauto_internal::source_save, dc_error::storeerror(), gtool_historyauto_internal::time_unit_suffix, gtool_historyauto_internal::title_save, and gtool_historyauto_internal::wgtsuf.

Here is the call graph for this function:

The documentation for this interface was generated from the following file: