gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
historyclose.f90
Go to the documentation of this file.
1!> @file historyclose.F
2!>
3!> @author Yasuhiro MORIKAWA, Eizi TOYODA
4!> @copyright Copyright (C) GFD Dennou Club, 2000-2026. All rights reserved. <br/>
5!> License is BSD-2-Clause. See [COPYRIGHT](@ref COPYRIGHT) in detail
6!>
7!> @en
8!> @brief Close gtool4 data output
9!> @enden
10!>
11!> @ja
12!> @brief gtool4 データの終了処理
13!> @endja
14!>
15!> @en
16!> @brief Close gtool4 data output
17!>
18!> Performs finalization of data output started by HistoryCreate.
19!> When HistoryCreate is used in a program, this subroutine must
20!> be called before the program terminates.
21!> @param[inout] history History structure (optional)
22!> @param[in] quiet Suppress messages (optional)
23!> @param[out] err Error flag (optional)
24!> @enden
25!>
26!> @ja
27!> @brief gtool4 データの終了処理
28!>
29!> HistoryCreate で始まったデータ出力の終了処理をおこなうものです。
30!> プログラム内で HistoryCreate を用いた場合、プログラムを終了する
31!> 前に必ずこのサブルーチンを呼んで下さい。
32!> @param[inout] history 出力ファイル設定構造体 (省略可能)
33!> @param[in] quiet メッセージ出力抑制 (省略可能)
34!> @param[out] err エラーフラグ (省略可能)
35!> @endja
36!>
37 subroutine historyclose( history, quiet, err )
38 !
42 use gtdata_generic, only: close, inquire
43 use gtdata_types, only: gt_variable
44 use dc_message, only: messagenotify
45 use dc_url, only: urlsplit
48 use dc_types, only: string, dp
51 implicit none
52 type(gt_history), intent(inout), optional, target:: history
53 ! 出力ファイルの設定に関する情報を
54 ! 格納した構造体
55 !
56 ! ここに指定するものは,
57 ! HistoryCreate によって初期設定
58 ! されていなければなりません.
59 !
60 logical, intent(in), optional:: quiet
61 ! .true. を与えた場合,
62 ! メッセージ出力が抑制されます.
63 !
64 ! If ".true." is given,
65 ! messages are suppressed.
66 !
67 logical, intent(out), optional:: err
68 ! 例外処理用フラグ.
69 ! デフォルトでは, この手続き内でエラーが
70 ! 生じた場合, プログラムは強制終了します.
71 ! 引数 *err* が与えられる場合,
72 ! プログラムは強制終了せず, 代わりに
73 ! *err* に .true. が代入されます.
74 !
75 ! Exception handling flag.
76 ! By default, when error occur in
77 ! this procedure, the program aborts.
78 ! If this *err* argument is given,
79 ! .true. is substituted to *err* and
80 ! the program does not abort.
81 type(gt_history), pointer:: hst =>null()
82 character(STRING):: url, file
83 integer:: i, v_size
84 integer:: stat
85 character(STRING):: cause_c
86 character(len = *), parameter:: subname = "HistoryClose"
87 continue
88 call beginsub(subname)
89 stat = dc_noerr
90 cause_c = ""
91 if (present(history)) then
92 hst => history
93 else
94 hst => default
95 endif
96 !-----------------------------------------------------------------
97 ! 初期設定のチェック
98 ! Check initialization
99 !-----------------------------------------------------------------
100 if ( .not. hst % initialized ) then
101 stat = dc_enotinit
102 cause_c = 'GT_HISTORY'
103 goto 999
104 end if
105 !-----------------------------------------------------------------
106 ! メッセージ出力用にファイル名取得
107 ! Get filename for output messages
108 !-----------------------------------------------------------------
109 if ( .not. hst % mpi_gather &
110 & .or. ( hst % mpi_gather .and. hst % mpi_myrank == 0 ) ) then
111 if ( .not. present_and_true(quiet) ) then
112 call inquire( hst % dimvars(1), & ! (in)
113 & url = url ) ! (out)
114 call urlsplit( fullname = url, & ! (in)
115 & file = file ) ! (out)
116 end if
117 endif
118 !-----------------------------------------------------------------
119 ! 変数のクローズ
120 ! Close variables
121 !-----------------------------------------------------------------
122 if ( .not. hst % mpi_gather &
123 & .or. ( hst % mpi_gather .and. hst % mpi_myrank == 0 ) ) then
124 v_size = size(hst % dimvars)
125 do, i = 1, v_size
126 if (.not. hst % dim_value_written(i)) &
127 call set_fake_dim_value(hst, i)
128 call close(hst % dimvars(i))
129 enddo
130 v_size = size(hst % vars)
131 do, i = 1, v_size
132 call close(hst % vars(i))
133 enddo
134 endif
135 deallocate(hst % dimvars)
136 v_size = size(hst % vars)
137 !-----------------------------------------------------------------
138 ! 設定のクリア
139 ! Clear configurations
140 !-----------------------------------------------------------------
141 hst % unlimited_index = 0
142 hst % unlimited_units = ''
143 hst % unlimited_units_symbol = unit_symbol_err
144 if (associated(hst % dim_value_written)) deallocate(hst % dim_value_written)
145 if (associated(hst % vars)) deallocate(hst % vars)
146 if (associated(hst % growable_indices)) deallocate(hst % growable_indices)
147 if (associated(hst % count)) deallocate(hst % count)
148 if (associated(hst % var_avr_count)) deallocate(hst % var_avr_count)
149 do, i = 1, v_size
150 if (associated(hst % var_avr_data(i) % a_DataAvr)) deallocate(hst % var_avr_data(i) % a_DataAvr)
151 enddo
152 if (associated(hst % var_avr_data)) deallocate(hst % var_avr_data)
153 if (associated(hst % var_avr_firstput)) deallocate(hst % var_avr_firstput)
154 if (associated(hst % var_avr_coefsum)) deallocate(hst % var_avr_coefsum)
155 if (associated(hst % var_avr_baseint)) deallocate(hst % var_avr_baseint)
156 if (associated(hst % var_avr_prevtime)) deallocate(hst % var_avr_prevtime)
157 hst % time_bnds = 0.0_dp
158 hst % time_bnds_output_count = 0
159 hst % time_nv_index = 0
160 hst % origin_setting = .false.
161 if ( associated( hst % mpi_fileinfo % axes ) ) deallocate( hst % mpi_fileinfo % axes )
162 if ( associated( hst % mpi_fileinfo ) ) deallocate( hst % mpi_fileinfo )
163 v_size = size(hst % mpi_dimdata_all)
164 do, i = 1, v_size
165 if ( associated( hst % mpi_dimdata_all(i) % a_Axis ) ) deallocate( hst % mpi_dimdata_all(i) % a_Axis )
166 if ( associated( hst % mpi_dimdata_all(i) % attrs ) ) deallocate( hst % mpi_dimdata_all(i) % attrs )
167 enddo
168 if ( associated( hst % mpi_dimdata_all ) ) deallocate( hst % mpi_dimdata_all )
169 v_size = size(hst % mpi_dimdata_each)
170 do, i = 1, v_size
171 if ( associated( hst % mpi_dimdata_each(i) % a_Axis ) ) deallocate( hst % mpi_dimdata_each(i) % a_Axis )
172 enddo
173 if ( associated( hst % mpi_dimdata_each ) ) deallocate( hst % mpi_dimdata_each )
174 if ( associated( hst % mpi_gthr_info ) ) then
175 v_size = size(hst % mpi_gthr_info)
176 do, i = 1, v_size
177 if ( associated( hst % mpi_gthr_info(i) % index_all ) ) deallocate( hst % mpi_gthr_info(i) % index_all )
178 if ( associated( hst % mpi_gthr_info(i) % length ) ) deallocate( hst % mpi_gthr_info(i) % length )
179 end do
180 deallocate( hst % mpi_gthr_info )
181 end if
182 if ( associated(hst % mpi_varinfo) ) then
183 v_size = size(hst % mpi_varinfo)
184 do, i = 1, v_size
185 call historyvarinfoclear( hst % mpi_varinfo(i), err )
186 end do
187 deallocate( hst % mpi_varinfo )
188 end if
189 if ( associated(hst % mpi_vars_index) ) then
190 v_size = size(hst % mpi_vars_index)
191 do, i = 1, v_size
192 if ( associated( hst % mpi_vars_index(i) % each2all ) ) deallocate( hst % mpi_vars_index(i) % each2all )
193 if ( associated( hst % mpi_vars_index(i) % allcount ) ) deallocate( hst % mpi_vars_index(i) % allcount )
194 end do
195 deallocate( hst % mpi_vars_index )
196 end if
197 !-----------------------------------------------------------------
198 ! メッセージ出力
199 ! Output messages
200 !-----------------------------------------------------------------
201 if ( .not. hst % mpi_gather &
202 & .or. ( hst % mpi_gather .and. hst % mpi_myrank == 0 ) ) then
203 if ( .not. present_and_true(quiet) ) then
204 call messagenotify('M', subname, &
205 & '"%c" is closed', &
206 & c1 = trim( file ), rank_mpi = -1 )
207 end if
208 endif
209 hst % mpi_myrank = -1
210 hst % mpi_nprocs = -1
211 hst % mpi_gather = .false.
212 hst % mpi_split = .false.
213 !-----------------------------------------------------------------
214 ! 終了処理, 例外処理
215 ! Termination and Exception handling
216 !-----------------------------------------------------------------
217 hst % initialized = .false.
218999 continue
219 call storeerror( stat, subname, err, cause_c )
220 call endsub( subname )
221 end subroutine historyclose
subroutine historyclose(history, quiet, err)
Derived types and parameters for date and time.
integer, parameter, public unit_symbol_err
Symbol for invalid unit
Error handling module.
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
integer, parameter, public dc_enotinit
-400 or less: DC utilities errors
Definition dc_error.f90:534
integer, parameter, public dc_noerr
Error storage variables
Definition dc_error.f90:468
Message output module.
Judge optional control parameters.
logical function, public present_and_true(arg)
Debug tracing module.
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
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public string
Character length for string
Definition dc_types.f90:137
integer, parameter, public dp
Double Precision Real number
Definition dc_types.f90:92
Variable URL string parser.
Definition dc_url.f90:61
type(gt_history), target, save, public default