Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
file.f90
Go to the documentation of this file.
1! Copyright (c) 2019-2026, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
34module file
36 use num_types, only : rp
38 use nmsh_file, only : nmsh_file_t
39 use chkp_file, only : chkp_file_t
40 use map_file, only : map_file_t
41 use rea_file, only : rea_file_t
42 use re2_file, only : re2_file_t
43 use bp_file, only : bp_file_t
44 use fld_file, only : fld_file_t
46 use vtk_file, only : vtk_file_t
47 use vtkhdf_file, only : vtkhdf_file_t
48 use stl_file, only : stl_file_t
49 use csv_file, only : csv_file_t
50 use hdf5_file, only : hdf5_file_t
51 implicit none
52
56 type file_t
57 class(generic_file_t), allocatable :: file_type
58 contains
60 procedure, pass (this) :: init => file_init
62 procedure :: write => file_write
64 procedure :: read => file_read
66 procedure :: get_fname => file_get_fname
68 procedure :: get_base_fname => file_get_base_fname
70 procedure :: get_counter => file_get_counter
72 procedure :: set_counter => file_set_counter
74 procedure :: set_start_counter => file_set_start_counter
76 procedure :: set_header => file_set_header
78 procedure :: set_precision => file_set_precision
80 procedure :: set_layout => file_set_layout
82 procedure, pass (this) :: set_overwrite => file_set_overwrite
84 procedure :: set_subdivide => file_set_subdivide
86 procedure, pass(this) :: free => file_free
87 end type file_t
88
89contains
90
93 subroutine file_init(this, fname, header, precision, layout, overwrite)
94 class(file_t), intent(inout) :: this
95 character(len=*), intent(in) :: fname
96 character(len=*), intent(in), optional :: header
97 integer, intent(in), optional :: precision
98 integer, intent(in), optional :: layout
99 logical, intent(in), optional :: overwrite
100 character(len=80) :: suffix
101
102 call filename_suffix(fname, suffix)
103
104 if (allocated(this%file_type)) then
105 deallocate(this%file_type)
106 end if
107
108 select case (trim(suffix))
109 case ("rea")
110 allocate(rea_file_t::this%file_type)
111 case ("re2")
112 allocate(re2_file_t::this%file_type)
113 case ("map")
114 allocate(map_file_t::this%file_type)
115 case ("vtk")
116 allocate(vtk_file_t::this%file_type)
117 case ("nmsh")
118 allocate(nmsh_file_t::this%file_type)
119 case ("bp")
120 allocate(bp_file_t::this%file_type)
121 case ("fld")
122 allocate(fld_file_t::this%file_type)
123 case ("chkp")
124 allocate(chkp_file_t::this%file_type)
125 case ("stl")
126 allocate(stl_file_t::this%file_type)
127 case ("csv")
128 allocate(csv_file_t::this%file_type)
129 this%file_type%serial = .true.
130 case ("hdf5", "h5")
131 allocate(hdf5_file_t::this%file_type)
132 case ("vtkhdf")
133 allocate(vtkhdf_file_t::this%file_type)
134 case default
135 call neko_error('Unknown file format: "' // trim(suffix) // '"')
136 end select
137
138 call this%file_type%init(fname)
139
140 if (present(header)) then
141 call this%set_header(header)
142 end if
143
144 if (present(precision)) then
145 call this%set_precision(precision)
146 end if
147
148 if (present(layout) .and. (suffix .eq. "bp")) then
149 call this%set_layout(layout)
150 end if
151
152 if (present(overwrite)) then
153 call this%set_overwrite(overwrite)
154 end if
155
156 end subroutine file_init
157
159 subroutine file_free(this)
160 class(file_t), intent(inout) :: this
161
162 if (allocated(this%file_type)) then
163 deallocate(this%file_type)
164 end if
165
166 end subroutine file_free
167
170 subroutine file_write(this, data, t)
171 class(file_t), intent(inout) :: this
172 class(*), intent(inout) :: data
173 real(kind=rp), intent(in), optional :: t
174
175 call this%file_type%write(data, t = t)
176
177 end subroutine file_write
178
181 subroutine file_read(this, data)
182 class(file_t), intent(in) :: this
183 class(*), intent(inout) :: data
184
185 call this%file_type%read(data)
186
187 end subroutine file_read
188
190 function file_get_fname(this) result(fname)
191 class(file_t), intent(in) :: this
192 character(len=1024) :: fname
193
194 fname = ""
195
196 select type (ft => this%file_type)
197 class is (generic_file_t)
198 fname = ft%get_fname()
199 end select
200
201 end function file_get_fname
202
204 function file_get_base_fname(this) result(fname)
205 class(file_t), intent(in) :: this
206 character(len=1024) :: fname
207
208 fname = ""
209
210 select type (ft => this%file_type)
211 class is (generic_file_t)
212 fname = ft%get_base_fname()
213 end select
214
215 end function file_get_base_fname
216
218 function file_get_counter(this) result(n)
219 class(file_t), intent(inout) :: this
220 integer :: n
221 n = 0
222
223 select type (ft => this%file_type)
224 class is (generic_file_t)
225 n = ft%get_counter()
226 end select
227
228 end function file_get_counter
229
231 subroutine file_set_counter(this, n)
232 class(file_t), intent(inout) :: this
233 integer, intent(in) :: n
234
235 select type (ft => this%file_type)
236 class is (generic_file_t)
237 call ft%set_counter(n)
238 end select
239
240 end subroutine file_set_counter
241
243 subroutine file_set_start_counter(this, n)
244 class(file_t), intent(inout) :: this
245 integer, intent(in) :: n
246
247 select type (ft => this%file_type)
248 class is (generic_file_t)
249 call ft%set_start_counter(n)
250 end select
251
252 end subroutine file_set_start_counter
253
255 subroutine file_set_header(this, hd)
256 class(file_t), intent(inout) :: this
257 character(len=*), intent(in) :: hd
258 character(len=80) :: suffix
259
260 select type (ft => this%file_type)
261 class is (csv_file_t)
262 call ft%set_header(hd)
263 class default
264 call filename_suffix(this%file_type%get_fname(), suffix)
265 call neko_warning("No set_header defined for " // trim(suffix) // " yet")
266 end select
267
268 end subroutine file_set_header
269
272 subroutine file_set_precision(this, precision)
273 class(file_t), intent(inout) :: this
274 integer, intent(in) :: precision
275 character(len=80) :: suffix
276
277 select type (ft => this%file_type)
278 type is (fld_file_t)
279 call ft%set_precision(precision)
280 type is (bp_file_t)
281 call ft%set_precision(precision)
282 type is (vtkhdf_file_t)
283 call ft%set_precision(precision)
284 class default
285 call filename_suffix(this%file_type%get_fname(), suffix)
286 call neko_warning("No precision strategy defined for " // trim(suffix) &
287 // " files")
288 end select
289
290 end subroutine file_set_precision
291
294 subroutine file_set_layout(this, layout)
295 class(file_t), intent(inout) :: this
296 integer, intent(in) :: layout
297 character(len=80) :: suffix
298
299 select type (ft => this%file_type)
300 type is (bp_file_t)
301 call ft%set_layout(layout)
302 class default
303 call filename_suffix(this%file_type%get_fname(), suffix)
304 call neko_warning("No set_layout defined for " // trim(suffix) // " yet")
305 end select
306
307 end subroutine file_set_layout
308
310 subroutine file_set_overwrite(this, overwrite)
311 class(file_t), intent(inout) :: this
312 logical, intent(in) :: overwrite
313 character(len=80) :: suffix
314
315 select type (ft => this%file_type)
316 class is (generic_file_t)
317 call ft%set_overwrite(overwrite)
318 end select
319 end subroutine file_set_overwrite
320
324 subroutine file_set_subdivide(this, subdivide)
325 class(file_t), intent(inout) :: this
326 logical, intent(in) :: subdivide
327 character(len=80) :: suffix
328
329 select type (ft => this%file_type)
330 type is (vtkhdf_file_t)
331 call ft%set_subdivide(subdivide)
332 class default
333 if (subdivide) then
334 call filename_suffix(this%file_type%get_fname(), suffix)
335 call neko_warning("Subdivide output not supported for " // &
336 trim(suffix) // " files")
337 end if
338 end select
339 end subroutine file_set_subdivide
340
341end module file
ADIOS2 bp file format.
Definition bp_file.F90:36
Neko checkpoint file format.
Definition chkp_file.f90:35
File format for .csv files, used for any read/write operations involving floating point data.
Definition csv_file.f90:35
Module for file I/O operations.
Definition file.f90:34
subroutine file_set_header(this, hd)
Set a file's header.
Definition file.f90:256
subroutine file_set_overwrite(this, overwrite)
Sets the file's overwrite flag.
Definition file.f90:311
subroutine file_set_start_counter(this, n)
Set a file's start counter.
Definition file.f90:244
subroutine file_set_counter(this, n)
Set a file's counter.
Definition file.f90:232
character(len=1024) function file_get_fname(this)
Get a file's name.
Definition file.f90:191
subroutine file_set_layout(this, layout)
Set a file's output layout.
Definition file.f90:295
integer function file_get_counter(this)
Get a file's counter.
Definition file.f90:219
subroutine file_read(this, data)
Read data from a file.
Definition file.f90:182
subroutine file_set_precision(this, precision)
Set a file's output precision.
Definition file.f90:273
subroutine file_set_subdivide(this, subdivide)
Enable or disable subdivision of spectral elements into linear sub-cells. Only has effect for VTKHDF ...
Definition file.f90:325
subroutine file_free(this)
File operation destructor.
Definition file.f90:160
subroutine file_init(this, fname, header, precision, layout, overwrite)
Constructor.
Definition file.f90:94
character(len=1024) function file_get_base_fname(this)
Get a file's base name.
Definition file.f90:205
subroutine file_write(this, data, t)
Writes data to a file.
Definition file.f90:171
Simple module to handle fld file series. Provides an interface to the different fields sotred in a fl...
NEKTON fld file format.
Definition fld_file.f90:35
HDF5 file format.
Definition hdf5_file.F90:34
NEKTON map file.
Definition map_file.f90:35
Neko binary mesh data.
Definition nmsh_file.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
NEKTON mesh data in re2 format.
Definition re2_file.f90:35
NEKTON session data reader.
Definition rea_file.f90:35
Stereolithography (STL) file.
Definition stl_file.f90:34
Utilities.
Definition utils.f90:35
subroutine, public neko_warning(warning_msg)
Reports a warning to standard output.
Definition utils.f90:392
subroutine, public filename_suffix(fname, suffix)
Extract a filename's suffix.
Definition utils.f90:118
Legacy VTK file format.
Definition vtk_file.f90:35
VTKHDF file format.
Interface for ADIOS2 bp files.
Definition bp_file.F90:71
Interface for Neko checkpoint files.
Definition chkp_file.f90:61
A wrapper around a polymorphic generic_file_t that handles its init. This is essentially a factory fo...
Definition file.f90:56
Interface for NEKTON fld files.
Definition fld_file.f90:66
A generic file handler.
Interface for HDF5 files.
Definition hdf5_file.F90:60
Interface for NEKTON map files.
Definition map_file.f90:45
Interface for Neko nmsh files.
Definition nmsh_file.f90:60
Interface for NEKTON re2 files.
Definition re2_file.f90:65
Interface for NEKTON ascii files.
Definition rea_file.f90:61
Interface for STL files.
Definition stl_file.f90:50
Interface for legacy VTK files.
Definition vtk_file.f90:51
Interface for HDF5 files.