46 character(len=1024) :: header =
""
47 logical :: header_is_written = .false.
67 class(*),
target,
intent(in) :: data
68 real(kind=
rp),
intent(in),
optional :: t
78 if (.not.
allocated(data%x))
then
79 call neko_error(
"Vector is not allocated. Use &
80 &vector%init() to associate your array &
81 &with a vector_t object")
86 if (.not.
allocated(data%x))
then
87 call neko_error(
"Matrix is not allocated. Use &
88 &matrix%init() to associate your array &
89 &with a matrix_t object")
94 call neko_error(
"Invalid data. Expected vector_t or &
101 call neko_log%message(
"Writing to " // trim(this%fname))
102 if (
associated(vec))
then
104 else if (
associated(mat))
then
123 real(kind=
rp),
intent(in),
optional :: t
124 integer :: file_unit, ierr, n
126 open(
file = trim(f%fname), position =
"append", iostat = ierr, &
128 if (ierr .ne. 0)
call neko_error(
"Error while opening " // trim(f%fname))
131 if (f%header .ne.
"" .and. .not. f%header_is_written)
then
132 write (file_unit,
'(A)') trim(f%header)
133 f%header_is_written = .true.
137 if (
present(t))
write (file_unit,
'(g0,",")', advance =
"no") t
140 write (file_unit,
'(*(g0,","))', advance =
"no") data%x(1:n-1)
141 write (file_unit,
'(g0)') data%x(n)
155 real(kind=
rp),
intent(in),
optional :: t
156 integer :: file_unit, i, ierr, nc
158 open(
file = trim(f%fname), position =
"append", iostat = ierr, &
160 if (ierr .ne. 0)
call neko_error(
"Error while opening " // trim(f%fname))
163 if (f%header .ne.
"" .and. .not. f%header_is_written)
then
164 write (file_unit,
'(A)') trim(f%header)
165 f%header_is_written = .true.
168 do i = 1, data%get_nrows()
169 if (
present(t))
write (file_unit,
'(g0,",")', advance =
"no") t
170 nc = data%get_ncols()
171 write (file_unit,
'(*(g0,","))', advance =
"no") &
173 write (file_unit,
'(g0)') data%x(i, nc)
185 class(*),
target,
intent(inout) :: data
189 call this%check_exists()
197 if (.not.
allocated(data%x))
then
198 call neko_error(
"Vector is not allocated. Use &
199 &vector%init() to associate your array &
200 &with a vector_t object")
205 if (.not.
allocated(data%x))
then
206 call neko_error(
"Matrix is not allocated. Use &
207 &matrix%init() to associate your array &
208 &with a matrix_t object")
213 call neko_error(
"Invalid data type for csv_file (expected: vector_t, &
220 call neko_log%message(
"Reading csv file " // trim(this%fname))
221 if (
associated(vec))
then
223 else if (
associated(mat))
then
240 type(
vector_t),
intent(inout) :: vec
241 integer :: ierr, file_unit, n_lines
242 character(len=80) :: tmp
244 n_lines = f%count_lines()
246 open(
file = trim(f%fname), status =
'old', newunit = file_unit, &
248 if (ierr .ne. 0)
call neko_error(
"Error while opening " // trim(f%fname))
251 if (n_lines .gt. 1)
then
252 read (file_unit,
'(A)') tmp
256 read (file_unit,*) vec%x
257 close(unit = file_unit)
269 type(
matrix_t),
intent(inout) :: mat
270 integer :: ierr, file_unit, i, n_lines
271 character(len=80) :: tmp
273 n_lines = f%count_lines()
275 open(
file = trim(f%fname), status =
'old', newunit = file_unit, &
277 if (ierr .ne. 0)
call neko_error(
"Error while opening " // trim(f%fname))
281 if (n_lines .gt. mat%get_nrows())
then
282 read (file_unit,
'(A)') tmp
286 do i = 1, mat%get_nrows()
287 read (file_unit,*) mat%x(i,:)
289 close(unit = file_unit)
299 character(len=*),
intent(in) :: hd
301 this%header = trim(hd)
311 integer :: ierr, file_unit
313 call this%check_exists()
315 open(
file = trim(this%fname), status =
'old', newunit = file_unit, &
317 if (ierr .ne. 0)
call neko_error(
"Error while opening " // trim(this%fname))
324 read (file_unit, *, iostat = ierr)
325 if (ierr .ne. 0)
exit
329 close(unit = file_unit)
integer, public pe_rank
MPI rank.
File format for .csv files, used for any read/write operations involving floating point data.
subroutine csv_file_set_header(this, hd)
Sets the header for a csv file. For example: hd = "u,v,w,p".
subroutine csv_file_write_matrix(f, data, t)
Writes a matrix_t object to an output file. If the parameter t is present, it will be appended at the...
subroutine csv_file_write_vector(f, data, t)
Writes a vector_t object to an output file, in a row format. If the parameter t is present,...
subroutine csv_file_write(this, data, t)
Writes data to an output file.
subroutine csv_file_read(this, data)
Reads data from an input file.
subroutine csv_file_read_matrix(f, mat)
Read a matrix from a csv file.
integer function csv_file_count_lines(this)
Count the number of lines in a file by going through it entirely until the end is reached.
subroutine csv_file_read_vector(f, vec)
Read a vector (i.e. data on a single row) from a csv file.
Module for file I/O operations.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
integer, parameter, public rp
Global precision used in computations.