问题描述
我正在尝试在 Fortran 95 中读取 CSV 数据集。
我最初问了 this 个问题,但已被标记为重复,已建议两个帖子。但是,当我合并 iostat 的帖子检查时,我仍然会遇到 Segmentation Overflow。这些帖子与读取文件有关,而我的问题与标准输入有关(在原始 SO 请求中可能不完全清楚,所以我现在更清楚了)。
CSV 数据具有以下结构:
submit(Callable<T>)
数据显示在标准输入中。
有人建议我查看这些 SO 帖子:
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
两者都使用文件,而不是标准输入。
12,30,2010,23,00,01,125550,1,10643,125575,4665142,0
12,44,10644,125525,4665188,55,10645,4665287,02,20,10646,4665299,0
但是,当我运行程序时,我仍然遇到 Segmentation fault (core dumped):
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
注意:test_data.txt 包含开头呈现的数据。
对于之前建议的 SO 帖子,我做错了什么?
编辑:显然它读取标准输入直到数据结束,然后输出三个寄存器,但程序以$cat test_data.txt | ./a.out
12 30 2010 23 0 44
125550 1 10644 125525 125550 4665188
0 0
12 30 2010 23 1 55
125575 1 10645 125550 125575 4665287
0 0
12 30 2010 23 2 20
125550 1 10646 125550 125575 4665299
0 0
Segmentation fault (core dumped)
结束。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)