回 帖 发 新 帖 刷新版面

主题:如何只读取文件中的前两列?

请问怎样只读取文件中的前两列?

回复列表 (共5个回复)

沙发

假如要读入前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就是你不要的那些列,有几列写几个字母就好了。

板凳


总是有错误提示:
At line 53 of file ls_spline_1d.f90 (unit = 11, file = 'test.txt')
Fortran runtime error: End of file

3 楼

这个问题跟之前你发的帖是同一个??

4 楼

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 楼

OPEN(2,FILE='需读取的文件名')
    DO J = 1,Ni
    READ(2,'(2F19.8)')(变量名(J,I),I=1,2)
    ENDDO
CLOSE(2)

我来回复

您尚未登录,请登录后再回复。点此登录或注册