如果你改变你的格式
10 format (i4,'.dat')
我想这例如
character *8 filename
do i=1,9999
write (filename, 10) i
write (*,*) filename
end do
10 format (i4,'.dat')
end
而且我在我的文件名没有前导零。
你是在找这个帽子吗?
更新
我看到...
然后格式应为
10 format (i0,'.dat')
的 '0' 表示左对齐。
我用下面的PGM
character*12, fn
integer x(11,5)
integer y(11,5)
integer z(11,5)
do i=1,11
write(fn,10)i
open(1,file=fn)
do j=1,5
read(1,*)x(i,j),y(i,j),z(i,j)
end do
close(1)
end do
10 format(i0,'.dat')
end
测试它,这为我工作。
更新2
implicit none
integer n,ns,i,j
real x(9999,400),y(9999,400),z(9999,400),a(9999,400),aa(400)
character*12, fn
n = 14
ns = 2
do i = 0,n
do j = 1, 5
a(i,j) = 0.0
end do
end do
do i=1,n
write(fn,10)i
open(1,file=fn)
do j=1,5
read(1,*)x(i,j),y(i,j),z(i,j)
if(i.le.ns) then
a(i,j) = x(i,j)
else
a(i,j) = x(i,j) + a(i-ns,j)
end if
aa(j) = a(i,j)
write(*,*) j,x(i,j),y(i,j),z(i,j),a(i,j)
end do
close(1)
do j = 1, 5
write(*,*) aa(j)
end do
end do
10 format(i0,'.dat')
end
为我工作。
输出(在Ubuntu 10.10上)。
./a.out
1 1.0000000 3.0000000 5.0000000 1.0000000
2 2.0000000 5.0000000 7.0000000 2.0000000
3 3.0000000 7.0000000 8.0000000 3.0000000
4 1.0000000 4.0000000 8.0000000 1.0000000
5 1.0000000 4.0000000 8.0000000 1.0000000
1.0000000
2.0000000
3.0000000
1.0000000
1.0000000
1 3.0000000 8.0000000 5.0000000 3.0000000
2 7.0000000 5.0000000 7.0000000 7.0000000
3 3.0000000 7.0000000 8.0000000 3.0000000
4 1.0000000 4.0000000 10.000000 1.0000000
5 3.0000000 5.0000000 7.0000000 3.0000000
3.0000000
7.0000000
3.0000000
1.0000000
3.0000000
1 3.0000000 8.0000000 5.0000000 4.0000000
2 7.0000000 5.0000000 7.0000000 9.0000000
3 3.0000000 7.0000000 8.0000000 6.0000000
4 1.0000000 4.0000000 10.000000 2.0000000
5 3.0000000 5.0000000 7.0000000 4.0000000
4.0000000
9.0000000
6.0000000
2.0000000
4.0000000
1 3.0000000 8.0000000 5.0000000 6.0000000
2 7.0000000 5.0000000 7.0000000 14.000000
3 3.0000000 7.0000000 8.0000000 6.0000000
4 1.0000000 4.0000000 10.000000 2.0000000
5 3.0000000 5.0000000 7.0000000 6.0000000
6.0000000
14.000000
6.0000000
2.0000000
6.0000000
1 3.0000000 8.0000000 5.0000000 7.0000000
2 7.0000000 5.0000000 7.0000000 16.000000
3 3.0000000 7.0000000 8.0000000 9.0000000
4 1.0000000 4.0000000 10.000000 3.0000000
5 3.0000000 5.0000000 7.0000000 7.0000000
7.0000000
16.000000
9.0000000
3.0000000
7.0000000
1 3.0000000 8.0000000 5.0000000 9.0000000
2 7.0000000 5.0000000 7.0000000 21.000000
3 3.0000000 7.0000000 8.0000000 9.0000000
4 1.0000000 4.0000000 10.000000 3.0000000
5 3.0000000 5.0000000 7.0000000 9.0000000
9.0000000
21.000000
9.0000000
3.0000000
9.0000000
1 3.0000000 8.0000000 5.0000000 10.000000
2 7.0000000 5.0000000 7.0000000 23.000000
3 3.0000000 7.0000000 8.0000000 12.000000
4 1.0000000 4.0000000 10.000000 4.0000000
5 3.0000000 5.0000000 7.0000000 10.000000
10.000000
23.000000
12.000000
4.0000000
10.000000
1 3.0000000 8.0000000 5.0000000 12.000000
2 7.0000000 5.0000000 7.0000000 28.000000
3 3.0000000 7.0000000 8.0000000 12.000000
4 1.0000000 4.0000000 10.000000 4.0000000
5 3.0000000 5.0000000 7.0000000 12.000000
12.000000
28.000000
12.000000
4.0000000
12.000000
1 3.0000000 8.0000000 5.0000000 13.000000
2 7.0000000 5.0000000 7.0000000 30.000000
3 3.0000000 7.0000000 8.0000000 15.000000
4 1.0000000 4.0000000 10.000000 5.0000000
5 3.0000000 5.0000000 7.0000000 13.000000
13.000000
30.000000
15.000000
5.0000000
13.000000
1 3.0000000 8.0000000 5.0000000 15.000000
2 7.0000000 5.0000000 7.0000000 35.000000
3 3.0000000 7.0000000 8.0000000 15.000000
4 1.0000000 4.0000000 10.000000 5.0000000
5 3.0000000 5.0000000 7.0000000 15.000000
15.000000
35.000000
15.000000
5.0000000
15.000000
1 3.0000000 8.0000000 5.0000000 16.000000
2 7.0000000 5.0000000 7.0000000 37.000000
3 3.0000000 7.0000000 8.0000000 18.000000
4 1.0000000 4.0000000 10.000000 6.0000000
5 3.0000000 5.0000000 7.0000000 16.000000
16.000000
37.000000
18.000000
6.0000000
16.000000
At line 23 of file c.for (unit = 1, file = '12.dat')
Fortran runtime error: End of file
谢谢阿兰。然而,我得到了同样的错误,如:list in:文件末尾明显状态:单元1命名为1.dat最后格式:列表io最近阅读顺序格式化外部IO中止您对此有何看法? – nagendra 2011-03-06 21:54:47
您可以使用这些文件的样本更新问题,以便我们为您提供一个简单的阅读程序? – 2011-03-06 22:07:36
当然。其实我在Linux [Ubuntu]工作,我自己写了数据文件。我不知道如何为您提供我的数据文件,但它包含3列和9行。而已。如果我将文件重命名为0001.dat,0002.dat而不是1.dat,2.dat,则该程序可以读取。 – nagendra 2011-03-06 22:46:24