Neko  0.8.1
A portable framework for high-order spectral element flow simulations
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 !
34 module file
36  use num_types, only : rp
37  use generic_file, only : generic_file_t
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
44  use fld_file_data, only : fld_file_data_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  implicit none
49 
53  type file_t
54  class(generic_file_t), allocatable :: file_type
55  contains
57  procedure :: write => file_write
59  procedure :: read => file_read
61  procedure :: set_counter => file_set_counter
63  procedure :: set_start_counter => file_set_start_counter
65  procedure :: set_header => file_set_header
67  procedure :: set_precision => file_set_precision
69  final :: file_free
70  end type file_t
71 
72  interface file_t
73  module procedure file_init
74  end interface file_t
75 
76 contains
77 
80  function file_init(fname, header, precision) result(this)
81  character(len=*) :: fname
82  character(len=*), optional :: header
83  integer, optional :: precision
84  type(file_t), target :: this
85  character(len=80) :: suffix
86  class(generic_file_t), pointer :: q
87 
88  call filename_suffix(fname, suffix)
89 
90  if (allocated(this%file_type)) then
91  deallocate(this%file_type)
92  end if
93 
94  if (suffix .eq. "rea") then
95  allocate(rea_file_t::this%file_type)
96  else if (suffix .eq. "re2") then
97  allocate(re2_file_t::this%file_type)
98  else if (suffix .eq. "map") then
99  allocate(map_file_t::this%file_type)
100  else if (suffix .eq. "vtk") then
101  allocate(vtk_file_t::this%file_type)
102  else if (suffix .eq. "nmsh") then
103  allocate(nmsh_file_t::this%file_type)
104  else if (suffix .eq. "fld") then
105  allocate(fld_file_t::this%file_type)
106  else if (suffix .eq. "chkp") then
107  allocate(chkp_file_t::this%file_type)
108  else if (suffix .eq. "stl") then
109  allocate(stl_file_t::this%file_type)
110  else if (suffix .eq. "csv") then
111  allocate(csv_file_t::this%file_type)
112  this%file_type%serial = .true.
113  else
114  call neko_error('Unknown file format')
115  end if
116 
117  call this%file_type%init(fname)
118 
119  if (present(header)) then
120  call this%set_header(header)
121  end if
122 
123  if (present(precision)) then
124  call this%set_precision(precision)
125  end if
126 
127  end function file_init
128 
130  subroutine file_free(this)
131  type(file_t), intent(inout) :: this
132 
133  if (allocated(this%file_type)) then
134  deallocate(this%file_type)
135  end if
136 
137  end subroutine file_free
138 
141  subroutine file_write(this, data, t)
142  class(file_t), intent(inout) :: this
143  class(*), intent(inout) :: data
144  real(kind=rp), intent(in), optional :: t
145 
146  if (present(t)) then
147  call this%file_type%write(data, t)
148  else
149  call this%file_type%write(data)
150  end if
151 
152  end subroutine file_write
153 
156  subroutine file_read(this, data)
157  class(file_t), intent(in) :: this
158  class(*), intent(inout) :: data
159 
160  call this%file_type%read(data)
161 
162  end subroutine file_read
163 
165  subroutine file_set_counter(this, n)
166  class(file_t), intent(inout) :: this
167  integer, intent(in) :: n
168 
169  select type(ft => this%file_type)
170  class is (generic_file_t)
171  call ft%set_counter(n)
172  end select
173 
174  end subroutine file_set_counter
175 
177  subroutine file_set_start_counter(this, n)
178  class(file_t), intent(inout) :: this
179  integer, intent(in) :: n
180 
181  select type(ft => this%file_type)
182  class is (generic_file_t)
183  call ft%set_start_counter(n)
184  end select
185 
186  end subroutine file_set_start_counter
187 
189  subroutine file_set_header(this, hd)
190  class(file_t), intent(inout) :: this
191  character(len=*), intent(in) :: hd
192 
193  character(len=80) :: suffix
194 
195  select type(ft => this%file_type)
196  class is (csv_file_t)
197  call ft%set_header(hd)
198  class default
199  call filename_suffix(this%file_type%fname, suffix)
200  call neko_warning("No set_header defined for " // trim(suffix) // " yet!")
201  end select
202 
203  end subroutine file_set_header
204 
207  subroutine file_set_precision(this, precision)
208  class(file_t), intent(inout) :: this
209  integer, intent(in) :: precision
210 
211  character(len=80) :: suffix
212 
213  select type(ft => this%file_type)
214  type is (fld_file_t)
215  call ft%set_precision(precision)
216  class default
217  call filename_suffix(this%file_type%fname, suffix)
218  call neko_warning("No precision strategy defined for " // trim(suffix) //&
219  " files!")
220  end select
221 
222  end subroutine file_set_precision
223 
224 end 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:190
subroutine file_set_start_counter(this, n)
Set a file's start counter.
Definition: file.f90:178
subroutine file_set_counter(this, n)
Set a file's counter.
Definition: file.f90:166
type(file_t) function, target file_init(fname, header, precision)
File reader/writer constructor.
Definition: file.f90:81
subroutine file_read(this, data)
Read data from a file.
Definition: file.f90:157
subroutine file_set_precision(this, precision)
Set a file's output precision.
Definition: file.f90:208
subroutine file_free(this)
File operation destructor.
Definition: file.f90:131
subroutine file_write(this, data, t)
Writes data to a file.
Definition: file.f90:142
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
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 filename_suffix(fname, suffix)
Extract a filename's suffix.
Definition: utils.f90:62
subroutine neko_warning(warning_msg)
Definition: utils.f90:191
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:53
Interface for NEKTON fld files.
Definition: fld_file.f90:61
A generic file handler.
Interface for NEKTON map files.
Definition: map_file.f90:44
Interface for Neko nmsh files.
Definition: nmsh_file.f90:54
Interface for NEKTON re2 files.
Definition: re2_file.f90:55
Interface for NEKTON ascii files.
Definition: rea_file.f90:53
Interface for STL files.
Definition: stl_file.f90:49
Interface for legacy VTK files.
Definition: vtk_file.f90:51