主题:如何只读取文件中的前两列?
Belinda124
[专家分:0] 发布于 2011-03-15 21:52:00
请问怎样只读取文件中的前两列?
回复列表 (共5个回复)
沙发
kikyomn [专家分:30] 发布于 2011-03-15 22:51:00
假如要读入前N行的前两列
do i=1,N
read(2,*) a(i),b(i),s,b,l,o,v
end do
这样,第一列就直接存到a数组,第二列就存到b数组中了,后面的s,b,l,o,v就是你不要的那些列,有几列写几个字母就好了。
板凳
Belinda124 [专家分:0] 发布于 2011-03-16 01:01:00
总是有错误提示:
At line 53 of file ls_spline_1d.f90 (unit = 11, file = 'test.txt')
Fortran runtime error: End of file
3 楼
yeg001 [专家分:14390] 发布于 2011-03-16 13:39:00
这个问题跟之前你发的帖是同一个??
4 楼
Belinda124 [专家分:0] 发布于 2011-03-17 21:36:00
very sorry for having to write in english, as my PC doesn't support the chinese characters for reply except for the issue of launching a new talk.
now the question is:
using the following procedure, the program can run very well, but when coming to a situation that I just need to read the second column data, that is just read yi(l), errors appear immediately. and another strnage phenomenon is when I tring to change xi(l) instead by zi(l), just one word changes, error appears again. So I wanna know the right answer to these two situations. and many thanks.
OPEN(11,file='test.txt',status="old",iostat=error)
if(error/=0)then
write(*,*)"open test.txt fail"
stop
end if
do l=1,ni
read(11,'(3(f9.6,3x))',END=20)xi(l),yi(l),s
end do
20 continue
5 楼
tpycx [专家分:20] 发布于 2011-03-27 17:37:00
OPEN(2,FILE='需读取的文件名')
DO J = 1,Ni
READ(2,'(2F19.8)')(变量名(J,I),I=1,2)
ENDDO
CLOSE(2)
我来回复