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