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_counter => file_get_counter
67 procedure :: set_counter => file_set_counter
69 procedure :: set_start_counter => file_set_start_counter
71 procedure :: set_header => file_set_header
73 procedure :: set_precision => file_set_precision
75 procedure :: set_layout => file_set_layout
77 procedure, pass (this) :: set_overwrite => file_set_overwrite
79 final :: file_free
80 end type file_t
81
82contains
83
86 subroutine file_init(this, fname, header, precision, layout, overwrite)
87 class(file_t), intent(inout) :: this
88 character(len=*), intent(in) :: fname
89 character(len=*), intent(in), optional :: header
90 integer, intent(in), optional :: precision
91 integer, intent(in), optional :: layout
92 logical, intent(in), optional :: overwrite
93 character(len=80) :: suffix
94 class(generic_file_t), pointer :: q
95
96 call filename_suffix(fname, suffix)
97
98 if (allocated(this%file_type)) then
99 deallocate(this%file_type)
100 end if
101
102 select case (suffix)
103 case ("rea")
104 allocate(rea_file_t::this%file_type)
105 case ("re2")
106 allocate(re2_file_t::this%file_type)
107 case ("map")
108 allocate(map_file_t::this%file_type)
109 case ("vtk")
110 allocate(vtk_file_t::this%file_type)
111 case ("nmsh")
112 allocate(nmsh_file_t::this%file_type)
113 case ("bp")
114 allocate(bp_file_t::this%file_type)
115 case ("fld")
116 allocate(fld_file_t::this%file_type)
117 case ("chkp")
118 allocate(chkp_file_t::this%file_type)
119 case ("stl")
120 allocate(stl_file_t::this%file_type)
121 case ("csv")
122 allocate(csv_file_t::this%file_type)
123 this%file_type%serial = .true.
124 case ("hdf5", "h5")
125 allocate(hdf5_file_t::this%file_type)
126 case default
127 call neko_error('Unknown file format')
128 end select
129
130 call this%file_type%init(fname)
131
132 if (present(header)) then
133 call this%set_header(header)
134 end if
135
136 if (present(precision)) then
137 call this%set_precision(precision)
138 end if
139
140 if (present(layout).and. (suffix .eq. "bp")) then
141 call this%set_layout(layout)
142 end if
143
144 if (present(overwrite)) then
145 call this%set_overwrite(overwrite)
146 end if
147
148 end subroutine file_init
149
151 subroutine file_free(this)
152 type(file_t), intent(inout) :: this
153
154 if (allocated(this%file_type)) then
155 deallocate(this%file_type)
156 end if
157
158 end subroutine file_free
159
162 subroutine file_write(this, data, t)
163 class(file_t), intent(inout) :: this
164 class(*), intent(inout) :: data
165 real(kind=rp), intent(in), optional :: t
166
167 call this%file_type%write(data, t = t)
168
169 end subroutine file_write
170
173 subroutine file_read(this, data)
174 class(file_t), intent(in) :: this
175 class(*), intent(inout) :: data
176
177 call this%file_type%read(data)
178
179 end subroutine file_read
180
182 function file_get_counter(this) result(n)
183 class(file_t), intent(inout) :: this
184 integer :: n
185 n = 0
186
187 select type (ft => this%file_type)
188 class is (generic_file_t)
189 n = ft%counter
190 end select
191
192 end function file_get_counter
193
195 subroutine file_set_counter(this, n)
196 class(file_t), intent(inout) :: this
197 integer, intent(in) :: n
198
199 select type (ft => this%file_type)
200 class is (generic_file_t)
201 call ft%set_counter(n)
202 end select
203
204 end subroutine file_set_counter
205
207 subroutine file_set_start_counter(this, n)
208 class(file_t), intent(inout) :: this
209 integer, intent(in) :: n
210
211 select type (ft => this%file_type)
212 class is (generic_file_t)
213 call ft%set_start_counter(n)
214 end select
215
216 end subroutine file_set_start_counter
217
219 subroutine file_set_header(this, hd)
220 class(file_t), intent(inout) :: this
221 character(len=*), intent(in) :: hd
222 character(len=80) :: suffix
223
224 select type (ft => this%file_type)
225 class is (csv_file_t)
226 call ft%set_header(hd)
227 class default
228 call filename_suffix(this%file_type%fname, suffix)
229 call neko_warning("No set_header defined for " // trim(suffix) // " yet")
230 end select
231
232 end subroutine file_set_header
233
236 subroutine file_set_precision(this, precision)
237 class(file_t), intent(inout) :: this
238 integer, intent(in) :: precision
239 character(len=80) :: suffix
240
241 select type (ft => this%file_type)
242 type is (fld_file_t)
243 call ft%set_precision(precision)
244 type is (bp_file_t)
245 call ft%set_precision(precision)
246 class default
247 call filename_suffix(this%file_type%fname, suffix)
248 call neko_warning("No precision strategy defined for " // trim(suffix) &
249 // " files")
250 end select
251
252 end subroutine file_set_precision
253
256 subroutine file_set_layout(this, layout)
257 class(file_t), intent(inout) :: this
258 integer, intent(in) :: layout
259 character(len=80) :: suffix
260
261 select type (ft => this%file_type)
262 type is (bp_file_t)
263 call ft%set_layout(layout)
264 class default
265 call filename_suffix(this%file_type%fname, suffix)
266 call neko_warning("No set_layout defined for " // trim(suffix) // " yet")
267 end select
268
269 end subroutine file_set_layout
270
272 subroutine file_set_overwrite(this, overwrite)
273 class(file_t), intent(inout) :: this
274 logical, intent(in) :: overwrite
275 character(len=80) :: suffix
276
277 select type (ft => this%file_type)
278 type is (csv_file_t)
279 call ft%set_overwrite(overwrite)
280 class default
281 call filename_suffix(this%file_type%fname, suffix)
282 call neko_warning("No set_overwrite defined for " // trim(suffix) // &
283 " yet")
284 end select
285 end subroutine file_set_overwrite
286
287end 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:220
subroutine file_set_overwrite(this, overwrite)
Sets the file's overwrite flag.
Definition file.f90:273
subroutine file_set_start_counter(this, n)
Set a file's start counter.
Definition file.f90:208
subroutine file_set_counter(this, n)
Set a file's counter.
Definition file.f90:196
subroutine file_set_layout(this, layout)
Set a file's output layout.
Definition file.f90:257
integer function file_get_counter(this)
Get a file's counter.
Definition file.f90:183
subroutine file_read(this, data)
Read data from a file.
Definition file.f90:174
subroutine file_set_precision(this, precision)
Set a file's output precision.
Definition file.f90:237
subroutine file_free(this)
File operation destructor.
Definition file.f90:152
subroutine file_init(this, fname, header, precision, layout, overwrite)
Constructor.
Definition file.f90:87
subroutine file_write(this, data, t)
Writes data to a file.
Definition file.f90:163
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:284
subroutine, public filename_suffix(fname, suffix)
Extract a filename's suffix.
Definition utils.f90:71
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:56
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:65
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