Neko 1.99.9
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 : dp
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 call this%free()
105
106 select case (trim(suffix))
107 case ("rea")
108 allocate(rea_file_t::this%file_type)
109 case ("re2")
110 allocate(re2_file_t::this%file_type)
111 case ("map")
112 allocate(map_file_t::this%file_type)
113 case ("vtk")
114 allocate(vtk_file_t::this%file_type)
115 case ("nmsh")
116 allocate(nmsh_file_t::this%file_type)
117 case ("bp")
118 allocate(bp_file_t::this%file_type)
119 case ("fld")
120 allocate(fld_file_t::this%file_type)
121 case ("chkp")
122 allocate(chkp_file_t::this%file_type)
123 case ("stl")
124 allocate(stl_file_t::this%file_type)
125 case ("csv")
126 allocate(csv_file_t::this%file_type)
127 this%file_type%serial = .true.
128 case ("hdf5", "h5")
129 allocate(hdf5_file_t::this%file_type)
130 case ("vtkhdf")
131 allocate(vtkhdf_file_t::this%file_type)
132 case default
133 call neko_error('Unknown file format: "' // trim(suffix) // '"')
134 end select
135
136 call this%file_type%init(fname)
137
138 if (present(header)) then
139 call this%set_header(header)
140 end if
141
142 if (present(precision)) then
143 call this%set_precision(precision)
144 end if
145
146 if (present(layout) .and. (suffix .eq. "bp")) then
147 call this%set_layout(layout)
148 end if
149
150 if (present(overwrite)) then
151 call this%set_overwrite(overwrite)
152 end if
153
154 end subroutine file_init
155
157 subroutine file_free(this)
158 class(file_t), intent(inout) :: this
159
160 if (allocated(this%file_type)) then
161 ! Release the (device mapped) output mask of an fld file
162 select type (ft => this%file_type)
163 class is (fld_file_t)
164 call ft%set_mask()
165 end select
166 deallocate(this%file_type)
167 end if
168
169 end subroutine file_free
170
173 subroutine file_write(this, data, t)
174 class(file_t), intent(inout) :: this
175 class(*), intent(inout) :: data
176 real(kind=dp), intent(in), optional :: t
177
178 call this%file_type%write(data, t = t)
179
180 end subroutine file_write
181
184 subroutine file_read(this, data)
185 class(file_t), intent(in) :: this
186 class(*), intent(inout) :: data
187
188 call this%file_type%read(data)
189
190 end subroutine file_read
191
193 function file_get_fname(this) result(fname)
194 class(file_t), intent(in) :: this
195 character(len=1024) :: fname
196
197 fname = ""
198
199 select type (ft => this%file_type)
200 class is (generic_file_t)
201 fname = ft%get_fname()
202 end select
203
204 end function file_get_fname
205
207 function file_get_base_fname(this) result(fname)
208 class(file_t), intent(in) :: this
209 character(len=1024) :: fname
210
211 fname = ""
212
213 select type (ft => this%file_type)
214 class is (generic_file_t)
215 fname = ft%get_base_fname()
216 end select
217
218 end function file_get_base_fname
219
221 function file_get_counter(this) result(n)
222 class(file_t), intent(inout) :: this
223 integer :: n
224 n = 0
225
226 select type (ft => this%file_type)
227 class is (generic_file_t)
228 n = ft%get_counter()
229 end select
230
231 end function file_get_counter
232
234 subroutine file_set_counter(this, n)
235 class(file_t), intent(inout) :: this
236 integer, intent(in) :: n
237
238 select type (ft => this%file_type)
239 class is (generic_file_t)
240 call ft%set_counter(n)
241 end select
242
243 end subroutine file_set_counter
244
246 subroutine file_set_start_counter(this, n)
247 class(file_t), intent(inout) :: this
248 integer, intent(in) :: n
249
250 select type (ft => this%file_type)
251 class is (generic_file_t)
252 call ft%set_start_counter(n)
253 end select
254
255 end subroutine file_set_start_counter
256
258 subroutine file_set_header(this, hd)
259 class(file_t), intent(inout) :: this
260 character(len=*), intent(in) :: hd
261 character(len=80) :: suffix
262
263 select type (ft => this%file_type)
264 class is (csv_file_t)
265 call ft%set_header(hd)
266 class default
267 call filename_suffix(this%file_type%get_fname(), suffix)
268 call neko_warning("No set_header defined for " // trim(suffix) // " yet")
269 end select
270
271 end subroutine file_set_header
272
275 subroutine file_set_precision(this, precision)
276 class(file_t), intent(inout) :: this
277 integer, intent(in) :: precision
278 character(len=80) :: suffix
279
280 select type (ft => this%file_type)
281 type is (fld_file_t)
282 call ft%set_precision(precision)
283 type is (bp_file_t)
284 call ft%set_precision(precision)
285 type is (vtkhdf_file_t)
286 call ft%set_precision(precision)
287 class default
288 call filename_suffix(this%file_type%get_fname(), suffix)
289 call neko_warning("No precision strategy defined for " // trim(suffix) &
290 // " files")
291 end select
292
293 end subroutine file_set_precision
294
297 subroutine file_set_layout(this, layout)
298 class(file_t), intent(inout) :: this
299 integer, intent(in) :: layout
300 character(len=80) :: suffix
301
302 select type (ft => this%file_type)
303 type is (bp_file_t)
304 call ft%set_layout(layout)
305 class default
306 call filename_suffix(this%file_type%get_fname(), suffix)
307 call neko_warning("No set_layout defined for " // trim(suffix) // " yet")
308 end select
309
310 end subroutine file_set_layout
311
313 subroutine file_set_overwrite(this, overwrite)
314 class(file_t), intent(inout) :: this
315 logical, intent(in) :: overwrite
316 character(len=80) :: suffix
317
318 select type (ft => this%file_type)
319 class is (generic_file_t)
320 call ft%set_overwrite(overwrite)
321 end select
322 end subroutine file_set_overwrite
323
327 subroutine file_set_subdivide(this, subdivide)
328 class(file_t), intent(inout) :: this
329 logical, intent(in) :: subdivide
330 character(len=80) :: suffix
331
332 select type (ft => this%file_type)
333 type is (vtkhdf_file_t)
334 call ft%set_subdivide(subdivide)
335 class default
336 if (subdivide) then
337 call filename_suffix(this%file_type%get_fname(), suffix)
338 call neko_warning("Subdivide output not supported for " // &
339 trim(suffix) // " files")
340 end if
341 end select
342 end subroutine file_set_subdivide
343
344end module file
ADIOS2 bp file format.
Definition bp_file.F90:36
Neko legacy checkpoint file format.
Definition chkp_file.f90:36
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:259
subroutine file_set_overwrite(this, overwrite)
Sets the file's overwrite flag.
Definition file.f90:314
subroutine file_set_start_counter(this, n)
Set a file's start counter.
Definition file.f90:247
subroutine file_set_counter(this, n)
Set a file's counter.
Definition file.f90:235
character(len=1024) function file_get_fname(this)
Get a file's name.
Definition file.f90:194
subroutine file_set_layout(this, layout)
Set a file's output layout.
Definition file.f90:298
integer function file_get_counter(this)
Get a file's counter.
Definition file.f90:222
subroutine file_read(this, data)
Read data from a file.
Definition file.f90:185
subroutine file_set_precision(this, precision)
Set a file's output precision.
Definition file.f90:276
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:328
subroutine file_free(this)
File operation destructor.
Definition file.f90:158
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:208
subroutine file_write(this, data, t)
Writes data to a file.
Definition file.f90:174
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 dp
Definition num_types.f90:10
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:454
subroutine, public filename_suffix(fname, suffix)
Extract a filename's suffix.
Definition utils.f90:163
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 legacy checkpoint files.
Definition chkp_file.f90:95
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:68
Interface for NEKTON map files.
Definition map_file.f90:45
Interface for Neko nmsh files.
Definition nmsh_file.f90:61
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:52
Interface for HDF5 files.