gtool_historyauto_internal::hstfilecreate Interface Reference

Private Member Functions

subroutine hstfilecreate (gthist, varname, time)
 

Detailed Description

Definition at line 345 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 
)
private

Definition at line 625 of file gtool_historyauto_internal.f90.

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

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