Neko 1.99.1
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
generic_file.f90
Go to the documentation of this file.
1! Copyright (c) 2019-2023, 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 use num_types, only: rp
35 use utils, only: neko_error
36 use comm, only: pe_rank, neko_comm
37 use mpi_f08, only: mpi_bcast, mpi_logical
38 implicit none
39
41 type, abstract :: generic_file_t
42 character(len=1024) :: fname
43 integer :: counter = 0
44 integer :: start_counter = 0
46 logical :: serial = .false.
47 contains
49 procedure :: init => generic_file_init
50
51 procedure(generic_file_write), deferred :: write
52
53 procedure(generic_file_read), deferred :: read
55 procedure :: set_counter => generic_file_set_counter
57 procedure :: set_start_counter => generic_file_set_start_counter
59 procedure :: check_exists => generic_file_check_exists
60 end type generic_file_t
61
62 abstract interface
63 subroutine generic_file_write(this, data, t)
64 import :: generic_file_t
65 import :: rp
66 class(generic_file_t), intent(inout) :: this
67 class(*), target, intent(in) :: data
68 real(kind=rp), intent(in), optional :: t
69 end subroutine generic_file_write
70 end interface
71
72 abstract interface
73 subroutine generic_file_read(this, data)
74 import :: generic_file_t
75 class(generic_file_t) :: this
76 class(*), target, intent(inout) :: data
77 end subroutine generic_file_read
78 end interface
79
80contains
81
84 subroutine generic_file_init(this, fname)
85 class(generic_file_t) :: this
86 character(len=*) :: fname
87
88 this%fname = fname
89 this%counter = 0
90
91 end subroutine generic_file_init
92
94 subroutine generic_file_set_counter(this, n)
95 class(generic_file_t), intent(inout) :: this
96 integer, intent(in) :: n
97 this%counter = n
98 end subroutine generic_file_set_counter
99
102 class(generic_file_t), intent(inout) :: this
103 integer, intent(in) :: n
104 this%start_counter = n
105 end subroutine generic_file_set_start_counter
106
109 class(generic_file_t), intent(in) :: this
110 logical :: file_exists
111 integer :: neko_mpi_ierr
112
113 file_exists = .false.
114
115 if (pe_rank .eq. 0 .or. this%serial) then
116 ! Stop if the file does not exist
117 inquire(file = this%fname, exist = file_exists)
118 end if
119
120 if (.not. this%serial) then
121 call mpi_bcast(file_exists, 1, mpi_logical, 0, neko_comm, neko_mpi_ierr)
122 end if
123
124 if (.not. file_exists) then
125 call neko_error('File does not exist: ' // trim(this%fname))
126 end if
127
128 end subroutine generic_file_check_exists
129
130
131end module generic_file
Definition comm.F90:1
integer, public pe_rank
MPI rank.
Definition comm.F90:55
type(mpi_comm), public neko_comm
MPI communicator.
Definition comm.F90:42
Module for file I/O operations.
Definition file.f90:34
subroutine generic_file_check_exists(this)
check if the file exists
subroutine generic_file_set_start_counter(this, n)
Set the file start counter to n.
subroutine generic_file_init(this, fname)
Generic file constructor.
subroutine generic_file_set_counter(this, n)
Set the file counter to n.
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Utilities.
Definition utils.f90:35
A generic file handler.