fcode 发表于 2015-3-13 18:47 我好好研究一下。感谢! |
|
因为你执行了 12 次循环,所以需要12行。 如无特别声明,每个 read 读一行。如果你只有 3 行,可以这样读: [Fortran] 查看源码 复制源码 Program t
Implicit None
Integer, Parameter :: row = 3
Integer, Parameter :: col = 4
Real :: a(1:row,1:col)
Integer :: i,j
Open(11,file='in.txt')
Do i = 1,row
Do j = 1,col
a(i,j) = 10*i+j
Write(11,*) a(i,j)
Enddo
Enddo
! read the array==============================================
Do i = 1,row
Do j = 1,col
Read(11,*) a(i,1)
Enddo
Enddo
Close(11)
End Program t更多的二维数组与文本文件行列问题,请阅读: http://fcode.cn/guide-45-1.html |
|
[Fortran] 查看源码 复制源码 Program t
Implicit None
Integer, Parameter :: row = 3
Integer, Parameter :: col = 4
Real :: a(1:row,1:col)
Integer :: i,j
Open(11,file='in.txt')
Do i = 1,row
Read(11,*) a(i,:)
Write(*,*) a(i,:)
Enddo
Close(11)
End Program t
当你对 11 号文件写入后,文件操作位置就在文件的最末端,此时你再读取,后面没有数据,所以会出错。 你可以把文件操作位置重新设置为文件开始。用 Rewind 语句。 也可以关闭文件,然后重新读取。 (一般情况下,同一次 Open Close,不要即读又写,比较容易出错) |
|
end-of-file 错误: http://fcode.cn/guide-36-2.html |
捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )
GMT+8, 2025-12-28 23:06