I am trying to read a CSV file with the following structure:
12,30,2010,23,00,01,125550,1,10643,125550,125575,4665142,0,0
12,30,2010,23,00,44,125550,1,10644,125525,125550,4665188,0,0
12,30,2010,23,01,55,125575,1,10645,125550,125575,4665287,0,0
12,30,2010,23,02,20,125550,1,10646,125550,125575,4665299,0,0
The data is presented in the standard input.
I have been suggested to look at these SO posts:
Using do loop in a Fortran 90 program to read different number of lines for n frames?
Read a file with an unknown number rows in Fortran
Both uses files, not the standard input.
I have modified my code and added the iostat check:
program file_parser
implicit none
! -------------------
! TYPE DEFINITION
! -------------------
type :: type1_record
integer :: month
integer :: day
integer :: year
integer :: hour
integer :: minute
integer :: second
integer :: field1
integer :: field2
integer :: field3
integer :: field4
integer :: field5
integer :: field6
integer :: field7
integer :: field8
end type
! -------------------
! VARIABLE DEFINITION
! -------------------
integer :: i, io_result
type(type1_record), dimension(10000) :: input_data
i = 0
do
read(*,*,iostat=io_result) input_data(i)
if (io_result /= 0) exit
i = i + 1
end do
do i = 1, 3
write(*,*) input_data(i)
end do
end program
However, when I run the program I still get Segmentation fault (core dumped):
$cat test_data.txt | ./a.out
Segmentation fault (core dumped)
Note: test_data.txt contains the data presented at the beginning.
What I am doing wrong with respect of the SO posts that have been previously suggested?
I am using flang
and trying to stick to Fortran 95 standard.