Io 正在从文件结尾读取整数,但已完成格式化数据传输的``缺少格式``

Io 正在从文件结尾读取整数,但已完成格式化数据传输的``缺少格式``,io,format,fortran,Io,Format,Fortran,我正在更新Fortran程序以满足我的需要。该程序使用f95和gcc版本4.1.2进行编译(我知道它很旧,但无法更新)。我想从文件中读取参数,并通过 inquire (file="resLast", exist=resExist) if (readStart.eq.1.and.resExist) then open (unit=18,file='resLast', status='old', action='read') read (1

我正在更新Fortran程序以满足我的需要。该程序使用
f95
gcc
版本4.1.2进行编译(我知道它很旧,但无法更新)。我想从文件中读取参数,并通过

      inquire (file="resLast", exist=resExist)
      if (readStart.eq.1.and.resExist) then
         open (unit=18,file='resLast', status='old', action='read')
         read (18) startConf
         read (18) avlength, stdlength, avenergy
         read (18) i,h2(1)
         read (18) i,h2(2)
         read (18) i,h2(4)
         read (18) i,h2(5)
         read (18) i,h2(8)
         read (18) i,h2(9)
         read (18) i,h2(13)
         read (18) i,h2(16)
         read (18) i,h2(17)
         read (18) i,h2(18)
         read (18) i,h2(20)
         read (18) i,h2(25)
         read (18) i,h2(32)
         close (18)
      else
         startConf = 0
         do i=1,32
            h2(i)=0
            comh2(i)=0
         enddo
         avlength=0d0
         stdlength=0d0
         avenergy=0d0
      endif
输入文件如下所示

           0
   196.090732114834        38451.5752213317        53.4452884569457     
           1  9.188750409521163E-004
           2  4.548226133920252E-004
           4  8.704101492185146E-005
           5  2.175445697503164E-004
           8  4.992044341634028E-005
           9  2.108949411194772E-005
          13  4.304789035813883E-005
          16  4.693072696682066E-005
          17  8.976260141935199E-005
          18  2.737747854553163E-005
          20  5.637826689053327E-005
          25  3.860405195155181E-005
          32  3.193027441739105E-005
当我试着运行这个时,我得到了一个错误

Fortran runtime error: Missing format for FORMATTED data transfer
done
它指向第一个
读取
行。
startConf变量以及
i``是一个整数。其余变量为双精度变量


我以前使用此方法将数据读入整数(即使是在同一代码中),没有问题,我当前的错误在哪里?

由于您没有明确指定它,您的
open
语句假定一个
格式的
(文本)文件。读取文本文件时,还必须提供格式:

read(18, *) i1
或者,如果文件未格式化
(二进制),请相应地打开文件:

 open (unit=18, file='resLast', status='old', action='read', form='unformatted')

阅读(18,*)是更好的选择。您可以试试这个。

确切地说,您的示例是“列表定向I/O”。它会起作用,而且比提供格式容易得多。