Loading [MathJax]/extensions/tex2jax.js
Neko 0.9.99
A portable framework for high-order spectral element flow simulations
All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros Pages
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 fld_file, only : fld_file_t
45 use vtk_file, only : vtk_file_t
46 use stl_file, only : stl_file_t
47 use csv_file, only : csv_file_t
48 use hdf5_file, only : hdf5_file_t
49 implicit none
50
54 type file_t
55 class(generic_file_t), allocatable :: file_type
56 contains
58 procedure :: write => file_write
60 procedure :: read => file_read
62 procedure :: get_counter => file_get_counter
64 procedure :: set_counter => file_set_counter
66 procedure :: set_start_counter => file_set_start_counter
68 procedure :: set_header => file_set_header
70 procedure :: set_precision => file_set_precision
72 final :: file_free
73 end type file_t
74
75 interface file_t
76 module procedure file_init
77 end interface file_t
78
79contains
80
83 function file_init(fname, header, precision) result(this)
84 character(len=*) :: fname
85 character(len=*), optional :: header
86 integer, optional :: precision
87 type(file_t), target :: this
88 character(len=80) :: suffix
89 class(generic_file_t), pointer :: q
90
91 call filename_suffix(fname, suffix)
92
93 if (allocated(this%file_type)) then
94 deallocate(this%file_type)
95 end if
96
97 if (suffix .eq. "rea") then
98 allocate(rea_file_t::this%file_type)
99 else if (suffix .eq. "re2") then
100 allocate(re2_file_t::this%file_type)
101 else if (suffix .eq. "map") then
102 allocate(map_file_t::this%file_type)
103 else if (suffix .eq. "vtk") then
104 allocate(vtk_file_t::this%file_type)
105 else if (suffix .eq. "nmsh") then
106 allocate(nmsh_file_t::this%file_type)
107 else if (suffix .eq. "fld") then
108 allocate(fld_file_t::this%file_type)
109 else if (suffix .eq. "chkp") then
110 allocate(chkp_file_t::this%file_type)
111 else if (suffix .eq. "stl") then
112 allocate(stl_file_t::this%file_type)
113 else if (suffix .eq. "csv") then
114 allocate(csv_file_t::this%file_type)
115 this%file_type%serial = .true.
116 else if ((suffix .eq. "hdf5") .or. (suffix .eq. "h5")) then
117 allocate(hdf5_file_t::this%file_type)
118 else
119 call neko_error('Unknown file format')
120 end if
121
122 call this%file_type%init(fname)
123
124 if (present(header)) then
125 call this%set_header(header)
126 end if
127
128 if (present(precision)) then
129 call this%set_precision(precision)
130 end if
131
132 end function file_init
133
135 subroutine file_free(this)
136 type(file_t), intent(inout) :: this
137
138 if (allocated(this%file_type)) then
139 deallocate(this%file_type)
140 end if
141
142 end subroutine file_free
143
146 subroutine file_write(this, data, t)
147 class(file_t), intent(inout) :: this
148 class(*), intent(inout) :: data
149 real(kind=rp), intent(in), optional :: t
150
151 if (present(t)) then
152 call this%file_type%write(data, t)
153 else
154 call this%file_type%write(data)
155 end if
156
157 end subroutine file_write
158
161 subroutine file_read(this, data)
162 class(file_t), intent(in) :: this
163 class(*), intent(inout) :: data
164
165 call this%file_type%read(data)
166
167 end subroutine file_read
168
170 function file_get_counter(this) result(n)
171 class(file_t), intent(inout) :: this
172 integer :: n
173 n = 0
174
175 select type(ft => this%file_type)
176 class is (generic_file_t)
177 n = ft%counter
178 end select
179
180 end function file_get_counter
181
183 subroutine file_set_counter(this, n)
184 class(file_t), intent(inout) :: this
185 integer, intent(in) :: n
186
187 select type(ft => this%file_type)
188 class is (generic_file_t)
189 call ft%set_counter(n)
190 end select
191
192 end subroutine file_set_counter
193
195 subroutine file_set_start_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_start_counter(n)
202 end select
203
204 end subroutine file_set_start_counter
205
207 subroutine file_set_header(this, hd)
208 class(file_t), intent(inout) :: this
209 character(len=*), intent(in) :: hd
210
211 character(len=80) :: suffix
212
213 select type(ft => this%file_type)
214 class is (csv_file_t)
215 call ft%set_header(hd)
216 class default
217 call filename_suffix(this%file_type%fname, suffix)
218 call neko_warning("No set_header defined for " // trim(suffix) // " yet!")
219 end select
220
221 end subroutine file_set_header
222
225 subroutine file_set_precision(this, precision)
226 class(file_t), intent(inout) :: this
227 integer, intent(in) :: precision
228
229 character(len=80) :: suffix
230
231 select type(ft => this%file_type)
232 type is (fld_file_t)
233 call ft%set_precision(precision)
234 class default
235 call filename_suffix(this%file_type%fname, suffix)
236 call neko_warning("No precision strategy defined for " // trim(suffix) //&
237 " files!")
238 end select
239
240 end subroutine file_set_precision
241
242end module file
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:208
subroutine file_set_start_counter(this, n)
Set a file's start counter.
Definition file.f90:196
subroutine file_set_counter(this, n)
Set a file's counter.
Definition file.f90:184
type(file_t) function, target file_init(fname, header, precision)
File reader/writer constructor.
Definition file.f90:84
integer function file_get_counter(this)
Get a file's counter.
Definition file.f90:171
subroutine file_read(this, data)
Read data from a file.
Definition file.f90:162
subroutine file_set_precision(this, precision)
Set a file's output precision.
Definition file.f90:226
subroutine file_free(this)
File operation destructor.
Definition file.f90:136
subroutine file_write(this, data, t)
Writes data to a file.
Definition file.f90:147
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:266
subroutine, public filename_suffix(fname, suffix)
Extract a filename's suffix.
Definition utils.f90:70
Legacy VTK file format.
Definition vtk_file.f90:35
Interface for Neko checkpoint files.
Definition chkp_file.f90:55
A wrapper around a polymorphic generic_file_t that handles its init. This is essentially a factory fo...
Definition file.f90:54
Interface for NEKTON fld files.
Definition fld_file.f90:64
A generic file handler.
Interface for HDF5 files.
Definition hdf5_file.F90:54
Interface for NEKTON map files.
Definition map_file.f90:44
Interface for Neko nmsh files.
Definition nmsh_file.f90:60
Interface for NEKTON re2 files.
Definition re2_file.f90:62
Interface for NEKTON ascii files.
Definition rea_file.f90:61
Interface for STL files.
Definition stl_file.f90:49
Interface for legacy VTK files.
Definition vtk_file.f90:51