Neko 1.99.1
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-2024, 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 stl_file, only : stl_file_t
48 use csv_file, only : csv_file_t
49 use hdf5_file, only : hdf5_file_t
50 implicit none
51
55 type file_t
56 class(generic_file_t), allocatable :: file_type
57 contains
59 procedure, pass (this) :: init => file_init
61 procedure :: write => file_write
63 procedure :: read => file_read
65 procedure :: get_fname => file_get_fname
67 procedure :: get_base_fname => file_get_base_fname
69 procedure :: get_counter => file_get_counter
71 procedure :: set_counter => file_set_counter
73 procedure :: set_start_counter => file_set_start_counter
75 procedure :: set_header => file_set_header
77 procedure :: set_precision => file_set_precision
79 procedure :: set_layout => file_set_layout
81 procedure, pass (this) :: set_overwrite => file_set_overwrite
83 procedure, pass(this) :: free => file_free
84 end type file_t
85
86contains
87
90 subroutine file_init(this, fname, header, precision, layout, overwrite)
91 class(file_t), intent(inout) :: this
92 character(len=*), intent(in) :: fname
93 character(len=*), intent(in), optional :: header
94 integer, intent(in), optional :: precision
95 integer, intent(in), optional :: layout
96 logical, intent(in), optional :: overwrite
97 character(len=80) :: suffix
98 class(generic_file_t), pointer :: q
99
100 call filename_suffix(fname, suffix)
101
102 if (allocated(this%file_type)) then
103 deallocate(this%file_type)
104 end if
105
106 select case (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 default
131 call neko_error('Unknown file format')
132 end select
133
134 call this%file_type%init(fname)
135
136 if (present(header)) then
137 call this%set_header(header)
138 end if
139
140 if (present(precision)) then
141 call this%set_precision(precision)
142 end if
143
144 if (present(layout).and. (suffix .eq. "bp")) then
145 call this%set_layout(layout)
146 end if
147
148 if (present(overwrite)) then
149 call this%set_overwrite(overwrite)
150 end if
151
152 end subroutine file_init
153
155 subroutine file_free(this)
156 class(file_t), intent(inout) :: this
157
158 if (allocated(this%file_type)) then
159 deallocate(this%file_type)
160 end if
161
162 end subroutine file_free
163
166 subroutine file_write(this, data, t)
167 class(file_t), intent(inout) :: this
168 class(*), intent(inout) :: data
169 real(kind=rp), intent(in), optional :: t
170
171 call this%file_type%write(data, t = t)
172
173 end subroutine file_write
174
177 subroutine file_read(this, data)
178 class(file_t), intent(in) :: this
179 class(*), intent(inout) :: data
180
181 call this%file_type%read(data)
182
183 end subroutine file_read
184
186 function file_get_fname(this) result(fname)
187 class(file_t), intent(in) :: this
188 character(len=1024) :: fname
189
190 fname = ""
191
192 select type (ft => this%file_type)
193 class is (generic_file_t)
194 fname = ft%get_fname()
195 end select
196
197 end function file_get_fname
198
200 function file_get_base_fname(this) result(fname)
201 class(file_t), intent(in) :: this
202 character(len=1024) :: fname
203
204 fname = ""
205
206 select type (ft => this%file_type)
207 class is (generic_file_t)
208 fname = ft%get_base_fname()
209 end select
210
211 end function file_get_base_fname
212
214 function file_get_counter(this) result(n)
215 class(file_t), intent(inout) :: this
216 integer :: n
217 n = 0
218
219 select type (ft => this%file_type)
220 class is (generic_file_t)
221 n = ft%get_counter()
222 end select
223
224 end function file_get_counter
225
227 subroutine file_set_counter(this, n)
228 class(file_t), intent(inout) :: this
229 integer, intent(in) :: n
230
231 select type (ft => this%file_type)
232 class is (generic_file_t)
233 call ft%set_counter(n)
234 end select
235
236 end subroutine file_set_counter
237
239 subroutine file_set_start_counter(this, n)
240 class(file_t), intent(inout) :: this
241 integer, intent(in) :: n
242
243 select type (ft => this%file_type)
244 class is (generic_file_t)
245 call ft%set_start_counter(n)
246 end select
247
248 end subroutine file_set_start_counter
249
251 subroutine file_set_header(this, hd)
252 class(file_t), intent(inout) :: this
253 character(len=*), intent(in) :: hd
254 character(len=80) :: suffix
255
256 select type (ft => this%file_type)
257 class is (csv_file_t)
258 call ft%set_header(hd)
259 class default
260 call filename_suffix(this%file_type%get_fname(), suffix)
261 call neko_warning("No set_header defined for " // trim(suffix) // " yet")
262 end select
263
264 end subroutine file_set_header
265
268 subroutine file_set_precision(this, precision)
269 class(file_t), intent(inout) :: this
270 integer, intent(in) :: precision
271 character(len=80) :: suffix
272
273 select type (ft => this%file_type)
274 type is (fld_file_t)
275 call ft%set_precision(precision)
276 type is (bp_file_t)
277 call ft%set_precision(precision)
278 class default
279 call filename_suffix(this%file_type%get_fname(), suffix)
280 call neko_warning("No precision strategy defined for " // trim(suffix) &
281 // " files")
282 end select
283
284 end subroutine file_set_precision
285
288 subroutine file_set_layout(this, layout)
289 class(file_t), intent(inout) :: this
290 integer, intent(in) :: layout
291 character(len=80) :: suffix
292
293 select type (ft => this%file_type)
294 type is (bp_file_t)
295 call ft%set_layout(layout)
296 class default
297 call filename_suffix(this%file_type%get_fname(), suffix)
298 call neko_warning("No set_layout defined for " // trim(suffix) // " yet")
299 end select
300
301 end subroutine file_set_layout
302
304 subroutine file_set_overwrite(this, overwrite)
305 class(file_t), intent(inout) :: this
306 logical, intent(in) :: overwrite
307 character(len=80) :: suffix
308
309 select type (ft => this%file_type)
310 class is (generic_file_t)
311 call ft%set_overwrite(overwrite)
312 end select
313 end subroutine file_set_overwrite
314
315end 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:252
subroutine file_set_overwrite(this, overwrite)
Sets the file's overwrite flag.
Definition file.f90:305
subroutine file_set_start_counter(this, n)
Set a file's start counter.
Definition file.f90:240
subroutine file_set_counter(this, n)
Set a file's counter.
Definition file.f90:228
character(len=1024) function file_get_fname(this)
Get a file's name.
Definition file.f90:187
subroutine file_set_layout(this, layout)
Set a file's output layout.
Definition file.f90:289
integer function file_get_counter(this)
Get a file's counter.
Definition file.f90:215
subroutine file_read(this, data)
Read data from a file.
Definition file.f90:178
subroutine file_set_precision(this, precision)
Set a file's output precision.
Definition file.f90:269
subroutine file_free(this)
File operation destructor.
Definition file.f90:156
subroutine file_init(this, fname, header, precision, layout, overwrite)
Constructor.
Definition file.f90:91
character(len=1024) function file_get_base_fname(this)
Get a file's base name.
Definition file.f90:201
subroutine file_write(this, data, t)
Writes data to a file.
Definition file.f90:167
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
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:55
Interface for NEKTON fld files.
Definition fld_file.f90:64
A generic file handler.
Interface for HDF5 files.
Definition hdf5_file.F90:56
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:51
Interface for legacy VTK files.
Definition vtk_file.f90:51