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
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
Rewind(11) !// 增加这句
! read the array==============================================
Do i = 1,row
Do j = 1,col
Read(11,*) a(i,1)
Enddo
Enddo
Close(11)
End Program t
fcode 发表于 2015-3-13 18:04
Program t
Implicit None
Integer, Parameter :: row = 3
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
Read(11,*) a(i,j)
Write(*,*) a(i,j)
Enddo
Enddo
Close(11)
End Program t
执行结果.PNG (3.77 KB, 下载次数: 397)
执行结果
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
fcode 发表于 2015-3-13 18:47
因为你执行了 12 次循环,所以需要12行。
如无特别声明,每个 read 读一行。如果你只有 3 行,可以这样读 ...
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |